NymphRPC Remote Procedure Call Library
nymph_method.h
1 /*
2  nymph_method.h - header file for the NympRPC hMethod 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_METHOD_H
18 #define NYMPH_METHOD_H
19 
20 #include "nymph_types.h"
21 #include "nymph_listener.h"
22 #include "nymph_message.h"
23 #include "nymph_session.h"
24 
25 #include <Poco/Poco.h>
26 #include <Poco/Net/StreamSocket.h>
27 
28 #include <vector>
29 #include <string>
30 #include <functional>
31 
32 
33 class NymphRemoteClient;
34 
35 
36 //typedef NymphMessage* (*NymphMethodCallback)(int session, NymphMessage* msg, void* data);
37 typedef std::function<NymphMessage*(int, NymphMessage*, void*)> NymphMethodCallback;
38 
39 
40 class NymphMethod {
41  friend class NymphRemoteClient;
42  friend class NymphRemoteServer;
43 
44  std::string name;
45  uint32_t id;
46  std::vector<NymphTypes> parameters;
47  NymphMethodCallback callback;
48  NymphTypes returnType;
49  std::string loggerName;
50  std::string serialized;
51  bool isCallback;
52 
53  void setId(uint32_t id);
54 
55 public:
56  NymphMethod(std::string name, std::vector<NymphTypes> parameters, NymphTypes retType);
57  void setCallback(NymphMethodCallback callback);
58  NymphMessage* callCallback(int handle, NymphMessage* msg);
59  bool call(Poco::Net::StreamSocket* socket, NymphRequest* &request, std::vector<NymphType*> &values, std::string &result);
60  bool call(NymphSession* session, std::vector<NymphType*> &values, std::string &result);
61  uint32_t getId() { return id; }
62  std::string getSerialized() { return serialized; }
63  bool enableCallback(bool state = true) { isCallback = state; return true; }
64 };
65 
66 #endif
Definition: nymph_message.h:38
Definition: nymph_method.h:40
Definition: remote_client.h:33
Definition: remote_server.h:31
Definition: nymph_session.h:26
Definition: nymph_socket_listener.h:40