Prechádzať zdrojové kódy

Teilimplementation der Properties (nur Getter) zum Testen

Rind 7 rokov pred
rodič
commit
8814cdde33

+ 4 - 2
QmlTest/main.qml

@@ -14,10 +14,12 @@ Window {
 
     MouseArea {
         anchors.fill: parent
-        onClicked: {
+        onClicked:
+        {
             if(idItf.initialize())
             {
-                var ifs = idItf.getInterface("eth0");
+                var ifs = idItf.getInterface("eth1");
+
                 if(ifs.length > 0)
                 {
                     console.log(ifs[0].ipAddress);

+ 7 - 3
libgfanet/deploy.sh

@@ -2,6 +2,10 @@
 set -e
 set -o pipefail
 
+# install gfanet "%{CurrentBuild:Type}" "%{CurrentKit:Name}" "%{SysRoot:FilePath}" "%{sourceDir}"
+# clean gfanet "%{CurrentBuild:Type}" "%{CurrentKit:Name}" "%{SysRoot:FilePath}" "%{sourceDir}"
+# deploy gfanet "%{CurrentBuild:Type}" "%{CurrentKit:Name}" "%{SysRoot:FilePath}" "%{sourceDir}" "%{CurrentDevice:HostAddress}" "%{CurrentDevice:UserName}" "root"
+
 COMMAND=$1
 LIB_BASE=$2
 BUILD_TYPE=$3
@@ -37,9 +41,9 @@ LIB_LINK0=$LIB_NAME
 LIB_LINK1=$LIB_NAME".1"
 
 if [ "$COMMAND" == "deploy" ]; then
-	HOST=$6
-	USER=$7@$HOST
-	PASS=$8
+	HOST=$7
+	USER=$8@$HOST
+	PASS=$9
 	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 - 1
libgfanet/gfanet.pro

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

+ 40 - 7
qtplugin/netinterfaces.cpp

@@ -1,5 +1,9 @@
 #include "netinterfaces.h"
 
+#ifndef _countof
+#define _countof(a)					(sizeof(a) / sizeof(*a))
+#endif	//	_countof
+
 /////////////////////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////////////////////
 
@@ -78,6 +82,20 @@ QVariantList NetInterfaces::getInterface(const QString &itfName)
 Interface::Interface(ITF_IFACE_BLOCK &ifb, QObject *pParent) : QObject(pParent), m_ifb(ifb)
 {
 	setObjectName("Interface");
+
+	for(size_t i = 0; i < _countof(m_ifb.inet4s.namesvr); i++)
+	{
+		if(m_ifb.inet4s.namesvr[i].s_addr)
+		{
+			QString qs(inet_ntoa(m_ifb.inet4s.namesvr[i]));
+			m_dnsList.append(qs);
+		}
+		else
+		{
+			QString qs("");
+			m_dnsList.append(qs);
+		}
+	}
 }
 
 Interface::~Interface(void)
@@ -89,20 +107,35 @@ QString Interface::name(void) const
 	return QString::fromStdString(m_ifb.cfgName);
 }
 
+QString Interface::family(void) const
+{
+	return ::GetIfaceProtoStr(m_ifb.proto);
+}
+
+QString Interface::method(void) const
+{
+	return ::GetIfaceMethodStr(m_ifb.method);
+}
+
 QString Interface::ipAddress(void) const
 {
-	if(m_ifb.proto == IFP_Inet && m_ifb.method == IFM_Static)
+//	if(m_ifb.proto == IFP_Inet && m_ifb.method == IFM_Static)
 		return inet_ntoa(m_ifb.inet4s.addr);
-	else
-		return "";
+//	else
+//		return "";
 }
 
-QString Interface::family(void) const
+QString Interface::netMask(void) const
 {
-	return ::GetIfaceProtoStr(m_ifb.proto);
+	return inet_ntoa(m_ifb.inet4s.netmask);
 }
 
-QString Interface::method(void) const
+QString Interface::gateway(void) const
 {
-	return ::GetIfaceMethodStr(m_ifb.method);
+	return inet_ntoa(m_ifb.inet4s.gate);
+}
+
+QStringList Interface::dnsServers(void) const
+{
+	return m_dnsList;
 }

+ 24 - 4
qtplugin/netinterfaces.h

@@ -19,24 +19,44 @@ class Interface : public QObject
     Q_OBJECT
     Q_PROPERTY(QString name READ name)
     Q_PROPERTY(QString family READ family)
-    Q_PROPERTY(QString ipAddress READ ipAddress)
     Q_PROPERTY(QString method READ method)
+	// static
+    Q_PROPERTY(QString ipAddress READ ipAddress)
+    Q_PROPERTY(QString netMask READ netMask)
+    Q_PROPERTY(QString gateway READ gateway)
+    Q_PROPERTY(QStringList dnsServers READ dnsServers)
+    // dhcp
 
 public:
     explicit Interface(ITF_IFACE_BLOCK &ifb, QObject *pParent = 0);
     virtual ~Interface(void);
-    
+
     inline const ITF_IFACE_BLOCK & getIface(void) const {
     	return m_ifb;}
-    
+
+	enum AddressFamily
+	{
+		AF_Unknown = -1,
+		AF_Inet,
+		AF_Inet6,
+		AF_Ipx,
+		AF_Can,
+		AF_Invalid
+	};
+	Q_ENUMS(AddressFamily)
+
 private:
     QString name(void) const;
-    QString ipAddress(void) const;
     QString family(void) const;
     QString method(void) const;
+    QString ipAddress(void) const;
+    QString netMask(void) const;
+    QString gateway(void) const;
+    QStringList dnsServers(void) const;
 
 private:
 	ITF_IFACE_BLOCK &m_ifb;
+	QStringList m_dnsList;
 };
 
 /////////////////////////////////////////////////////////////////////////////

+ 4 - 3
qtplugin/netinterfaces.pro

@@ -41,10 +41,11 @@ DISTFILES += gfa.plugins.qml.net.qmltypes
 }
 
 qmldir.files = qmldir
-unix {
+
+#unix {
     installPath = $$[QT_INSTALL_QML]/$$replace(uri, \\., /)
     qmldir.path = $$installPath
     target.path = $$installPath
     INSTALLS += target qmldir
-message($${installPath})
-}
+    message($${installPath})
+#}

+ 1 - 3
qtplugin/netinterfaces_plugin.cpp

@@ -4,9 +4,7 @@
 
 void NetInterfacesPlugin::registerTypes(const char *uri)
 {
-    // @uri gfa.plugins.qml.net
+    // gfa.plugins.qml.net
     qmlRegisterType<NetInterfaces>(uri, 1, 0, "NetInterfaces");
-//    qmlRegisterType<Interface>(uri, 1, 0, "Interface");
     qmlRegisterUncreatableType<Interface>(uri, 1, 0, "Interface", "return type only");
-//    qmlRegisterUncreatableType<QList<Interface*>>(uri, 1, 0, "InterfaceList", "return type only");
 }

+ 3 - 1
qtplugin/pdump.sh

@@ -4,5 +4,7 @@ set -e
 PDUMP="/home/wrk/Qt5.7.0/5.7/gcc_64/bin/qmlplugindump"
 URI="gfa.plugins.qml.net"
 VERSION=1.0
+OUTFILE="/home/wrk/Qt5.7.0/5.7/gcc_64/qml/gfa/plugins/qml/net/net.qmltypes"
+
+$PDUMP $URI $VERSION "/home/wrk/share/gfanet/qtplugin/Debug/Desktop_Qt_5_7_0_GCC_64bit" > $OUTFILE
 
-$PDUMP $URI $VERSION > /home/wrk/Qt5.7.0/5.7/gcc_64/qml/gfa/plugins/qml/net/net.qmltypes