Client.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <zeus/WebServer.hpp>
9 #include <eproperty/Value.hpp>
10 #include <zeus/debug.hpp>
11 #include <chrono>
12 
13 #include <zeus/Future.hpp>
14 #include <zeus/ServiceRemote.hpp>
15 
16 namespace zeus {
20  class Client : public eproperty::Interface {
21  friend class ServiceRemote;
22  public:
25  private:
26  ememory::SharedPtr<zeus::WebServer> m_interfaceClient;
27  public:
34  //Client(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken);
40  //Client(const std::string& _address, const std::string& _userPassword);
41  //Client(const std::string& _address);
42 
48  Client();
54  virtual ~Client();
55  protected:
60  bool connectTo(const std::string& _address);
61  public:
66  bool connect(const std::string& _address);
72  bool connect(const std::string& _address, const std::string& _userPassword);
79  bool connect(const std::string& _address, const std::string& _clientName, const std::string& _clientTocken);
83  void disconnect();
84  public:
90  zeus::ServiceRemote getService(const std::string& _serviceName);
91  private:
96  void onClientData(ememory::SharedPtr<zeus::Buffer> _value);
97  public:
104  template<class... _ARGS>
105  zeus::FutureBase call(const std::string& _functionName, _ARGS&&... _args) {
106  if (m_interfaceClient == nullptr) {
108  ret->addError("NULLPTR", "call " + _functionName + " with no interface open");
109  return zeus::FutureBase(0, ret);
110  }
111  return m_interfaceClient->call(_functionName, _args...);
112  }
120  template<class... _ARGS>
121  zeus::FutureBase callAction(const std::string& _functionName, _ARGS&&... _args, zeus::FutureData::ObserverFinish _callback) {
122  if (m_interfaceClient == nullptr) {
124  ret->addError("NULLPTR", "call " + _functionName + " with no interface open");
125  return zeus::FutureBase(0, ret, _callback);
126  }
127  return m_interfaceClient->callAction(_functionName, _args..., _callback);
128  }
129  private:
133  void onPropertyChangeIp();
137  void onPropertyChangePort();
138  };
139 }
140 
std::function< bool(zeus::FutureBase)> ObserverFinish
Define an Observer: function pointer.
Definition: FutureData.hpp:21
void disconnect()
Disconnect of the current interface.
Definition: ServiceRemote.hpp:22
zeus::FutureBase callAction(const std::string &_functionName, _ARGS &&... _args, zeus::FutureData::ObserverFinish _callback)
Definition: WebServer.hpp:258
bool connectTo(const std::string &_address)
Connetc to a remote extern server.
eproperty::Value< uint16_t > propertyPort
Port of the WebSocket connection.
Definition: Client.hpp:24
static ememory::SharedPtr< zeus::BufferAnswer > create()
Create a shared pointer on the BufferAnswer.
Generic zeus Future interface to get data asynchronously.
Definition: FutureBase.hpp:14
zeus::FutureBase call(const std::string &_functionName, _ARGS &&... _args)
Definition: WebServer.hpp:247
void addError(const std::string &_value, const std::string &_comment)
Ann an error on the message answer.
Client()
Create a client on a specific user in a client mode with the tocken associated.
Client interface to acces on the remote service and gateway.
Definition: Client.hpp:20
zeus::FutureBase callAction(const std::string &_functionName, _ARGS &&... _args, zeus::FutureData::ObserverFinish _callback)
Create a call on the interface gateway.
Definition: Client.hpp:121
zeus::ServiceRemote getService(const std::string &_serviceName)
Get a remote service.
bool connect(const std::string &_address)
Create a client on a specific user in an ANONIMOUS way.
Main zeus library namespace.
Definition: AbstractFunction.hpp:15
virtual ~Client()
zeus::FutureBase call(const std::string &_functionName, _ARGS &&... _args)
Create a call on the interface gateway.
Definition: Client.hpp:105
eproperty::Value< std::string > propertyIp
Ip of WebSocket TCP connection.
Definition: Client.hpp:23