123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- // netinterfaces.h :
- //
- #if !defined(AGD_NETINTERFACES_H__54DE87BE_1F3C_4914_A062_9CCFCB496122__INCLUDED_)
- #define AGD_NETINTERFACES_H__54DE87BE_1F3C_4914_A062_9CCFCB496122__INCLUDED_
- #include <vector>
- #include <QObject>
- #include <QList>
- #include <QQmlListProperty>
- #include <qqmlparserstatus.h>
- #include "../../gfaipc/src/mutex.h"
- #include <gfa/gfanet.h>
- /////////////////////////////////////////////////////////////////////////////
- // netinterfaces.h - Declarations:
- class Interface;
- class NotificationSink
- {
- public:
- virtual void reportError(const char *pszFormatStr, ...) = 0;
- virtual void filterPropertyChanged(void) const = 0;
- virtual void selConfigChanged(Interface* pi, unsigned int cfgOld, unsigned int cfgNew) = 0;
- virtual int getInterfaceSelConfig(Interface &ri) = 0;
- };
- /////////////////////////////////////////////////////////////////////////////
- typedef bool (*PFN_ADDRESS_VALIDATOR)(const struct in_addr &addr);
- class IPv4Address : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QString address READ address WRITE setAddress NOTIFY addressChanged)
- Q_PROPERTY(int b0 READ b0 WRITE setB0 NOTIFY b0Changed)
- Q_PROPERTY(int b1 READ b1 WRITE setB1 NOTIFY b1Changed)
- Q_PROPERTY(int b2 READ b2 WRITE setB2 NOTIFY b2Changed)
- Q_PROPERTY(int b3 READ b3 WRITE setB3 NOTIFY b3Changed)
- public:
- explicit IPv4Address(struct in_addr &addr, NotificationSink ¬ifyer, QObject *pParent = 0, PFN_ADDRESS_VALIDATOR pfnAddrValidator = NULL);
- virtual ~IPv4Address(void);
- private:
- QString address(void) const;
- int b0(void) const;
- int b1(void) const;
- int b2(void) const;
- int b3(void) const;
-
- void setAddress(const QString &addr);
- void setB0(int b);
- void setB1(int b);
- void setB2(int b);
- void setB3(int b);
- signals:
- void addressChanged(const QString&);
- void b0Changed(int);
- void b1Changed(int);
- void b2Changed(int);
- void b3Changed(int);
- private:
- struct in_addr &m_addr;
- PFN_ADDRESS_VALIDATOR m_pfnAddrValidator;
- NotificationSink &m_rNotifyer;
- };
- /////////////////////////////////////////////////////////////////////////////
- class Static : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(IPv4Address* ipAddress READ ipAddress CONSTANT)
- Q_PROPERTY(IPv4Address* netMask READ netMask CONSTANT)
- Q_PROPERTY(IPv4Address* gateway READ gateway CONSTANT)
- Q_PROPERTY(IPv4Address* bcastAddress READ bcastAddress CONSTANT)
- Q_PROPERTY(IPv4Address* ptpAddress READ ptpAddress CONSTANT)
- Q_PROPERTY(QQmlListProperty<IPv4Address> dnsServer READ dnsServer CONSTANT)
- Q_PROPERTY(int metric READ metric WRITE setMetric NOTIFY metricChanged)
- Q_PROPERTY(int mtu READ mtu WRITE setMtu NOTIFY mtuChanged)
- Q_PROPERTY(int netPrefix READ netPrefix WRITE setNetPrefix NOTIFY netPrefixChanged)
- public:
- explicit Static(IFACE_INET_STATIC &itfs, NotificationSink ¬ifyer, QObject *pParent = 0);
- virtual ~Static(void);
- private:
- IPv4Address* ipAddress(void);
- IPv4Address* netMask(void);
- IPv4Address* gateway(void);
- IPv4Address* bcastAddress(void);
- IPv4Address* ptpAddress(void);
- QQmlListProperty<IPv4Address> dnsServer(void);
- int metric(void) const;
- void setMetric(int metric);
- int mtu(void) const;
- void setMtu(int mtu);
- int netPrefix(void) const;
- void setNetPrefix(int netprefix);
- private slots:
- void netmaskChanged(const QString&);
- signals:
- void metricChanged(int metric);
- void mtuChanged(int mtu);
- void netPrefixChanged(unsigned int netprefix);
- private:
- IFACE_INET_STATIC &m_itfs;
- NotificationSink &m_rNotifyer;
- IPv4Address m_ipAddr;
- IPv4Address m_netmask;
- IPv4Address m_gateway;
- IPv4Address m_bcastAddr;
- IPv4Address m_ptpAddr;
- QList<IPv4Address*> m_dnsList;
- };
- /////////////////////////////////////////////////////////////////////////////
- class Dhcp : public QObject
- {
- Q_OBJECT
- public:
- explicit Dhcp(IFACE_INET_DHCP &itfd, NotificationSink ¬ifyer, QObject *pParent = 0);
- virtual ~Dhcp(void);
- private:
- IFACE_INET_DHCP &m_itfd;
- NotificationSink &m_rNotifyer;
- };
- /////////////////////////////////////////////////////////////////////////////
- class Inet : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(Static* stat READ stat CONSTANT)
- Q_PROPERTY(Dhcp* dhcp READ dhcp CONSTANT)
- public:
- explicit Inet(ITF_IFACE_BLOCK &ifb, NotificationSink ¬ifyer, QObject *pParent = 0);
- virtual ~Inet(void);
- private:
- Static* stat(void);
- Dhcp* dhcp(void);
- private:
- Static m_static;
- Dhcp m_dhcp;
- NotificationSink &m_rNotifyer;
- };
- /////////////////////////////////////////////////////////////////////////////
- class Interface : public QObject
- {
- Q_OBJECT
- Q_PROPERTY(QString name READ name CONSTANT)
- Q_PROPERTY(QString afName READ afName NOTIFY afNameChanged)
- Q_PROPERTY(int af READ af WRITE setAf NOTIFY afChanged)
- Q_PROPERTY(QString methodName READ methodName NOTIFY methodNameChanged)
- Q_PROPERTY(int method READ method WRITE setMethod NOTIFY methodChanged)
- Q_PROPERTY(int selCfg READ selCfg WRITE setSelCfg NOTIFY selCfgChanged)
- Q_PROPERTY(Inet* inet READ inet CONSTANT)
- public:
- explicit Interface(ITF_IFACE_BLOCK &ifb, NotificationSink ¬ifyer, QObject *pParent = 0);
- virtual ~Interface(void);
- inline const ITF_IFACE_BLOCK & getIface(void) const {
- return m_ifb;}
- inline ITF_IFACE_BLOCK & getIface(void){
- return m_ifb;}
-
- inline unsigned long getID(void) const {
- return m_ifb.id;}
-
- inline int getSelCfg(void) const {
- return m_selCfg;}
-
- inline const char * getName(void) const {
- return m_ifb.cfgName.c_str();}
- enum AddressFamily
- {
- AF_Unknown = 0,
- AF_Inet = 0x0001,
- AF_Inet6 = 0x0002,
- AF_Ipx = 0x0004,
- AF_Can = 0x0008,
- AF_Invalid = 0x0010
- };
- Q_ENUMS(AddressFamily)
- enum ItfMethod
- {
- IM_Unknown = 0,
- IM_Static = 0x0001,
- IM_Dhcp = 0x0002,
- IM_Manual = 0x0004,
- IM_BootP = 0x0008,
- IM_Tunnel = 0x0010,
- IM_Ppp = 0x0020,
- IM_WvDial = 0x0040,
- IM_IpV4ll = 0x0080,
- IM_Loopback = 0x0100,
- IM_Auto = 0x0200,
- IM_Invalid = 0x0400
- };
- Q_ENUMS(ItfMethod)
- enum SelConfig
- {
- SC_None = 0,
- SC_Auto = 0x0001,
- SC_AllowAuto = 0x0002,
- SC_AllowHotplug = 0x0004,
- SC_NoAutoDown = 0x0008,
- SC_NoScripts = 0x0010,
- SC_Invalid = 0x0020
- };
- Q_ENUMS(SelConfig)
- private:
- QString name(void) const;
- QString afName(void) const;
- int af(void) const;
- void setAf(int af);
- QString methodName(void) const;
- int method(void) const;
- void setMethod(int method);
- int selCfg(void) const;
- void setSelCfg(int cfg);
- Inet* inet(void);
- signals:
- void afNameChanged(void);
- void afChanged(int af);
- void methodNameChanged(void);
- void methodChanged(int method);
- void selCfgChanged(int cfg);
- private:
- ITF_IFACE_BLOCK &m_ifb;
- Inet m_inet;
- NotificationSink &m_rNotifyer;
- int m_selCfg;
- };
- /////////////////////////////////////////////////////////////////////////////
- class NetInterfaces;
- typedef struct _IF_UPDOWN_CONTEXT
- {
- NetInterfaces *pThis;
- Interface *pi;
- int ctx;
- }IF_UPDOWN_CONTEXT, *LPIF_UPDOWN_CONTEXT;
- typedef const IF_UPDOWN_CONTEXT *LPCIF_UPDOWN_CONTEXT;
- class NetInterfaces : public QObject, public QQmlParserStatus, public NotificationSink
- {
- Q_OBJECT
- Q_INTERFACES(QQmlParserStatus)
- Q_PROPERTY(QQmlListProperty<Interface> interfaces READ interfaces NOTIFY interfacesChanged)
- Q_PROPERTY(QQmlListProperty<Interface> filteredInterfaces READ filteredInterfaces NOTIFY filteredInterfacesChanged)
- Q_PROPERTY(QString itfFilterName READ itfFilterName WRITE setItfFilterName NOTIFY itfFilterNameChanged)
- Q_PROPERTY(int itfFilterAF READ itfFilterAF WRITE setItfFilterAF NOTIFY itfFilterAFChanged)
- Q_PROPERTY(int itfFilterMethod READ itfFilterMethod WRITE setItfFilterMethod NOTIFY itfFilterMethodChanged)
- Q_PROPERTY(bool ifUpDownInProgress READ ifUpDownInProgress CONSTANT)
- public:
- explicit NetInterfaces(QObject *pParent = 0);
- virtual ~NetInterfaces(void);
- enum IfUpDownCtx
- {
- UDC_Start,
- UDC_Stop,
- UDC_Restart
- };
- Q_ENUMS(IfUpDownCtx)
- public:
- Q_INVOKABLE void reset(void);
- Q_INVOKABLE bool initialize(void);
- Q_INVOKABLE bool save(void);
- Q_INVOKABLE bool saveAs(const QString &path);
- Q_INVOKABLE Interface* newInterface(QString name, int af, int method);
- Q_INVOKABLE void removeInterface(Interface *pi);
- Q_INVOKABLE bool startInterface(Interface *pi);
- Q_INVOKABLE bool stopInterface(Interface *pi);
- Q_INVOKABLE bool restartInterface(Interface *pi);
- Q_INVOKABLE bool cancelStartStopInterface(void);
- virtual void classBegin();
- virtual void componentComplete();
- virtual void reportError(const char *pszFormatStr, ...);
- virtual void filterPropertyChanged(void) const;
- virtual void selConfigChanged(Interface* pi, unsigned int cfgOld, unsigned int cfgNew);
- virtual int getInterfaceSelConfig(Interface &ri);
-
- inline pid_t GetIfUpDownPid(void) const {
- return m_ifUpDownPid;}
-
- inline void SetIfUpDownPid(pid_t pid){
- m_ifUpDownPid = pid;}
-
- inline bool GetIfUpDownInProgress(void) const {
- return m_bIfUpDownInProgress;}
-
- inline void SetIfUpDownInProgress(bool bVal){
- m_bIfUpDownInProgress = bVal;}
-
- bool SetInterlockedIfUpDownInProgress(void);
- signals:
- void interfacesChanged(void) const;
- void filteredInterfacesChanged(void) const;
- void itfFilterNameChanged(const QString &val) const;
- void itfFilterAFChanged(int af) const;
- void itfFilterMethodChanged(int method) const;
- void error(QString msg) const;
- void ifUpDown(QString msg) const;
- void ifUpDownCompleted(int ctx, int code) const;
- private:
- QQmlListProperty<Interface> interfaces(void);
- QQmlListProperty<Interface> filteredInterfaces(void);
- const QString& itfFilterName(void) const;
- void setItfFilterName(const QString &val);
- int itfFilterAF(void) const;
- void setItfFilterAF(int nval);
- int itfFilterMethod(void) const;
- void setItfFilterMethod(int method);
- bool ifUpDownInProgress(void) const;
- static void onIfUpDown(const char *pszMsg, void *pCtx);
- static void onIfUpCompleted(int nExitCode, void *pCtx);
- static void onIfDownCompleted(int nExitCode, void *pCtx);
- static void onIfRestartCompleted(int nExitCode, void *pCtx);
- private:
- ETC_NETWORK_INTERFACES m_eni;
- QList<Interface*> m_interfaces;
- QList<Interface*> m_filteredInterfaces;
- QString m_itfFilterName;
- int m_itfFilterAF;
- int m_itfFilterMethod;
- bool m_bIfUpDownInProgress;
- pid_t m_ifUpDownPid;
- CLocalMutex m_mutex;
- };
- /////////////////////////////////////////////////////////////////////////////
- #endif // !defined(AGD_NETINTERFACES_H__54DE87BE_1F3C_4914_A062_9CCFCB496122__INCLUDED_)
|