Rind 7 anos atrás
pai
commit
26c59e6506

+ 1 - 1
QmlTest/QmlTest.pro

@@ -26,5 +26,5 @@ DEFINES += QT_DEPRECATED_WARNINGS
 
 # Default rules for deployment.
 qnx: target.path = /tmp/$${TARGET}/bin
-else: unix:!android: target.path = /opt/$${TARGET}/bin
+else: unix:!android: target.path = /opt/GfA/$${TARGET}
 !isEmpty(target.path): INSTALLS += target

+ 25 - 16
QmlTest/main.qml

@@ -8,8 +8,20 @@ Window {
     height: 480
     title: qsTr("Hello World")
 
+	Text {
+         id: idIpAddr
+         x: 5
+         y: 40
+         color: "blue"
+         font.pixelSize: 14
+         text: idItf.interfaces[0].ipAddress.address
+     }
+
     NetInterfaces {
         id: idItf
+        itfFilterName: "eth0"
+        itfFilterAF: Interface.AF_Inet
+        itfFilterMethod: Interface.IM_Static
         onSigError:
         {
             console.error(msg);
@@ -20,24 +32,21 @@ Window {
         anchors.fill: parent
         onClicked:
         {
-            if(idItf.initialize())
+            if(idItf.filteredInterfaces.length > 0)
             {
-                var ifs = idItf.getInterface("eth1");
-
-                if(ifs.length > 0)
-                {
-                    ifs[0].ipAddress.b3 = 412;
-                    ifs[0].ipAddress.address = "192.168.0.256"
-                    ifs[0].ipAddress.address = "155.18.2.156"
-                    console.log(ifs[0].ipAddress.address);
-                }
-                else
-                {
-                    console.log("No interface found!");
-                }
-
-                idItf.save("/home/wrk/share/gfanet/libgfanet/res/testitf");
+                idItf.filteredInterfaces[0].ipAddress.address = "192.168.0.256"
+                idItf.filteredInterfaces[0].ipAddress.address = "155.18.2.156"
+                idItf.filteredInterfaces[0].ipAddress.b0 = 255;
+                console.log(idItf.filteredInterfaces[0].ipAddress.address);
             }
+            else
+            {
+                console.warn("No interface found!");
+            }
+
+            idItf.itfFilterName = "eth1";
+            idItf.itfFilterMethod = Interface.IM_Dhcp
+            idItf.saveAs("/home/wrk/share/gfanet/libgfanet/res/testitf");
         }
     }
 }

+ 1 - 0
libgfanet/deploy.sh

@@ -44,6 +44,7 @@ if [ "$COMMAND" == "deploy" ]; then
 	HOST=$7
 	USER=$8@$HOST
 	PASS=$9
+#	echo pscp -pw $PASS $LIB_NAME $USER:/usr/lib/$LIB_TARGET
 	pscp -pw $PASS $LIB_NAME $USER:/usr/lib/$LIB_TARGET > /dev/null
 	plink -batch -t -pw $PASS $USER ln -sfn /usr/lib/$LIB_TARGET /usr/lib/$LIB_LINK0
 	plink -batch -t -pw $PASS $USER ln -sfn /usr/lib/$LIB_TARGET /usr/lib/$LIB_LINK1

+ 2 - 2
libgfanet/gfanet.pro

@@ -34,5 +34,5 @@ linux-buildroot-g++ {
 #	INSTALLS += target
 }
 
-message($$[QT_INSTALL_QML])
-message($$qtLibraryTarget($$TARGET))
+#message($$[QT_INSTALL_QML])
+#message($$qtLibraryTarget($$TARGET))

+ 1 - 1
libgfanet/interfaces.cpp

@@ -327,7 +327,7 @@ void ProcessGroupMembers(ETC_NETWORK_INTERFACES &eni)
 	for(auto cIt1 = eni.cgl.begin(); cIt1 != eni.cgl.end(); cIt1++)
 	{
 		ITF_CONFIG_GROUP &icg1 = *cIt1;
-		for(auto cIt2 = cIt1 + 1; cIt2 != eni.cgl.end(); cIt2++)
+        for(auto cIt2 = ++cIt1; cIt2 != eni.cgl.end(); cIt2++)
 		{
 			ITF_CONFIG_GROUP &icg2 = *cIt2;
 			if(!icg1.cfgName.compare(icg2.cfgName))

+ 6 - 4
libgfanet/interfaces.h

@@ -20,6 +20,7 @@
 #include <linux/if_packet.h>
 #include <linux/if_arp.h>
 #include <vector>
+#include <list>
 #include <string>
 #include "inet4s.h"
 #include "inet4d.h"
@@ -40,7 +41,7 @@ typedef struct _ITF_CONFIG_GROUP
 	std::vector<std::string> members;
 }ITF_CONFIG_GROUP, *LPITF_CONFIG_GROUP;
 typedef const ITF_CONFIG_GROUP *LPCITF_CONFIG_GROUP;
-typedef std::vector<ITF_CONFIG_GROUP> ITF_CONFIG_GROUP_LIST;
+typedef std::list<ITF_CONFIG_GROUP> ITF_CONFIG_GROUP_LIST;
 
 typedef enum CfgGroup
 {
@@ -128,7 +129,7 @@ typedef struct _ITF_INCLUDE
 	std::string path;
 }ITF_INCLUDE, *LPITF_INCLUDE;
 typedef const ITF_INCLUDE *LPCITF_INCLUDE;
-typedef std::vector<ITF_INCLUDE> ITF_INCLUDE_LIST;
+typedef std::list<ITF_INCLUDE> ITF_INCLUDE_LIST;
 
 bool ParseIncludes(const std::vector<std::string> &v, ITF_INCLUDE_LIST &inc);
 const char *GetIncTypeStr(ItfInclude inc);
@@ -165,7 +166,8 @@ typedef struct _ITF_IFACE_BLOCK
 	IFACE_INET_MANUAL inet4m;
 }ITF_IFACE_BLOCK, *LPITF_IFACE_BLOCK;
 typedef const ITF_IFACE_BLOCK *LPCITF_IFACE_BLOCK;
-typedef std::vector<ITF_IFACE_BLOCK> ITF_IFACE_BLOCK_LIST;
+//typedef std::vector<ITF_IFACE_BLOCK> ITF_IFACE_BLOCK_LIST;
+typedef std::list<ITF_IFACE_BLOCK> ITF_IFACE_BLOCK_LIST;
 
 typedef enum IfaceHdrType
 {
@@ -191,7 +193,7 @@ typedef struct _ITF_MAPPING_BLOCK
 	std::vector<std::string> unparsed;
 }ITF_MAPPING_BLOCK, *LPITF_MAPPING_BLOCK;
 typedef const ITF_MAPPING_BLOCK *LPCITF_MAPPING_BLOCK;
-typedef std::vector<ITF_MAPPING_BLOCK> ITF_MAPPING_BLOCK_LIST;
+typedef std::list<ITF_MAPPING_BLOCK> ITF_MAPPING_BLOCK_LIST;
 
 bool ParseMapping(const std::vector<std::string> &v, ITF_MAPPING_BLOCK &mab);
 

+ 7 - 3
libgfanet/util.cpp

@@ -141,7 +141,7 @@ ssize_t ReadFile(const char *pszPath, void **ppBuf, size_t nBlockSize)
 	}
 
 	nRead += l;
-	p[nRead] = '\n';
+	p[nRead] = '\0';
 	*ppBuf = p;
 	return nRead;
 }
