/** * @file DeviceFacade.h * @brief routes all requests and data from connections to devices * @copyright 2015 Dual Inventive Technology Centre B.V. * * routes all requests and data from connections to devices */ #ifndef INCLUDE_DEVICE_DEVICEFACADE_H_ #define INCLUDE_DEVICE_DEVICEFACADE_H_ #include #include #include #include #include #include #include #include #include class TCPConnection; class UDPConnection; class UdpServer; class PublishInterface; class Device; struct Message; class DeviceFacade { public: /** * Device Facade constructor * @param c configuration pointer */ explicit DeviceFacade(const std::shared_ptr &c); /** * Destructor for device facade */ ~DeviceFacade(); void registerUDPServer(const std::shared_ptr &udpServer); bool authDevice(const std::string &devId, const std::shared_ptr &conn); bool deauthDevice(const std::string &devId, const std::shared_ptr &conn); void delTCPConnection(const std::shared_ptr &conn); bool addUDPConnection(const std::string &devId, const std::shared_ptr &conn); void delUDPConnection(const std::shared_ptr &conn); bool rpcMessage(const std::shared_ptr &msg); bool repMessage(const std::shared_ptr &msg); bool reqMessage(const std::shared_ptr &msg, const std::shared_ptr> &replyMailbox, uint32_t *error); void pubMessage(const std::shared_ptr &msg); private: std::unordered_map> __devices; std::shared_ptr __udpServer; std::shared_ptr __protoFacade; std::shared_ptr __publishInterface; std::shared_ptr __repThread; mutable std::shared_timed_mutex __mut; std::atomic_bool __running; void __replyTimeoutThread(void); void __connectPubMessage(const std::string &deviceUid, const std::string &peer); void __disconnectPubMessage(const std::string &deviceUid, const std::string &peer, int code); }; #endif // INCLUDE_DEVICE_DEVICEFACADE_H_