From 47370d7d5f9c5528743284364e95cce357ce9ad5 Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Sat, 13 Apr 2024 00:49:49 -0400 Subject: [PATCH 1/3] init --- .../CARMACloudPlugin/src/CARMACloudPlugin.cpp | 27 ++++++------------- .../CARMACloudPlugin/src/CARMACloudPlugin.h | 3 +++ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp index 651384e09..1e723b20e 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp @@ -463,25 +463,14 @@ int CARMACloudPlugin::StartWebService() QHostAddress address = QHostAddress(QString::fromStdString (webip)); quint16 port = static_cast(webport); - QSharedPointer handler(new OpenAPI::OAIApiRequestHandler()); - handler = QSharedPointer (new OpenAPI::OAIApiRequestHandler()); - - auto router = QSharedPointer::create(); - router->setUpRoutes(); - - QObject::connect(handler.data(), &OpenAPI::OAIApiRequestHandler::requestReceived, [&](QHttpEngine::Socket *socket) { - - CARMAResponseHandler(socket); - }); - - QObject::connect(handler.data(), &OpenAPI::OAIApiRequestHandler::requestReceived, [&](QHttpEngine::Socket *socket) { - - router->processRequest(socket); - }); - - QHttpEngine::Server server(handler.data()); - - if (!server.listen(address, port)) { + QHttpEngine::QObjectHandler apiHandler; + apiHandler.registerMethod(TCM_REPLY, [&](QHttpEngine::Socket *socket) + { + CARMAResponseHandler(socket); + socket->close(); }); + QHttpEngine::Server server(&apiHandler); + + if (!server.listen(address, port)) { qCritical("Unable to listen on the specified port."); return 1; } diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h index 066e65756..75fe9d6b0 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h @@ -67,6 +67,7 @@ #include #endif #include +#include #include @@ -210,6 +211,8 @@ class CARMACloudPlugin: public PluginClient { const char *CONTENT_ENCODING_KEY = "Content-Encoding"; const char *CONTENT_ENCODING_VALUE = "gzip"; std::string list_tcm = "true"; + //API URL to accept TCM response + const std::string TCM_REPLY="tcmreply"; }; std::mutex _cfgLock; From feafe1632fb6a2c8e2c65df9edbbccfa09ec2ad4 Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Mon, 15 Apr 2024 08:55:20 -0400 Subject: [PATCH 2/3] update --- src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h index 75fe9d6b0..6384aa627 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h @@ -212,7 +212,7 @@ class CARMACloudPlugin: public PluginClient { const char *CONTENT_ENCODING_VALUE = "gzip"; std::string list_tcm = "true"; //API URL to accept TCM response - const std::string TCM_REPLY="tcmreply"; + const QString TCM_REPLY="tcmreply"; }; std::mutex _cfgLock; From ea4144138325f2f36d384bbc891078d7d9c35e13 Mon Sep 17 00:00:00 2001 From: dan-du-car Date: Mon, 15 Apr 2024 12:56:20 -0400 Subject: [PATCH 3/3] address codesmell --- src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp | 4 ++-- src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp index 1e723b20e..d2110c575 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp @@ -464,9 +464,9 @@ int CARMACloudPlugin::StartWebService() quint16 port = static_cast(webport); QHttpEngine::QObjectHandler apiHandler; - apiHandler.registerMethod(TCM_REPLY, [&](QHttpEngine::Socket *socket) + apiHandler.registerMethod(TCM_REPLY, [this](QHttpEngine::Socket *socket) { - CARMAResponseHandler(socket); + this->CARMAResponseHandler(socket); socket->close(); }); QHttpEngine::Server server(&apiHandler); diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h index 6384aa627..9a9d85061 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h @@ -100,6 +100,7 @@ class CARMACloudPlugin: public PluginClient { uint16_t webport; std::string webip; uint16_t fetchtime; + void CARMAResponseHandler(QHttpEngine::Socket *socket); protected: void UpdateConfigSettings(); @@ -110,7 +111,6 @@ class CARMACloudPlugin: public PluginClient { void OnStateChange(IvpPluginState state); int StartWebService(); - void CARMAResponseHandler(QHttpEngine::Socket *socket); int CloudSend(const string& msg,const string& url, const string& base, const string& method); //Send HTTP request async void CloudSendAsync(const string& msg,const string& url, const string& base, const string& method);