grpc added get hooks and add hook

This commit is contained in:
bharnden 2019-03-16 12:33:24 -07:00
parent 8559b425ee
commit 5d72b6af26
3 changed files with 81 additions and 2 deletions

View file

@ -212,6 +212,19 @@ class CoreApiClient(object):
)
return self.stub.DeleteLink(request)
def get_hooks(self, session):
request = core_pb2.GetHooksRequest()
request.session = session
return self.stub.GetHooks(request)
def add_hook(self, session, state, file_name, file_data):
request = core_pb2.AddHookRequest()
request.session = session
request.hook.state = state.value
request.hook.file = file_name
request.hook.data = file_data
return self.stub.AddHook(request)
def get_services(self):
request = core_pb2.GetServicesRequest()
return self.stub.GetServices(request)
@ -317,10 +330,10 @@ def main():
# create session
session_data = client.create_session()
print("created session: {}".format(session_data))
print("default services: {}".format(client.get_service_defaults(session_data.id)))
print("emane models: {}".format(client.get_emane_models(session_data.id)))
print("add hook: {}".format(client.add_hook(session_data.id, EventTypes.RUNTIME_STATE, "test", "echo hello")))
print("hooks: {}".format(client.get_hooks(session_data.id)))
response = client.get_sessions()
print("core client received: {}".format(response))

View file

@ -507,6 +507,32 @@ class CoreApiServer(core_pb2_grpc.CoreApiServicer):
response.result = True
return response
def GetHooks(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
response = core_pb2.GetHooksResponse()
for state, state_hooks in session._hooks.iteritems():
for file_name, file_data in state_hooks:
hook = response.hooks.add()
hook.state = state
hook.file = file_name
hook.data = file_data
return response
def AddHook(self, request, context):
session = self.coreemu.sessions.get(request.session)
if not session:
raise Exception("no session found")
hook = request.hook
session.add_hook(hook.state, hook.file, None, hook.data)
response = core_pb2.AddHookResponse()
response.result = True
return response
def GetServices(self, request, context):
response = core_pb2.GetServicesResponse()
for service in ServiceManager.services.itervalues():

View file

@ -3,6 +3,7 @@ syntax = "proto3";
package core;
service CoreApi {
// session rpc
rpc CreateSession (CreateSessionRequest) returns (CreateSessionResponse) {
}
rpc DeleteSession (DeleteSessionRequest) returns (DeleteSessionResponse) {
@ -19,6 +20,8 @@ service CoreApi {
}
rpc SetSessionState (SetSessionStateRequest) returns (SetSessionStateResponse) {
}
// node rpc
rpc CreateNode (CreateNodeRequest) returns (CreateNodeResponse) {
}
rpc GetNode (GetNodeRequest) returns (GetNodeResponse) {
@ -27,6 +30,8 @@ service CoreApi {
}
rpc DeleteNode (DeleteNodeRequest) returns (DeleteNodeResponse) {
}
// link rpc
rpc GetNodeLinks (GetNodeLinksRequest) returns (GetNodeLinksResponse) {
}
rpc CreateLink (CreateLinkRequest) returns (CreateLinkResponse) {
@ -35,6 +40,14 @@ service CoreApi {
}
rpc DeleteLink (DeleteLinkRequest) returns (DeleteLinkResponse) {
}
// hook rpc
rpc GetHooks (GetHooksRequest) returns (GetHooksResponse) {
}
rpc AddHook (AddHookRequest) returns (AddHookResponse) {
}
// service rpc
rpc GetServices (GetServicesRequest) returns (GetServicesResponse) {
}
rpc GetServiceDefaults (GetServiceDefaultsRequest) returns (GetServiceDefaultsResponse) {
@ -43,6 +56,8 @@ service CoreApi {
}
rpc GetNodeService (GetNodeServiceRequest) returns (GetNodeServiceResponse) {
}
// emane rpc
rpc GetEmaneConfig (GetEmaneConfigRequest) returns (GetEmaneConfigResponse) {
}
rpc SetEmaneConfig (SetEmaneConfigRequest) returns (SetEmaneConfigResponse) {
@ -55,6 +70,8 @@ service CoreApi {
}
rpc GetEmaneModelConfigs (GetEmaneModelConfigsRequest) returns (GetEmaneModelConfigsResponse) {
}
// xml rpc
rpc SaveXml (SaveXmlRequest) returns (SaveXmlResponse) {
}
rpc OpenXml (OpenXmlRequest) returns (OpenXmlResponse) {
@ -221,6 +238,23 @@ message DeleteLinkResponse {
bool result = 1;
}
message GetHooksRequest {
int32 session = 1;
}
message GetHooksResponse {
repeated Hook hooks = 1;
}
message AddHookRequest {
int32 session = 1;
Hook hook = 2;
}
message AddHookResponse {
bool result = 1;
}
message GetServicesRequest {
}
@ -365,6 +399,12 @@ enum ServiceValidationMode {
TIMER = 2;
}
message Hook {
SessionState state = 1;
string file = 2;
bytes data = 3;
}
message ServiceDefaults {
string node_type = 1;
repeated string services = 2;