MultiplexingContext.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/Synchronization/MultiplexingContext.h>
00004 
00005 #include <fesa-core/Synchronization/CycleDescriptor.h>
00006 #include <fesa-core/Synchronization/SynchronizationLabObjectFactory.h>
00007 #include <fesa-core/Core/MessageTypes.h>
00008 #include <fesa-core/Core/AbstractEquipment.h>
00009 #include <fesa-core/Diagnostic/FesaStream.h>
00010 #include <fesa-core/Exception/FesaException.h>
00011 
00012 
00013 namespace fesa
00014 {
00015 
00016 MultiplexingContext::MultiplexingContext() :
00017     cycleName_(""), extraCondition_(""), cycleId_(-1), cycleStamp_(0), type_(NoneCtxt),
00018     forewarning_(false), timingDomainId_(-1), timingDomainName_(""),  settingAccessMask_(0),  acquisitionAccessMask_(0)
00019 {
00020     // accessing from specific init, even from the server should be allowed
00021     AbstractEquipment* pEquipment = AbstractEquipment::getInstance();
00022     if(!pEquipment->isInitialized())
00023     {
00024         setSettingAccess(SET_ALLOWED);
00025     }
00026     setAcquisitionAccess(SET_ALLOWED);
00027 }
00028 
00029 MultiplexingContext::MultiplexingContext(std::istream& stream)
00030 {
00031     int32_t type;
00032     std::string none = "NONE";
00033     stream >> type;
00034     type_ = (MuxContextType)type;
00035     stream >> cycleName_;
00036     if (!cycleName_.compare(none))
00037         cycleName_ = "";
00038     stream >> extraCondition_;
00039     if (!extraCondition_.compare(none))
00040         extraCondition_ = "";
00041     stream >> timingDomainName_;
00042     if (!timingDomainName_.compare(none))
00043         timingDomainName_ = "";
00044     stream >> cycleId_;
00045     stream >> timingDomainId_;
00046     stream >> cycleStamp_;
00047     stream >> forewarning_;
00048     uint32_t mask; // Using 32-bit variable to force ASCII decoding
00049     stream >> mask;
00050     settingAccessMask_ = static_cast<uint8_t>(mask);
00051     stream >> mask;
00052     acquisitionAccessMask_ = static_cast<uint8_t>(mask);
00053 }
00054 
00055 MultiplexingContext::~MultiplexingContext()
00056 {
00057 
00058 }
00059 
00060 void MultiplexingContext::serialize(std::ostream& stream)
00061 {
00062 
00063     stream << type_ << NUMBER_SEPARATOR;
00064     std::string none = "NONE";
00065 
00066     if (cycleName_.empty())
00067     {
00068         stream << none << STRING_SEPARATOR;
00069     }
00070     else
00071     {
00072         stream << cycleName_ << STRING_SEPARATOR;
00073     }
00074 
00075     if (extraCondition_.empty())
00076     {
00077         stream << none << STRING_SEPARATOR;
00078     }
00079     else
00080     {
00081         stream << extraCondition_ << STRING_SEPARATOR;
00082     }
00083 
00084     if (timingDomainName_.empty())
00085     {
00086         stream << none << STRING_SEPARATOR;
00087     }
00088     else
00089     {
00090         stream << timingDomainName_ << STRING_SEPARATOR;
00091     }
00092 
00093     stream << cycleId_;
00094     stream << NUMBER_SEPARATOR;
00095     stream << timingDomainId_;
00096     stream << NUMBER_SEPARATOR;
00097     stream << cycleStamp_;
00098     stream << NUMBER_SEPARATOR;
00099     stream << forewarning_;
00100     stream << NUMBER_SEPARATOR;
00101     stream << static_cast<uint32_t>(settingAccessMask_); // Using 32-bit cast to force ASCII encoding
00102     stream << NUMBER_SEPARATOR;
00103     stream << static_cast<uint32_t>(acquisitionAccessMask_); // Using 32-bit cast to force ASCII encoding
00104     stream << NUMBER_SEPARATOR;
00105 }
00106 
00107 void MultiplexingContext::setExtraCondition(const std::string& extraCondition)
00108 {
00109 
00110     CycleSelector selector;
00111 
00112     fesa::parseCycleSelector(extraCondition, selector);
00113 
00114     SynchronizationLabObjectFactory* syncFactory = SynchronizationLabObjectFactory::getInstance();
00115     CycleDescriptor::CycleDescriptor* td = syncFactory->getCycleDescriptor(selector.domain_,selector.criterion_);
00116 
00117     if (td->isValidCycleSelector(extraCondition))
00118     {
00119         extraCondition_ = extraCondition;
00120     }
00121     else
00122     {
00123         throw FesaException(__FILE__, __LINE__, FesaErrorNotValidExtraCondition.c_str(), extraCondition.c_str());
00124 
00125     }
00126 }
00127 
00128 uint8_t MultiplexingContext::getSettingAccessMask()
00129 {
00130     return settingAccessMask_;
00131 }
00132 
00133 void MultiplexingContext::setSettingAccess(uint8_t accessMask)
00134 {
00135     settingAccessMask_ =  accessMask;
00136 }
00137 
00138 uint8_t MultiplexingContext::getAcquisitionAccessMask()
00139 {
00140     return acquisitionAccessMask_;
00141 }
00142 
00143 void MultiplexingContext::setAcquisitionAccess(unsigned char accessMask)
00144 {
00145     acquisitionAccessMask_ =  accessMask;
00146 }
00147 
00148 } // fesa

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1