libdebugger: Add initial version of network interface.
[haiku.git] / src / kits / debugger / target_host_interface / network / NetworkTargetHostInterfaceInfo.cpp
blob30d30c369b67c77576743f06b8c4e429ad5a5d31
1 /*
2 * Copyright 2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "NetworkTargetHostInterfaceInfo.h"
7 #include <AutoDeleter.h>
9 #include "NetworkTargetHostInterface.h"
10 #include "SettingsDescription.h"
11 #include "Setting.h"
14 static const char* kHostnameSetting = "hostname";
15 static const char* kPortSetting = "port";
18 NetworkTargetHostInterfaceInfo::NetworkTargetHostInterfaceInfo()
20 TargetHostInterfaceInfo("Network"),
21 fDescription(NULL)
26 NetworkTargetHostInterfaceInfo::~NetworkTargetHostInterfaceInfo()
28 delete fDescription;
32 status_t
33 NetworkTargetHostInterfaceInfo::Init()
35 fDescription = new(std::nothrow) SettingsDescription;
36 if (fDescription == NULL)
37 return B_NO_MEMORY;
39 Setting* setting = new(std::nothrow) StringSettingImpl(kHostnameSetting,
40 "Hostname", "");
41 if (setting == NULL)
42 return B_NO_MEMORY;
43 ObjectDeleter<Setting> settingDeleter(setting);
44 if (!fDescription->AddSetting(setting))
45 return B_NO_MEMORY;
47 settingDeleter.Detach();
48 setting = new(std::nothrow) BoundedSettingImpl(kPortSetting, "Port",
49 (uint16)0, (uint16)65535, (uint16)8305);
50 if (setting == NULL)
51 return B_NO_MEMORY;
52 if (!fDescription->AddSetting(setting)) {
53 delete setting;
54 return B_NO_MEMORY;
57 return B_OK;
61 bool
62 NetworkTargetHostInterfaceInfo::IsLocal() const
64 return false;
68 bool
69 NetworkTargetHostInterfaceInfo::IsConfigured(Settings* settings) const
71 return true;
75 SettingsDescription*
76 NetworkTargetHostInterfaceInfo::GetSettingsDescription() const
78 return fDescription;
82 status_t
83 NetworkTargetHostInterfaceInfo::CreateInterface(Settings* settings,
84 TargetHostInterface*& _interface) const
86 NetworkTargetHostInterface* interface
87 = new(std::nothrow) NetworkTargetHostInterface;
88 if (interface == NULL)
89 return B_NO_MEMORY;
91 status_t error = interface->Init(settings);
92 if (error != B_OK) {
93 delete interface;
94 return error;
97 _interface = interface;
98 return B_OK;