/// <summary> /// Generates a client function for the <paramref name="funcName"/>. Optional <paramref name="typeMapping"/> string /// may be used to specify data omission and reordering options. /// </summary> /// <returns>The generated client function.</returns> /// <param name="serviceName">Service that contains the wrapped function.</param> /// <param name="functionName">Name of the function that should be wrapped.</param> public virtual ClientFunction GenerateClientFunction(string serviceName, string functionName) { if (!SinTD.SINFONIServices.ContainsService(serviceName)) { throw new ServiceNotRegisteredException(serviceName); } var service = SinTD.SINFONIServices.GetService(serviceName); if (!service.ContainsServiceFunction(functionName)) { throw new ServiceNotRegisteredException(functionName); } return((ClientFunction) delegate(object[] parameters) { SINFONIService registeredService = SinTD.SINFONIServices.GetService(serviceName); ServiceFunctionDescription registeredServiceFunction = registeredService.GetServiceFunction(functionName); if (!registeredServiceFunction.CanBeCalledWithParameters(parameters)) { throw new ParameterMismatchException( "Could not call Service Function " + serviceName + "." + functionName + ". The provided parameters can not be mapped to the parameters specified in the IDL."); } object[] callParameters = new object[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { SinTDType expectedParameterType = registeredServiceFunction.Parameters.ElementAt(i).Value; callParameters[i] = expectedParameterType.AssignValuesFromObject(parameters[i]); } return CallClientFunction(serviceName + "." + functionName, callParameters); }); }
/// <summary> /// Reads the name of a service when IDL parser encounters a service definition and creates a service /// of respective name. Puts IDL parser in service parsing mode so that every following line will be /// treated as service function definition /// </summary> /// <param name="serviceDefinition">Line of the IDL defining a new service</param> internal void startServiceParsing(string serviceDefinition) { Regex nameRegEx = new Regex("service ([A-Za-z0-9_]*)[{}._<,>; ]*"); Match nameMatch = nameRegEx.Match(serviceDefinition); string name = nameMatch.Groups[1].Value; currentlyParsedService = new SINFONIService(name); }
public void Setup() { SinTDInstance = new SinTD(); SinTDInstance.SINFONIServices = new ServiceRegistry(); i32 = SinTDInstance.GetSinTDType("i32"); SinTD_string = SinTDInstance.GetSinTDType("string"); intStruct = new SinTDStruct("intStruct"); intStruct.members["x"] = i32; intStruct.members["y"] = i32; serviceFunction = new ServiceFunctionDescription("function", new SinTDType("void")); serviceFunction.Parameters.Add("intParameter", i32); serviceFunction.Parameters.Add("stringParameter", SinTD_string); service = new SINFONIService("service"); service.serviceFunctions.Add("function", serviceFunction); SinTDInstance.SINFONIServices.services.Add("service", service); connection = new TestConnection(); connection.SinTD = SinTDInstance; }