Commits

iorodeo  committed 1c5d7ff

Added additional commands to external http server. Save/load configuration, get
camera guid, get frame count.

  • Participants
  • Parent commits e035d2c

Comments (0)

Files changed (4)

File src/gui/basic_http_server.cpp

         os << "Content-Type: application/json; charset=\"utf-8\"\r\n\r\n";
 
         // Handle requests
-        //QVariantMap respMap;
-        //QVariantMap respMap;
         QVariantList respList;
         QVariantMap cmdMap;
         for (unsigned int i=0; i<paramsList.size(); i++)
         }
         else if (name == QString("enable-logging"))
         {
-            cmdMap.insert("success", true);
-            cmdMap.insert("message", "");
-            cmdMap.insert("value", "");
+            cmdMap = handleLoggingEnable();
         }
         else if (name == QString("disable-logging"))
         {
-            cmdMap.insert("success", true);
-            cmdMap.insert("message", "");
-            cmdMap.insert("value", "");
+            cmdMap = handleLoggingDisable();
         }
-        else if (name == QString("set-config-file"))
+        else if (name == QString("load-configuration"))
         {
-            cmdMap.insert("success", true);
-            cmdMap.insert("message", "");
-            cmdMap.insert("value", "");
+            cmdMap = handleLoadConfiguration(value);
+        }
+        else if (name == QString("save-configuration"))
+        {
+            cmdMap = handleSaveConfiguration(value);
         }
         else if (name == QString("get-frame-count"))
         {
-            cmdMap.insert("success", true);
-            cmdMap.insert("message", "");
-            cmdMap.insert("value", "");
+            cmdMap = handleGetFrameCount();
         }
         else if (name == QString("get-camera-guid"))
         {
-            cmdMap.insert("success", true);
-            cmdMap.insert("message", "");
-            cmdMap.insert("value", "");
+            cmdMap = handleGetCameraGuid();
         }
         else if (name == QString("get-status"))
         {
 
     QVariantMap BasicHttpServer::handleSetConfiguration(QString jsonConfig)
     {
-        std::cout << jsonConfig.toStdString() << std::endl;
         QVariantMap cmdMap;
         QByteArray jsonArray = jsonConfig.toLatin1();
         RtnStatus status = cameraWindowPtr_ -> setConfigurationFromJson(jsonArray);
     }
 
 
+    QVariantMap BasicHttpServer::handleLoggingEnable()
+    {
+        QVariantMap cmdMap;
+        RtnStatus status = cameraWindowPtr_ -> enableLogging(false);
+        cmdMap.insert("success", status.success);
+        cmdMap.insert("message", status.message);
+        cmdMap.insert("value", "");
+        return cmdMap;
+    }
+
+
+    QVariantMap BasicHttpServer::handleLoggingDisable()
+    {
+        QVariantMap cmdMap;
+        RtnStatus status = cameraWindowPtr_ -> disableLogging(false);
+        cmdMap.insert("success", status.success);
+        cmdMap.insert("message", status.message);
+        cmdMap.insert("value", "");
+        return cmdMap;
+    }
+
+
+    QVariantMap BasicHttpServer::handleSaveConfiguration(QString fileName)
+    {
+        QVariantMap cmdMap;
+        RtnStatus status = cameraWindowPtr_ -> saveConfiguration(fileName,false);
+        cmdMap.insert("success", status.success);
+        cmdMap.insert("message", status.message);
+        cmdMap.insert("value", "");
+        return cmdMap;
+    }
+
+
+    QVariantMap BasicHttpServer::handleLoadConfiguration(QString fileName)
+    {
+        QVariantMap cmdMap;
+        RtnStatus status = cameraWindowPtr_ -> loadConfiguration(fileName,false);
+        cmdMap.insert("success", status.success);
+        cmdMap.insert("message", status.message);
+        cmdMap.insert("value", "");
+        return cmdMap;
+    }
+
+    
+    QVariantMap BasicHttpServer::handleGetFrameCount()
+    {
+        QVariantMap cmdMap;
+        unsigned long frameCount = cameraWindowPtr_ -> getFrameCount();
+        cmdMap.insert("success", true);
+        cmdMap.insert("message", QString("Frame count retrieved successfully"));
+        cmdMap.insert("value", qulonglong(frameCount));
+        return cmdMap;
+    }
+
+    QVariantMap BasicHttpServer::handleGetCameraGuid()
+    {
+        QVariantMap cmdMap;
+        RtnStatus status; 
+        QString guid = cameraWindowPtr_ -> getCameraGuidString(status);
+        cmdMap.insert("success", status.success);
+        cmdMap.insert("message", status.message);
+        if (status.success)
+        {
+            cmdMap.insert("value", guid);
+        }
+        else
+        {
+            cmdMap.insert("value", "");
+        }
+        return cmdMap;
+    }
+
+
     void BasicHttpServer::sendBadRequestResp(QTextStream &os, QString msg)
     { 
 

File src/gui/basic_http_server.hpp

             QVariantMap handleStopCaptureRequest();
             QVariantMap handleGetConfiguration();
             QVariantMap handleSetConfiguration(QString jsonConfig);
+            QVariantMap handleLoggingEnable();
+            QVariantMap handleLoggingDisable();
+            QVariantMap handleSaveConfiguration(QString fileName);
+            QVariantMap handleLoadConfiguration(QString fileName);
+            QVariantMap handleGetCameraGuid();
+            QVariantMap handleGetFrameCount();
 
             void sendBadRequestResp(QTextStream &os, QString msg);
             void sendRunningResp(QTextStream &os);

File src/gui/camera_window.cpp

     }
 
 
-    void CameraWindow::saveConfiguration(QString fileName)
+    RtnStatus CameraWindow::saveConfiguration(QString fileName, bool showErrorDlg)
+    {
+        // --------------------------------------------------------------------
+        // TO DO  ... need to work on error checking. 
+        // --------------------------------------------------------------------
+        RtnStatus rtnStatus;
+        QString msgTitle("Save Configuration Error");
+
+        if (!connected_) 
+        { 
+            QString msgText("Unable to determine configuration: camera not connected");
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this, msgTitle, msgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = msgText;
+            return rtnStatus; 
+        }
+
+        QByteArray jsonConfig = getConfigurationJson(rtnStatus);
+        if ( (!rtnStatus.success) || (jsonConfig.isEmpty()) ) 
+        { 
+            return rtnStatus; 
+        }
+
+        QByteArray jsonConfigPretty = prettyIndentJson(jsonConfig); 
+        QFile configFile(fileName);
+
+        bool ok = configFile.open(QIODevice::WriteOnly);
+        if (!ok)
+        {
+            QString msgText = QString("Unable to open file %s").arg(fileName);
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this, msgTitle, msgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = msgText;
+            return rtnStatus;
+        }
+        configFile.write(jsonConfigPretty);
+        configFile.close(); 
+        rtnStatus.success = true;
+        rtnStatus.message = QString("Configuration saved successfully");
+        return rtnStatus;
+    } 
+    
+
+    RtnStatus CameraWindow::loadConfiguration(QString fileName, bool showErrorDlg) 
     {
         // --------------------------------------------------------------------
         // TO DO  ... need to add error checking. 
         // --------------------------------------------------------------------
-        if (!connected_) { return; }
         RtnStatus rtnStatus;
-        QByteArray jsonConfig = getConfigurationJson(rtnStatus);
-        if (jsonConfig.isEmpty()) 
-        { 
-            return; 
-        }
-        QByteArray jsonConfigPretty = prettyIndentJson(jsonConfig); 
+        QString msgTitle("Load Configuration Error");
         QFile configFile(fileName);
-        configFile.open(QIODevice::WriteOnly);
-        configFile.write(jsonConfigPretty);
-        configFile.close(); 
-    } 
-    
-
-    void CameraWindow::loadConfiguration(QString fileName) 
-    {
-        // --------------------------------------------------------------------
-        // TO DO  ... need to add error checking. 
-        // --------------------------------------------------------------------
-        QFile configFile(fileName);
+
         if (!configFile.exists())
         {
-            QString errMsgTitle("Load Configuration Error");
-            QString errMsgText("Error configuration file does not exist");
-            QMessageBox::critical(this, errMsgTitle, errMsgText);
-            return;
-        }
-        configFile.open(QIODevice::ReadOnly);
+            QString msgText = QString("Configuration file, %s, does not exist").arg(fileName);
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this, msgTitle, msgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = msgText;
+            return rtnStatus;
+        }
+
+        bool ok = configFile.open(QIODevice::ReadOnly);
+        if (!ok)
+        {
+            QString msgText = QString("Unable to open configuration file %s").arg(fileName);
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this, msgTitle, msgText);
+            }
+            rtnStatus.success = false;
+            rtnStatus.message = msgText;
+            return rtnStatus;
+        }
         QByteArray jsonConfig = configFile.readAll();
         configFile.close();
