From: <umg...@us...> - 2007-07-10 13:53:29
|
Revision: 466 http://svn.sourceforge.net/pybridge/?rev=466&view=rev Author: umgangee Date: 2007-07-10 06:53:31 -0700 (Tue, 10 Jul 2007) Log Message: ----------- Encapsulate TableClient view reference within the state dict provided by LocalTable:getStateToCacheAndObserveFor() and consumed by RemoteTable:setCopyableState(), instead of passing it alongside the table reference. Modified Paths: -------------- trunk/pybridge/pybridge/network/client.py trunk/pybridge/pybridge/network/localtable.py trunk/pybridge/pybridge/network/remotetable.py trunk/pybridge/pybridge/server/user.py Modified: trunk/pybridge/pybridge/network/client.py =================================================================== --- trunk/pybridge/pybridge/network/client.py 2007-07-09 15:40:59 UTC (rev 465) +++ trunk/pybridge/pybridge/network/client.py 2007-07-10 13:53:31 UTC (rev 466) @@ -173,8 +173,7 @@ def joinTable(self, tableid, host=False): - def success((table, remote)): - table.master = remote # Set RemoteReference for RemoteBridgeTable. + def success(table): self.tables[tableid] = table self.notify('joinTable', tableid=tableid, table=table) return table Modified: trunk/pybridge/pybridge/network/localtable.py =================================================================== --- trunk/pybridge/pybridge/network/localtable.py 2007-07-09 15:40:59 UTC (rev 465) +++ trunk/pybridge/pybridge/network/localtable.py 2007-07-10 13:53:31 UTC (rev 466) @@ -40,6 +40,27 @@ info = property(lambda self: {'game': self.gametype.__name__}) + class TableClient(pb.Viewable): + """Provides a public front-end to an instantiated LocalTable. + + Serialization flavors are mutually exclusive and cannot be mixed, + so this class is a subclass of pb.Viewable. + """ + + + def __init__(self, table): + self.__table = table + + + def view_joinGame(self, user, position): + # TODO: return a deferred? + return self.__table.joinGame(user, position) + + + def view_leaveGame(self, user, position): + return self.__table.leaveGame(user, position) + + def __init__(self, id, gametype, config={}): self.listeners = [] @@ -51,7 +72,7 @@ self.observers = {} # For each user perspective, a remote ITableEvents. self.players = {} # Positions mapped to perspectives of game players. - self.view = LocalTableViewable(self) # For remote clients. + self.view = self.TableClient(self) # For remote clients. # Configuration variables. self.config = {} @@ -75,6 +96,7 @@ state['observers'] = [p.name for p in self.observers.keys()] state['players'] = dict([(pos, p.name) for pos, p in self.players.items()]) + state['view'] = self.view return state # To observer. @@ -163,30 +185,3 @@ del self.players[position] self.notify('leaveGame', player=user.name, position=position) - - - -class LocalTableViewable(pb.Viewable): - """Provides a public front-end to an instantiated LocalTable. - - Serialization flavors are mutually exclusive and cannot be mixed, - so this class is a subclass of pb.Viewable. - """ - - - def __init__(self, table): - """ - - @param table: a instantiated LocalTable. - """ - self.__table = table - - - def view_joinGame(self, user, position): - # TODO: return a deferred? - return self.__table.joinGame(user, position) - - - def view_leaveGame(self, user, position): - return self.__table.leaveGame(user, position) - Modified: trunk/pybridge/pybridge/network/remotetable.py =================================================================== --- trunk/pybridge/pybridge/network/remotetable.py 2007-07-09 15:40:59 UTC (rev 465) +++ trunk/pybridge/pybridge/network/remotetable.py 2007-07-10 13:53:31 UTC (rev 466) @@ -43,19 +43,10 @@ info = property(lambda self: {'game': self.gametype.__name__}) - # TODO: is there any need for this initialisation? def __init__(self): - self.master = None # Server-side ITable object. self.listeners = [] - self.id = None - self.chat = None - self.game = None - self.gametype = None - self.observers = [] # Observers of master table. - self.players = {} # Positions mapped to player identifiers. - def setCopyableState(self, state): self.id = state['id'] if state['gametype'] in GAMETYPES: @@ -70,18 +61,19 @@ self.players = state['players'] for position in self.players: self.game.addPlayer(position) + self.__view = state['view'] # Implementation of ITable. def joinGame(self, position, user=None): - d = self.master.callRemote('joinGame', position) + d = self.__view.callRemote('joinGame', position) return d def leaveGame(self, position, user=None): - d = self.master.callRemote('leaveGame', position) + d = self.__view.callRemote('leaveGame', position) return d Modified: trunk/pybridge/pybridge/server/user.py =================================================================== --- trunk/pybridge/pybridge/server/user.py 2007-07-09 15:40:59 UTC (rev 465) +++ trunk/pybridge/pybridge/server/user.py 2007-07-10 13:53:31 UTC (rev 466) @@ -100,8 +100,7 @@ table = self.server.tables[tableid] self.tables[tableid] = table - # Returning table reference creates a RemoteTable object on client. - return table, table.view + return table def perspective_leaveTable(self, tableid): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |