Example #1
0
        /// <summary>
        /// Creates a member entry for a member specified in the IDL. A SinTDType object of respective type is
        /// retrieved from the SinTD or created for map or array typed members. Registers the member to the
        /// struct's members under the name given in the IDL
        /// </summary>
        /// <param name="memberDefinition">IDL entry defining type and name of the member</param>
        /// <param name="createdStruct">Struct that is created during the currrent parsing process</param>
        internal void createSinTDTypeForMember(string memberDefinition, SinTDStruct createdStruct)
        {
            if (!memberDefinition.Contains(';'))
            {
                return;
            }

            // Removes semicolon and comments at the end of line
            memberDefinition = memberDefinition.Trim().Split(';')[0];

            // TODO:
            // Consider additional spaces that may occur after comma of map definitions
            string[] memberComponents;
            string   memberType;
            string   memberName;

            if (!(memberDefinition.Contains("array") || memberDefinition.Contains("map")))
            {
                memberComponents = memberDefinition.Split(' ');
                memberType       = memberComponents[0];
                memberName       = memberComponents[1];
            }
            else
            {
                memberDefinition = Regex.Replace(memberDefinition, @"\s+", "");
                int closingBracket = memberDefinition.IndexOf('>') + 1;
                memberType = memberDefinition.Substring(0, closingBracket);
                memberName = memberDefinition.Substring(closingBracket, memberDefinition.Length - closingBracket);
            }

            SinTDType typeObject = getTypeForMember(memberType);

            createdStruct.members.Add(memberName, typeObject);
        }
Example #2
0
        /// <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);
            });
        }
Example #3
0
        private object[] ConvertParameters(string methodName, List <object> args, List <int> callbacks, List <ParameterInfo> paramInfo)
        {
            object[] parameters = new object[paramInfo.Count];

            // Special handling for the first parameter if it's of type Connection.
            if (paramInfo.Count > 0 && paramInfo[0].ParameterType.Equals(typeof(Connection)))
            {
                parameters[0] = this;
                var otherParams = ConvertParameters(methodName, args, callbacks, paramInfo.GetRange(1, paramInfo.Count - 1));
                otherParams.CopyTo(parameters, 1);
                return(parameters);
            }

            if (paramInfo.Count != args.Count)
            {
                throw new Exception("Incorrect number of arguments for a method. Expected: " +
                                    paramInfo.Count + ". Received: " + args.Count);
            }

            for (int i = 0; i < args.Count; i++)
            {
                // TODO: Handling of callbacks will change in the future and callbacks should be derived from the IDL.
                // Callbacks should not be transmitted as extra list, as it is unclear how list is treated in some protocols
                if (callbacks != null && callbacks.Contains(i))
                {
                    if (paramInfo[i].ParameterType == typeof(ClientFunction))
                    {
                        parameters[i] = CreateFuncWrapperDelegate((string)args[i]);
                    }
                    else if (typeof(Delegate).IsAssignableFrom(paramInfo[i].ParameterType))
                    {
                        parameters[i] = CreateCustomDelegate((string)args[i], paramInfo[i].ParameterType);
                    }
                    else
                    {
                        throw new Exception("Parameter " + i + " is neither a delegate nor a FuncWrapper. " +
                                            "Cannot pass callback method in its place");
                    }
                }
                else
                {
                    // Super Evil Hack! See other super evil hack comment above
                    if (SinTD == null)
                    {
                        parameters[i] = Convert.ChangeType(args[i], paramInfo[i].ParameterType);
                    }
                    else
                    {
                        string[]  service      = methodName.Split('.');
                        SinTDType idlParameter = SinTD.SINFONIServices.GetService(service[0])
                                                 .GetServiceFunction(service[1]).Parameters.ElementAt(i).Value;
                        parameters[i] = idlParameter.AssignValuesToNativeType(args[i], paramInfo[i].ParameterType);
                    }
                }
            }

            return(parameters);
        }
