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

#pragma once
#ifndef _QIMESSAGING_SESSION_HPP_
#define _QIMESSAGING_SESSION_HPP_

#include <qimessaging/api.hpp>
#include <qimessaging/transport_socket.hpp>
#include <qimessaging/service_info.hpp>
#include <qimessaging/future.hpp>
#include <qimessaging/object.hpp>

#include <vector>
#include <string>

namespace qi {

  class SessionPrivate;

  class QIMESSAGING_API SessionInterface
  {
  public:
    virtual ~SessionInterface() = 0;
    inline virtual void onSessionConnected(Session *QI_UNUSED(session), void *data)
    {
      qiLogVerbose("session.hpp") << "onSessionConnected not implemented";
    }

    inline virtual void onSessionConnectionError(Session *QI_UNUSED(session), void *data)
    {
      qiLogVerbose("session.hpp") << "onSessionConnectionError not implemented";
    }

    inline virtual void onSessionDisconnected(Session *QI_UNUSED(session), void *data)
    {
      qiLogVerbose("session.hpp") << "onSessionDisconnected not implemented";
    }

    inline virtual void onServiceRegistered(Session *QI_UNUSED(session),
                                            const std::string &QI_UNUSED(serviceName), void *data)
    {
      qiLogVerbose("session.hpp") << "onServiceRegistered not implemented";
    }

    inline virtual void onServiceUnregistered(Session *QI_UNUSED(session),
                                              const std::string &QI_UNUSED(serviceName), void *data)
    {
      qiLogVerbose("session.hpp") << "onServiceUnregistered not implemented";
    }
  };

  class QIMESSAGING_API Session {
  public:
    Session();
    virtual ~Session();

    enum ServiceLocality {
      ServiceLocality_All    = 0,
      ServiceLocality_Local  = 1,
      ServiceLocality_Remote = 2
    };

    void addCallbacks(SessionInterface *delegate, void *data);
    void removeCallbacks(SessionInterface *delegate);

    //Client
    bool connect(const qi::Url &serviceDirectoryURL);
    bool isConnected() const;
    qi::Url url() const;
    bool waitForConnected(int msecs = 30000);
    bool waitForDisconnected(int msecs = 30000);


    bool waitForServiceReady(const std::string &service, int msecs = 30000);

    qi::Future< std::vector<ServiceInfo> > services(ServiceLocality locality = ServiceLocality_All);

    qi::Future< qi::Object* > service(const std::string &service,
                                      ServiceLocality locality = ServiceLocality_All,
                                      const std::string &protocol  = std::string("any"));

    //Server
    bool    listen(const std::string &address);
    qi::Url listenUrl() const;

    //close both client and server side
    void    close();

    qi::Future<unsigned int> registerService(const std::string &name, qi::Object *object);
    qi::Future<void>         unregisterService(unsigned int idx);

<commit_msg>fix addcallback default argument<commit_after>/*
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2012 Aldebaran Robotics
*/

#pragma once
#ifndef _QIMESSAGING_SESSION_HPP_
#define _QIMESSAGING_SESSION_HPP_

#include <qimessaging/api.hpp>
#include <qimessaging/transport_socket.hpp>
#include <qimessaging/service_info.hpp>
#include <qimessaging/future.hpp>
#include <qimessaging/object.hpp>

#include <vector>
#include <string>

namespace qi {

  class SessionPrivate;

  class QIMESSAGING_API SessionInterface
  {
  public:
    virtual ~SessionInterface() = 0;
    inline virtual void onSessionConnected(Session *QI_UNUSED(session), void *data)
    {
      qiLogVerbose("session.hpp") << "onSessionConnected not implemented";
    }

    inline virtual void onSessionConnectionError(Session *QI_UNUSED(session), void *data)
    {
      qiLogVerbose("session.hpp") << "onSessionConnectionError not implemented";
    }

    inline virtual void onSessionDisconnected(Session *QI_UNUSED(session), void *data)
    {
      qiLogVerbose("session.hpp") << "onSessionDisconnected not implemented";
    }

    inline virtual void onServiceRegistered(Session *QI_UNUSED(session),
                                            const std::string &QI_UNUSED(serviceName), void *data)
    {
      qiLogVerbose("session.hpp") << "onServiceRegistered not implemented";
    }

    inline virtual void onServiceUnregistered(Session *QI_UNUSED(session),
                                              const std::string &QI_UNUSED(serviceName), void *data)
    {
      qiLogVerbose("session.hpp") << "onServiceUnregistered not implemented";
    }
  };

  class QIMESSAGING_API Session {
  public:
    Session();
    virtual ~Session();

    enum ServiceLocality {
      ServiceLocality_All    = 0,
      ServiceLocality_Local  = 1,
      ServiceLocality_Remote = 2
    };

    void addCallbacks(SessionInterface *delegate, void *data = 0);
    void removeCallbacks(SessionInterface *delegate);

    //Client
    bool connect(const qi::Url &serviceDirectoryURL);
    bool isConnected() const;
    qi::Url url() const;
    bool waitForConnected(int msecs = 30000);
    bool waitForDisconnected(int msecs = 30000);


    bool waitForServiceReady(const std::string &service, int msecs = 30000);

    qi::Future< std::vector<ServiceInfo> > services(ServiceLocality locality = ServiceLocality_All);

    qi::Future< qi::Object* > service(const std::string &service,
                                      ServiceLocality locality = ServiceLocality_All,
                                      const std::string &protocol  = std::string("any"));

    //Server
    bool    listen(const std::string &address);
    qi::Url listenUrl() const;

    //close both client and server side
    void    close();

    qi::Future<unsigned int> registerService(const std::string &name, qi::Object *object);
    qi::Future<void>         unregisterService(unsigned int idx);


{'fraction_non_alphanumeric': 0.10795551753635586, 'fraction_numerical': 0.008041060735671514, 'mean_word_length': 3.2859237536656893, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2873724', 'n_tokens_mistral': 1788, 'n_tokens_neox': 1673, 'n_words': 392}