eis/TestProject/DCR/connection/connection.h

54 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <TestProject/DCR/fp.h>
#include <TestProject/DCR/ihdb_header.h>
#include <stdint.h>
#include <atomic>
#include <future>
#include <mutex>
#include <numeric>
#include <string>
#include <thread>
#include <vector>
namespace DCR {
namespace ihd {
/**
* @brief IhyperDB的连接
*/
struct Connection {
// 由于iHyperDB的设计独特一个进程只使用一个iHyperDB连接
// 且ihyperDB的连接一经建立即使断开网络连接也不会自动释放故不再对其使用手动释放
struct Config {
// 基本信息
std::string username;
std::string password;
HD3Connection hd3_conn;
};
enum class State { disconnected, connected };
Config config;
State state;
std::thread::id tid;
};
auto read_conn_config_maybe() -> maybe<Connection::Config>;
auto init_conn_maybe(maybe<Connection::Config>&& conn_config_maybe)
-> maybe<Connection>;
auto disconnect_maybe(maybe<Connection> conn_maybe) -> maybe<Connection>;
auto connect_maybe(maybe<Connection> conn_maybe) -> maybe<Connection>;
auto read_conn_state() -> Connection::State;
auto read_conn() -> Connection;
auto store_conn_to_local(Connection& conn) -> Connection;
auto auto_connect() -> maybe<Connection>; ///<对外实际使用
} // namespace ihd
} // namespace DCR