Example #4
0
        /// <summary>
        /// Creates a SinTDTyped object and stores it under the name specified in the IDL for the corresponding parameter.
        /// The created Parameter is added to the list of parameters for the currently parsed service function object.
        /// </summary>
        /// <param name="param">String defining name and type of the parameter</param>
        /// <param name="functionDescription">Service Function object to which the parameter should be added</param>
        private void createParameterForServiceFunction(string param, ServiceFunctionDescription functionDescription)
        {
            string[] values = splitDeclarationInNameAndType(param);

            SinTDType paramType = getSinTDType(values[0].Trim());
            string    paramName = values[1].Trim();

            functionDescription.Parameters.Add(paramName, paramType);
        }
Example #5
0
        /// <summary>
        /// Converts the <paramref name="result"/> into <paramref name="type"/>.
        /// </summary>
        /// <returns>The converted result.</returns>
        /// <param name="result">Result.</param>
        /// <param name="type">Type to which the result must be converted.</param>
        protected object ConvertResult(object result, Type type)
        {
            SinTDType idlReturnType = CallingConnection.SinTD.SINFONIServices
                                      .GetService(ServiceName)
                                      .GetServiceFunction(FunctionName)
                                      .ReturnType;

            var convertedResult = idlReturnType.AssignValuesToNativeType(result, type);

            return(convertedResult);
        }
Example #6
0
        /// <summary>
        /// Registers a new Type to the SinTD. The type object that is used for registration must contain a
        /// valid name (not null, not registered before). Otherwise, SinTD will throw an exception.
        /// </summary>
        /// <param name="type">New type that should be registered to the SinTD</param>
        public void RegisterType(SinTDType type)
        {
            if (type.Name == null ||
                type.Name.Length == 0)
            {
                throw new InvalidTypeNameException();
            }

            if (registeredTypes.ContainsKey(type.Name))
            {
                throw new TypeNameConflictException(type.Name);
            }

            registeredTypes.Add(type.Name, type);
        }
Example #7
0
        private object getFieldValueForSinTDInstance(object other, string fieldName, SinTDType SinTDType)
        {
            var assignedValue = other;
            var otherField    = other.GetType().GetField(fieldName);

            if (otherField == null)
            {
                var property = other.GetType().GetProperty(fieldName);
                assignedValue = SinTDType.AssignValuesFromObject(property.GetValue(other, null));
            }
            else
            {
                assignedValue = SinTDType.AssignValuesFromObject(otherField.GetValue(other));
            }
            return(assignedValue);
        }
Example #8
0
        /// <summary>
        /// Creates a new service function definition from an entry in the IDL. Reads type and name of the service
        /// function and creates a respective object from these
        /// </summary>
        /// <param name="nameAndType">Content of IDL defining name and type of a service function</param>
        /// <returns>ServiceFunction object with corresponding name and type</returns>
        private ServiceFunctionDescription createTypedServiceFunction(string nameAndType)
        {
            string[] values = splitDeclarationInNameAndType(nameAndType);

            SinTDType returnType;

            if (values[0].Trim() == "void")
            {
                returnType = new SinTDType("void");
            }
            else
            {
                returnType = getSinTDType(values[0].Trim());
            }

            return(new ServiceFunctionDescription(values[1], returnType));
        }
Example #9
0
        /// <summary>
        /// Retrieves the respective SinTD Type for a member type that is specified by its name in the IDL. Creates an
        /// Array or Map for array or map typed objects and queries the respective type from the SinTD otherwise.
        /// </summary>
        /// <param name="memberType">Name of the member type as given in the IDL</param>
        /// <returns>SinTD Type object with the given name</returns>
        private SinTDType getTypeForMember(string memberType)
        {
            SinTDType typeObject = new SinTDType();

            if (memberIsArray(memberType))
            {
                typeObject = ArrayParser.Instance.ParseArray(memberType);
            }
            else if (memberIsMap(memberType))
            {
                typeObject = MapParser.Instance.ParseMap(memberType);
            }
            else
            {
                typeObject = IDLParser.Instance.CurrentlyParsedSinTD.GetSinTDType(memberType);
            }

            return(typeObject);
        }
