Skip to content

Commit

Permalink
Debugger: Add initial version of TargetHostInterfaceRoster.
Browse files Browse the repository at this point in the history
TargetHostInterfaceRoster:
- Provides a singleton interface to enumerate both the available interface
  types, and all currently running instances. This will provide clients like
  the TeamsWindow with a way to present the user with all available types,
  as well as the necessary information to configure/instantiate them.

TargetHostInterfaceInfo:
- Provides an information object for each available type of interface,
  including an optional description of the settings needed to configure it.
  Callers can then use this to provide a configuration UI as needed, and
  once complete, request a corresponding interface instance for the desired
  configuration.

{Local}TargetHostInterface:
- Add Settings parameter to Init(). Adjust LocalTargetHostInterface
  accordingly.

LocalTargetHostInterfaceInfo:
- Implementation of TargetHostInterfaceInfo for the local system case.
  • Loading branch information
anevilyak committed Apr 10, 2016
1 parent 7442abd commit d9e4b4c
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/apps/debugger/Jamfile
Expand Up @@ -35,7 +35,7 @@ SEARCH_SOURCE += [ FDirName $(SUBDIR) source_language ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) source_language c_family ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) source_language x86 ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) target_host_interface ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) target_host_interface interfaces ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) target_host_interface local ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) types ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface ] ;
SEARCH_SOURCE += [ FDirName $(SUBDIR) user_interface cli ] ;
Expand Down Expand Up @@ -244,9 +244,12 @@ local sources =

# target_host_interface
TargetHostInterface.cpp
TargetHostInterfaceInfo.cpp
TargetHostInterfaceRoster.cpp

# target_host_interface/interfaces
# target_host_interface/local
LocalTargetHostInterface.cpp
LocalTargetHostInterfaceInfo.cpp

# types
ArrayIndexPath.cpp
Expand Down
Expand Up @@ -13,6 +13,7 @@


class DebuggerInterface;
class Settings;
class TargetHost;
class TeamDebugger;

Expand All @@ -32,7 +33,7 @@ class TargetHostInterface : public BReferenceable {
status_t AddTeamDebugger(TeamDebugger* debugger);
void RemoveTeamDebugger(TeamDebugger* debugger);

virtual status_t Init() = 0;
virtual status_t Init(Settings* settings) = 0;
virtual void Close() = 0;

virtual bool Connected() const = 0;
Expand Down
@@ -0,0 +1,18 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "TargetHostInterfaceInfo.h"


TargetHostInterfaceInfo::TargetHostInterfaceInfo(const BString& name)
:
BReferenceable(),
fName(name)
{
}


TargetHostInterfaceInfo::~TargetHostInterfaceInfo()
{
}
40 changes: 40 additions & 0 deletions src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.h
@@ -0,0 +1,40 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TARGET_HOST_INTERFACE_INFO_H
#define TARGET_HOST_INTERFACE_INFO_H

#include <String.h>

#include <Referenceable.h>
#include <util/DoublyLinkedList.h>


class Settings;
class SettingsDescription;
class TargetHostInterface;


class TargetHostInterfaceInfo : public BReferenceable {
public:
TargetHostInterfaceInfo(const BString& name);
virtual ~TargetHostInterfaceInfo();

const BString& Name() const { return fName; }

virtual status_t Init() = 0;

virtual bool IsLocal() const = 0;
virtual bool IsConfigured(Settings* settings) const = 0;
virtual SettingsDescription* GetSettingsDescription() const = 0;

virtual status_t CreateInterface(Settings* settings,
TargetHostInterface*& _interface) const
= 0;

private:
BString fName;
};

#endif // TARGET_HOST_INTERFACE_INFO_H
101 changes: 101 additions & 0 deletions src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.cpp
@@ -0,0 +1,101 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "TargetHostInterfaceRoster.h"

#include <new>

#include <AutoDeleter.h>

#include "LocalTargetHostInterfaceInfo.h"
#include "TargetHostInterface.h"
#include "TargetHostInterfaceInfo.h"


/*static*/ TargetHostInterfaceRoster*
TargetHostInterfaceRoster::sDefaultInstance = NULL;


TargetHostInterfaceRoster::TargetHostInterfaceRoster()
:
fLock(),
fInterfaceInfos(20, false),
fActiveInterfaces(20, false)
{
}


TargetHostInterfaceRoster::~TargetHostInterfaceRoster()
{
}


/*static*/ TargetHostInterfaceRoster*
TargetHostInterfaceRoster::Default()
{
return sDefaultInstance;
}


/*static*/ status_t
TargetHostInterfaceRoster::CreateDefault()
{
if (sDefaultInstance != NULL)
return B_OK;

TargetHostInterfaceRoster* roster
= new(std::nothrow) TargetHostInterfaceRoster;
if (roster == NULL)
return B_NO_MEMORY;
ObjectDeleter<TargetHostInterfaceRoster> rosterDeleter(roster);

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

error = roster->RegisterInterfaceInfos();
if (error != B_OK)
return error;

sDefaultInstance = rosterDeleter.Detach();
return B_OK;
}


/*static*/ void
TargetHostInterfaceRoster::DeleteDefault()
{
TargetHostInterfaceRoster* roster = sDefaultInstance;
sDefaultInstance = NULL;
delete roster;
}


status_t
TargetHostInterfaceRoster::Init()
{
return fLock.InitCheck();
}


status_t
TargetHostInterfaceRoster::RegisterInterfaceInfos()
{
TargetHostInterfaceInfo* info = NULL;
BReference<TargetHostInterfaceInfo> interfaceReference;

#undef REGISTER_INTERFACE_INFO
#define REGISTER_INTERFACE_INFO(type) \
info = new(std::nothrow) type##TargetHostInterfaceInfo; \
if (info == NULL) \
return B_NO_MEMORY; \
interfaceReference.SetTo(info, true); \
if (!fInterfaceInfos.AddItem(info)) \
return B_NO_MEMORY; \
interfaceReference.Detach();

REGISTER_INTERFACE_INFO(Local)

return B_OK;
}
@@ -0,0 +1,55 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef TARGET_HOST_INTERFACE_ROSTER_H
#define TARGET_HOST_INTERFACE_ROSTER_H

#include <OS.h>

#include <Locker.h>
#include <ObjectList.h>


class Settings;
class TargetHostInterface;
class TargetHostInterfaceInfo;


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

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

status_t Init();
status_t RegisterInterfaceInfos();

int32 CountInterfaceInfos();
TargetHostInterfaceInfo*
InterfaceInfoAt(int32 index) const;

status_t CreateInterface(TargetHostInterfaceInfo* info,
Settings* settings,
TargetHostInterface*& _interface) const;

int32 CountActiveInterfaces();
TargetHostInterface* ActiveInterfaceAt(int32 index) const;

private:
typedef BObjectList<TargetHostInterfaceInfo> InfoList;
typedef BObjectList<TargetHostInterface> InterfaceList;

private:
BLocker fLock;
static TargetHostInterfaceRoster* sDefaultInstance;

InfoList fInterfaceInfos;
InterfaceList fActiveInterfaces;
};


