-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathClientObject.cpp
More file actions
83 lines (66 loc) · 2.07 KB
/
Copy pathClientObject.cpp
File metadata and controls
83 lines (66 loc) · 2.07 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "ClientObject.hpp"
#include "ClientSocket.hpp"
#include "../../helpers/Log.hpp"
#include "../../helpers/FFI.hpp"
#include "../../Macros.hpp"
#include "../message/MessageType.hpp"
#include "../message/MessageParser.hpp"
#include "../message/messages/GenericProtocolMessage.hpp"
#include <cstdarg>
#include <cstring>
#include <ffi.h>
using namespace Hyprwire;
CClientObject::CClientObject(SP<CClientSocket> client) : m_client(client) {
;
}
CClientObject::~CClientObject() {
if (!m_destroyed && m_id != 0 && m_spec && m_client && m_client->m_fd.isValid()) {
const auto methods = methodsOut();
for (const auto& method : methods) {
if (!method.isDestructor)
continue;
if (method.since > m_version)
continue;
if (!method.returnsType.empty()) {
Debug::log(WARN, "can't auto-call destructor for object {}: method {} has returns type", m_id, method.idx);
break;
}
if (!method.params.empty()) {
Debug::log(WARN, "can't auto-call destructor for object {}: method {} has params", m_id, method.idx);
break;
}
TRACE(Debug::log(TRACE, "auto-calling protocol destructor {} for object {}", method.idx, m_id));
call(method.idx);
break;
}
}
TRACE(Debug::log(TRACE, "destroying object {}", m_id));
}
const std::vector<SMethod>& CClientObject::methodsOut() {
return m_spec->c2s();
}
const std::vector<SMethod>& CClientObject::methodsIn() {
return m_spec->s2c();
}
void CClientObject::errd() {
if (m_client)
m_client->m_error = true;
}
void CClientObject::sendMessage(const IMessage& msg) {
if (m_client)
m_client->sendMessage(msg);
}
SP<IServerClient> CClientObject::client() {
return nullptr;
}
bool CClientObject::server() {
return false;
}
SP<IObject> CClientObject::self() {
return m_self.lock();
}
SP<IClientSocket> CClientObject::clientSock() {
if (!m_client)
return nullptr;
return m_client.lock();
}