From 90ace3be2d89a543fa68c43c8dcfdd9f59f21822 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 23 Jan 2012 17:54:12 +0100 Subject: new option -n to activate network discovery --- src/fbgui/main.cpp | 24 +++++++++++++++++------- src/fbgui/ndgui.cpp | 3 ++- src/fbgui/ndgui.h | 4 +++- src/fbgui/sysinfo.cpp | 24 +++++++++++++++++++++++- testApp.sh | 2 +- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/fbgui/main.cpp b/src/fbgui/main.cpp index e8b65f9..4c7daf8 100644 --- a/src/fbgui/main.cpp +++ b/src/fbgui/main.cpp @@ -80,12 +80,12 @@ int main(int argc, char *argv[]) { // parse command line arguments using getopt QMap clOpts; int longIndex = 0; - static const char *optString = "c:u:d:s:t:D:hl:"; + static const char *optString = "c:u:d:s:t:D:hl:n"; static const struct option longOpts[] = { { "config", required_argument, NULL, 'c' }, { "url", required_argument, NULL, 'u' }, { "download", required_argument, NULL, 'd' }, { "serial", required_argument, NULL, 's' }, { "trigger", required_argument, NULL, 't' }, { "debug", required_argument, NULL, 'D' }, { "help", no_argument, NULL, 'h' }, { "log", - required_argument, NULL, 'l' }, + required_argument, NULL, 'l' }, { "nd", no_argument, NULL, 'n' } , { "server", required_argument, NULL, 'S' }, { "autoup", no_argument, NULL, 'a' }, { "socketserverpath", required_argument, NULL, 'p' }, @@ -118,6 +118,9 @@ int main(int argc, char *argv[]) { case 'h': clOpts.insert("help", "help"); break; + case 'n': + clOpts.insert("nd", "nd"); + break; case 'S': clOpts.insert("server", optarg); break; @@ -289,12 +292,19 @@ int main(int argc, char *argv[]) { //QWSServer::instance()->setDefaultMouse("IntelliMouse:/dev/mice"); - // start ndgui - LOG4CXX_DEBUG(logger, "Initializing ndgui..."); - ndgui ngui; fbgui gui; + ndgui ngui; + + if (clOpts.contains("nd") || confFileSettings.contains("default/nd")) { + LOG4CXX_DEBUG(logger, "Initializing ndgui..."); + QObject::connect(&ngui, SIGNAL(initFbgui()), &gui, SLOT(init())); + ngui.init(); + ngui.show(); + } + else { + gui.init(); + gui.show(); + } - QObject::connect(&ngui, SIGNAL(initFbgui()), &gui, SLOT(init())); - ngui.show(); return app.exec(); } diff --git a/src/fbgui/ndgui.cpp b/src/fbgui/ndgui.cpp index 98436df..4e0b3f6 100644 --- a/src/fbgui/ndgui.cpp +++ b/src/fbgui/ndgui.cpp @@ -32,7 +32,6 @@ QString gPathToDhcpExe(""); */ ndgui::ndgui(QMainWindow *parent) : QMainWindow(parent) { - init(); } @@ -41,12 +40,14 @@ ndgui::ndgui(QMainWindow *parent) : * destructor */ ndgui::~ndgui() { + delete _debugConsole; delete _toggleDebugConsole; delete _allowUserChoice; delete _tryAgain; delete _webView; delete _networkDiscovery; + } diff --git a/src/fbgui/ndgui.h b/src/fbgui/ndgui.h index d4ab0b1..1cb285c 100644 --- a/src/fbgui/ndgui.h +++ b/src/fbgui/ndgui.h @@ -41,6 +41,8 @@ public: Q_INVOKABLE QString readLogFile(); Q_INVOKABLE QVariantMap getInterfaceConf(QString ifName); + void init(); + public slots: void handleConnectionEstablished(QString ifName); void abortBoot(QString msg); @@ -104,7 +106,7 @@ private: // triggers toggleDebugConsole() QAction* _toggleDebugConsole; - void init(); + void setupLayout(); void createDebugConsole(); void toggleDebugConsole(); diff --git a/src/fbgui/sysinfo.cpp b/src/fbgui/sysinfo.cpp index 80f4a64..d1ac44f 100644 --- a/src/fbgui/sysinfo.cpp +++ b/src/fbgui/sysinfo.cpp @@ -46,6 +46,7 @@ const QString SysInfo::getInfo(const QString& infoName) { return getMainboardSerial(); else if (infoName == QString("usb")) return getUsbVendorIdProductIdSerialNumber(); + /* unknown code */ LOG4CXX_DEBUG(siLogger, "unknown requested"); return "info_error"; @@ -128,22 +129,35 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() { return "error"; } cnt = libusb_get_device_list(ctx, &devs); //get the list of devices + if (cnt < 0) { LOG4CXX_DEBUG(siLogger, tag + "Get Device Error"); //there was an error } - LOG4CXX_DEBUG(siLogger, tag + cnt + " Devices in list."); //print total number of usb devices + LOG4CXX_DEBUG(siLogger, tag << cnt << " Devices in list."); //print total number of usb devices ssize_t i; //for iterating through the list# for (i = 0; i < cnt; i++) { //printdev(devs[i]); //print specs of this device + QVariantMap infos; libusb_device *dev = devs[i]; + + libusb_config_descriptor *config; + int cr = 1; + cr = libusb_get_config_descriptor(dev, 1, &config); + if (cr < 0) { + LOG4CXX_DEBUG(siLogger, "Couldn't open config desc, code: " << cr); + } + //LOG4CXX_DEBUG(siLogger, "bmAttribute: " << config->bmAttributes); + libusb_device_descriptor desc; int re = libusb_get_device_descriptor(dev, &desc); if (re < 0) { LOG4CXX_DEBUG(siLogger, tag + "failed to get device descriptor"); return "error"; } + infos.insert("vendorId", desc.idVendor); + //LOG4CXX_DEBUG(siLogger, "idVendor: " << infos.value("vendorId").toString()); infos.insert("productId", desc.idProduct); unsigned char string[256]; libusb_device_handle *handle; @@ -158,6 +172,7 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() { LOG4CXX_DEBUG(siLogger, tag + "failed to get SerialNumber"); return "error"; } + //LOG4CXX_DEBUG(siLogger, "SN: " << string); infos.insert("serialnumber", QString((const char *) string)); re = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string)); @@ -175,11 +190,18 @@ const QString SysInfo::getUsbVendorIdProductIdSerialNumber() { infos.insert("manuacturer", QString((const char *) string)); list << infos; + + /* + for (int i = 0; i < list.size(); ++i) { + LOG4CXX_DEBUG(siLogger, "list: " << list[i].toString()); + }*/ + libusb_close(handle); } libusb_free_device_list(devs, 1); //free the list, unref the devices in it libusb_exit(ctx); //close the session + /* QByteArray json = serializer.serialize(list); LOG4CXX_DEBUG(siLogger, tag + "json object: " + json); diff --git a/testApp.sh b/testApp.sh index 054169d..b78bebe 100755 --- a/testApp.sh +++ b/testApp.sh @@ -31,6 +31,6 @@ display_id=$(grep -n $(whoami) /etc/passwd| head -n 1|awk -F : '{print $1}') # quick sleep to wait for qvfb loading sleep 0.2 # Start fbgui connecting to QVFb with display_id from above. -$working_path/build/fbgui -display QVFb:$display_id $@ +$working_path/build/src/fbgui/fbgui -display QVFb:$display_id $@ # kill qvfb since fbgui stopped killall qvfb -- cgit v1.2.3-55-g7522