def global_init_serializer(init): """Global Init Message serializer.""" serializer = sl_global_pb2.SLInitMsg() if 'major' in init: serializer.MajorVer = init['major'] if 'minor' in init: serializer.MinorVer = init['minor'] if 'sub_ver' in init: serializer.SubVer = init['sub_ver'] return serializer
def client_init(self, stub, event): # # Create SLInitMsg to handshake the version number with the server. # The Server will allow/deny access based on the version number. # The same RPC is used to setup a notification channel for global # events coming from the server. # # # Set the client version number based on the current proto files' version init_msg = sl_global_pb2.SLInitMsg() init_msg.MajorVer = sl_version_pb2.SL_MAJOR_VERSION init_msg.MinorVer = sl_version_pb2.SL_MINOR_VERSION init_msg.SubVer = sl_version_pb2.SL_SUB_VERSION # Set a very large timeout, as we will "for ever" loop listening on # notifications from the server Timeout = 365 * 24 * 60 * 60 # Seconds #Timeout = 5 while True: # This for loop will never end unless the server closes the session for response in stub.SLGlobalInitNotif(init_msg, Timeout): if response.EventType == sl_global_pb2.SL_GLOBAL_EVENT_TYPE_VERSION: if (sl_common_types_pb2.SLErrorStatus.SL_SUCCESS == response.ErrStatus.Status) or \ (sl_common_types_pb2.SLErrorStatus.SL_INIT_STATE_CLEAR == response.ErrStatus.Status) or \ (sl_common_types_pb2.SLErrorStatus.SL_INIT_STATE_READY == response.ErrStatus.Status): print("Server Returned 0x%x, Version %d.%d.%d" % (response.ErrStatus.Status, response.InitRspMsg.MajorVer, response.InitRspMsg.MinorVer, response.InitRspMsg.SubVer)) print( "Successfully Initialized, connection established!" ) # Any thread waiting on this event can proceed event.set() else: print("client init error code 0x%x", response.ErrStatus.Status) sys.exit(0) elif response.EventType == sl_global_pb2.SL_GLOBAL_EVENT_TYPE_HEARTBEAT: print("Received HeartBeat") elif response.EventType == sl_global_pb2.SL_GLOBAL_EVENT_TYPE_ERROR: if (sl_common_types_pb2.SLErrorStatus.SL_NOTIF_TERM == response.ErrStatus.Status): print("Received notice to terminate. Client Takeover?") sys.exit(0) else: print("Error not handled:", response) else: print("client init unrecognized response %d", response.EventType) sys.exit(0)