WebCFace 2.5.2
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
sync.h
Go to the documentation of this file.
1#pragma once
2#include "./base.h"
4#include <unordered_map>
5#include <chrono>
6
7#ifndef MSGPACK_DEFINE_MAP
8#define MSGPACK_DEFINE_MAP(...)
9#endif
10
12namespace message {
13
30struct SyncInit : public MessageBase<MessageKind::sync_init> {
40 unsigned int member_id;
47 std::string lib_name;
48 std::string lib_ver;
49 std::string addr;
50
51 MSGPACK_DEFINE_MAP(MSGPACK_NVP("M", member_name),
52 MSGPACK_NVP("m", member_id), MSGPACK_NVP("l", lib_name),
53 MSGPACK_NVP("v", lib_ver), MSGPACK_NVP("a", addr))
54};
55
64struct SyncInitEnd : public MessageBase<MessageKind::sync_init_end> {
71 std::string svr_name;
76 std::string ver;
81 unsigned int member_id;
86 std::string hostname;
87 MSGPACK_DEFINE_MAP(MSGPACK_NVP("n", svr_name), MSGPACK_NVP("v", ver),
88 MSGPACK_NVP("m", member_id), MSGPACK_NVP("h", hostname))
89};
101struct Ping : public MessageBase<MessageKind::ping> {
102 Ping() = default;
103};
108struct PingStatus : public MessageBase<MessageKind::ping_status> {
113 std::shared_ptr<std::unordered_map<unsigned int, int>> status;
114 MSGPACK_DEFINE_MAP(MSGPACK_NVP("s", status))
115};
122struct PingStatusReq : public MessageBase<MessageKind::ping_status_req> {
123 PingStatusReq() = default;
124};
134struct Sync : public MessageBase<MessageKind::sync> {
135 unsigned int member_id;
140 std::uint64_t time;
141 Sync(unsigned int member_id,
142 const std::chrono::system_clock::time_point &time)
143 : member_id(member_id),
144 time(std::chrono::duration_cast<std::chrono::milliseconds>(
145 time.time_since_epoch())
146 .count()) {}
147 Sync() : Sync(0, std::chrono::system_clock::now()) {}
148 Sync(const std::chrono::system_clock::time_point &time) : Sync(0, time) {}
149 std::chrono::system_clock::time_point getTime() const {
150 return std::chrono::system_clock::time_point(
151 std::chrono::milliseconds(time));
152 }
153 MSGPACK_DEFINE_MAP(MSGPACK_NVP("m", member_id), MSGPACK_NVP("t", time))
154};
155
156} // namespace message
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
#define MSGPACK_DEFINE_MAP(...)
Definition canvas2d.h:10
型からkindを取得するためだけのベースクラス
Definition base.h:53
ping状況のリクエスト (client->server)
Definition sync.h:122
各クライアントのping状況 (server->client)
Definition sync.h:108
std::shared_ptr< std::unordered_map< unsigned int, int > > status
member_id: ping応答時間(ms) のmap
Definition sync.h:113
ping(server->client->server)
Definition sync.h:101
serverのバージョン情報(server->client)
Definition sync.h:64
std::string ver
serverのバージョン
Definition sync.h:76
std::string hostname
サーバーのホスト名
Definition sync.h:86
unsigned int member_id
クライアントのmember id
Definition sync.h:81
std::string svr_name
serverの名前
Definition sync.h:71
client初期化(client->server->client)
Definition sync.h:30
std::string addr
Definition sync.h:49
SharedString member_name
member名
Definition sync.h:35
std::string lib_ver
Definition sync.h:48
std::string lib_name
clientライブラリの名前(id) このライブラリでは"cpp"
Definition sync.h:47
unsigned int member_id
member id (1以上)
Definition sync.h:40
syncの時刻(client->server->client)
Definition sync.h:134
Sync()
Definition sync.h:147
Sync(const std::chrono::system_clock::time_point &time)
Definition sync.h:148
std::uint64_t time
1970/1/1 0:00(utc) からの経過ミリ秒数で表し、閏秒はカウントしない
Definition sync.h:140
Sync(unsigned int member_id, const std::chrono::system_clock::time_point &time)
Definition sync.h:141
std::chrono::system_clock::time_point getTime() const
Definition sync.h:149
unsigned int member_id
member id
Definition sync.h:135
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103