restructure repository

This commit is contained in:
2021-07-13 18:40:52 +02:00
parent 5adb5cce95
commit bdb8b0a757
738 changed files with 0 additions and 78 deletions

View File

@ -0,0 +1,232 @@
#include "HousekeepingMessage.h"
#include "../objectmanager/ObjectManager.h"
#include <cstring>
HousekeepingMessage::~HousekeepingMessage() {}
void HousekeepingMessage::setHkReportReply(CommandMessage* message, sid_t sid,
store_address_t storeId) {
message->setCommand(HK_REPORT);
message->setMessageSize(HK_MESSAGE_SIZE);
setSid(message, sid);
message->setParameter3(storeId.raw);
}
void HousekeepingMessage::setHkDiagnosticsReply(CommandMessage* message,
sid_t sid, store_address_t storeId) {
message->setCommand(DIAGNOSTICS_REPORT);
message->setMessageSize(HK_MESSAGE_SIZE);
setSid(message, sid);
message->setParameter3(storeId.raw);
}
sid_t HousekeepingMessage::getHkDataReply(const CommandMessage *message,
store_address_t *storeIdToSet) {
if(storeIdToSet != nullptr) {
*storeIdToSet = message->getParameter3();
}
return getSid(message);
}
void HousekeepingMessage::setToggleReportingCommand(CommandMessage *message,
sid_t sid, bool enableReporting, bool isDiagnostics) {
if(isDiagnostics) {
if(enableReporting) {
message->setCommand(ENABLE_PERIODIC_DIAGNOSTICS_GENERATION);
}
else {
message->setCommand(DISABLE_PERIODIC_DIAGNOSTICS_GENERATION);
}
}
else {
if(enableReporting) {
message->setCommand(ENABLE_PERIODIC_HK_REPORT_GENERATION);
}
else {
message->setCommand(DISABLE_PERIODIC_HK_REPORT_GENERATION);
}
}
setSid(message, sid);
}
void HousekeepingMessage::setStructureReportingCommand(CommandMessage *command,
sid_t sid, bool isDiagnostics) {
if(isDiagnostics) {
command->setCommand(REPORT_DIAGNOSTICS_REPORT_STRUCTURES);
}
else {
command->setCommand(REPORT_HK_REPORT_STRUCTURES);
}
setSid(command, sid);
}
void HousekeepingMessage::setOneShotReportCommand(CommandMessage *command,
sid_t sid, bool isDiagnostics) {
if(isDiagnostics) {
command->setCommand(GENERATE_ONE_DIAGNOSTICS_REPORT);
}
else {
command->setCommand(GENERATE_ONE_PARAMETER_REPORT);
}
setSid(command, sid);
}
void HousekeepingMessage::setCollectionIntervalModificationCommand(
CommandMessage *command, sid_t sid, float collectionInterval,
bool isDiagnostics) {
if(isDiagnostics) {
command->setCommand(MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL);
}
else {
command->setCommand(MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL);
}
/* Raw storage of the float in the message. Do not use setParameter3, does
implicit conversion to integer type! */
std::memcpy(command->getData() + 2 * sizeof(uint32_t), &collectionInterval,
sizeof(collectionInterval));
setSid(command, sid);
}
sid_t HousekeepingMessage::getCollectionIntervalModificationCommand(
const CommandMessage* command, float* newCollectionInterval) {
if(newCollectionInterval != nullptr) {
std::memcpy(newCollectionInterval, command->getData() + 2 * sizeof(uint32_t),
sizeof(*newCollectionInterval));
}
return getSid(command);
}
void HousekeepingMessage::setHkRequestSuccessReply(CommandMessage *reply,
sid_t sid) {
setSid(reply, sid);
reply->setCommand(HK_REQUEST_SUCCESS);
}
void HousekeepingMessage::setHkRequestFailureReply(CommandMessage *reply,
sid_t sid, ReturnValue_t error) {
setSid(reply, sid);
reply->setCommand(HK_REQUEST_FAILURE);
reply->setParameter3(error);
}
sid_t HousekeepingMessage::getHkRequestFailureReply(const CommandMessage *reply,
ReturnValue_t *error) {
if(error != nullptr) {
*error = reply->getParameter3();
}
return getSid(reply);
}
sid_t HousekeepingMessage::getSid(const CommandMessage* message) {
sid_t sid;
std::memcpy(&sid.raw, message->getData(), sizeof(sid.raw));
return sid;
}
gp_id_t HousekeepingMessage::getGpid(const CommandMessage* message) {
gp_id_t globalPoolId;
std::memcpy(&globalPoolId.raw, message->getData(), sizeof(globalPoolId.raw));
return globalPoolId;
}
void HousekeepingMessage::setHkStuctureReportReply(CommandMessage *reply,
sid_t sid, store_address_t storeId) {
reply->setCommand(HK_DEFINITIONS_REPORT);
setSid(reply, sid);
reply->setParameter3(storeId.raw);
}
void HousekeepingMessage::setDiagnosticsStuctureReportReply(
CommandMessage *reply, sid_t sid, store_address_t storeId) {
reply->setCommand(DIAGNOSTICS_DEFINITION_REPORT);
setSid(reply, sid);
reply->setParameter3(storeId.raw);
}
void HousekeepingMessage::clear(CommandMessage* message) {
switch(message->getCommand()) {
case(HK_REPORT):
case(DIAGNOSTICS_REPORT):
case(HK_DEFINITIONS_REPORT):
case(DIAGNOSTICS_DEFINITION_REPORT):
case(UPDATE_SNAPSHOT_SET):
case(UPDATE_SNAPSHOT_VARIABLE): {
store_address_t storeId;
getHkDataReply(message, &storeId);
StorageManagerIF *ipcStore = ObjectManager::instance()->get<StorageManagerIF>(
objects::IPC_STORE);
if (ipcStore != nullptr) {
ipcStore->deleteData(storeId);
}
}
}
message->setCommand(CommandMessage::CMD_NONE);
}
void HousekeepingMessage::setUpdateNotificationSetCommand(
CommandMessage *command, sid_t sid) {
command->setCommand(UPDATE_NOTIFICATION_SET);
setSid(command, sid);
}
void HousekeepingMessage::setUpdateNotificationVariableCommand(
CommandMessage *command, gp_id_t globalPoolId) {
command->setCommand(UPDATE_NOTIFICATION_VARIABLE);
setGpid(command, globalPoolId);
}
void HousekeepingMessage::setUpdateSnapshotSetCommand(CommandMessage *command,
sid_t sid, store_address_t storeId) {
command->setCommand(UPDATE_SNAPSHOT_SET);
setSid(command, sid);
command->setParameter3(storeId.raw);
}
void HousekeepingMessage::setUpdateSnapshotVariableCommand(
CommandMessage *command, gp_id_t globalPoolId, store_address_t storeId) {
command->setCommand(UPDATE_SNAPSHOT_VARIABLE);
setGpid(command, globalPoolId);
command->setParameter3(storeId.raw);
}
sid_t HousekeepingMessage::getUpdateNotificationSetCommand(
const CommandMessage *command) {
return getSid(command);
}
gp_id_t HousekeepingMessage::getUpdateNotificationVariableCommand(
const CommandMessage *command) {
return getGpid(command);
}
sid_t HousekeepingMessage::getUpdateSnapshotSetCommand(
const CommandMessage *command, store_address_t *storeId) {
if(storeId != nullptr) {
*storeId = command->getParameter3();
}
return getSid(command);
}
gp_id_t HousekeepingMessage::getUpdateSnapshotVariableCommand(
const CommandMessage *command, store_address_t *storeId) {
if(storeId != nullptr) {
*storeId = command->getParameter3();
}
return getGpid(command);
}
void HousekeepingMessage::setSid(CommandMessage *message, sid_t sid) {
std::memcpy(message->getData(), &sid.raw, sizeof(sid.raw));
}
void HousekeepingMessage::setGpid(CommandMessage *message, gp_id_t globalPoolId) {
std::memcpy(message->getData(), &globalPoolId.raw, sizeof(globalPoolId.raw));
}

