src.dualinventive.com/dinet/libdipp/include/di/rpc/AsyncReader.h

44 lines
1.0 KiB
C++

#ifndef INCLUDE_DI_RPC_ASYNCREADER_H_
#define INCLUDE_DI_RPC_ASYNCREADER_H_
#include <string>
#include <memory>
#include <mutex>
#include <thread>
#include <unordered_map>
#include <type_traits>
#include <di/rpc/Reader.h>
#include <di/rpc/Msg.h>
#include <di/Mailbox.h>
#include <di/types.h>
namespace Di {
namespace Rpc {
class AsyncReader : public Reader {
public:
AsyncReader();
~AsyncReader();
di_errno_t queueAsync(std::shared_ptr<Msg> msg);
di_errno_t checkAsyncStatus(std::shared_ptr<Msg> msg);
std::shared_ptr<std::string> getAsyncReply(std::shared_ptr<Msg> msg);
private:
Di::Mailbox<Msg> __requestQueue;
std::unordered_map<std::string, std::shared_ptr<std::string>> __replyQueue;
std::unordered_map<std::string, uint64_t> __queueTimeout;
std::mutex __replyQueueLock;
std::shared_ptr<std::thread> __asyncWorker;
bool __workerRunning;
std::string __createMapKey(const std::shared_ptr<Msg> &msg);
void __worker(void);
};
} // namespace Rpc
} // namespace Di
#endif // INCLUDE_DI_RPC_ASYNCREADER_H_