RollingMultiplexingManager.cpp
Go to the documentation of this file.00001
00002
00003 #include <fesa-core/Synchronization/RollingMultiplexingManager.h>
00004
00005 #include <fesa-core/Synchronization/CycleDescriptor.h>
00006 #include <fesa-core/Synchronization/MultiplexingContext.h>
00007 #include <fesa-core/Exception/FesaException.h>
00008
00009 #include <sstream>
00010
00011
00012 namespace fesa
00013 {
00014
00015 RollingMultiplexingManager::RollingMultiplexingManager(std::string& name, CycleDescriptor* timingDescriptor,
00016 RollingMultiplexingDataManager* dataManager) :
00017 AbstractMultiplexingManager(name, timingDescriptor), dataManager_(dataManager)
00018 {
00019 }
00020
00021 RollingMultiplexingManager::RollingMultiplexingManager(RollingMultiplexingDataManager* dataManager) :
00022 AbstractMultiplexingManager("ROLLING", NULL), dataManager_(dataManager)
00023 {
00024
00025 }
00026
00027 int32_t RollingMultiplexingManager::getLastSlot(const std::string& cycleName)
00028 {
00029 int32_t cycleId = timingDescriptor_->getCycleSelectorId(cycleName);
00030 int32_t slot = dataManager_->findCycleIdBackward(cycleId);
00031
00032
00033 if (slot == -1)
00034 {
00035 std::ostringstream errorStringStream;
00036 errorStringStream << cycleId;
00037 throw FesaException(__FILE__, __LINE__, FesaErrorVAcceleratorSlotValueNotCorrect.c_str(), errorStringStream.str().c_str());
00038 }
00039
00040 return slot;
00041 }
00042
00043 int32_t RollingMultiplexingManager::getLastSlot(int32_t cycleId)
00044 {
00045
00046 int32_t slot = dataManager_->findCycleIdBackward(cycleId);
00047
00048
00049 if (slot == -1)
00050 {
00051 std::ostringstream errorStringStream;
00052 errorStringStream << cycleId;
00053 throw FesaException(__FILE__, __LINE__, FesaErrorVAcceleratorSlotValueNotCorrect.c_str(), errorStringStream.str().c_str());
00054 }
00055
00056 return slot;
00057 }
00058
00059
00060 int32_t RollingMultiplexingManager::getSlot(MultiplexingContext& context)
00061 {
00062 int32_t slot = -1;
00063
00064 if (context.getCycleStamp() != 0)
00065 {
00066 slot = dataManager_->findCycleStampBackward(context.getCycleStamp());
00067 }
00068
00069 if (slot == -1)
00070 {
00071 int32_t cycleId = timingDescriptor_->getCycleSelectorId(context.getCycleName());
00072 slot = dataManager_->findCycleIdBackward(cycleId);
00073 if (slot != -1)
00074 {
00075 context.setCycleStamp(dataManager_->getCycleStamp(slot));
00076 }
00077 }
00078
00079
00080 if (slot == -1)
00081 {
00082
00083 throw FesaException(__FILE__, __LINE__, FesaErrorVAcceleratorSlotValueNotCorrect.c_str(),
00084 context.getCycleName().c_str());
00085 }
00086
00087 return slot;
00088 }
00089
00090 int32_t RollingMultiplexingManager::requireSlot(const std::string& cycleName)
00091 {
00092 throw FesaException(__FILE__, __LINE__, FesaErrorRollingManagerRequiresCycleStamp.c_str());
00093 return -1;
00094
00095 }
00096
00097
00098 int32_t RollingMultiplexingManager::requireSlot(int32_t cycleId)
00099 {
00100 throw FesaException(__FILE__, __LINE__, FesaErrorRollingManagerRequiresCycleStamp.c_str());
00101 return -1;
00102
00103 }
00104
00105 int32_t RollingMultiplexingManager::requireSlot(MultiplexingContext& context)
00106 {
00107 if (context.getCycleStamp() == 0)
00108 {
00109 throw FesaException(__FILE__, __LINE__, FesaErrorWrongContext.c_str());
00110 }
00111 int32_t slot = dataManager_->findCycleStampBackward(context.getCycleStamp());
00112
00113 if (slot == -1)
00114 {
00115 int32_t cycleId = timingDescriptor_->getCycleSelectorId(context.getCycleName());
00116 slot = dataManager_->nextPosition(context.getCycleStamp(), cycleId);
00117 }
00118
00119 return slot;
00120 }
00121
00122 }