1fd55fb66SAxel Dörfler /* 2fd55fb66SAxel Dörfler * Copyright 2006-2015, Haiku, Inc. All Rights Reserved. 3fd55fb66SAxel Dörfler * Distributed under the terms of the MIT License. 4fd55fb66SAxel Dörfler * 5fd55fb66SAxel Dörfler * Authors: 6fd55fb66SAxel Dörfler * Axel Dörfler, axeld@pinc-software.de 7fd55fb66SAxel Dörfler */ 8fd55fb66SAxel Dörfler #ifndef SETTINGS_H 9fd55fb66SAxel Dörfler #define SETTINGS_H 10fd55fb66SAxel Dörfler 11fd55fb66SAxel Dörfler 12f16f9ee4SAxel Dörfler #include <vector> 13f16f9ee4SAxel Dörfler 14fd55fb66SAxel Dörfler #include <Message.h> 15fd55fb66SAxel Dörfler #include <Messenger.h> 16f16f9ee4SAxel Dörfler #include <NetworkAddress.h> 17fd55fb66SAxel Dörfler #include <Path.h> 18f16f9ee4SAxel Dörfler #include <StringList.h> 19fd55fb66SAxel Dörfler 20fd55fb66SAxel Dörfler 21fd55fb66SAxel Dörfler namespace BNetworkKit { 22fd55fb66SAxel Dörfler 23fd55fb66SAxel Dörfler 24b00dcbcaSAxel Dörfler class BNetworkInterfaceSettings; 257ca40f60SAxel Dörfler class BNetworkServiceSettings; 26b00dcbcaSAxel Dörfler 27b00dcbcaSAxel Dörfler 28fd55fb66SAxel Dörfler class BNetworkSettings { 29fd55fb66SAxel Dörfler public: 30fd55fb66SAxel Dörfler static const uint32 kMsgInterfaceSettingsUpdated = 'SUif'; 31f16f9ee4SAxel Dörfler static const uint32 kMsgNetworkSettingsUpdated = 'SUnw'; 32fd55fb66SAxel Dörfler static const uint32 kMsgServiceSettingsUpdated = 'SUsv'; 33fd55fb66SAxel Dörfler 34fd55fb66SAxel Dörfler public: 35fd55fb66SAxel Dörfler BNetworkSettings(); 36fd55fb66SAxel Dörfler ~BNetworkSettings(); 37fd55fb66SAxel Dörfler 38fd55fb66SAxel Dörfler status_t GetNextInterface(uint32& cookie, 39fd55fb66SAxel Dörfler BMessage& interface); 40d880e2d9SAxel Dörfler status_t GetInterface(const char* name, 41*f7ccc9afSAxel Dörfler BMessage& interface) const; 42fd55fb66SAxel Dörfler status_t AddInterface(const BMessage& interface); 43fd55fb66SAxel Dörfler status_t RemoveInterface(const char* name); 44b00dcbcaSAxel Dörfler BNetworkInterfaceSettings 45b00dcbcaSAxel Dörfler Interface(const char* name); 46*f7ccc9afSAxel Dörfler const BNetworkInterfaceSettings 47*f7ccc9afSAxel Dörfler Interface(const char* name) const; 48fd55fb66SAxel Dörfler 49fd55fb66SAxel Dörfler int32 CountNetworks() const; 50fd55fb66SAxel Dörfler status_t GetNextNetwork(uint32& cookie, 51fd55fb66SAxel Dörfler BMessage& network) const; 52d880e2d9SAxel Dörfler status_t GetNetwork(const char* name, 53*f7ccc9afSAxel Dörfler BMessage& network) const; 54fd55fb66SAxel Dörfler status_t AddNetwork(const BMessage& network); 55fd55fb66SAxel Dörfler status_t RemoveNetwork(const char* name); 56fd55fb66SAxel Dörfler 57d880e2d9SAxel Dörfler const BMessage& Services() const; 58fd55fb66SAxel Dörfler status_t GetNextService(uint32& cookie, 59fd55fb66SAxel Dörfler BMessage& service); 60*f7ccc9afSAxel Dörfler status_t GetService(const char* name, 61*f7ccc9afSAxel Dörfler BMessage& service) const; 62fd55fb66SAxel Dörfler status_t AddService(const BMessage& service); 63fd55fb66SAxel Dörfler status_t RemoveService(const char* name); 647ca40f60SAxel Dörfler BNetworkServiceSettings 657ca40f60SAxel Dörfler Service(const char* name); 66*f7ccc9afSAxel Dörfler const BNetworkServiceSettings 67*f7ccc9afSAxel Dörfler Service(const char* name) const; 68fd55fb66SAxel Dörfler 69fd55fb66SAxel Dörfler status_t StartMonitoring(const BMessenger& target); 70fd55fb66SAxel Dörfler status_t StopMonitoring(const BMessenger& target); 71fd55fb66SAxel Dörfler 72fd55fb66SAxel Dörfler status_t Update(BMessage* message); 73fd55fb66SAxel Dörfler 74fd55fb66SAxel Dörfler private: 75fd55fb66SAxel Dörfler status_t _Load(const char* name = NULL, 76fd55fb66SAxel Dörfler uint32* _type = NULL); 77fd55fb66SAxel Dörfler status_t _Save(const char* name = NULL); 78fd55fb66SAxel Dörfler BPath _Path(BPath& parent, const char* name); 79fd55fb66SAxel Dörfler status_t _GetPath(const char* name, BPath& path); 80fd55fb66SAxel Dörfler 81fd55fb66SAxel Dörfler status_t _StartWatching(const char* name, 82fd55fb66SAxel Dörfler const BMessenger& target); 83fd55fb66SAxel Dörfler _IsWatching(const BMessenger & target)84fd55fb66SAxel Dörfler bool _IsWatching(const BMessenger& target) const 85fd55fb66SAxel Dörfler { return fListener == target; } _IsWatching()86fd55fb66SAxel Dörfler bool _IsWatching() const 87fd55fb66SAxel Dörfler { return fListener.IsValid(); } 88fd55fb66SAxel Dörfler 89fd55fb66SAxel Dörfler status_t _ConvertNetworkToSettings(BMessage& message); 90fd55fb66SAxel Dörfler status_t _ConvertNetworkFromSettings(BMessage& message); 91d880e2d9SAxel Dörfler 92*f7ccc9afSAxel Dörfler status_t _GetItem(const BMessage& container, 93d880e2d9SAxel Dörfler const char* itemField, 94d880e2d9SAxel Dörfler const char* nameField, const char* name, 95*f7ccc9afSAxel Dörfler int32& _index, BMessage& item) const; 96fd55fb66SAxel Dörfler status_t _RemoveItem(BMessage& container, 97d880e2d9SAxel Dörfler const char* itemField, 98d880e2d9SAxel Dörfler const char* nameField, const char* name, 99d880e2d9SAxel Dörfler const char* store = NULL); 100fd55fb66SAxel Dörfler 101fd55fb66SAxel Dörfler private: 102fd55fb66SAxel Dörfler BMessenger fListener; 103fd55fb66SAxel Dörfler BMessage fInterfaces; 104fd55fb66SAxel Dörfler BMessage fNetworks; 105fd55fb66SAxel Dörfler BMessage fServices; 106fd55fb66SAxel Dörfler }; 107fd55fb66SAxel Dörfler 108fd55fb66SAxel Dörfler 109f16f9ee4SAxel Dörfler class BNetworkInterfaceAddressSettings { 110f16f9ee4SAxel Dörfler public: 111e4f4658aSAxel Dörfler BNetworkInterfaceAddressSettings(); 112f16f9ee4SAxel Dörfler BNetworkInterfaceAddressSettings( 113f16f9ee4SAxel Dörfler const BMessage& data); 114e4f4658aSAxel Dörfler BNetworkInterfaceAddressSettings( 115e4f4658aSAxel Dörfler const BNetworkInterfaceAddressSettings& 116e4f4658aSAxel Dörfler other); 117f16f9ee4SAxel Dörfler ~BNetworkInterfaceAddressSettings(); 118f16f9ee4SAxel Dörfler 119f16f9ee4SAxel Dörfler int Family() const; 120e4f4658aSAxel Dörfler void SetFamily(int family); 121b00dcbcaSAxel Dörfler bool IsAutoConfigure() const; 122e4f4658aSAxel Dörfler void SetAutoConfigure(bool configure); 123f16f9ee4SAxel Dörfler 124f16f9ee4SAxel Dörfler const BNetworkAddress& 125f16f9ee4SAxel Dörfler Address() const; 126e4f4658aSAxel Dörfler BNetworkAddress& Address(); 127f16f9ee4SAxel Dörfler const BNetworkAddress& 128f16f9ee4SAxel Dörfler Mask() const; 129e4f4658aSAxel Dörfler BNetworkAddress& Mask(); 130f16f9ee4SAxel Dörfler const BNetworkAddress& 131f16f9ee4SAxel Dörfler Peer() const; 132e4f4658aSAxel Dörfler BNetworkAddress& Peer(); 133f16f9ee4SAxel Dörfler const BNetworkAddress& 134f16f9ee4SAxel Dörfler Broadcast() const; 135e4f4658aSAxel Dörfler BNetworkAddress& Broadcast(); 136f16f9ee4SAxel Dörfler const BNetworkAddress& 137f16f9ee4SAxel Dörfler Gateway() const; 138e4f4658aSAxel Dörfler BNetworkAddress& Gateway(); 139e4f4658aSAxel Dörfler 140e4f4658aSAxel Dörfler status_t GetMessage(BMessage& data) const; 141e4f4658aSAxel Dörfler 142e4f4658aSAxel Dörfler BNetworkInterfaceAddressSettings& 143e4f4658aSAxel Dörfler operator=( 144e4f4658aSAxel Dörfler const BNetworkInterfaceAddressSettings& 145e4f4658aSAxel Dörfler other); 146f16f9ee4SAxel Dörfler 147f16f9ee4SAxel Dörfler private: 148f16f9ee4SAxel Dörfler int32 fFamily; 149f16f9ee4SAxel Dörfler bool fAutoConfigure; 150f16f9ee4SAxel Dörfler BNetworkAddress fAddress; 151f16f9ee4SAxel Dörfler BNetworkAddress fMask; 152f16f9ee4SAxel Dörfler BNetworkAddress fPeer; 153f16f9ee4SAxel Dörfler BNetworkAddress fBroadcast; 154f16f9ee4SAxel Dörfler BNetworkAddress fGateway; 155f16f9ee4SAxel Dörfler }; 156f16f9ee4SAxel Dörfler 157f16f9ee4SAxel Dörfler 158f16f9ee4SAxel Dörfler class BNetworkInterfaceSettings { 159f16f9ee4SAxel Dörfler public: 160e4f4658aSAxel Dörfler BNetworkInterfaceSettings(); 161f16f9ee4SAxel Dörfler BNetworkInterfaceSettings( 162f16f9ee4SAxel Dörfler const BMessage& message); 163f16f9ee4SAxel Dörfler ~BNetworkInterfaceSettings(); 164f16f9ee4SAxel Dörfler 165f16f9ee4SAxel Dörfler const char* Name() const; 166e4f4658aSAxel Dörfler void SetName(const char* name); 167f16f9ee4SAxel Dörfler 168e4f4658aSAxel Dörfler int32 Flags() const; 169e4f4658aSAxel Dörfler void SetFlags(int32 flags); 170e4f4658aSAxel Dörfler int32 MTU() const; 171e4f4658aSAxel Dörfler void SetMTU(int32 mtu); 172e4f4658aSAxel Dörfler int32 Metric() const; 173e4f4658aSAxel Dörfler void SetMetric(int32 metric); 174e4f4658aSAxel Dörfler 175e4f4658aSAxel Dörfler int32 CountAddresses() const; 176e4f4658aSAxel Dörfler const BNetworkInterfaceAddressSettings& 177e4f4658aSAxel Dörfler AddressAt(int32 index) const; 178e4f4658aSAxel Dörfler BNetworkInterfaceAddressSettings& 179e4f4658aSAxel Dörfler AddressAt(int32 index); 180b00dcbcaSAxel Dörfler int32 FindFirstAddress(int family) const; 181e4f4658aSAxel Dörfler void AddAddress(const 182e4f4658aSAxel Dörfler BNetworkInterfaceAddressSettings& address); 183e4f4658aSAxel Dörfler void RemoveAddress(int32 index); 184e4f4658aSAxel Dörfler 185b00dcbcaSAxel Dörfler bool IsAutoConfigure(int family) const; 186b00dcbcaSAxel Dörfler 187e4f4658aSAxel Dörfler status_t GetMessage(BMessage& data) const; 188e4f4658aSAxel Dörfler 189e4f4658aSAxel Dörfler private: 190e4f4658aSAxel Dörfler BString fName; 191e4f4658aSAxel Dörfler int32 fFlags; 192e4f4658aSAxel Dörfler int32 fMTU; 193e4f4658aSAxel Dörfler int32 fMetric; 194e4f4658aSAxel Dörfler std::vector<BNetworkInterfaceAddressSettings> 195e4f4658aSAxel Dörfler fAddresses; 196f16f9ee4SAxel Dörfler }; 197f16f9ee4SAxel Dörfler 198f16f9ee4SAxel Dörfler 199f16f9ee4SAxel Dörfler class BNetworkServiceAddressSettings { 200f16f9ee4SAxel Dörfler public: 201f16f9ee4SAxel Dörfler BNetworkServiceAddressSettings(); 202f16f9ee4SAxel Dörfler BNetworkServiceAddressSettings( 203f16f9ee4SAxel Dörfler const BMessage& data, int family = -1, 204f16f9ee4SAxel Dörfler int type = -1, int protocol = -1, 205f16f9ee4SAxel Dörfler int port = -1); 206f16f9ee4SAxel Dörfler ~BNetworkServiceAddressSettings(); 207f16f9ee4SAxel Dörfler 208f16f9ee4SAxel Dörfler int Family() const; 209f16f9ee4SAxel Dörfler void SetFamily(int family); 210f16f9ee4SAxel Dörfler int Protocol() const; 211f16f9ee4SAxel Dörfler void SetProtocol(int protocol); 212f16f9ee4SAxel Dörfler int Type() const; 213f16f9ee4SAxel Dörfler void SetType(int type); 214f16f9ee4SAxel Dörfler 215f16f9ee4SAxel Dörfler const BNetworkAddress& 216f16f9ee4SAxel Dörfler Address() const; 217f16f9ee4SAxel Dörfler BNetworkAddress& Address(); 218f16f9ee4SAxel Dörfler 219e4f4658aSAxel Dörfler status_t GetMessage(BMessage& data) const; 220f16f9ee4SAxel Dörfler 221f16f9ee4SAxel Dörfler bool operator==( 222f16f9ee4SAxel Dörfler const BNetworkServiceAddressSettings& other) 223f16f9ee4SAxel Dörfler const; 224f16f9ee4SAxel Dörfler 225f16f9ee4SAxel Dörfler private: 226f16f9ee4SAxel Dörfler int32 fFamily; 227f16f9ee4SAxel Dörfler int fProtocol; 228f16f9ee4SAxel Dörfler int fType; 229f16f9ee4SAxel Dörfler BNetworkAddress fAddress; 230f16f9ee4SAxel Dörfler }; 231f16f9ee4SAxel Dörfler 232f16f9ee4SAxel Dörfler 233f16f9ee4SAxel Dörfler class BNetworkServiceSettings { 234f16f9ee4SAxel Dörfler public: 2351f94cdcdSAxel Dörfler BNetworkServiceSettings(); 236f16f9ee4SAxel Dörfler BNetworkServiceSettings( 237f16f9ee4SAxel Dörfler const BMessage& message); 238f16f9ee4SAxel Dörfler ~BNetworkServiceSettings(); 239f16f9ee4SAxel Dörfler 240f16f9ee4SAxel Dörfler status_t InitCheck() const; 241f16f9ee4SAxel Dörfler 242f16f9ee4SAxel Dörfler const char* Name() const; 2437ca40f60SAxel Dörfler void SetName(const char* name); 244f16f9ee4SAxel Dörfler bool IsStandAlone() const; 2457ca40f60SAxel Dörfler void SetStandAlone(bool alone); 2467ca40f60SAxel Dörfler bool IsEnabled() const; 2477ca40f60SAxel Dörfler void SetEnabled(bool enable); 2487ca40f60SAxel Dörfler 2497ca40f60SAxel Dörfler int Family() const; 2507ca40f60SAxel Dörfler void SetFamily(int family); 2517ca40f60SAxel Dörfler int Protocol() const; 2527ca40f60SAxel Dörfler void SetProtocol(int protocol); 2537ca40f60SAxel Dörfler int Type() const; 2547ca40f60SAxel Dörfler void SetType(int type); 2557ca40f60SAxel Dörfler int Port() const; 2567ca40f60SAxel Dörfler void SetPort(int port); 257f16f9ee4SAxel Dörfler 258f16f9ee4SAxel Dörfler int32 CountArguments() const; 259f16f9ee4SAxel Dörfler const char* ArgumentAt(int32 index) const; 2607ca40f60SAxel Dörfler void AddArgument(const char* argument); 2617ca40f60SAxel Dörfler void RemoveArgument(int32 index); 262f16f9ee4SAxel Dörfler 263f16f9ee4SAxel Dörfler int32 CountAddresses() const; 264f16f9ee4SAxel Dörfler const BNetworkServiceAddressSettings& 265f16f9ee4SAxel Dörfler AddressAt(int32 index) const; 2667ca40f60SAxel Dörfler void AddAddress(const 2677ca40f60SAxel Dörfler BNetworkServiceAddressSettings& address); 2687ca40f60SAxel Dörfler void RemoveAddress(int32 index); 2697ca40f60SAxel Dörfler 270*f7ccc9afSAxel Dörfler bool IsRunning() const; 271*f7ccc9afSAxel Dörfler 2727ca40f60SAxel Dörfler status_t GetMessage(BMessage& data) const; 273f16f9ee4SAxel Dörfler 274f16f9ee4SAxel Dörfler private: 2757ca40f60SAxel Dörfler BString fName; 2767ca40f60SAxel Dörfler int32 fFamily; 2777ca40f60SAxel Dörfler int32 fType; 2787ca40f60SAxel Dörfler int32 fProtocol; 2797ca40f60SAxel Dörfler int32 fPort; 2807ca40f60SAxel Dörfler bool fEnabled; 2817ca40f60SAxel Dörfler bool fStandAlone; 282f16f9ee4SAxel Dörfler BStringList fArguments; 283f16f9ee4SAxel Dörfler std::vector<BNetworkServiceAddressSettings> 284f16f9ee4SAxel Dörfler fAddresses; 285f16f9ee4SAxel Dörfler }; 286f16f9ee4SAxel Dörfler 287f16f9ee4SAxel Dörfler 288e4f4658aSAxel Dörfler } // namespace BNetworkKit 289e4f4658aSAxel Dörfler 290e4f4658aSAxel Dörfler 291fd55fb66SAxel Dörfler #endif // SETTINGS_H 292