BNetworkSettings: made interface settings writable.
* It also makes use of the new driver settings converter mechanism.
This commit is contained in:
parent
18811c71ae
commit
e4f4658a1b
@ -95,23 +95,41 @@ private:
|
||||
|
||||
class BNetworkInterfaceAddressSettings {
|
||||
public:
|
||||
BNetworkInterfaceAddressSettings();
|
||||
BNetworkInterfaceAddressSettings(
|
||||
const BMessage& data);
|
||||
BNetworkInterfaceAddressSettings(
|
||||
const BNetworkInterfaceAddressSettings&
|
||||
other);
|
||||
~BNetworkInterfaceAddressSettings();
|
||||
|
||||
int Family() const;
|
||||
void SetFamily(int family);
|
||||
bool AutoConfigure() const;
|
||||
void SetAutoConfigure(bool configure);
|
||||
|
||||
const BNetworkAddress&
|
||||
Address() const;
|
||||
BNetworkAddress& Address();
|
||||
const BNetworkAddress&
|
||||
Mask() const;
|
||||
BNetworkAddress& Mask();
|
||||
const BNetworkAddress&
|
||||
Peer() const;
|
||||
BNetworkAddress& Peer();
|
||||
const BNetworkAddress&
|
||||
Broadcast() const;
|
||||
BNetworkAddress& Broadcast();
|
||||
const BNetworkAddress&
|
||||
Gateway() const;
|
||||
BNetworkAddress& Gateway();
|
||||
|
||||
status_t GetMessage(BMessage& data) const;
|
||||
|
||||
BNetworkInterfaceAddressSettings&
|
||||
operator=(
|
||||
const BNetworkInterfaceAddressSettings&
|
||||
other);
|
||||
|
||||
private:
|
||||
int32 fFamily;
|
||||
@ -126,18 +144,42 @@ private:
|
||||
|
||||
class BNetworkInterfaceSettings {
|
||||
public:
|
||||
BNetworkInterfaceSettings();
|
||||
BNetworkInterfaceSettings(
|
||||
const BMessage& message);
|
||||
~BNetworkInterfaceSettings();
|
||||
|
||||
const char* Name() const;
|
||||
void SetName(const char* name);
|
||||
|
||||
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);
|
||||
void AddAddress(const
|
||||
BNetworkInterfaceAddressSettings& address);
|
||||
void RemoveAddress(int32 index);
|
||||
|
||||
status_t GetMessage(BMessage& data) const;
|
||||
|
||||
private:
|
||||
BString fName;
|
||||
int32 fFlags;
|
||||
int32 fMTU;
|
||||
int32 fMetric;
|
||||
std::vector<BNetworkInterfaceAddressSettings>
|
||||
fAddresses;
|
||||
};
|
||||
|
||||
|
||||
} // namespace BNetworkKit
|
||||
|
||||
|
||||
class BNetworkServiceAddressSettings {
|
||||
public:
|
||||
BNetworkServiceAddressSettings();
|
||||
@ -158,7 +200,7 @@ public:
|
||||
Address() const;
|
||||
BNetworkAddress& Address();
|
||||
|
||||
status_t GetMessage(BMessage& data);
|
||||
status_t GetMessage(BMessage& data) const;
|
||||
|
||||
bool operator==(
|
||||
const BNetworkServiceAddressSettings& other)
|
||||
@ -198,4 +240,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} // namespace BNetworkKit
|
||||
|
||||
|
||||
#endif // SETTINGS_H
|
||||
|
@ -33,10 +33,31 @@ static const char* kInterfaceSettingsName = "interfaces";
|
||||
static const char* kServicesSettingsName = "services";
|
||||
static const char* kNetworksSettingsName = "wireless_networks";
|
||||
|
||||
|
||||
// Interface templates
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
|
||||
class InterfaceAddressFamilyConverter : public DriverSettingsConverter {
|
||||
public:
|
||||
virtual status_t ConvertFromDriverSettings(
|
||||
const driver_parameter& parameter,
|
||||
const char* name, uint32 type,
|
||||
BMessage& target);
|
||||
virtual status_t ConvertToDriverSettings(const BMessage& source,
|
||||
const char* name, int32 index,
|
||||
uint32 type, BString& value);
|
||||
};
|
||||
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
using BPrivate::InterfaceAddressFamilyConverter;
|
||||
|
||||
|
||||
const static settings_template kInterfaceAddressTemplate[] = {
|
||||
{B_STRING_TYPE, "family", NULL, true},
|
||||
{B_STRING_TYPE, "family", NULL, true, new InterfaceAddressFamilyConverter},
|
||||
{B_STRING_TYPE, "address", NULL},
|
||||
{B_STRING_TYPE, "mask", NULL},
|
||||
{B_STRING_TYPE, "peer", NULL},
|
||||
@ -138,6 +159,17 @@ static const address_family kFamilies[] = {
|
||||
};
|
||||
|
||||
|
||||
static const char*
|
||||
get_family_name(int family)
|
||||
{
|
||||
for (int32 i = 0; kFamilies[i].family >= 0; i++) {
|
||||
if (kFamilies[i].family == family)
|
||||
return kFamilies[i].name;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
get_address_family(const char* argument)
|
||||
{
|
||||
@ -229,6 +261,37 @@ type_for_protocol(int protocol)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
InterfaceAddressFamilyConverter::ConvertFromDriverSettings(
|
||||
const driver_parameter& parameter, const char* name, uint32 type,
|
||||
BMessage& target)
|
||||
{
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
InterfaceAddressFamilyConverter::ConvertToDriverSettings(const BMessage& source,
|
||||
const char* name, int32 index, uint32 type, BString& value)
|
||||
{
|
||||
int32 family;
|
||||
if (source.FindInt32("family", &family) == B_OK) {
|
||||
const char* familyName = get_family_name(family);
|
||||
if (familyName != NULL)
|
||||
value << familyName;
|
||||
else
|
||||
value << family;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
return B_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
BNetworkSettings::BNetworkSettings()
|
||||
{
|
||||
_Load();
|
||||
@ -791,6 +854,14 @@ BNetworkSettings::_RemoveItem(BMessage& container, const char* itemField,
|
||||
// #pragma mark - BNetworkInterfaceAddressSettings
|
||||
|
||||
|
||||
BNetworkInterfaceAddressSettings::BNetworkInterfaceAddressSettings()
|
||||
:
|
||||
fFamily(AF_UNSPEC),
|
||||
fAutoConfigure(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BNetworkInterfaceAddressSettings::BNetworkInterfaceAddressSettings(
|
||||
const BMessage& data)
|
||||
{
|
||||
@ -821,6 +892,20 @@ BNetworkInterfaceAddressSettings::BNetworkInterfaceAddressSettings(
|
||||
}
|
||||
|
||||
|
||||
BNetworkInterfaceAddressSettings::BNetworkInterfaceAddressSettings(
|
||||
const BNetworkInterfaceAddressSettings& other)
|
||||
:
|
||||
fFamily(other.fFamily),
|
||||
fAutoConfigure(other.fAutoConfigure),
|
||||
fAddress(other.fAddress),
|
||||
fMask(other.fMask),
|
||||
fPeer(other.fPeer),
|
||||
fBroadcast(other.fBroadcast),
|
||||
fGateway(other.fGateway)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BNetworkInterfaceAddressSettings::~BNetworkInterfaceAddressSettings()
|
||||
{
|
||||
}
|
||||
@ -833,6 +918,13 @@ BNetworkInterfaceAddressSettings::Family() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceAddressSettings::SetFamily(int family)
|
||||
{
|
||||
fFamily = family;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BNetworkInterfaceAddressSettings::AutoConfigure() const
|
||||
{
|
||||
@ -840,6 +932,13 @@ BNetworkInterfaceAddressSettings::AutoConfigure() const
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceAddressSettings::SetAutoConfigure(bool configure)
|
||||
{
|
||||
fAutoConfigure = configure;
|
||||
}
|
||||
|
||||
|
||||
const BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Address() const
|
||||
{
|
||||
@ -847,6 +946,13 @@ BNetworkInterfaceAddressSettings::Address() const
|
||||
}
|
||||
|
||||
|
||||
BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Address()
|
||||
{
|
||||
return fAddress;
|
||||
}
|
||||
|
||||
|
||||
const BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Mask() const
|
||||
{
|
||||
@ -854,6 +960,13 @@ BNetworkInterfaceAddressSettings::Mask() const
|
||||
}
|
||||
|
||||
|
||||
BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Mask()
|
||||
{
|
||||
return fMask;
|
||||
}
|
||||
|
||||
|
||||
const BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Peer() const
|
||||
{
|
||||
@ -861,6 +974,13 @@ BNetworkInterfaceAddressSettings::Peer() const
|
||||
}
|
||||
|
||||
|
||||
BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Peer()
|
||||
{
|
||||
return fPeer;
|
||||
}
|
||||
|
||||
|
||||
const BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Broadcast() const
|
||||
{
|
||||
@ -868,6 +988,13 @@ BNetworkInterfaceAddressSettings::Broadcast() const
|
||||
}
|
||||
|
||||
|
||||
BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Broadcast()
|
||||
{
|
||||
return fBroadcast;
|
||||
}
|
||||
|
||||
|
||||
const BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Gateway() const
|
||||
{
|
||||
@ -875,7 +1002,203 @@ BNetworkInterfaceAddressSettings::Gateway() const
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - BNetworkServiceAddress
|
||||
BNetworkAddress&
|
||||
BNetworkInterfaceAddressSettings::Gateway()
|
||||
{
|
||||
return fGateway;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BNetworkInterfaceAddressSettings::GetMessage(BMessage& data) const
|
||||
{
|
||||
status_t status = B_OK;
|
||||
if (fFamily != AF_UNSPEC)
|
||||
status = data.SetInt32("family", fFamily);
|
||||
if (status == B_OK && fAutoConfigure)
|
||||
return data.SetBool("auto_config", fAutoConfigure);
|
||||
|
||||
if (status == B_OK && !fAddress.IsEmpty()) {
|
||||
status = data.SetString("address", fAddress.ToString());
|
||||
if (status == B_OK && !fMask.IsEmpty())
|
||||
status = data.SetString("mask", fMask.ToString());
|
||||
}
|
||||
if (status == B_OK && !fPeer.IsEmpty())
|
||||
status = data.SetString("peer", fPeer.ToString());
|
||||
if (status == B_OK && !fBroadcast.IsEmpty())
|
||||
status = data.SetString("broadcast", fBroadcast.ToString());
|
||||
if (status == B_OK && !fGateway.IsEmpty())
|
||||
status = data.SetString("gateway", fGateway.ToString());
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
BNetworkInterfaceAddressSettings&
|
||||
BNetworkInterfaceAddressSettings::operator=(
|
||||
const BNetworkInterfaceAddressSettings& other)
|
||||
{
|
||||
fFamily = other.fFamily;
|
||||
fAutoConfigure = other.fAutoConfigure;
|
||||
fAddress = other.fAddress;
|
||||
fMask = other.fMask;
|
||||
fPeer = other.fPeer;
|
||||
fBroadcast = other.fBroadcast;
|
||||
fGateway = other.fGateway;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - BNetworkInterfaceSettings
|
||||
|
||||
|
||||
BNetworkInterfaceSettings::BNetworkInterfaceSettings()
|
||||
:
|
||||
fFlags(0),
|
||||
fMTU(0),
|
||||
fMetric(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BNetworkInterfaceSettings::BNetworkInterfaceSettings(const BMessage& message)
|
||||
{
|
||||
fName = message.GetString("device");
|
||||
fFlags = message.GetInt32("flags", 0);
|
||||
fMTU = message.GetInt32("mtu", 0);
|
||||
fMetric = message.GetInt32("metric", 0);
|
||||
|
||||
BMessage addressData;
|
||||
for (int32 index = 0; message.FindMessage("address", index,
|
||||
&addressData) == B_OK; index++) {
|
||||
BNetworkInterfaceAddressSettings address(addressData);
|
||||
fAddresses.push_back(address);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BNetworkInterfaceSettings::~BNetworkInterfaceSettings()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
BNetworkInterfaceSettings::Name() const
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceSettings::SetName(const char* name)
|
||||
{
|
||||
fName = name;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BNetworkInterfaceSettings::Flags() const
|
||||
{
|
||||
return fFlags;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceSettings::SetFlags(int32 flags)
|
||||
{
|
||||
fFlags = flags;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BNetworkInterfaceSettings::MTU() const
|
||||
{
|
||||
return fMTU;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceSettings::SetMTU(int32 mtu)
|
||||
{
|
||||
fMTU = mtu;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BNetworkInterfaceSettings::Metric() const
|
||||
{
|
||||
return fMetric;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceSettings::SetMetric(int32 metric)
|
||||
{
|
||||
fMetric = metric;
|
||||
}
|
||||
|
||||
|
||||
int32
|
||||
BNetworkInterfaceSettings::CountAddresses() const
|
||||
{
|
||||
return fAddresses.size();
|
||||
}
|
||||
|
||||
|
||||
const BNetworkInterfaceAddressSettings&
|
||||
BNetworkInterfaceSettings::AddressAt(int32 index) const
|
||||
{
|
||||
return fAddresses[index];
|
||||
}
|
||||
|
||||
|
||||
BNetworkInterfaceAddressSettings&
|
||||
BNetworkInterfaceSettings::AddressAt(int32 index)
|
||||
{
|
||||
return fAddresses[index];
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceSettings::AddAddress(
|
||||
const BNetworkInterfaceAddressSettings& address)
|
||||
{
|
||||
fAddresses.push_back(address);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BNetworkInterfaceSettings::RemoveAddress(int32 index)
|
||||
{
|
||||
fAddresses.erase(fAddresses.begin() + index);
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BNetworkInterfaceSettings::GetMessage(BMessage& data) const
|
||||
{
|
||||
status_t status = data.SetString("device", fName);
|
||||
if (status == B_OK && fFlags != 0)
|
||||
status = data.SetInt32("flags", fFlags);
|
||||
if (status == B_OK && fMTU != 0)
|
||||
status = data.SetInt32("mtu", fMTU);
|
||||
if (status == B_OK && fMetric != 0)
|
||||
status = data.SetInt32("metric", fMetric);
|
||||
|
||||
for (int32 i = 0; i < CountAddresses(); i++) {
|
||||
BMessage address;
|
||||
status = AddressAt(i).GetMessage(address);
|
||||
if (status == B_OK)
|
||||
status = data.AddMessage("address", &address);
|
||||
if (status != B_OK)
|
||||
break;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - BNetworkServiceAddressSettings
|
||||
|
||||
|
||||
BNetworkServiceAddressSettings::BNetworkServiceAddressSettings()
|
||||
@ -984,7 +1307,7 @@ BNetworkServiceAddressSettings::Address()
|
||||
|
||||
|
||||
status_t
|
||||
BNetworkServiceAddressSettings::GetMessage(BMessage& data)
|
||||
BNetworkServiceAddressSettings::GetMessage(BMessage& data) const
|
||||
{
|
||||
// TODO!
|
||||
return B_NOT_SUPPORTED;
|
||||
|
@ -24,6 +24,8 @@
|
||||
|
||||
|
||||
using namespace std;
|
||||
using namespace BNetworkKit;
|
||||
|
||||
|
||||
struct service_connection {
|
||||
struct service* owner;
|
||||
|
Loading…
x
Reference in New Issue
Block a user