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