Example #10
0
        /// <summary>
        /// Retrieves the respective SinTD Type for a member type that is specified by its name in the IDL. Creates an
        /// Array or Map for array or map typed objects and queries the respective type from the SinTD otherwise.
        /// </summary>
        /// <param name="memberType">Name of the member type as given in the IDL</param>
        /// <returns>SinTD Type object with the given name</returns>
        private SinTDType getTypeForMember(string memberType)
        {
            SinTDType typeObject = new SinTDType();

            if (memberIsArray(memberType))
            {
                typeObject = ArrayParser.Instance.ParseArray(memberType);
            }
            else if (memberIsMap(memberType))
            {
                typeObject = MapParser.Instance.ParseMap(memberType);
            }
            else
            {
                typeObject = IDLParser.Instance.CurrentlyParsedSinTD.GetSinTDType(memberType);
            }

            return typeObject;
        }
Example #11
0
        private object getFieldValueForSinTDInstance(object other, string fieldName, SinTDType SinTDType)
        {
            var assignedValue = other;
            var otherField = other.GetType().GetField(fieldName);

            if (otherField == null)
            {
                var property = other.GetType().GetProperty(fieldName);
                assignedValue = SinTDType.AssignValuesFromObject(property.GetValue(other, null));
            }
            else
            {
                assignedValue = SinTDType.AssignValuesFromObject(otherField.GetValue(other));
            }
            return assignedValue;
        }
Example #12
0
        /// <summary>
        /// Registers a new Type to the SinTD. The type object that is used for registration must contain a
        /// valid name (not null, not registered before). Otherwise, SinTD will throw an exception.
        /// </summary>
        /// <param name="type">New type that should be registered to the SinTD</param>
        public void RegisterType(SinTDType type)
        {
            if(type.Name == null
                || type.Name.Length == 0)
                throw new InvalidTypeNameException();

            if (registeredTypes.ContainsKey(type.Name))
                throw new TypeNameConflictException(type.Name);

            registeredTypes.Add(type.Name, type);
        }
 internal ServiceFunctionDescription(string name, SinTDType returnType)
 {
     Name = name;
     ReturnType = returnType;
 }
Example #14
0
 public SinTDMap(SinTDType key, SinTDType element)
 {
     keyType     = key;
     elementType = element;
 }
Example #15
0
        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;
        }
Example #16
0
        /// <summary>
        /// Creates a new service function definition from an entry in the IDL. Reads type and name of the service
        /// function and creates a respective object from these
        /// </summary>
        /// <param name="nameAndType">Content of IDL defining name and type of a service function</param>
        /// <returns>ServiceFunction object with corresponding name and type</returns>
        private ServiceFunctionDescription createTypedServiceFunction(string nameAndType)
        {
            string[] values = splitDeclarationInNameAndType(nameAndType);

            SinTDType returnType;
            if (values[0].Trim() == "void")
                returnType = new SinTDType("void");
            else
                returnType = getSinTDType(values[0].Trim());

            return new ServiceFunctionDescription(values[1], returnType);
        }
Example #17
0
        public void TestSetUp()
        {
            i32 = SinTDInstance.GetSinTDType("i32");
            SinTDString = SinTDInstance.GetSinTDType("string");
            SinTDBool = SinTDInstance.GetSinTDType("boolean");

            intStruct = new SinTDStruct("intStruct");
            intStruct.members["x"] = i32;
            intStruct.members["y"] = i32;

            aStruct = new SinTDStruct("arrayStruct");
            aStruct.members.Add("arr", new SinTDArray(i32));
            SinTDInstance.RegisterType(aStruct);

            mStruct = new SinTDStruct("mapStruct");
            mStruct.members.Add("map", new SinTDMap(SinTDString, SinTDBool));
            SinTDInstance.RegisterType(mStruct);

            sStruct = new SinTDStruct("structStruct");
            sStruct.members.Add("child", intStruct);
            SinTDInstance.RegisterType(sStruct);

            SinTDInstance = new SinTD();
        }
Example #18
0
 public SinTDArray(SinTDType type)
 {
     elementType = type;
 }
Example #19
0
 internal ServiceFunctionDescription(string name, SinTDType returnType)
 {
     Name       = name;
     ReturnType = returnType;
 }