NymphRPC Remote Procedure Call Library
remote_client.h
1/*
2 remote_client.h - header file for the NymphRPC Remote Client class.
3
4 Revision 0
5
6 Notes:
7 - This class declares the main class to be used by Nymph servers.
8
9 2017/06/24, Maya Posch : Initial version.
10 (c) Nyanko.ws
11*/
12
13
14#pragma once
15#ifndef NYMPH_REMOTE_CLIENT_H
16#define NYMPH_REMOTE_CLIENT_H
17
18
19#include <vector>
20#include <string>
21#include <map>
22
23#include <Poco/Mutex.h>
24#include <Poco/Net/SocketAddress.h>
25#include <Poco/Net/StreamSocket.h>
26
27#include "nymph_method.h"
28#include "nymph_listener.h"
29#include "nymph_logger.h"
30#include "nymph_session.h"
31
32
34 static Poco::Mutex methodsMutex;
35 static Poco::Mutex callbacksMutex;
36 static Poco::Mutex sessionsMutex;
37 static std::map<int, NymphSession*> sessions;
38 static long timeout;
39 static std::string loggerName;
40 static bool synced;
41 static std::string serializedMethods;
42 static uint32_t nextMethodId;
43
44 static std::map<std::string, NymphMethod>& callbacks();
45 static std::map<std::string, NymphMethod>& methods();
46 static std::map<uint32_t, NymphMethod*>& methodsIds();
47
48 static NymphMessage* syncMethods(int session, NymphMessage* msg, void* data);
49
50public:
51 static bool init(logFnc logger, int level = NYMPH_LOG_LEVEL_TRACE, long timeout = 3000);
52 static void setLogger(logFnc logger, int level);
53 static bool start(int port = 4004);
54 static bool shutdown();
55 static bool registerMethod(std::string name, NymphMethod method);
56 static bool callMethodCallback(int handle, uint32_t methodId, NymphMessage* msg, NymphMessage* &response);
57 static bool removeMethod(std::string name);
58
59 static bool registerCallback(std::string name, NymphMethod method);
60 static bool callCallback(int handle, std::string name,
61 std::vector<NymphType*> &values, std::string &result);
62 static bool removeCallback(std::string name);
63
64 static bool addSession(int handle, NymphSession* session);
65 static bool removeSession(int handle);
66};
67
68#endif
Definition: nymph_message.h:39
Definition: nymph_method.h:39
Definition: remote_client.h:33
Definition: nymph_session.h:26