<commit_before>/*
*  Author(s):
*  - <NAME> <<EMAIL>>
*  - <NAME> <<EMAIL>>
*
*  Copyright (C) 2010 Aldebaran Robotics
*/

#include <qimessaging/object.hpp>
#include <qimessaging/server.hpp>
#include <qimessaging/transport/transport_server.hpp>
#include <qimessaging/transport/network_thread.hpp>

namespace qi {

  class ServerPrivate {
  public:
    std::map<std::string, qi::Object*> _services;
    TransportServer                    _ts;
  };

  Server::Server()
    : _p(new ServerPrivate())
  {
//    _p->_ts.setDelegate(this);
  }

  Server::~Server()
  {
    delete _p;
  }


  void Server::start(const std::string &addr, unsigned short port, qi::NetworkThread *base) {

    _p->_ts.start(addr, port, base->getEventBase());
  };

  void Server::advertiseService(const std::string &name, qi::Object *obj) {
    _p->_services[name] = obj;
  };

  void Server::onConnected(const qi::Message &msg) {
  };

  void Server::onWrite(const qi::Message &msg) {

  };

  void Server::onRead(const qi::Message &msg) {
    qi::Object *obj;

    obj = _p->_services[msg.destination()];
    qi::DataStream ds(msg.data());
    qi::DataStream rs;

    obj->metaCall(msg.path(), "", ds, rs);

    qi::Message retval;
    retval.setType(qi::Message::Answer);
    retval.setId(msg.id());
    retval.setSource(msg.destination());
    retval.setDestination(msg.source());
    retval.setPath(msg.path());
    retval.setData(rs.str());
    //_p->_ts.send(retval);
  };

}<commit_msg>server: use new TransportSocketInterface<commit_after>/*
*  Author(s):
*  - <NAME> <<EMAIL>>
*  - <NAME> <<EMAIL>>
*
*  Copyright (C) 2010 Aldebaran Robotics
*/

#include <qimessaging/object.hpp>
#include <qimessaging/server.hpp>
#include <qimessaging/transport/transport_server.hpp>
#include <qimessaging/transport/network_thread.hpp>

namespace qi {

  class ServerPrivate : public TransportServerInterface, public TransportSocketInterface {
  public:

    virtual void newConnection() {
      TransportSocket *socket = _ts.nextPendingConnection();
      if (!socket)
        return;
      socket->setDelegate(this);
    };

    virtual void onRead(TransportSocket *client, const qi::Message &msg) {
      qi::Object *obj;

      obj = _services[msg.destination()];
      qi::DataStream ds(msg.data());
      qi::DataStream rs;

      obj->metaCall(msg.path(), "", ds, rs);

      qi::Message retval;
      retval.setType(qi::Message::Answer);
      retval.setId(msg.id());
      retval.setSource(msg.destination());
      retval.setDestination(msg.source());
      retval.setPath(msg.path());
      retval.setData(rs.str());
      client->send(retval);
    };

    virtual void onWrite(TransportSocket *client, const qi::Message &msg) {
    };

    virtual void onConnected(TransportSocket *client, const Message &msg)
    {
    }

    virtual void onDisconnected(TransportSocket *client, const Message &msg)
    {
    }

  public:
    std::map<std::string, qi::Object*> _services;
    TransportServer                    _ts;
  };

  Server::Server()
    : _p(new ServerPrivate())
  {
//    _p->_ts.setDelegate(this);
  }

  Server::~Server()
  {
    delete _p;
  }

  void Server::start(const std::string &addr, unsigned short port, qi::NetworkThread *base) {
    _p->_ts.setDelegate(_p);
    _p->_ts.start(addr, port, base->getEventBase());
  };

  void Server::advertiseService(const std::string &name, qi::Object *obj) {
    _p->_services[name] = obj;
  };

}
{'fraction_non_alphanumeric': 0.16341392368191088, 'fraction_numerical': 0.002330323332362365, 'mean_word_length': 3.4597402597402596, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 40, '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': '2478941', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1137, 'n_words': 211}