WebCFace 2.5.2
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
store.h
Go to the documentation of this file.
1#pragma once
2#include <unordered_map>
3#include <memory>
4#include <functional>
5#include <spdlog/common.h>
8
10namespace server {
11struct MemberData;
12using MemberDataPtr = std::shared_ptr<MemberData>;
13
15 std::mutex store_m;
16
21 std::unordered_map<wsConnPtr, MemberDataPtr> clients;
29 std::unordered_map<unsigned int, MemberDataPtr> clients_by_id;
30
31
36 void removeClient(std::unordered_map<wsConnPtr, MemberDataPtr>::iterator it,
37 std::unique_lock<std::mutex> &lock);
38
39 public:
40 auto clientsCopy() {
41 std::lock_guard lock(store_m);
42 return clients;
43 }
45 std::lock_guard lock(store_m);
46 return clients_by_id;
47 }
48
49 std::shared_ptr<std::unordered_map<unsigned int, int>> ping_status;
51
53 std::string hostname;
54
55 explicit ServerStorage(Server *server, int keep_log = 1000)
56 : clients(), clients_by_id(), ping_status(), server(server),
57 keep_log(keep_log), hostname() {}
58 ~ServerStorage() { clear(); }
59
63 void clear();
64
65 void newClient(const wsConnPtr &con, const std::string &remote_addr,
66 const spdlog::sink_ptr &sink,
67 spdlog::level::level_enum level);
68 void initClientId(unsigned int id, const wsConnPtr &con);
69 void removeClient(const wsConnPtr &con);
70 MemberDataPtr getClient(const wsConnPtr &con);
71
72 void clientSendAll();
73
78 void findAndDo(const SharedString &name,
79 const std::function<void(MemberDataPtr)> &func,
80 const std::function<void()> &func_else = nullptr);
85 void findAndDo(unsigned int id,
86 const std::function<void(MemberDataPtr)> &func,
87 const std::function<void()> &func_else = nullptr);
93 void findConnectedAndDo(unsigned int id,
94 const std::function<void(MemberDataPtr)> &func,
95 const std::function<void()> &func_else = nullptr);
102 void forEach(const std::function<void(MemberDataPtr)> &func);
109 void forEachWithName(const std::function<void(MemberDataPtr)> &func);
110};
111
112} // namespace server
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
Definition store.h:14
auto clientsCopy()
Definition store.h:40
std::shared_ptr< std::unordered_map< unsigned int, int > > ping_status
Definition store.h:49
Server * server
Definition store.h:50
~ServerStorage()
Definition store.h:58
int keep_log
Definition store.h:52
std::string hostname
Definition store.h:53
auto clientsByIdCopy()
Definition store.h:44
ServerStorage(Server *server, int keep_log=1000)
Definition store.h:55
Definition server.h:25
void * wsConnPtr
Definition server.h:21
std::shared_ptr< MemberData > MemberDataPtr
Definition store.h:12
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103