3#include <condition_variable>
9#include <unordered_map>
11#include <spdlog/logger.h>
30void wsThreadMain(
const std::shared_ptr<ClientData> &data);
35struct ClientData : std::enable_shared_from_this<ClientData> {
48 return base.
member_ == self_member_name;
54 bool current_curl_connected =
false;
55 void *current_curl_handle =
nullptr;
57 std::string current_ws_buf =
"";
78 struct SyncDataSnapshot {
79 std::chrono::system_clock::time_point time;
91 struct SyncDataFirst {
93 canvas3d_req, canvas2d_req, image_req, log_req;
96 SyncDataSnapshot sync_data;
102 std::atomic<bool> closing =
false;
109 bool connected =
false;
114 bool sync_init_end =
false;
121 bool do_ws_init =
false;
131 bool do_ws_recv =
false;
136 bool recv_ready =
false;
138 std::queue<std::vector<std::pair<int, std::shared_ptr<void>>>>
153 std::queue<std::variant<std::string, SyncDataSnapshot>>
sync_queue;
180 : std::unique_lock<std::mutex>(data->ws_m), data(data) {}
184 assert(this->owns_lock());
185 return data->ws_data;
192 std::atomic<bool> auto_reconnect =
true;
251 : std::unique_lock<std::mutex>(data->sync_m), data(data) {}
255 assert(this->owns_lock());
256 return data->sync_data;
268 if (lock_ws.
getData().connected) {
269 lock_ws.
getData().sync_queue.push(std::move(msg));
270 this->ws_cond.notify_all();
286 has_sync_first = (lock_s.
getData().sync_first != std::nullopt);
288 if (has_sync_first) {
290 lock_ws.
getData().sync_queue.push(std::move(msg));
291 this->ws_cond.notify_all();
304 lock_ws.
getData().sync_queue.push(std::move(msg));
305 this->ws_cond.notify_all();
309 lock_ws.
getData().sync_queue.push(std::move(msg));
310 this->ws_cond.notify_all();
313 std::string packSyncDataFirst(
const SyncDataFirst &data);
314 std::string packSyncData(std::stringstream &buffer,
int &len,
315 const SyncDataSnapshot &data);
336 void syncImpl(
bool sync,
bool forever,
337 std::optional<std::chrono::microseconds> timeout);
344 onRecv(
const std::vector<std::pair<
int, std::shared_ptr<void>>> &messages);
370 if (self_member_id && *self_member_id ==
id) {
371 return self_member_name;
373 for (
const auto &it : member_ids) {
374 if (it.second ==
id) {
382 if (name == self_member_name && self_member_id) {
383 return *self_member_id;
385 auto it = member_ids.find(name);
386 if (it != member_ids.end()) {
429 StrMap1<std::shared_ptr<std::function<void(
Log)>>>
441 std::shared_ptr<std::unordered_map<unsigned int, int>> ping_status =
443 bool ping_status_req =
false;
448 void pingStatusReq();
Canvas2Dの送受信データを表すクラス
Definition canvas2d.h:24
Canvas3Dの送受信データを表すクラス
Definition canvas3d.h:28
関数1つを表すクラス
Definition func.h:95
(ver1.3から追加) 画像の送受信データを表すクラス
Definition image.h:20
ログの送受信データを表すクラス
Definition log.h:65
Memberを指すクラス
Definition member.h:22
RobotModelの送受信データを表すクラス
Definition robot_model.h:26
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
文字列の送受信データを表すクラス
Definition text.h:183
実数値またはその配列の送受信データを表すクラス
Definition value.h:23
文字列、数値などの型を送受信するクラス
Definition text.h:25
Viewの送受信データを表すクラス
Definition view.h:26
Definition client_internal.h:246
ScopedSyncLock(const std::shared_ptr< ClientData > &data)
Definition client_internal.h:252
auto & getData()
Definition client_internal.h:254
ScopedSyncLock(ClientData *data)
Definition client_internal.h:250
Definition client_internal.h:175
auto & getData()
Definition client_internal.h:183
ScopedWsLock(ClientData *data)
Definition client_internal.h:179
ScopedWsLock(const std::shared_ptr< ClientData > &data)
Definition client_internal.h:181
PromiseDataのリストを保持する。
Definition func_internal.h:88
Definition data_store1.h:10
送受信するデータを保持するクラス
Definition data_store2.h:21
std::atomic< int > log_keep_lines
Definition log.cc:9
void wsThreadMain(const std::shared_ptr< ClientData > &data)
Definition client_threading.cc:78
std::map< SharedString, T > StrMap1
Definition encoding.h:110
StrMap1< StrMap1< T > > StrMap2
Definition encoding.h:112
std::set< SharedString > StrSet1
Definition encoding.h:113
メンバ名とデータ名を持つクラス
Definition field.h:37
SharedString member_
メンバー名
Definition field.h:42
Definition client_internal.h:194
std::optional< SyncDataFirst > sync_first
Definition client_internal.h:208
Definition client_internal.h:104
std::queue< std::vector< std::pair< int, std::shared_ptr< void > > > > recv_queue
Definition client_internal.h:139
std::queue< std::variant< std::string, SyncDataSnapshot > > sync_queue
送信したいメッセージを入れるキュー
Definition client_internal.h:153
Definition client_internal.h:35
FuncResultStore func_result_store
Definition client_internal.h:358
std::unordered_map< unsigned int, std::string > member_lib_name
Definition client_internal.h:367
unsigned int getMemberIdFromName(const SharedString &name) const
Definition client_internal.h:381
bool messagePushOnline(std::string &&msg)
Definition client_internal.h:266
SyncDataStore2< std::shared_ptr< message::Canvas3DData > > canvas3d_store
Definition client_internal.h:354
std::thread ws_thread
websocket接続、通信するスレッド
Definition client_internal.h:69
StrMap1< std::shared_ptr< std::function< void(Member)> > > sync_event
Definition client_internal.h:416
StrMap2< std::shared_ptr< std::function< void(Variant)> > > text_change_event
Definition client_internal.h:406
std::optional< unsigned int > self_member_id
Definition client_internal.h:46
SyncDataStore2< std::shared_ptr< TextData > > text_store
Definition client_internal.h:349
StrMap1< std::shared_ptr< std::function< void(Value)> > > value_entry_event
Definition client_internal.h:418
StrMap1< std::unique_ptr< std::streambuf > > logger_buf
Definition client_internal.h:434
bool messagePushReq(std::string &&msg)
Definition client_internal.h:282
StrMap2< std::shared_ptr< std::function< void(RobotModel)> > > robot_model_change_event
Definition client_internal.h:409
std::shared_ptr< std::function< void(Member)> > member_entry_event
Definition client_internal.h:403
bool isSelf(const FieldBase &base) const
Definition client_internal.h:47
StrMap2< std::shared_ptr< std::function< void(View)> > > view_change_event
Definition client_internal.h:410
std::string current_curl_path
Definition client_internal.h:56
StrSet1 member_entry
Definition client_internal.h:347
int port
Definition client_internal.h:53
std::string svr_hostname
Definition client_internal.h:439
SyncDataStore2< std::shared_ptr< LogData > > log_store
Definition client_internal.h:356
StrMap1< unsigned int > member_ids
Definition client_internal.h:366
SyncDataStore2< std::shared_ptr< ValueData > > value_store
Definition client_internal.h:348
StrMap1< std::shared_ptr< std::function< void(Log)> > > log_entry_event
Definition client_internal.h:430
StrMap2< std::shared_ptr< std::function< void(Value)> > > value_change_event
Definition client_internal.h:405
StrMap1< std::shared_ptr< std::function< void(Text)> > > text_entry_event
Definition client_internal.h:419
SyncDataStore2< ImageData, message::ImageReq > image_store
Definition client_internal.h:352
StrMap1< std::unique_ptr< std::wostream > > logger_os_w
Definition client_internal.h:437
SharedString host
Definition client_internal.h:52
StrMap1< std::shared_ptr< std::function< void(Member)> > > ping_event
Definition client_internal.h:417
std::unordered_map< unsigned int, std::string > member_addr
Definition client_internal.h:368
void messagePushAlways(std::string &&msg)
Definition client_internal.h:302
StrMap1< std::unique_ptr< std::ostream > > logger_os
Definition client_internal.h:435
StrMap1< std::shared_ptr< std::function< void(Canvas2D)> > > canvas2d_entry_event
Definition client_internal.h:428
SharedString self_member_name
Client自身の名前
Definition client_internal.h:45
StrMap1< std::shared_ptr< std::function< void(Func)> > > func_entry_event
Definition client_internal.h:420
std::mutex entry_m
Definition client_internal.h:346
StrMap2< std::shared_ptr< std::function< void(Canvas3D)> > > canvas3d_change_event
Definition client_internal.h:412
SyncDataStore1< std::chrono::system_clock::time_point > sync_time_store
Definition client_internal.h:357
StrMap2< std::shared_ptr< std::function< void(Image)> > > image_change_event
Definition client_internal.h:407
SyncDataStore2< std::shared_ptr< FuncData > > func_store
Definition client_internal.h:350
const SharedString & getMemberNameFromId(unsigned int id) const
Definition client_internal.h:369
std::mutex logger_m
Definition client_internal.h:433
std::mutex event_m
コールバックリスト(のmapなど)にアクセスするときにロック
Definition client_internal.h:396
SyncDataStore2< std::shared_ptr< message::Canvas2DData > > canvas2d_store
Definition client_internal.h:355
StrMap1< std::shared_ptr< std::function< void(RobotModel)> > > robot_model_entry_event
Definition client_internal.h:424
StrMap1< std::shared_ptr< std::function< void(Canvas3D)> > > canvas3d_entry_event
Definition client_internal.h:426
std::shared_ptr< void > curl_initializer
Definition client_internal.h:58
SyncDataStore2< std::shared_ptr< RobotModelData > > robot_model_store
Definition client_internal.h:353
SyncDataStore2< std::shared_ptr< message::ViewData > > view_store
Definition client_internal.h:351
StrMap2< std::shared_ptr< std::function< void(Canvas2D)> > > canvas2d_change_event
Definition client_internal.h:414
StrMap1< std::shared_ptr< std::function< void(View)> > > view_entry_event
Definition client_internal.h:421
std::condition_variable ws_cond
ws_thread, recv_thread, queue 間の同期
Definition client_internal.h:170
std::shared_ptr< spdlog::logger > logger_internal
Definition client_internal.h:432
StrMap2< std::shared_ptr< std::function< void(Log)> > > log_append_event
Definition client_internal.h:415
StrMap1< std::unique_ptr< std::wstreambuf > > logger_buf_w
Definition client_internal.h:436
StrMap1< std::shared_ptr< std::function< void(Image)> > > image_entry_event
Definition client_internal.h:422
StrMap1< Queue< FuncCallHandle > > func_listener_handlers
listenerがfetchするの待ちの関数呼び出しをためておく
Definition client_internal.h:364
void messagePushAlways(SyncDataSnapshot &&msg)
Definition client_internal.h:307
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103