AbstractServerAction.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/Server/AbstractServerAction.h>
00004 
00005 #include <fesa-core/Server/AbstractServerEquipment.h>
00006 #include <fesa-core/Server/AbstractServerDeviceClass.h>
00007 #include <fesa-core/Server/AbstractServerController.h>
00008 #include <fesa-core/DataStore/AbstractField.h>
00009 #include <fesa-core/DataStore/FaultField.h>
00010 #include <fesa-core/DataStore/AbstractDevice.h>
00011 #include <fesa-core/DataStore/AbstractDeviceFactory.h>
00012 #include <fesa-core/DataStore/GlobalDevice.h>
00013 #include <fesa-core/DataStore/FieldSynchroManager.h>
00014 #include <fesa-core/Core/NotificationProducer.h>
00015 #include <fesa-core/Core/MessageTypes.h>
00016 #include <fesa-core/Core/OnDemandProducer.h>
00017 #include <fesa-core/Diagnostic/FesaStream.h>
00018 
00019 namespace fesa
00020 {
00021 
00022 AbstractServerAction::AbstractServerAction(ServerActionConfig& actionConfig, const AbstractServiceLocator* serviceLocator, const std::map<std::string, const AbstractServiceLocator*> serviceLocatorRelatedClasses) :
00023         AbstractAction(actionConfig.name_,actionConfig.className_,serviceLocator,serviceLocatorRelatedClasses),
00024         notifiedPropertiesCol_(actionConfig.notifiedPropertiesCol_),
00025         disablingFieldNamesCol_(actionConfig.disablingFieldNamesCol_), disablingGlobalFieldNamesCol_(actionConfig.disablingGlobalFieldNamesCol_),
00026         partialSetIsAllowed_(actionConfig.partialSetIsAllowed_), needFilter_(actionConfig.needFilter_),
00027         autoNotification_(actionConfig.autoNotification_), transactionalSetIsAllowed_(actionConfig.transactionalSetIsAllowed_),
00028         defaultImpl_(actionConfig.defaultImpl_), pGlobalDevice_(0)
00029 {
00030         theNotificationProducer_ = NotificationProducer::getInstance();
00031 }
00032 
00033 AbstractServerAction::~AbstractServerAction()
00034 {
00035 
00036 }
00037 
00038 void AbstractServerAction::releaseStaticObjects()
00039 {
00040 
00041 }
00042 
00043 void AbstractServerAction::checkInvalidatingFields(AbstractDevice* device, MultiplexingContext* ctx)
00044 {
00045     for (uint32_t i = 0; i < disablingFieldNamesCol_.size(); ++i)
00046         {
00047                 AbstractField* aF(device->getField(disablingFieldNamesCol_[i].c_str()));
00048                 FaultField<FaultField_DataType>* pFF = (FaultField<FaultField_DataType>*) aF;
00049                 if (pFF->isRaised(ctx))
00050                 {
00051                         throw FesaException(__FILE__, __LINE__, FesaErrorActionDisabledByFaultField.c_str(),
00052                                                         pFF->getDescription().c_str());
00053                 }
00054         }
00055         if (pGlobalDevice_ == 0)
00056         {
00057                 AbstractServerEquipment* equipment = AbstractServerEquipment::getInstance();
00058                 pGlobalDevice_
00059                                                 = (equipment->getDeviceClassFromDeviceName(device->getName())->getDeviceFactory()->getGlobalDevice());
00060         }
00061         for (uint32_t i = 0; i < disablingGlobalFieldNamesCol_.size(); ++i)
00062         {
00063                 AbstractField* aF(pGlobalDevice_->getField(disablingGlobalFieldNamesCol_[i].c_str()));
00064                 FaultField<FaultField_DataType>* pFF = (FaultField<FaultField_DataType>*) aF;
00065                 if (pFF->isRaised(ctx))
00066                 {
00067                         throw FesaException(__FILE__, __LINE__, FesaErrorActionDisabledByFaultField.c_str(),
00068                                                         pFF->getDescription().c_str());
00069                 }
00070         }
00071         return;
00072 }
00073 
00074 void AbstractServerAction::notify(MultiplexingContext& context, AbstractDevice& device, RequestType reqType)
00075 {
00076         if (!notifiedPropertiesCol_.empty())
00077         {
00078                 AbstractServerEquipment* equipment = AbstractServerEquipment::getInstance();
00079                 AbstractServerDeviceClass* deviceclass = equipment->getDeviceClassFromDeviceName(device.getName());
00080                 std::vector<std::string>::iterator iter;
00081 
00082                 ManualNotificationMessage mnm(deviceclass->getName());
00083                 mnm.muxContext_=&context;
00084 
00085                 for (iter = notifiedPropertiesCol_.begin(); iter != notifiedPropertiesCol_.end(); ++iter)
00086                 {
00087                         mnm.addPropertyAndDevice(*iter,device.getName());
00088                 }
00089                 theNotificationProducer_->sendManualNotification(mnm);
00090         }
00091 }
00092 
00093 void AbstractServerAction::printConfig(FesaStream* configStream)
00094 {
00095         *configStream << "name=\"" << name_ << " implementation=\"" << ((defaultImpl_)? "default" : "custom") << "\">" << std::endl;
00096         //list of disabling fields
00097         *configStream << "\t\t\t\t\t\t<disabling-fields name=\"";
00098         for(std::vector<std::string>::iterator it=disablingFieldNamesCol_.begin(); it!=disablingFieldNamesCol_.end(); ++it)
00099         {
00100                 *configStream << *it << " ";
00101         }
00102         for(std::vector<std::string>::iterator it=disablingGlobalFieldNamesCol_.begin(); it!=disablingGlobalFieldNamesCol_.end(); ++it)
00103         {
00104                 *configStream << *it << " ";
00105         }
00106         *configStream << "\"" << std::endl;
00107 
00108         if (!notifiedPropertiesCol_.empty())
00109         {
00110                 //list of properties to be notified
00111                 *configStream << "\t\t\t\t\t\t<notified-properties name=\"";
00112                 for(std::vector<std::string>::iterator it=notifiedPropertiesCol_.begin(); it!=notifiedPropertiesCol_.end(); ++it)
00113                 {
00114                         *configStream << *it << " ";
00115                 }
00116                 *configStream << "\"" << std::endl;
00117         }
00118 }
00119 
00120 void AbstractServerAction::printState(FesaStream* fesaStream, double elapsedTime)
00121 {
00122 
00123 }
00124 
00125 bool AbstractServerAction::needFilter()
00126 {
00127 
00128         return needFilter_;
00129 }
00130 
00131 }

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1