ComponentObserverConsumer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 ##
00005 # @file ComponentObserverConsumer.py
00006 # @brief Component observer SDO service consumer implementation
00007 # @date $Date$
00008 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara
00009 #
00010 # Copyright (C) 2011
00011 #     Noriaki Ando
00012 #     Intelligent Systems Research Institute,
00013 #     National Institute of
00014 #         Advanced Industrial Science and Technology (AIST), Japan
00015 #     All rights reserved.
00016 #
00017 
00018 import sys
00019 sys.path.insert(1,".")
00020 
00021 import RTC
00022 import OpenRTM
00023 import OpenRTM_aist
00024 
00025 ##
00026 # @if jp
00027 # @else
00028 # @endif
00029 #
00030 class ComponentObserverConsumer(OpenRTM_aist.SdoServiceConsumerBase):
00031   """
00032   """
00033 
00034   ##
00035   # @if jp
00036   # @brief ctor of ComponentObserverConsumer
00037   # @else
00038   # @brief ctor of ComponentObserverConsumer
00039   # @endif
00040   #
00041   def __init__(self):
00042     self._rtobj = None
00043     self._profile = None
00044     self._observer = OpenRTM_aist.CorbaConsumer(interfaceType=OpenRTM.ComponentObserver)
00045     self._observed = [ False for i in range(OpenRTM.STATUS_KIND_NUM._v)]
00046 
00047     self._compstat = self.CompStatMsg(self)
00048     self._portaction = self.PortAction(self)
00049     self._ecaction = self.ECAction(self)
00050     self._configMsg = self.ConfigAction(self)
00051 
00052     self._interval = OpenRTM_aist.TimeValue(1, 0)
00053     self._heartbeat = False
00054     self._hblistenerid = None
00055 
00056     # このタイマーはいずれグローバルなタイマにおきかえる
00057     self._timer = OpenRTM_aist.Timer(self._interval)
00058     return
00059 
00060 
00061   ##
00062   # @if jp
00063   # @brief dtor
00064   # @else
00065   # @brief dtor
00066   # @endif
00067   #
00068   def __del__(self):
00069     self.unsetComponentProfileListeners()
00070     self.unsetComponentStatusListeners()
00071     self.unsetPortProfileListeners()
00072     self.unsetExecutionContextListeners()
00073     self.unsetConfigurationListeners()
00074     self.unsetHeartbeat()
00075     del self._timer
00076     return
00077 
00078 
00079   ##
00080   # @if jp
00081   # @brief 初期化
00082   # @else
00083   # @brief Initialization
00084   # @endif
00085   #
00086   # virtual bool init(RTObject_impl& rtobj,
00087   #                   const SDOPackage::ServiceProfile& profile);
00088   def init(self, rtobj, profile):
00089     if not self._observer.setObject(profile.service):
00090       # narrowing failed
00091       return False
00092 
00093     self._rtobj = rtobj
00094     self._profile = profile
00095     prop = OpenRTM_aist.Properties()
00096     OpenRTM_aist.NVUtil.copyToProperties(prop, profile.properties)
00097     self.setHeartbeat(prop)
00098     self.setListeners(prop)
00099     return True
00100 
00101 
00102   ##
00103   # @if jp
00104   # @brief 再初期化
00105   # @else
00106   # @brief Re-initialization
00107   # @endif
00108   #
00109   # virtual bool reinit(const SDOPackage::ServiceProfile& profile);
00110   def reinit(self, profile):
00111     if not self._observer._ptr()._is_equivalent(profile.service):
00112       tmp = OpenRTM_aist.CorbaConsumer(interfaceType=OpenRTM.ComponentObserver)
00113       if not tmp.setObject(profile.service):
00114         return False
00115       self._observer.releaseObject()
00116       self._observer.setObject(profile.service)
00117 
00118     self._profile= profile
00119     prop = OpenRTM_aist.Properties()
00120     OpenRTM_aist.NVUtil.copyToProperties(prop, profile.properties)
00121     self.setHeartbeat(prop)
00122     self.setListeners(prop)
00123     return True
00124 
00125 
00126   ##
00127   # @if jp
00128   # @brief ServiceProfile を取得する
00129   # @else
00130   # @brief getting ServiceProfile
00131   # @endif
00132   #
00133   # virtual const SDOPackage::ServiceProfile& getProfile() const;
00134   def getProfile(self):
00135     return self._profile
00136 
00137     
00138   ##
00139   # @if jp
00140   # @brief 終了処理
00141   # @else
00142   # @brief Finalization
00143   # @endif
00144   #
00145   # virtual void finalize();
00146   def finalize(self):
00147     self.unsetComponentProfileListeners()
00148     self.unsetComponentStatusListeners()
00149     self.unsetPortProfileListeners()
00150     self.unsetExecutionContextListeners()
00151     self.unsetConfigurationListeners()
00152     self.unsetHeartbeat()
00153     return
00154 
00155 
00156   ##
00157   # @if jp
00158   # @brief リモートオブジェクトコール
00159   # @else
00160   # @brief Calling remote object
00161   # @endif
00162   #
00163   # inline void updateStatus(OpenRTM::StatusKind statuskind, const char* msg)
00164   def updateStatus(self, statuskind, msg):
00165     try:
00166       self._observer._ptr().update_status(statuskind, msg)
00167     except:
00168       self._rtobj.removeSdoServiceConsumer(self._profile.id)
00169     return
00170 
00171   ##
00172   # @if jp
00173   # @brief Kindを文字列へ変換する
00174   # @else
00175   # @brief Converting kind to string
00176   # @endif
00177   #
00178   # inline const char* toString(OpenRTM::StatusKind kind)
00179   def toString(self, kind):
00180     kinds = ["COMPONENT_PROFILE",
00181              "RTC_STATUS",
00182              "EC_STATUS",
00183              "PORT_PROFILE",
00184              "CONFIGURATION",
00185              "HEARTBEAT"]
00186     if kind._v < OpenRTM.STATUS_KIND_NUM._v:
00187       return kinds[kind._v]
00188     return ""
00189 
00190 
00191   ##
00192   # @if jp
00193   # @brief RTObjectへのリスナ接続処理
00194   # @else
00195   # @brief Connectiong listeners to RTObject
00196   # @endif
00197   #
00198   # void setListeners(coil::Properties& prop);
00199   def setListeners(self, prop):
00200     if not prop.getProperty("observed_status"):
00201       prop.setProperty("observed_status", "ALL")
00202 
00203     observed_ = [s.strip() for s in prop.getProperty("observed_status").split(",")]
00204     flags_ = [ False for i in range(OpenRTM.STATUS_KIND_NUM._v) ]
00205 
00206     for i in range(len(observed_)):
00207       observed_[i] = observed_[i].upper()
00208       if observed_[i] == "COMPONENT_PROFILE":
00209         flags_[OpenRTM.COMPONENT_PROFILE._v] = True
00210       elif observed_[i] == "RTC_STATUS":
00211         flags_[OpenRTM.RTC_STATUS._v] = True
00212       elif observed_[i] == "EC_STATUS":
00213         flags_[OpenRTM.EC_STATUS._v] = True
00214       elif observed_[i] == "PORT_PROFILE":
00215         flags_[OpenRTM.PORT_PROFILE._v] = True
00216       elif observed_[i] == "CONFIGURATION":
00217         flags_[OpenRTM.CONFIGURATION._v] = True
00218       elif observed_[i] == "ALL":
00219         for j in range(OpenRTM.STATUS_KIND_NUM._v):
00220           flags_[j] = True
00221         break
00222   
00223     self.switchListeners(flags_[OpenRTM.COMPONENT_PROFILE._v],
00224                          self._observed,
00225                          OpenRTM.COMPONENT_PROFILE._v,
00226                          self.setComponentProfileListeners,
00227                          self.unsetComponentProfileListeners)
00228 
00229     self.switchListeners(flags_[OpenRTM.RTC_STATUS._v],
00230                          self._observed,
00231                          OpenRTM.RTC_STATUS._v,
00232                          self.setComponentStatusListeners,
00233                          self.unsetComponentStatusListeners)
00234 
00235     self.switchListeners(flags_[OpenRTM.EC_STATUS._v],
00236                          self._observed,
00237                          OpenRTM.EC_STATUS._v,
00238                          self.setExecutionContextListeners,
00239                          self.unsetExecutionContextListeners)
00240 
00241     self.switchListeners(flags_[OpenRTM.PORT_PROFILE._v],
00242                          self._observed,
00243                          OpenRTM.PORT_PROFILE._v,
00244                          self.setPortProfileListeners,
00245                          self.unsetPortProfileListeners)
00246 
00247     self.switchListeners(flags_[OpenRTM.CONFIGURATION._v],
00248                          self._observed,
00249                          OpenRTM.CONFIGURATION._v,
00250                          self.setConfigurationListeners,
00251                          self.unsetConfigurationListeners)
00252 
00253     return
00254 
00255 
00256   ##
00257   # @if jp
00258   # @brief リスナ接続・切断スイッチング処理
00259   # @else
00260   # @brief Switching listeners connecting/disconnecting
00261   # @endif
00262   #
00263   # void switchListeners(bool& next, bool& pre,
00264   #                      void (ComponentObserverConsumer::*setfunc)(), 
00265   #                      void (ComponentObserverConsumer::*unsetfunc)());
00266   def switchListeners(self, next, pre, pre_idx, setfunc, unsetfunc):
00267     if (not pre[pre_idx]) and next:
00268       setfunc()
00269       pre[pre_idx] = True
00270     elif pre[pre_idx] and (not next):
00271       unsetfunc()
00272       pre[pre_idx] = False
00273 
00274     return
00275 
00276 
00277   #============================================================
00278   # Heartbeat related functions
00279 
00280   ##
00281   # @if jp
00282   # @brief ハートビートをオブザーバに伝える
00283   # @else
00284   # @brief Sending a heartbeart signal to observer
00285   # @endif
00286   #
00287   # void heartbeat();
00288   def heartbeat(self):
00289     self.updateStatus(OpenRTM.HEARTBEAT, "")
00290     return
00291 
00292 
00293   ##
00294   # @if jp
00295   # @brief ハートビートを設定する
00296   # @else
00297   # @brief Setting heartbeat
00298   # @endif
00299   #
00300   # void setHeartbeat(coil::Properties& prop);
00301   def setHeartbeat(self, prop):
00302     if OpenRTM_aist.toBool(prop.getProperty("heartbeat.enable"), "YES", "NO", False):
00303       interval_ = prop.getProperty("heartbeat.interval")
00304       if not interval_:
00305         self._interval.set_time(1.0)
00306       else:
00307         tmp_ = float(interval_)
00308         self._interval.set_time(tmp_)
00309 
00310       tm_ = self._interval
00311       self._hblistenerid = self._timer.registerListenerObj(self,
00312                                                            ComponentObserverConsumer.heartbeat,
00313                                                            tm_)
00314       if not self._heartbeat:
00315         self._timer.start()
00316         self._heartbeat = True
00317 
00318     else:
00319       if self._heartbeat and self._hblistenerid:
00320         self.unsetHeartbeat()
00321 
00322     return
00323 
00324 
00325   ##
00326   # @if jp
00327   # @brief ハートビートを解除する
00328   # @else
00329   # @brief Unsetting heartbeat
00330   # @endif
00331   #
00332   # void unsetHeartbeat();
00333   def unsetHeartbeat(self):
00334     self._timer.unregisterListener(self._hblistenerid)
00335     self._hblistenerid = 0
00336     self._timer.stop()
00337     self._heartbeat = False
00338     return
00339 
00340 
00341   #============================================================
00342   # Component status related functions
00343   
00344   ##
00345   # @if jp
00346   # @brief RTC状態変化リスナの設定処理
00347   # @else
00348   # @brief Setting RTC status listeners
00349   # @endif
00350   #
00351   # void setComponentStatusListeners();
00352   def setComponentStatusListeners(self):
00353     postclistener_ = OpenRTM_aist.PostComponentActionListenerType
00354     if not self._compstat.activatedListener:
00355       self._compstat.activatedListener = \
00356           self._rtobj.addPostComponentActionListener(postclistener_.POST_ON_ACTIVATED,
00357                                                      self._compstat.onActivated)
00358     if not self._compstat.deactivatedListener:
00359       self._compstat.deactivatedListener = \
00360           self._rtobj.addPostComponentActionListener(postclistener_.POST_ON_DEACTIVATED,
00361                                                      self._compstat.onDeactivated)
00362 
00363     if not self._compstat.resetListener:
00364       self._compstat.resetListener = \
00365           self._rtobj.addPostComponentActionListener(postclistener_.POST_ON_RESET,
00366                                                      self._compstat.onReset)
00367 
00368     if not self._compstat.abortingListener:
00369       self._compstat.abortingListener = \
00370           self._rtobj.addPostComponentActionListener(postclistener_.POST_ON_ABORTING,
00371                                                      self._compstat.onAborting)
00372 
00373     if not self._compstat.finalizeListener:
00374       self._compstat.finalizeListener = \
00375           self._rtobj.addPostComponentActionListener(postclistener_.POST_ON_FINALIZE,
00376                                                      self._compstat.onFinalize)
00377 
00378     return
00379 
00380   
00381   ##
00382   # @if jp
00383   # @brief RTC状態変化リスナの解除処理
00384   # @else
00385   # @brief Unsetting RTC status listeners
00386   # @endif
00387   #
00388   # void unsetComponentStatusListeners();
00389   def unsetComponentStatusListeners(self):
00390     postclistener_ = OpenRTM_aist.PostComponentActionListenerType
00391     if self._compstat.activatedListener:
00392       self._rtobj.removePostComponentActionListener(postclistener_.POST_ON_ACTIVATED,
00393                                                     self._compstat.activatedListener)
00394       self._compstat.activatedListener = None
00395 
00396     if self._compstat.deactivatedListener:
00397       self._rtobj.removePostComponentActionListener(postclistener_.POST_ON_DEACTIVATED,
00398                                                     self._compstat.deactivatedListener)
00399       self._compstat.deactivatedListener = None
00400 
00401     if self._compstat.resetListener:
00402       self._rtobj.removePostComponentActionListener(postclistener_.POST_ON_RESET,
00403                                                     self._compstat.resetListener)
00404       self._compstat.resetListener = None
00405 
00406     if self._compstat.abortingListener:
00407       self._rtobj.removePostComponentActionListener(postclistener_.POST_ON_ABORTING,
00408                                                     self._compstat.abortingListener)
00409       self._compstat.abortingListener = None
00410 
00411     if self._compstat.finalizeListener:
00412       self._rtobj.removePostComponentActionListener(postclistener_.POST_ON_FINALIZE,
00413                                                     self._compstat.finalizeListener)
00414       self._compstat.finalizeListener = None
00415 
00416     return
00417 
00418 
00419   #============================================================
00420   # Port profile related functions
00421 
00422   ##
00423   # @if jp
00424   # @brief Portプロファイル変化リスナの設定処理
00425   # @else
00426   # @brief Setting port profile listener
00427   # @endif
00428   #
00429   # void setPortProfileListeners();
00430   def setPortProfileListeners(self):
00431     plistener_ = OpenRTM_aist.PortActionListenerType
00432     if not self._portaction.portAddListener:
00433       self._portaction.portAddListener = \
00434           self._rtobj.addPortActionListener(plistener_.ADD_PORT,
00435                                             self._portaction.onAddPort)
00436 
00437     if not self._portaction.portRemoveListener:
00438       self._portaction.portRemoveListener = \
00439           self._rtobj.addPortActionListener(plistener_.REMOVE_PORT,
00440                                             self._portaction.onRemovePort)
00441 
00442     pclistener_ = OpenRTM_aist.PortConnectRetListenerType
00443     if not self._portaction.portConnectListener:
00444       self._portaction.portConnectListener = \
00445           self._rtobj.addPortConnectRetListener(pclistener_.ON_CONNECTED,
00446                                                 self._portaction.onConnect)
00447 
00448     if not self._portaction.portDisconnectListener:
00449       self._portaction.portDisconnectListener = \
00450           self._rtobj.addPortConnectRetListener(pclistener_.ON_DISCONNECTED,
00451                                                 self._portaction.onDisconnect)
00452 
00453     return
00454 
00455   ##
00456   # @if jp
00457   # @brief Portプロファイル変化リスナの解除処理
00458   # @else
00459   # @brief Unsetting port profile listener
00460   # @endif
00461   #
00462   # void unsetPortProfileListeners();
00463   def unsetPortProfileListeners(self):
00464     plistener_ = OpenRTM_aist.PortActionListenerType
00465     if self._portaction.portAddListener:
00466       self._rtobj.removePortActionListener(plistener_.ADD_PORT,
00467                                            self._portaction.portAddListener)
00468       self._portaction.portAddListener = None
00469 
00470     if self._portaction.portRemoveListener:
00471       self._rtobj.removePortActionListener(plistener_.REMOVE_PORT,
00472                                            self._portaction.portRemoveListener)
00473       self._portaction.portRemoveListener = None
00474 
00475     pclistener_ = OpenRTM_aist.PortConnectRetListenerType
00476     if self._portaction.portConnectListener:
00477       self._rtobj.removePortConnectRetListener(pclistener_.ON_CONNECTED,
00478                                                self._portaction.portConnectListener)
00479       self._portaction.portConnectListener = None
00480 
00481     if self._portaction.portDisconnectListener:
00482       self._rtobj.removePortConnectRetListener(pclistener_.ON_DISCONNECTED,
00483                                                self._portaction.portDisconnectListener)
00484       self._portaction.portDisconnectListener = None
00485 
00486     return
00487 
00488 
00489   #============================================================
00490   # EC profile related functions
00491    
00492   ##
00493   # @if jp
00494   # @brief ECの状態変化リスナの設定
00495   # @else
00496   # @brief Setting EC status listener
00497   # @endif
00498   #
00499   # void setExecutionContextListeners();
00500   def setExecutionContextListeners(self):
00501     ectype_ = OpenRTM_aist.ExecutionContextActionListenerType
00502     if not self._ecaction.ecAttached:
00503       self._ecaction.ecAttached = \
00504           self._rtobj.addExecutionContextActionListener(ectype_.EC_ATTACHED,
00505                                                         self._ecaction.onAttached)
00506 
00507     if not self._ecaction.ecDetached:
00508       self._ecaction.ecDetached = \
00509           self._rtobj.addExecutionContextActionListener(ectype_.EC_DETACHED,
00510                                                         self._ecaction.onDetached)
00511 
00512     pcaltype_ = OpenRTM_aist.PostComponentActionListenerType
00513     if not self._ecaction.ecRatechanged:
00514       self._ecaction.ecRatechanged = \
00515           self._rtobj.addPostComponentActionListener(pcaltype_.POST_ON_RATE_CHANGED,
00516                                                      self._ecaction.onRateChanged)
00517 
00518     if not self._ecaction.ecStartup:
00519       self._ecaction.ecStartup = \
00520           self._rtobj.addPostComponentActionListener(pcaltype_.POST_ON_STARTUP,
00521                                                      self._ecaction.onStartup)
00522 
00523     if not self._ecaction.ecShutdown:
00524       self._ecaction.ecShutdown = \
00525           self._rtobj.addPostComponentActionListener(pcaltype_.POST_ON_SHUTDOWN,
00526                                                      self._ecaction.onShutdown)
00527 
00528     return
00529 
00530 
00531   ##
00532   # @if jp
00533   # @brief ECの状態変化リスナの解除
00534   # @else
00535   # @brief Unsetting EC status listener
00536   # @endif
00537   #
00538   # void unsetExecutionContextListeners();
00539   def unsetExecutionContextListeners(self):
00540     ectype_ = OpenRTM_aist.ExecutionContextActionListenerType
00541     if self._ecaction.ecAttached:
00542       self._rtobj.removeExecutionContextActionListener(ectype_.EC_ATTACHED,
00543                                                        self._ecaction.ecAttached)
00544 
00545     if self._ecaction.ecDetached:
00546       self._rtobj.removeExecutionContextActionListener(ectype_.EC_ATTACHED,
00547                                                        self._ecaction.ecDetached)
00548 
00549     pcaltype_ = OpenRTM_aist.PostComponentActionListenerType
00550     if self._ecaction.ecRatechanged:
00551       self._rtobj.removePostComponentActionListener(pcaltype_.POST_ON_RATE_CHANGED,
00552                                                     self._ecaction.ecRatechanged)
00553 
00554     if self._ecaction.ecStartup:
00555       self._rtobj.removePostComponentActionListener(pcaltype_.POST_ON_STARTUP,
00556                                                     self._ecaction.ecStartup)
00557 
00558     if self._ecaction.ecShutdown:
00559       self._rtobj.removePostComponentActionListener(pcaltype_.POST_ON_SHUTDOWN,
00560                                                     self._ecaction.ecShutdown)
00561 
00562     return
00563 
00564 
00565   #============================================================
00566   # ComponentProfile related functions
00567 
00568   ##
00569   # @if jp
00570   # @brief ComponentProfile状態変化リスナの設定
00571   # @else
00572   # @brief Setting ComponentProfile listener
00573   # @endif
00574   #
00575   # void setComponentProfileListeners();
00576   def setComponentProfileListeners(self):
00577     pass
00578 
00579 
00580   ##
00581   # @if jp
00582   # @brief ComponentProfile状態変化リスナの解除
00583   # @else
00584   # @brief Unsetting ComponentProfile listener
00585   # @endif
00586   #
00587   # void unsetComponentProfileListeners();
00588   def unsetComponentProfileListeners(self):
00589     pass
00590 
00591 
00592   #============================================================
00593   # Configuration related functions
00594 
00595   ##
00596   # @if jp
00597   # @brief Configuration状態変化リスナの設定
00598   # @else
00599   # @brief Setting Configuration listener
00600   # @endif
00601   #
00602   # void setConfigurationListeners();
00603   def setConfigurationListeners(self):
00604     confprmlistenertype_ = OpenRTM_aist.ConfigurationParamListenerType
00605     self._configMsg.updateConfigParamListener = \
00606         self._rtobj.addConfigurationParamListener(confprmlistenertype_.ON_UPDATE_CONFIG_PARAM,
00607                                                   self._configMsg.updateConfigParam)
00608 
00609     confsetlistenertype_ = OpenRTM_aist.ConfigurationSetListenerType
00610     self._configMsg.setConfigSetListener = \
00611         self._rtobj.addConfigurationSetListener(confsetlistenertype_.ON_SET_CONFIG_SET,
00612                                                 self._configMsg.setConfigSet)
00613 
00614     self._configMsg.addConfigSetListener = \
00615         self._rtobj.addConfigurationSetListener(confsetlistenertype_.ON_ADD_CONFIG_SET,
00616                                                 self._configMsg.addConfigSet)
00617 
00618     confsetnamelistenertype_ = OpenRTM_aist.ConfigurationSetNameListenerType
00619     self._configMsg.updateConfigSetListener = \
00620         self._rtobj.addConfigurationSetNameListener(confsetnamelistenertype_.ON_UPDATE_CONFIG_SET,
00621                                                     self._configMsg.updateConfigSet)
00622 
00623     self._configMsg.removeConfigSetListener = \
00624         self._rtobj.addConfigurationSetNameListener(confsetnamelistenertype_.ON_REMOVE_CONFIG_SET,
00625                                                     self._configMsg.removeConfigSet)
00626     self._configMsg.activateConfigSetListener = \
00627         self._rtobj.addConfigurationSetNameListener(confsetnamelistenertype_.ON_ACTIVATE_CONFIG_SET,
00628                                                     self._configMsg.activateConfigSet)
00629     return
00630 
00631 
00632   ##
00633   # @if jp
00634   # @brief Configuration状態変化リスナの解除
00635   # @else
00636   # @brief Unsetting Configurationlistener
00637   # @endif
00638   #
00639   # void unsetConfigurationListeners();
00640   def unsetConfigurationListeners(self):
00641     confprmlistenertype_ = OpenRTM_aist.ConfigurationParamListenerType
00642     if self._configMsg.updateConfigParamListener:
00643       self._rtobj.removeConfigurationParamListener(confprmlistenertype_.ON_UPDATE_CONFIG_PARAM,
00644                                                    self._configMsg.updateConfigParamListener)
00645       self._configMsg.updateConfigParamListener = None
00646 
00647     confsetlistenertype_ = OpenRTM_aist.ConfigurationSetListenerType
00648     if self._configMsg.setConfigSetListener:
00649       self._rtobj.removeConfigurationSetListener(confsetlistenertype_.ON_SET_CONFIG_SET,
00650                                                  self._configMsg.setConfigSetListener)
00651       self._configMsg.setConfigSetListener = None
00652 
00653     if self._configMsg.addConfigSetListener:
00654       self._rtobj.removeConfigurationSetListener(confsetlistenertype_.ON_ADD_CONFIG_SET,
00655                                                  self._configMsg.addConfigSetListener)
00656       self._configMsg.addConfigSetListener = None
00657 
00658     confsetnamelistenertype_ = OpenRTM_aist.ConfigurationSetNameListenerType
00659     if self._configMsg.updateConfigSetListener:
00660       self._rtobj.removeConfigurationSetNameListener(confsetnamelistenertype_.ON_UPDATE_CONFIG_SET,
00661                                                      self._configMsg.updateConfigSetListener)
00662       self._configMsg.updateConfigSetListener = None
00663 
00664     if self._configMsg.removeConfigSetListener:
00665       self._rtobj.removeConfigurationSetNameListener(confsetnamelistenertype_.ON_REMOVE_CONFIG_SET,
00666                                                      self._configMsg.removeConfigSetListener)
00667       self._configMsg.removeConfigSetListener = None
00668 
00669     if self._configMsg.activateConfigSetListener:
00670       self._rtobj.removeConfigurationSetNameListener(confsetnamelistenertype_.ON_ACTIVATE_CONFIG_SET,
00671                                                      self._configMsg.activateConfigSetListener)
00672       self._configMsg.activateConfigSetListener = None
00673 
00674     return
00675 
00676 
00677   ##
00678   # @if jp
00679   # @brief PostComponentActionListener class
00680   # @else
00681   # @brief PostComponentActionListener class
00682   # @endif
00683   #
00684   class CompStatMsg:
00685     """
00686     """
00687 
00688     #CompStatMsg(ComponentObserverConsumer& coc)
00689     def __init__(self, coc):
00690       self.activatedListener = None
00691       self.deactivatedListener = None
00692       self.resetListener = None
00693       self.abortingListener = None
00694       self.finalizeListener = None
00695       self._coc = coc
00696       return
00697 
00698     def __del__(self):
00699       del self._coc
00700       return
00701 
00702     #void onGeneric(const char* msgprefix, UniqueId ec_id, ReturnCode_t ret)
00703     def onGeneric(self, msgprefix, ec_id, ret):
00704       if ret == RTC.RTC_OK:
00705         msg_ = msgprefix
00706         msg_ += str(ec_id)
00707         self._coc.updateStatus(OpenRTM.RTC_STATUS, msg_)
00708       return
00709 
00710     #void onActivated(UniqueId ec_id, ReturnCode_t ret)
00711     def onActivated(self, ec_id, ret):
00712       self.onGeneric("ACTIVE:", ec_id, ret)
00713       return
00714 
00715     #void onDeactivated(UniqueId ec_id, ReturnCode_t ret)
00716     def onDeactivated(self, ec_id, ret):
00717       self.onGeneric("INACTIVE:", ec_id, ret)
00718       return
00719 
00720     #void onReset(UniqueId ec_id, ReturnCode_t ret)
00721     def onReset(self, ec_id, ret):
00722       self.onGeneric("INACTIVE:", ec_id, ret)
00723       return
00724 
00725     #void onAborting(UniqueId ec_id, ReturnCode_t ret)
00726     def onAborting(self, ec_id, ret):
00727       self.onGeneric("ERROR:", ec_id, ret)
00728       return
00729 
00730     #void onFinalize(UniqueId ec_id, ReturnCode_t ret)
00731     def onFinalize(self, ec_id, ret):
00732       self.onGeneric("FINALIZE:", ec_id, ret)
00733       return
00734 
00735   ##
00736   # @if jp
00737   # @brief PortActionListener
00738   # @else
00739   # @brief PortActionListener
00740   # @endif
00741   #
00742   class PortAction:
00743     """
00744     """
00745 
00746     #PortAction(ComponentObserverConsumer& coc)
00747     def __init__(self, coc):
00748       self.portAddListener = None
00749       self.portRemoveListener = None
00750       self.portConnectListener = None
00751       self.portDisconnectListener = None
00752       self._coc = coc
00753       return
00754 
00755     def __del__(self):
00756       del self._coc
00757       return
00758 
00759     #void onGeneric(const char* _msg, const char* portname)
00760     def onGeneric(self, _msg, portname):
00761       msg_ = _msg
00762       msg_ += portname
00763       self._coc.updateStatus(OpenRTM.PORT_PROFILE, msg_)
00764       return
00765 
00766     #void onAddPort(const ::RTC::PortProfile& pprof)
00767     def onAddPort(self, pprof):
00768       self.onGeneric("ADD:", str(pprof.name))
00769       return
00770 
00771     #void onRemovePort(const ::RTC::PortProfile& pprof)
00772     def onRemovePort(self, pprof):
00773       self.onGeneric("REMOVE:", str(pprof.name))
00774       return
00775 
00776     #void onConnect(const char* portname,
00777     #                 ::RTC::ConnectorProfile& pprof, ReturnCode_t ret)
00778     def onConnect(self, portname, pprof, ret):
00779       if ret == RTC.RTC_OK:
00780         self.onGeneric("CONNECT:", portname)
00781       return
00782 
00783     #void onDisconnect(const char* portname,
00784     #                  ::RTC::ConnectorProfile& pprof, ReturnCode_t ret)
00785     def onDisconnect(self, portname, pprof, ret):
00786       if ret == RTC.RTC_OK:
00787         self.onGeneric("DISCONNECT:", portname)
00788       return
00789 
00790 
00791   ##
00792   # @if jp
00793   # @brief ExecutionContextActionListener
00794   # @else
00795   # @brief ExecutionContextActionListener
00796   # @endif
00797   #
00798   class ECAction:
00799     """
00800     """
00801 
00802     #ECAction(ComponentObserverConsumer& coc)
00803     def __init__(self, coc):
00804       self.ecAttached = None
00805       self.ecDetached = None
00806       self.ecRatechanged = None
00807       self.ecStartup = None
00808       self.ecShutdown = None
00809       self._coc = coc
00810       return
00811 
00812     def __del__(self):
00813       del self._coc
00814       return
00815 
00816     #void onGeneric(const char* _msg, UniqueId ec_id)
00817     def onGeneric(self, _msg, ec_id):
00818       msg_ = _msg + str(ec_id)
00819       self._coc.updateStatus(OpenRTM.EC_STATUS, msg_)
00820       return
00821 
00822     #void onAttached(UniqueId ec_id)
00823     def onAttached(self, ec_id):
00824       self.onGeneric("ATTACHED:", ec_id)
00825       return
00826 
00827     #void onDetached(UniqueId ec_id)
00828     def onDetached(self, ec_id):
00829       self.onGeneric("DETACHED:", ec_id)
00830       return
00831 
00832     #void onRateChanged(UniqueId ec_id, ReturnCode_t ret)
00833     def onRateChanged(self, ec_id, ret):
00834       if ret == RTC.RTC_OK:
00835         self.onGeneric("RATE_CHANGED:", ec_id)
00836       return
00837 
00838     #void onStartup(UniqueId ec_id, ReturnCode_t ret)
00839     def onStartup(self, ec_id, ret):
00840       if ret == RTC.RTC_OK:
00841         self.onGeneric("STARTUP:", ec_id)
00842       return
00843 
00844     #void onShutdown(UniqueId ec_id, ReturnCode_t ret)
00845     def onShutdown(self, ec_id, ret):
00846       if ret == RTC.RTC_OK:
00847         self.onGeneric("SHUTDOWN:", ec_id)
00848       return
00849 
00850 
00851   ##
00852   # @if jp
00853   # @brief ConfigActionListener
00854   # @else
00855   # @brief ConfigActionListener
00856   # @endif
00857   #
00858   class ConfigAction:
00859     """
00860     """
00861 
00862     #ConfigAction(ComponentObserverConsumer& coc)
00863     def __init__(self, coc):
00864       self.updateConfigParamListener = None
00865       self.setConfigSetListener = None
00866       self.addConfigSetListener = None
00867       self.updateConfigSetListener = None
00868       self.removeConfigSetListener = None
00869       self.activateConfigSetListener = None
00870       self._coc = coc
00871 
00872     def __del__(self):
00873       del self._coc
00874       return
00875 
00876     #void updateConfigParam(const char* configsetname,
00877     #                       const char* configparamname)
00878     def updateConfigParam(self, configsetname, configparamname):
00879       msg_ = "UPDATE_CONFIG_PARAM: "
00880       msg_ += configsetname
00881       msg_ += "."
00882       msg_ += configparamname
00883       self._coc.updateStatus(OpenRTM.CONFIGURATION, msg_)
00884       return
00885 
00886     #void setConfigSet(const coil::Properties& config_set)
00887     def setConfigSet(self, config_set):
00888       msg_ = "SET_CONFIG_SET: "
00889       msg_ += config_set.getName()
00890       self._coc.updateStatus(OpenRTM.CONFIGURATION, msg_)
00891       return
00892 
00893     #void addConfigSet(const coil::Properties& config_set)
00894     def addConfigSet(self, config_set):
00895       msg_ = "ADD_CONFIG_SET: "
00896       msg_ += config_set.getName()
00897       self._coc.updateStatus(OpenRTM.CONFIGURATION, msg_)
00898       return
00899 
00900     #void updateConfigSet(const char* config_set_name)
00901     def updateConfigSet(self, config_set_name):
00902       msg_ = "UPDATE_CONFIG_SET: "
00903       msg_ += config_set_name
00904       self._coc.updateStatus(OpenRTM.CONFIGURATION, msg_)
00905       return
00906 
00907     #void removeConfigSet(const char* config_set_name)
00908     def removeConfigSet(self, config_set_name):
00909       msg_ = "REMOVE_CONFIG_SET: "
00910       msg_ += config_set_name
00911       self._coc.updateStatus(OpenRTM.CONFIGURATION, msg_)
00912       return
00913 
00914     #void activateConfigSet(const char* config_set_name)
00915     def activateConfigSet(self, config_set_name):
00916       msg_ = "ACTIVATE_CONFIG_SET: "
00917       msg_ += config_set_name
00918       self._coc.updateStatus(OpenRTM.CONFIGURATION, msg_)
00919       return
00920 
00921 def ComponentObserverConsumerInit(mgr=None):
00922   factory = OpenRTM_aist.SdoServiceConsumerFactory.instance()
00923   factory.addFactory(OpenRTM.ComponentObserver._NP_RepositoryId,
00924                      ComponentObserverConsumer,
00925                      OpenRTM_aist.Delete)
00926   return


openrtm_aist_python
Author(s): Shinji Kurihara
autogenerated on Thu Aug 27 2015 14:17:28