#ifndef INCLUDE_DI_RPC_MSG_H_ #define INCLUDE_DI_RPC_MSG_H_ #include #include #include #include #include #include namespace Di { namespace Rpc { #define DiRpcMsgCallbackClass(callback, classCtx) \ std::bind(&callback, classCtx, std::placeholders::_1, std::placeholders::_2) #define DiRpcMsgCallback(callback) \ std::bind(reinterpret_cast *)>(&callback), \ std::placeholders::_1, std::placeholders::_2) class Msg { public: enum Type : unsigned int { UNKNOWN = 0, REQUEST = 1, REPLY = 2, PUBLISH = 3 }; typedef std::function *data)> Callback; Msg(void); explicit Msg(const std::shared_ptr &msg); virtual ~Msg(void); unsigned int getRpcVersion(); /**< RPC version */ uint32_t getId(); /**< Message identifier */ uint64_t getTime(); /**< DI-Net time */ std::string getDeviceUid(); /**< Device unique identifier */ uint32_t getProjectId(); /**< Project identifier */ uint32_t getUserId(); /**< Get user id */ Type getMsgType(); /**< Message type */ std::string getClass(); /**< Message class */ std::string getMethod(); /**< Message method */ std::string getClassMethod(); /** Method to receive [:] */ std::shared_ptr getData(); /**< JSON object of this message */ void setQueueReply(); bool isAsyncQueueRequest(); bool isAsyncStatusRequest(); bool hasError(); di_errno_t getError(); bool hasCallback(void); di_errno_t runCallback(void); di_errno_t runCallback(std::shared_ptr *data); void setCallback(const Callback callback); std::string getMsgTypeString(); bool decodeHeader(const std::shared_ptr &msg); virtual std::shared_ptr serialize(); bool hasDecodeError(void); protected: enum { SYNC, ASYNC_QUEUE, ASYNC_STATUS } _commType; unsigned int _rpcVersion; /**< RPC version */ uint32_t _id; /**< Message identifier */ uint64_t _time; /**< DI-Net time */ std::string _deviceUid; /**< Device unique identifier */ uint32_t _projectId; /**< Project identifier */ uint32_t _userId; /**< User identifier */ Type _msgType; /**< Message type */ std::string _class; /**< Message class */ std::string _method; /**< Message method */ std::shared_ptr _data; di_errno_t _errorCode; bool _decodeError; private: Callback _callback; void __decodeType(void); bool __decodeTypeInt(std::string type, Type enumType); void __decodeClassMethod(std::string classMethod); }; } // namespace Rpc } // namespace Di #endif // INCLUDE_DI_RPC_MSG_H_