NymphRPC Remote Procedure Call Library
nymph_message.h
1/*
2 nymph_message.h - Declares the NymphRPC Message class.
3
4 Revision 0
5
6 Notes:
7 -
8
9 2017/06/24, Maya Posch : Initial version.
10 (c) Nyanko.ws
11*/
12
13
14#pragma once
15#ifndef NYMPH_MESSAGE_H
16#define NYMPH_MESSAGE_H
17
18#include "nymph_types.h"
19
20#include <Poco/Poco.h>
21
22#include <vector>
23#include <atomic>
24
25
26enum {
27 NYMPH_MESSAGE_REPLY = 0x01, // Message is a reply.
28 NYMPH_MESSAGE_EXCEPTION = 0x02, // Message is an exception.
29 NYMPH_MESSAGE_CALLBACK = 0x04 // Message is a callback.
30};
31
32
34 uint32_t id;
35 std::string value;
36};
37
38
40 std::vector<NymphType*> values;
41 uint32_t command;
42 uint32_t flags;
43 uint32_t methodId;
44 int state;
45 bool corrupt;
46 uint64_t messageId;
47 uint64_t responseId;
48 NymphException exception;
49 bool hasResult;
50 std::string callbackName;
51 NymphType* response = 0;
52 std::string loggerName;
53 uint8_t* data_buffer;
54 uint32_t buffer_length;
55 bool responseOwned = true;
56 std::atomic<uint32_t> refCount = { 0 };
57 std::atomic<bool> deleted = { false };
58
59public:
61 NymphMessage(uint32_t methodId);
62 NymphMessage(uint8_t* binmsg, uint64_t bytes);
64 bool addValue(NymphType* value);
65 bool addValues(std::vector<NymphType*> &values);
66
67 void serialize();
68 uint8_t* buffer() { return data_buffer; }
69 uint32_t buffer_size() { return buffer_length; }
70
71 int getState() { return state; }
72 bool isCorrupt() { return corrupt; }
73
74 void setInReplyTo(uint64_t msgId);
75 bool isCallback() { return flags & NYMPH_MESSAGE_CALLBACK; }
76 uint64_t getResponseId() { return responseId; }
77 uint64_t getMessageId() { return messageId; }
78 void setResultValue(NymphType* value);
79 NymphType* getResponse(bool take = false) { responseOwned = take; return response; }
80 std::vector<NymphType*>& parameters() { return values; }
81 uint32_t getMethodId() { return methodId; }
82 NymphMessage* getReplyMessage();
83 NymphException getException() { return exception; }
84 std::string getCallbackName() { return callbackName; }
85 bool isReply() { return flags & NYMPH_MESSAGE_REPLY; }
86 bool isException() { return flags & NYMPH_MESSAGE_EXCEPTION; }
87 bool setException(int exceptionId, std::string value);
88 bool setCallback(std::string name);
89
90 void addReferenceCount();
91 void decrementReferenceCount();
92 void discard();
93};
94
95#endif
Definition: nymph_message.h:39
Definition: nymph_types.h:85
Definition: nymph_message.h:33