def server_create_command_services(): pydim.dis_add_cmnd('test1', CMND1FORMAT, dummy, 1) SAY('Added command test1 with DIM format %s' %CMND1FORMAT) pydim.dis_add_cmnd('test2', CMND2FORMAT, MyClass().dummy, 2) SAY('Added command test2 with DIM format %s' %CMND2FORMAT) pydim.dis_add_cmnd('test3', CMND3FORMAT, dummy, 2) SAY('Added command test3 with DIM format %s' %CMND3FORMAT) pydim.dis_start_serving()
def server_create_command_services(): #adding the first command pydim.dis_add_cmnd('test1', CMND1FORMAT, dummy, 1) SAY('Added command test1 with DIM format %s' % CMND1FORMAT) #adding the second command pydim.dis_add_cmnd('test2', CMND2FORMAT, MyClass().dummy, 2) SAY('Added command test2 with DIM format %s' % CMND2FORMAT) #adding the third command pydim.dis_add_cmnd('test3', CMND3FORMAT, dummy, 2) SAY('Added command test3 with DIM format %s' % CMND3FORMAT) #starting DIM pydim.dis_start_serving()
def run(self): dis_start_serving(self.name) print self.clients for x in self.clients: DEBUG("DIMTASK %s : Registering to service %s" % (self.name, DimTask.SRV1NAME + x)) dic_info_service(DimTask.SRV1NAME + x, DimTask.SRV1FORMAT, self.client_callback1) DEBUG("DIMTASK %s : Registering to service %s" % (self.name, DimTask.SRV2NAME + x)) dic_info_service(DimTask.SRV2NAME + x, DimTask.SRV2FORMAT, self.client_callback2) DEBUG("DIMTASK %s : Registering to service %s" % (self.name, DimTask.SRV3NAME + x)) dic_info_service(DimTask.SRV3NAME + x, DimTask.SRV3FORMAT, self.client_callback3) counter = 0 DEBUG("DIMTASK %s : Starting service update " % self.name) while counter < self.updates: counter += 1 SAY("DIMTASK %s : Updating service nr. 1" % self.name) values = (counter, counter + 1, 999.0, 999.0, 'BAU', 'B') SAY('DIMTASK %s : Updated %d clients' % (self.name, dis_update_service(self.svc1, values))) SAY("DIMTASK %s : Updating service nr. 2" % self.name) values = (counter, ) SAY('DIMTASK %s : Updated %d clients' \ %(self.name, dis_update_service(self.svc2, values))) SAY("DIMTASK %s : Updating service nr. 3" % self.name) values = ('ALABALAP\x00ORTOCALA', ) SAY('DIMTASK %s : Updated %d clients' \ %(self.name, dis_update_service(self.svc3, values))) sleep(DimTask.DELAY) dis_stop_serving()
def client_callback(tag, ret): SAY('The client callback function has received tag %d and return code %d' % (tag, ret))
def dummy(self, *args): SAY( "Server: I am dummy func bound to a 'MyClass' instance. I\'ve received", args)
def dummy(*args): SAY('Server: I am an unbound dummy function. I\'ve received', args)
if __name__ == '__main__': # Server configuration: server_create_command_services() #The client command execution counter = 0 while counter < 1000 or True: counter += 1 print('\n\n' + 80 * '-') print('Iteration number %d' % counter) # executing the first command tuple_args = ('Test call no. %03d' % counter, ) res = pydim.dic_cmnd_callback('test1', tuple_args, CMND1FORMAT, client_callback, 1) if res: SAY('Client: Successfully executed command test1 (return code %d)' % res) else: SAY('Client: Command test1 execution failed (return code %d)' % res) sleep(COMMAND_DELAY) print # second command tuple_args = (counter, counter + 1, counter * 9, counter * 1.9, counter, counter - 1, 'ABRACADABRA') res = pydim.dic_cmnd_callback('test2', tuple_args, CMND2FORMAT, client_callback, 2) if res: SAY('Client: Successfully executed command test2 (return code %d)' % res) else:
def client_callback1(self, *args): SAY('DIMTASK %s : client callback called for service1. Args are %s' % (self.name, args))