00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 """
00023 GUI用ディクショナリの管理クラス
00024 """
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 import sys,os
00035 import string
00036 import mutex
00037 from omniORB import CORBA
00038
00039
00040
00041 import RTC
00042 from RTM import *
00043 from RtmDialog import *
00044
00045 NAME_PATH_NUM = 6
00046
00047
00048
00049 class RtmDictCore:
00050 """ディクショナリ管理クラス"""
00051 def __init__(self, parent):
00052 """クラスの初期化
00053
00054 [引数]
00055 parent -- 親クラス
00056
00057 [戻り値]
00058 void
00059 """
00060 self.parent = parent
00061 self.dict = {}
00062 self.default_ns = 'localhost'
00063 default_dict = {}
00064
00065 def __del__(self):
00066 pass
00067
00068
00069 def SplitTokenToFullpath(self, fullname):
00070 """フルパス名称のトークン分割
00071
00072 [引数]
00073 fullname -- '/'区切りのフルパス
00074 5階層以上の文字列はエラー
00075
00076 [戻り値]
00077 key_list -- トークンのlist
00078 """
00079 key_list = string.splitfields(fullname,'/')
00080 if len(key_list) > NAME_PATH_NUM:
00081 print "Error: SplitTokenToFullpath: fullpath is too long(please set to 5 or less)"
00082 key_list = None
00083 return key_list
00084
00085
00086 def ClearDictionary(self):
00087 """ディクショナリの削除
00088
00089 [引数]
00090 void
00091
00092 [戻り値]
00093 void
00094 """
00095 del self.dict
00096 self.dict = None
00097
00098 def GetInPortToRefCallback(self, fullpath):
00099 """ディクショナリのオブジェクトリファレンスからInPortを取得
00100
00101 [引数]
00102 fullpath -- フルパス指定
00103
00104 [戻り値]
00105 inport_list -- インポートリスト
00106 """
00107
00108 self.retlist = []
00109 try:
00110 ref = self.dict[fullpath]['objref']
00111 ref = ref._narrow(RTC.RTObject)
00112
00113 in_list = []
00114 ret_list = []
00115 in_list = ref._get_inports()
00116 tmp = {}
00117 n = 0
00118 for inp in in_list:
00119 inp = inp._narrow(InPort)
00120 tmp = {}
00121 tmp['ref'] = inp
00122 prof = inp._get_profile()
00123 tmp['name'] = prof.name
00124 tmp['port_type'] = prof.port_type.name()
00125
00126
00127
00128
00129
00130 ret_list.append(tmp)
00131 n=n+1
00132 except:
00133 except_mess("GetObjRefToInPort error!:")
00134 ret_list = []
00135
00136 self.retlist = ret_list
00137 return ret_list
00138
00139 def GetOutPortToRefCallback(self, fullpath):
00140 """ディクショナリのオブジェクトリファレンスからOutPortを取得
00141
00142 [引数]
00143 fullpath -- フルパス指定
00144
00145 [戻り値]
00146 outport_list -- アウトポートリスト
00147 """
00148 self.retlist = []
00149 try:
00150 ref = self.dict[fullpath]['objref']
00151 ref = ref._narrow(RTC.RTObject)
00152
00153 out_list = []
00154 out_list = ref._get_outports()
00155 ret_list = []
00156 tmp = {}
00157 n=0
00158 for outp in out_list:
00159 outp = outp._narrow(OutPort)
00160 tmp = {}
00161 tmp['ref'] = outp
00162 prof = outp._get_profile()
00163 tmp['name'] = prof.name
00164 tmp['port_type'] = prof.port_type.name()
00165
00166
00167
00168 ret_list.append(tmp)
00169 n=n+1
00170 except:
00171 except_mess("GetObjRefToOutPort error!:")
00172 ret_list = []
00173
00174 self.retlist = ret_list
00175 return ret_list
00176
00177
00178 def SetObjRefToFullpath(self, position, comp):
00179 """ディクショナリにオブジェクトリファレンスを追加
00180
00181 [引数]
00182 position -- フルパス指定
00183 comp -- objref,id,kind のディクショナリ
00184
00185 [戻り値]
00186 void
00187 """
00188 if comp == None:
00189 ref = None
00190 comp = {}
00191 comp['id'] = None
00192 comp['kind'] = 'ns'
00193 comp['bname'] = None
00194 else:
00195 ref = comp['objref']
00196 if comp['kind'] == 'rtc':
00197 if not self.dict.has_key(position):
00198
00199 try:
00200 ref = ref._duplicate(ref)
00201 except:
00202 err_mess = 'duplicate exception!!:%s\n' % comp['objref']
00203 except_mess(err_mess)
00204 try:
00205 ref = ref._narrow(RTC.RTObject)
00206 except:
00207 except_mess('SetObjRefToFullPath error!:')
00208 ref = None
00209 if comp['kind'] == 'mgr':
00210 if not self.dict.has_key(position):
00211
00212 try:
00213 ref = ref._duplicate(ref)
00214 except:
00215 ref = None
00216 err_mess = 'duplicate exception!!:%s\n' % comp['objref']
00217 except_mess(err_mess)
00218
00219
00220
00221
00222
00223
00224 self.dict[position] = {}
00225 self.dict[position]['objref'] = ref
00226 self.dict[position]['id'] = comp['id']
00227 self.dict[position]['kind'] = comp['kind']
00228 self.dict[position]['bname'] = comp['bname']
00229
00230
00231 def GetObjRefToFullpathCallback(self, position):
00232 """ディクショナリからオブジェクトリファレンスを取得
00233
00234 [引数]
00235 position -- フルパス指定
00236
00237 [戻り値]
00238 ref -- オブジェクトリファレンス
00239 """
00240
00241 self.ret = None
00242 if self.dict.has_key(position):
00243 ref = self.dict[position]['objref']
00244 else:
00245 print "Error: GetObjRefToFullpath: fullpath error!"
00246 ref = None
00247
00248 self.ret = ref
00249 return ref
00250
00251 def GetKindToFullpathCallback(self, position):
00252 """ディクショナリからKindを取得
00253
00254 [引数]
00255 position -- フルパス指定
00256
00257 [戻り値]
00258 kind -- Kind
00259 """
00260 kind_list = ['ns','host_cxt','mgr_cxt','mgr','cate_cxt','mod_cxt','rtc']
00261
00262 self.ret = None
00263 if self.dict.has_key(position):
00264 kind = self.dict[position]['kind']
00265 else:
00266 print "Error: GetKindToFullpath: fullpath error!"
00267 kind = 'unknown'
00268
00269 if kind not in kind_list:
00270 kind = 'unknown'
00271
00272 self.ret = kind
00273 return kind
00274
00275 def GetIdToFullpathCallback(self, position):
00276 """ディクショナリからIdを取得
00277
00278 [引数]
00279 position -- フルパス指定
00280
00281 [戻り値]
00282 Id -- Id
00283 """
00284
00285 self.ret = None
00286 if self.dict.has_key(position):
00287 Id = self.dict[position]['id']
00288 else:
00289 print "Error: GetIdToFullpath: fullpath error!"
00290 Id = None
00291
00292 self.ret = Id
00293 return Id
00294
00295 def GetBindingNameToFullpath(self, position):
00296 """ディクショナリからBinding_nameを取得
00297
00298 [引数]
00299 position -- フルパス指定
00300
00301 [戻り値]
00302 bname -- binding name
00303 """
00304
00305 self.ret = None
00306 if self.dict.has_key(position):
00307 bname = self.dict[position]['bname']
00308 else:
00309 print "Error: GetBindingNameToFullpath: fullpath error!"
00310 bname = None
00311
00312 self.ret = bname
00313 return bname
00314
00315
00316
00317 class RtmCompData(RtmDictCore):
00318 """ディクショナリのアクセス・クラス(ラッパー?)
00319 ここに、ディクショナリを使用するラッパーメソッドを記述する
00320 """
00321 def __init__(self, parent):
00322 """クラスの初期化
00323
00324
00325 [引数]
00326 parent -- 親クラス
00327
00328 [戻り値]
00329 void
00330 """
00331 RtmDictCore.__init__(self,parent)
00332 self.parent = parent
00333 self.Mutex = mutex.mutex()
00334
00335 def GetCompStateCallback(self,fullpath):
00336 self.ret2 = 0
00337 tmp = 0
00338 try:
00339 ref = self.GetObjRefToFullpathCallback(fullpath)
00340 ref = ref._narrow(RTC.RTObject)
00341 except :
00342 err_mess = 'GetCompState: obj-ref error:%s\n' % fullpath
00343 except_mess(err_mess)
00344 tmp = 0
00345 self.ret2 = 0
00346 return
00347 try:
00348 tmp_port = ref._get_rtc_state()
00349 tmp_port = tmp_port._narrow(OutPort)
00350 tmp = tmp_port.get()
00351 tmp = tmp.value()
00352 tmp = tmp.data
00353 print "refresh state:",tmp
00354 except :
00355 err_mess = 'GetCompState: rtc_state error:%s\n' % fullpath
00356 except_mess(err_mess)
00357
00358 tmp = 0
00359
00360 self.ret2 = tmp
00361 return tmp
00362
00363 def GetCompState(self,fullpath):
00364 self.Mutex.lock(self.GetCompStateCallback,fullpath)
00365 self.Mutex.unlock()
00366 return self.ret2
00367
00368 def GetCompNameCallback(self,fullpath):
00369 self.ret2 = ''
00370 key_list = self.SplitTokenToFullpath(fullpath)
00371 num = len(key_list)
00372
00373 self.ret2 = key_list[num-1]
00374 num = self.ret2.find('|')
00375 self.ret2 = str(self.ret2[0:num])
00376 return self.ret2
00377
00378 def GetCompName(self,fullpath):
00379 self.Mutex.lock(self.GetCompNameCallback,fullpath)
00380 self.Mutex.unlock()
00381 return self.ret2
00382
00383 def GetCateNameCallback(self,fullpath):
00384 self.ret2 = ''
00385 key_list = self.SplitTokenToFullpath(fullpath)
00386 num = len(key_list)
00387
00388 for cate_str in key_list:
00389 num = cate_str.find('|')
00390 if num > 0:
00391 if str(cate_str[num+1:]) == 'cate_cxt':
00392 self.ret2 = str(cate_str[0:num])
00393 return self.ret2
00394
00395 def GetCateName(self,fullpath):
00396 self.Mutex.lock(self.GetCateNameCallback,fullpath)
00397 self.Mutex.unlock()
00398 return self.ret2
00399
00400 def GetObjRefToFullpath(self, position):
00401 self.Mutex.lock(self.GetObjRefToFullpathCallback,position)
00402 self.Mutex.unlock()
00403 return self.ret
00404
00405 def GetInPortToRef(self, fullpath):
00406 self.Mutex.lock(self.GetInPortToRefCallback,fullpath)
00407 self.Mutex.unlock()
00408 return self.retlist
00409
00410 def GetOutPortToRef(self, fullpath):
00411 self.Mutex.lock(self.GetOutPortToRefCallback,fullpath)
00412 self.Mutex.unlock()
00413 return self.retlist
00414
00415 def TreeListCompStartCallback(self,fullpath):
00416 """TreeList上のコンポーネントをスタート
00417 ※SystemDraw用のメソッドと統廃合する可能性あり
00418
00419 [引数]
00420 fullpath -- フルパス指定
00421
00422 [戻り値]
00423 void
00424 """
00425 self.ret2 = RTM_OK
00426 ret = RTM_OK
00427 ref = self.GetObjRefToFullpathCallback(fullpath)
00428 try:
00429 ref = ref._narrow(RTC.RTObject)
00430 ret = ref.rtc_start()
00431 if ret != RTM_OK:
00432 print "Error rtc_start(): ",fullpath
00433 except:
00434 except_mess('rtc_start error!:%s\n'%fullpath)
00435 ret = RTM_ERR
00436
00437
00438
00439 for sys_no in self.parent.drawWin.keys():
00440 self.parent.drawWin[sys_no].changeCompColor(fullpath, 'active')
00441
00442
00443 self.ret2 = ret
00444 return ret
00445
00446 def TreeListCompStart(self,fullpath):
00447 self.Mutex.lock(self.TreeListCompStartCallback,fullpath)
00448 self.Mutex.unlock()
00449 return self.ret2
00450
00451 def TreeListCompStopCallback(self,fullpath):
00452 """TreeList上のコンポーネントをストップ
00453 ※SystemDraw用のメソッドと統廃合する可能性あり
00454
00455 [引数]
00456 fullpath -- フルパス指定
00457
00458 [戻り値]
00459 void
00460 """
00461 self.ret2 = RTM_OK
00462 ret = RTM_OK
00463 ref = self.GetObjRefToFullpathCallback(fullpath)
00464 try:
00465 ref = ref._narrow(RTC.RTObject)
00466 ret = ref.rtc_stop()
00467 if ret != RTM_OK:
00468 print "Error rtc_stop(): ",fullpath
00469 except:
00470 except_mess('rtc_stop error!:%s\n'%fullpath)
00471 ret = RTM_ERR
00472
00473 for sys_no in self.parent.drawWin.keys():
00474 self.parent.drawWin[sys_no].changeCompColor(fullpath, 'inactive')
00475
00476 self.ret2 = ret
00477 return ret
00478
00479 def TreeListCompStop(self,fullpath):
00480 self.Mutex.lock(self.TreeListCompStopCallback,fullpath)
00481 self.Mutex.unlock()
00482 return self.ret2
00483
00484 def TreeListCompResetCallback(self,fullpath):
00485 """TreeList上のコンポーネントをリセット
00486 ※SystemDraw用のメソッドと統廃合する可能性あり
00487
00488 [引数]
00489 fullpath -- フルパス指定
00490
00491 [戻り値]
00492 void
00493 """
00494 self.ret2 = RTM_OK
00495 ret = RTM_OK
00496 ref = self.GetObjRefToFullpathCallback(fullpath)
00497 try:
00498 ref = ref._narrow(RTC.RTObject)
00499 ret = ref.rtc_reset()
00500 if ret != RTM_OK:
00501 print "Error rtc_reset(): ",fullpath
00502 except:
00503 except_mess('rtc_reset error!:%s\n'%fullpath)
00504 ret = RTM_ERR
00505
00506 for sys_no in self.parent.drawWin.keys():
00507 self.parent.drawWin[sys_no].changeCompColor(fullpath, 'inactive')
00508
00509
00510 self.ret2 = ret
00511 return ret
00512
00513 def TreeListCompReset(self,fullpath):
00514 self.Mutex.lock(self.TreeListCompResetCallback,fullpath)
00515 self.Mutex.unlock()
00516 return self.ret2
00517
00518 def TreeListCompExitCallback(self,fullpath):
00519 """TreeList上のコンポーネントをExit
00520 ※SystemDraw用のメソッドと統廃合する可能性あり
00521
00522 [引数]
00523 fullpath -- フルパス指定
00524
00525 [戻り値]
00526 void
00527 """
00528 self.ret2 = RTM_OK
00529 ret = RTM_OK
00530 ref = self.GetObjRefToFullpathCallback(fullpath)
00531 try:
00532 ref = ref._narrow(RTC.RTObject)
00533 ret = ref.rtc_exit()
00534 if ret != RTM_OK:
00535 print "Error rtc_exit(): ",fullpath
00536 except:
00537 except_mess('rtc_exit error!:%s\n'%fullpath)
00538 ret = RTM_ERR
00539
00540 for sys_no in self.parent.drawWin.keys():
00541 self.parent.drawWin[sys_no].changeCompColor(fullpath, 'inactive')
00542
00543
00544 self.ret2 = ret
00545 return ret
00546
00547 def TreeListCompExit(self,fullpath):
00548 self.Mutex.lock(self.TreeListCompExitCallback,fullpath)
00549 self.Mutex.unlock()
00550 return self.ret2
00551
00552 def TreeListCompKillCallback(self,fullpath):
00553 """TreeList上のコンポーネントをkill
00554 ※SystemDraw用のメソッドと統廃合する可能性あり
00555
00556 [引数]
00557 fullpath -- フルパス指定
00558
00559 [戻り値]
00560 void
00561 """
00562 self.ret2 = RTM_OK
00563 ret = RTM_OK
00564 ref = self.GetObjRefToFullpathCallback(fullpath)
00565 try:
00566 ref = ref._narrow(RTC.RTObject)
00567 ret = ref.rtc_kill()
00568 if ret != RTM_OK:
00569 print "Error rtc_kill(): ",fullpath
00570 except:
00571 except_mess('rtc_kill error!:%s\n'%fullpath)
00572 ret = RTM_ERR
00573
00574 for sys_no in self.parent.drawWin.keys():
00575 self.parent.drawWin[sys_no].changeCompColor(fullpath, 'inactive')
00576
00577
00578 self.ret2 = ret
00579 return ret
00580
00581 def TreeListCompKill(self,fullpath):
00582 self.Mutex.lock(self.TreeListCompKillCallback,fullpath)
00583 self.Mutex.unlock()
00584 return self.ret2
00585
00586 def GetIdToFullpath(self,fullpath):
00587 self.Mutex.lock(self.GetIdToFullpathCallback,fullpath)
00588 self.Mutex.unlock()
00589 return self.ret
00590
00591 def GetKindToFullpath(self,fullpath):
00592 self.Mutex.lock(self.GetKindToFullpathCallback,fullpath)
00593 self.Mutex.unlock()
00594 return self.ret
00595
00596 def setCompBodyColor(self,fullpath, state):
00597 for sys_no in self.parent.drawWin.keys():
00598 self.parent.drawWin[sys_no].changeCompColor(fullpath,state)