-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathas_debugger_dap.h
67 lines (52 loc) · 1.48 KB
/
as_debugger_dap.h
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
// MIT Licensed
// see https://github.com/Paril/angelscript-debugger
#pragma once
#include <dap/io.h>
#include <dap/network.h>
#include <dap/protocol.h>
#include <memory>
class asIDBDebugger;
class asIDBDAPClient;
// implementation of DAP server that connects
// back to an asIDBDebugger.
class asIDBDAPServer
{
public:
// port to connect to
const int port;
// ptr back to debugger
asIDBDebugger *dbg;
asIDBDAPServer(int port, asIDBDebugger *debugger);
virtual ~asIDBDAPServer();
// queries
bool ServerActive()
{
return server.get() != nullptr;
}
bool ClientConnected()
{
return ServerActive() && client.get() != nullptr;
}
// server management
void StartServer();
void StopServer();
void Tick();
// client management
template<typename T>
void SendEventToClient(const T &event)
{
const dap::TypeInfo *typeinfo = dap::TypeOf<T>::type();
SendEventToClient(typeinfo, &event);
}
protected:
// server ptr
std::unique_ptr<dap::net::Server> server;
// connected client
// TODO: does this have to be mutexed? I think it's
// atomic and we only care if it's set or not, we never
// call into the client from the main thread
std::unique_ptr<asIDBDAPClient> client;
void ClientConnected(const std::shared_ptr<dap::ReaderWriter> &socket);
void ClientError(const char *msg);
void SendEventToClient(const dap::TypeInfo *typeinfo, const void *event);
};