@@ -151,12 +151,16 @@ ssize_t ReadFile(const char *pszPath, void **ppBuf, size_t nBlockSize)
 ssize_t ReadFile(const char *pszPath, std::string &str)
 {
 	char *pszBuf;
+	str.clear();
 	ssize_t nRet = ReadFile(pszPath, (void**)&pszBuf, 0);
 
-	if(nRet > 0)
-		str = pszBuf;
 	if(pszBuf)
+	{
+		if(nRet > 0)
+			str = pszBuf;
 		free(pszBuf);
+	}
+
 	return nRet;
 }
 

+ 142 - 14
qtplugin/netinterfaces.cpp

@@ -12,6 +12,8 @@
 NetInterfaces::NetInterfaces(QObject *pParent) : QObject(pParent)
 {
 	setObjectName("NetInterfaces");
+	m_itfFilterAF = Interface::AF_Inet;
+	m_itfFilterMethod = Interface::IM_Static;
 }
 
 NetInterfaces::~NetInterfaces(void)
@@ -25,32 +27,50 @@ void NetInterfaces::classBegin()
 
 void NetInterfaces::componentComplete()
 {
+	if(!initialize())
+		emitError("NetInterfaces::initialize failed!");
 }
 
 void NetInterfaces::reset(void)
 {
-	for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
+/*	for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
 	{
 		Interface *pi = *it;
 		delete pi;
 	}
 
-	m_itfList.clear();
+	m_itfList.clear();*/
+
+	Interface *pItf;
+	
+    for(int i = 0; i < m_interfaces.count(); i++)
+    {
+        if((pItf = m_interfaces.at(i)))
+        	delete pItf;
+    }
+    m_interfaces.clear();
+	emit interfaces_Changed();
+
 	m_eni._reset();
 }
 
 bool NetInterfaces::initialize(void)
 {
-	bool bRet = false;
+	bool bRet;
 	reset();
+
 	if((bRet = ::ParseEtcNetworkInterfaces(m_eni)))
 	{
 		for(auto it = m_eni.ibl.begin(); it != m_eni.ibl.end(); it++)
 		{
 			ITF_IFACE_BLOCK &ibl = *it;
-			m_itfList.push_back(new Interface(ibl, static_cast<const Emitter&>(*this), this));
+			m_interfaces.append(new Interface(ibl, static_cast<const Emitter&>(*this), this));
+//			m_itfList.push_back(new Interface(ibl, static_cast<const Emitter&>(*this), this));
 		}
+
+		emit interfaces_Changed();
 	}
+
 	return bRet;
 }
 
