-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient_manager.cpp
More file actions
69 lines (54 loc) · 1.54 KB
/
client_manager.cpp
File metadata and controls
69 lines (54 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "client_manager.h"
#include "client.h"
client_manager::client_manager()
{
}
client_manager::~client_manager()
{
}
void client_manager::process_login(boost::asio::io_service &ios, int value, Json::Value &respons)
{
std::shared_ptr<client_interface> sc;
ERROR_CODE ec = find_client_use_id(value, sc);
if (ec)
respons["errorcode"] = insert_client_use_id(ios, value, sc);
if (sc)
sc->get_session_data(respons);
}
void client_manager::process_logic(Json::Value &root, Json::Value &respons)
{
std::shared_ptr<client_interface> sc;
ERROR_CODE ec = find_client_use_id(root["UsrID"].asInt(), sc);
if (!ec)
{
ec = sc->do_some(root, respons);
sc->get_session_data(respons);
}
respons["errorcode"] = ec;
}
ERROR_CODE client_manager::find_client_use_id(int id, std::shared_ptr<client_interface> &sc)
{
ERROR_CODE isfind = USER_NOT_LOGIN;
std::lock_guard<std::mutex> lock(m_lock);
auto it = m_client.find(id);
if (it != m_client.end())
{
isfind = SUCCEEDED;
sc = it->second;
}
return isfind;
}
ERROR_CODE client_manager::insert_client_use_id(boost::asio::io_service &ios, int id, std::shared_ptr<client_interface> &sc)
{
ERROR_CODE ec = find_client_use_id(id, sc);
if (ec)
{
sc = std::shared_ptr<client_interface>(new client(ios, shared_from_this()));
ec = sc->init_user_info(id);
if (ec)
sc.reset();
else
return !insert(id, sc) ? UNKNOWN_ERROR : SUCCEEDED;
}
return ec;
}