Skip to content

Commit

Permalink
Debugger: Further additions to TargetHostInterface.
Browse files Browse the repository at this point in the history
TargetHostInterface:
- Provide interface for tracking list of TeamDebuggers attached to this
  particular interface instance. Will eventually replace the current
  mechanism where the Debugger app tracks this directly.

LocalTargetHostInterface:
- Cleanups.
  • Loading branch information
anevilyak committed Apr 10, 2016
1 parent 0421aa8 commit 7442abd
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 6 deletions.
71 changes: 70 additions & 1 deletion src/apps/debugger/target_host_interface/TargetHostInterface.cpp
Expand Up @@ -5,8 +5,16 @@

#include "TargetHostInterface.h"

#include "TeamDebugger.h"


TargetHostInterface::TargetHostInterface()
:
BReferenceable(),
fTeamDebuggers(20, false)
{
}

// #pragma mark - TargetHostInterface

TargetHostInterface::~TargetHostInterface()
{
Expand All @@ -18,3 +26,64 @@ TargetHostInterface::SetName(const BString& name)
{
fName = name;
}


int32
TargetHostInterface::CountTeamDebuggers() const
{
return fTeamDebuggers.CountItems();
}


TeamDebugger*
TargetHostInterface::TeamDebuggerAt(int32 index) const
{
return fTeamDebuggers.ItemAt(index);
}


TeamDebugger*
TargetHostInterface::FindTeamDebugger(team_id team) const
{
return fTeamDebuggers.BinarySearchByKey(team, &_FindDebuggerByKey);
}


status_t
TargetHostInterface::AddTeamDebugger(TeamDebugger* debugger)
{
if (!fTeamDebuggers.BinaryInsert(debugger, &_CompareDebuggers))
return B_NO_MEMORY;

return B_OK;
}


void
TargetHostInterface::RemoveTeamDebugger(TeamDebugger* debugger)
{
int32 index = fTeamDebuggers.BinarySearchIndexByKey(debugger->TeamID(),
&_FindDebuggerByKey);
if (index >= 0)
fTeamDebuggers.RemoveItemAt(index);
}


/*static*/ int
TargetHostInterface::_CompareDebuggers(const TeamDebugger* a,
const TeamDebugger* b)
{
return a->TeamID() < b->TeamID() ? -1 : 1;
}


/*static*/ int
TargetHostInterface::_FindDebuggerByKey(const team_id* team,
const TeamDebugger* debugger)
{
if (*team < debugger->TeamID())
return -1;
else if (*team > debugger->TeamID())
return 1;
return 0;
}
25 changes: 22 additions & 3 deletions src/apps/debugger/target_host_interface/TargetHostInterface.h
Expand Up @@ -8,23 +8,33 @@
#include <OS.h>
#include <String.h>

#include <ObjectList.h>
#include <Referenceable.h>


class DebuggerInterface;
class TargetHost;
class TeamDebugger;


class TargetHostInterface : public BReferenceable {
public:
TargetHostInterface();
virtual ~TargetHostInterface();

virtual status_t Init() = 0;
virtual void Close() = 0;

const BString& Name() const { return fName; }
void SetName(const BString& name);


int32 CountTeamDebuggers() const;
TeamDebugger* TeamDebuggerAt(int32 index) const;
TeamDebugger* FindTeamDebugger(team_id team) const;
status_t AddTeamDebugger(TeamDebugger* debugger);
void RemoveTeamDebugger(TeamDebugger* debugger);

virtual status_t Init() = 0;
virtual void Close() = 0;

virtual bool Connected() const = 0;

virtual TargetHost* GetTargetHost() = 0;
Expand All @@ -36,8 +46,17 @@ class TargetHostInterface : public BReferenceable {
const char* const* arguments,
DebuggerInterface*& _interface) = 0;

private:
static int _CompareDebuggers(const TeamDebugger* a,
const TeamDebugger* b);
static int _FindDebuggerByKey(const team_id* team,
const TeamDebugger* debugger);
private:
typedef BObjectList<TeamDebugger> TeamDebuggerList;

private:
BString fName;
TeamDebuggerList fTeamDebuggers;
};


Expand Down
Expand Up @@ -10,6 +10,8 @@
#include <stdio.h>
#include <unistd.h>

#include <image.h>

#include <AutoLocker.h>
#include <system_info.h>
#include <util/KMessage.h>
Expand Down
Expand Up @@ -7,8 +7,6 @@

#include "TargetHostInterface.h"

#include <Looper.h>


class LocalTargetHostInterface : public TargetHostInterface {
public:
Expand Down

0 comments on commit 7442abd

Please sign in to comment.