denso_task.cpp
Go to the documentation of this file.
00001 
00025 #include "denso_robot_core/denso_task.h"
00026 
00027 namespace denso_robot_core {
00028 
00029 DensoTask::DensoTask(DensoBase* parent,
00030     Service_Vec& service, Handle_Vec& handle,
00031     const std::string& name, const int* mode)
00032   : DensoBase(parent, service, handle, name, mode)
00033 {
00034 
00035 }
00036 
00037 DensoTask::~DensoTask()
00038 {
00039 
00040 }
00041 
00042 HRESULT DensoTask::InitializeBCAP(XMLElement *xmlElem)
00043 {
00044   return AddVariable(xmlElem);
00045 }
00046 
00047 HRESULT DensoTask::StartService(ros::NodeHandle& node)
00048 {
00049   DensoVariable_Vec::iterator itVar;
00050   for(itVar  = m_vecVar.begin();
00051       itVar != m_vecVar.end();
00052       itVar++)
00053   {
00054     (*itVar)->StartService(node);
00055   }
00056 
00057   m_serving = true;
00058 
00059   return S_OK;
00060 }
00061 
00062 HRESULT DensoTask::StopService()
00063 {
00064   m_mtxSrv.lock();
00065   m_serving = false;
00066   m_mtxSrv.unlock();
00067 
00068   DensoVariable_Vec::iterator itVar;
00069   for(itVar  = m_vecVar.begin();
00070       itVar != m_vecVar.end();
00071       itVar++)
00072   {
00073     (*itVar)->StopService();
00074   }
00075 
00076   return S_OK;
00077 }
00078 
00079 bool DensoTask::Update()
00080 {
00081   boost::mutex::scoped_lock lockSrv(m_mtxSrv);
00082   if(!m_serving) return false;
00083 
00084   DensoVariable_Vec::iterator itVar;
00085   for(itVar  = m_vecVar.begin();
00086       itVar != m_vecVar.end();
00087       itVar++)
00088   {
00089     (*itVar)->Update();
00090   }
00091 
00092   return true;
00093 }
00094 
00095 HRESULT DensoTask::get_Variable(const std::string& name, DensoVariable_Ptr* var)
00096 {
00097   if(var == NULL) {
00098     return E_INVALIDARG;
00099   }
00100 
00101   DensoBase_Vec vecBase;
00102   vecBase.insert(vecBase.end(), m_vecVar.begin(), m_vecVar.end());
00103 
00104   DensoBase_Ptr pBase;
00105   HRESULT hr = DensoBase::get_Object(vecBase, name, &pBase);
00106   if(SUCCEEDED(hr)) {
00107     *var = boost::dynamic_pointer_cast<DensoVariable>(pBase);
00108   }
00109 
00110   return hr;
00111 }
00112 
00113 HRESULT DensoTask::AddVariable(const std::string& name)
00114 {
00115   return DensoBase::AddVariable(ID_TASK_GETVARIABLE,
00116       name, m_vecVar);
00117 }
00118 
00119 HRESULT DensoTask::AddVariable(XMLElement *xmlElem)
00120 {
00121   HRESULT hr = S_OK;
00122   XMLElement *xmlVar;
00123 
00124   for(xmlVar = xmlElem->FirstChildElement(XML_VARIABLE_NAME);
00125       xmlVar!= NULL;
00126       xmlVar = xmlVar->NextSiblingElement(XML_VARIABLE_NAME))
00127   {
00128     hr = DensoBase::AddVariable(ID_TASK_GETVARIABLE,
00129         xmlVar, m_vecVar);
00130     if(FAILED(hr)) break;
00131   }
00132 
00133   return hr;
00134 }
00135 
00136 }


denso_robot_core
Author(s): DENSO WAVE INCORPORATED
autogenerated on Thu Jun 6 2019 21:00:11