src.dualinventive.com/dinet/sec-multi-proxy/include/device/DeviceFacade.h

70 lines
2.2 KiB
C++

/**
* @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 <memory>
#include <string>
#include <atomic>
#include <shared_mutex>
#include <unordered_map>
#include <di/Configuration.h>
#include <di/Buffer.h>
#include <di/Mailbox.h>
#include <server/ProtocolFacade.h>
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<Di::Configuration> &c);
/**
* Destructor for device facade
*/
~DeviceFacade();
void registerUDPServer(const std::shared_ptr<UdpServer> &udpServer);
bool authDevice(const std::string &devId, const std::shared_ptr<TCPConnection> &conn);
bool deauthDevice(const std::string &devId, const std::shared_ptr<TCPConnection> &conn);
void delTCPConnection(const std::shared_ptr<TCPConnection> &conn);
bool addUDPConnection(const std::string &devId, const std::shared_ptr<UDPConnection> &conn);
void delUDPConnection(const std::shared_ptr<UDPConnection> &conn);
bool rpcMessage(const std::shared_ptr<struct Message> &msg);
bool repMessage(const std::shared_ptr<struct Message> &msg);
bool reqMessage(const std::shared_ptr<struct Message> &msg,
const std::shared_ptr<Di::Mailbox<std::string>> &replyMailbox,
uint32_t *error);
void pubMessage(const std::shared_ptr<struct Message> &msg);
private:
std::unordered_map<std::string, std::shared_ptr<Device>> __devices;
std::shared_ptr<UdpServer> __udpServer;
std::shared_ptr<ProtocolFacade> __protoFacade;
std::shared_ptr<PublishInterface> __publishInterface;
std::shared_ptr<std::thread> __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_