Commits

iorodeo committed ea6dd6b

Working on external control server. Currently have issue with passing query string as json object.

Comments (0)

Files changed (4)

src/gui/basic_http_server.cpp

         if (socketPtr->canReadLine()) 
         {
             QString requestString = QString(socketPtr->readLine());
+
+            // --
+            std::cout << requestString.toStdString() << std::endl;
+            // --
+
             QStringList tokens = requestString.split(QRegExp("[ \r\n][ \r\n]*"));
+            //QStringList tokens = splitRequestString(requestString);
+            if (tokens.isEmpty())
+            {
+                return;
+            }
+
+            // --
+            for (unsigned int i=0; i<tokens.size(); i++) 
+            {
+                std::cout << i << ", " << tokens[i].toStdString() << std::endl;
+            }
+            // --
+
             if (tokens[0] == "GET") 
             {
                 handleGetRequest(socketPtr, tokens);
         }
         else if (name == QString("set-configuration"))
         {
-            cmdMap.insert("success", true);
-            cmdMap.insert("message", "");
-            cmdMap.insert("value", "");
+            cmdMap = handleSetConfiguration(value);
         }
         else if (name == QString("enable-logging"))
         {
         return cmdMap;
     }
 
+
+    QVariantMap BasicHttpServer::handleSetConfiguration(QString jsonConfig)
+    {
+        std::cout << jsonConfig.toStdString() << std::endl;
+        QVariantMap cmdMap;
+        QByteArray jsonArray = jsonConfig.toLatin1();
+        RtnStatus status = cameraWindowPtr_ -> setConfigurationFromJson(jsonArray);
+        cmdMap.insert("success", status.success);
+        cmdMap.insert("message", status.message);
+        cmdMap.insert("value", "");
+        return cmdMap;
+    }
+
+
     void BasicHttpServer::sendBadRequestResp(QTextStream &os, QString msg)
     { 
 
         os << "</body>\n";
         os << "</html>\n";
     }
-}
+
+
+    QStringList splitRequestString(QString reqString)
+    {
+        QStringList reqList;
+        if (reqString.isEmpty())
+        {
+            return reqList;
+        }
+
+        QString marks;
+        unsigned int parenCnt = 0;
+        for (unsigned int i=0; i<reqString.length(); i++)
+        {
+            if ((reqString[i] == ' ') && (parenCnt == 0))
+            {
+                marks.append('1');
+            }
+            else
+            {
+                marks.append('0');
+            }
+            if (reqString[i] == '{')
+            {
+                parenCnt++;
+            }
+            if (reqString[i] == '}') 
+            {
+                parenCnt--;
+            }
+        }
+        std::cout << marks.toStdString() << std::endl;
+
+
+        return reqList;
+    }
+
+} // namespace bias

src/gui/basic_http_server.hpp

 #include <QTcpServer>
 #include <QPointer>
 #include <QString>
+#include <QStringList>
 #include <QTextStream>
 #include <QMap>
 #include <QVariantMap>
             QVariantMap handleStartCaptureRequest();
             QVariantMap handleStopCaptureRequest();
             QVariantMap handleGetConfiguration();
+            QVariantMap handleSetConfiguration(QString jsonConfig);
 
             void sendBadRequestResp(QTextStream &os, QString msg);
             void sendRunningResp(QTextStream &os);
 
     };
 
+    QStringList splitRequestString(QString reqString);
+
 
 } // namespace bias
 

src/gui/camera_window.cpp

     }
 
 
