2006-10-19 15:24:57 +04:00
|
|
|
/*
|
2015-02-18 20:26:52 +03:00
|
|
|
* Copyright 2006-2015, Haiku, Inc. All Rights Reserved.
|
2006-10-19 15:24:57 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Axel Dörfler, axeld@pinc-software.de
|
|
|
|
*/
|
|
|
|
#ifndef SETTINGS_H
|
|
|
|
#define SETTINGS_H
|
|
|
|
|
|
|
|
|
2015-02-26 15:05:21 +03:00
|
|
|
#include <vector>
|
|
|
|
|
2006-10-19 15:24:57 +04:00
|
|
|
#include <Message.h>
|
2006-10-19 17:37:13 +04:00
|
|
|
#include <Messenger.h>
|
2015-02-26 15:05:21 +03:00
|
|
|
#include <NetworkAddress.h>
|
2013-09-30 03:11:23 +04:00
|
|
|
#include <Path.h>
|
2015-02-26 15:05:21 +03:00
|
|
|
#include <StringList.h>
|
2006-10-19 15:24:57 +04:00
|
|
|
|
|
|
|
|
2015-02-18 20:26:52 +03:00
|
|
|
namespace BNetworkKit {
|
|
|
|
|
|
|
|
|
2015-03-05 15:54:35 +03:00
|
|
|
class BNetworkInterfaceSettings;
|
|
|
|
|
|
|
|
|
2015-02-18 20:26:52 +03:00
|
|
|
class BNetworkSettings {
|
2010-06-11 11:29:16 +04:00
|
|
|
public:
|
2015-02-18 20:26:52 +03:00
|
|
|
static const uint32 kMsgInterfaceSettingsUpdated = 'SUif';
|
2015-02-26 15:05:21 +03:00
|
|
|
static const uint32 kMsgNetworkSettingsUpdated = 'SUnw';
|
2015-02-18 20:26:52 +03:00
|
|
|
static const uint32 kMsgServiceSettingsUpdated = 'SUsv';
|
|
|
|
|
|
|
|
public:
|
|
|
|
BNetworkSettings();
|
|
|
|
~BNetworkSettings();
|
2010-06-11 11:29:16 +04:00
|
|
|
|
|
|
|
status_t GetNextInterface(uint32& cookie,
|
|
|
|
BMessage& interface);
|
2015-02-19 20:33:23 +03:00
|
|
|
status_t GetInterface(const char* name,
|
|
|
|
BMessage& interface);
|
2015-02-18 20:26:52 +03:00
|
|
|
status_t AddInterface(const BMessage& interface);
|
|
|
|
status_t RemoveInterface(const char* name);
|
2015-03-05 15:54:35 +03:00
|
|
|
BNetworkInterfaceSettings
|
|
|
|
Interface(const char* name);
|
2011-10-07 14:15:57 +04:00
|
|
|
|
2011-10-09 23:56:19 +04:00
|
|
|
int32 CountNetworks() const;
|
2010-12-09 03:11:15 +03:00
|
|
|
status_t GetNextNetwork(uint32& cookie,
|
2011-10-09 23:56:19 +04:00
|
|
|
BMessage& network) const;
|
2015-02-19 20:33:23 +03:00
|
|
|
status_t GetNetwork(const char* name,
|
|
|
|
BMessage& network);
|
2011-10-07 14:15:57 +04:00
|
|
|
status_t AddNetwork(const BMessage& network);
|
2011-10-09 23:56:19 +04:00
|
|
|
status_t RemoveNetwork(const char* name);
|
2011-10-07 14:15:57 +04:00
|
|
|
|
2015-02-19 20:33:23 +03:00
|
|
|
const BMessage& Services() const;
|
2010-06-11 11:29:16 +04:00
|
|
|
status_t GetNextService(uint32& cookie,
|
|
|
|
BMessage& service);
|
2015-02-19 20:33:23 +03:00
|
|
|
status_t GetService(const char* name, BMessage& service);
|
2015-02-18 20:26:52 +03:00
|
|
|
status_t AddService(const BMessage& service);
|
|
|
|
status_t RemoveService(const char* name);
|
2010-06-11 11:29:16 +04:00
|
|
|
|
|
|
|
status_t StartMonitoring(const BMessenger& target);
|
|
|
|
status_t StopMonitoring(const BMessenger& target);
|
|
|
|
|
|
|
|
status_t Update(BMessage* message);
|
|
|
|
|
|
|
|
private:
|
|
|
|
status_t _Load(const char* name = NULL,
|
|
|
|
uint32* _type = NULL);
|
2011-10-07 14:15:57 +04:00
|
|
|
status_t _Save(const char* name = NULL);
|
2013-09-30 03:11:23 +04:00
|
|
|
BPath _Path(BPath& parent, const char* name);
|
2010-06-11 11:29:16 +04:00
|
|
|
status_t _GetPath(const char* name, BPath& path);
|
|
|
|
|
|
|
|
status_t _StartWatching(const char* name,
|
|
|
|
const BMessenger& target);
|
2011-10-07 14:15:57 +04:00
|
|
|
|
2010-06-11 11:29:16 +04:00
|
|
|
bool _IsWatching(const BMessenger& target) const
|
|
|
|
{ return fListener == target; }
|
|
|
|
bool _IsWatching() const
|
|
|
|
{ return fListener.IsValid(); }
|
|
|
|
|
2015-02-18 20:26:52 +03:00
|
|
|
status_t _ConvertNetworkToSettings(BMessage& message);
|
|
|
|
status_t _ConvertNetworkFromSettings(BMessage& message);
|
2015-02-19 20:33:23 +03:00
|
|
|
|
|
|
|
status_t _GetItem(BMessage& container,
|
|
|
|
const char* itemField,
|
|
|
|
const char* nameField, const char* name,
|
|
|
|
int32& _index, BMessage& item);
|
2015-02-18 20:26:52 +03:00
|
|
|
status_t _RemoveItem(BMessage& container,
|
2015-02-19 20:33:23 +03:00
|
|
|
const char* itemField,
|
|
|
|
const char* nameField, const char* name,
|
|
|
|
const char* store = NULL);
|
2015-02-18 20:26:52 +03:00
|
|
|
|
2010-06-11 11:29:16 +04:00
|
|
|
private:
|
|
|
|
BMessenger fListener;
|
|
|
|
BMessage fInterfaces;
|
2010-12-14 01:24:39 +03:00
|
|
|
BMessage fNetworks;
|
2010-06-11 11:29:16 +04:00
|
|
|
BMessage fServices;
|
2006-10-19 15:24:57 +04:00
|
|
|
};
|
|
|
|
|
2010-06-11 11:29:16 +04:00
|
|
|
|
2015-02-26 15:05:21 +03:00
|
|
|
class BNetworkInterfaceAddressSettings {
|
|
|
|
public:
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkInterfaceAddressSettings();
|
2015-02-26 15:05:21 +03:00
|
|
|
BNetworkInterfaceAddressSettings(
|
|
|
|
const BMessage& data);
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkInterfaceAddressSettings(
|
|
|
|
const BNetworkInterfaceAddressSettings&
|
|
|
|
other);
|
2015-02-26 15:05:21 +03:00
|
|
|
~BNetworkInterfaceAddressSettings();
|
|
|
|
|
|
|
|
int Family() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
void SetFamily(int family);
|
2015-03-05 15:54:35 +03:00
|
|
|
bool IsAutoConfigure() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
void SetAutoConfigure(bool configure);
|
2015-02-26 15:05:21 +03:00
|
|
|
|
|
|
|
const BNetworkAddress&
|
|
|
|
Address() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkAddress& Address();
|
2015-02-26 15:05:21 +03:00
|
|
|
const BNetworkAddress&
|
|
|
|
Mask() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkAddress& Mask();
|
2015-02-26 15:05:21 +03:00
|
|
|
const BNetworkAddress&
|
|
|
|
Peer() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkAddress& Peer();
|
2015-02-26 15:05:21 +03:00
|
|
|
const BNetworkAddress&
|
|
|
|
Broadcast() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkAddress& Broadcast();
|
2015-02-26 15:05:21 +03:00
|
|
|
const BNetworkAddress&
|
|
|
|
Gateway() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkAddress& Gateway();
|
|
|
|
|
|
|
|
status_t GetMessage(BMessage& data) const;
|
|
|
|
|
|
|
|
BNetworkInterfaceAddressSettings&
|
|
|
|
operator=(
|
|
|
|
const BNetworkInterfaceAddressSettings&
|
|
|
|
other);
|
2015-02-26 15:05:21 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
int32 fFamily;
|
|
|
|
bool fAutoConfigure;
|
|
|
|
BNetworkAddress fAddress;
|
|
|
|
BNetworkAddress fMask;
|
|
|
|
BNetworkAddress fPeer;
|
|
|
|
BNetworkAddress fBroadcast;
|
|
|
|
BNetworkAddress fGateway;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BNetworkInterfaceSettings {
|
|
|
|
public:
|
2015-03-04 19:54:22 +03:00
|
|
|
BNetworkInterfaceSettings();
|
2015-02-26 15:05:21 +03:00
|
|
|
BNetworkInterfaceSettings(
|
|
|
|
const BMessage& message);
|
|
|
|
~BNetworkInterfaceSettings();
|
|
|
|
|
|
|
|
const char* Name() const;
|
2015-03-04 19:54:22 +03:00
|
|
|
void SetName(const char* name);
|
2015-02-26 15:05:21 +03:00
|
|
|
|
2015-03-04 19:54:22 +03:00
|
|
|
int32 Flags() const;
|
|
|
|
void SetFlags(int32 flags);
|
|
|
|
int32 MTU() const;
|
|
|
|
void SetMTU(int32 mtu);
|
|
|
|
int32 Metric() const;
|
|
|
|
void SetMetric(int32 metric);
|
|
|
|
|
|
|
|
int32 CountAddresses() const;
|
|
|
|
const BNetworkInterfaceAddressSettings&
|
|
|
|
AddressAt(int32 index) const;
|
|
|
|
BNetworkInterfaceAddressSettings&
|
|
|
|
AddressAt(int32 index);
|
2015-03-05 15:54:35 +03:00
|
|
|
int32 FindFirstAddress(int family) const;
|
2015-03-04 19:54:22 +03:00
|
|
|
void AddAddress(const
|
|
|
|
BNetworkInterfaceAddressSettings& address);
|
|
|
|
void RemoveAddress(int32 index);
|
2015-02-26 15:05:21 +03:00
|
|
|
|
2015-03-05 15:54:35 +03:00
|
|
|
bool IsAutoConfigure(int family) const;
|
|
|
|
|
2015-03-04 19:54:22 +03:00
|
|
|
status_t GetMessage(BMessage& data) const;
|
2015-02-26 15:05:21 +03:00
|
|
|
|
2015-03-04 19:54:22 +03:00
|
|
|
private:
|
|
|
|
BString fName;
|
|
|
|
int32 fFlags;
|
|
|
|
int32 fMTU;
|
|
|
|
int32 fMetric;
|
|
|
|
std::vector<BNetworkInterfaceAddressSettings>
|
|
|
|
fAddresses;
|
|
|
|
};
|
2006-10-19 17:37:13 +04:00
|
|
|
|
2010-06-11 11:29:16 +04:00
|
|
|
|
2015-02-26 15:05:21 +03:00
|
|
|
class BNetworkServiceAddressSettings {
|
|
|
|
public:
|
|
|
|
BNetworkServiceAddressSettings();
|
|
|
|
BNetworkServiceAddressSettings(
|
|
|
|
const BMessage& data, int family = -1,
|
|
|
|
int type = -1, int protocol = -1,
|
|
|
|
int port = -1);
|
|
|
|
~BNetworkServiceAddressSettings();
|
|
|
|
|
|
|
|
int Family() const;
|
|
|
|
void SetFamily(int family);
|
|
|
|
int Protocol() const;
|
|
|
|
void SetProtocol(int protocol);
|
|
|
|
int Type() const;
|
|
|
|
void SetType(int type);
|
|
|
|
|
|
|
|
const BNetworkAddress&
|
|
|
|
Address() const;
|
|
|
|
BNetworkAddress& Address();
|
|
|
|
|
2015-03-04 19:54:22 +03:00
|
|
|
status_t GetMessage(BMessage& data) const;
|
2015-02-26 15:05:21 +03:00
|
|
|
|
|
|
|
bool operator==(
|
|
|
|
const BNetworkServiceAddressSettings& other)
|
|
|
|
const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32 fFamily;
|
|
|
|
int fProtocol;
|
|
|
|
int fType;
|
|
|
|
BNetworkAddress fAddress;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BNetworkServiceSettings {
|
|
|
|
public:
|
|
|
|
BNetworkServiceSettings(
|
|
|
|
const BMessage& message);
|
|
|
|
~BNetworkServiceSettings();
|
|
|
|
|
|
|
|
status_t InitCheck() const;
|
|
|
|
|
|
|
|
const char* Name() const;
|
|
|
|
bool IsStandAlone() const;
|
|
|
|
|
|
|
|
int32 CountArguments() const;
|
|
|
|
const char* ArgumentAt(int32 index) const;
|
|
|
|
|
|
|
|
int32 CountAddresses() const;
|
|
|
|
const BNetworkServiceAddressSettings&
|
|
|
|
AddressAt(int32 index) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const BMessage& fData;
|
|
|
|
BStringList fArguments;
|
|
|
|
std::vector<BNetworkServiceAddressSettings>
|
|
|
|
fAddresses;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-04 19:54:22 +03:00
|
|
|
} // namespace BNetworkKit
|
|
|
|
|
|
|
|
|
2006-10-19 15:24:57 +04:00
|
|
|
#endif // SETTINGS_H
|