WebCFace 2.5.2
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
member_data.h
Go to the documentation of this file.
1#pragma once
2#include <deque>
3#include <string>
4#include <unordered_map>
5#include <chrono>
6#include <optional>
7#include <mutex>
8#include <atomic>
9#include <condition_variable>
10#include <thread>
11#include <spdlog/common.h>
12#include <spdlog/logger.h>
24
26namespace server {
27
28std::pair<unsigned int, SharedString> findReqField(StrMap2<unsigned int> &req,
29 const SharedString &member,
30 const SharedString &field);
31
32struct MemberData {
33 spdlog::sink_ptr sink;
34 std::shared_ptr<spdlog::logger> logger;
35 spdlog::level::level_enum logger_level;
36
38
43 std::string remote_addr;
44 bool connected() const { return con != nullptr; }
45
52 bool sync_init = false;
53
55 unsigned int member_id;
69
80 std::condition_variable image_cv;
81 std::mutex image_m;
96
97 std::chrono::system_clock::time_point last_sync_time;
99 StrMap2<unsigned int> value_req, text_req, view_req, image_req,
100 view_old_req, robot_model_req, canvas3d_req, canvas3d_old_req,
101 canvas2d_req, canvas2d_old_req, log_req;
102
103 // image_convert_thread[imageのmember][imageのfield] =
104 // imageを変換してthisに送るスレッド
106 void imageConvertThreadMain(const SharedString &member,
107 const SharedString &field);
109
110 bool hasReq(const SharedString &member);
125 std::unordered_map<unsigned int, std::unordered_map<std::size_t, int>>
127
128 inline static unsigned int last_member_id = 0;
129
130 MemberData() = delete;
131 MemberData(const MemberData &) = delete;
132 MemberData &operator=(const MemberData &) = delete;
133 explicit MemberData(ServerStorage *store, const wsConnPtr &con,
134 std::string_view remote_addr,
135 const spdlog::sink_ptr &sink,
136 spdlog::level::level_enum level)
137 : sink(sink), logger_level(level), store(store), con(con),
138 remote_addr(remote_addr) {
139 this->member_id = ++last_member_id;
140 logger = std::make_shared<spdlog::logger>(
141 std::to_string(member_id) + "_(unknown client)", this->sink);
142 logger->set_level(this->logger_level);
143 }
144 ~MemberData() { onClose(); }
145
146 void onConnect();
147 void onRecv(const std::string &msg);
148 void onClose();
149 std::atomic<bool> closing = false;
150
151 void sendPing();
152 static constexpr std::chrono::milliseconds ping_interval{5000};
153 std::chrono::system_clock::time_point last_send_ping;
154 std::optional<std::chrono::milliseconds> last_ping_duration;
155 bool ping_status_req = false;
156
157 std::stringstream send_buffer;
158 int send_len = 0;
159 void send();
160 void send(const std::string &msg);
161
162 template <typename T>
163 void pack(const T &data) {
164 message::pack(send_buffer, send_len, data);
165 }
166};
167} // namespace server
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
Definition store.h:14
void * wsConnPtr
Definition server.h:21
std::pair< unsigned int, SharedString > findReqField(StrMap2< unsigned int > &req, const SharedString &member, const SharedString &field)
Definition member_data.cc:122
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
client初期化(client->server->client)
Definition sync.h:30
Definition member_data.h:32
std::mutex image_m
Definition member_data.h:81
StrMap1< message::ImageFrame > image
Definition member_data.h:70
spdlog::sink_ptr sink
Definition member_data.h:33
StrMap2< message::ImageReq > image_req_info
Definition member_data.h:95
StrMap1< int > image_changed
Definition member_data.h:86
SharedString name
Definition member_data.h:54
std::stringstream send_buffer
Definition member_data.h:157
std::optional< std::chrono::milliseconds > last_ping_duration
Definition member_data.h:154
StrMap1< message::Canvas2DData > canvas2d
Definition member_data.h:68
std::chrono::system_clock::time_point last_sync_time
Definition member_data.h:97
MemberData(ServerStorage *store, const wsConnPtr &con, std::string_view remote_addr, const spdlog::sink_ptr &sink, spdlog::level::level_enum level)
Definition member_data.h:133
StrMap2< unsigned int > image_req
Definition member_data.h:99
StrMap1< std::vector< std::shared_ptr< message::RobotLink > > > robot_model
Definition member_data.h:108
StrMap1< message::ViewData > view
Definition member_data.h:66
void pack(const T &data)
Definition member_data.h:163
std::unordered_map< unsigned int, std::unordered_map< std::size_t, int > > pending_calls
まだ完了していない自分へのcall呼び出しのリスト
Definition member_data.h:126
std::condition_variable image_cv
Definition member_data.h:80
StrMap1< std::shared_ptr< message::FuncInfo > > func
Definition member_data.h:65
std::chrono::system_clock::time_point last_send_ping
Definition member_data.h:153
StrMap1< std::shared_ptr< ValAdaptor > > text
Definition member_data.h:64
StrMap1< std::shared_ptr< std::deque< message::LogLine > > > log
ログ全履歴
Definition member_data.h:114
StrMap1< std::shared_ptr< std::vector< double > > > value
最新の値
Definition member_data.h:63
wsConnPtr con
ws接続のポインタ、切断後(onClose後)nullptrになる
Definition member_data.h:42
StrMap2< unsigned int > canvas3d_old_req
Definition member_data.h:100
message::SyncInit init_data
Definition member_data.h:56
~MemberData()
Definition member_data.h:144
bool connected() const
Definition member_data.h:44
StrMap2< unsigned int > canvas2d_old_req
Definition member_data.h:101
MemberData(const MemberData &)=delete
StrMap1< message::Canvas3DData > canvas3d
Definition member_data.h:67
StrSet1 log_req_default
古いLogリクエスト ("default"のログを古いメッセージ形式で返す)
Definition member_data.h:112
std::shared_ptr< spdlog::logger > logger
Definition member_data.h:34
spdlog::level::level_enum logger_level
Definition member_data.h:35
StrMap2< int > image_req_changed
Definition member_data.h:90
ServerStorage * store
Definition member_data.h:37
MemberData & operator=(const MemberData &)=delete
StrMap2< std::optional< std::thread > > image_convert_thread
Definition member_data.h:105
unsigned int member_id
Definition member_data.h:55
std::string remote_addr
Definition member_data.h:43
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103