#endif // TARGET_HOST_INTERFACE_ROSTER_H
Expand Up @@ -40,7 +40,7 @@ LocalTargetHostInterface::~LocalTargetHostInterface()


status_t
LocalTargetHostInterface::Init()
LocalTargetHostInterface::Init(Settings* settings)
{
char hostname[HOST_NAME_MAX + 1];
status_t error = gethostname(hostname, sizeof(hostname));
Expand Down
Expand Up @@ -13,7 +13,7 @@ class LocalTargetHostInterface : public TargetHostInterface {
LocalTargetHostInterface();
virtual ~LocalTargetHostInterface();

virtual status_t Init();
virtual status_t Init(Settings* settings);
virtual void Close();

virtual bool Connected() const;
Expand Down
@@ -0,0 +1,72 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "LocalTargetHostInterfaceInfo.h"

#include "LocalTargetHostInterface.h"


LocalTargetHostInterfaceInfo::LocalTargetHostInterfaceInfo()
:
TargetHostInterfaceInfo("Local")
{
}


LocalTargetHostInterfaceInfo::~LocalTargetHostInterfaceInfo()
{
}


status_t
LocalTargetHostInterfaceInfo::Init()
{
return B_OK;
}


bool
LocalTargetHostInterfaceInfo::IsLocal() const
{
return true;
}


bool
LocalTargetHostInterfaceInfo::IsConfigured(Settings* settings) const
{
return true;
}


SettingsDescription*
LocalTargetHostInterfaceInfo::GetSettingsDescription() const
{
// the local interface requires no configuration, therefore
// it returns no settings description, and has no real work
// to do as far as settings validation is concerned.
return NULL;
}


status_t
LocalTargetHostInterfaceInfo::CreateInterface(Settings* settings,
TargetHostInterface*& _interface) const
{
LocalTargetHostInterface* interface
= new(std::nothrow) LocalTargetHostInterface;
if (interface == NULL)
return B_NO_MEMORY;

BReference<LocalTargetHostInterface> interfaceReference(interface, true);
status_t error = interface->Init(settings);
if (error != B_OK)
return error;

_interface = interface;
interfaceReference.Detach();

return B_OK;
}

@@ -0,0 +1,29 @@
/*
* Copyright 2016, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#ifndef LOCAL_TARGET_HOST_INTERFACE_INFO_H
#define LOCAL_TARGET_HOST_INTERFACE_INFO_H

#include "TargetHostInterfaceInfo.h"


class LocalTargetHostInterfaceInfo : public TargetHostInterfaceInfo {
public:
LocalTargetHostInterfaceInfo();
virtual ~LocalTargetHostInterfaceInfo();

virtual status_t Init();

virtual bool IsLocal() const;
virtual bool IsConfigured(Settings* settings) const;
virtual SettingsDescription* GetSettingsDescription() const;

virtual status_t CreateInterface(Settings* settings,
TargetHostInterface*& _interface) const;

private:
BString fName;
};

#endif // TARGET_HOST_INTERFACE_INFO_H
Expand Up @@ -148,7 +148,7 @@ TeamsWindow::_Init()

fTargetHostInterface = new LocalTargetHostInterface();

if (fTargetHostInterface->Init() != B_OK)
if (fTargetHostInterface->Init(NULL) != B_OK)
throw std::bad_alloc();

BRect frame;
Expand Down

0 comments on commit d9e4b4c

Please sign in to comment.