-    bool CameraWindow::setConfigurationFromJson(QByteArray jsonConfig)
+    RtnStatus CameraWindow::setConfigurationFromJson(
+            QByteArray jsonConfig, 
+            bool showErrorDlg
+            )
     {
+        RtnStatus rtnStatus;
+        QString errMsgTitle("Load Configuration Error");
+
         bool ok;
-        RtnStatus rtnStatus;
         QVariantMap configMap = QtJson::parse(QString(jsonConfig), ok).toMap();
-        QVariantMap oldConfigMap = getConfigurationMap(rtnStatus);
-        QString errMsgTitle("Load Configuration Error");
         if (!ok)
         {
             QString errMsgText("Error loading configuration - "); 
             errMsgText += "unable to parse json.";
-            QMessageBox::critical(this, errMsgTitle, errMsgText);
-            return false;
+            if (showErrorDlg) 
+            {
+                QMessageBox::critical(this, errMsgTitle, errMsgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = errMsgText;
+            return rtnStatus;
         }
 
-        ok = setConfigurationFromMap(configMap);
-        if (!ok)
+        QVariantMap oldConfigMap = getConfigurationMap(rtnStatus);
+
+        rtnStatus = setConfigurationFromMap(configMap);
+        if (!rtnStatus.success)
         {
             // Something went wrong - try to revert to old configuration
-            ok = setConfigurationFromMap(oldConfigMap);
-            if (!ok)
+            rtnStatus = setConfigurationFromMap(oldConfigMap);
+            if (!rtnStatus.success)
             {
-                QString errMsgText("Error loading configuration and ");  
-                errMsgText += "unable to revert to previous configuration";
-                QMessageBox::critical(this, errMsgTitle, errMsgText);
-                return false;
+                QString errMsgText("Error loading configuration, worse yet");  
+                errMsgText += " unable to revert to previous configuration";
+                if (showErrorDlg)
+                {
+                    QMessageBox::critical(this, errMsgTitle, errMsgText);
+                }
+                rtnStatus.success = false;
+                rtnStatus.message = errMsgText;
+                return rtnStatus;
             }
             else
             {
-                QString errMsgText("Error loading configuration - ");  
-                errMsgText += "reverting to previous configuration";
-                QMessageBox::critical(this, errMsgTitle, errMsgText);
-                return false;
+                QString errMsgText("Error loading configuration");  
+                errMsgText += " reverting to previous configuration";
+                if (showErrorDlg)
+                {
+                    QMessageBox::critical(this, errMsgTitle, errMsgText);
+                }
+                rtnStatus.success = false;
+                rtnStatus.message = errMsgText;
+                return rtnStatus;
             }
         }
         updateAllMenus();
-        return true;
+        rtnStatus.success = true;
+        rtnStatus.message = QString("Configuration set successfully");
+        return rtnStatus;
     }
 
 
-    bool CameraWindow::setConfigurationFromMap(QVariantMap configMap)
+    RtnStatus CameraWindow::setConfigurationFromMap(
+            QVariantMap configMap, 
+            bool showErrorDlg
+            )
     {
-        bool ok = true;
+        RtnStatus rtnStatus;
         QString errMsgTitle("Load Configuration Error");
 
         // Set camera properties, videomode, etc.
         if (cameraMap.isEmpty())
         {
             QString errMsgText("Camera configuration is empty");
-            QMessageBox::critical(this,errMsgTitle,errMsgText);
-            return false;
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this,errMsgTitle,errMsgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = errMsgText;
+            return rtnStatus;
         }
+
+        // --------------------------------------------
+        // TO DO ... add rtnStatus to setCameraFrommap
+        // --------------------------------------------
         if (!setCameraFromMap(cameraMap))
         {
-            return false;
+            rtnStatus.success = false;
+            rtnStatus.message = QString("Unable to set camera values");
+            return rtnStatus;
         }
 
         // Set logging configuration
         if (loggingMap.isEmpty())
         {
             QString errMsgText("Logging configuration is empty");
-            QMessageBox::critical(this,errMsgTitle,errMsgText);
-            return false;
+            if (showErrorDlg) 
+            {
+                QMessageBox::critical(this,errMsgTitle,errMsgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = errMsgText;
+            return rtnStatus;
         }
+
+        //------------------------------------------------
+        //  TO DO ... add RtnStatus to  setLoggingFromMap
+        //------------------------------------------------
         if (!setLoggingFromMap(loggingMap))
         {
-            return false;
+            rtnStatus.success = false;
+            rtnStatus.message = QString("Unable to set logging values");
+            return rtnStatus;
         }
 
         // Set timer configuration
         if (timerMap.isEmpty())
         {
             QString errMsgText("Timer configuration is empty");
-            QMessageBox::critical(this,errMsgTitle,errMsgText);
-            return false;
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this,errMsgTitle,errMsgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = errMsgText;
+            return rtnStatus;
         }
+        // --------------------------------------------
+        // TO DO  .. add RtnStatus to setTimerFromMap
+        // --------------------------------------------
         if (!setTimerFromMap(timerMap))
         {
-            return false;
+            rtnStatus.success = false;
+            rtnStatus.message = QString("Unable to set timer from map");
+            return rtnStatus;
         }
 
         // Set display configuration
         if (displayMap.isEmpty())
         {
             QString errMsgText("Display configuration is empty");
-            QMessageBox::critical(this,errMsgTitle,errMsgText);
-            return false;
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this,errMsgTitle,errMsgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = errMsgText;
+            return rtnStatus;
         }
+        // ----------------------------------------------
+        // TO DO ... add RtnStatus to setDisplayFromMap
+        // ----------------------------------------------
         if (!setDisplayFromMap(displayMap))
         {
-            return false;
+            rtnStatus.success = false;
+            rtnStatus.message = QString("Unable to set display");
+            return rtnStatus;
         }
 
         // Set configuration file configuraiton 
         if (configFileMap.isEmpty())
         {
             QString errMsgText("Configuration file information is empty");
-            QMessageBox::critical(this,errMsgTitle,errMsgText);
-            return false;
+            if (showErrorDlg) 
+            {
+                QMessageBox::critical(this,errMsgTitle,errMsgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = errMsgText;
+            return rtnStatus;
         }
+        // -------------------------------------------------
+        // TO DO ... add RtnStatus to setConfigFileFromMap
+        // -------------------------------------------------
         if (!setConfigFileFromMap(configFileMap))
         {
-            return false;
+            rtnStatus.success = false;
+            rtnStatus.message = QString("Unable to set configuration file");
+            return rtnStatus;
         }
 
-        return true;
+        rtnStatus.success = true;
+        rtnStatus.message = QString("configuration set successfully");
+        return rtnStatus;
     }
 
 

src/gui/camera_window.hpp

             RtnStatus disconnectCamera(bool showErrorDlg=true);
             RtnStatus startImageCapture(bool showErrorDlg=true);
             RtnStatus stopImageCapture(bool showErrorDlg=true);
+
+            RtnStatus setConfigurationFromJson(
+                    QByteArray jsonConfig, 
+                    bool showErrorDlg=true
+                    );
+            RtnStatus setConfigurationFromMap(
+                    QVariantMap configMap, 
+                    bool showErrorDlg=true
+                    );
+
             QByteArray getConfigurationJson(
                     RtnStatus &rtnStatus, 
                     bool showErrorDlg=true
                     RtnStatus &rtnStatus, 
                     bool showErrorDlg=true
                     );
-
             void saveConfiguration(QString filename);
             void loadConfiguration(QString fileName);
-            bool setConfigurationFromJson(QByteArray jsonConfig);
-            bool setConfigurationFromMap(QVariantMap configMap);
 
         signals:
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.