View File

@ -0,0 +1,90 @@
#include "PeriodicHousekeepingHelper.h"
#include "../datapoollocal/LocalPoolDataSetBase.h"
#include <cmath>
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(
LocalPoolDataSetBase* owner): owner(owner) {}
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
dur_millis_t minimumPeriodicInterval, uint8_t nonDiagIntervalFactor) {
this->minimumPeriodicInterval = minimumPeriodicInterval;
this->nonDiagIntervalFactor = nonDiagIntervalFactor;
collectionIntervalTicks = intervalSecondsToIntervalTicks(collectionInterval);
/* This will cause a checkOpNecessary call to be true immediately. I think it's okay
if a HK packet is generated immediately instead of waiting one generation cycle. */
internalTickCounter = collectionIntervalTicks;
}
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() const {
return intervalTicksToSeconds(collectionIntervalTicks);
}
bool PeriodicHousekeepingHelper::checkOpNecessary() {
if(internalTickCounter >= collectionIntervalTicks) {
internalTickCounter = 1;
return true;
}
internalTickCounter++;
return false;
}
uint32_t PeriodicHousekeepingHelper::intervalSecondsToIntervalTicks(
float collectionIntervalSeconds) {
if(owner == nullptr) {
return 0;
}
bool isDiagnostics = owner->isDiagnostics();
/* Avoid division by zero */
if(minimumPeriodicInterval == 0) {
if(isDiagnostics) {
/* Perform operation each cycle */
return 1;
}
else {
return nonDiagIntervalFactor;
}
}
else {
dur_millis_t intervalInMs = collectionIntervalSeconds * 1000;
uint32_t divisor = minimumPeriodicInterval;
if(not isDiagnostics) {
/* We need to multiply the divisor because non-diagnostics only
allow a multiple of the minimum periodic interval */
divisor *= nonDiagIntervalFactor;
}
uint32_t ticks = std::ceil(static_cast<float>(intervalInMs) / divisor);
if(not isDiagnostics) {
/* Now we need to multiply the calculated ticks with the factor as as well
because the minimum tick count to generate a non-diagnostic is the factor itself.
Example calculation for non-diagnostic with
0.4 second interval and 0.2 second task interval.
Resultant tick count of 5 is equal to operation each second.
Examle calculation for non-diagnostic with 2.0 second interval and 0.2 second
task interval.
Resultant tick count of 10 is equal to operatin every 2 seconds.
Example calculation for diagnostic with 0.4 second interval and 0.3
second task interval. Resulting tick count of 2 is equal to operation
every 0.6 seconds. */
ticks *= nonDiagIntervalFactor;
}
return ticks;
}
}
float PeriodicHousekeepingHelper::intervalTicksToSeconds(
uint32_t collectionInterval) const {
/* Number of ticks times the minimum interval is in milliseconds, so we divide by 1000 to get
the value in seconds */
return static_cast<float>(collectionInterval * minimumPeriodicInterval / 1000.0);
}
void PeriodicHousekeepingHelper::changeCollectionInterval(
float newIntervalSeconds) {
collectionIntervalTicks = intervalSecondsToIntervalTicks(newIntervalSeconds);
}