66 lines
1.5 KiB
C
66 lines
1.5 KiB
C
|
|
/**
|
|||
|
|
* @file mix_cc/ihyper_db/connection.h
|
|||
|
|
* @brief ihyperDB的连接库
|
|||
|
|
* @author Cat (null.null.null@qq.com)
|
|||
|
|
* @version 0.1
|
|||
|
|
* @date 2020-12-12
|
|||
|
|
*
|
|||
|
|
* Copyright: Baosight Co. Ltd.
|
|||
|
|
* DO NOT COPY/USE WITHOUT PERMISSION
|
|||
|
|
*
|
|||
|
|
*/
|
|||
|
|
#pragma once
|
|||
|
|
|
|||
|
|
#include "mix_cc/fp.h"
|
|||
|
|
#include "mix_cc/ihyper_db/utility.h"
|
|||
|
|
#include "mix_cc/type/mix_time.h"
|
|||
|
|
#include <atomic>
|
|||
|
|
#include <future>
|
|||
|
|
#include <mutex>
|
|||
|
|
#include <numeric>
|
|||
|
|
#include <stdint.h>
|
|||
|
|
#include <string>
|
|||
|
|
#include <thread>
|
|||
|
|
#include <vector>
|
|||
|
|
|
|||
|
|
namespace mix_cc {
|
|||
|
|
|
|||
|
|
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 mix_cc
|