NymphRPC Remote Procedure Call Library
nymph_listener.h
1 /*
2  nymph_listener.h - Declares the NymphRPC Listener class.
3 
4  Revision 0
5 
6  Notes:
7  -
8 
9  History:
10  2017/06/24, Maya Posch : Initial version.
11 
12  (c) Nyanko.ws
13 */
14 
15 
16 #pragma once
17 #ifndef NYMPH_LISTENER_H
18 #define NYMPH_LISTENER_H
19 
20 
21 #include <vector>
22 #include <string>
23 #include <functional>
24 
25 #include <Poco/Mutex.h>
26 
27 #include "nymph_socket_listener.h"
28 
29 
30 // TYPES
31 
32 //typedef void (*NymphCallbackMethod)(uint32_t session, NymphMessage* msg, void* data);
33 typedef std::function<void(uint32_t, NymphMessage*, void*)> NymphCallbackMethod;
34 
35 
36 struct NymphCallback {
37  std::string name; // Callback method name.
38  NymphCallbackMethod method; // The callback.
39  void* data; // Custom user data.
40 };
41 
42 
43 // ---
44 
45 
47  static std::map<int, NymphSocketListener*> listeners;
48  static Poco::Mutex listenersMutex;
49  static std::string loggerName;
50 
51  static std::map<std::string, NymphCallback>& callbacks();
52  static Poco::Mutex& callbacksMutex();
53 
54 public:
55  static void stop();
56 
57  static bool addConnection(int handle, NymphSocket socket);
58  static bool removeConnection(int handle);
59  static bool addMessage(NymphRequest* &request);
60  static bool removeMessage(int handle, int64_t messageId);
61  static bool addCallback(NymphCallback callback);
62  static bool callCallback(uint32_t session, NymphMessage* msg, void* data);
63  static bool removeCallback(std::string name);
64 };
65 
66 #endif
Definition: nymph_listener.h:46
Definition: nymph_message.h:38
Definition: nymph_listener.h:36
Definition: nymph_socket_listener.h:40
Definition: nymph_socket_listener.h:32