Debugger: Add initial version of TargetHostInterfaceRoster.
[haiku.git] / src / apps / debugger / target_host_interface / TargetHostInterfaceRoster.cpp
bloba44324dde7c5da3e73d90c82d8d0a595a91422e9
1 /*
2 * Copyright 2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "TargetHostInterfaceRoster.h"
7 #include <new>
9 #include <AutoDeleter.h>
11 #include "LocalTargetHostInterfaceInfo.h"
12 #include "TargetHostInterface.h"
13 #include "TargetHostInterfaceInfo.h"
16 /*static*/ TargetHostInterfaceRoster*
17 TargetHostInterfaceRoster::sDefaultInstance = NULL;
20 TargetHostInterfaceRoster::TargetHostInterfaceRoster()
22 fLock(),
23 fInterfaceInfos(20, false),
24 fActiveInterfaces(20, false)
29 TargetHostInterfaceRoster::~TargetHostInterfaceRoster()
34 /*static*/ TargetHostInterfaceRoster*
35 TargetHostInterfaceRoster::Default()
37 return sDefaultInstance;
41 /*static*/ status_t
42 TargetHostInterfaceRoster::CreateDefault()
44 if (sDefaultInstance != NULL)
45 return B_OK;
47 TargetHostInterfaceRoster* roster
48 = new(std::nothrow) TargetHostInterfaceRoster;
49 if (roster == NULL)
50 return B_NO_MEMORY;
51 ObjectDeleter<TargetHostInterfaceRoster> rosterDeleter(roster);
53 status_t error = roster->Init();
54 if (error != B_OK)
55 return error;
57 error = roster->RegisterInterfaceInfos();
58 if (error != B_OK)
59 return error;
61 sDefaultInstance = rosterDeleter.Detach();
62 return B_OK;
66 /*static*/ void
67 TargetHostInterfaceRoster::DeleteDefault()
69 TargetHostInterfaceRoster* roster = sDefaultInstance;
70 sDefaultInstance = NULL;
71 delete roster;
75 status_t
76 TargetHostInterfaceRoster::Init()
78 return fLock.InitCheck();
82 status_t
83 TargetHostInterfaceRoster::RegisterInterfaceInfos()
85 TargetHostInterfaceInfo* info = NULL;
86 BReference<TargetHostInterfaceInfo> interfaceReference;
88 #undef REGISTER_INTERFACE_INFO
89 #define REGISTER_INTERFACE_INFO(type) \
90 info = new(std::nothrow) type##TargetHostInterfaceInfo; \
91 if (info == NULL) \
92 return B_NO_MEMORY; \
93 interfaceReference.SetTo(info, true); \
94 if (!fInterfaceInfos.AddItem(info)) \
95 return B_NO_MEMORY; \
96 interfaceReference.Detach();
98 REGISTER_INTERFACE_INFO(Local)
100 return B_OK;