AbstractMsgQueue.cpp
Go to the documentation of this file.00001
00002
00003 #include <fesa-core/Core/AbstractMsgQueue.h>
00004
00005 #include <fesa-core/Exception/FesaException.h>
00006 #include <cmw-log/Logger.h>
00007
00008 namespace
00009 {
00010
00011 CMW::Log::Logger& logger = CMW::Log::LoggerFactory::getLogger("FESA.FWK.fesa-core.Utilities.ConfigData");
00012
00013 }
00014
00015 namespace fesa
00016 {
00017
00018 AbstractMsgQueue::AbstractMsgQueue(const std::string& name, MQ_TYPE type, uint32_t queuelength) :
00019 queueName_(name), queueType_(type), queueLength_(queuelength)
00020 {
00021 if (queuelength > constants_.msg_num_max_)
00022 {
00023 throw FesaException(__FILE__, __LINE__, FesaErrorQueueLengthExceeded.c_str(), "Creating", name.c_str());
00024 }
00025 std::ostringstream traceStringStream;
00026 traceStringStream << "Creating the MessageQueue: '" << queueName_ << "' of length " << queueLength_ ;
00027 LOG_TRACE_IF(logger, traceStringStream.str());
00028 }
00029
00030 uint32_t AbstractMsgQueue::isFull()
00031 {
00032 uint32_t curMsgCount = getCurrentMsgCount();
00033 if (curMsgCount == queueLength_)
00034 {
00035 return curMsgCount;
00036 }
00037 else
00038 {
00039 return 0;
00040 }
00041 }
00042
00043 AbstractMsgQueue::~AbstractMsgQueue()
00044 {
00045 }
00046
00047 uint32_t AbstractMsgQueue::isAlmostFull()
00048 {
00049 uint32_t curMsgCount = getCurrentMsgCount();
00050 uint32_t diff = queueLength_ - curMsgCount;
00051 if ((diff <= constants_.queue_diag_slots) && (diff > 0))
00052 {
00053 return curMsgCount;
00054 }
00055 else
00056 {
00057 return 0;
00058 }
00059 }
00060
00061 void AbstractMsgQueue::checkState(uint32_t msgPrio)
00062 {
00063 if (isFull())
00064 {
00065 throw FesaException(__FILE__, __LINE__, FesaErrorQueueFull.c_str(), "completly",
00066 "No place even for DIAG msg", queueName_.c_str());
00067 }
00068 else if (isAlmostFull() && (msgPrio != HIGH_MQ_PRIO))
00069 {
00070 throw FesaException(__FILE__, __LINE__, FesaErrorQueueFull.c_str(), "almost", "Only DIAG msg are allowed",
00071 queueName_.c_str());
00072 }
00073 }
00074
00075 }