libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
servicedirectoryproxy.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2018 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QIMESSAGING_SERVICEDIRECTORYPROXY_HPP_
8 #define _QIMESSAGING_SERVICEDIRECTORYPROXY_HPP_
9 
10 #include <boost/optional.hpp>
11 #include <boost/shared_ptr.hpp>
12 #include <boost/utility/string_ref.hpp>
13 
14 #include <ka/functional.hpp>
15 #include <qi/anyobject.hpp> // for circular dependency with signal.hpp
16 #include <qi/anyvalue.hpp>
17 #include <qi/api.hpp>
18 #include <qi/future.hpp>
19 #include <qi/property.hpp>
20 #include <qi/signal.hpp>
21 #include <qi/url.hpp>
22 
23 namespace qi
24 {
25 class AuthProviderFactory;
26 using AuthProviderFactoryPtr = boost::shared_ptr<AuthProviderFactory>;
27 class ClientAuthenticatorFactory;
28 using ClientAuthenticatorFactoryPtr = boost::shared_ptr<ClientAuthenticatorFactory>;
29 
51 {
52  class Impl;
53  std::unique_ptr<Impl> _p; // must be declared before any other member
54 public:
55  enum class IdValidationStatus
56  {
57  Done,
58  PendingCheckOnListen,
59  };
60 
61  enum class ListenStatus
62  {
63  NotListening,
64  Listening,
65  Starting,
66  PendingConnection,
67  };
69 
70  enum class ConnectionStatus
71  {
72  NotConnected,
73  Connected,
74  Starting,
75  };
76 
77  using ServiceFilter = std::function<bool(boost::string_ref)>;
78 
79  struct Status
80  {
81  bool isReady() const
82  {
83  return connection == ConnectionStatus::Connected
84  && listen == ListenStatus::Listening;
85  }
86 
87  bool isConnected() const { return connection == ConnectionStatus::Connected; }
88  bool isListening() const { return listen == ListenStatus::Listening; }
89 
92  KA_GENERATE_FRIEND_REGULAR_OPS_2(Status, connection, listen);
93  };
94 
95 
100  ServiceDirectoryProxy(bool enforceAuth = true);
102 
103  QI_API_DEPRECATED_MSG("Use `status` instead.")
104  Property<bool>& connected;
105 
106  Property<Status>& status;
107 
108  UrlVector endpoints() const;
109 
110  Future<ListenStatus> listenAsync(const Url& url);
111 
112  Future<IdValidationStatus> setValidateIdentity(const std::string& key, const std::string& crt);
113 
114  void setAuthProviderFactory(AuthProviderFactoryPtr provider);
115  qi::Future<void> attachToServiceDirectory(const Url& serviceDirectoryUrl);
116  void close();
117 
122  Future<ServiceFilter> setServiceFilter(ServiceFilter filter
123  = ka::constant_function(false));
124 };
125 
126 QI_API std::ostream& operator<<(std::ostream&, ServiceDirectoryProxy::IdValidationStatus);
127 QI_API std::ostream& operator<<(std::ostream&, ServiceDirectoryProxy::ListenStatus);
128 QI_API std::ostream& operator<<(std::ostream&, ServiceDirectoryProxy::ConnectionStatus);
129 
130 }
131 
132 #endif // _QIMESSAGING_SERVICEDIRECTORYPROXY_HPP_
#define QI_API
Definition: api.hpp:33
std::function< bool(boost::string_ref)> ServiceFilter
dll import/export and compiler message
boost::shared_ptr< AuthProviderFactory > AuthProviderFactoryPtr
boost::shared_ptr< ClientAuthenticatorFactory > ClientAuthenticatorFactoryPtr
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:55
std::vector< Url > UrlVector
Definition: url.hpp:155
Definition: url.hpp:35