NymphRPC Remote Procedure Call Library
remote_server.h
1 /*
2  remote_server.h - header file for the Remote Server class.
3 
4  Revision 0
5 
6  Notes:
7  - This class declares the main class to be used by NymphRPC clients.
8 
9  2017/06/24, Maya Posch : Initial version.
10  (c) Nyanko.ws
11 */
12 
13 
14 #ifndef REMOTE_SERVER_H
15 #define REMOTE_SERVER_H
16 
17 
18 #include <vector>
19 #include <string>
20 #include <map>
21 
22 #include <Poco/Semaphore.h>
23 #include <Poco/Net/SocketAddress.h>
24 #include <Poco/Net/StreamSocket.h>
25 
26 #include "nymph_method.h"
27 #include "nymph_listener.h"
28 #include "nymph_logger.h"
29 
30 
32  static std::map<uint32_t, Poco::Net::StreamSocket*> sockets;
33  static std::map<uint32_t, Poco::Semaphore*> socketSemaphores;
34  static Poco::Mutex socketsMutex;
35  static uint32_t lastHandle;
36  static long timeout;
37  static std::string loggerName;
38  static uint32_t nextMethodId;
39 
40  static std::map<std::string, NymphMethod>& methods();
41  static std::map<uint32_t, NymphMethod*>& methodsIds();
42  static Poco::Mutex& methodsMutex();
43 
44  static bool registerMethod(std::string name, NymphMethod method);
45 
46 public:
47  static bool init(logFnc logger, int level = NYMPH_LOG_LEVEL_TRACE, long timeout = 3000);
48  static bool sync(uint32_t handle, std::string &result);
49  static void setLogger(logFnc logger, int level);
50  static bool shutdown();
51  static bool connect(std::string host, int port, uint32_t &handle, void* data, std::string &result);
52  static bool connect(std::string url, uint32_t &handle, void* data, std::string &result);
53  static bool connect(Poco::Net::SocketAddress sa, uint32_t &handle, void* data, std::string &result);
54  static bool disconnect(uint32_t handle, std::string &result);
55  static bool callMethod(uint32_t handle, std::string name, std::vector<NymphType*> &values,
56  NymphType* &returnvalue, std::string &result);
57  static bool callMethodId(uint32_t handle, uint32_t id, std::vector<NymphType*> &values, NymphType* &returnvalue, std::string &result);
58  static bool removeMethod(std::string name);
59 
60  static bool registerCallback(std::string name, NymphCallbackMethod method, void* data);
61  static bool removeCallback(std::string name);
62 };
63 
64 #endif
Definition: nymph_method.h:40
Definition: remote_server.h:31
Definition: nymph_types.h:133