AbstractRTDeviceClass.cpp
Go to the documentation of this file.00001
00002
00003 #include <fesa-core/RealTime/AbstractRTDeviceClass.h>
00004 #include <fesa-core/RealTime/AbstractRTEquipment.h>
00005 #include <fesa-core/DataStore/FieldSynchroManager.h>
00006 #include <fesa-core/DataStore/AbstractDevice.h>
00007 #include <fesa-core/DataStore/GlobalDevice.h>
00008 #include <fesa-core/DataStore/AbstractDeviceFactory.h>
00009 #include <fesa-core/Synchronization/NoneContext.h>
00010 #include <fesa-core/Core/AbstractDeviceClass.h>
00011
00012 namespace fesa
00013 {
00014 AbstractRTDeviceClass::AbstractRTDeviceClass(const std::string& name, const std::string& version) :
00015 AbstractDeviceClass(name, version)
00016 {
00017
00018
00019 AbstractRTEquipment::getInstance()->registerDeviceClass(this);
00020 }
00021
00022 AbstractRTDeviceClass::AbstractRTDeviceClass() :
00023 AbstractDeviceClass("", "")
00024 {
00025
00026
00027 }
00028
00029 AbstractRTDeviceClass::~AbstractRTDeviceClass()
00030 {
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 try
00044 {
00045 AbstractRTEquipment::getInstance()->deregisterDeviceClass(name_);
00046 }
00047
00048 catch (FesaException ex)
00049 {
00050
00051 }
00052 }
00053
00054 void AbstractRTDeviceClass::initialize()
00055 {
00056
00057 specificInit();
00058
00059
00060 FieldSynchroManager* pFieldSynchroManager = FieldSynchroManager::getInstance();
00061 pFieldSynchroManager->commitModifiedFieldSynchronization();
00062
00063 AbstractDeviceFactory* pAbstractDeviceFactory = getDeviceFactory();
00064 const std::vector<AbstractDevice*>& abstractDevCol = pAbstractDeviceFactory->getAbstractDeviceCollection();
00065 for (uint32_t i = 0; i < abstractDevCol.size(); ++i)
00066 {
00067 abstractDevCol[i]->synchronizeSettingFields();
00068 }
00069
00070 GlobalDevice* pGlobalDevice = pAbstractDeviceFactory->getGlobalDevice();
00071 if (pGlobalDevice != NULL)
00072 {
00073 pGlobalDevice->synchronizeSettingFields();
00074 }
00075 }
00076
00077 void AbstractRTDeviceClass::addDiagnosticSchedulingUnitInfo(std::vector<RTSchedulingUnitInfo*>& schedulingUnitInfo)
00078 {
00079
00080
00082 RTSchedulingUnitInfo* temp = new RTSchedulingUnitInfo();
00083
00084 temp->name_ = DIAGNOSTIC_LAYER;
00085 temp->actionName_ = "RTDiagnosticSetting";
00086 temp->className_ = name_;
00087 temp->selectionCriterion_ = "";
00088 temp->eventName_ = "diagnosticEvent";
00089 temp->eventField_ = "diagnosticEvent";
00090
00091 schedulingUnitInfo.push_back(temp);
00092 }
00093
00094 void AbstractRTDeviceClass::addDiagnosticRTActionInfo(RTActionInfoCol& actionInfoCol)
00095 {
00096
00097
00098 RTActionInfo* actionInfo = new RTActionInfo();
00099 actionInfo->className_ = name_;
00100 std::string s = "RTDiagnosticSetting";
00101 actionInfoCol.insert(std::make_pair(s, actionInfo));
00102 }
00103
00104 void AbstractRTDeviceClass::addDiagnosticEvents(ElementXML* xmlElementClass)
00105 {
00106
00107
00108
00109 ElementXML* eventsMapping = getOrCreateXMLElement(xmlElementClass,"events-mapping");
00110 ElementXML* logicalEvent = getOrCreateXMLElement(eventsMapping,"diagnosticEvent");
00111 ElementXML* eventConfiguration = getOrCreateXMLElement(logicalEvent,"event-configuration");
00112 addXMLAttribute(eventConfiguration,"name","diag-event-configuration");
00113 ElementXML* eventSource = getOrCreateXMLElement(eventConfiguration,"OnDemand");
00114 ElementXML* event = getOrCreateXMLElement(eventSource,"on-demand-event-source-ref");
00115 addXMLAttribute(event,"name",DIAG_EVENT_SOURCE_NAME);
00116
00117
00118 ElementXML* globalInstance = getOrCreateXMLElement(xmlElementClass,"global-instance");
00119 ElementXML* globalInstanceEventsMapping = getOrCreateXMLElement(globalInstance,"events-mapping");
00120 ElementXML* globalInstanceDiagEvent = getOrCreateXMLElement(globalInstanceEventsMapping,"diagnosticEvent");
00121 ElementXML* globalInstanceDiagEventConfigRef = getOrCreateXMLElement(globalInstanceDiagEvent,"event-configuration-ref");
00122 addXMLAttribute(globalInstanceDiagEventConfigRef,"name","diag-event-configuration");
00123 }
00124
00125 ElementXML* AbstractRTDeviceClass::getOrCreateXMLElement(ElementXML* baseElement,std::string name)
00126 {
00127 std::vector<ElementXML*>::iterator iter;
00128 for (iter=baseElement->childList_.begin();iter!=baseElement->childList_.end();iter++)
00129 {
00130 if((*iter)->name_ == name)
00131 {
00132 return *iter;
00133 }
00134 }
00135
00136
00137 ElementXML* element = new ElementXML;
00138 element->name_ = name;
00139 baseElement->childList_.push_back(element);
00140 return element;
00141 }
00142
00143 void AbstractRTDeviceClass::addXMLAttribute(ElementXML* baseElement,std::string name,std::string value)
00144 {
00145 AttributeXML* attr = new AttributeXML;
00146 attr->name_ = name;
00147 attr->value_ = value;
00148 baseElement->attributeList_.push_back(attr);
00149 }
00150 }