| 46 | } |
| 47 | |
| 48 | void DebuggerClientDap::makeRequest( const std::string_view& command, |
| 49 | const nlohmann::json& arguments, ResponseHandler onFinish, |
| 50 | const SessionId& sessionId ) { |
| 51 | auto& session = mSessions[sessionId]; |
| 52 | |
| 53 | nlohmann::json jsonCmd = { |
| 54 | { "seq", session.idx.load() }, |
| 55 | { "type", "request" }, |
| 56 | { "command", command }, |
| 57 | { "arguments", arguments.empty() ? nlohmann::json::object() : arguments } }; |
| 58 | |
| 59 | std::string cmd = jsonCmd.dump(); |
| 60 | std::string msg( String::format( "Content-Length: %zu\r\n\r\n%s", cmd.size(), cmd ) ); |
| 61 | |
| 62 | if ( mDebug ) { |
| 63 | Log::debug( "DebuggerClientDap::makeRequest [Session %s]:", sessionId ); |
| 64 | Log::debug( msg ); |
| 65 | } |
| 66 | |
| 67 | if ( !session.bus ) |
| 68 | return; |
| 69 | |
| 70 | session.bus->write( msg.data(), msg.size() ); |
| 71 | |
| 72 | Lock l( mRequestsMutex ); |
| 73 | mRequests[session.idx] = { std::string{ command }, arguments, onFinish, sessionId }; |
| 74 | session.idx.fetch_add( 1, std::memory_order_relaxed ); |
| 75 | } |
| 76 | |
| 77 | void DebuggerClientDap::makeResponse( int reqSeq, bool success, const std::string& command, |
| 78 | const nlohmann::json& body, const std::string& sessionId ) { |