<commit_before>/*
** qi.c
** Login : <<EMAIL>>
** Started on  Thu Nov 18 18:11:44 2010 <NAME>
** $Id$
**
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010 <NAME>
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <qi/qi.h>
#include <qi/messaging.hpp>
#include <qi/messaging/detail/client_impl.hpp>

struct client_private_t {
public:
  //Constructor
  client_private_t(const char *name, const char *address)
    : client(std::string(name), std::string(address))
  {}

public:
  qi::detail::ClientImpl client;
};


struct message_private_t {
  qi::serialization::BinarySerializer msg;
};


qi_client_t *qi_client_create(const char *name, const char *address) {
  client_private_t *pclient = new client_private_t(name, address);
  return (qi_client_t *)pclient;
}

void      qi_client_call(qi_client_t *client, const char *method, qi_message_t *msg, qi_message_t *ret)
{
  client_private_t  *pclient  = (client_private_t *)client;
  message_private_t *preturn  = (message_private_t *)ret;
  message_private_t *pmessage = (message_private_t *)msg;

  pclient->client.call(std::string(method), pmessage->msg, preturn->msg);
}

qi_message_t *qi_message_create()
{
  message_private_t *pmsg = new message_private_t();
  return (qi_message_t *)pmsg;
}

void qi_message_write_int(qi_message_t *msg, const int i)
{
  message_private_t *pmsg = (message_private_t *)msg;
  pmsg->msg.writeInt(i);
}

void qi_message_write_string(qi_message_t *msg, const char *s)
{
  message_private_t *pmsg = (message_private_t *)msg;
  pmsg->msg.writeString(std::string(s));
}

int qi_message_read_int(qi_message_t *msg)
{
  message_private_t *pmsg = (message_private_t *)msg;
  int i;
  pmsg->msg.readInt(i);
  return i;
}

// FIXME: strndup is a gnu thing
//char *qi_message_read_string(qi_message_t *msg)
//{
//  message_private_t *pmsg = (message_private_t *)msg;
//  std::string s;
//  pmsg->msg.readString(s);
//  //TODO: buffer overflow
//  return strndup(s.c_str(), s.size());
//}<commit_msg>c: reactivate qi_message_read_string<commit_after>/*
** qi.c
** Login : <<EMAIL>>
** Started on  Thu Nov 18 18:11:44 2010 <NAME>
** $Id$
**
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010 <NAME>
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <qi/qi.h>
#include <qi/messaging.hpp>
#include <qi/messaging/detail/client_impl.hpp>

struct client_private_t {
public:
  //Constructor
  client_private_t(const char *name, const char *address)
    : client(std::string(name), std::string(address))
  {}

public:
  qi::detail::ClientImpl client;
};


struct message_private_t {
  qi::serialization::BinarySerializer msg;
};


qi_client_t *qi_client_create(const char *name, const char *address) {
  client_private_t *pclient = new client_private_t(name, address);
  return (qi_client_t *)pclient;
}

void      qi_client_call(qi_client_t *client, const char *method, qi_message_t *msg, qi_message_t *ret)
{
  client_private_t  *pclient  = (client_private_t *)client;
  message_private_t *preturn  = (message_private_t *)ret;
  message_private_t *pmessage = (message_private_t *)msg;

  pclient->client.call(std::string(method), pmessage->msg, preturn->msg);
}

qi_message_t *qi_message_create()
{
  message_private_t *pmsg = new message_private_t();
  return (qi_message_t *)pmsg;
}

void qi_message_write_int(qi_message_t *msg, const int i)
{
  message_private_t *pmsg = (message_private_t *)msg;
  pmsg->msg.writeInt(i);
}

void qi_message_write_string(qi_message_t *msg, const char *s)
{
  message_private_t *pmsg = (message_private_t *)msg;
  pmsg->msg.writeString(std::string(s));
}

int qi_message_read_int(qi_message_t *msg)
{
  message_private_t *pmsg = (message_private_t *)msg;
  int i;
  pmsg->msg.readInt(i);
  return i;
}

char *qi_message_read_string(qi_message_t *msg)
{
 message_private_t *pmsg = (message_private_t *)msg;
 std::string s;
 pmsg->msg.readString(s);
 //TODO: buffer overflow
 return strdup(s.c_str());
}
{'fraction_non_alphanumeric': 0.125948406676783, 'fraction_numerical': 0.011760242792109257, 'mean_word_length': 5.026285714285715, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2325265', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1814, 'n_words': 521}