2016-06-15 23:48:41 +02:00
|
|
|
/**
|
|
|
|
* @file LimitViolationReporter.cpp
|
|
|
|
* @brief This file defines the LimitViolationReporter class.
|
|
|
|
* @date 17.07.2014
|
|
|
|
* @author baetz
|
|
|
|
*/
|
|
|
|
#include <framework/monitoring/LimitViolationReporter.h>
|
|
|
|
#include <framework/monitoring/MonitoringIF.h>
|
|
|
|
#include <framework/monitoring/ReceivesMonitoringReportsIF.h>
|
|
|
|
#include <framework/objectmanager/ObjectManagerIF.h>
|
|
|
|
#include <framework/serialize/SerializeAdapter.h>
|
|
|
|
|
|
|
|
ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF* data) {
|
|
|
|
ReturnValue_t result = checkClassLoaded();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
store_address_t storeId;
|
|
|
|
uint8_t* dataTarget = NULL;
|
2020-04-05 21:54:11 +02:00
|
|
|
size_t maxSize = data->getSerializedSize();
|
2016-06-15 23:48:41 +02:00
|
|
|
if (maxSize > MonitoringIF::VIOLATION_REPORT_MAX_SIZE) {
|
|
|
|
return MonitoringIF::INVALID_SIZE;
|
|
|
|
}
|
|
|
|
result = ipcStore->getFreeElement(&storeId, maxSize,
|
|
|
|
&dataTarget);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-05 17:58:39 +02:00
|
|
|
size_t size = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
result = data->serialize(&dataTarget, &size, maxSize, true);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-06-09 02:18:39 +02:00
|
|
|
MessageQueueMessage message;
|
|
|
|
CommandMessage report(&message);
|
2016-06-15 23:48:41 +02:00
|
|
|
MonitoringMessage::setLimitViolationReport(&report, storeId);
|
2020-06-22 19:22:52 +02:00
|
|
|
return MessageQueueSenderIF::sendMessage(reportQueue, &report,
|
|
|
|
MessageQueueMessage::MAX_MESSAGE_SIZE);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t LimitViolationReporter::checkClassLoaded() {
|
2018-07-12 16:29:32 +02:00
|
|
|
if (reportQueue == 0) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReceivesMonitoringReportsIF* receiver = objectManager->get<
|
2018-07-12 16:29:32 +02:00
|
|
|
ReceivesMonitoringReportsIF>(reportingTarget);
|
2016-06-15 23:48:41 +02:00
|
|
|
if (receiver == NULL) {
|
|
|
|
return ObjectManagerIF::NOT_FOUND;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
reportQueue = receiver->getCommandQueue();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
if (ipcStore == NULL) {
|
|
|
|
ipcStore = objectManager->get<StorageManagerIF>(objects::IPC_STORE);
|
|
|
|
if (ipcStore == NULL) {
|
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Lazy initialization.
|
2018-07-12 16:29:32 +02:00
|
|
|
MessageQueueId_t LimitViolationReporter::reportQueue = 0;
|
2016-06-15 23:48:41 +02:00
|
|
|
StorageManagerIF* LimitViolationReporter::ipcStore = NULL;
|
2018-07-12 16:29:32 +02:00
|
|
|
object_id_t LimitViolationReporter::reportingTarget = 0;
|