xref: /haiku/src/add-ons/network_settings/ipv4/IPv4InterfaceAddOn.cpp (revision 07addd7ef5fdb7da7f12678e6038b84c9ccaed39)
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 
48*07addd7eSAxel Dörfler 	virtual void				ConfigurationUpdated(const BMessage& message);
49*07addd7eSAxel Dörfler 
5085fb1470SAxel Dörfler private:
512864e4daSAxel Dörfler 			BNetworkSettings&	fSettings;
5285fb1470SAxel Dörfler 			BStringItem*		fItem;
5385fb1470SAxel Dörfler 			InterfaceAddressView*
5485fb1470SAxel Dörfler 								fView;
5585fb1470SAxel Dörfler };
5685fb1470SAxel Dörfler 
5785fb1470SAxel Dörfler 
5885fb1470SAxel Dörfler // #pragma mark -
5985fb1470SAxel Dörfler 
6085fb1470SAxel Dörfler 
612864e4daSAxel Dörfler IPv4InterfaceItem::IPv4InterfaceItem(const char* interface,
622864e4daSAxel Dörfler 	BNetworkSettings& settings)
6385fb1470SAxel Dörfler 	:
6485fb1470SAxel Dörfler 	BNetworkSettingsInterfaceItem(interface),
652864e4daSAxel Dörfler 	fSettings(settings),
6685fb1470SAxel Dörfler 	fItem(new BStringItem(B_TRANSLATE("IPv4"))),
6785fb1470SAxel Dörfler 	fView(NULL)
6885fb1470SAxel Dörfler {
6985fb1470SAxel Dörfler }
7085fb1470SAxel Dörfler 
7185fb1470SAxel Dörfler 
7285fb1470SAxel Dörfler IPv4InterfaceItem::~IPv4InterfaceItem()
7385fb1470SAxel Dörfler {
7485fb1470SAxel Dörfler 	if (fView->Parent() == NULL)
7585fb1470SAxel Dörfler 		delete fView;
7685fb1470SAxel Dörfler 
7785fb1470SAxel Dörfler 	delete fItem;
7885fb1470SAxel Dörfler }
7985fb1470SAxel Dörfler 
8085fb1470SAxel Dörfler 
8185fb1470SAxel Dörfler BListItem*
8285fb1470SAxel Dörfler IPv4InterfaceItem::ListItem()
8385fb1470SAxel Dörfler {
8485fb1470SAxel Dörfler 	return fItem;
8585fb1470SAxel Dörfler }
8685fb1470SAxel Dörfler 
8785fb1470SAxel Dörfler 
8885fb1470SAxel Dörfler BView*
8985fb1470SAxel Dörfler IPv4InterfaceItem::View()
9085fb1470SAxel Dörfler {
912864e4daSAxel Dörfler 	if (fView == NULL)
922864e4daSAxel Dörfler 		fView = new InterfaceAddressView(AF_INET, Interface(), fSettings);
932864e4daSAxel Dörfler 
9485fb1470SAxel Dörfler 	return fView;
9585fb1470SAxel Dörfler }
9685fb1470SAxel Dörfler 
9785fb1470SAxel Dörfler 
9885fb1470SAxel Dörfler status_t
9985fb1470SAxel Dörfler IPv4InterfaceItem::Revert()
10085fb1470SAxel Dörfler {
10185fb1470SAxel Dörfler 	return B_OK;
10285fb1470SAxel Dörfler }
10385fb1470SAxel Dörfler 
10485fb1470SAxel Dörfler 
10585fb1470SAxel Dörfler bool
10685fb1470SAxel Dörfler IPv4InterfaceItem::IsRevertable()
10785fb1470SAxel Dörfler {
10885fb1470SAxel Dörfler 	return false;
10985fb1470SAxel Dörfler }
11085fb1470SAxel Dörfler 
11185fb1470SAxel Dörfler 
112*07addd7eSAxel Dörfler void
113*07addd7eSAxel Dörfler IPv4InterfaceItem::ConfigurationUpdated(const BMessage& message)
114*07addd7eSAxel Dörfler {
115*07addd7eSAxel Dörfler 	if (fView != NULL)
116*07addd7eSAxel Dörfler 		fView->ConfigurationUpdated(message);
117*07addd7eSAxel Dörfler }
118*07addd7eSAxel Dörfler 
119*07addd7eSAxel Dörfler 
12085fb1470SAxel Dörfler // #pragma mark -
12185fb1470SAxel Dörfler 
12285fb1470SAxel Dörfler 
1232864e4daSAxel Dörfler IPv4InterfaceAddOn::IPv4InterfaceAddOn(image_id image,
1242864e4daSAxel Dörfler 	BNetworkSettings& settings)
12585fb1470SAxel Dörfler 	:
1262864e4daSAxel Dörfler 	BNetworkSettingsAddOn(image, settings)
12785fb1470SAxel Dörfler {
12885fb1470SAxel Dörfler }
12985fb1470SAxel Dörfler 
13085fb1470SAxel Dörfler 
13185fb1470SAxel Dörfler IPv4InterfaceAddOn::~IPv4InterfaceAddOn()
13285fb1470SAxel Dörfler {
13385fb1470SAxel Dörfler }
13485fb1470SAxel Dörfler 
13585fb1470SAxel Dörfler 
13685fb1470SAxel Dörfler BNetworkSettingsInterfaceItem*
13785fb1470SAxel Dörfler IPv4InterfaceAddOn::CreateNextInterfaceItem(uint32& cookie,
13885fb1470SAxel Dörfler 	const char* interface)
13985fb1470SAxel Dörfler {
14085fb1470SAxel Dörfler 	if (cookie++ == 0)
1412864e4daSAxel Dörfler 		return new IPv4InterfaceItem(interface, Settings());
14285fb1470SAxel Dörfler 
14385fb1470SAxel Dörfler 	return NULL;
14485fb1470SAxel Dörfler }
14585fb1470SAxel Dörfler 
14685fb1470SAxel Dörfler 
14785fb1470SAxel Dörfler // #pragma mark -
14885fb1470SAxel Dörfler 
14985fb1470SAxel Dörfler 
15085fb1470SAxel Dörfler extern "C"
15185fb1470SAxel Dörfler BNetworkSettingsAddOn*
1522864e4daSAxel Dörfler instantiate_network_settings_add_on(image_id image, BNetworkSettings& settings)
15385fb1470SAxel Dörfler {
1542864e4daSAxel Dörfler 	return new IPv4InterfaceAddOn(image, settings);
15585fb1470SAxel Dörfler }
156