Skip to content

Commit

Permalink
More DAP WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Dec 18, 2024
1 parent e4ee5f1 commit 8b2f178
Show file tree
Hide file tree
Showing 10 changed files with 253 additions and 121 deletions.
12 changes: 12 additions & 0 deletions src/tools/ecode/plugins/debugger/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

namespace ecode {

Bus::State Bus::state() const {
return mState;
}

void Bus::setState( State state ) {
if ( state == mState )
return;
mState = state;
onStateChanged( state );
}

void Bus::onStateChanged( State state ) {
}

} // namespace ecode
15 changes: 14 additions & 1 deletion src/tools/ecode/plugins/debugger/bus.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
#pragma once

#include "config.hpp"
#include <functional>

namespace ecode {

class Bus {
public:
enum class State { None, Running, Closed };

typedef std::function<void( const char* bytes, size_t n )> ReadFn;

State state() const;

virtual bool start() = 0;

virtual bool close() = 0;

virtual void startAsyncRead( ReadFn readFn ) = 0;

virtual size_t write( const char* buffer, const size_t& size ) = 0;

protected:
void setState( State state );

void onStateChanged( State state );

State mState{ State::None };
};

} // namespace ecode
21 changes: 17 additions & 4 deletions src/tools/ecode/plugins/debugger/busprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,23 @@ namespace ecode {
BusProcess::BusProcess( const Command& command ) : mCommand( command ), mProcess() {}

bool BusProcess::start() {
return mProcess.create( mCommand.command, mCommand.arguments,
Process::getDefaultOptions() | Process::Options::EnableAsync |
Process::Options::CombinedStdoutStderr,
mCommand.environment );
bool res = mProcess.create( mCommand.command, mCommand.arguments,
Process::getDefaultOptions() | Process::Options::EnableAsync |
Process::Options::CombinedStdoutStderr,
mCommand.environment );
if ( res )
setState( State::Running );

return res;
}

bool BusProcess::close() {
if ( mState == State::Running ) {
bool res = mProcess.kill();
if ( res )
setState( State::Closed );
}
return false;
}

void BusProcess::startAsyncRead( ReadFn readFn ) {
Expand Down
3 changes: 3 additions & 0 deletions src/tools/ecode/plugins/debugger/busprocess.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bus.hpp"
#include "config.hpp"
#include <eepp/system/process.hpp>

using namespace EE::System;
Expand All @@ -11,6 +12,8 @@ class BusProcess : public Bus {

bool start() override;

bool close() override;

void startAsyncRead( ReadFn readFn ) override;

size_t write( const char* buffer, const size_t& size ) override;
Expand Down
17 changes: 15 additions & 2 deletions src/tools/ecode/plugins/debugger/bussocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,21 @@ namespace ecode {
BusSocket::BusSocket( const Connection& connection ) : mConnection( connection ) {}

bool BusSocket::start() {
return mSocket.connect( IpAddress( mConnection.host ), mConnection.port ) ==
Socket::Status::Done;
bool res =
mSocket.connect( IpAddress( mConnection.host ), mConnection.port ) == Socket::Status::Done;
if ( res )
setState( State::Running );
return res;
}

bool BusSocket::close() {
if ( mState == State::Running ) {
mSocket.disconnect();
setState( State::Closed );
return true;
}

return false;
}

void BusSocket::startAsyncRead( ReadFn readFn ) {
Expand Down
5 changes: 4 additions & 1 deletion src/tools/ecode/plugins/debugger/bussocket.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "bus.hpp"
#include "config.hpp"
#include <eepp/network/tcpsocket.hpp>

using namespace EE::Network;
Expand All @@ -11,12 +12,14 @@ class BusSocket : public Bus {

bool start() override;

bool close() override;

void startAsyncRead( ReadFn readFn ) override;

size_t write( const char* buffer, const size_t& size ) override;

protected:
Connection mConnection;
Connection mConnection;
TcpSocket mSocket;
};

Expand Down
Loading

0 comments on commit 8b2f178

Please sign in to comment.