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

65 lines
1.9 KiB
C++

/**
* @file ReqRepInterface.h
* @brief RequestReply interface
* @copyright 2015 Dual Inventive Technology Centre B.V.
*
* Request reply interface is a pool of workers handling requests and receive replies
*/
#ifndef INCLUDE_DEVICE_REQREPINTERFACE_H_
#define INCLUDE_DEVICE_REQREPINTERFACE_H_
#include <string>
#include <vector>
#include <memory>
#include <atomic>
#include <di/Configuration.h>
#include <di/Zmq.h>
#include <di/rpc/Reader.h>
class DeviceFacade;
class LogInterface;
class ReqRep;
class ReqRepInterface {
public:
/**
* constructor for request reply interface
* @param cfg pointer to config
* @param l pointer to log interface
* @param deviceFacade pointer to device facade
*/
ReqRepInterface(const std::shared_ptr<Di::Configuration> &cfg,
const std::shared_ptr<LogInterface> &l,
const std::shared_ptr<DeviceFacade> &deviceFacade);
/**
* destuctor for request reply interface
*/
~ReqRepInterface();
private:
Di::Rpc::Reader __reader; /**< Reader object*/
std::shared_ptr<DeviceFacade> __deviceFacade; /**< pointer to DeviceFacade object*/
std::shared_ptr<Di::Configuration> __cfg; /**< pointer to configuration*/
std::shared_ptr<ReqRep> __reqRep; /**< pointer to request reply*/
std::vector<std::shared_ptr<std::thread>> __workers; /**< list of pointers to worker threads*/
std::atomic_bool __running; /**< bool to see if the program in running*/
/**
* Sending reply to message
* @param socket pointer to socket where to connect to
* @param msg pointer to message that needs a reply
* @param errorCode error code of the message
*/
void __sendReply(std::shared_ptr<Di::Zmq::Socket> socket, const std::shared_ptr<struct Message> &msg,
uint32_t errorCode);
/**
* worker for handling request reply messages
* @param socket pointer to socket where connection is done
*/
void __worker(std::shared_ptr<Di::Zmq::Socket> socket);
};
#endif /* INCLUDE_DEVICE_REQREPINTERFACE_H_ */