2#include <unordered_map>
18struct PromiseData :
public std::enable_shared_from_this<PromiseData> {
24 std::condition_variable
cond;
28 bool reach_event_done =
false;
29 bool finish_event_done =
false;
33 bool finished =
false;
34 bool is_error =
false;
45 const std::vector<ValAdaptor>
args_;
46 std::variant<int, std::vector<wcfMultiVal>, std::vector<wcfMultiValW>>
52 void callReachEvent();
56 void callFinishEvent();
62 std::size_t caller_id = 0)
63 : reach_event(), finish_event(), started_p(), result_p(),
64 started_f(started_p.get_future().share()),
65 result_f(result_p.get_future().share()), base(base),
66 caller_id(caller_id), args_(std::move(args)) {}
72 template <std::
size_t v_index,
typename CVal>
73 std::vector<CVal> &initCArgs();
78 std::size_t
callerId()
const {
return caller_id; }
90 std::unordered_map<std::size_t, std::shared_ptr<PromiseData>> promises;
91 std::size_t next_caller_id = 0;
99 std::lock_guard lock(mtx);
100 std::size_t caller_id = next_caller_id++;
101 auto state = std::make_shared<PromiseData>(
102 base, std::vector<ValAdaptor>{}, caller_id);
103 promises.emplace(caller_id, state);
110 std::shared_ptr<PromiseData>
getResult(std::size_t caller_id) {
111 std::lock_guard lock(mtx);
112 auto it = promises.find(caller_id);
113 if (it != promises.end()) {
116 throw std::out_of_range(
"caller id not found");
124 std::lock_guard lock(mtx);
125 auto it = promises.find(caller_id);
126 if (it != promises.end()) {
129 throw std::out_of_range(
"caller id not found");
144 std::optional<std::vector<Arg>>
args;
157 throw std::runtime_error(
"func_impl is null");
170 std::function<Func::FuncType> &&func_impl)
171 :
Field(base), return_type(return_type), args(std::move(args)),
172 func_impl(std::move(func_impl)) {}
呼び出された関数の引数の取得と戻り値のセットをするインタフェース
Definition func_result.h:323
非同期で実行した関数の実行結果を取得するインタフェース。
Definition func_result.h:50
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
数値、文字列などの値を相互変換するクラス
Definition val_adaptor.h:87
PromiseDataのリストを保持する。
Definition func_internal.h:88
std::shared_ptr< PromiseData > addResult(const Field &base)
新しいcaller_idを振って新しいAsyncFuncStateを生成しそれを返す
Definition func_internal.h:98
std::shared_ptr< PromiseData > getResult(std::size_t caller_id)
AsyncFuncStateを取得
Definition func_internal.h:110
void removeResult(std::size_t caller_id)
resultを設定し終わったstateを削除
Definition func_internal.h:123
ValType
引数や戻り値の型を表すenum
Definition val_adaptor.h:21
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:70
関数1つの情報を表す。関数の実体も持つ
Definition func_internal.h:142
std::function< Func::FuncType > func_impl
Definition func_internal.h:145
std::optional< std::vector< Arg > > args
Definition func_internal.h:144
FuncInfo()
Definition func_internal.h:168
ValType return_type
Definition func_internal.h:143
FuncInfo(const Field &base, ValType return_type, std::optional< std::vector< Arg > > &&args, std::function< Func::FuncType > &&func_impl)
Definition func_internal.h:169
void run(const CallHandle &handle)
func_implをこのスレッドで実行
Definition func_internal.h:153
PromiseとCallHandleのデータを保持するクラス
Definition func_internal.h:18
std::condition_variable cond
Definition func_internal.h:24
std::size_t callerId() const
Definition func_internal.h:78
std::size_t caller_id
Definition func_internal.h:44
std::function< void(Promise)> reach_event
Definition func_internal.h:26
ValAdaptor response
Definition func_internal.h:35
std::shared_future< bool > started_f
Definition func_internal.h:40
Field base
Definition func_internal.h:43
ValAdaptor rejection
Definition func_internal.h:36
std::function< void(Promise)> finish_event
Definition func_internal.h:27
std::shared_future< ValAdaptor > result_f
Definition func_internal.h:41
const std::vector< ValAdaptor > args_
Definition func_internal.h:45
PromiseData(const Field &base, std::vector< ValAdaptor > &&args, std::size_t caller_id=0)
Definition func_internal.h:61
std::mutex m
Definition func_internal.h:23
std::promise< ValAdaptor > result_p
Definition func_internal.h:39
std::variant< int, std::vector< wcfMultiVal >, std::vector< wcfMultiValW > > c_args_
Definition func_internal.h:47
std::promise< bool > started_p
Definition func_internal.h:38
関数呼び出し (client(caller)->server->client(receiver))
Definition func.h:23
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103