def _set_money( self, money ): try: CORBA.id(money) currency = getCurrency(money.currencyCode) m = Money(0, currency) m._setState(money.amount, currency) money = m except CORBA.BAD_PARAM: pass self._money = money
def con_evfn(batch, objnm, idx, num_events, num_batches, verbose): "consume an any, verify it contains the appropriate MyUnTest value" # initialize consume stats for idx, if necessary if (not con_valid.has_key(idx)): con_valid[idx] = 0 if (not con_total.has_key(idx)): con_total[idx] = 0 # the rest of the consume method if (len(batch) != 1): print "Internal Error (?): any consumer should not get an event batch" # process like a batch regardless for a in batch: con_total[idx] += 1 v = a.value(CORBA.TypeCode(CORBA.id(MyUnType))) if (v == None): if (verbose > 0): print objnm, ": con_evfn: unexpected non-union value consumed" break if (verbose > 0): print objnm, ": con_evfn: consumed union value", v._v if (v._d != MyUnTest.e5): if (verbose > 0): print objnm, ": con_evfn: wrong discriminator value" elif (v._v != Sup_Any_MyUnType.match_long): if (verbose > 0): print objnm, ': con_evfn: value (', v._v, ') != match_long (', Sup_Any_MyUnType.match_long, ')' else: con_valid[idx] += 1
def create( self, money): try: CORBA.id(money) currency = getCurrency(money.currencyCode) m = Money(money.amount, currency) money = m except CORBA.BAD_PARAM: pass pk = '%.5f' % time() moneyWidget = MoneyWidget(pk) moneyWidget._set_money(money) self.PersistenceService.create(moneyWidget) # Notify our observers that a new entity has been created #self._notifyCreate(moneyWidget) return moneyWidget
def close(self, evt): if self.toplevel: self.toplevel = None try: self.game.unwatchGame(self.cookie) except CORBA.SystemException, ex: print "System exception trying to unwatch game:" print " ", CORBA.id(ex), ex id = poa.servant_to_id(self) poa.deactivate_object(id)
def constructDefaultType(typeobj): if isinstance(typeobj, CORBA.TypeCode): tc = typeobj else: tc = CORBA.TypeCode(CORBA.id(typeobj)) kind = tc.kind() if kind == CORBA.tk_alias: return constructDefaultType(tc.content_type()) if kind == CORBA.tk_struct: # This is sort-of-dependent on omniORB implementation details, but # findType() is public by Python convention. It returns a tuple with # details of the type, but here we only need the class object. typeobj = omniORB.findType(tc.id())[1] args = [ constructDefaultType(tc.member_type(idx)) for idx in range(tc.member_count()) ] return typeobj(*args) if kind == CORBA.tk_enum: # As with above, an implementation detail. The last element of the # type details is the list values; return the first. return omniORB.findType(tc.id())[-1][0] if kind == CORBA.tk_union: # See comment in struct branch. typeobj = omniORB.findType(tc.id())[1] index = tc.default_index() if index < 0: index = tc.member_count() + index kwds = {} kwds[tc.member_name(index)] = constructDefaultType( tc.member_type(index)) return typeobj(**kwds) if kind == CORBA.tk_string: return str() if kind in (CORBA.tk_float, CORBA.tk_double): return float() if kind in (CORBA.tk_octet, CORBA.tk_short, CORBA.tk_ushort, CORBA.tk_long, CORBA.tk_boolean): return int() if kind in (CORBA.tk_ulong, CORBA.tk_longlong, CORBA.tk_ulonglong): return long() if kind == CORBA.tk_char: return '\x00' if kind == CORBA.tk_sequence: return [] if kind == CORBA.tk_any: return CORBA.Any(CORBA.TC_null, None) if kind == CORBA.tk_objref: return None raise NotImplementedError, tc
def killGame(self): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] try: info.obj.kill() msg = "killed" except CORBA.SystemException, ex: print "System exception trying to kill game:" print " ", CORBA.id(ex), ex msg = "error contacting object"
def publishEvent (self, simple_data=None, type_name=None, event_name="", se=None, supplier_name=None): ''' publishEvent is the one method developers have to use. Params: - simple_data is a user-defined IDL struct. If this parameter is not specified by the developer, se MUST be used. 99% of the time developers should specify the simple_data parameter and NOTHING ELSE! - type_name is literally the type_name field of a structured event. This is an optional parameter and should not be specified under normal circumstances. If unspecified, the name of the simple_data object is used. - event_name is the event_name field of the structured event. Not really useful. - se is a fully-defined structured event. If this parameter is specified, all other parameters will be completely ignored. A check is made to ensure that this object is really what it claims to be. This parameter is reserved for ACS internal usage. - suppier_name is the name of the supplier publishing the event. This parameter is reserved for ACS internal usage. Returns: Nothing Raises: - ACSErrTypeCommonImpl.CORBAProblemExImpl - ACSErrTypeCommonImpl.CouldntPerformActionExImpl - ACSErrTypeCommonImpl.TypeNotSupportedExImpl ''' #Whoah, user passed in the entire structured event...I'm impressed. if se != None: Supplier.publishEvent(simple_data,type_name,event_name,se, supplier_name) #User didn't specify type_name. Assume it's the name of the #repository ID. If that doesn't work either, must be a simple #CORBA type. if (type_name == None) and (simple_data != None): try: type_name = str(simple_data.__class__.__name__) except Exception, e: self.logger.logWarning(str(e)) print_exc() type_name = str(CORBA.id(simple_data))
def getGameList(self): """Get the list of games from the GameFactory, and populate the Listbox in the GUI""" # To make life interesting, we get the game information # structures one at a time from the server. It would be far # more sensible to get them many at a time. self.gameList = [] self.listbox.delete(0, END) try: seq, iterator = self.gameFactory.listGames(0) except CORBA.SystemException, ex: print "System exception contacting GameFactory:" print " ", CORBA.id(ex), ex return
def sup_evfn(objnm, idx, bsize, num_events, num_batches, verbose): "supply an any containing a MyUnType value" # initialize supply stats for idx, if necessary if (not sup_total.has_key(idx)): sup_total[idx] = 0 # the rest of the supply method batch = [] while (len(batch) < bsize): if (verbose > 0): print objnm, ": supplying event #", num_events counter = sup_total[idx] % 10 sup_total[idx] += 1 num_events += 1 if (counter == 0): u = MyUnType(e0_ar5=__str_array1) elif (counter == 1): u = MyUnType(e0_ar5=__str_array2) elif (counter == 2): u = MyUnType(e2_str=match_str) elif (counter == 3): u = MyUnType(e2_str='NOT ' + match_str) elif (counter == 4): u = MyUnType(e5_l=match_long) elif (counter == 5): u = MyUnType(e5_l=match_long + 1) elif (counter == 6): u = MyUnType(e6_s=match_short) elif (counter == 7): u = MyUnType(e6_s=match_short + 1) elif (counter == 8): u = MyUnType(def_b=match_bool) elif (counter == 9): u = MyUnType(def_b=not_match_bool) tc = CORBA.TypeCode(CORBA.id(MyUnType)) a = CORBA.Any(tc, u) if (verbose > 0): print objnm, ": sup_evfn: union value _d = ", u._d print objnm, ": sup_evfn: union value _v = ", u._v print objnm, ": sup_evfn: any value has typecode kind =", a.typecode( ).kind() print objnm, ": sup_evfn: any value =", a.value(a.typecode()) batch.append(a) return batch
def sup_evfn(objnm, idx, bsize, num_events, num_batches, verbose): "supply an any containing a MyStTest.MySt value" # initialize supply stats for idx, if necessary if (not sup_total.has_key(idx)): sup_total[idx] = 0 # the rest of the supply method batch = [] while (len(batch) < bsize): if (verbose > 0): print objnm, ": supplying event #", num_events vs = MySt(num_events) tc = CORBA.TypeCode(CORBA.id(MySt)) a = CORBA.Any(tc, vs) sup_total[idx] += 1 num_events += 1 if (verbose > 0): print objnm, ": sup_evfn: supplying MySt with ul = ", vs.ul batch.append(a) return batch
def click(self, evt): x = evt.x / 100 y = evt.y / 100 try: self.statusMessage("Waiting for other player...") state = self.controller.play(x, y) self.drawState(state) except TicTacToe.GameController.SquareOccupied: self.statusMessage("Square already occupied") except TicTacToe.GameController.NotYourGo: self.statusMessage("Not your go") except TicTacToe.GameController.InvalidCoordinates: self.statusMessage("Eek! Invalid coordinates") except CORBA.SystemException: print "System exception trying to contact GameController:" print " ", CORBA.id(ex), ex self.statusMessage("System exception contacting GameController!")
def newGameEntered(self, evt): name = evt.widget.get() self.newGameDialogue.destroy() self.newGameDialogue = None if name == "": self.statusMessage("You must give a non-empty name") return try: game = self.gameFactory.newGame(name) except TicTacToe.GameFactory.NameInUse: self.statusMessage("Game name in use") return except CORBA.SystemException, ex: print "System exception trying to create new game:" print " ", CORBA.id(ex), ex self.statusMessage("System exception trying to create new game") return
def selectGame(self, evt): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] try: players = info.obj._get_players() if players == 0: msg = "no players yet" elif players == 1: msg = "one player waiting" else: msg = "game in progress" except CORBA.SystemException, ex: print "System exception contacting Game:" print " ", CORBA.id(ex), ex msg = "error contacting Game object"
def watchGame(self): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] si = Spectator_i(self.master, info.name) id = poa.activate_object(si) so = poa.id_to_reference(id) try: cookie, state = info.obj.watchGame(so) si.go(info.obj, cookie, state) self.statusMessage("Watching %s" % info.name) except CORBA.SystemException, ex: poa.deactivate_object(id) print "System exception trying to watch game:" print " ", CORBA.id(ex), ex self.statusMessage("%s: system exception contacting game" % info.name) self.getGameList()
else: raise TypeNotSupportedExImpl(nvSeq=[NameValue("channelname", self.channelName), NameValue("reason", "Not a structured event")]) #User didn't specify type_name. Assume it's the name of the #repository ID. If that doesn't work either, must be a simple #CORBA type. if (type_name == None) and (simple_data != None): try: type_name = str(simple_data.__class__.__name__) except Exception, e: self.logger.logWarning(str(e)) print_exc() type_name = str(CORBA.id(simple_data)) elif (simple_data == None): raise CouldntPerformActionExImpl(nvSeq=[NameValue("channelname", self.channelName), NameValue("reason", "Empty data")]) #create the CORBA Any in the "normal" manner first. If this #fails, try omniORB's any helper module designed for simple types. try: corba_any = CORBA.Any(CORBA.TypeCode(CORBA.id(simple_data)), simple_data) except Exception, e: self.logger.logTrace(str(e)) try: corba_any = any.to_any(simple_data)
poa.create_request_processing_policy(PortableServer.USE_SERVANT_MANAGER), poa.create_lifespan_policy(PortableServer.PERSISTENT)] child = poa.create_POA("MyPOA", poaManager, ps) # Create the ServantActivator and set it as the child's ServantManager # Note that since ServantActivator is a LocalObject, we do not need to # activate the servant in a POA. sai = ServantActivator_i() child.set_servant_manager(sai) del sai # Create an object reference with no servant eo = child.create_reference_with_id("MyEcho", CORBA.id(_GlobalIDL.Echo)) print orb.object_to_string(eo) # Run, or do some local calls... if not (len(sys.argv) > 1 and sys.argv[1] == "-l"): orb.run() time.sleep(1) print "Calling..." # On this invocation, the servant will be activated print eo.echoString("Hello from same address space") time.sleep(1) # This invocation uses the local case optimisation, since the servant
else: raise TypeNotSupportedExImpl(nvSeq=[ NameValue("channelname", self.channelName), NameValue("reason", "Not a structured event") ]) #User didn't specify type_name. Assume it's the name of the #repository ID. If that doesn't work either, must be a simple #CORBA type. if (type_name == None) and (simple_data != None): try: type_name = str(simple_data.__class__.__name__) except Exception, e: self.logger.logWarning(str(e)) print_exc() type_name = str(CORBA.id(simple_data)) elif (simple_data == None): raise CouldntPerformActionExImpl(nvSeq=[ NameValue("channelname", self.channelName), NameValue("reason", "Empty data") ]) #create the CORBA Any in the "normal" manner first. If this #fails, try omniORB's any helper module designed for simple types. try: corba_any = CORBA.Any(CORBA.TypeCode(CORBA.id(simple_data)), simple_data) except Exception, e: self.logger.logTrace(str(e)) try: corba_any = any.to_any(simple_data)
stype = "noughts" else: stype = "crosses" pi.go(info.obj, controller, stype) self.statusMessage("%s: joined game as %s" % (info.name, stype)) except TicTacToe.Game.CannotJoin, ex: poa.deactivate_object(id) self.statusMessage("%s: cannot join game" % info.name) except CORBA.SystemException, ex: poa.deactivate_object(id) print "System exception trying to join game:" print " ", CORBA.id(ex), ex self.statusMessage("%s: system exception contacting game" % info.name) self.getGameList() def watchGame(self): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] si = Spectator_i(self.master, info.name) id = poa.activate_object(si) so = poa.id_to_reference(id) try: