NymphRPC Remote Procedure Call Library
nymph_socket_listener.h
1 /*
2  nymph_socket_listener.h - Declares the NymphRPC Socket 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_SOCKET_LISTENER_H
18 #define NYMPH_SOCKET_LISTENER_H
19 
20 #include "nymph_message.h"
21 
22 #include <Poco/Runnable.h>
23 #include <Poco/Net/StreamSocket.h>
24 #include <Poco/Semaphore.h>
25 #include <Poco/Condition.h>
26 
27 #include <map>
28 #include <string>
29 
30 // TYPES
31 
32 struct NymphSocket {
33  Poco::Net::StreamSocket* socket; // Pointer to the socket instance.
34  Poco::Semaphore* semaphore; // Signals when it's safe to delete the socket.
35  void* data; // User data.
36  uint32_t handle; // The Nymph internal socket handle.
37 };
38 
39 
40 struct NymphRequest {
41  int handle;
42  uint64_t messageId;
43  Poco::Mutex mutex;
44  Poco::Condition condition;
45  NymphType* response;
46  bool exception;
47  NymphException exceptionData;
48 };
49 
50 // ---
51 
52 
53 class NymphSocketListener : public Poco::Runnable {
54  std::string loggerName;
55  bool listen;
56  NymphSocket nymphSocket;
57  Poco::Net::StreamSocket* socket;
58  std::map<uint64_t, NymphRequest*> messages;
59  Poco::Mutex messagesMutex;
60  bool init;
61  Poco::Condition* readyCond;
62  Poco::Mutex* readyMutex;
63 
64 public:
65  NymphSocketListener(NymphSocket socket, Poco::Condition* cond, Poco::Mutex* mtx);
67  void run();
68  void stop();
69  bool addMessage(NymphRequest* &request);
70  bool removeMessage(uint64_t messageId);
71 };
72 
73 #endif
Definition: nymph_socket_listener.h:53
Definition: nymph_types.h:133
Definition: nymph_message.h:32
Definition: nymph_socket_listener.h:40
Definition: nymph_socket_listener.h:32