00001 #!/usr/bin/env python 00002 # -*- coding: euc-jp -*- 00003 00004 ## 00005 # @file PortBase.py 00006 # @brief RTC's Port base class 00007 # @date $Date: 2007/09/18 $ 00008 # @author Noriaki Ando <n-ando@aist.go.jp> and Shinji Kurihara 00009 # 00010 # Copyright (C) 2006-2008 00011 # Task-intelligence Research Group, 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 threading 00019 00020 import OpenRTM 00021 import RTC, RTC__POA 00022 00023 00024 00025 ## 00026 # @if jp 00027 # @class ScopedLock 00028 # @brief ScopedLock クラス 00029 # 00030 # 排他処理用ロッククラス。 00031 # 00032 # @since 0.4.0 00033 # 00034 # @else 00035 # 00036 # @endif 00037 class ScopedLock: 00038 00039 00040 00041 ## 00042 # @if jp 00043 # @brief コンストラクタ 00044 # 00045 # コンストラクタ 00046 # 00047 # @param self 00048 # @param mutex ロック用ミューテックス 00049 # 00050 # @else 00051 # 00052 # @endif 00053 def __init__(self, mutex): 00054 self.mutex = mutex 00055 self.mutex.acquire() 00056 00057 00058 ## 00059 # @if jp 00060 # @brief デストラクタ 00061 # 00062 # デストラクタ 00063 # 00064 # @param self 00065 # 00066 # @else 00067 # 00068 # @endif 00069 def __del__(self): 00070 self.mutex.release() 00071 00072 00073 00074 ## 00075 # @if jp 00076 # @class PortBase 00077 # @brief Port の基底クラス 00078 # 00079 # RTC::Port の基底となるクラス。 00080 # RTC::Port はほぼ UML Port の概念を継承しており、ほぼ同等のものとみなす 00081 # ことができる。RT コンポーネントのコンセプトにおいては、 00082 # Port はコンポーネントに付属し、コンポーネントが他のコンポーネントと相互作用 00083 # を行う接点であり、通常幾つかのインターフェースと関連付けられる。 00084 # コンポーネントは Port を通して外部に対しインターフェースを提供または要求 00085 # することができ、Portはその接続を管理する役割を担う。 00086 # <p> 00087 # Port の具象クラスは、通常 RT コンポーネントインスタンス生成時に同時に 00088 # 生成され、提供・要求インターフェースを登録した後、RT コンポーネントに 00089 # 登録され、外部からアクセス可能な Port として機能することを想定している。 00090 # <p> 00091 # RTC::Port は CORBA インターフェースとして以下のオペレーションを提供する。 00092 # 00093 # - get_port_profile() 00094 # - get_connector_profiles() 00095 # - get_connector_profile() 00096 # - connect() 00097 # - notify_connect() 00098 # - disconnect() 00099 # - notify_disconnect() 00100 # - disconnect_all() 00101 # 00102 # このクラスでは、これらのオペレーションの実装を提供する。 00103 # <p> 00104 # これらのオペレーションのうち、get_port_profile(), get_connector_profiles(), 00105 # get_connector_profile(), connect(), disconnect(), disconnect_all() は、 00106 # サブクラスにおいて特に振る舞いを変更する必要がないため、オーバーライド 00107 # することは推奨されない。 00108 # <p> 00109 # notify_connect(), notify_disconnect() については、サブクラスが提供・要求 00110 # するインターフェースの種類に応じて、振る舞いを変更する必要が生ずる 00111 # かもしれないが、これらを直接オーバーライドすることは推奨されず、 00112 # 後述の notify_connect(), notify_disconnect() の項においても述べられる通り 00113 # これらの関数に関連した 関数をオーバーライドすることにより振る舞いを変更する 00114 # ことが推奨される。 00115 # 00116 # @since 0.4.0 00117 # 00118 # @else 00119 # 00120 # 00121 # @endif 00122 class PortBase(RTC__POA.Port): 00123 """ 00124 """ 00125 00126 00127 00128 ## 00129 # @if jp 00130 # @brief コンストラクタ 00131 # 00132 # PortBase のコンストラクタは Port 名 name を引数に取り初期化を行う 00133 # と同時に、自分自身を CORBA Object として活性化し、自身の PortProfile 00134 # の port_ref に自身のオブジェクトリファレンスを格納する。 00135 # 00136 # @param self 00137 # @param name Port の名前(デフォルト値:None) 00138 # 00139 # @else 00140 # 00141 # @brief Constructor 00142 # 00143 # The constructor of the ProtBase class is given the name of this Port 00144 # and initialized. At the same time, the PortBase activates itself 00145 # as CORBA object and stores its object reference to the PortProfile's 00146 # port_ref member. 00147 # 00148 # @param name The name of Port 00149 # 00150 # @endif 00151 def __init__(self, name=None): 00152 self._profile = RTC.PortProfile("", [], RTC.Port._nil, [], RTC.RTObject._nil,[]) 00153 00154 if name is None: 00155 self._profile.name = "" 00156 else: 00157 self._profile.name = name 00158 00159 self._objref = self._this() 00160 self._profile.port_ref = self._objref 00161 self._profile.owner = RTC.RTObject._nil 00162 self._profile_mutex = threading.RLock() 00163 00164 00165 ## 00166 # @if jp 00167 # 00168 # @brief [CORBA interface] PortProfileを取得する 00169 # 00170 # Portが保持するPortProfileを返す。 00171 # PortProfile 構造体は以下のメンバーを持つ。 00172 # 00173 # - name [string 型] Port の名前。 00174 # - interfaces [PortInterfaceProfileList 型] Port が保持する 00175 # PortInterfaceProfile のシーケンス 00176 # - port_ref [Port Object 型] Port 自身のオブジェクトリファレンス 00177 # - connector_profile [ConnectorProfileList 型] Port が現在保持する 00178 # ConnectorProfile のシーケンス 00179 # - owner [RTObject Object 型] この Port を所有する 00180 # RTObjectのリファレンス 00181 # - properties [NVList 型] その他のプロパティ。 00182 # 00183 # @param self 00184 # 00185 # @return PortProfile 00186 # 00187 # @else 00188 # 00189 # @brief [CORBA interface] Get the PortProfile of the Port 00190 # 00191 # This operation returns the PortProfile of the Port. 00192 # PortProfile struct has the following members, 00193 # 00194 # - name [string ] The name of the Port. 00195 # - interfaces [PortInterfaceProfileList 型] The sequence of 00196 # PortInterfaceProfile owned by the Port 00197 # - port_ref [Port Object] The object reference of the Port. 00198 # - connector_profile [ConnectorProfileList 型] The sequence of 00199 # ConnectorProfile owned by the Port. 00200 # - owner [RTObject Object] The object reference of 00201 # RTObject that is owner of the Port. 00202 # - properties [NVList] The other properties. 00203 # 00204 # @return the PortProfile of the Port 00205 # 00206 # @endif 00207 def get_port_profile(self): 00208 guard = ScopedLock(self._profile_mutex) 00209 prof = RTC.PortProfile(self._profile.name, 00210 self._profile.interfaces, 00211 self._profile.port_ref, 00212 self._profile.connector_profiles, 00213 self._profile.owner, 00214 self._profile.properties) 00215 00216 return prof 00217 00218 00219 ## 00220 # @if jp 00221 # 00222 # @brief [CORBA interface] ConnectorProfileListを取得する 00223 # 00224 # Portが保持する ConnectorProfile の sequence を返す。 00225 # ConnectorProfile は Port 間の接続プロファイル情報を保持する構造体であり、 00226 # 接続時にPort間で情報交換を行い、関連するすべての Port で同一の値が 00227 # 保持される。 00228 # ConnectorProfile は以下のメンバーを保持している。 00229 # 00230 # - name [string 型] このコネクタの名前。 00231 # - connector_id [string 型] ユニークなID 00232 # - ports [Port sequnce] このコネクタに関連する Port のオブジェクト 00233 # リファレンスのシーケンス。 00234 # - properties [NVList 型] その他のプロパティ。 00235 # 00236 # @param self 00237 # 00238 # @return この Port が保持する ConnectorProfile 00239 # 00240 # @else 00241 # 00242 # @brief [CORBA interface] Get the ConnectorProfileList of the Port 00243 # 00244 # This operation returns a list of the ConnectorProfiles of the Port. 00245 # ConnectorProfile includes the connection information that describes 00246 # relation between (among) Ports, and Ports exchange the ConnectionProfile 00247 # on connection process and hold the same information in each Port. 00248 # ConnectionProfile has the following members, 00249 # 00250 # - name [string] The name of the connection. 00251 # - connector_id [string] Unique identifier. 00252 # - ports [Port sequnce] The sequence of Port's object reference 00253 # that are related the connection. 00254 # - properties [NVList] The other properties. 00255 # 00256 # @return the ConnectorProfileList of the Port 00257 # 00258 # @endif 00259 def get_connector_profiles(self): 00260 guard = ScopedLock(self._profile_mutex) 00261 return self._profile.connector_profiles 00262 00263 00264 ## 00265 # @if jp 00266 # 00267 # @brief [CORBA interface] ConnectorProfile を取得する 00268 # 00269 # connector_id で指定された ConnectorProfile を返す。 00270 # 指定した connector_id を持つ ConnectorProfile を保持していない場合は、 00271 # 空の ConnectorProfile を返す。 00272 # 00273 # @param self 00274 # @param connector_id ConnectorProfile の ID 00275 # 00276 # @return connector_id で指定された ConnectorProfile 00277 # 00278 # @else 00279 # 00280 # @brief [CORBA interface] Get the ConnectorProfile 00281 # 00282 # This operation returns the ConnectorProfiles specified connector_id. 00283 # 00284 # @param connector_id ID of the ConnectorProfile 00285 # 00286 # @return the ConnectorProfile identified by the connector_id 00287 # 00288 # @endif 00289 def get_connector_profile(self, connector_id): 00290 guard = ScopedLock(self._profile_mutex) 00291 index = OpenRTM.CORBA_SeqUtil.find(self._profile.connector_profiles, 00292 self.find_conn_id(connector_id)) 00293 if index < 0: 00294 conn_prof = RTC.ConnectorProfile("","",[],[]) 00295 return conn_prof 00296 00297 conn_prof = RTC.ConnectorProfile(self._profile.connector_profiles[index].name, 00298 self._profile.connector_profiles[index].connector_id, 00299 self._profile.connector_profiles[index].ports, 00300 self._profile.connector_profiles[index].properties) 00301 return conn_prof 00302 00303 00304 ## 00305 # @if jp 00306 # 00307 # @brief [CORBA interface] Port の接続を行う 00308 # 00309 # 与えられた ConnectoionProfile の情報を基に、Port間の接続を確立する。 00310 # アプリケーションプログラム側は、幾つかのコンポーネントが持つ複数の 00311 # Port を接続したい場合、適切な値をセットした ConnectorProfile を 00312 # connect() の引数として与えてコールすることにより、関連する Port の 00313 # 接続を確立する。 00314 # 00315 # connect() に与える ConnectorProfile のメンバーのうち、name, ports, 00316 # properties メンバーに対してデータをセットしなければならない。 00317 # 00318 # OutPort 側の connect() では以下のシーケンスで処理が行われる。 00319 # 00320 # 1. OutPort に関連する connector 情報の生成およびセット 00321 # 00322 # 2. InPortに関連する connector 情報の取得 00323 # - ConnectorProfile::properties["dataport.corba_any.inport_ref"]に 00324 # OutPortAny のオブジェクトリファレンスが設定されている場合、 00325 # リファレンスを取得してConsumerオブジェクトにセットする。 00326 # リファレンスがセットされていなければ無視して継続。 00327 # (OutPortがconnect() 呼び出しのエントリポイントの場合は、 00328 # InPortのオブジェクトリファレンスはセットされていないはずである。) 00329 # 00330 # 3. PortBase::connect() をコール 00331 # Portの接続の基本処理が行われる。 00332 # 00333 # 4. 上記2.でInPortのリファレンスが取得できなければ、再度InPortに 00334 # 関連する connector 情報を取得する。 00335 # 00336 # 5. ConnectorProfile::properties で与えられた情報から、 00337 # OutPort側の初期化処理を行う。 00338 # 00339 # - [dataport.interface_type]<BR> 00340 # -- CORBA_Any の場合: 00341 # InPortAny を通してデータ交換される。 00342 # ConnectorProfile::properties["dataport.corba_any.inport_ref"]に 00343 # InPortAny のオブジェクトリファレンスをセットする。<BR> 00344 # 00345 # - [dataport.dataflow_type]<BR> 00346 # -- Pushの場合: Subscriberを生成する。Subscriberのタイプは、 00347 # dataport.subscription_type に設定されている。<BR> 00348 # -- Pullの場合: InPort側がデータをPull型で取得するため、 00349 # 特に何もする必要が無い。 00350 # 00351 # - [dataport.subscription_type]<BR> 00352 # -- Onceの場合: SubscriberOnceを生成する。<BR> 00353 # -- Newの場合: SubscriberNewを生成する。<BR> 00354 # -- Periodicの場合: SubscriberPeriodicを生成する。 00355 # 00356 # - [dataport.push_interval]<BR> 00357 # -- dataport.subscription_type=Periodicの場合周期を設定する。 00358 # 00359 # 6. 上記の処理のうち一つでもエラーであれば、エラーリターンする。 00360 # 正常に処理が行われた場合は RTC::RTC_OK でリターンする。 00361 # 00362 # @param self 00363 # @param connector_profile ConnectorProfile 00364 # 00365 # @return ReturnCode_t 型のリターンコード 00366 # 00367 # @else 00368 # 00369 # @brief [CORBA interface] Connect the Port 00370 # 00371 # This operation establishes connection according to the given 00372 # ConnectionProfile inforamtion. 00373 # Application programs, which is going to establish the connection 00374 # among Ports owned by RT-Components, have to set valid values to the 00375 # ConnectorProfile and give it to the argument of connect() operation. 00376 # 00377 # name, ports, properties members of ConnectorProfile should be set 00378 # valid values before giving to the argument of connect() operation. 00379 # 00380 # @param connector_profile The ConnectorProfile. 00381 # 00382 # @return ReturnCode_t The return code of this operation. 00383 # 00384 # @endif 00385 def connect(self, connector_profile): 00386 if self.isEmptyId(connector_profile): 00387 self.setUUID(connector_profile) 00388 assert(not self.isExistingConnId(connector_profile.connector_id)) 00389 00390 try: 00391 retval,connector_profile = connector_profile.ports[0].notify_connect(connector_profile) 00392 return (retval, connector_profile) 00393 #return connector_profile.ports[0].notify_connect(connector_profile) 00394 except: 00395 return (RTC.BAD_PARAMETER, connector_profile) 00396 00397 return (RTC.RTC_ERROR, connector_profile) 00398 00399 00400 ## 00401 # @if jp 00402 # 00403 # @brief [CORBA interface] Port の接続通知を行う 00404 # 00405 # このオペレーションは、Port間の接続が行われる際に、Port間で内部的に 00406 # 呼ばれるオペレーションである。 00407 # ConnectorProfile には接続対象 Port のリスト情報が保持されている。Port は 00408 # ConnectorProfile を保持するとともに、リスト中の次 Port の notify_connect 00409 # を呼び出す。そして、ポートをコネクタに追加した後、ConnectorProfile に 00410 # 呼びだし先の Port を設定し、呼びだし元に返す。このように ConnectorProfile 00411 # を使用して接続通知が伝達されていく。 00412 # 00413 # @param self 00414 # @param connector_profile ConnectorProfile 00415 # 00416 # @return ReturnCode_t 型のリターンコード 00417 # 00418 # @else 00419 # 00420 # @brief [CORBA interface] Notify the Ports connection 00421 # 00422 # This operation is invoked between Ports internally when the connection 00423 # is established. 00424 # This operation notifies this PortService of the connection between its 00425 # corresponding port and the other ports and propagates the given 00426 # ConnectionProfile. 00427 # A ConnectorProfile has a sequence of port references. This PortService 00428 # stores the ConnectorProfile and invokes the notify_connect operation of 00429 # the next PortService in the sequence. As ports are added to the 00430 # connector, PortService references are added to the ConnectorProfile and 00431 # provided to the caller. In this way, notification of connection is 00432 # propagated with the ConnectorProfile. 00433 # 00434 # @param connector_profile The ConnectorProfile. 00435 # 00436 # @return ReturnCode_t The return code of this operation. 00437 # 00438 # @endif 00439 def notify_connect(self, connector_profile): 00440 # publish owned interface information to the ConnectorProfile 00441 retval = self.publishInterfaces(connector_profile) 00442 00443 if retval != RTC.RTC_OK: 00444 return (retval, connector_profile) 00445 00446 # call notify_connect() of the next Port 00447 retval, connector_profile = self.connectNext(connector_profile) 00448 if retval != RTC.RTC_OK: 00449 return (retval, connector_profile) 00450 00451 # subscribe interface from the ConnectorProfile's information 00452 retval = self.subscribeInterfaces(connector_profile) 00453 if retval != RTC.RTC_OK: 00454 #cleanup this connection for downstream ports 00455 self.notify_disconnect(connector_profile.connector_id) 00456 return (retval, connector_profile) 00457 00458 # update ConnectorProfile 00459 index = self.findConnProfileIndex(connector_profile.connector_id) 00460 if index < 0: 00461 OpenRTM.CORBA_SeqUtil.push_back(self._profile.connector_profiles, 00462 connector_profile) 00463 else: 00464 self._profile.connector_profiles[index] = connector_profile 00465 00466 return (retval, connector_profile) 00467 00468 00469 ## 00470 # @if jp 00471 # 00472 # @brief [CORBA interface] Port の接続を解除する 00473 # 00474 # このオペレーションは接続確立時に接続に対して与えられる connector_id に 00475 # 対応するピア Port との接続を解除する。 00476 # Port は ConnectorProfile 中のポートリストに含まれる1つのポートの 00477 # notify_disconnect を呼びだす。接続解除の通知は notify_disconnect によって 00478 # 実行される。 00479 # 00480 # @param self 00481 # @param connector_id ConnectorProfile の ID 00482 # 00483 # @return ReturnCode_t 型のリターンコード 00484 # 00485 # @else 00486 # 00487 # @brief [CORBA interface] Connect the Port 00488 # 00489 # This operation destroys connection between this port and the peer port 00490 # according to given id that is given when the connection established. 00491 # This port invokes the notify_disconnect operation of one of the ports 00492 # included in the sequence of the ConnectorProfile stored when the 00493 # connection was established. The notification of disconnection is 00494 # propagated by the notify_disconnect operation. 00495 # 00496 # @param connector_id The ID of the ConnectorProfile. 00497 # 00498 # @return ReturnCode_t The return code of this operation. 00499 # 00500 # @endif 00501 def disconnect(self, connector_id): 00502 # find connector_profile 00503 if not self.isExistingConnId(connector_id): 00504 return RTC.BAD_PARAMETER 00505 00506 index = self.findConnProfileIndex(connector_id) 00507 prof = RTC.ConnectorProfile(self._profile.connector_profiles[index].name, 00508 self._profile.connector_profiles[index].connector_id, 00509 self._profile.connector_profiles[index].ports, 00510 self._profile.connector_profiles[index].properties) 00511 return prof.ports[0].notify_disconnect(connector_id) 00512 00513 00514 ## 00515 # @if jp 00516 # 00517 # @brief [CORBA interface] Port の接続解除通知を行う 00518 # 00519 # このオペレーションは、Port間の接続解除が行われる際に、Port間で内部的に 00520 # 呼ばれるオペレーションである。 00521 # このオペレーションは、該当する Port と接続されている他の Port に接続解除 00522 # を通知する。接続解除対象の Port はIDによって指定される。Port は 00523 # ConnectorProfile 中のポートリスト内の次 Port の notify_disconnect を呼び 00524 # 出す。ポートの接続が解除されると ConnectorProfile から該当する Port の 00525 # 情報が削除される。このように notify_disconnect を使用して接続解除通知が 00526 # 伝達されていく。 00527 # 00528 # @param self 00529 # @param connector_id ConnectorProfile の ID 00530 # 00531 # @return ReturnCode_t 型のリターンコード 00532 # 00533 # @else 00534 # 00535 # @brief [CORBA interface] Notify the Ports disconnection 00536 # 00537 # This operation is invoked between Ports internally when the connection 00538 # is destroied. 00539 # This operation notifies a PortService of a disconnection between its 00540 # corresponding port and the other ports. The disconnected connector is 00541 # identified by the given ID, which was given when the connection was 00542 # established. 00543 # This port invokes the notify_disconnect operation of the next PortService 00544 # in the sequence of the ConnectorProfile that was stored when the 00545 # connection was established. As ports are disconnected, PortService 00546 # references are removed from the ConnectorProfile. In this way, 00547 # the notification of disconnection is propagated by the notify_disconnect 00548 # operation. 00549 # 00550 # @param connector_id The ID of the ConnectorProfile. 00551 # 00552 # @return ReturnCode_t The return code of this operation. 00553 # 00554 # @endif 00555 def notify_disconnect(self, connector_id): 00556 00557 # The Port of which the reference is stored in the beginning of 00558 # connectorProfile's PortList is master Port. 00559 # The master Port has the responsibility of disconnecting all Ports. 00560 # The slave Ports have only responsibility of deleting its own 00561 # ConnectorProfile. 00562 00563 # find connector_profile 00564 if not self.isExistingConnId(connector_id): 00565 return RTC.BAD_PARAMETER 00566 00567 index = self.findConnProfileIndex(connector_id) 00568 prof = RTC.ConnectorProfile(self._profile.connector_profiles[index].name, 00569 self._profile.connector_profiles[index].connector_id, 00570 self._profile.connector_profiles[index].ports, 00571 self._profile.connector_profiles[index].properties) 00572 00573 self.unsubscribeInterfaces(prof) 00574 retval = self.disconnectNext(prof) 00575 00576 OpenRTM.CORBA_SeqUtil.erase(self._profile.connector_profiles, index) 00577 00578 return retval 00579 00580 00581 ## 00582 # @if jp 00583 # 00584 # @brief [CORBA interface] Port の全接続を解除する 00585 # 00586 # このオペレーションはこの Port に関連した全ての接続を解除する。 00587 # 00588 # @param self 00589 # 00590 # @return ReturnCode_t 型のリターンコード 00591 # 00592 # @else 00593 # 00594 # @brief [CORBA interface] Connect the Port 00595 # 00596 # This operation destroys all connection channels owned by the Port. 00597 # 00598 # @return ReturnCode_t The return code of this operation. 00599 # 00600 # @endif 00601 def disconnect_all(self): 00602 guard = ScopedLock(self._profile_mutex) 00603 # disconnect all connections 00604 # Call disconnect() for each ConnectorProfile. 00605 f = OpenRTM.CORBA_SeqUtil.for_each(self._profile.connector_profiles, 00606 self.disconnect_all_func(self)) 00607 return f.return_code 00608 00609 00610 00611 #============================================================ 00612 # Local operations 00613 #============================================================ 00614 00615 ## 00616 # @if jp 00617 # @brief Port の名前を設定する 00618 # 00619 # Port の名前を設定する。この名前は Port が保持する PortProfile.name 00620 # に反映される。 00621 # 00622 # @param self 00623 # @param name Port の名前 00624 # 00625 # @else 00626 # @brief Set the name of this Port 00627 # 00628 # This operation sets the name of this Port. The given Port's name is 00629 # applied to Port's PortProfile.name. 00630 # 00631 # @param name The name of this Port. 00632 # 00633 # @endif 00634 def setName(self, name): 00635 guard = ScopedLock(self._profile_mutex) 00636 self._profile.name = name 00637 00638 00639 ## 00640 # @if jp 00641 # @brief PortProfileを取得する 00642 # 00643 # Portが保持する PortProfile の const 参照を返す。 00644 # 00645 # @param self 00646 # 00647 # @return この Port の PortProfile 00648 # 00649 # @else 00650 # @brief Get the PortProfile of the Port 00651 # 00652 # This operation returns const reference of the PortProfile. 00653 # 00654 # @return the PortProfile of the Port 00655 # 00656 # @endif 00657 def getProfile(self): 00658 guard = ScopedLock(self._profile_mutex) 00659 return self._profile 00660 00661 00662 ## 00663 # @if jp 00664 # 00665 # @brief Port のオブジェクト参照を設定する 00666 # 00667 # このオペレーションは Port の PortProfile にこの Port 自身の 00668 # オブジェクト参照を設定する。 00669 # 00670 # @param self 00671 # @param port_ref この Port のオブジェクト参照 00672 # 00673 # @else 00674 # 00675 # @brief Set the object reference of this Port 00676 # 00677 # This operation sets the object reference itself 00678 # to the Port's PortProfile. 00679 # 00680 # @param The object reference of this Port. 00681 # 00682 # @endif 00683 def setPortRef(self, port_ref): 00684 guard = ScopedLock(self._profile_mutex) 00685 self._profile.port_ref = port_ref 00686 00687 00688 ## 00689 # @if jp 00690 # 00691 # @brief Port のオブジェクト参照を取得する 00692 # 00693 # このオペレーションは Port の PortProfile が保持している 00694 # この Port 自身のオブジェクト参照を取得する。 00695 # 00696 # @param self 00697 # 00698 # @return この Port のオブジェクト参照 00699 # 00700 # @else 00701 # 00702 # @brief Get the object reference of this Port 00703 # 00704 # This operation returns the object reference 00705 # that is stored in the Port's PortProfile. 00706 # 00707 # @return The object reference of this Port. 00708 # 00709 # @endif 00710 def getPortRef(self): 00711 guard = ScopedLock(self._profile_mutex) 00712 return self._profile.port_ref 00713 00714 00715 ## 00716 # @if jp 00717 # 00718 # @brief Port の owner の RTObject を指定する 00719 # 00720 # このオペレーションは Port の PortProfile.owner を設定する。 00721 # 00722 # @param self 00723 # @param owner この Port を所有する RTObject の参照 00724 # 00725 # @else 00726 # 00727 # @brief Set the owner RTObject of the Port 00728 # 00729 # This operation sets the owner RTObject of this Port. 00730 # 00731 # @param owner The owner RTObject's reference of this Port 00732 # 00733 # @endif 00734 def setOwner(self, owner): 00735 guard = ScopedLock(self._profile_mutex) 00736 self._profile.owner = owner 00737 00738 00739 ## 00740 # @if jp 00741 # 00742 # @brief Interface 情報を公開する(サブクラス実装用) 00743 # 00744 # このオペレーションは、notify_connect() 処理シーケンスの始めにコール 00745 # される関数である。 00746 # notify_connect() では、 00747 # 00748 # - publishInterfaces() 00749 # - connectNext() 00750 # - subscribeInterfaces() 00751 # - updateConnectorProfile() 00752 # 00753 # の順に protected 関数がコールされ接続処理が行われる。 00754 # <br> 00755 # 具象 Port ではこのオペレーションをオーバーライドし、引数として 00756 # 与えられた ConnectorProfile に従い処理を行い、パラメータが不適切 00757 # であれば、RteurnCode_t 型のエラーコードを返す。 00758 # 通常 publishInterafaces() 内においては、この Port に属する 00759 # インターフェースに関する情報を ConnectorProfile に対して適切に設定し 00760 # 他の Port に通知しなければならない。 00761 # <br> 00762 # また、この関数がコールされる段階では、他の Port の Interface に関する 00763 # 情報はすべて含まれていないので、他の Port の Interface を取得する処理 00764 # は subscribeInterfaces() 内で行われるべきである。 00765 # <br> 00766 # このオペレーションは、新規の connector_id に対しては接続の生成、 00767 # 既存の connector_id に対しては更新が適切に行われる必要がある。<BR> 00768 # ※サブクラスでの実装参照用 00769 # 00770 # @param self 00771 # @param connector_profile 接続に関するプロファイル情報 00772 # 00773 # @return ReturnCode_t 型のリターンコード 00774 # 00775 # @else 00776 # 00777 # @brief Publish interface information 00778 # 00779 # This operation is pure virutal method that would be called at the 00780 # beginning of the notify_connect() process sequence. 00781 # In the notify_connect(), the following methods would be called in order. 00782 # 00783 # - publishInterfaces() 00784 # - connectNext() 00785 # - subscribeInterfaces() 00786 # - updateConnectorProfile() 00787 # 00788 # In the concrete Port, this method should be overridden. This method 00789 # processes the given ConnectorProfile argument and if the given parameter 00790 # is invalid, it would return error code of ReturnCode_t. 00791 # Usually, publishInterfaces() method should set interfaces information 00792 # owned by this Port, and publish it to the other Ports. 00793 # <br> 00794 # When this method is called, other Ports' interfaces information may not 00795 # be completed. Therefore, the process to obtain other Port's interfaces 00796 # information should be done in the subscribeInterfaces() method. 00797 # <br> 00798 # This operation should create the new connection for the new 00799 # connector_id, and should update the connection for the existing 00800 # connection_id. 00801 # 00802 # @param connector_profile The connection profile information 00803 # @return The return code of ReturnCode_t type. 00804 # 00805 #@endif 00806 def publishInterfaces(self, connector_profile): 00807 pass 00808 00809 00810 ## 00811 # @if jp 00812 # 00813 # @brief 次の Port に対して notify_connect() をコールする 00814 # 00815 # ConnectorProfile の port_ref 内に格納されている Port のオブジェクト 00816 # リファレンスのシーケンスの中から、自身の Port の次の Port に対して 00817 # notify_connect() をコールする。 00818 # 00819 # @param self 00820 # @param connector_profile 接続に関するプロファイル情報 00821 # 00822 # @return ReturnCode_t 型のリターンコード 00823 # 00824 # @else 00825 # 00826 # @brief Call notify_connect() of the next Port 00827 # 00828 # This operation calls the notify_connect() of the next Port's 00829 # that stored in ConnectorProfile's port_ref sequence. 00830 # 00831 # @param connector_profile The connection profile information 00832 # 00833 # @return The return code of ReturnCode_t type. 00834 # 00835 # @endif 00836 def connectNext(self, connector_profile): 00837 index = OpenRTM.CORBA_SeqUtil.find(connector_profile.ports, 00838 self.find_port_ref(self._profile.port_ref)) 00839 if index < 0: 00840 return RTC.BAD_PARAMETER, connector_profile 00841 00842 index += 1 00843 if index < len(connector_profile.ports): 00844 p = connector_profile.ports[index] 00845 return p.notify_connect(connector_profile) 00846 00847 return RTC.RTC_OK, connector_profile 00848 00849 00850 ## 00851 # @if jp 00852 # 00853 # @brief 次の Port に対して notify_disconnect() をコールする 00854 # 00855 # ConnectorProfile の port_ref 内に格納されている Port のオブジェクト 00856 # リファレンスのシーケンスの中から、自身の Port の次の Port に対して 00857 # notify_disconnect() をコールする。 00858 # 00859 # @param self 00860 # @param connector_profile 接続に関するプロファイル情報 00861 # 00862 # @return ReturnCode_t 型のリターンコード 00863 # 00864 # @else 00865 # 00866 # @brief Call notify_disconnect() of the next Port 00867 # 00868 # This operation calls the notify_disconnect() of the next Port's 00869 # that stored in ConnectorProfile's port_ref sequence. 00870 # 00871 # @param connector_profile The connection profile information 00872 # 00873 # @return The return code of ReturnCode_t type. 00874 # 00875 # @endif 00876 def disconnectNext(self, connector_profile): 00877 index = OpenRTM.CORBA_SeqUtil.find(connector_profile.ports, 00878 self.find_port_ref(self._profile.port_ref)) 00879 if index < 0: 00880 return RTC.BAD_PARAMETER 00881 00882 index += 1 00883 00884 if index < len(connector_profile.ports): 00885 p = connector_profile.ports[index] 00886 return p.notify_disconnect(connector_profile.connector_id) 00887 00888 self.unsubscribeInterfaces(connector_profile) 00889 return RTC.RTC_OK 00890 00891 00892 ## 00893 # @if jp 00894 # 00895 # @brief Interface 情報を取得する(サブクラス実装用) 00896 # 00897 # このオペレーションは、notify_connect() 処理シーケンスの中間にコール 00898 # される関数である。 00899 # notify_connect() では、 00900 # 00901 # - publishInterfaces() 00902 # - connectNext() 00903 # - subscribeInterfaces() 00904 # - updateConnectorProfile() 00905 # 00906 # の順に protected 関数がコールされ接続処理が行われる。 00907 # <br> 00908 # 具象 Port ではこのオペレーションをオーバーライドし、引数として 00909 # 与えられた ConnectorProfile に従い処理を行い、パラメータが不適切 00910 # であれば、RteurnCode_t 型のエラーコードを返す。 00911 # 引数 ConnectorProfile には他の Port の Interface に関する情報が 00912 # 全て含まれている。 00913 # 通常 subscribeInterafaces() 内においては、この Port が使用する 00914 # Interface に関する情報を取得し、要求側のインターフェースに対して 00915 # 情報を設定しなければならない。 00916 # <br> 00917 # このオペレーションは、新規の connector_id に対しては接続の生成、 00918 # 既存の connector_id に対しては更新が適切に行われる必要がある。<BR> 00919 # ※サブクラスでの実装参照用 00920 # 00921 # @param self 00922 # @param connector_profile 接続に関するプロファイル情報 00923 # 00924 # @return ReturnCode_t 型のリターンコード 00925 # 00926 # @else 00927 # 00928 # @brief Publish interface information 00929 # 00930 # This operation is pure virutal method that would be called at the 00931 # mid-flow of the notify_connect() process sequence. 00932 # In the notify_connect(), the following methods would be called in order. 00933 # 00934 # - publishInterfaces() 00935 # - connectNext() 00936 # - subscribeInterfaces() 00937 # - updateConnectorProfile() 00938 # 00939 # In the concrete Port, this method should be overridden. This method 00940 # processes the given ConnectorProfile argument and if the given parameter 00941 # is invalid, it would return error code of ReturnCode_t. 00942 # The given argument ConnectorProfile includes all the interfaces 00943 # information in it. 00944 # Usually, subscribeInterafaces() method obtains information of interfaces 00945 # from ConnectorProfile, and should set it to the interfaces that require 00946 # them. 00947 # <br> 00948 # This operation should create the new connection for the new 00949 # connector_id, and should update the connection for the existing 00950 # connection_id. 00951 # 00952 # @param connector_profile The connection profile information 00953 # 00954 # @return The return code of ReturnCode_t type. 00955 # 00956 #@endif 00957 def subscribeInterfaces(self, connector_profile): 00958 pass 00959 00960 00961 ## 00962 # @if jp 00963 # 00964 # @brief Interface の接続を解除する(サブクラス実装用) 00965 # 00966 # このオペレーションは、notify_disconnect() 処理シーケンスの終わりにコール 00967 # される関数である。 00968 # notify_disconnect() では、 00969 # - disconnectNext() 00970 # - unsubscribeInterfaces() 00971 # - eraseConnectorProfile() 00972 # の順に protected 関数がコールされ接続解除処理が行われる。 00973 # <br> 00974 # 具象 Port ではこのオペレーションをオーバーライドし、引数として 00975 # 与えられた ConnectorProfile に従い接続解除処理を行う。<BR> 00976 # ※サブクラスでの実装参照用 00977 # 00978 # @param self 00979 # @param connector_profile 接続に関するプロファイル情報 00980 # 00981 # @else 00982 # 00983 # @brief Disconnect interface connection 00984 # 00985 # This operation is pure virutal method that would be called at the 00986 # end of the notify_disconnect() process sequence. 00987 # In the notify_disconnect(), the following methods would be called. 00988 # - disconnectNext() 00989 # - unsubscribeInterfaces() 00990 # - eraseConnectorProfile() 00991 # <br> 00992 # In the concrete Port, this method should be overridden. This method 00993 # processes the given ConnectorProfile argument and disconnect interface 00994 # connection. 00995 # 00996 # @param connector_profile The connection profile information 00997 # 00998 # @endif 00999 def unsubscribeInterfaces(self, connector_profile): 01000 pass 01001 01002 01003 ## 01004 # @if jp 01005 # 01006 # @brief ConnectorProfile の connector_id フィールドが空かどうか判定 01007 # 01008 # 指定された ConnectorProfile の connector_id が空であるかどうかの判定を 01009 # 行う。 01010 # 01011 # @param self 01012 # @param connector_profile 判定対象コネクタプロファイル 01013 # 01014 # @return 引数で与えられた ConnectorProfile の connector_id が空であれば、 01015 # true、そうでなければ false を返す。 01016 # 01017 # @else 01018 # 01019 # @brief Whether connector_id of ConnectorProfile is empty 01020 # 01021 # @return If the given ConnectorProfile's connector_id is empty string, 01022 # it returns true. 01023 # 01024 # @endif 01025 def isEmptyId(self, connector_profile): 01026 return connector_profile.connector_id == "" 01027 01028 01029 ## 01030 # @if jp 01031 # 01032 # @brief UUIDを生成する 01033 # 01034 # このオペレーションは UUID を生成する。 01035 # 01036 # @param self 01037 # 01038 # @return uuid 01039 # 01040 # @else 01041 # 01042 # @brief Get the UUID 01043 # 01044 # This operation generates UUID. 01045 # 01046 # @return uuid 01047 # 01048 # @endif 01049 def getUUID(self): 01050 return str(OpenRTM.uuid1()) 01051 01052 01053 ## 01054 # @if jp 01055 # 01056 # @brief UUIDを生成し ConnectorProfile にセットする 01057 # 01058 # このオペレーションは UUID を生成し、ConnectorProfile にセットする。 01059 # 01060 # @param self 01061 # @param connector_profile connector_id をセットする ConnectorProfile 01062 # 01063 # @else 01064 # 01065 # @brief Create and set the UUID to the ConnectorProfile 01066 # 01067 # This operation generates and set UUID to the ConnectorProfile. 01068 # 01069 # @param connector_profile ConnectorProfile to be set connector_id 01070 # 01071 # @endif 01072 def setUUID(self, connector_profile): 01073 connector_profile.connector_id = self.getUUID() 01074 assert(connector_profile.connector_id != "") 01075 01076 01077 ## 01078 # @if jp 01079 # 01080 # @brief id が既存の ConnectorProfile のものかどうか判定する 01081 # 01082 # このオペレーションは与えられた ID が既存の ConnectorProfile のリスト中に 01083 # 存在するかどうか判定する。 01084 # 01085 # @param self 01086 # @param id_ 判定する connector_id 01087 # 01088 # @return id の存在判定結果 01089 # 01090 # @else 01091 # 01092 # @brief Whether the given id exists in stored ConnectorProfiles 01093 # 01094 # This operation returns boolean whether the given id exists in 01095 # the Port's ConnectorProfiles. 01096 # 01097 # @param id connector_id to be find in Port's ConnectorProfiles 01098 # 01099 # @endif 01100 def isExistingConnId(self, id_): 01101 return OpenRTM.CORBA_SeqUtil.find(self._profile.connector_profiles, 01102 self.find_conn_id(id_)) >= 0 01103 01104 01105 ## 01106 # @if jp 01107 # 01108 # @brief id を持つ ConnectorProfile を探す 01109 # 01110 # このオペレーションは与えられた ID を持つ ConnectorProfile を Port が 01111 # もつ ConnectorProfile のリスト中から探す。 01112 # もし、同一の id を持つ ConnectorProfile がなければ、空の ConnectorProfile 01113 # が返される。 01114 # 01115 # @param self 01116 # @param id_ 検索する connector_id 01117 # 01118 # @return connector_id を持つ ConnectorProfile 01119 # 01120 # @else 01121 # 01122 # @brief Find ConnectorProfile with id 01123 # 01124 # This operation returns ConnectorProfile with the given id from Port's 01125 # ConnectorProfiles' list. 01126 # If the ConnectorProfile with connector id that is identical with the 01127 # given id does not exist, empty ConnectorProfile is returned. 01128 # 01129 # @param id the connector_id to be searched in Port's ConnectorProfiles 01130 # 01131 # @return CoonectorProfile with connector_id 01132 # 01133 # @endif 01134 def findConnProfile(self, id_): 01135 index = OpenRTM.CORBA_SeqUtil.find(self._profile.connector_profiles, 01136 self.find_conn_id(id_)) 01137 if index < 0 or index >= len(self._profile.connector_profiles): 01138 return RTC.ConnectorProfile("","",[],[]) 01139 01140 return self._profile.connector_profiles[index] 01141 01142 01143 ## 01144 # @if jp 01145 # 01146 # @brief id を持つ ConnectorProfile を探す 01147 # 01148 # このオペレーションは与えられた ID を持つ ConnectorProfile を Port が 01149 # もつ ConnectorProfile のリスト中から探しインデックスを返す。 01150 # もし、同一の id を持つ ConnectorProfile がなければ、-1 を返す。 01151 # 01152 # @param self 01153 # @param id_ 検索する connector_id 01154 # 01155 # @return Port の ConnectorProfile リストのインデックス 01156 # 01157 # @else 01158 # 01159 # @brief Find ConnectorProfile with id 01160 # 01161 # This operation returns ConnectorProfile with the given id from Port's 01162 # ConnectorProfiles' list. 01163 # If the ConnectorProfile with connector id that is identical with the 01164 # given id does not exist, empty ConnectorProfile is returned. 01165 # 01166 # @param id the connector_id to be searched in Port's ConnectorProfiles 01167 # 01168 # @return The index of ConnectorProfile of the Port 01169 # 01170 # @endif 01171 def findConnProfileIndex(self, id_): 01172 return OpenRTM.CORBA_SeqUtil.find(self._profile.connector_profiles, 01173 self.find_conn_id(id_)) 01174 01175 01176 ## 01177 # @if jp 01178 # 01179 # @brief ConnectorProfile の追加もしくは更新 01180 # 01181 # このオペレーションは与えられた与えられた ConnectorProfile を 01182 # Port に追加もしくは更新保存する。 01183 # 与えられた ConnectorProfile の connector_id と同じ ID を持つ 01184 # ConnectorProfile がリストになければ、リストに追加し、 01185 # 同じ ID が存在すれば ConnectorProfile を上書き保存する。 01186 # 01187 # @param self 01188 # @param connector_profile 追加もしくは更新する ConnectorProfile 01189 # 01190 # @else 01191 # 01192 # @brief Append or update the ConnectorProfile list 01193 # 01194 # This operation appends or updates ConnectorProfile of the Port 01195 # by the given ConnectorProfile. 01196 # If the connector_id of the given ConnectorProfile does not exist 01197 # in the Port's ConnectorProfile list, the given ConnectorProfile would be 01198 # append to the list. If the same id exists, the list would be updated. 01199 # 01200 # @param connector_profile the ConnectorProfile to be appended or updated 01201 # 01202 # @endif 01203 def updateConnectorProfile(self, connector_profile): 01204 index = OpenRTM.CORBA_SeqUtil.find(self._profile.connector_profiles, 01205 self.find_conn_id(connector_profile.connector_id)) 01206 01207 if index < 0: 01208 OpenRTM.CORBA_SeqUtil.push_back(self._profile.connector_profiles, 01209 self.connector_profile) 01210 else: 01211 self._profile.connector_profiles[index] = connector_profile 01212 01213 01214 ## 01215 # @if jp 01216 # 01217 # @brief ConnectorProfile を削除する 01218 # 01219 # このオペレーションは Port の PortProfile が保持している 01220 # ConnectorProfileList のうち与えられた id を持つ ConnectorProfile 01221 # を削除する。 01222 # 01223 # @param self 01224 # @param id_ 削除する ConnectorProfile の id 01225 # 01226 # @return 正常に削除できた場合は true、 01227 # 指定した ConnectorProfile が見つからない場合は false を返す 01228 # 01229 # @else 01230 # 01231 # @brief Delete the ConnectorProfile 01232 # 01233 # This operation deletes a ConnectorProfile specified by id from 01234 # ConnectorProfileList owned by PortProfile of this Port. 01235 # 01236 # @param id The id of the ConnectorProfile to be deleted. 01237 # 01238 # @endif 01239 def eraseConnectorProfile(self, id_): 01240 guard = ScopedLock(self._profile_mutex) 01241 01242 index = OpenRTM.CORBA_SeqUtil.find(self._profile.connector_profiles, 01243 self.find_conn_id(id_)) 01244 01245 if index < 0: 01246 return False 01247 01248 OpenRTM.CORBA_SeqUtil.erase(self._profile.connector_profiles, index) 01249 01250 return True 01251 01252 01253 ## 01254 # @if jp 01255 # 01256 # @brief PortInterfaceProfile に インターフェースを登録する 01257 # 01258 # このオペレーションは Port が持つ PortProfile の、PortInterfaceProfile 01259 # にインターフェースの情報を追加する。 01260 # この情報は、get_port_profile() 似よって得られる PortProfile のうち 01261 # PortInterfaceProfile の値を変更するのみであり、実際にインターフェースを 01262 # 提供したり要求したりする場合には、サブクラスで、 publishInterface() , 01263 # subscribeInterface() 等の関数を適切にオーバーライドしインターフェースの 01264 # 提供、要求処理を行わなければならない。 01265 # 01266 # インターフェース(のインスタンス)名は Port 内で一意でなければならない。 01267 # 同名のインターフェースがすでに登録されている場合、この関数は false を 01268 # 返す。 01269 # 01270 # @param self 01271 # @param instance_name インターフェースのインスタンスの名前 01272 # @param type_name インターフェースの型の名前 01273 # @param pol インターフェースの属性 (RTC::PROVIDED もしくは RTC:REQUIRED) 01274 # 01275 # @return インターフェース登録処理結果。 01276 # 同名のインターフェースが既に登録されていれば false を返す。 01277 # 01278 # @else 01279 # 01280 # @brief Append an interface to the PortInterfaceProfile 01281 # 01282 # This operation appends interface information to the PortInterfaceProfile 01283 # that is owned by the Port. 01284 # The given interfaces information only updates PortInterfaceProfile of 01285 # PortProfile that is obtained through get_port_profile(). 01286 # In order to provide and require interfaces, proper functions (for 01287 # example publishInterface(), subscribeInterface() and so on) should be 01288 # overridden in subclasses, and these functions provide concrete interface 01289 # connection and disconnection functionality. 01290 # 01291 # The interface (instance) name have to be unique in the Port. 01292 # If the given interface name is identical with stored interface name, 01293 # this function returns false. 01294 # 01295 # @param name The instance name of the interface. 01296 # @param type_name The type name of the interface. 01297 # @param pol The interface's polarity (RTC::PROVIDED or RTC:REQUIRED) 01298 # 01299 # @return false would be returned if the same name is already registered. 01300 # 01301 # @endif 01302 def appendInterface(self, instance_name, type_name, pol): 01303 index = OpenRTM.CORBA_SeqUtil.find(self._profile.interfaces, 01304 self.find_interface(instance_name, pol)) 01305 01306 if index >= 0: 01307 return False 01308 01309 # setup PortInterfaceProfile 01310 prof = RTC.PortInterfaceProfile(instance_name, type_name, pol) 01311 OpenRTM.CORBA_SeqUtil.push_back(self._profile.interfaces, prof) 01312 01313 return True 01314 01315 01316 ## 01317 # @if jp 01318 # 01319 # @brief PortInterfaceProfile からインターフェース登録を削除する 01320 # 01321 # このオペレーションは Port が持つ PortProfile の、PortInterfaceProfile 01322 # からインターフェースの情報を削除する。 01323 # 01324 # @param self 01325 # @param name インターフェースのインスタンスの名前 01326 # @param pol インターフェースの属性 (RTC::PROVIDED もしくは RTC:REQUIRED) 01327 # 01328 # @return インターフェース削除処理結果。 01329 # インターフェースが登録されていなければ false を返す。 01330 # 01331 # @else 01332 # 01333 # @brief Delete an interface from the PortInterfaceProfile 01334 # 01335 # This operation deletes interface information from the 01336 # PortInterfaceProfile that is owned by the Port. 01337 # 01338 # @param name The instance name of the interface. 01339 # @param pol The interface's polarity (RTC::PROVIDED or RTC:REQUIRED) 01340 # 01341 # @return false would be returned if the given name is not registered. 01342 # 01343 # @endif 01344 def deleteInterface(self, name, pol): 01345 index = OpenRTM.CORBA_SeqUtil.find(self._profile.interfaces, 01346 self.find_interface(name, pol)) 01347 01348 if index < 0: 01349 return False 01350 01351 OpenRTM.CORBA_SeqUtil.erase(self._profile.interfaces, index) 01352 return True 01353 01354 01355 ## 01356 # @if jp 01357 # 01358 # @brief PortProfile の properties に NameValue 値を追加する 01359 # 01360 # PortProfile の properties に NameValue 値を追加する。 01361 # 追加するデータの型をValueTypeで指定する。 01362 # 01363 # @param self 01364 # @param key properties の name 01365 # @param value properties の value 01366 # 01367 # @else 01368 # 01369 # @brief Add NameValue data to PortProfile's properties 01370 # 01371 # @param key The name of properties 01372 # @param value The value of properties 01373 # 01374 # @endif 01375 def addProperty(self, key, value): 01376 OpenRTM.CORBA_SeqUtil.push_back(self._profile.properties, 01377 OpenRTM.NVUtil.newNV(key, value)) 01378 01379 01380 #============================================================ 01381 # Functor 01382 #============================================================ 01383 01384 ## 01385 # @if jp 01386 # @class if_name 01387 # @brief instance_name を持つ PortInterfaceProfile を探す Functor 01388 # @else 01389 # @brief A functor to find a PortInterfaceProfile named instance_name 01390 # @endif 01391 class if_name: 01392 def __init__(self, name): 01393 self._name = name 01394 01395 def __call__(self, prof): 01396 return str(self._name) == str(prof.instance_name) 01397 01398 01399 ## 01400 # @if jp 01401 # @class find_conn_id 01402 # @brief id を持つ ConnectorProfile を探す Functor 01403 # @else 01404 # @brief A functor to find a ConnectorProfile named id 01405 # @endif 01406 class find_conn_id: 01407 def __init__(self, id_): 01408 """ 01409 \param id_(string) 01410 """ 01411 self._id = id_ 01412 01413 def __call__(self, cprof): 01414 """ 01415 \param cprof(RTC.ConnectorProfile) 01416 """ 01417 return str(self._id) == str(cprof.connector_id) 01418 01419 ## 01420 # @if jp 01421 # @class find_port_ref 01422 # @brief コンストラクタ引数 port_ref と同じオブジェクト参照を探す Functor 01423 # @else 01424 # @brief A functor to find the object reference that is identical port_ref 01425 # @endif 01426 class find_port_ref: 01427 def __init__(self, port_ref): 01428 """ 01429 \param port_ref(RTC.Port) 01430 """ 01431 self._port_ref = port_ref 01432 01433 def __call__(self, port_ref): 01434 """ 01435 \param port_ref(RTC.Port) 01436 """ 01437 return self._port_ref._is_equivalent(port_ref) 01438 01439 ## 01440 # @if jp 01441 # @class connect_func 01442 # @brief Port の接続を行う Functor 01443 # @else 01444 # @brief A functor to connect Ports 01445 # @endif 01446 class connect_func: 01447 def __init__(self, p, prof): 01448 """ 01449 \param p(RTC.Port) 01450 \param prof(RTC.ConnectorProfile) 01451 """ 01452 self._port_ref = p 01453 self._connector_profile = prof 01454 self.return_code = RTC.RTC_OK 01455 01456 def __call__(self, p): 01457 """ 01458 \param p(RTC.Port) 01459 """ 01460 if not self._port_ref._is_equivalent(p): 01461 retval = p.notify_connect(self._connector_profile) 01462 if retval != RTC.RTC_OK: 01463 self.return_code = retval 01464 01465 ## 01466 # @if jp 01467 # @class disconnect_func 01468 # @brief Port の接続解除を行う Functor 01469 # @else 01470 # @brief A functor to disconnect Ports 01471 # @endif 01472 class disconnect_func: 01473 def __init__(self, p, prof): 01474 """ 01475 \param p(RTC.Port) 01476 \param prof(RTC.ConnectorProfile) 01477 """ 01478 self._port_ref = p 01479 self._connector_profile = prof 01480 self.return_code = RTC.RTC_OK 01481 01482 def __call__(self, p): 01483 """ 01484 \param p(RTC.Port) 01485 """ 01486 if not self._port_ref._is_equivalent(p): 01487 retval = p.disconnect(self._connector_profile.connector_id) 01488 if retval != RTC.RTC_OK: 01489 self.return_code = retval 01490 01491 ## 01492 # @if jp 01493 # @class disconnect_all_func 01494 # @brief Port の全接続解除を行う Functor 01495 # @else 01496 # @brief A functor to disconnect all Ports 01497 # @endif 01498 class disconnect_all_func: 01499 def __init__(self, p): 01500 """ 01501 \param p(OpenRTM.PortBase) 01502 """ 01503 self.return_code = RTC.RTC_OK 01504 self._port = p 01505 01506 def __call__(self, p): 01507 """ 01508 \param p(RTC.ConnectorProfile) 01509 """ 01510 retval = self._port.disconnect(p.connector_id) 01511 if retval != RTC.RTC_OK: 01512 self.return_code = retval 01513 01514 ## 01515 # @if jp 01516 # @class find_interface 01517 # @brief name と polarity から interface を探す Functor 01518 # @else 01519 # @brief A functor to find interface from name and polarity 01520 # @endif 01521 class find_interface: 01522 def __init__(self, name, pol): 01523 """ 01524 \param name(string) 01525 \param pol(RTC.PortInterfacePolarity) 01526 """ 01527 self._name = name 01528 self._pol = pol 01529 01530 def __call__(self, prof): 01531 """ 01532 \param prof(RTC.PortInterfaceProfile) 01533 """ 01534 name = prof.instance_name 01535 return (str(self._name) == str(name)) and (self._pol == prof.polarity)