185fb1470SAxel Dörfler /*
285fb1470SAxel Dörfler * Copyright 2015 Haiku, Inc. All rights reserved.
385fb1470SAxel Dörfler * Distributed under the terms of the MIT License.
485fb1470SAxel Dörfler *
585fb1470SAxel Dörfler * Authors:
685fb1470SAxel Dörfler * Axel Dörfler, <axeld@pinc-software.de>
785fb1470SAxel Dörfler */
885fb1470SAxel Dörfler
985fb1470SAxel Dörfler
1085fb1470SAxel Dörfler #include <Catalog.h>
1185fb1470SAxel Dörfler #include <NetworkSettingsAddOn.h>
1285fb1470SAxel Dörfler #include <StringItem.h>
1385fb1470SAxel Dörfler
1485fb1470SAxel Dörfler #include "InterfaceAddressView.h"
1585fb1470SAxel Dörfler
1685fb1470SAxel Dörfler
1785fb1470SAxel Dörfler using namespace BNetworkKit;
1885fb1470SAxel Dörfler
1985fb1470SAxel Dörfler
2085fb1470SAxel Dörfler #undef B_TRANSLATION_CONTEXT
2185fb1470SAxel Dörfler #define B_TRANSLATION_CONTEXT "IPv4InterfaceAddOn"
2285fb1470SAxel Dörfler
2385fb1470SAxel Dörfler
2485fb1470SAxel Dörfler class IPv4InterfaceAddOn : public BNetworkSettingsAddOn {
2585fb1470SAxel Dörfler public:
262864e4daSAxel Dörfler IPv4InterfaceAddOn(image_id image,
272864e4daSAxel Dörfler BNetworkSettings& settings);
2885fb1470SAxel Dörfler virtual ~IPv4InterfaceAddOn();
2985fb1470SAxel Dörfler
3085fb1470SAxel Dörfler virtual BNetworkSettingsInterfaceItem*
3185fb1470SAxel Dörfler CreateNextInterfaceItem(uint32& cookie,
3285fb1470SAxel Dörfler const char* interface);
3385fb1470SAxel Dörfler };
3485fb1470SAxel Dörfler
3585fb1470SAxel Dörfler
3685fb1470SAxel Dörfler class IPv4InterfaceItem : public BNetworkSettingsInterfaceItem {
3785fb1470SAxel Dörfler public:
382864e4daSAxel Dörfler IPv4InterfaceItem(const char* interface,
392864e4daSAxel Dörfler BNetworkSettings& settings);
4085fb1470SAxel Dörfler virtual ~IPv4InterfaceItem();
4185fb1470SAxel Dörfler
4285fb1470SAxel Dörfler virtual BListItem* ListItem();
4385fb1470SAxel Dörfler virtual BView* View();
4485fb1470SAxel Dörfler
4585fb1470SAxel Dörfler virtual status_t Revert();
4685fb1470SAxel Dörfler virtual bool IsRevertable();
4785fb1470SAxel Dörfler
4807addd7eSAxel Dörfler virtual void ConfigurationUpdated(const BMessage& message);
4907addd7eSAxel Dörfler
5085fb1470SAxel Dörfler private:
512864e4daSAxel Dörfler BNetworkSettings& fSettings;
525274e9b0SAxel Dörfler BNetworkInterfaceListItem*
535274e9b0SAxel Dörfler fItem;
5485fb1470SAxel Dörfler InterfaceAddressView*
5585fb1470SAxel Dörfler fView;
5685fb1470SAxel Dörfler };
5785fb1470SAxel Dörfler
5885fb1470SAxel Dörfler
5985fb1470SAxel Dörfler // #pragma mark -
6085fb1470SAxel Dörfler
6185fb1470SAxel Dörfler
IPv4InterfaceItem(const char * interface,BNetworkSettings & settings)622864e4daSAxel Dörfler IPv4InterfaceItem::IPv4InterfaceItem(const char* interface,
632864e4daSAxel Dörfler BNetworkSettings& settings)
6485fb1470SAxel Dörfler :
6585fb1470SAxel Dörfler BNetworkSettingsInterfaceItem(interface),
662864e4daSAxel Dörfler fSettings(settings),
675274e9b0SAxel Dörfler fItem(new BNetworkInterfaceListItem(AF_INET, Interface(),
685274e9b0SAxel Dörfler B_TRANSLATE("IPv4"), settings)),
6985fb1470SAxel Dörfler fView(NULL)
7085fb1470SAxel Dörfler {
7185fb1470SAxel Dörfler }
7285fb1470SAxel Dörfler
7385fb1470SAxel Dörfler
~IPv4InterfaceItem()7485fb1470SAxel Dörfler IPv4InterfaceItem::~IPv4InterfaceItem()
7585fb1470SAxel Dörfler {
7685fb1470SAxel Dörfler if (fView->Parent() == NULL)
7785fb1470SAxel Dörfler delete fView;
7885fb1470SAxel Dörfler
7985fb1470SAxel Dörfler delete fItem;
8085fb1470SAxel Dörfler }
8185fb1470SAxel Dörfler
8285fb1470SAxel Dörfler
8385fb1470SAxel Dörfler BListItem*
ListItem()8485fb1470SAxel Dörfler IPv4InterfaceItem::ListItem()
8585fb1470SAxel Dörfler {
8685fb1470SAxel Dörfler return fItem;
8785fb1470SAxel Dörfler }
8885fb1470SAxel Dörfler
8985fb1470SAxel Dörfler
9085fb1470SAxel Dörfler BView*
View()9185fb1470SAxel Dörfler IPv4InterfaceItem::View()
9285fb1470SAxel Dörfler {
932864e4daSAxel Dörfler if (fView == NULL)
942864e4daSAxel Dörfler fView = new InterfaceAddressView(AF_INET, Interface(), fSettings);
952864e4daSAxel Dörfler
9685fb1470SAxel Dörfler return fView;
9785fb1470SAxel Dörfler }
9885fb1470SAxel Dörfler
9985fb1470SAxel Dörfler
10085fb1470SAxel Dörfler status_t
Revert()10185fb1470SAxel Dörfler IPv4InterfaceItem::Revert()
10285fb1470SAxel Dörfler {
103*6a290205SAxel Dörfler return fView != NULL ? fView->Revert() : B_OK;
10485fb1470SAxel Dörfler }
10585fb1470SAxel Dörfler
10685fb1470SAxel Dörfler
10785fb1470SAxel Dörfler bool
IsRevertable()10885fb1470SAxel Dörfler IPv4InterfaceItem::IsRevertable()
10985fb1470SAxel Dörfler {
110*6a290205SAxel Dörfler return fView != NULL ? fView->IsRevertable() : false;
11185fb1470SAxel Dörfler }
11285fb1470SAxel Dörfler
11385fb1470SAxel Dörfler
11407addd7eSAxel Dörfler void
ConfigurationUpdated(const BMessage & message)11507addd7eSAxel Dörfler IPv4InterfaceItem::ConfigurationUpdated(const BMessage& message)
11607addd7eSAxel Dörfler {
11707addd7eSAxel Dörfler if (fView != NULL)
11807addd7eSAxel Dörfler fView->ConfigurationUpdated(message);
11907addd7eSAxel Dörfler }
12007addd7eSAxel Dörfler
12107addd7eSAxel Dörfler
12285fb1470SAxel Dörfler // #pragma mark -
12385fb1470SAxel Dörfler
12485fb1470SAxel Dörfler
IPv4InterfaceAddOn(image_id image,BNetworkSettings & settings)1252864e4daSAxel Dörfler IPv4InterfaceAddOn::IPv4InterfaceAddOn(image_id image,
1262864e4daSAxel Dörfler BNetworkSettings& settings)
12785fb1470SAxel Dörfler :
1282864e4daSAxel Dörfler BNetworkSettingsAddOn(image, settings)
12985fb1470SAxel Dörfler {
13085fb1470SAxel Dörfler }
13185fb1470SAxel Dörfler
13285fb1470SAxel Dörfler
~IPv4InterfaceAddOn()13385fb1470SAxel Dörfler IPv4InterfaceAddOn::~IPv4InterfaceAddOn()
13485fb1470SAxel Dörfler {
13585fb1470SAxel Dörfler }
13685fb1470SAxel Dörfler
13785fb1470SAxel Dörfler
13885fb1470SAxel Dörfler BNetworkSettingsInterfaceItem*
CreateNextInterfaceItem(uint32 & cookie,const char * interface)13985fb1470SAxel Dörfler IPv4InterfaceAddOn::CreateNextInterfaceItem(uint32& cookie,
14085fb1470SAxel Dörfler const char* interface)
14185fb1470SAxel Dörfler {
14285fb1470SAxel Dörfler if (cookie++ == 0)
1432864e4daSAxel Dörfler return new IPv4InterfaceItem(interface, Settings());
14485fb1470SAxel Dörfler
14585fb1470SAxel Dörfler return NULL;
14685fb1470SAxel Dörfler }
14785fb1470SAxel Dörfler
14885fb1470SAxel Dörfler
14985fb1470SAxel Dörfler // #pragma mark -
15085fb1470SAxel Dörfler
15185fb1470SAxel Dörfler
15285fb1470SAxel Dörfler extern "C"
15385fb1470SAxel Dörfler BNetworkSettingsAddOn*
instantiate_network_settings_add_on(image_id image,BNetworkSettings & settings)1542864e4daSAxel Dörfler instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings)
15585fb1470SAxel Dörfler {
1562864e4daSAxel Dörfler return new IPv4InterfaceAddOn(image, settings);
15785fb1470SAxel Dörfler }
158