| 75 | } |
| 76 | |
| 77 | void DebuggerClientDap::makeResponse( int reqSeq, bool success, const std::string& command, |
| 78 | const nlohmann::json& body, const std::string& sessionId ) { |
| 79 | auto& session = mSessions[sessionId]; |
| 80 | session.idx.fetch_add( 1, std::memory_order_relaxed ); |
| 81 | |
| 82 | nlohmann::json jsonCmd = { { "type", "response" }, |
| 83 | { "request_seq", reqSeq }, |
| 84 | { "seq", session.idx.load() }, |
| 85 | { "success", success }, |
| 86 | { "command", command } }; |
| 87 | |
| 88 | if ( !body.empty() ) |
| 89 | jsonCmd["body"] = body; |
| 90 | |
| 91 | std::string cmd = jsonCmd.dump(); |
| 92 | std::string msg( String::format( "Content-Length: %zu\r\n\r\n%s", cmd.size(), cmd ) ); |
| 93 | |
| 94 | if ( mDebug ) { |
| 95 | Log::debug( "DebuggerClientDap::makeResponse:" ); |
| 96 | Log::debug( msg ); |
| 97 | } |
| 98 | |
| 99 | if ( !mSessions[sessionId].bus ) |
| 100 | return; |
| 101 | |
| 102 | mSessions[sessionId].bus->write( msg.data(), msg.size() ); |
| 103 | } |
| 104 | |
| 105 | bool DebuggerClientDap::isServerConnected() const { |
| 106 | if ( !mSessions.empty() ) { |