-        setConfigurationFromJson(jsonConfig);
+        rtnStatus = setConfigurationFromJson(jsonConfig,showErrorDlg);
+        return rtnStatus;
     }
 
 
     }
 
 
+    RtnStatus CameraWindow::enableLogging(bool showErrorDlg)
+    {
+        RtnStatus rtnStatus;
+        QString msgTitle("Logging Enable Error");
+
+        if (actionLoggingEnabledPtr_ -> isChecked())
+        {
+            QString msgText("Logging already enabled");
+            if (showErrorDlg) 
+            {
+                QMessageBox::critical(this, msgTitle, msgText);
+            }
+            rtnStatus.success = true;
+            rtnStatus.message = msgText;
+        }
+        else 
+        {
+            if (!haveDefaultVideoFileDir_)
+            {
+                QString msgText("Unable to determine default location for video files");
+                if (showErrorDlg)
+                {
+                    QMessageBox::critical(this, msgTitle, msgText);
+                }
+                rtnStatus.success = false;
+                rtnStatus.message = msgText;
+            }
+            else if (capturing_)
+            {
+                QString msgText("Unable to enable logging: capturing images");
+                if (showErrorDlg)
+                {
+                    QMessageBox::critical(this, msgTitle, msgText);
+                }
+                rtnStatus.success = false;
+                rtnStatus.message = msgText;
+            }
+            else
+            {
+                logging_ = true;
+                actionLoggingEnabledPtr_ -> setChecked(true);
+                rtnStatus.success = true;
+                rtnStatus.message = QString("Logging enabled");
+            }
+        }
+        return rtnStatus;
+    }
+
+
+    RtnStatus CameraWindow::disableLogging(bool showErrorDlg)
+    {
+        RtnStatus rtnStatus;
+        QString msgTitle("Logging Disable Error");
+
+        if (!(actionLoggingEnabledPtr_ -> isChecked()))
+        {
+            QString msgText("Logging already disabled");
+            if (showErrorDlg)
+            {
+                QMessageBox::critical(this, msgTitle, msgText);
+            }
+            rtnStatus.success = true;
+            rtnStatus.message = msgText;
+        }
+        else
+        {
+            if (capturing_)
+            {
+                QString msgText("Unable to disable logging: capturing images");
+                if (showErrorDlg)
+                {
+                    QMessageBox::critical(this, msgTitle, msgText);
+                }
+                rtnStatus.success = false;
+                rtnStatus.message = msgText;
+            }
+            else
+            {
+                logging_ = false;
+                actionLoggingEnabledPtr_ -> setChecked(false);
+                rtnStatus.success = true;
+                rtnStatus.message = QString("Logging disabled");
+            }
+        }
+        return rtnStatus;
+    }
+
+    
+    QString CameraWindow::getCameraGuidString(RtnStatus &rtnStatus)
+    {
+        if (!connected_)
+        {
+            rtnStatus.success = false;
+            rtnStatus.message = QString("Unable to get camera Guid: camera not connected");
+            QString emptyString;
+            return emptyString;
+        }
+
+        Guid guid = cameraPtr_ -> getGuid();
+        QString guidString = QString::fromStdString(guid.toString());
+        rtnStatus.success = true;
+        rtnStatus.message = QString("Camera guid acquired successfully");
+        return guidString;
+    }
+
+
+    unsigned long CameraWindow::getFrameCount()
+    {
+        return frameCount_;
+    }
+
     // Protected methods
     // ----------------------------------------------------------------------------------
 

File src/gui/camera_window.hpp

                     RtnStatus &rtnStatus, 
                     bool showErrorDlg=true
                     );
-            void saveConfiguration(QString filename);
-            void loadConfiguration(QString fileName);
+
+            RtnStatus enableLogging(bool showErrorDlg=true);
+            RtnStatus disableLogging(bool showErrorDlg=true);
+
+            RtnStatus saveConfiguration(
+                    QString filename, 
+                    bool showErrorDlg=true
+                    );
+
+            RtnStatus loadConfiguration(
+                    QString fileName, 
+                    bool showErrorDlg=true
+                    );
+
+            QString getCameraGuidString(RtnStatus &rtnStatus);
+
+            unsigned long getFrameCount();
+
 
         signals: