Skip to content

Commit

Permalink
Debugger: Implement host interface roster listener.
Browse files Browse the repository at this point in the history
TargetHostInterfaceRoster:
- Add Listener interface. For now, this simply notifies the listener of
  changes to the active debugger count.
- Adjust show new team window command to automatically fall back to the local
  interface window if one isn't specified. Fixes the Start New Team menu item
  in the TeamWindow. The latter will later be expanded to show the available
  interfaces to start a new team on in a submenu.

Debugger:
- Implement roster listener interface in order to know when to attempt
  application quit.

With this commit, all necessary work to isolate the application from the target
host is complete, and work on the actual remote interface and protocol can
begin.
  • Loading branch information
anevilyak committed Apr 21, 2016
1 parent 8527cd4 commit aed5c39
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
37 changes: 28 additions & 9 deletions src/apps/debugger/Debugger.cpp
Expand Up @@ -208,7 +208,7 @@ parse_arguments(int argc, const char* const* argv, bool noOutput,
}

static status_t
global_init()
global_init(TargetHostInterfaceRoster::Listener* listener)
{
status_t error = TypeHandlerRoster::CreateDefault();
if (error != B_OK)
Expand All @@ -222,7 +222,7 @@ global_init()
if (error != B_OK)
return error;

error = TargetHostInterfaceRoster::CreateDefault();
error = TargetHostInterfaceRoster::CreateDefault(listener);
if (error != B_OK)
return error;

Expand All @@ -242,7 +242,8 @@ global_init()
// #pragma mark - Debugger application class


class Debugger : public BApplication {
class Debugger : public BApplication,
private TargetHostInterfaceRoster::Listener {
public:
Debugger();
~Debugger();
Expand All @@ -256,6 +257,9 @@ class Debugger : public BApplication {
virtual bool QuitRequested();
virtual void Quit();

// TargetHostInterfaceRoster::Listener
virtual void TeamDebuggerCountChanged(int32 count);

private:
status_t _StartNewTeam(TargetHostInterface* interface,
const char* teamPath, const char* args);
Expand All @@ -270,7 +274,7 @@ class Debugger : public BApplication {
// #pragma mark - CliDebugger


class CliDebugger {
class CliDebugger : private TargetHostInterfaceRoster::Listener {
public:
CliDebugger();
~CliDebugger();
Expand All @@ -279,7 +283,7 @@ class CliDebugger {
};


class ReportDebugger {
class ReportDebugger : private TargetHostInterfaceRoster::Listener {
public:
ReportDebugger();
~ReportDebugger();
Expand All @@ -293,6 +297,7 @@ class ReportDebugger {
Debugger::Debugger()
:
BApplication(kDebuggerSignature),
TargetHostInterfaceRoster::Listener(),
fTeamsWindow(NULL),
fStartTeamWindow(NULL)
{
Expand All @@ -311,7 +316,7 @@ Debugger::~Debugger()
status_t
Debugger::Init()
{
status_t error = global_init();
status_t error = global_init(this);
if (error != B_OK)
return error;

Expand Down Expand Up @@ -351,8 +356,12 @@ Debugger::MessageReceived(BMessage* message)
TargetHostInterface* hostInterface;
if (message->FindPointer("interface",
reinterpret_cast<void**>(&hostInterface)) != B_OK) {
break;
// if an interface isn't explicitly supplied, fall back to
// the default local interface.
hostInterface = TargetHostInterfaceRoster::Default()
->ActiveInterfaceAt(0);
}

BMessenger messenger(fStartTeamWindow);
if (!messenger.IsValid()) {
fStartTeamWindow = StartTeamWindow::Create(hostInterface);
Expand Down Expand Up @@ -473,6 +482,16 @@ Debugger::Quit()
}


void
Debugger::TeamDebuggerCountChanged(int32 count)
{
if (count == 0) {
AutoLocker<Debugger> lock(this);
Quit();
}
}


status_t
Debugger::_StartNewTeam(TargetHostInterface* interface, const char* path,
const char* args)
Expand Down Expand Up @@ -529,7 +548,7 @@ CliDebugger::Run(const Options& options)
SignalSet(SIGINT).BlockInCurrentThread();

// initialize global objects and settings manager
status_t error = global_init();
status_t error = global_init(this);
if (error != B_OK) {
fprintf(stderr, "Error: Global initialization failed: %s\n",
strerror(error));
Expand Down Expand Up @@ -596,7 +615,7 @@ bool
ReportDebugger::Run(const Options& options)
{
// initialize global objects and settings manager
status_t error = global_init();
status_t error = global_init(this);
if (error != B_OK) {
fprintf(stderr, "Error: Global initialization failed: %s\n",
strerror(error));
Expand Down
Expand Up @@ -23,7 +23,8 @@ TargetHostInterfaceRoster::TargetHostInterfaceRoster()
fLock(),
fRunningTeamDebuggers(0),
fInterfaceInfos(20, false),
fActiveInterfaces(20, false)
fActiveInterfaces(20, false),
fListener(NULL)
{
}

Expand All @@ -41,7 +42,7 @@ TargetHostInterfaceRoster::Default()


/*static*/ status_t
TargetHostInterfaceRoster::CreateDefault()
TargetHostInterfaceRoster::CreateDefault(Listener* listener)
{
if (sDefaultInstance != NULL)
return B_OK;
Expand All @@ -52,7 +53,7 @@ TargetHostInterfaceRoster::CreateDefault()
return B_NO_MEMORY;
ObjectDeleter<TargetHostInterfaceRoster> rosterDeleter(roster);

status_t error = roster->Init();
status_t error = roster->Init(listener);
if (error != B_OK)
return error;

Expand All @@ -75,8 +76,9 @@ TargetHostInterfaceRoster::DeleteDefault()


status_t
TargetHostInterfaceRoster::Init()
TargetHostInterfaceRoster::Init(Listener* listener)
{
fListener = listener;
return fLock.InitCheck();
}

Expand Down Expand Up @@ -161,13 +163,15 @@ void
TargetHostInterfaceRoster::TeamDebuggerStarted(TeamDebugger* debugger)
{
fRunningTeamDebuggers++;
fListener->TeamDebuggerCountChanged(fRunningTeamDebuggers);
}


void
TargetHostInterfaceRoster::TeamDebuggerQuit(TeamDebugger* debugger)
{
fRunningTeamDebuggers--;
fListener->TeamDebuggerCountChanged(fRunningTeamDebuggers);
}


Expand All @@ -178,3 +182,17 @@ TargetHostInterfaceRoster::TargetHostInterfaceQuit(
AutoLocker<TargetHostInterfaceRoster> locker(this);
fActiveInterfaces.RemoveItem(interface);
}


// #pragma mark - TargetHostInterfaceRoster::Listener


TargetHostInterfaceRoster::Listener::~Listener()
{
}


void
TargetHostInterfaceRoster::Listener::TeamDebuggerCountChanged(int32 count)
{
}
Expand Up @@ -19,17 +19,18 @@ class TargetHostInterfaceInfo;

class TargetHostInterfaceRoster : private TargetHostInterface::Listener {
public:
class Listener;
TargetHostInterfaceRoster();
virtual ~TargetHostInterfaceRoster();

static TargetHostInterfaceRoster* Default();
static status_t CreateDefault();
static status_t CreateDefault(Listener* listener);
static void DeleteDefault();

bool Lock() { return fLock.Lock(); }
void Unlock() { fLock.Unlock(); }

status_t Init();
status_t Init(Listener* listener);
status_t RegisterInterfaceInfos();

int32 CountInterfaceInfos() const;
Expand Down Expand Up @@ -63,6 +64,15 @@ class TargetHostInterfaceRoster : private TargetHostInterface::Listener {
int32 fRunningTeamDebuggers;
InfoList fInterfaceInfos;
InterfaceList fActiveInterfaces;
Listener* fListener;
};


class TargetHostInterfaceRoster::Listener {
public:
virtual ~Listener();

virtual void TeamDebuggerCountChanged(int32 newCount);
};


Expand Down

0 comments on commit aed5c39

Please sign in to comment.