EventsMappingLoader.cpp

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #include <fesa-core/RealTime/EventsMappingLoader.h>
00004 #include <fesa-core/Utilities/ParserElements/LogicalEventElement.h>
00005 #include <fesa-core/Utilities/ParserElements/EventConfigurationElement.h>
00006 #include <fesa-core/Utilities/ParserElements/ParserElementFactory.h>
00007 #include <fesa-core/Utilities/XMLParser.h>
00008 #include <fesa-core/RealTime/AbstractRTDeviceClass.h>
00009 
00010 namespace fesa
00011 {
00012 
00013 EventsMappingLoader::EventsMappingLoader(boost::shared_ptr<ClassElement> classElement,XMLParser* parser):classElement_(classElement)
00014 {
00015         loadEventsMapping(parser);
00016 }
00017 
00018 EventsMappingLoader::~EventsMappingLoader()
00019 {
00020 
00021 }
00022 
00023 std::vector< EventElementPointer > EventsMappingLoader::getEventElementCol(const std::string& logicalEventName) const
00024 {
00025         return classElement_->getActiveEvents(logicalEventName);
00026 }
00027 
00028 EventMap EventsMappingLoader::getEventMap() const
00029 {
00030         return classElement_->getActiveEventMap();
00031 }
00032 
00033 void EventsMappingLoader::loadEventsMapping(XMLParser* parser)
00034 {
00035         std::string xpath = CLASS_BASE_PATH + classElement_->getClassName();
00036         ElementXML* xmlElementClass;
00037         std::vector<ElementXML*>* xmlElements = parser->extractElementsFromXPath(xpath);
00038         if (xmlElements == NULL)
00039         {
00040                 throw FesaException(__FILE__, __LINE__, FesaErrorXMLElementNotFound.c_str(),xpath.c_str());
00041         }
00042         if((*xmlElements).empty())
00043         {
00044                 delete xmlElements;
00045                 throw FesaException(__FILE__, __LINE__, FesaErrorXMLElementNotFound.c_str(),xpath.c_str());
00046         }
00047         xmlElementClass = (*xmlElements)[0];
00048 
00049         try
00050         {
00051                 //TODO this is still very ugly ... Diagnostic implementation has to be done in another way
00052                 (static_cast<AbstractRTDeviceClass*>(classElement_->getClassRef()))->addDiagnosticEvents(xmlElementClass);
00053                 ParserElementFactory factory;
00054                 classElement_->initialize(xpath,xmlElementClass,factory);
00055         }
00056         catch(...)
00057         {
00058                 deleteXMLElements(xmlElements);
00059                 throw;
00060         }
00061 
00062         deleteXMLElements(xmlElements);
00063 }
00064 
00065 void EventsMappingLoader::deleteXMLElements(std::vector<ElementXML*>* xmlElements) const
00066 {
00067         //Still necessary, since our XML parser is crap & does not return a shared pointer :X
00068         std::vector<ElementXML*>::iterator iter;
00069         for (iter=xmlElements->begin();iter!=xmlElements->end();++iter)
00070         {
00071                 delete *iter;
00072         }
00073         delete xmlElements;
00074 }
00075 
00076 }

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1