From 8d47f6890d31d1eac483249de99c846f59366c60 Mon Sep 17 00:00:00 2001 From: Teddy Date: Thu, 22 Aug 2013 20:25:12 +0800 Subject: ... --- server/piztor_server.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'server') diff --git a/server/piztor_server.py b/server/piztor_server.py index 3809f22..4845748 100644 --- a/server/piztor_server.py +++ b/server/piztor_server.py @@ -26,7 +26,7 @@ class DataManager(object): pass class UserManager(DataManager): - def handle(self, opt_type, data): + def authentication_handle(self, opt_type, data): print "Parsing User Data" pos = -1 for i in xrange(0, len(data)): @@ -45,7 +45,7 @@ class UserManager(DataManager): class MesgManager(DataManager): - def handle(self, opt_type, data): + def mesg_sending_handle(self, opt_type, data): print "Parsing Mesg Data" try: if len(data) < 8: @@ -58,7 +58,7 @@ class MesgManager(DataManager): raise ReqInvalidError() class LocationManager(DataManager): - def handle(self, opt_type, data): + def location_update_handle(self, opt_type, data): print "Parsing Loc Data" try: if len(data) < 8: @@ -73,9 +73,13 @@ class LocationManager(DataManager): class PiztorServer(): - mgr_map = [ UserManager(), - MesgManager(), - LocationManager() ] + user_mgr = UserManager() + mesg_mgr = MesgManager() + location_mgr = LocationManager() + + mgr_map = [ user_mgr.authentication_handle, + mesg_mgr.mesg_sending_handle, + location_mgr.location_update_handle ] class GenericHandler(SocketServer.StreamRequestHandler): @@ -101,8 +105,7 @@ class PiztorServer(): if len(data) < 1: raise ReqInvalidError() opt_id = struct.unpack("!B", data[0])[0] - reply = PiztorServer.mgr_map[opt_id].handle( - opt_id, data[1:]) + reply = PiztorServer.mgr_map[opt_id](opt_id, data[1:]) sock.sendall(reply) sock.close() -- cgit v1.2.3-70-g09d2