PeriodicECSharedComposite.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 
00004 ##
00005 # @file PeriodicECSharedComposite.h
00006 # @brief Periodic Execution Context Shared Composite Component class
00007 # @date $Date$
00008 # @author Noriaki Ando <n-ando@aist.go.jp>
00009 #
00010 # Copyright (C) 2008
00011 #     Noriaki Ando
00012 #     Task-intelligence Research Group,
00013 #     Intelligent Systems Research Institute,
00014 #     National Institute of
00015 #         Advanced Industrial Science and Technology (AIST), Japan
00016 #     All rights reserved.
00017 #
00018 # $Id$
00019 #
00020 
00021 import string
00022 import sys
00023 import time
00024 
00025 from omniORB import CORBA
00026 import OpenRTM
00027 import RTC
00028 import OpenRTM_aist
00029 
00030 
00031 periodicecsharedcomposite_spec = ["implementation_id", "PeriodicECSharedComposite",
00032                                   "type_name",         "PeriodicECSharedComposite",
00033                                   "description",       "PeriodicECSharedComposite",
00034                                   "version",           "1.0",
00035                                   "vendor",            "jp.go.aist",
00036                                   "category",          "composite.PeriodicECShared",
00037                                   "activity_type",     "DataFlowComponent",
00038                                   "max_instance",      "0",
00039                                   "language",          "Python",
00040                                   "lang_type",         "script",
00041                                   "exported_ports",    "",
00042                                   "conf.default.members", "",
00043                                   "conf.default.exported_ports", "",
00044                                   ""]
00045                                   
00046 
00047 def stringToStrVec(v, _is):
00048   str = [_is]
00049   OpenRTM_aist.eraseBlank(str)
00050   v[0] = str[0].split(",")
00051   return True
00052 
00053 
00054 class setCallback(OpenRTM_aist.ConfigurationSetListener):
00055   def __init__(self, org):
00056     self._org = org
00057     pass
00058 
00059   def __call__(self, config_set):
00060     self._org.updateDelegatedPorts()
00061 
00062 
00063 
00064 class addCallback(OpenRTM_aist.ConfigurationSetListener):
00065   def __init__(self, org):
00066     self._org = org
00067     pass
00068 
00069   def __call__(self, config_set):
00070     self._org.updateDelegatedPorts()
00071     return
00072 
00073 
00074 ##
00075 # @if jp
00076 # @namespace SDOPacakge
00077 #
00078 # @brief SDO
00079 #
00080 # @else
00081 #
00082 # @namespace SDOPackage
00083 #
00084 # @brief SDO
00085 #
00086 # @endif
00087 #
00088 class PeriodicECOrganization(OpenRTM_aist.Organization_impl):
00089 
00090 
00091   ##
00092   # @if jp
00093   # @brief コンストラクタ
00094   #
00095   # コンストラクタ
00096   #
00097   # @param rtobj オブジェクト
00098   #
00099   # @else
00100   # @brief Constructor
00101   #
00102   # Constructor
00103   #
00104   # @param rtobj Object
00105   #
00106   # @endif
00107   #
00108   def __init__(self, rtobj):
00109     OpenRTM_aist.Organization_impl.__init__(self,rtobj.getObjRef())
00110     self._rtobj      = rtobj
00111     self._ec         = None
00112     self._rtcMembers = []
00113     self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("rtobject.PeriodicECOrganization")
00114     self._expPorts = []
00115     return
00116 
00117 
00118   ##
00119   # @if jp
00120   # 
00121   # @brief [CORBA interface] Organizationメンバーを追加する
00122   #
00123   # Organization が保持するメンバーリストに与えられたSDOListを追加する。
00124   # 
00125   # @param sdo_list 追加される SDO メンバーのリスト
00126   # @return 追加が成功したかどうかがboolで返される
00127   #
00128   # @else
00129   # 
00130   # @brief [CORBA interface] Add Organization member
00131   #
00132   # This operation adds the given SDOList to the existing organization's 
00133   # member list
00134   # 
00135   # @param sdo_list SDO member list to be added
00136   # @return boolean will returned if the operation succeed
00137   #
00138   # @endif
00139   #
00140   # Boolean add_members(const SDOList& sdo_list)
00141   def add_members(self, sdo_list):
00142     self._rtcout.RTC_DEBUG("add_members()")
00143     self.updateExportedPortsList()
00144     for sdo in sdo_list:
00145       dfc = [None]
00146       if not self.sdoToDFC(sdo, dfc):
00147         continue
00148       member = self.Member(dfc[0])
00149       self.stopOwnedEC(member)
00150       self.addOrganizationToTarget(member)
00151       self.addParticipantToEC(member)
00152       self.addPort(member, self._expPorts)
00153       self._rtcMembers.append(member)
00154 
00155     result = OpenRTM_aist.Organization_impl.add_members(self,sdo_list)
00156 
00157     return result
00158 
00159 
00160   ##
00161   # @if jp
00162   # 
00163   # @brief [CORBA interface] Organizationメンバーをセットする
00164   #
00165   # Organization が保持するメンバーリストを削除し、与えられた
00166   # SDOListを新規にセットする。
00167   # 
00168   # @param sdo_list 新規にセットされる SDO メンバーのリスト
00169   # @return 追加が成功したかどうかがboolで返される
00170   #
00171   # @else
00172   # 
00173   # @brief [CORBA interface] Set Organization member
00174   #
00175   # This operation removes existing member list and sets the given
00176   # SDOList to the existing organization's member list
00177   # 
00178   # @param sdo_list SDO member list to be set
00179   # @return boolean will returned if the operation succeed
00180   #
00181   # @endif
00182   #
00183   # Boolean set_members(const SDOList& sdo_list)
00184   def set_members(self, sdo_list):
00185     self._rtcout.RTC_DEBUG("set_members()")
00186     # self._rtcMembers = []
00187     self.removeAllMembers()
00188     self.updateExportedPortsList()
00189 
00190     for sdo in sdo_list:
00191       dfc = [None]
00192       if not self.sdoToDFC(sdo, dfc):
00193         continue
00194       
00195       member = self.Member(dfc[0])
00196       self.stopOwnedEC(member)
00197       self.addOrganizationToTarget(member)
00198       self.addParticipantToEC(member)
00199       self.addPort(member, self._expPorts)
00200       self._rtcMembers.append(member)
00201       
00202     result = OpenRTM_aist.Organization_impl.set_members(self, sdo_list)
00203 
00204     return result
00205 
00206 
00207   ##
00208   # @if jp
00209   # 
00210   # @brief [CORBA interface] Organizationメンバーを削除する
00211   #
00212   # Organization が保持するメンバーリスト内の特定のSDOを削除する。
00213   # 
00214   # @param id 削除される SDO の ID
00215   # @return 追加が成功したかどうかがboolで返される
00216   #
00217   # @else
00218   # 
00219   # @brief [CORBA interface] Remove a member of Organization
00220   #
00221   # This operation removes a SDO from existing member list by specified ID.
00222   # 
00223   # @param id The ID of the SDO to be removed
00224   # @return boolean will returned if the operation succeed
00225   #
00226   # @endif
00227   #
00228   # Boolean remove_member(const char* id)
00229   def remove_member(self, id):
00230     self._rtcout.RTC_DEBUG("remove_member(id = %s)", id)
00231     rm_rtc = []
00232     for member in self._rtcMembers:
00233       if str(id) != str(member._profile.instance_name):
00234         continue
00235       self.removePort(member, self._expPorts)
00236       self._rtobj.getProperties().setProperty("conf.default.exported_ports", OpenRTM_aist.flatten(self._expPorts))
00237       self.removeParticipantFromEC(member)
00238       self.removeOrganizationFromTarget(member)
00239       self.startOwnedEC(member)
00240       rm_rtc.append(member)
00241 
00242     for m in rm_rtc:
00243       self._rtcMembers.remove(m)
00244             
00245     result = OpenRTM_aist.Organization_impl.remove_member(self, id)
00246     return result
00247 
00248 
00249   ##
00250   # @if jp
00251   # @brief Organizationメンバーを削除する
00252   # @else
00253   # @brief Remove a member of Organization
00254   # @endif
00255   #
00256   def removeAllMembers(self):
00257     self._rtcout.RTC_DEBUG("removeAllMembers()")
00258     self.updateExportedPortsList()
00259     for member in self._rtcMembers:
00260       self.removePort(member, self._expPorts)
00261       self.removeParticipantFromEC(member)
00262       self.removeOrganizationFromTarget(member)
00263       self.startOwnedEC(member)
00264       OpenRTM_aist.Organization_impl.remove_member(self, member._profile.instance_name)
00265 
00266     self._rtcMembers = []
00267     self._expPorts   = []
00268     return
00269 
00270         
00271   ##
00272   # @if jp
00273   # @brief SDOからDFCへの変換
00274   # @else
00275   # @brief Conversion from SDO to DFC
00276   # @endif
00277   #
00278   # bool sdoToDFC(const SDO_ptr sdo, ::OpenRTM::DataFlowComponent_ptr& dfc);
00279   def sdoToDFC(self, sdo, dfc):
00280     if CORBA.is_nil(sdo):
00281       return False
00282 
00283     dfc[0] = sdo._narrow(OpenRTM.DataFlowComponent)
00284     if CORBA.is_nil(dfc[0]):
00285       return False
00286 
00287     return True
00288 
00289 
00290   ##
00291   # @if jp
00292   # @brief Owned ExecutionContext を停止させる
00293   # @else
00294   # @brief Stop Owned ExecutionContexts
00295   # @endif
00296   #
00297   # void stopOwnedEC(Member& member);
00298   def stopOwnedEC(self, member):
00299     ecs = member._eclist
00300     for ec in ecs:
00301       ret = ec.stop()
00302 
00303     return
00304 
00305 
00306   ##
00307   # @if jp
00308   # @brief Owned ExecutionContext を起動する
00309   # @else
00310   # @brief Start Owned ExecutionContexts
00311   # @endif
00312   #
00313   def startOwnedEC(self, member):
00314     ecs = member._eclist
00315     for ec in ecs:
00316       ret = ec.start()
00317 
00318     return
00319 
00320 
00321   ##
00322   # @if jp
00323   # @brief DFC に Organization オブジェクトを与える
00324   # @else
00325   # @brief Set Organization object to target DFC 
00326   # @endif
00327   #
00328   # void addOrganizationToTarget(Member& member);
00329   def addOrganizationToTarget(self, member):
00330     conf = member._config
00331     if CORBA.is_nil(conf):
00332       return
00333 
00334     conf.add_organization(self._objref)
00335     return
00336 
00337 
00338   ##
00339   # @if jp
00340   # @brief Organization オブジェクトを DFCから削除する
00341   # @else
00342   # @brief Remove Organization object from a target DFC 
00343   # @endif
00344   #
00345   # void removeOrganizationFromTarget(Member& member)
00346   def removeOrganizationFromTarget(self, member):
00347     # get given RTC's configuration object
00348     if CORBA.is_nil(member._config):
00349       return
00350     
00351     # set organization to target RTC's conf
00352     ret = member._config.remove_organization(self._pId)
00353     return
00354 
00355 
00356   ##
00357   # @if jp
00358   # @brief Composite の ExecutionContext を DFC にセットする
00359   # @else
00360   # @brief Set CompositeRTC's ExecutionContext to the given DFC
00361   # @endif
00362   #
00363   # void addParticipantToEC(Member& member)
00364   def addParticipantToEC(self, member):
00365     if CORBA.is_nil(self._ec) or self._ec is None:
00366       ecs = self._rtobj.get_owned_contexts()
00367       if len(ecs) > 0:
00368         self._ec = ecs[0]
00369       else:
00370         return
00371     # set ec to target RTC
00372     ret = self._ec.add_component(member._rtobj)
00373 
00374     orglist = member._rtobj.get_organizations()
00375     for org in orglist:
00376       sdos = org.get_members()
00377       for sdo in sdos:
00378         dfc = [None]
00379         if not self.sdoToDFC(sdo, dfc):
00380           continue
00381         self._ec.add_component(dfc[0])
00382     return
00383 
00384 
00385   ##
00386   # @if jp
00387   # @brief Composite の ExecutionContext から DFC を削除する
00388   # @else
00389   # @brief Remove participant DFC from CompositeRTC's ExecutionContext
00390   # @endif
00391   #
00392   # void PeriodicECOrganization::removeParticipantFromEC(Member& member)
00393   def removeParticipantFromEC(self, member):
00394     if CORBA.is_nil(self._ec) or self._ec is None:
00395       ecs = self._rtobj.get_owned_contexts()
00396       if len(ecs) > 0:
00397         self._ec = ecs[0]
00398       else:
00399         self._rtcout.RTC_FATAL("no owned EC")
00400         return
00401     self._ec.remove_component(member._rtobj)
00402 
00403     orglist = member._rtobj.get_organizations()
00404 
00405     for org in orglist:
00406       sdos = org.get_members()
00407       for sdo in sdos:
00408         dfc = [None]
00409         if not self.sdoToDFC(sdo, dfc):
00410           continue
00411         self._ec.remove_component(dfc[0])
00412     return
00413 
00414 
00415   ##
00416   # @if jp
00417   # @brief Composite の ExecutionContext を DFC にセットする
00418   # @else
00419   # @brief Set CompositeRTC's ExecutionContext to the given DFC
00420   # @endif
00421   #
00422   # void setCompositeECToTarget(::OpenRTM::DataFlowComponent_ptr dfc);
00423   # def setCompositeECToTarget(self, dfc):
00424   #    if CORBA.is_nil(dfc):
00425   #        return
00426   #
00427   #    if CORBA.is_nil(self._ec) or self._ec is None:
00428   #        ecs = self._rtobj.get_owned_contexts()
00429   #        if len(ecs) > 0:
00430   #            self._ec = ecs[0]
00431   #        else:
00432   #            return
00433   #
00434   #    self._ec.add_component(dfc)
00435 
00436   ##
00437   # @if jp
00438   # @brief ポートを委譲する
00439   # @else
00440   # @brief Delegate given RTC's ports to the Composite
00441   # @endif
00442   #
00443   # void addPort(Member& member, PortList& portlist);
00444   def addPort(self, member, portlist):
00445     self._rtcout.RTC_TRACE("addPort(%s)", OpenRTM_aist.flatten(portlist))
00446     if len(portlist) == 0:
00447       return
00448         
00449     comp_name = member._profile.instance_name
00450     plist = member._profile.port_profiles
00451       
00452     # port delegation
00453     for prof in plist:
00454       # port name -> comp_name.port_name
00455       port_name = prof.name
00456 
00457       self._rtcout.RTC_DEBUG("port_name: %s is in %s?", (port_name,OpenRTM_aist.flatten(portlist)))
00458       if not port_name in portlist:
00459         self._rtcout.RTC_DEBUG("Not found: %s is in %s?", (port_name,OpenRTM_aist.flatten(portlist)))
00460         continue
00461 
00462       self._rtcout.RTC_DEBUG("Found: %s is in %s", (port_name,OpenRTM_aist.flatten(portlist)))
00463       self._rtobj.addPort(prof.port_ref)
00464       self._rtcout.RTC_DEBUG("Port %s was delegated.", port_name)
00465 
00466     return
00467 
00468 
00469   ##
00470   # @if jp
00471   # @brief 委譲していたポートを削除する
00472   # @else
00473   # @brief Remove delegated participatns's ports from the composite
00474   # @endif
00475   #
00476   # void removePort(Member& member, PortList& portlist)
00477   def removePort(self, member, portlist):
00478     self._rtcout.RTC_DEBUG("removePort()")
00479     if len(portlist) == 0:
00480       return
00481 
00482     comp_name = member._profile.instance_name
00483     plist = member._profile.port_profiles
00484     
00485     # port delegation
00486     for prof in plist:
00487       # port name -> comp_name.port_name
00488       port_name = prof.name
00489         
00490       self._rtcout.RTC_DEBUG("port_name: %s is in %s?", (port_name,OpenRTM_aist.flatten(portlist)))
00491       if not port_name in portlist:
00492         self._rtcout.RTC_DEBUG("Not found: %s is in %s?", (port_name,OpenRTM_aist.flatten(portlist)))
00493         continue
00494 
00495       self._rtcout.RTC_DEBUG("Found: %s is in %s", (port_name,OpenRTM_aist.flatten(portlist)))
00496       self._rtobj.removePort(prof.port_ref)
00497       portlist.remove(port_name)
00498       self._rtcout.RTC_DEBUG("Port %s was deleted.", port_name)
00499 
00500     return
00501 
00502 
00503   ##
00504   # @if jp
00505   # @brief PortsListを更新する
00506   # @else
00507   # @brief PortsList is updated. 
00508   # @endif
00509   #
00510   def updateExportedPortsList(self):
00511     plist = self._rtobj.getProperties().getProperty("conf.default.exported_ports")
00512     if plist:
00513       p = [plist]
00514       OpenRTM_aist.eraseBlank(p)
00515       self._expPorts = p[0].split(",")
00516 
00517     return
00518 
00519   ##
00520   # @if jp
00521   # @brief Organizationメンバーを更新/削除する
00522   # @else
00523   # @brief Update/Remove a member of Organization
00524   # @endif
00525   #
00526   def updateDelegatedPorts(self):
00527     oldPorts = self._expPorts
00528     ports = self._rtobj.getProperties().getProperty("conf.default.exported_ports")
00529     newPorts = ports.split(",")
00530 
00531     
00532     removedPorts = list(set(oldPorts).difference(set(newPorts)))
00533     createdPorts = list(set(newPorts).difference(set(oldPorts)))
00534     
00535     self._rtcout.RTC_VERBOSE("old    ports: %s", OpenRTM_aist.flatten(oldPorts))
00536     self._rtcout.RTC_VERBOSE("new    ports: %s", OpenRTM_aist.flatten(newPorts))
00537     self._rtcout.RTC_VERBOSE("remove ports: %s", OpenRTM_aist.flatten(removedPorts))
00538     self._rtcout.RTC_VERBOSE("add    ports: %s", OpenRTM_aist.flatten(createdPorts))
00539 
00540     for member in self._rtcMembers:
00541       self.removePort(member, removedPorts)
00542       self.addPort(member, createdPorts)
00543 
00544     self._expPorts = newPorts
00545     return
00546 
00547 
00548   class Member:
00549     def __init__(self, rtobj):
00550       self._rtobj   = rtobj
00551       self._profile = rtobj.get_component_profile()
00552       self._eclist  = rtobj.get_owned_contexts()
00553       self._config  = rtobj.get_configuration()
00554       return
00555             
00556     def __call__(self, x):
00557       tmp = x
00558       tmp.swap(self)
00559       return self
00560 
00561         
00562     def swap(self, x):
00563       rtobj   = x._rtobj
00564       profile = x._profile
00565       eclist  = x._eclist
00566       config  = x._config
00567       
00568       x._rtobj   = self._rtobj
00569       x._profile = self._profile
00570       x._eclist  = self._eclist
00571       x._config  = self._config
00572 
00573       self._rtobj   = rtobj
00574       self._profile = profile
00575       self._eclist  = eclist
00576       self._config  = config
00577       return
00578             
00579 
00580 ##
00581 # @if jp
00582 # @namespace RTC
00583 #
00584 # @brief RTコンポーネント
00585 #
00586 # @else
00587 #
00588 # @namespace RTC
00589 #
00590 # @brief RT-Component
00591 #
00592 # @endif
00593 #
00594 
00595 ##
00596 # @if jp
00597 # @class PeriodicECSharedComposite
00598 # @brief PeriodicECSharedComposite クラス
00599 #
00600 # データフロー型RTComponentの基底クラス。
00601 # 各種データフロー型RTComponentを実装する場合は、本クラスを継承する形で実装
00602 # する。
00603 #
00604 # @since 0.4.0
00605 #
00606 # @else
00607 # @class PeriodicECSharedComposite
00608 # @brief PeriodicECSharedComposite class
00609 #
00610 # This is a base class of the data flow type RT-Component.
00611 # Inherit this class when implementing various data flow type RT-Components.
00612 #
00613 # @since 0.4.0
00614 #
00615 # @endif
00616 #
00617 class PeriodicECSharedComposite(OpenRTM_aist.RTObject_impl):
00618 
00619 
00620   ##
00621   # @if jp
00622   # @brief コンストラクタ
00623   #
00624   # コンストラクタ
00625   #
00626   # @param manager マネージャオブジェクト
00627   #
00628   # @else
00629   # @brief Constructor
00630   #
00631   # Constructor
00632   #
00633   # @param manager Manager object
00634   #
00635   # @endif
00636   #
00637   def __init__(self, manager):
00638     OpenRTM_aist.RTObject_impl.__init__(self,manager)
00639     self._ref = self._this()
00640     self._objref = self._ref
00641     self._org = OpenRTM_aist.PeriodicECOrganization(self)
00642     OpenRTM_aist.CORBA_SeqUtil.push_back(self._sdoOwnedOrganizations,
00643                                          self._org.getObjRef())
00644 
00645     self._members = [[]]
00646     self.bindParameter("members", self._members, "", stringToStrVec)
00647     self._rtcout = OpenRTM_aist.Manager.instance().getLogbuf("rtobject.periodic_ec_shared")
00648     self._configsets.addConfigurationSetListener(\
00649       OpenRTM_aist.ConfigurationSetListenerType.ON_SET_CONFIG_SET,
00650       setCallback(self._org))
00651 
00652     self._configsets.addConfigurationSetListener(\
00653       OpenRTM_aist.ConfigurationSetListenerType.ON_ADD_CONFIG_SET,
00654       addCallback(self._org))
00655 
00656     return
00657 
00658 
00659   ##
00660   # @if jp
00661   # @brief デストラクタ
00662   #
00663   # デストラクタ
00664   #
00665   # @else
00666   # @brief Destructor
00667   #
00668   # Destructor
00669   #
00670   # @endif
00671   #
00672   def __del__(self):
00673     self._rtcout.RTC_TRACE("destructor of PeriodicECSharedComposite")
00674     pass
00675 
00676     
00677   ##
00678   # @if jp
00679   # @brief 初期化
00680   #
00681   # データフロー型 RTComponent の初期化を実行する。
00682   # 実際の初期化処理は、各具象クラス内に記述する。
00683   #
00684   # @else
00685   # @brief Initialization
00686   #
00687   # Initialization the data flow type RT-Component.
00688   # Write the actual initialization code in each concrete class.
00689   #
00690   # @endif
00691   #
00692   def onInitialize(self):
00693     self._rtcout.RTC_TRACE("onInitialize()")
00694 
00695     active_set = self._properties.getProperty("configuration.active_config",
00696                                               "default")
00697     if self._configsets.haveConfig(active_set):
00698       self._configsets.update(active_set)
00699     else:
00700       self._configsets.update("default")
00701 
00702     mgr = OpenRTM_aist.Manager.instance()
00703     sdos = []
00704     for member in self._members[0]:
00705       if member == "":
00706         continue
00707 
00708       rtc = mgr.getComponent(member)
00709 
00710       if rtc is None:
00711         print "no RTC found: ", member
00712         continue
00713 
00714       sdo = rtc.getObjRef()
00715       if CORBA.is_nil(sdo):
00716         continue
00717 
00718       OpenRTM_aist.CORBA_SeqUtil.push_back(sdos, sdo)
00719     
00720     try:
00721       self._org.set_members(sdos)
00722     except:
00723       self._rtcout.RTC_ERROR(OpenRTM_aist.Logger.print_exception())
00724 
00725     return RTC.RTC_OK
00726 
00727 
00728   ##
00729   # @if jp
00730   #
00731   # @brief 活性化処理用コールバック関数
00732   # 
00733   # ComponentAction::on_activated が呼ばれた際に実行されるコールバック
00734   # 関数。<BR>
00735   # 本関数は無条件に RTC::RTC_OK を返すようにダミー実装されているので、
00736   # 各コンポーネントの実際の活性化処理は、本関数をオーバーライドして実装する
00737   # 必要がある。
00738   # 
00739   # @param exec_handle 参加している ExecutionContext の ID
00740   #
00741   # @return ReturnCode_t 型のリターンコード
00742   # 
00743   # @else
00744   #
00745   # @brief Callback function to activate
00746   # 
00747   # This is a callback function that is executed when
00748   # ComponentAction::on_activated was invoked.<BR>
00749   # As for actual activation of each component, since this function is
00750   # dummy-implemented to return RTC::RTC_OK unconditionally, you need to
00751   # implement this function by overriding it.
00752   # 
00753   # @param exec_handle ID of the participant ExecutionContext
00754   #
00755   # @return The return code of ReturnCode_t type
00756   # 
00757   # @endif
00758   #
00759   def onActivated(self, exec_handle):
00760     self._rtcout.RTC_TRACE("onActivated(%d)", exec_handle)
00761     ecs = self.get_owned_contexts()
00762     sdos = self._org.get_members()
00763 
00764     for sdo in sdos:
00765       rtc = sdo._narrow(RTC.RTObject)
00766       ecs[0].activate_component(rtc)
00767 
00768     len_ = len(self._members[0])
00769 
00770     # since Python 2.5
00771     # self._rtcout.RTC_DEBUG("%d member RTC%s activated.", (len_,(lambda x:  if x > 1 else "was")(len_)))
00772     if len_ > 1:
00773       str_ = "s were"
00774     else:
00775       str_ = "was"
00776 
00777     self._rtcout.RTC_DEBUG("%d member RTC%s activated.", (len_, str_))
00778 
00779     return RTC.RTC_OK
00780 
00781 
00782   ##
00783   # @if jp
00784   #
00785   # @brief 非活性化処理用コールバック関数
00786   # 
00787   # ComponentAction::on_deactivated が呼ばれた際に実行されるコールバック
00788   # 関数。<BR>
00789   # 本関数は無条件に RTC::RTC_OK を返すようにダミー実装されているので、
00790   # 各コンポーネントの実際の非活性化処理は、本関数をオーバーライドして実装する
00791   # 必要がある。
00792   # 
00793   # @param exec_handle 参加している ExecutionContext の ID
00794   #
00795   # @return ReturnCode_t 型のリターンコード
00796   # 
00797   # @else
00798   #
00799   # @brief Callback function to deactivate
00800   # 
00801   # This is a callback function that is executed when
00802   # ComponentAction::on_deactivated was invoked.<BR>
00803   # As for actual deactivation of each component, since this function is
00804   # dummy-implemented to return RTC::RTC_OK unconditionally, you need to
00805   # implement this function by overriding it.
00806   # 
00807   # @param exec_handle ID of the participant ExecutionContext
00808   #
00809   # @return The return code of ReturnCode_t type
00810   # 
00811   # @endif
00812   #
00813   def onDeactivated(self, exec_handle):
00814     self._rtcout.RTC_TRACE("onDeactivated(%d)", exec_handle)
00815     ecs = self.get_owned_contexts()
00816     sdos = self._org.get_members()
00817 
00818     for sdo in sdos:
00819       rtc = sdo._narrow(RTC.RTObject)
00820       ecs[0].deactivate_component(rtc)
00821 
00822     return RTC.RTC_OK
00823 
00824 
00825   ##
00826   # @if jp
00827   #
00828   # @brief リセット処理用コールバック関数
00829   # 
00830   # ComponentAction::on_reset が呼ばれた際に実行されるコールバック関数。<BR>
00831   # 本関数は無条件に RTC::RTC_OK を返すようにダミー実装されているので、
00832   # 各コンポーネントの実際のリセット処理は、本関数をオーバーライドして実装する
00833   # 必要がある。
00834   # 
00835   # @param exec_handle 参加している ExecutionContext の ID
00836   #
00837   # @return ReturnCode_t 型のリターンコード
00838   # 
00839   # @else
00840   #
00841   # @brief Callback function to reset
00842   # 
00843   # This is a callback function that is executed when
00844   # ComponentAction::on_reset was invoked.<BR>
00845   # As for actual reset of each component, since this function is
00846   # dummy-implemented to return RTC::RTC_OK unconditionally, you need to
00847   # implement this function by overriding it.
00848   # 
00849   # @param exec_handle ID of the participant ExecutionContext
00850   #
00851   # @return The return code of ReturnCode_t type
00852   # 
00853   # @endif
00854   #
00855   def onReset(self, exec_handle):
00856     self._rtcout.RTC_TRACE("onReset(%d)", exec_handle)
00857     ecs = self.get_owned_contexts()
00858     sdos = self._org.get_members()
00859 
00860     for sdo in sdos:
00861       rtc = sdo._narrow(RTC.RTObject)
00862       ecs[0].reset_component(rtc)
00863 
00864     return RTC.RTC_OK
00865 
00866 
00867   ##
00868   # @if jp
00869   #
00870   # @brief [ComponentAction CORBA interface] RTC の終了
00871   #
00872   # RTC が破棄される。
00873   # RTC 固有の終了処理はここで実行する。
00874   # このオペレーション呼び出しの結果として onFinalize() コールバック関数が
00875   # 呼び出される。
00876   #
00877   # @return ReturnCode_t 型のリターンコード
00878   #
00879   # @else
00880   #
00881   # @brief [ComponentAction CORBA interface] Finalize RTC
00882   #
00883   # The RTC is being destroyed.
00884   # Any final RTC-specific tear-down logic should be performed here.
00885   # As a result of this operation, onFinalize() callback function is called.
00886   #
00887   # @return The return code of ReturnCode_t type
00888   #
00889   # @endif
00890   #
00891   def onFinalize(self):
00892     self._rtcout.RTC_TRACE("onFinalize()")
00893     self._org.removeAllMembers()
00894     self._rtcout.RTC_PARANOID("onFinalize() done")
00895     return RTC.RTC_OK
00896 
00897 
00898     
00899 def PeriodicECSharedCompositeInit(manager):
00900   profile = OpenRTM_aist.Properties(defaults_str=periodicecsharedcomposite_spec)
00901   manager.registerFactory(profile,
00902                           OpenRTM_aist.PeriodicECSharedComposite,
00903                           OpenRTM_aist.Delete)
00904 


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