Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tcm intermittent reception #604

Merged
merged 3 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,25 +463,14 @@ int CARMACloudPlugin::StartWebService()
QHostAddress address = QHostAddress(QString::fromStdString (webip));
quint16 port = static_cast<quint16>(webport);

QSharedPointer<OpenAPI::OAIApiRequestHandler> handler(new OpenAPI::OAIApiRequestHandler());
handler = QSharedPointer<OpenAPI::OAIApiRequestHandler> (new OpenAPI::OAIApiRequestHandler());

auto router = QSharedPointer<OpenAPI::OAIApiRouter>::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, [this](QHttpEngine::Socket *socket)
{
this->CARMAResponseHandler(socket);
socket->close(); });
QHttpEngine::Server server(&apiHandler);

if (!server.listen(address, port)) {
qCritical("Unable to listen on the specified port.");
return 1;
}
Expand Down
5 changes: 4 additions & 1 deletion src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include <unistd.h>
#endif
#include <qhttpengine/server.h>
#include <qhttpengine/qobjecthandler.h>
#include <v2xhubWebAPI/OAIApiRouter.h>


Expand Down Expand Up @@ -99,6 +100,7 @@ class CARMACloudPlugin: public PluginClient {
uint16_t webport;
std::string webip;
uint16_t fetchtime;
void CARMAResponseHandler(QHttpEngine::Socket *socket);
protected:

void UpdateConfigSettings();
Expand All @@ -109,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);
Expand Down Expand Up @@ -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 QString TCM_REPLY="tcmreply";

};
std::mutex _cfgLock;
Expand Down
Loading