<commit_before>/*
** network_client.hpp
** Login : <<EMAIL>>
** Started on  Thu Feb  2 11:59:48 2012 <NAME>
** $Id$
**
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2012 <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
*/

#ifndef   	NETWORK_CLIENT_HPP_
# define   	NETWORK_CLIENT_HPP_

#include <qimessaging/transport/transport_socket.hpp>
#include <qimessaging/datastream.hpp>

#include <vector>
#include <string>

namespace qi {

  class NetworkThread;
  class Object;

  class MachineInfo {
  public:
    std::string uuid;
  };

  class EndpointInfo {
  public:
    int port;
    std::string  ip;
    std::string  type;

    bool operator==(const EndpointInfo &b) const
    {
      if (port == b.port &&
          ip == b.ip &&
          type == b.type)
        return true;

      return false;
    }

  };

  static DataStream& operator<<(DataStream &d, const EndpointInfo &e)
  {
    d << e.ip;
    d << e.port;
    d << e.type;

    return d;
  }

  static DataStream& operator>>(DataStream &d, EndpointInfo &e)
  {
    d >> e.ip;
    d >> e.port;
    d >> e.type;

    return d;
  }

  class ServiceInfo {
  public:
    std::string name;
    std::vector<qi::EndpointInfo> endpoint;
  };


  class Session : public qi::TransportSocketInterface {
  public:
    Session();
    virtual ~Session();

    void onConnected(TransportSocket *client);
    void onDisconnected(TransportSocket *client);
    void onWriteDone(TransportSocket *client);
    void onReadyRead(TransportSocket *client, const qi::Message &msg);


    void connect(const std::string &masterAddress);
    bool disconnect();

    bool waitForConnected(int msecs = 30000);
    bool waitForDisconnected(int msecs = 30000);

    void registerMachine(const qi::MachineInfo& m);
    void unregisterMachine(const qi::MachineInfo& m);

    void registerEndpoint(const std::string &e);
    void unregisterEndpoint(const std::string &e);

    std::vector<std::string> machines();
    std::vector<std::string> services();

    qi::TransportSocket* serviceSocket(const std::string &name,
                                       const std::string &type = "tcp");

    qi::Object* service(const std::string &name,
                        const std::string &type = "tcp");

    bool isInitialized() const;

    qi::TransportSocket *tc;
    qi::NetworkThread   *_nthd;

  protected:
    std::string _destination;
    std::string _name;
    bool                 _isInitialized;
  };
}


#endif	    /* !NETWORK_CLIENT_PP_ */
<commit_msg>Remove leftover from previous commit.<commit_after>/*
** network_client.hpp
** Login : <<EMAIL>>
** Started on  Thu Feb  2 11:59:48 2012 <NAME>
** $Id$
**
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2012 <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
*/

#ifndef   	NETWORK_CLIENT_HPP_
# define   	NETWORK_CLIENT_HPP_

#include <qimessaging/transport/transport_socket.hpp>
#include <qimessaging/datastream.hpp>

#include <vector>
#include <string>

namespace qi {

  class NetworkThread;
  class Object;

  class MachineInfo {
  public:
    std::string uuid;
  };

  class EndpointInfo {
  public:
    int port;
    std::string  ip;
    std::string  type;

    bool operator==(const EndpointInfo &b) const
    {
      if (port == b.port &&
          ip == b.ip &&
          type == b.type)
        return true;

      return false;
    }

  };

  static DataStream& operator<<(DataStream &d, const EndpointInfo &e)
  {
    d << e.ip;
    d << e.port;
    d << e.type;

    return d;
  }

  static DataStream& operator>>(DataStream &d, EndpointInfo &e)
  {
    d >> e.ip;
    d >> e.port;
    d >> e.type;

    return d;
  }

  class ServiceInfo {
  public:
    std::string name;
    std::vector<qi::EndpointInfo> endpoint;
  };


  class Session : public qi::TransportSocketInterface {
  public:
    Session();
    virtual ~Session();

    void onConnected(TransportSocket *client);
    void onDisconnected(TransportSocket *client);
    void onWriteDone(TransportSocket *client);
    void onReadyRead(TransportSocket *client, const qi::Message &msg);


    void connect(const std::string &masterAddress);
    bool disconnect();

    bool waitForConnected(int msecs = 30000);
    bool waitForDisconnected(int msecs = 30000);

    void registerMachine(const qi::MachineInfo& m);
    void unregisterMachine(const qi::MachineInfo& m);

    void registerEndpoint(const std::string &e);
    void unregisterEndpoint(const std::string &e);

    std::vector<std::string> machines();
    std::vector<std::string> services();

    qi::TransportSocket* serviceSocket(const std::string &name,
                                       const std::string &type = "tcp");

    qi::Object* service(const std::string &name,
                        const std::string &type = "tcp");

    qi::TransportSocket *tc;
    qi::NetworkThread   *_nthd;

  protected:
    std::string _destination;
    std::string _name;
    bool                 _isInitialized;
  };
}


#endif	    /* !NETWORK_CLIENT_PP_ */

{'fraction_non_alphanumeric': 0.11720107407992418, 'fraction_numerical': 0.01263623440214816, 'mean_word_length': 3.138562091503268, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1995400', 'n_tokens_mistral': 2015, 'n_tokens_neox': 1886, 'n_words': 613}