Files
MuditaOS/module-services/service-desktop/parser/MessageHandler.cpp
Bartek Cichocki f07b337e2d [EGD-3463] Added service-desktop <-> DB interface
added changelog entry

added simple tests

added simple negative tests

fixed empty number contact case, added appropiate test
2020-08-07 09:30:51 +02:00

65 lines
2.2 KiB
C++

#include "MessageHandler.hpp"
#include "Contacts.hpp"
#include "EndpointHandler.hpp"
#include "log/log.hpp"
#include "ParserUtils.hpp"
using namespace ParserStateMachine;
xQueueHandle MessageHandler::sendQueue;
MessageHandler::MessageHandler(std::string &message, sys::Service *OwnerService)
: messageJson(json11::Json::parse(message, JsonErrorMsg)), OwnerServicePtr(OwnerService)
{}
void MessageHandler::processMessage()
{
auto body = messageJson[json::body];
int endpoint = messageJson[json::endpoint].number_value();
unsigned long uuid = messageJson[json::uuid].number_value();
int method = messageJson[json::method].number_value();
LOG_DEBUG(
"[MsgHandler]\nmethod: %d\nendpoint: %d\nuuid: %lu\nbody: %s\n", method, endpoint, uuid, body.dump().c_str());
std::string responseStr;
switch (static_cast<Endpoint>(endpoint)) {
case Endpoint::deviceInfo:
EndpointHandler::deviceInfo(method, uuid, body, responseStr, OwnerServicePtr);
LOG_DEBUG("[ENDPOINT] DeviceInfo: %s", responseStr.c_str());
putToSendQueue(responseStr);
break;
case Endpoint::update:
EndpointHandler::update(method, uuid, body, responseStr, OwnerServicePtr);
LOG_DEBUG("[ENDPOINT] Update: %s", responseStr.c_str());
putToSendQueue(responseStr);
break;
case Endpoint::backup:
EndpointHandler::backup(method, uuid, body, responseStr, OwnerServicePtr);
LOG_DEBUG("[ENDPOINT] Backup: %s", responseStr.c_str());
putToSendQueue(responseStr);
break;
case Endpoint::restore:
EndpointHandler::restore(method, uuid, body, responseStr, OwnerServicePtr);
LOG_DEBUG("[ENDPOINT] Restore: %s", responseStr.c_str());
putToSendQueue(responseStr);
break;
case Endpoint::contacts:
EndpointHandler::contacts(method, uuid, body, responseStr, OwnerServicePtr);
break;
default:
break;
}
}
void MessageHandler::putToSendQueue(const std::string msg)
{
#if defined(TARGET_RT1051)
if (uxQueueSpacesAvailable(sendQueue) != 0) {
auto *responseString = new std::string(msg);
xQueueSend(sendQueue, &responseString, portMAX_DELAY);
}
#endif
}