Breakpoint hits reaching all the way to UI.
Nasty json only hackery right now, but fixable to support other protocols.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
XEDECLARECLASS2(xe, debug, DebugServer);
|
||||
|
||||
struct json_t;
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace debug {
|
||||
@@ -31,6 +33,8 @@ public:
|
||||
virtual int Setup() = 0;
|
||||
virtual void Close() = 0;
|
||||
|
||||
virtual void SendEvent(json_t* event_json) = 0;
|
||||
|
||||
protected:
|
||||
void MakeReady();
|
||||
|
||||
|
||||
@@ -126,6 +126,15 @@ DebugTarget* DebugServer::GetTarget(const char* name) {
|
||||
return target;
|
||||
}
|
||||
|
||||
void DebugServer::BroadcastEvent(json_t* event_json) {
|
||||
// TODO(benvanik): avoid lock somehow?
|
||||
xe_mutex_lock(lock_);
|
||||
for (auto client : clients_) {
|
||||
client->SendEvent(event_json);
|
||||
}
|
||||
xe_mutex_unlock(lock_);
|
||||
}
|
||||
|
||||
int DebugServer::WaitForClient() {
|
||||
while (!has_clients()) {
|
||||
WaitForSingleObject(client_event_, INFINITE);
|
||||
|
||||
@@ -21,6 +21,8 @@ XEDECLARECLASS2(xe, debug, DebugClient);
|
||||
XEDECLARECLASS2(xe, debug, DebugTarget);
|
||||
XEDECLARECLASS2(xe, debug, Protocol);
|
||||
|
||||
struct json_t;
|
||||
|
||||
|
||||
namespace xe {
|
||||
namespace debug {
|
||||
@@ -43,6 +45,8 @@ public:
|
||||
void RemoveTarget(const char* name);
|
||||
DebugTarget* GetTarget(const char* name);
|
||||
|
||||
void BroadcastEvent(json_t* event_json);
|
||||
|
||||
int WaitForClient();
|
||||
|
||||
private:
|
||||
|
||||
@@ -37,6 +37,8 @@ public:
|
||||
virtual int Setup();
|
||||
virtual void Close();
|
||||
|
||||
virtual void SendEvent(json_t* event_json) {}
|
||||
|
||||
private:
|
||||
static void StartCallback(void* param);
|
||||
|
||||
|
||||
@@ -371,7 +371,12 @@ void WSClient::EventThread() {
|
||||
delete this;
|
||||
}
|
||||
|
||||
void WSClient::Write(const char* value) {
|
||||
void WSClient::SendEvent(json_t* event_json) {
|
||||
char* str = json_dumps(event_json, 0);
|
||||
Write(str);
|
||||
}
|
||||
|
||||
void WSClient::Write(char* value) {
|
||||
const uint8_t* buffers[] = {
|
||||
(uint8_t*)value,
|
||||
};
|
||||
@@ -475,7 +480,8 @@ void WSClient::OnMessage(const uint8_t* data, size_t length) {
|
||||
json_object_set_new(response, "result", result_json);
|
||||
|
||||
// Encode response to string and send back.
|
||||
const char* response_string = json_dumps(response, JSON_INDENT(2));
|
||||
// String freed by Write.
|
||||
char* response_string = json_dumps(response, JSON_INDENT(2));
|
||||
Write(response_string);
|
||||
|
||||
json_decref(request);
|
||||
|
||||
@@ -38,7 +38,9 @@ public:
|
||||
virtual int Setup();
|
||||
virtual void Close();
|
||||
|
||||
void Write(const char* value);
|
||||
virtual void SendEvent(json_t* event_json);
|
||||
|
||||
void Write(char* value);
|
||||
void Write(const uint8_t** buffers, size_t* lengths, size_t count,
|
||||
bool binary = true);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user