updates to allow new gui to recreate session to continue where it left off
This commit is contained in:
parent
f2da8dc2c9
commit
c4234d33f0
4 changed files with 60 additions and 9 deletions
|
@ -262,6 +262,16 @@ class CoreGrpcClient:
|
||||||
"""
|
"""
|
||||||
return self.stub.GetSessions(core_pb2.GetSessionsRequest())
|
return self.stub.GetSessions(core_pb2.GetSessionsRequest())
|
||||||
|
|
||||||
|
def check_session(self, session_id: int) -> core_pb2.CheckSessionResponse:
|
||||||
|
"""
|
||||||
|
Check if a session exists.
|
||||||
|
|
||||||
|
:param session_id: id of session to check for
|
||||||
|
:return: response with result if session was found
|
||||||
|
"""
|
||||||
|
request = core_pb2.CheckSessionRequest(session_id=session_id)
|
||||||
|
return self.stub.CheckSession(request)
|
||||||
|
|
||||||
def get_session(self, session_id: int) -> core_pb2.GetSessionResponse:
|
def get_session(self, session_id: int) -> core_pb2.GetSessionResponse:
|
||||||
"""
|
"""
|
||||||
Retrieve a session.
|
Retrieve a session.
|
||||||
|
|
|
@ -453,6 +453,19 @@ class CoreGrpcServer(core_pb2_grpc.CoreApiServicer):
|
||||||
session.metadata = dict(request.config)
|
session.metadata = dict(request.config)
|
||||||
return core_pb2.SetSessionMetadataResponse(result=True)
|
return core_pb2.SetSessionMetadataResponse(result=True)
|
||||||
|
|
||||||
|
def CheckSession(
|
||||||
|
self, request: core_pb2.GetSessionRequest, context: ServicerContext
|
||||||
|
) -> core_pb2.CheckSessionResponse:
|
||||||
|
"""
|
||||||
|
Checks if a session exists.
|
||||||
|
|
||||||
|
:param request: check session request
|
||||||
|
:param context: context object
|
||||||
|
:return: check session response
|
||||||
|
"""
|
||||||
|
result = request.session_id in self.coreemu.sessions
|
||||||
|
return core_pb2.CheckSessionResponse(result=result)
|
||||||
|
|
||||||
def GetSession(
|
def GetSession(
|
||||||
self, request: core_pb2.GetSessionRequest, context: ServicerContext
|
self, request: core_pb2.GetSessionRequest, context: ServicerContext
|
||||||
) -> core_pb2.GetSessionResponse:
|
) -> core_pb2.GetSessionResponse:
|
||||||
|
|
|
@ -58,7 +58,7 @@ class CoreClient:
|
||||||
"""
|
"""
|
||||||
Create a CoreGrpc instance
|
Create a CoreGrpc instance
|
||||||
"""
|
"""
|
||||||
self.client = client.CoreGrpcClient(proxy=proxy)
|
self._client = client.CoreGrpcClient(proxy=proxy)
|
||||||
self.session_id = None
|
self.session_id = None
|
||||||
self.node_ids = []
|
self.node_ids = []
|
||||||
self.app = app
|
self.app = app
|
||||||
|
@ -102,6 +102,22 @@ class CoreClient:
|
||||||
|
|
||||||
self.modified_service_nodes = set()
|
self.modified_service_nodes = set()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def client(self):
|
||||||
|
if self.session_id:
|
||||||
|
response = self._client.check_session(self.session_id)
|
||||||
|
if not response.result:
|
||||||
|
throughputs_enabled = self.handling_throughputs is not None
|
||||||
|
self.cancel_throughputs()
|
||||||
|
self.cancel_events()
|
||||||
|
self._client.create_session(self.session_id)
|
||||||
|
self.handling_events = self._client.events(
|
||||||
|
self.session_id, self.handle_events
|
||||||
|
)
|
||||||
|
if throughputs_enabled:
|
||||||
|
self.enable_throughputs()
|
||||||
|
return self._client
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
# helpers
|
# helpers
|
||||||
self.interfaces_manager.reset()
|
self.interfaces_manager.reset()
|
||||||
|
@ -121,12 +137,8 @@ class CoreClient:
|
||||||
mobility_player.handle_close()
|
mobility_player.handle_close()
|
||||||
self.mobility_players.clear()
|
self.mobility_players.clear()
|
||||||
# clear streams
|
# clear streams
|
||||||
if self.handling_throughputs:
|
self.cancel_throughputs()
|
||||||
self.handling_throughputs.cancel()
|
self.cancel_events()
|
||||||
self.handling_throughputs = None
|
|
||||||
if self.handling_events:
|
|
||||||
self.handling_events.cancel()
|
|
||||||
self.handling_events = None
|
|
||||||
|
|
||||||
def set_observer(self, value: str):
|
def set_observer(self, value: str):
|
||||||
self.observer = value
|
self.observer = value
|
||||||
|
@ -217,8 +229,14 @@ class CoreClient:
|
||||||
)
|
)
|
||||||
|
|
||||||
def cancel_throughputs(self):
|
def cancel_throughputs(self):
|
||||||
self.handling_throughputs.cancel()
|
if self.handling_throughputs:
|
||||||
self.handling_throughputs = None
|
self.handling_throughputs.cancel()
|
||||||
|
self.handling_throughputs = None
|
||||||
|
|
||||||
|
def cancel_events(self):
|
||||||
|
if self.handling_events:
|
||||||
|
self.handling_events.cancel()
|
||||||
|
self.handling_events = None
|
||||||
|
|
||||||
def handle_throughputs(self, event: core_pb2.ThroughputsEvent):
|
def handle_throughputs(self, event: core_pb2.ThroughputsEvent):
|
||||||
if event.session_id != self.session_id:
|
if event.session_id != self.session_id:
|
||||||
|
|
|
@ -22,6 +22,8 @@ service CoreApi {
|
||||||
}
|
}
|
||||||
rpc GetSession (GetSessionRequest) returns (GetSessionResponse) {
|
rpc GetSession (GetSessionRequest) returns (GetSessionResponse) {
|
||||||
}
|
}
|
||||||
|
rpc CheckSession (CheckSessionRequest) returns (CheckSessionResponse) {
|
||||||
|
}
|
||||||
rpc GetSessionOptions (GetSessionOptionsRequest) returns (GetSessionOptionsResponse) {
|
rpc GetSessionOptions (GetSessionOptionsRequest) returns (GetSessionOptionsResponse) {
|
||||||
}
|
}
|
||||||
rpc SetSessionOptions (SetSessionOptionsRequest) returns (SetSessionOptionsResponse) {
|
rpc SetSessionOptions (SetSessionOptionsRequest) returns (SetSessionOptionsResponse) {
|
||||||
|
@ -212,6 +214,14 @@ message GetSessionsResponse {
|
||||||
repeated SessionSummary sessions = 1;
|
repeated SessionSummary sessions = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message CheckSessionRequest {
|
||||||
|
int32 session_id = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message CheckSessionResponse {
|
||||||
|
bool result = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message GetSessionRequest {
|
message GetSessionRequest {
|
||||||
int32 session_id = 1;
|
int32 session_id = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue