2020-08-13 20:53:35 +02:00
|
|
|
#include "TcDistributor.h"
|
2020-10-01 13:23:06 +02:00
|
|
|
|
|
|
|
#include "../serviceinterface/ServiceInterfaceStream.h"
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../tmtcservices/TmTcMessage.h"
|
|
|
|
#include "../ipc/QueueFactory.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
TcDistributor::TcDistributor(object_id_t objectId) :
|
|
|
|
SystemObject(objectId) {
|
|
|
|
tcQueue = QueueFactory::instance()->
|
|
|
|
createMessageQueue(DISTRIBUTER_MAX_PACKETS);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TcDistributor::~TcDistributor() {
|
2018-07-12 16:29:32 +02:00
|
|
|
QueueFactory::instance()->deleteMessageQueue(tcQueue);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t TcDistributor::performOperation(uint8_t opCode) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t status = RETURN_OK;
|
2018-07-12 16:29:32 +02:00
|
|
|
for (status = tcQueue->receiveMessage(¤tMessage); status == RETURN_OK;
|
|
|
|
status = tcQueue->receiveMessage(¤tMessage)) {
|
2016-06-15 23:48:41 +02:00
|
|
|
status = handlePacket();
|
|
|
|
}
|
2018-07-13 18:28:26 +02:00
|
|
|
if (status == MessageQueueIF::EMPTY) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return RETURN_OK;
|
|
|
|
} else {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TcDistributor::handlePacket() {
|
|
|
|
|
2020-10-01 13:23:06 +02:00
|
|
|
TcMqMapIter queueMapIt = this->selectDestination();
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t returnValue = RETURN_FAILED;
|
|
|
|
if (queueMapIt != this->queueMap.end()) {
|
2018-07-12 16:29:32 +02:00
|
|
|
returnValue = this->tcQueue->sendMessage(queueMapIt->second,
|
2016-06-15 23:48:41 +02:00
|
|
|
&this->currentMessage);
|
|
|
|
}
|
|
|
|
return this->callbackAfterSending(returnValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TcDistributor::print() {
|
2020-10-01 13:23:06 +02:00
|
|
|
sif::debug << "Distributor content is: " << std::endl
|
|
|
|
<< "ID\t| Message Queue ID" << std::endl;
|
|
|
|
sif::debug << std::setfill('0') << std::setw(8) << std::hex;
|
|
|
|
for (const auto& queueMapIter: queueMap) {
|
|
|
|
sif::debug << queueMapIter.first << "\t| 0x" << queueMapIter.second
|
|
|
|
<< std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-10-01 13:23:06 +02:00
|
|
|
sif::debug << std::setfill(' ') << std::dec;
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t TcDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|