Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
DapInterface.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_DAPINTERFACE
19#define INCLUDED_DAPINTERFACE
20
21#include "lib/code_annotation.h"
22
23#include <condition_variable>
24#include <js/RootingAPI.h>
25#include <js/TypeDecls.h>
26#include <js/Value.h>
27#include <memory>
28#include <mutex>
29#include <stdexcept>
30#include <string>
31
32namespace Script { class Context; }
33namespace Script { class Interface; }
34
35namespace DAP
36{
37 // DapInterfaceException
38 class DapInterfaceException : public std::runtime_error
39 {
40 public:
41 explicit DapInterfaceException(const std::string& message)
42 : std::runtime_error(message) {}
43 };
44
46 {
47 public:
48 explicit DapInterfaceNoJSDebuggerException(const std::string& message)
49 : DapInterfaceException(message) {}
50 };
51
53 {
54 public:
55 Interface(const std::string server_address, int port, Script::Context& scriptContext);
58
59 void TryHandleMessage();
60
61 void WaitForMessage();
63
64 private:
65 class SocketHandler;
66
67 bool isJSHandlerDefined();
68 std::string SendDapMessage(const std::string& message);
69 std::string OnMessage(const std::string& message);
70 void SendEventToClient();
71
72 std::unique_ptr<SocketHandler> m_SocketImpl;
73 std::unique_ptr<Script::Interface> m_ScriptInterface;
74
75 std::string m_DapRequest;
76 std::string m_DapResponse;
77
78 std::mutex m_MsgLock;
79 std::mutex m_WaitingLock;
80 std::condition_variable m_MsgApplied;
81
82 bool m_IsWaiting{false};
83 JS::RootedValue m_ModuleValue;
84 };
85}
86
87#endif // !INCLUDED_DAPINTERFACE
Definition: DapInterface.h:39
DapInterfaceException(const std::string &message)
Definition: DapInterface.h:41
Definition: DapInterface.h:46
DapInterfaceNoJSDebuggerException(const std::string &message)
Definition: DapInterface.h:48
Definition: DapInterface.cpp:56
Definition: DapInterface.h:53
std::string m_DapResponse
Definition: DapInterface.h:76
void TryHandleMessage()
Definition: DapInterface.cpp:414
std::mutex m_MsgLock
Definition: DapInterface.h:78
std::unique_ptr< SocketHandler > m_SocketImpl
Definition: DapInterface.h:72
void SendEventToClient()
Definition: DapInterface.cpp:387
Interface(const std::string server_address, int port, Script::Context &scriptContext)
Definition: DapInterface.cpp:289
bool isJSHandlerDefined()
Definition: DapInterface.cpp:337
std::string m_DapRequest
Definition: DapInterface.h:75
JS::RootedValue m_ModuleValue
Definition: DapInterface.h:83
bool m_IsWaiting
Definition: DapInterface.h:82
void EndWaitingForMessage()
Definition: DapInterface.cpp:445
std::string OnMessage(const std::string &message)
Definition: DapInterface.cpp:366
NONCOPYABLE(Interface)
std::mutex m_WaitingLock
Definition: DapInterface.h:79
std::unique_ptr< Script::Interface > m_ScriptInterface
Definition: DapInterface.h:73
std::string SendDapMessage(const std::string &message)
Definition: DapInterface.cpp:355
void WaitForMessage()
Definition: DapInterface.cpp:428
std::condition_variable m_MsgApplied
Definition: DapInterface.h:80
Definition: Context.h:51
Definition: DapInterface.cpp:55
Abstraction around a SpiderMonkey JSContext.
Definition: DapInterface.h:32
Definition: ShaderDefines.cpp:43