2 * Copyright 2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
5 #include "TargetHostInterfaceRoster.h"
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()
23 fInterfaceInfos(20, false),
24 fActiveInterfaces(20, false)
29 TargetHostInterfaceRoster::~TargetHostInterfaceRoster()
34 /*static*/ TargetHostInterfaceRoster
*
35 TargetHostInterfaceRoster::Default()
37 return sDefaultInstance
;
42 TargetHostInterfaceRoster::CreateDefault()
44 if (sDefaultInstance
!= NULL
)
47 TargetHostInterfaceRoster
* roster
48 = new(std::nothrow
) TargetHostInterfaceRoster
;
51 ObjectDeleter
<TargetHostInterfaceRoster
> rosterDeleter(roster
);
53 status_t error
= roster
->Init();
57 error
= roster
->RegisterInterfaceInfos();
61 sDefaultInstance
= rosterDeleter
.Detach();
67 TargetHostInterfaceRoster::DeleteDefault()
69 TargetHostInterfaceRoster
* roster
= sDefaultInstance
;
70 sDefaultInstance
= NULL
;
76 TargetHostInterfaceRoster::Init()
78 return fLock
.InitCheck();
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; \
93 interfaceReference.SetTo(info, true); \
94 if (!fInterfaceInfos.AddItem(info)) \
96 interfaceReference.Detach();
98 REGISTER_INTERFACE_INFO(Local
)