@@ -59,15 +79,12 @@ bool NetInterfaces::save(void)
 	return ::WriteEtcNetworkInterfaces(m_eni, NULL);
 }
 
-bool NetInterfaces::save(QString path)
+bool NetInterfaces::saveAs(const QString &path)
 {
-	std::string p;
-	const char *pszPath = NULL;
-	if(path.length() > 0)
-	{
-		p = path.toStdString();
-		pszPath = p.c_str();
-	}
+	if(!path.length())
+		return false;
+	std::string p = path.toStdString();
+	const char *pszPath = p.c_str();
 	return ::WriteEtcNetworkInterfaces(m_eni, pszPath);
 }
 
@@ -87,9 +104,11 @@ QVariantList NetInterfaces::getInterface(const QString &itfName)
 
 	if(m_eni.ibl.size() > 0)
 	{
-		for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
+//		for(auto it = m_itfList.begin(); it != m_itfList.end(); it++)
+	    for(int i = 0; i < m_interfaces.count(); i++)
 		{
-			Interface *pi = *it;
+	        Interface *pi = m_interfaces.at(i);
+//			Interface *pi = *it;
 			const ITF_IFACE_BLOCK &ibl = pi->getIface();
 
 			if(	itfName == ibl.cfgName.c_str() &&
@@ -105,6 +124,104 @@ QVariantList NetInterfaces::getInterface(const QString &itfName)
 	return list;
 }
 
+QVariant NetInterfaces::newInterface(QString name, int af, int method, QString cfg)
+{
+	m_eni.ibl.emplace_back();
+	ITF_IFACE_BLOCK &rib = m_eni.ibl.back();
+    rib.cfgName = name.toStdString();
+	rib.proto = (IfaceProtos)af;
+	rib.method = (IfaceMethods)method;
+	Interface *pi = new Interface(rib, static_cast<const Emitter&>(*this), this);
+
+	m_interfaces.append(pi);
+	emit interfaces_Changed();
+
+//	m_itfList.push_back(pi);
+	return QVariant::fromValue(pi);
+}
+
+QQmlListProperty<Interface> NetInterfaces::interfaces(void)
+{
+	return QQmlListProperty<Interface>(this, m_interfaces);
+}
+
+QQmlListProperty<Interface> NetInterfaces::filteredInterfaces(void)
+{
+	m_filteredInterfaces.clear();
+
+    for(int i = 0; i < m_interfaces.count(); i++)
+	{
+        Interface *pi = m_interfaces.at(i);
+		const ITF_IFACE_BLOCK &ibl = pi->getIface();
+
+		if(	m_itfFilterName == ibl.cfgName.c_str() &&
+			(int)ibl.proto == m_itfFilterAF &&
+			(int)ibl.method == m_itfFilterMethod)
+		{
+			m_filteredInterfaces.append(pi);
+		}
+	}
+
+	return QQmlListProperty<Interface>(this, m_filteredInterfaces);
+}
+
+const QString& NetInterfaces::itfFilterName(void) const
+{
+	return m_itfFilterName;
+}
+
+void NetInterfaces::set_itfFilterName(const QString &val)
+{
+	if(val != m_itfFilterName)
+	{
+		m_itfFilterName = val;
+		emit itfFilterName_Changed(m_itfFilterName);
+		emit filteredInterfaces_Changed();
+	}
+}
+
+int NetInterfaces::itfFilterAF(void) const
+{
+	return m_itfFilterAF;
+}
+
+void NetInterfaces::set_itfFilterAF(int af)
+{
+	if(af <= Interface::AF_Unknown || af >= Interface::AF_Invalid)
+	{
+		emitError("Invalid address family filter: %d!", af);
+		return;
+	}
+
+	if(m_itfFilterAF != af)
+	{
+		m_itfFilterAF = af;
+		emit itfFilterAF_Changed(af);
+		emit filteredInterfaces_Changed();
+	}
+}
+
+int NetInterfaces::itfFilterMethod(void) const
+{
+	return m_itfFilterMethod;
+}
+
+void NetInterfaces::set_itfFilterMethod(int method)
+{
+	if(method <= Interface::IM_Unknown || method >= Interface::IM_Invalid)
+	{
+		emitError("Invalid method filter: %d!", method);
+		return;
+	}
+
+	if(m_itfFilterMethod != method)
+	{
+		m_itfFilterMethod = method;
+		emit itfFilterMethod_Changed(method);
+		emit filteredInterfaces_Changed();
+	}
+}
+
 /////////////////////////////////////////////////////////////////////////////
 
 Interface::Interface(ITF_IFACE_BLOCK &ifb, const Emitter &errHandler, QObject *pParent) : 	QObject(pParent),
@@ -161,11 +278,21 @@ QString Interface::family(void) const
 	return ::GetIfaceProtoStr(m_ifb.proto);
 }
 
+int Interface::af(void) const
+{
+	return (int)m_ifb.proto;
+}
+
 QString Interface::method(void) const
 {
 	return ::GetIfaceMethodStr(m_ifb.method);
 }
 
+int Interface::itfMethod(void) const
+{
+	return (int)m_ifb.method;
+}
+
 IPv4Address* Interface::ipAddress(void)
 {
 	return &m_ipAddr;
@@ -226,6 +353,7 @@ QString Interface::dns3(void) const
 
 IPv4Address::IPv4Address(struct in_addr &addr, const Emitter &errHandler, QObject *pParent) : QObject(pParent), m_addr(addr), m_errHandler(errHandler)
 {
+	setObjectName("IPv4Address");
 }
 
 IPv4Address::~IPv4Address(void)

+ 56 - 43
qtplugin/netinterfaces.h

@@ -22,22 +22,6 @@ public:
 
 /////////////////////////////////////////////////////////////////////////////
 
-#if 0
-class Nameservers : public QObject
-{
-    Q_OBJECT
-
-public:
-    explicit Nameservers(struct in_addr (&namesvr)[3], QObject *pParent = 0);
-    virtual ~Nameservers(void);
-
-private:
-	struct in_addr (&m_dnsSvr)[3];
-};
-#endif
-
-/////////////////////////////////////////////////////////////////////////////
-
 class IPv4Address : public QObject
 {
     Q_OBJECT
@@ -81,23 +65,18 @@ private:
 class Interface : public QObject
 {
     Q_OBJECT
-    Q_PROPERTY(QString name READ name)
+    Q_PROPERTY(QString name READ name CONSTANT)
     Q_PROPERTY(QString family READ family)
+    Q_PROPERTY(int af READ af)
     Q_PROPERTY(QString method READ method)
+    Q_PROPERTY(int itfMethod READ itfMethod)
 	// static
-    Q_PROPERTY(IPv4Address* ipAddress READ ipAddress)
-    Q_PROPERTY(IPv4Address* netMask READ netMask)
-    Q_PROPERTY(IPv4Address* gateway READ gateway)
-    Q_PROPERTY(IPv4Address* bcastAddress READ bcastAddress)
-    Q_PROPERTY(IPv4Address* ptpAddress READ ptpAddress)
-    Q_PROPERTY(QQmlListProperty<IPv4Address> dnsServer READ dnsServer)
-
-#if 0
-    Q_PROPERTY(QStringList dnsServers READ dnsServers)
-#endif
-//    Q_PROPERTY(QString dns1 READ dns1)
-//    Q_PROPERTY(QString dns2 READ dns2)
-//    Q_PROPERTY(QString dns3 READ dns3)
+    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)
     // dhcp
 
 public:
@@ -118,10 +97,29 @@ public:
 	};
 	Q_ENUMS(AddressFamily)
 
+	enum ItfMethod
+	{
+		IM_Unknown = -1,
+		IM_Static,
+		IM_Dhcp,
+		IM_Manual,
+		IM_BootP,
+		IM_Tunnel,
+		IM_Ppp,
+		IM_WvDial,
+		IM_IpV4ll,
+		IM_Loopback,
+		IM_Auto,
+		IM_Invalid
+	};
+	Q_ENUMS(ItfMethod)
+
 private:
     QString name(void) const;
     QString family(void) const;
+    int af(void) const;
     QString method(void) const;
+    int itfMethod(void) const;
     IPv4Address* ipAddress(void);
     IPv4Address* netMask(void);
     IPv4Address* gateway(void);
@@ -129,13 +127,6 @@ private:
     IPv4Address* ptpAddress(void);
     QQmlListProperty<IPv4Address> dnsServer(void);
 
-//    QString dns1(void) const;
-//    QString dns2(void) const;
-//    QString dns3(void) const;
-#if 0
-    QStringList dnsServers(void) const;
-#endif
-
 private:
 	ITF_IFACE_BLOCK &m_ifb;
 	IPv4Address m_ipAddr;
@@ -145,10 +136,6 @@ private:
 	IPv4Address m_ptpAddr;
 	QList<IPv4Address*> m_dnsList;
 	const Emitter &m_errHandler;
-#if 0
-	QStringList m_dnsList;
-	Nameservers m_dnsSvr;
-#endif
 };
 
 /////////////////////////////////////////////////////////////////////////////
@@ -157,6 +144,11 @@ class NetInterfaces : public QObject, public QQmlParserStatus, public Emitter
 {
     Q_OBJECT
     Q_INTERFACES(QQmlParserStatus)
+    Q_PROPERTY(QQmlListProperty<Interface> interfaces READ interfaces NOTIFY interfaces_Changed)
+    Q_PROPERTY(QQmlListProperty<Interface> filteredInterfaces READ filteredInterfaces NOTIFY filteredInterfaces_Changed)
+    Q_PROPERTY(QString itfFilterName READ itfFilterName WRITE set_itfFilterName NOTIFY itfFilterName_Changed)
+    Q_PROPERTY(int itfFilterAF READ itfFilterAF WRITE set_itfFilterAF NOTIFY itfFilterAF_Changed)
+    Q_PROPERTY(int itfFilterMethod READ itfFilterMethod WRITE set_itfFilterMethod NOTIFY itfFilterMethod_Changed)
 
 public:
     explicit NetInterfaces(QObject *pParent = 0);
@@ -166,21 +158,42 @@ public:
 	Q_INVOKABLE void reset(void);
 	Q_INVOKABLE bool initialize(void);
 	Q_INVOKABLE bool save(void);
-	Q_INVOKABLE bool save(QString path);
+	Q_INVOKABLE bool saveAs(const QString &path);
 	Q_INVOKABLE QVariantList getInterface(const QString &itfName);
+	Q_INVOKABLE QVariant newInterface(QString name, int af, int method, QString cfg);
 
 	virtual void classBegin();
 	virtual void componentComplete();
 	virtual void emitError(const char *pszFormatStr, ...) const;
 
+signals:
+	void interfaces_Changed(void);
+	void filteredInterfaces_Changed(void);
+	void itfFilterName_Changed(const QString &val);
+	void itfFilterAF_Changed(int af);
+	void itfFilterMethod_Changed(int method);
+
 private:
+	QQmlListProperty<Interface> interfaces(void);
+	QQmlListProperty<Interface> filteredInterfaces(void);
+	const QString& itfFilterName(void) const;
+	void set_itfFilterName(const QString &val);
+	int itfFilterAF(void) const;
+	void set_itfFilterAF(int nval);
+	int itfFilterMethod(void) const;
+	void set_itfFilterMethod(int method);
 
 signals:
 	void sigError(QString msg) const;
 
 private:
 	ETC_NETWORK_INTERFACES m_eni;
-	std::vector<Interface*> m_itfList;
+//	std::vector<Interface*> m_itfList;
+	QList<Interface*> m_interfaces;
+	QList<Interface*> m_filteredInterfaces;
+	QString m_itfFilterName;
+	int m_itfFilterAF;
+	int m_itfFilterMethod;
 };
 
 /////////////////////////////////////////////////////////////////////////////

+ 2 - 2
qtplugin/netinterfaces.pro

@@ -29,7 +29,7 @@ HEADERS += \
     netinterfaces_plugin.h
 
 DISTFILES = qmldir
-DISTFILES += gfa.plugins.qml.net.qmltypes
+#DISTFILES += gfa.plugins.qml.net.qmltypes
 
 !equals(_PRO_FILE_PWD_, $$OUT_PWD)
 {
@@ -47,5 +47,5 @@ qmldir.files = qmldir
     qmldir.path = $$installPath
     target.path = $$installPath
     INSTALLS += target qmldir
-    message($${installPath})
+#    message($${installPath})
 #}

+ 7 - 1
qtplugin/pdump.sh

@@ -4,7 +4,13 @@ set -e
 PDUMP="/home/wrk/Qt5.7.0/5.7/gcc_64/bin/qmlplugindump"
 URI="gfa.plugins.qml.net"
 VERSION=1.0
+
+# Desktop:
 OUTFILE="/home/wrk/Qt5.7.0/5.7/gcc_64/qml/gfa/plugins/qml/net/net.qmltypes"
+IMPORTPATH="/home/wrk/share/gfanet/qtplugin/Debug/Desktop_Qt_5_7_0_GCC_64bit"
 
-$PDUMP $URI $VERSION "/home/wrk/share/gfanet/qtplugin/Debug/Desktop_Qt_5_7_0_GCC_64bit" > $OUTFILE
+# Target:
+#OUTFILE="/opt/GfA/TC_L312_C493_QT57/usr/arm-buildroot-linux-gnueabihf/sysroot/usr/qml/gfa/plugins/qml/net/net.qmltypes"
+#IMPORTPATH="/home/wrk/share/gfanet/qtplugin/Debug/GfA_Device"
 
+$PDUMP $URI $VERSION $IMPORTPATH > $OUTFILE