From d9e4b4cec5073d13408bbac2d104f378c140b96c Mon Sep 17 00:00:00 2001 From: Rene Gollent Date: Wed, 6 Apr 2016 20:58:01 -0400 Subject: [PATCH] Debugger: Add initial version of TargetHostInterfaceRoster. 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. --- src/apps/debugger/Jamfile | 7 +- .../TargetHostInterface.h | 3 +- .../TargetHostInterfaceInfo.cpp | 18 ++++ .../TargetHostInterfaceInfo.h | 40 +++++++ .../TargetHostInterfaceRoster.cpp | 101 ++++++++++++++++++ .../TargetHostInterfaceRoster.h | 55 ++++++++++ .../LocalTargetHostInterface.cpp | 2 +- .../LocalTargetHostInterface.h | 2 +- .../local/LocalTargetHostInterfaceInfo.cpp | 72 +++++++++++++ .../local/LocalTargetHostInterfaceInfo.h | 29 +++++ .../gui/teams_window/TeamsWindow.cpp | 2 +- 11 files changed, 325 insertions(+), 6 deletions(-) create mode 100644 src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.cpp create mode 100644 src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.h rename src/apps/debugger/target_host_interface/{interfaces => local}/LocalTargetHostInterface.cpp (98%) rename src/apps/debugger/target_host_interface/{interfaces => local}/LocalTargetHostInterface.h (95%) create mode 100644 src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.cpp create mode 100644 src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.h diff --git a/src/apps/debugger/Jamfile b/src/apps/debugger/Jamfile index 7b49c77bb1a..15f0c2bc393 100644 --- a/src/apps/debugger/Jamfile +++ b/src/apps/debugger/Jamfile @@ -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 ] ; @@ -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 diff --git a/src/apps/debugger/target_host_interface/TargetHostInterface.h b/src/apps/debugger/target_host_interface/TargetHostInterface.h index d6ad373978c..d7d95d8f84f 100644 --- a/src/apps/debugger/target_host_interface/TargetHostInterface.h +++ b/src/apps/debugger/target_host_interface/TargetHostInterface.h @@ -13,6 +13,7 @@ class DebuggerInterface; +class Settings; class TargetHost; class TeamDebugger; @@ -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; diff --git a/src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.cpp b/src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.cpp new file mode 100644 index 00000000000..bc9dcd50f5d --- /dev/null +++ b/src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.cpp @@ -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() +{ +} diff --git a/src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.h b/src/apps/debugger/target_host_interface/TargetHostInterfaceInfo.h new file mode 100644 index 00000000000..a853c8a21c5 --- /dev/null +++ b/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 + +#include +#include + + +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 diff --git a/src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.cpp b/src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.cpp index e69de29bb2d..a44324dde7c 100644 --- a/src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.cpp +++ b/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 + +#include + +#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 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 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; +} diff --git a/src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.h b/src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.h index e69de29bb2d..2a1689269f3 100644 --- a/src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.h +++ b/src/apps/debugger/target_host_interface/TargetHostInterfaceRoster.h @@ -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 + +#include +#include + + +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 InfoList; + typedef BObjectList InterfaceList; + +private: + BLocker fLock; + static TargetHostInterfaceRoster* sDefaultInstance; + + InfoList fInterfaceInfos; + InterfaceList fActiveInterfaces; +}; + + +#endif // TARGET_HOST_INTERFACE_ROSTER_H diff --git a/src/apps/debugger/target_host_interface/interfaces/LocalTargetHostInterface.cpp b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterface.cpp similarity index 98% rename from src/apps/debugger/target_host_interface/interfaces/LocalTargetHostInterface.cpp rename to src/apps/debugger/target_host_interface/local/LocalTargetHostInterface.cpp index d1064787f70..b25cece5fbb 100644 --- a/src/apps/debugger/target_host_interface/interfaces/LocalTargetHostInterface.cpp +++ b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterface.cpp @@ -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)); diff --git a/src/apps/debugger/target_host_interface/interfaces/LocalTargetHostInterface.h b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterface.h similarity index 95% rename from src/apps/debugger/target_host_interface/interfaces/LocalTargetHostInterface.h rename to src/apps/debugger/target_host_interface/local/LocalTargetHostInterface.h index 41bee898476..00f02eedf0d 100644 --- a/src/apps/debugger/target_host_interface/interfaces/LocalTargetHostInterface.h +++ b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterface.h @@ -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; diff --git a/src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.cpp b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.cpp new file mode 100644 index 00000000000..5ac0f128d31 --- /dev/null +++ b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.cpp @@ -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 interfaceReference(interface, true); + status_t error = interface->Init(settings); + if (error != B_OK) + return error; + + _interface = interface; + interfaceReference.Detach(); + + return B_OK; +} + diff --git a/src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.h b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.h new file mode 100644 index 00000000000..dc92bcfa7a9 --- /dev/null +++ b/src/apps/debugger/target_host_interface/local/LocalTargetHostInterfaceInfo.h @@ -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 diff --git a/src/apps/debugger/user_interface/gui/teams_window/TeamsWindow.cpp b/src/apps/debugger/user_interface/gui/teams_window/TeamsWindow.cpp index 130b7af017c..53d599dae32 100644 --- a/src/apps/debugger/user_interface/gui/teams_window/TeamsWindow.cpp +++ b/src/apps/debugger/user_interface/gui/teams_window/TeamsWindow.cpp @@ -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;