1563f3c11SAxel Dörfler /*
2563f3c11SAxel Dörfler * Copyright 2015 Haiku, Inc. All rights reserved.
3563f3c11SAxel Dörfler * Distributed under the terms of the MIT License.
4563f3c11SAxel Dörfler *
5563f3c11SAxel Dörfler * Authors:
6563f3c11SAxel Dörfler * Axel Dörfler, <axeld@pinc-software.de>
7563f3c11SAxel Dörfler */
8563f3c11SAxel Dörfler
9563f3c11SAxel Dörfler
10563f3c11SAxel Dörfler #include <Catalog.h>
11563f3c11SAxel Dörfler #include <NetworkSettingsAddOn.h>
12563f3c11SAxel Dörfler #include <StringItem.h>
13563f3c11SAxel Dörfler
14563f3c11SAxel Dörfler #include "InterfaceAddressView.h"
15563f3c11SAxel Dörfler
16563f3c11SAxel Dörfler
17563f3c11SAxel Dörfler using namespace BNetworkKit;
18563f3c11SAxel Dörfler
19563f3c11SAxel Dörfler
20563f3c11SAxel Dörfler #undef B_TRANSLATION_CONTEXT
21563f3c11SAxel Dörfler #define B_TRANSLATION_CONTEXT "IPv6InterfaceAddOn"
22563f3c11SAxel Dörfler
23563f3c11SAxel Dörfler
24563f3c11SAxel Dörfler class IPv6InterfaceAddOn : public BNetworkSettingsAddOn {
25563f3c11SAxel Dörfler public:
26563f3c11SAxel Dörfler IPv6InterfaceAddOn(image_id image,
27563f3c11SAxel Dörfler BNetworkSettings& settings);
28563f3c11SAxel Dörfler virtual ~IPv6InterfaceAddOn();
29563f3c11SAxel Dörfler
30563f3c11SAxel Dörfler virtual BNetworkSettingsInterfaceItem*
31563f3c11SAxel Dörfler CreateNextInterfaceItem(uint32& cookie,
32563f3c11SAxel Dörfler const char* interface);
33563f3c11SAxel Dörfler };
34563f3c11SAxel Dörfler
35563f3c11SAxel Dörfler
36563f3c11SAxel Dörfler class IPv6InterfaceItem : public BNetworkSettingsInterfaceItem {
37563f3c11SAxel Dörfler public:
38563f3c11SAxel Dörfler IPv6InterfaceItem(const char* interface,
39563f3c11SAxel Dörfler BNetworkSettings& settings);
40563f3c11SAxel Dörfler virtual ~IPv6InterfaceItem();
41563f3c11SAxel Dörfler
42563f3c11SAxel Dörfler virtual BListItem* ListItem();
43563f3c11SAxel Dörfler virtual BView* View();
44563f3c11SAxel Dörfler
45563f3c11SAxel Dörfler virtual status_t Revert();
46563f3c11SAxel Dörfler virtual bool IsRevertable();
47563f3c11SAxel Dörfler
48563f3c11SAxel Dörfler virtual void ConfigurationUpdated(const BMessage& message);
49563f3c11SAxel Dörfler
50563f3c11SAxel Dörfler private:
51563f3c11SAxel Dörfler BNetworkSettings& fSettings;
525274e9b0SAxel Dörfler BNetworkInterfaceListItem*
535274e9b0SAxel Dörfler fItem;
54563f3c11SAxel Dörfler InterfaceAddressView*
55563f3c11SAxel Dörfler fView;
56563f3c11SAxel Dörfler };
57563f3c11SAxel Dörfler
58563f3c11SAxel Dörfler
59563f3c11SAxel Dörfler // #pragma mark -
60563f3c11SAxel Dörfler
61563f3c11SAxel Dörfler
IPv6InterfaceItem(const char * interface,BNetworkSettings & settings)62563f3c11SAxel Dörfler IPv6InterfaceItem::IPv6InterfaceItem(const char* interface,
63563f3c11SAxel Dörfler BNetworkSettings& settings)
64563f3c11SAxel Dörfler :
65563f3c11SAxel Dörfler BNetworkSettingsInterfaceItem(interface),
66563f3c11SAxel Dörfler fSettings(settings),
675274e9b0SAxel Dörfler fItem(new BNetworkInterfaceListItem(AF_INET6, Interface(),
685274e9b0SAxel Dörfler B_TRANSLATE("IPv6"), settings)),
69563f3c11SAxel Dörfler fView(NULL)
70563f3c11SAxel Dörfler {
71563f3c11SAxel Dörfler }
72563f3c11SAxel Dörfler
73563f3c11SAxel Dörfler
~IPv6InterfaceItem()74563f3c11SAxel Dörfler IPv6InterfaceItem::~IPv6InterfaceItem()
75563f3c11SAxel Dörfler {
76563f3c11SAxel Dörfler if (fView->Parent() == NULL)
77563f3c11SAxel Dörfler delete fView;
78563f3c11SAxel Dörfler
79563f3c11SAxel Dörfler delete fItem;
80563f3c11SAxel Dörfler }
81563f3c11SAxel Dörfler
82563f3c11SAxel Dörfler
83563f3c11SAxel Dörfler BListItem*
ListItem()84563f3c11SAxel Dörfler IPv6InterfaceItem::ListItem()
85563f3c11SAxel Dörfler {
86563f3c11SAxel Dörfler return fItem;
87563f3c11SAxel Dörfler }
88563f3c11SAxel Dörfler
89563f3c11SAxel Dörfler
90563f3c11SAxel Dörfler BView*
View()91563f3c11SAxel Dörfler IPv6InterfaceItem::View()
92563f3c11SAxel Dörfler {
93563f3c11SAxel Dörfler if (fView == NULL)
94563f3c11SAxel Dörfler fView = new InterfaceAddressView(AF_INET6, Interface(), fSettings);
95563f3c11SAxel Dörfler
96563f3c11SAxel Dörfler return fView;
97563f3c11SAxel Dörfler }
98563f3c11SAxel Dörfler
99563f3c11SAxel Dörfler
100563f3c11SAxel Dörfler status_t
Revert()101563f3c11SAxel Dörfler IPv6InterfaceItem::Revert()
102563f3c11SAxel Dörfler {
103*6a290205SAxel Dörfler return fView != NULL ? fView->Revert() : B_OK;
104563f3c11SAxel Dörfler }
105563f3c11SAxel Dörfler
106563f3c11SAxel Dörfler
107563f3c11SAxel Dörfler bool
IsRevertable()108563f3c11SAxel Dörfler IPv6InterfaceItem::IsRevertable()
109563f3c11SAxel Dörfler {
110*6a290205SAxel Dörfler return fView != NULL ? fView->IsRevertable() : false;
111563f3c11SAxel Dörfler }
112563f3c11SAxel Dörfler
113563f3c11SAxel Dörfler
114563f3c11SAxel Dörfler void
ConfigurationUpdated(const BMessage & message)115563f3c11SAxel Dörfler IPv6InterfaceItem::ConfigurationUpdated(const BMessage& message)
116563f3c11SAxel Dörfler {
117563f3c11SAxel Dörfler if (fView != NULL)
118563f3c11SAxel Dörfler fView->ConfigurationUpdated(message);
119563f3c11SAxel Dörfler }
120563f3c11SAxel Dörfler
121563f3c11SAxel Dörfler
122563f3c11SAxel Dörfler // #pragma mark -
123563f3c11SAxel Dörfler
124563f3c11SAxel Dörfler
IPv6InterfaceAddOn(image_id image,BNetworkSettings & settings)125563f3c11SAxel Dörfler IPv6InterfaceAddOn::IPv6InterfaceAddOn(image_id image,
126563f3c11SAxel Dörfler BNetworkSettings& settings)
127563f3c11SAxel Dörfler :
128563f3c11SAxel Dörfler BNetworkSettingsAddOn(image, settings)
129563f3c11SAxel Dörfler {
130563f3c11SAxel Dörfler }
131563f3c11SAxel Dörfler
132563f3c11SAxel Dörfler
~IPv6InterfaceAddOn()133563f3c11SAxel Dörfler IPv6InterfaceAddOn::~IPv6InterfaceAddOn()
134563f3c11SAxel Dörfler {
135563f3c11SAxel Dörfler }
136563f3c11SAxel Dörfler
137563f3c11SAxel Dörfler
138563f3c11SAxel Dörfler BNetworkSettingsInterfaceItem*
CreateNextInterfaceItem(uint32 & cookie,const char * interface)139563f3c11SAxel Dörfler IPv6InterfaceAddOn::CreateNextInterfaceItem(uint32& cookie,
140563f3c11SAxel Dörfler const char* interface)
141563f3c11SAxel Dörfler {
142563f3c11SAxel Dörfler if (cookie++ == 0)
143563f3c11SAxel Dörfler return new IPv6InterfaceItem(interface, Settings());
144563f3c11SAxel Dörfler
145563f3c11SAxel Dörfler return NULL;
146563f3c11SAxel Dörfler }
147563f3c11SAxel Dörfler
148563f3c11SAxel Dörfler
149563f3c11SAxel Dörfler // #pragma mark -
150563f3c11SAxel Dörfler
151563f3c11SAxel Dörfler
152563f3c11SAxel Dörfler extern "C"
153563f3c11SAxel Dörfler BNetworkSettingsAddOn*
instantiate_network_settings_add_on(image_id image,BNetworkSettings & settings)154563f3c11SAxel Dörfler instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings)
155563f3c11SAxel Dörfler {
156563f3c11SAxel Dörfler return new IPv6InterfaceAddOn(image, settings);
157563f3c11SAxel Dörfler }
158