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 std::string loggerName = "NymphServerInstance";
33 Poco::Net::StreamSocket* socket = 0;
34 Poco::Semaphore* socketSemaphore = 0;
35 uint32_t nextMethodId = 0;
36 std::map<std::string, NymphMethod> methods;
37 std::map<uint32_t, NymphMethod*> methodIds;
38 Poco::Mutex methodsMutex;
39 uint32_t handle;
40 uint32_t timeout;
41
42public:
43 NymphServerInstance(uint32_t handle, Poco::Net::StreamSocket* socket, uint32_t timeout = 3000);
45
46 void setHandle(uint32_t handle);
47 uint32_t getHandle();
48 Poco::Semaphore* semaphore();
49 bool sync(std::string &result);
50 bool addMethod(std::string name, NymphMethod method);
51 bool removeMethod(std::string name);
52 bool disconnect(std::string& result);
53 bool callMethod(std::string name, std::vector<NymphType*> &values,
54 NymphType* &returnvalue, std::string &result);
55 bool callMethodId(uint32_t id, std::vector<NymphType*> &values, NymphType* &returnvalue, std::string &result);
56};
57
58
60 static std::map<uint32_t, NymphServerInstance*> instances;
61 static Poco::Mutex instancesMutex;
62 static uint32_t lastHandle;
63 static long timeout;
64 static std::string loggerName;
65 static uint32_t nextMethodId;
66
67public:
68 static bool init(logFnc logger, int level = NYMPH_LOG_LEVEL_TRACE, long timeout = 3000);
69 static void setLogger(logFnc logger, int level);
70 static bool shutdown();
71 static bool connect(std::string host, int port, uint32_t &handle, void* data, std::string &result);
72 static bool connect(std::string url, uint32_t &handle, void* data, std::string &result);
73 static bool connect(Poco::Net::SocketAddress sa, uint32_t &handle, void* data, std::string &result);
74 static bool disconnect(uint32_t handle, std::string &result);
75 static bool callMethod(uint32_t handle, std::string name, std::vector<NymphType*> &values,
76 NymphType* &returnvalue, std::string &result);
77 static bool callMethodId(uint32_t handle, uint32_t id, std::vector<NymphType*> &values, NymphType* &returnvalue, std::string &result);
78 static bool removeMethod(uint32_t handle, std::string name);
79
80 static bool registerCallback(std::string name, NymphCallbackMethod method, void* data);
81 static bool removeCallback(std::string name);
82};
83
84#endif
Definition: nymph_method.h:39
Definition: remote_server.h:59
Definition: remote_server.h:31
Definition: nymph_types.h:85