<commit_before>#pragma once
/*
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010 Aldebaran Robotics
*/
#ifndef   __QI_MESSAGING_DETAIL_MASTER_IMPL_HPP__
#define   __QI_MESSAGING_DETAIL_MASTER_IMPL_HPP__

#include <string>
#include <qi/messaging/detail/server_impl.hpp>
#include <qi/messaging/detail/mutexednamelookup.hpp>
#include <qi/messaging/detail/address_manager.hpp>
#include <qi/messaging/context.hpp>
#include <qi/transport/detail/network/endpoint_context.hpp>
#include <qi/transport/detail/network/machine_context.hpp>

namespace qi {
  namespace detail {

    class MasterImpl {
    public:
      explicit MasterImpl(const std::string& masterAddress);

      ~MasterImpl();

      void registerService(const std::string& methodSignature,
                           const std::string& serverID);

      void registerMachine(const std::string& hostName,
                           const std::string& machineID,
                           const std::string& publicIPAddress,
                           const int&         platformID);

      void registerServer(const std::string& name,
                          const std::string& endpointID,
                          const std::string& contextID,
                          const std::string& machineID,
                          const int& port);

      void unregisterServer(const std::string& id);

      void registerClient(const std::string& name,
                          const std::string& clientID,
                          const std::string& contextID,
                          const std::string& machineID);

      void unregisterClient(const std::string& id);

      std::string locateService(const std::string& methodSignature, const std::string& clientID);

      const std::map<std::string, std::string>& listServices();

      bool isInitialized() const;

    private:
      std::string _name;
      std::string _address;
      ServerImpl  _server;

      void xInit();
      void xRegisterServer(const EndpointContext& endpoint);
      void xRegisterMachine(const MachineContext& machine);

      // Helper method
      template <typename OBJECT_TYPE, typename METHOD_TYPE>
      void xAddMasterMethod(
        const std::string& endpointID,
        const std::string& methodName,
        OBJECT_TYPE obj,
        METHOD_TYPE method)
      {
        std::string signature = makeSignature(methodName, method);
        _server.addService(signature, makeFunctor(obj, method));
        registerService(signature, endpointID);
      }

      // map from methodSignature to nodeAddress
      MutexedNameLookup<std::string> _knownServices;

      // map from id to EndpointContext
      MutexedNameLookup<qi::detail::EndpointContext> _knownServers;

      // map from id to EndpointContext
      MutexedNameLookup<qi::detail::EndpointContext> _knownClients;

      // map from id to MachineContext
      MutexedNameLookup<qi::detail::MachineContext> _knownMachines;

      AddressManager _addressManager;
    };
  }
}

#endif // __QI_MESSAGING_DETAIL_MASTER_IMPL_HPP__
<commit_msg>Lookups on the master for publishers, subscribers and topics<commit_after>#pragma once
/*
** Author(s):
**  - <NAME> <<EMAIL>>
**
** Copyright (C) 2010 Aldebaran Robotics
*/
#ifndef   __QI_MESSAGING_DETAIL_MASTER_IMPL_HPP__
#define   __QI_MESSAGING_DETAIL_MASTER_IMPL_HPP__

#include <string>
#include <qi/messaging/detail/server_impl.hpp>
#include <qi/messaging/detail/mutexednamelookup.hpp>
#include <qi/messaging/detail/address_manager.hpp>
#include <qi/messaging/detail/topic_info.hpp>
#include <qi/messaging/context.hpp>
#include <qi/transport/detail/network/endpoint_context.hpp>
#include <qi/transport/detail/network/machine_context.hpp>

namespace qi {
  namespace detail {
    class MasterImpl {
    public:
      explicit MasterImpl(const std::string& masterAddress);

      ~MasterImpl();

      void registerService(const std::string& methodSignature,
                           const std::string& serverID);

      void registerMachine(const std::string& hostName,
                           const std::string& machineID,
                           const std::string& publicIPAddress,
                           const int&         platformID);

      void registerServer(const std::string& name,
                          const std::string& endpointID,
                          const std::string& contextID,
                          const std::string& machineID,
                          const int& port);

      void unregisterServer(const std::string& id);

      void registerClient(const std::string& name,
                          const std::string& clientID,
                          const std::string& contextID,
                          const std::string& machineID);

      void unregisterClient(const std::string& id);

      std::string locateService(const std::string& methodSignature, const std::string& clientID);

      const std::map<std::string, std::string>& listServices();

      bool isInitialized() const;

    private:
      std::string _name;
      std::string _address;
      ServerImpl  _server;

      void xInit();
      void xRegisterServer(const EndpointContext& endpoint);
      void xRegisterMachine(const MachineContext& machine);

      // Helper method
      template <typename OBJECT_TYPE, typename METHOD_TYPE>
      void xAddMasterMethod(
        const std::string& endpointID,
        const std::string& methodName,
        OBJECT_TYPE obj,
        METHOD_TYPE method)
      {
        std::string signature = makeSignature(methodName, method);
        _server.addService(signature, makeFunctor(obj, method));
        registerService(signature, endpointID);
      }

      // map from methodSignature to nodeAddress
      MutexedNameLookup<std::string> _knownServices;

      // map from id to EndpointContext
      MutexedNameLookup<qi::detail::EndpointContext> _knownServers;

      // map from id to EndpointContext
      MutexedNameLookup<qi::detail::EndpointContext> _knownClients;

      // map from id to MachineContext
      MutexedNameLookup<qi::detail::MachineContext> _knownMachines;

      // map from id to EndpointContext
      MutexedNameLookup<qi::detail::EndpointContext> _knownPublishers;

      // map from id to EndpointContext
      MutexedNameLookup<qi::detail::EndpointContext> _knownSubscribers;

      // map from id to EndpointContext
      MutexedNameLookup<qi::detail::TopicInfo>       _knownTopics;

      AddressManager _addressManager;
    };
  }
}

#endif // __QI_MESSAGING_DETAIL_MASTER_IMPL_HPP__

{'fraction_non_alphanumeric': 0.09448939093268204, 'fraction_numerical': 0.00122118760494581, 'mean_word_length': 2.7079796264855687, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, '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': '6183411', 'n_tokens_mistral': 1875, 'n_tokens_neox': 1763, 'n_words': 407}