/// <summary>
        /// Given an IDLProperty, generate all the necessaries
        /// </summary>
        /// <remarks>Override to expand functionality or replace it</remarks>
        /// <param name="idlIntf"></param>
        /// <param name="idlProperty"></param>
        /// <returns></returns>
        public virtual CodeTypeMember HandleProperty(IDLInterface idlIntf, IDLProperty idlProperty)
        {
            CodeMemberProperty property = new CodeMemberProperty();

            property.Comments.Add(new CodeCommentStatement(idlProperty.Name));
            property.Name       = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
            property.Attributes = MemberAttributes.Abstract;
            IDLMethodArgument idlMethodArgGet = new IDLMethodArgument {
                Direction = "out", Name = "value", Type = idlProperty.Type
            };
            IDLMethod idlMethodGet = new IDLMethod
            {
                Arguments = new List <IDLMethodArgument>(new IDLMethodArgument[] { idlMethodArgGet }),
                Name      = "get",
            };

            Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethodGet);
            property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArgGet.Direction, idlMethodArgGet.Name, idlMethodArgGet.Type)));
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForProperty(idlIntf, idlProperty.Name, idlMethodArgGet.Name, idlMethodArgGet.Type, idlMethodArgGet.Direction);

            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArgGet.Type, context);

            // Arguments.
            CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtypeHolder.paramtype.CodeType, idlMethodArgGet.Name);

            property.Type   = paramtypeHolder.paramtype.CodeType;
            property.HasGet = CodeBuilderCommon.HasGet(idlProperty);
            property.HasSet = CodeBuilderCommon.HasSet(idlProperty);
            property.Parameters.Add(param);

            return(property);
        }
示例#2
0
 public override void EndStruct(Udbus.Parsing.BuildContext context, Udbus.Parsing.IParamCodeTypeHandler paramtypeHandler)
 {
     base.EndStruct(context, paramtypeHandler);
     this.parent.VariantDelegate += this.VariantDelegate;
     this.parent.ObjectDelegate  += this.ObjectDelegate;
     this.parent.HandleStruct(null, null, null);
 }
示例#3
0
 public override void FinishDictionary(Udbus.Parsing.BuildContext context, Udbus.Parsing.IParamCodeTypeHandler paramtypeHandler)
 {
     System.Diagnostics.Debug.WriteLine("Finishing dictionary");
     owner.VariantDelegate += this.VariantDelegate;
     owner.ObjectDelegate  += this.ObjectDelegate;
     this.owner.HandleDictionary(null, null, null);
 }
示例#4
0
 public override void EndStruct(Udbus.Parsing.BuildContext context, Udbus.Parsing.IParamCodeTypeHandler paramtypeHandler)
 {
     base.EndStruct(context, paramtypeHandler);
     context.declarationHolder.Add(this.declaration);
     paramtypeHandler.HandleStruct(new Udbus.Parsing.CodeParamDeclaredType(this.declaration), this.name,
                                   CodeBuilderCommon.GetScopedName(CodeBuilderCommon.nsDbusMarshalCustom, context.declarationHolder.Name)
                                   );
 }
示例#5
0
 public static CodeTypeReference PropertyType(CodeTypeFactory codetypefactoryOut, string idlPropertyType)
 {
     Udbus.Parsing.ICodeTypeDeclarationHolder     declarationHolderProperty = new Udbus.Parsing.CodeTypeNoOpHolder();
     Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder     = new Udbus.Parsing.IDLArgumentTypeNameBuilderNoOp();
     marshal.outward.ParamCodeTypeHolderProperty  paramtypeHolder = new marshal.outward.ParamCodeTypeHolderProperty(codetypefactoryOut, FieldDirection.Out);
     Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolderProperty);
     Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlPropertyType, context);
     return(paramtypeHolder.paramtype.CodeType);
 }
示例#6
0
        private void GenerateMethod(IDLInterface idlIntf, IDLMethod idlMethod
                                    , Udbus.Parsing.ICodeTypeDeclarationHolder contextDeclarationHolder
                                    , CodeTypeReference typerefDbusInterface
                                    , CodeTypeReference typerefDbusMarshal
                                    , CodeTypeDeclaration typeProxy)
        {
            // Straight-forward interface method.
            CodeMemberMethod         methodInterface   = new CodeMemberMethod();
            CodeExpressionCollection interfaceCallArgs = new CodeExpressionCollection();

            methodInterface.Name       = idlMethod.Name;
            methodInterface.Attributes = MemberAttributes.Public;
            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(contextDeclarationHolder);

            #region Methods args
            foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments)
            {
                CodeCommentStatement commentMethod = new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type));
                methodInterface.Comments.Add(commentMethod);
                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod);
                ParamCodeTypeFactory paramtypeHolder = new ParamCodeTypeFactory(CodeTypeFactory.Default,
                                                                                idlMethodArg.Direction == "out" ? FieldDirection.Out : FieldDirection.In);
                Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context);
                Udbus.Parsing.ICodeParamType paramtype = paramtypeHolder.paramtype;

                // Arguments.
                CodeParameterDeclarationExpression param           = new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name);
                CodeVariableReferenceExpression    varrefMethodArg = new CodeVariableReferenceExpression(idlMethodArg.Name);

                if (idlMethodArg.Direction == "out")
                {
                    // Add to interface parameters.
                    interfaceCallArgs.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg));
                    // Add parameter to interface method.
                    param.Direction = FieldDirection.Out;
                }
                else
                {
                    interfaceCallArgs.Add(varrefMethodArg);
                }
                methodInterface.Parameters.Add(param);
            } // Ends loop over method arguments
            #endregion

            methodInterface.Statements.Add(this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal));
            methodInterface.Statements.Add(new CodeMethodInvokeExpression(varrefTarget, idlMethod.Name, interfaceCallArgs.Cast <CodeExpression>().ToArray()));

            //methodInterface.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisProxyFieldRef, idlMethod.Name)
            //    , interfaceCallArgs.Cast<CodeExpression>().ToArray()
            //));

            // Finish up.
            typeProxy.Members.Add(methodInterface);
        }
        protected virtual ParamCodeTypeFactory HandleSignalArgument(IDLInterface idlIntf, IDLSignal idlSignal, IDLSignalArgument idlSignalArg)
        {
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLSignalArgumentTypeNameBuilder(idlIntf, idlSignal);
            ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForMethod("in");

            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlSignalArg.Type, context);

            // Arguments
            return(paramtypeHolder);
        }
示例#8
0
 public override void FinishDictionary(Udbus.Parsing.BuildContext context, Udbus.Parsing.IParamCodeTypeHandler paramtypeHandler)
 {
     base.FinishDictionary(context, paramtypeHandler);
     this.typerefDict = new CodeTypeReference(this.DictionaryType.Name,
                                              new CodeTypeReference[]
     {
         this.paramtypeKey.CodeType,
         this.paramtypeValue.CodeType
     }
                                              );
     paramtypeHandler.HandleDictionary(new Udbus.Parsing.CodeParamType(this.typerefDict), this.name, CodeBuilderCommon.GetMarshalDictionaryScope());
 }
        /// <summary>
        /// Given an IDL Method, generate the necessary bits
        /// </summary>
        /// <remarks>Override to expand functionality or replace it</remarks>
        /// <param name="idlIntf"></param>
        /// <param name="idlMethod"></param>
        /// <returns></returns>
        protected virtual CodeMemberMethod HandleMethod(IDLInterface idlIntf, IDLMethod idlMethod)
        {
            // Method.
            CodeMemberMethod method = new CodeMemberMethod();

            method.Comments.Add(new CodeCommentStatement(idlMethod.Name));
            method.Name = idlMethod.Name;

            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);

            foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments)
            {
                method.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type)));
                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod);
                ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForMethod(idlMethodArg.Direction);
                Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context);
                Console.WriteLine(idlMethodArg.Type);
                // Arguments.
                method.Parameters.Add(HandleMethodArgument(idlMethodArg, paramtypeHolder));
            } // Ends loop over method arguments
            return(method);
        }
示例#10
0
 public override string getDictionaryNames(Udbus.Parsing.BuildContext context, out string fullName)
 {
     return(Udbus.Parsing.IDLArgumentTypeNameBuilderBase.getDictionaryNameImpl(context, this.methodName, out fullName));
 }
示例#11
0
        public override void GenerateMethods(IDLInterface idlIntf)
        {
            if (idlIntf.Methods != null) // If got methods
            {
                bAddNamespace = idlIntf.Methods.Count > 0;

                foreach (IDLMethod idlMethod in idlIntf.Methods)
                {
                    // Structs for capturing input/output from method.
                    Udbus.Parsing.CodeTypeDeferredStructHolder paramsHolder = new Udbus.Parsing.CodeTypeDeferredStructHolder(idlMethod.Name + "AsyncParams");
                    Udbus.Parsing.CodeTypeDeferredStructHolder resultHolder = new Udbus.Parsing.CodeTypeDeferredStructHolder(idlMethod.Name + "AsyncResult");
                    CodeConstructor constructorResults = new CodeConstructor();
                    CodeConstructor constructorParams  = new CodeConstructor();
                    constructorResults.Attributes = constructorParams.Attributes = MemberAttributes.Public;

                    // Create Call method.
                    CodeMemberMethod methodCall = new CodeMemberMethod();
                    methodCall.Name = "Call" + idlMethod.Name;
                    // Actual call to proxy arguments will be added to as we parse IDL arguments.
                    CodeExpressionCollection        callParameters    = new CodeExpressionCollection();
                    CodeExpressionCollection        callResultArgs    = new CodeExpressionCollection();
                    CodeExpressionCollection        interfaceCallArgs = new CodeExpressionCollection();
                    CodeArgumentReferenceExpression argrefCallData    = new CodeArgumentReferenceExpression(dataName);

                    // Event Args
                    string eventName = idlMethod.Name + "EventArgs";
                    CodeTypeDeclaration typeEvent = new CodeTypeDeclaration(eventName);
                    typeEvent.IsClass        = true;
                    typeEvent.TypeAttributes = TypeAttributes.Public;
                    typeEvent.BaseTypes.Add(new CodeTypeReference(typeof(AsyncCompletedEventArgs)));
                    CodeConstructor constructorEventArgs = new CodeConstructor();
                    eventsDeclarationHolder.Add(typeEvent);
                    CodeExpressionCollection makeEventArgs = new CodeExpressionCollection();

                    // Event Raiser...
                    string            raiserName  = "raiser" + idlMethod.Name;
                    CodeTypeReference raiserRef   = new CodeTypeReference("AsyncOperationEventRaiser", new CodeTypeReference(eventName));
                    CodeMemberField   fieldRaiser = new CodeMemberField(raiserRef, raiserName);
                    fieldRaiser.InitExpression = new CodeObjectCreateExpression(raiserRef);
                    fieldRaiser.Attributes     = MemberAttributes.Private;
                    typeProxy.Members.Add(fieldRaiser);

                    // Event raiser EventCompleted Property - unfortunately CodeMemberEvent is useless here since can't add custom add/remove.
                    // So anything other than CSharp is now a bust. Brilliant.
                    CodeSnippetTypeMember eventRaiser = new CodeSnippetTypeMember();
                    eventRaiser.Text = string.Format(@"        public event System.EventHandler<{0}> {1}Completed
        {{
            add {{ this.{2}.CompletedEvent += value; }}
            remove {{ this.{2}.CompletedEvent -= value; }}
        }}
", eventName, idlMethod.Name, raiserName
                                                     ); // Adding text here.

                    //CodeMemberEvent eventRaiser = new CodeMemberEvent();
                    //eventRaiser.Attributes = MemberAttributes.Public;
                    //CodeParamDeclaredType declaredType = new CodeParamDeclaredType(typeEvent);
                    //eventRaiser.Type = new CodeTypeReference(CodeBuilderCommon.EventHandlerType.Name, declaredType.CodeType);
                    //eventRaiser.Name = idlMethod.Name + "Completed";

                    typeProxy.Members.Add(eventRaiser);

                    // Async method.
                    CodeMemberMethod methodAsync = new CodeMemberMethod();
                    methodAsync.Name       = idlMethod.Name + "Async";
                    methodAsync.Attributes = MemberAttributes.Public;

                    // Straight-forward interface method.
                    CodeMemberMethod methodInterface = new CodeMemberMethod();
                    methodInterface.Name       = idlMethod.Name;
                    methodInterface.Attributes = MemberAttributes.Public;

                    //        CodeComment commentMethod = new CodeComment(idlMethod.Name);
                    //        method.Comments.Add(new CodeCommentStatement(idlMethod.Name));
                    CodeExpressionCollection   asyncArgs = new CodeExpressionCollection();
                    Udbus.Parsing.BuildContext context   = new Udbus.Parsing.BuildContext(contextDeclarationHolder);

                    foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments)
                    {
                        CodeCommentStatement commentMethod = new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type));
                        methodAsync.Comments.Add(commentMethod);
                        methodInterface.Comments.Add(commentMethod);
                        // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                        Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod);
                        ParamCodeTypeFactory paramtypeHolder = new ParamCodeTypeFactory(CodeTypeFactory.Default,
                                                                                        idlMethodArg.Direction == "out" ? FieldDirection.Out : FieldDirection.In);
                        Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context);
                        Udbus.Parsing.ICodeParamType paramtype = paramtypeHolder.paramtype;

                        // Arguments.
                        CodeParameterDeclarationExpression param           = new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name);
                        CodeVariableReferenceExpression    varrefMethodArg = new CodeVariableReferenceExpression(idlMethodArg.Name);

                        if (idlMethodArg.Direction == "out") // If out argument
                        {
                            // Add to interface parameters.
                            interfaceCallArgs.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg));

                            // Put into result holding struct...
                            param.Direction = FieldDirection.Out;
                            methodInterface.Parameters.Add(param);

                            CodeTypeReference argType        = CodeBuilderCommon.GetReadOnlyCodeReference(paramtypeHolder.paramtype.CodeType);
                            CodeMemberField   fieldResultArg = new CodeMemberField(argType, idlMethodArg.Name);
                            fieldResultArg.Attributes = MemberAttributes.Public;
                            resultHolder.CodeType.Members.Add(fieldResultArg);

                            constructorResults.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name));
                            CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression(
                                new CodeThisReferenceExpression(), idlMethodArg.Name
                                );
                            constructorResults.Statements.Add(new CodeAssignStatement(thisArg,
                                                                                      new CodeArgumentReferenceExpression(idlMethodArg.Name)));

                            // Add placeholder variables to call method.
                            methodCall.Statements.Add(new CodeVariableDeclarationStatement(paramtype.CodeType, idlMethodArg.Name));

                            // Add appropriate parameter in actual call to interface.
                            callParameters.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg));

                            // Add appropriate parameter in call to result constructor.
                            callResultArgs.Add(new CodeArgumentReferenceExpression(idlMethodArg.Name));

                            // Put into event args class...
                            string          fieldEventArgName = idlMethodArg.Name + "_";
                            CodeMemberField fieldEventArg     = new CodeMemberField(paramtype.CodeType, fieldEventArgName);
                            fieldEventArg.Attributes = MemberAttributes.Private;
                            typeEvent.Members.Add(fieldEventArg);

                            // Add argument property to EventArgs.
                            CodeMemberProperty propEventArg = new CodeMemberProperty();
                            propEventArg.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                            propEventArg.Name       = idlMethodArg.Name;
                            propEventArg.HasGet     = true;
                            propEventArg.Type       = paramtype.CodeType;
                            propEventArg.GetStatements.Add(new CodeMethodInvokeExpression(null, "RaiseExceptionIfNecessary"));
                            propEventArg.GetStatements.Add(new CodeMethodReturnStatement(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), fieldEventArgName)));
                            typeEvent.Members.Add(propEventArg);

                            // Add constructor parameter and statement to EventArgs.
                            constructorEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name));
                            constructorEventArgs.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldEventArgName),
                                                                                        new CodeArgumentReferenceExpression(idlMethodArg.Name)
                                                                                        ));

                            // Add as parameter in call to EventArgs constructor.
                            makeEventArgs.Add(new CodeFieldReferenceExpression(new CodeArgumentReferenceExpression(resultName), idlMethodArg.Name));
                        }    // Ends if out argument
                        else // Else in argument
                        {
                            // Add to interface parameters.
                            interfaceCallArgs.Add(varrefMethodArg);
                            // Put into parameter holding struct.
                            CodeMemberField fieldArg = new CodeMemberField(CodeBuilderCommon.GetReadOnlyCodeReference(paramtype.CodeType), idlMethodArg.Name);
                            fieldArg.Attributes = MemberAttributes.Public;
                            paramsHolder.CodeType.Members.Add(fieldArg);

                            constructorParams.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name));
                            CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression(
                                new CodeThisReferenceExpression(), idlMethodArg.Name
                                );
                            constructorParams.Statements.Add(new CodeAssignStatement(thisArg,
                                                                                     new CodeArgumentReferenceExpression(idlMethodArg.Name)));

                            // Add appropriate parameter in actual call to interface.
                            callParameters.Add(new CodeFieldReferenceExpression(argrefCallData, idlMethodArg.Name));

                            // Add appropriate parameter to async method parameters constructor call.
                            asyncArgs.Add(new CodeArgumentReferenceExpression(idlMethodArg.Name));

                            // Add parameter to async method.
                            methodAsync.Parameters.Add(param);
                            // Add parameter to interface method.
                            methodInterface.Parameters.Add(param);
                        } // Ends else in argument
                    }     // Ends loop over method arguments

                    methodAsync.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "userState"));

                    // Add method body, then sort out arguments code...
                    CodeFieldReferenceExpression thisRaiser = new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), raiserName
                        );
                    CodeTypeReference typerefResult = null;
                    if (idlMethod.Return != null) // If method has return type
                    {
                        // Add result to Result type.
                        // TODO replace typeof(string) with actual return type.
                        typerefResult = new CodeTypeReference("???");
                    }

                    CodeTypeReference typerefResults      = null;
                    CodeTypeReference typerefParams       = null;
                    CodeExpression    exprAsyncParamValue = null;
                    string            asyncMethodName     = "AsyncFuncImpl"; // Default is assuming that function returns something.

                    if (paramsHolder.QuType())                               // If got params type
                    {
                        typerefParams = new CodeTypeReference(paramsHolder.CodeType.Name);

                        // Add proxy field to params struct.
                        CodeMemberField memberParamsProxy = new CodeMemberField(new CodeTypeReference("readonly " + genInterfaceName), proxyName);
                        memberParamsProxy.Attributes = MemberAttributes.Public;
                        paramsHolder.CodeType.Members.Insert(0, memberParamsProxy); // TODO: Going to need a using or a fully qualified name.

                        // Add initialisation to constructor
                        constructorParams.Parameters.Insert(0, paramProxy);
                        // Constructor will take proxy as first argument.
                        constructorParams.Statements.Insert(0, assignProxy);


                        paramsHolder.CodeType.TypeAttributes = TypeAttributes.NestedPrivate;
                        paramsHolder.CodeType.IsStruct       = true;
                        constructorParams.Attributes         = MemberAttributes.Public;
                        paramsHolder.CodeType.Members.Add(constructorParams);
                        typeProxy.Members.Add(paramsHolder.CodeType);

                        asyncArgs.Insert(0, thisProxyFieldRef);
                        exprAsyncParamValue = new CodeObjectCreateExpression(typerefParams, asyncArgs.Cast <CodeExpression>().ToArray());
                    } // Ends if got params type

                    if (resultHolder.QuType()) // If got results type
                    {
                        typerefResults = new CodeTypeReference(resultHolder.CodeType.Name);

                        methodCall.ReturnType = typerefResults;

                        // Setup call method parameters.
                        if (idlMethod.Return != null)
                        {
                            // Add result field to EventArgs.
                            CodeMemberField fieldResult = new CodeMemberField(typerefResult, resultName);
                            fieldResult.Attributes = MemberAttributes.Private;
                            typeEvent.Members.Insert(0, fieldResult);

                            // Add result property to EventArgs.
                            CodeMemberProperty propResult = new CodeMemberProperty();
                            propResult.Attributes = MemberAttributes.Public;
                            propResult.Name       = resultName;
                            propResult.HasGet     = true;
                            propResult.Type       = typerefResult;
                            propResult.GetStatements.Add(new CodeMethodInvokeExpression(null, "RaiseExceptionIfNecessary"));
                            propResult.GetStatements.Add(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), resultName));
                            typeEvent.Members.Add(propResult);

                            // Add suitable parameter as first EventArgs constructor argument.
                            constructorEventArgs.Parameters.Insert(0, new CodeParameterDeclarationExpression(typerefResult, resultName));
                            // Add statement to initialise result member.
                            CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression(
                                new CodeThisReferenceExpression(), resultName
                                );

                            // Include result in parameters to EventArgs in MakeEventArgs statements.
                            makeEventArgs.Insert(0, new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), resultName));

                            // Add result to Result type.
                            CodeTypeReference typerefReadOnlyResult = CodeBuilderCommon.GetReadOnlyCodeReference(typerefResult);
                            CodeMemberField   fieldReadOnlyResult   = new CodeMemberField(typerefReadOnlyResult, resultName);
                            fieldResult.Attributes = MemberAttributes.Public;
                            resultHolder.CodeType.Members.Insert(0, fieldReadOnlyResult);

                            // Add suitable parameter as first constructor argument.
                            constructorResults.Parameters.Insert(0, new CodeParameterDeclarationExpression(typerefResult, resultName));
                            // Add statement to initialise result member.
                            constructorResults.Statements.Insert(0, new CodeAssignStatement(thisArg,
                                                                                            new CodeArgumentReferenceExpression(resultName)));
                        } // End if there is a return statement

                        resultHolder.CodeType.TypeAttributes = TypeAttributes.NestedPrivate;
                        resultHolder.CodeType.IsStruct       = true;

                        resultHolder.CodeType.Members.Add(constructorResults);
                        typeProxy.Members.Add(resultHolder.CodeType);
                    }    // Ends if got results type
                    else // Else no results type
                    {
                        // Absolutely no results (including out parameters) means it's an Action.
                        asyncMethodName = "AsyncActionImpl";
                    } // Ends else no results type

                    // Time to bite the bullet.
                    CodeTypeReference typerefEvent        = new CodeTypeReference(typeEvent.Name);
                    CodeMemberMethod  methodMakeEventArgs = new CodeMemberMethod();
                    methodMakeEventArgs.Name = "Make" + idlMethod.Name + "AsyncEventArgs";

                    // Add missing parameters to EventArgs...
                    constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclException);
                    constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclCancelled);
                    constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclUserState);
                    // Pass through to base class.
                    constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefException);
                    constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefCancelled);
                    constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefUserState);

                    // Add MakeEventArgs method...
                    // Create MakeEventArgs method.
                    methodMakeEventArgs.Attributes = MemberAttributes.Private | MemberAttributes.Static;
                    if (typerefParams != null) // If got params type
                    {
                        methodMakeEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(typerefParams, dataName));
                    }
                    else // Else no params type
                    {
                        // The interface will be passed as the first parameter.
                        methodMakeEventArgs.Parameters.Add(paramProxy);
                    } // Ends else no params type

                    if (typerefResults != null) // If got results type
                    {
                        methodMakeEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(typerefResults, resultName));
                    }
                    methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclException);
                    methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclCancelled);
                    methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclUserState);
                    makeEventArgs.Add(CodeBuilderCommon.argrefException);
                    makeEventArgs.Add(CodeBuilderCommon.argrefCancelled);
                    makeEventArgs.Add(CodeBuilderCommon.argrefUserState);
                    methodMakeEventArgs.Statements.Add(new CodeMethodReturnStatement(
                                                           new CodeObjectCreateExpression(
                                                               typerefEvent, makeEventArgs.Cast <CodeExpression>().ToArray()
                                                               )
                                                           ));
                    methodMakeEventArgs.ReturnType = typerefEvent;
                    typeProxy.Members.Add(methodMakeEventArgs);

                    // Setup call method parameters.
                    methodCall.Attributes = MemberAttributes.Private | MemberAttributes.Static;
                    CodeExpression exprProxyRef;
                    //methodCall.ReturnType = new CodeTypeReference(resultHolder.CodeType.Name);
                    if (typerefParams != null) // If passing parameters
                    {
                        methodCall.Parameters.Add(new CodeParameterDeclarationExpression(typerefParams, dataName));
                        exprProxyRef = new CodeFieldReferenceExpression(argrefCallData, proxyName);
                    }    // Ends if passing parameters
                    else // Else just passing proxy
                    {
                        methodCall.Parameters.Add(new CodeParameterDeclarationExpression(genInterfaceName, proxyName));
                        exprProxyRef = new CodeArgumentReferenceExpression(proxyName);
                    } // Ends else just passing proxy

                    // Add call method body...
                    // Invocation to proxy.
                    CodeMethodReferenceExpression methodProxy = new CodeMethodReferenceExpression(exprProxyRef, idlMethod.Name);
                    CodeMethodInvokeExpression    invokeProxy = new CodeMethodInvokeExpression(methodProxy, callParameters.Cast <CodeExpression>().ToArray());
                    if (idlMethod.Return != null) // If got return type
                    {
                        // TODO - return values.
                        // Add invocation of actual interface method and store result.
                        CodeVariableDeclarationStatement exprResult = new CodeVariableDeclarationStatement(typerefResult, resultName, invokeProxy);
                        methodCall.Statements.Add(exprResult);

                        // Initialise result parameter in Result struct.
                        callResultArgs.Insert(0, new CodeArgumentReferenceExpression(resultName));
                    }    // Ends if got return type
                    else // Else no return type
                    {
                        // Add invocation of actual interface method and ignore result.
                        methodCall.Statements.Add(invokeProxy);
                    } // Ends else no return type

                    if (typerefResults != null) // If got result type
                    {
                        // Create Call return statement.
                        CodeMethodReturnStatement retCall = new CodeMethodReturnStatement(
                            new CodeObjectCreateExpression(typerefResults, callResultArgs.Cast <CodeExpression>().ToArray())
                            );
                        methodCall.Statements.Add(retCall);
                    } // Ends if got result type

                    // Add call method to type.
                    typeProxy.Members.Add(methodCall);

                    // Add async method implementation...
                    if (exprAsyncParamValue == null) // If no params
                    {
                        // Just pass the proxy.
                        exprAsyncParamValue = thisProxyFieldRef;
                    } // Ends if no params

                    methodAsync.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisRaiser, asyncMethodName)
                                                                              , new CodeArgumentReferenceExpression("userState")
                                                                              , exprAsyncParamValue
                                                                              , new CodeMethodReferenceExpression(null, methodCall.Name)
                                                                              , new CodeMethodReferenceExpression(null, methodMakeEventArgs.Name)
                                                                              ));

                    methodInterface.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisProxyFieldRef, idlMethod.Name)
                                                                                  , interfaceCallArgs.Cast <CodeExpression>().ToArray()
                                                                                  ));
                    // Finish up.
                    typeEvent.Members.Add(constructorEventArgs);
                    constructorEventArgs.Attributes = MemberAttributes.Public;
                    ns.Types.Add(typeEvent);
                    typeProxy.Members.Add(methodAsync);
                    typeProxy.Members.Add(methodInterface);
                } // Ends loop over methods
            }     // Ends if got methods
        }
示例#12
0
 abstract public void FinishDictionary(Udbus.Parsing.BuildContext context, Udbus.Parsing.IParamCodeTypeHandler paramtypeHandler);
示例#13
0
 abstract public void StartDictionary(string name, Udbus.Parsing.BuildContext context);
示例#14
0
        public override void GenerateMethods(IDLInterface idlIntf)
        {
            if (idlIntf.Methods != null) // If got methods
            {
                bAddNamespace = idlIntf.Methods.Count > 0;

                foreach (IDLMethod idlMethod in idlIntf.Methods)
                {
                    // Structs for capturing input/output from method.
                    Udbus.Parsing.CodeTypeDeferredStructHolder paramsHolder = new Udbus.Parsing.CodeTypeDeferredStructHolder(idlMethod.Name + "AsyncParams");
                    Udbus.Parsing.CodeTypeDeferredStructHolder resultHolder = new Udbus.Parsing.CodeTypeDeferredStructHolder(idlMethod.Name + "AsyncResult");
                    CodeConstructor constructorResults = new CodeConstructor();
                    CodeConstructor constructorParams = new CodeConstructor();
                    constructorResults.Attributes = constructorParams.Attributes = MemberAttributes.Public;

                    // Create Call method.
                    CodeMemberMethod methodCall = new CodeMemberMethod();
                    methodCall.Name = "Call" + idlMethod.Name;
                    // Actual call to proxy arguments will be added to as we parse IDL arguments.
                    CodeExpressionCollection callParameters = new CodeExpressionCollection();
                    CodeExpressionCollection callResultArgs = new CodeExpressionCollection();
                    CodeExpressionCollection interfaceCallArgs = new CodeExpressionCollection();
                    CodeArgumentReferenceExpression argrefCallData = new CodeArgumentReferenceExpression(dataName);

                    // Event Args
                    string eventName = idlMethod.Name + "EventArgs";
                    CodeTypeDeclaration typeEvent = new CodeTypeDeclaration(eventName);
                    typeEvent.IsClass = true;
                    typeEvent.TypeAttributes = TypeAttributes.Public;
                    typeEvent.BaseTypes.Add(new CodeTypeReference(typeof(AsyncCompletedEventArgs)));
                    CodeConstructor constructorEventArgs = new CodeConstructor();
                    eventsDeclarationHolder.Add(typeEvent);
                    CodeExpressionCollection makeEventArgs = new CodeExpressionCollection();

                    // Event Raiser...
                    string raiserName = "raiser" + idlMethod.Name;
                    CodeTypeReference raiserRef = new CodeTypeReference("AsyncOperationEventRaiser", new CodeTypeReference(eventName));
                    CodeMemberField fieldRaiser = new CodeMemberField(raiserRef, raiserName);
                    fieldRaiser.InitExpression = new CodeObjectCreateExpression(raiserRef);
                    fieldRaiser.Attributes = MemberAttributes.Private;
                    typeProxy.Members.Add(fieldRaiser);

                    // Event raiser EventCompleted Property - unfortunately CodeMemberEvent is useless here since can't add custom add/remove.
                    // So anything other than CSharp is now a bust. Brilliant.
                    CodeSnippetTypeMember eventRaiser = new CodeSnippetTypeMember();
                    eventRaiser.Text = string.Format(@"        public event System.EventHandler<{0}> {1}Completed
            {{
            add {{ this.{2}.CompletedEvent += value; }}
            remove {{ this.{2}.CompletedEvent -= value; }}
            }}
            ", eventName, idlMethod.Name, raiserName
                        ); // Adding text here.

                    //CodeMemberEvent eventRaiser = new CodeMemberEvent();
                    //eventRaiser.Attributes = MemberAttributes.Public;
                    //CodeParamDeclaredType declaredType = new CodeParamDeclaredType(typeEvent);
                    //eventRaiser.Type = new CodeTypeReference(CodeBuilderCommon.EventHandlerType.Name, declaredType.CodeType);
                    //eventRaiser.Name = idlMethod.Name + "Completed";

                    typeProxy.Members.Add(eventRaiser);

                    // Async method.
                    CodeMemberMethod methodAsync = new CodeMemberMethod();
                    methodAsync.Name = idlMethod.Name + "Async";
                    methodAsync.Attributes = MemberAttributes.Public;

                    // Straight-forward interface method.
                    CodeMemberMethod methodInterface = new CodeMemberMethod();
                    methodInterface.Name = idlMethod.Name;
                    methodInterface.Attributes = MemberAttributes.Public;

                    //        CodeComment commentMethod = new CodeComment(idlMethod.Name);
                    //        method.Comments.Add(new CodeCommentStatement(idlMethod.Name));
                    CodeExpressionCollection asyncArgs = new CodeExpressionCollection();
                    Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(contextDeclarationHolder);

                    foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments)
                    {
                        CodeCommentStatement commentMethod = new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type));
                        methodAsync.Comments.Add(commentMethod);
                        methodInterface.Comments.Add(commentMethod);
                        // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                        Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod);
                        ParamCodeTypeFactory paramtypeHolder = new ParamCodeTypeFactory(CodeTypeFactory.Default,
                            idlMethodArg.Direction == "out" ? FieldDirection.Out : FieldDirection.In);
                        Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context);
                        Udbus.Parsing.ICodeParamType paramtype = paramtypeHolder.paramtype;

                        // Arguments.
                        CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name);
                        CodeVariableReferenceExpression varrefMethodArg = new CodeVariableReferenceExpression(idlMethodArg.Name);

                        if (idlMethodArg.Direction == "out") // If out argument
                        {
                            // Add to interface parameters.
                            interfaceCallArgs.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg));

                            // Put into result holding struct...
                            param.Direction = FieldDirection.Out;
                            methodInterface.Parameters.Add(param);

                            CodeTypeReference argType = CodeBuilderCommon.GetReadOnlyCodeReference(paramtypeHolder.paramtype.CodeType);
                            CodeMemberField fieldResultArg = new CodeMemberField(argType, idlMethodArg.Name);
                            fieldResultArg.Attributes = MemberAttributes.Public;
                            resultHolder.CodeType.Members.Add(fieldResultArg);

                            constructorResults.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name));
                            CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression(
                                new CodeThisReferenceExpression(), idlMethodArg.Name
                            );
                            constructorResults.Statements.Add(new CodeAssignStatement(thisArg,
                                new CodeArgumentReferenceExpression(idlMethodArg.Name)));

                            // Add placeholder variables to call method.
                            methodCall.Statements.Add(new CodeVariableDeclarationStatement(paramtype.CodeType, idlMethodArg.Name));

                            // Add appropriate parameter in actual call to interface.
                            callParameters.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg));

                            // Add appropriate parameter in call to result constructor.
                            callResultArgs.Add(new CodeArgumentReferenceExpression(idlMethodArg.Name));

                            // Put into event args class...
                            string fieldEventArgName = idlMethodArg.Name + "_";
                            CodeMemberField fieldEventArg = new CodeMemberField(paramtype.CodeType, fieldEventArgName);
                            fieldEventArg.Attributes = MemberAttributes.Private;
                            typeEvent.Members.Add(fieldEventArg);

                            // Add argument property to EventArgs.
                            CodeMemberProperty propEventArg = new CodeMemberProperty();
                            propEventArg.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                            propEventArg.Name = idlMethodArg.Name;
                            propEventArg.HasGet = true;
                            propEventArg.Type = paramtype.CodeType;
                            propEventArg.GetStatements.Add(new CodeMethodInvokeExpression(null, "RaiseExceptionIfNecessary"));
                            propEventArg.GetStatements.Add(new CodeMethodReturnStatement(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), fieldEventArgName)));
                            typeEvent.Members.Add(propEventArg);

                            // Add constructor parameter and statement to EventArgs.
                            constructorEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name));
                            constructorEventArgs.Statements.Add(new CodeAssignStatement(new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), fieldEventArgName),
                                new CodeArgumentReferenceExpression(idlMethodArg.Name)
                            ));

                            // Add as parameter in call to EventArgs constructor.
                            makeEventArgs.Add(new CodeFieldReferenceExpression(new CodeArgumentReferenceExpression(resultName), idlMethodArg.Name));

                        } // Ends if out argument
                        else // Else in argument
                        {
                            // Add to interface parameters.
                            interfaceCallArgs.Add(varrefMethodArg);
                            // Put into parameter holding struct.
                            CodeMemberField fieldArg = new CodeMemberField(CodeBuilderCommon.GetReadOnlyCodeReference(paramtype.CodeType), idlMethodArg.Name);
                            fieldArg.Attributes = MemberAttributes.Public;
                            paramsHolder.CodeType.Members.Add(fieldArg);

                            constructorParams.Parameters.Add(new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name));
                            CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression(
                                new CodeThisReferenceExpression(), idlMethodArg.Name
                            );
                            constructorParams.Statements.Add(new CodeAssignStatement(thisArg,
                                new CodeArgumentReferenceExpression(idlMethodArg.Name)));

                            // Add appropriate parameter in actual call to interface.
                            callParameters.Add(new CodeFieldReferenceExpression(argrefCallData, idlMethodArg.Name));

                            // Add appropriate parameter to async method parameters constructor call.
                            asyncArgs.Add(new CodeArgumentReferenceExpression(idlMethodArg.Name));

                            // Add parameter to async method.
                            methodAsync.Parameters.Add(param);
                            // Add parameter to interface method.
                            methodInterface.Parameters.Add(param);

                        } // Ends else in argument

                    } // Ends loop over method arguments

                    methodAsync.Parameters.Add(new CodeParameterDeclarationExpression(typeof(object), "userState"));

                    // Add method body, then sort out arguments code...
                    CodeFieldReferenceExpression thisRaiser = new CodeFieldReferenceExpression(
                        new CodeThisReferenceExpression(), raiserName
                    );
                    CodeTypeReference typerefResult = null;
                    if (idlMethod.Return != null) // If method has return type
                    {
                        // Add result to Result type.
                        // TODO replace typeof(string) with actual return type.
                        typerefResult = new CodeTypeReference("???");
                    }

                    CodeTypeReference typerefResults = null;
                    CodeTypeReference typerefParams = null;
                    CodeExpression exprAsyncParamValue = null;
                    string asyncMethodName = "AsyncFuncImpl"; // Default is assuming that function returns something.

                    if (paramsHolder.QuType()) // If got params type
                    {
                        typerefParams = new CodeTypeReference(paramsHolder.CodeType.Name);

                        // Add proxy field to params struct.
                        CodeMemberField memberParamsProxy = new CodeMemberField(new CodeTypeReference("readonly " + genInterfaceName), proxyName);
                        memberParamsProxy.Attributes = MemberAttributes.Public;
                        paramsHolder.CodeType.Members.Insert(0, memberParamsProxy); // TODO: Going to need a using or a fully qualified name.

                        // Add initialisation to constructor
                        constructorParams.Parameters.Insert(0, paramProxy);
                        // Constructor will take proxy as first argument.
                        constructorParams.Statements.Insert(0, assignProxy);

                        paramsHolder.CodeType.TypeAttributes = TypeAttributes.NestedPrivate;
                        paramsHolder.CodeType.IsStruct = true;
                        constructorParams.Attributes = MemberAttributes.Public;
                        paramsHolder.CodeType.Members.Add(constructorParams);
                        typeProxy.Members.Add(paramsHolder.CodeType);

                        asyncArgs.Insert(0, thisProxyFieldRef);
                        exprAsyncParamValue = new CodeObjectCreateExpression(typerefParams, asyncArgs.Cast<CodeExpression>().ToArray());
                    } // Ends if got params type

                    if (resultHolder.QuType()) // If got results type
                    {
                        typerefResults = new CodeTypeReference(resultHolder.CodeType.Name);

                        methodCall.ReturnType = typerefResults;

                        // Setup call method parameters.
                        if (idlMethod.Return != null)
                        {
                            // Add result field to EventArgs.
                            CodeMemberField fieldResult = new CodeMemberField(typerefResult, resultName);
                            fieldResult.Attributes = MemberAttributes.Private;
                            typeEvent.Members.Insert(0, fieldResult);

                            // Add result property to EventArgs.
                            CodeMemberProperty propResult = new CodeMemberProperty();
                            propResult.Attributes = MemberAttributes.Public;
                            propResult.Name = resultName;
                            propResult.HasGet = true;
                            propResult.Type = typerefResult;
                            propResult.GetStatements.Add(new CodeMethodInvokeExpression(null, "RaiseExceptionIfNecessary"));
                            propResult.GetStatements.Add(new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), resultName));
                            typeEvent.Members.Add(propResult);

                            // Add suitable parameter as first EventArgs constructor argument.
                            constructorEventArgs.Parameters.Insert(0, new CodeParameterDeclarationExpression(typerefResult, resultName));
                            // Add statement to initialise result member.
                            CodeFieldReferenceExpression thisArg = new CodeFieldReferenceExpression(
                                new CodeThisReferenceExpression(), resultName
                            );

                            // Include result in parameters to EventArgs in MakeEventArgs statements.
                            makeEventArgs.Insert(0, new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), resultName));

                            // Add result to Result type.
                            CodeTypeReference typerefReadOnlyResult = CodeBuilderCommon.GetReadOnlyCodeReference(typerefResult);
                            CodeMemberField fieldReadOnlyResult = new CodeMemberField(typerefReadOnlyResult, resultName);
                            fieldResult.Attributes = MemberAttributes.Public;
                            resultHolder.CodeType.Members.Insert(0, fieldReadOnlyResult);

                            // Add suitable parameter as first constructor argument.
                            constructorResults.Parameters.Insert(0, new CodeParameterDeclarationExpression(typerefResult, resultName));
                            // Add statement to initialise result member.
                            constructorResults.Statements.Insert(0, new CodeAssignStatement(thisArg,
                                new CodeArgumentReferenceExpression(resultName)));

                        } // End if there is a return statement

                        resultHolder.CodeType.TypeAttributes = TypeAttributes.NestedPrivate;
                        resultHolder.CodeType.IsStruct = true;

                        resultHolder.CodeType.Members.Add(constructorResults);
                        typeProxy.Members.Add(resultHolder.CodeType);

                    } // Ends if got results type
                    else // Else no results type
                    {
                        // Absolutely no results (including out parameters) means it's an Action.
                        asyncMethodName = "AsyncActionImpl";

                    } // Ends else no results type

                    // Time to bite the bullet.
                    CodeTypeReference typerefEvent = new CodeTypeReference(typeEvent.Name);
                    CodeMemberMethod methodMakeEventArgs = new CodeMemberMethod();
                    methodMakeEventArgs.Name = "Make" + idlMethod.Name + "AsyncEventArgs";

                    // Add missing parameters to EventArgs...
                    constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclException);
                    constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclCancelled);
                    constructorEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclUserState);
                    // Pass through to base class.
                    constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefException);
                    constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefCancelled);
                    constructorEventArgs.BaseConstructorArgs.Add(CodeBuilderCommon.argrefUserState);

                    // Add MakeEventArgs method...
                    // Create MakeEventArgs method.
                    methodMakeEventArgs.Attributes = MemberAttributes.Private | MemberAttributes.Static;
                    if (typerefParams != null) // If got params type
                    {
                        methodMakeEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(typerefParams, dataName));
                    }
                    else // Else no params type
                    {
                        // The interface will be passed as the first parameter.
                        methodMakeEventArgs.Parameters.Add(paramProxy);

                    } // Ends else no params type

                    if (typerefResults != null) // If got results type
                    {
                        methodMakeEventArgs.Parameters.Add(new CodeParameterDeclarationExpression(typerefResults, resultName));
                    }
                    methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclException);
                    methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclCancelled);
                    methodMakeEventArgs.Parameters.Add(CodeBuilderCommon.paramdeclUserState);
                    makeEventArgs.Add(CodeBuilderCommon.argrefException);
                    makeEventArgs.Add(CodeBuilderCommon.argrefCancelled);
                    makeEventArgs.Add(CodeBuilderCommon.argrefUserState);
                    methodMakeEventArgs.Statements.Add(new CodeMethodReturnStatement(
                        new CodeObjectCreateExpression(
                            typerefEvent, makeEventArgs.Cast<CodeExpression>().ToArray()
                        )
                    ));
                    methodMakeEventArgs.ReturnType = typerefEvent;
                    typeProxy.Members.Add(methodMakeEventArgs);

                    // Setup call method parameters.
                    methodCall.Attributes = MemberAttributes.Private | MemberAttributes.Static;
                    CodeExpression exprProxyRef;
                    //methodCall.ReturnType = new CodeTypeReference(resultHolder.CodeType.Name);
                    if (typerefParams != null) // If passing parameters
                    {
                        methodCall.Parameters.Add(new CodeParameterDeclarationExpression(typerefParams, dataName));
                        exprProxyRef = new CodeFieldReferenceExpression(argrefCallData, proxyName);

                    } // Ends if passing parameters
                    else // Else just passing proxy
                    {
                        methodCall.Parameters.Add(new CodeParameterDeclarationExpression(genInterfaceName, proxyName));
                        exprProxyRef = new CodeArgumentReferenceExpression(proxyName);

                    } // Ends else just passing proxy

                    // Add call method body...
                    // Invocation to proxy.
                    CodeMethodReferenceExpression methodProxy = new CodeMethodReferenceExpression(exprProxyRef, idlMethod.Name);
                    CodeMethodInvokeExpression invokeProxy = new CodeMethodInvokeExpression(methodProxy, callParameters.Cast<CodeExpression>().ToArray());
                    if (idlMethod.Return != null) // If got return type
                    {
                        // TODO - return values.
                        // Add invocation of actual interface method and store result.
                        CodeVariableDeclarationStatement exprResult = new CodeVariableDeclarationStatement(typerefResult, resultName, invokeProxy);
                        methodCall.Statements.Add(exprResult);

                        // Initialise result parameter in Result struct.
                        callResultArgs.Insert(0, new CodeArgumentReferenceExpression(resultName));

                    } // Ends if got return type
                    else // Else no return type
                    {
                        // Add invocation of actual interface method and ignore result.
                        methodCall.Statements.Add(invokeProxy);

                    } // Ends else no return type

                    if (typerefResults != null) // If got result type
                    {
                        // Create Call return statement.
                        CodeMethodReturnStatement retCall = new CodeMethodReturnStatement(
                            new CodeObjectCreateExpression(typerefResults, callResultArgs.Cast<CodeExpression>().ToArray())
                        );
                        methodCall.Statements.Add(retCall);

                    } // Ends if got result type

                    // Add call method to type.
                    typeProxy.Members.Add(methodCall);

                    // Add async method implementation...
                    if (exprAsyncParamValue == null) // If no params
                    {
                        // Just pass the proxy.
                        exprAsyncParamValue = thisProxyFieldRef;

                    } // Ends if no params

                    methodAsync.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisRaiser, asyncMethodName)
                        , new CodeArgumentReferenceExpression("userState")
                        , exprAsyncParamValue
                        , new CodeMethodReferenceExpression(null, methodCall.Name)
                        , new CodeMethodReferenceExpression(null, methodMakeEventArgs.Name)
                    ));

                    methodInterface.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisProxyFieldRef, idlMethod.Name)
                        , interfaceCallArgs.Cast<CodeExpression>().ToArray()
                    ));
                    // Finish up.
                    typeEvent.Members.Add(constructorEventArgs);
                    constructorEventArgs.Attributes = MemberAttributes.Public;
                    ns.Types.Add(typeEvent);
                    typeProxy.Members.Add(methodAsync);
                    typeProxy.Members.Add(methodInterface);

                } // Ends loop over methods
            } // Ends if got methods
        }
示例#15
0
 public override Udbus.Parsing.BuildContext CreateNestedContext(Udbus.Parsing.BuildContext context)
 {
     return(this.CreateNestedContext(context, new Udbus.Parsing.CodeTypeMemberHolder(this.declaration.Members, this.name)));
 }
示例#16
0
        static public CodeMemberMethod MakeMethod(CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn,
            Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf,
            IDLMethod idlMethod,
            MarshalBuilderHelper codebuilder)
        {
            CodeMemberMethod method = new CodeMemberMethod();
            CodeComment commentMethod = new CodeComment(idlMethod.Name);
            method.Comments.Add(new CodeCommentStatement(idlMethod.Name));
            method.Name = idlMethod.Name;
            method.Attributes = MemberAttributes.Public;

            foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments)
            {
                method.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type)));
            }

            // Context used for all arguments in method.
            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            MakeMethodParameters(codetypefactoryOut, codetypefactoryIn,
                declarationHolder,
                idlIntf,
                method.Name,
                idlMethod.Name,
                idlMethod.Arguments,
                method.Parameters,
                method.Statements,
                context,
                codebuilder
            );

            return method;
        }
        /// <summary>
        /// Given an IDL Method, generate the necessary bits
        /// </summary>
        /// <remarks>Override to expand functionality or replace it</remarks>
        /// <param name="idlIntf"></param>
        /// <param name="idlMethod"></param>
        /// <returns></returns>
        protected virtual CodeMemberMethod HandleMethod(IDLInterface idlIntf, IDLMethod idlMethod)
        {
            // Method.
            CodeMemberMethod method = new CodeMemberMethod();
            method.Comments.Add(new CodeCommentStatement(idlMethod.Name));
            method.Name = idlMethod.Name;

            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);

            foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments)
            {
                method.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type)));
                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod);
                ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForMethod(idlMethodArg.Direction);
                Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context);
                Console.WriteLine(idlMethodArg.Type);
                // Arguments.
                method.Parameters.Add(HandleMethodArgument(idlMethodArg, paramtypeHolder));
            } // Ends loop over method arguments
            return method;
        }
示例#18
0
        static public CodeMemberMethod MakeSignal(CodeNamespace ns, CodeTypeDeclaration typeMarshal, CodeTypeFactory codetypefactoryOut,
            Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf,
            IDLSignal idlSignal,
            MarshalBuilderHelper codebuilder)
        {
            string signalMethodName = "Handle" + CodeBuilderCommon.GetSignalTypeName(idlSignal.Name);

            //// * public class <signal_as_type>Args : EventArgs
            CodeTypeDeclaration typeArgs = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name));
            //typeArgs.BaseTypes.Add(typerefSignalEventArgs);

            // * const string StorageSpaceLowMatchRule = "type=\'signal\',interface=\'<interface>\',member=\'<signal>'";
            CodeMemberField fieldMatchRule = new CodeMemberField(typeof(string), CodeBuilderCommon.GetSignalCompilableName(idlSignal.Name) + "MatchRule");
            fieldMatchRule.InitExpression = new CodePrimitiveExpression(string.Format("type='signal',interface='{0}',member='{1}'", idlIntf.Name, idlSignal.Name));
            fieldMatchRule.Attributes = MemberAttributes.Private | MemberAttributes.Const;
            typeMarshal.Members.Add(fieldMatchRule);
            CodeFieldReferenceExpression fieldrefMatchrule = new CodeFieldReferenceExpression(null, fieldMatchRule.Name);

            // * private Udbus.Core.SignalKey StorageSpaceLowSignalKey { get { return new Udbus.Core.SignalKey(this.ConnectionParameters.Path, this.ConnectionParameters.Interface, "storage_space_low"); } }
            // * private Udbus.Core.SignalEntry StorageSpaceLowSignalEntry { get { return new Udbus.Core.SignalEntry(this.StorageSpaceLowSignalKey, this.HandleStorageSpaceLow); } }
            CodeMethodReferenceExpression methodrefSignal = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), signalMethodName);
            CodeMemberProperty propSignalKey = new CodeMemberProperty();
            propSignalKey.Name = CodeBuilderCommon.GetSignalCompilableName(idlSignal.Name) + "Key";
            propSignalKey.Type = typerefSignalKey;
            propSignalKey.Attributes = MemberAttributes.Private | MemberAttributes.Final;
            propSignalKey.GetStatements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression(typerefSignalKey
                , proprefConnectionParametersPath, proprefConnectionParametersInterface, new CodePrimitiveExpression(idlSignal.Name)
            )));
            CodeMemberProperty propSignalEntry = new CodeMemberProperty();
            propSignalEntry.Name = CodeBuilderCommon.GetSignalCompilableName(idlSignal.Name) + "Entry";
            propSignalEntry.Type = typerefSignalEntry;
            propSignalEntry.Attributes = MemberAttributes.Private | MemberAttributes.Final;
            propSignalEntry.GetStatements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression(typerefSignalEntry
                , new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), propSignalKey.Name)
                , methodrefSignal
            )));
            typeMarshal.Members.Add(propSignalKey);
            typeMarshal.Members.Add(propSignalEntry);

            // * public virtual void RegisterForStorageSpaceLow()
            // * {
            // *     this.RegisterForSignal(StorageSpaceLowMatchRule, this.StorageSpaceLowSignalEntry, this.RegisterSignalHandlers);
            // * }
            CodeMemberMethod methodRegisterForSpecificSignal = new CodeMemberMethod();
            methodRegisterForSpecificSignal.Name = CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name);
            methodRegisterForSpecificSignal.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), RegisterForSignal
                , fieldrefMatchrule
                , new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), propSignalEntry.Name)
                , new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), proprefRegisterSignalHandlers.PropertyName)
            ));
            typeMarshal.Members.Add(methodRegisterForSpecificSignal);

            CodeMemberEvent eventSignal = CodeBuilderCommon.CreateSignalEvent(idlSignal);
            CodeVariableReferenceExpression varrefSignalHandler = new CodeVariableReferenceExpression("signalHandler");
            CodeEventReferenceExpression eventrefSignalHandlerSignal = new CodeEventReferenceExpression(varrefSignalHandler, eventSignal.Name);
            CodeMethodInvokeExpression invokeGetSignalHandler = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), GetSignalHandler);
            CodeTypeReference typerefMarshal = new CodeTypeReference(typeMarshal.Name);
            CodeMemberProperty propEventSignal = new CodeMemberProperty();
            propEventSignal.Name = CodeBuilderCommon.GetSignalEventPropertyName(idlSignal.Name);
            propEventSignal.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            propEventSignal.Type = eventSignal.Type;
            // * return this.GetSignalHandler().storageSpaceLowEvent;
            propEventSignal.GetStatements.Add(new CodeMethodReturnStatement(new CodeEventReferenceExpression(invokeGetSignalHandler, eventSignal.Name)));

            // * <service> signalHandler = this.GetSignalHandler();
            propEventSignal.SetStatements.Add(new CodeVariableDeclarationStatement(typerefMarshal, varrefSignalHandler.VariableName, invokeGetSignalHandler));
            // * if (signalHandler.<signal>Event == null)
            propEventSignal.SetStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(eventrefSignalHandlerSignal, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null))
                // *     signalHandler.RegisterFor<signal>();
                , new CodeExpressionStatement(new CodeMethodInvokeExpression(varrefSignalHandler, methodRegisterForSpecificSignal.Name))
            ));
            // * signalHandler.<signal>Event = value;
            propEventSignal.SetStatements.Add(
                new CodeAssignStatement(eventrefSignalHandlerSignal, new CodePropertySetValueReferenceExpression())
            );
            // * private event System.EventHandler< <signal>Args > <signal>Event { ... }
            // * public System.EventHandler< <signal>Args > <signal>;
            typeMarshal.Members.Add(eventSignal);
            typeMarshal.Members.Add(propEventSignal);

            // * public event System.EventHandler< <signal>Args > <signal>;
            //string eventPropertyName = CodeBuilderCommon.GetSignalEventName(idlSignal.Name);
            //CodeMemberEvent eventSignal = new CodeMemberEvent();
            //eventSignal.Attributes = MemberAttributes.Public;
            //eventSignal.Name = CodeBuilderCommon.GetSignalEventName(idlSignal.Name);
            //CodeTypeReference typerefEvent = new CodeTypeReference(typeof(System.EventHandler<>));
            //typerefEvent.TypeArguments.Add(new CodeTypeReference(CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name)));
            //eventSignal.Type = typerefEvent;
            //typeMarshal.Members.Add(eventSignal);

            //// * public void RegisterFor<signal_compilable>()
            //// * {
            //// *     this.AddMatchInternal("type='signal',interface='<interface>',member='<signal>'");
            //// * }
            //CodeMemberMethod methodRegister = new CodeMemberMethod();
            //methodRegister.Attributes = MemberAttributes.Public;
            //methodRegister.Name = GetSignalRegisterFunctionName(idlSignal.Name);
            //methodRegister.Statements.Add(
            //    new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), AddMatchInternal.Name
            //        ,new CodePrimitiveExpression(string.Format(
            //            "type='signal',interface='{0}',member='{1}'", idlIntf.Name, idlSignal.Name
            //        ))
            //    )
            //);
            //typeMarshal.Members.Add(methodRegister);

            //CodeMemberMethod methodRegisterWithInterface = new CodeMemberMethod();
            //methodRegisterWithInterface.Attributes = MemberAttributes.Public;
            //methodRegisterWithInterface.Name = methodRegister.Name;
            //methodRegisterWithInterface.Parameters.Add(new CodeParameterDeclarationExpression(typerefIRegisterSignalHandlers, register));
            //methodRegisterWithInterface.Statements.Add(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), methodRegister.Name));
            //// * new Udbus.Core.SignalEntry(new Udbus.Core.SignalKey(this.ConnectionParameters.Path, this.ConnectionParameters.Interface, "storage_space_low")
            //methodRegisterWithInterface.Statements.Add(new CodeMethodInvokeExpression(argrefRegister, AddSignalHandler
            //    , new CodeObjectCreateExpression(typerefSignalEntry
            //        , new CodeObjectCreateExpression(typerefSignalKey
            //            , MarshalBuilderHelper.proprefThisConnectionParametersPath
            //            , MarshalBuilderHelper.proprefThisConnectionParametersInterface
            //            , new CodePrimitiveExpression(idlSignal.Name)
            //        )
            //        , methodrefSignal
            //    )
            //));
            //typeMarshal.Members.Add(methodRegisterWithInterface);

            // * Handle<signal>(<signal>Args args)
            CodeMemberMethod method = new CodeMemberMethod();
            CodeComment commentMethod = new CodeComment(idlSignal.Name);
            method.Comments.Add(new CodeCommentStatement(idlSignal.Name));
            method.Name = signalMethodName;
            method.Attributes = MemberAttributes.Public;
            method.Parameters.Add(MarshalBuilderHelper.paramdeclMessageResponse);

            foreach (IDLSignalArgument idlSignalArg in idlSignal.Arguments)
            {
                method.Comments.Add(new CodeCommentStatement(string.Format(" {0} \"{1}\"", idlSignalArg.Name, idlSignalArg.Type)));
            }

            // Context used for all arguments in method.
            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            MakeSignalParameters(typeArgs, codetypefactoryOut,
                declarationHolder,
                idlIntf,
                method.Name,
                idlSignal.Name,
                idlSignal.Arguments,
                method.Parameters,
                method.Statements,
                context,
                codebuilder
            );

            //ns.Types.Add(typeArgs);
            return method;
        }
示例#19
0
        public override string getDictionaryScopedNames(Udbus.Parsing.BuildContext context, out string fullName)
        {
            string result = this.getNames(context, out fullName);

            return(getScopedNamesResult(ref fullName, result));
        }
示例#20
0
        private void GenerateMethod(IDLInterface idlIntf, IDLMethod idlMethod
            , Udbus.Parsing.ICodeTypeDeclarationHolder contextDeclarationHolder
            , CodeTypeReference typerefDbusInterface
            , CodeTypeReference typerefDbusMarshal
            , CodeTypeDeclaration typeProxy)
        {
            // Straight-forward interface method.
            CodeMemberMethod methodInterface = new CodeMemberMethod();
            CodeExpressionCollection interfaceCallArgs = new CodeExpressionCollection();
            methodInterface.Name = idlMethod.Name;
            methodInterface.Attributes = MemberAttributes.Public;
            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(contextDeclarationHolder);

            #region Methods args
            foreach (IDLMethodArgument idlMethodArg in idlMethod.Arguments)
            {
                CodeCommentStatement commentMethod = new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArg.Direction, idlMethodArg.Name, idlMethodArg.Type));
                methodInterface.Comments.Add(commentMethod);
                // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethod);
                ParamCodeTypeFactory paramtypeHolder = new ParamCodeTypeFactory(CodeTypeFactory.Default,
                                                                              idlMethodArg.Direction == "out" ? FieldDirection.Out : FieldDirection.In);
                Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArg.Type, context);
                Udbus.Parsing.ICodeParamType paramtype = paramtypeHolder.paramtype;

                // Arguments.
                CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtype.CodeType, idlMethodArg.Name);
                CodeVariableReferenceExpression varrefMethodArg = new CodeVariableReferenceExpression(idlMethodArg.Name);

                if (idlMethodArg.Direction == "out")
                {
                    // Add to interface parameters.
                    interfaceCallArgs.Add(new CodeDirectionExpression(FieldDirection.Out, varrefMethodArg));
                    // Add parameter to interface method.
                    param.Direction = FieldDirection.Out;
                } else {
                    interfaceCallArgs.Add(varrefMethodArg);
                }
                methodInterface.Parameters.Add(param);

            } // Ends loop over method arguments
            #endregion

            methodInterface.Statements.Add(this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal));
            methodInterface.Statements.Add(new CodeMethodInvokeExpression(varrefTarget, idlMethod.Name, interfaceCallArgs.Cast<CodeExpression>().ToArray()));

            //methodInterface.Statements.Add(new CodeMethodInvokeExpression(new CodeMethodReferenceExpression(thisProxyFieldRef, idlMethod.Name)
            //    , interfaceCallArgs.Cast<CodeExpression>().ToArray()
            //));

            // Finish up.
            typeProxy.Members.Add(methodInterface);
        }
示例#21
0
        }                                              // { get { return CodeBuilderCommon.DictionaryType; } }

        public override void StartDictionary(string name, Udbus.Parsing.BuildContext context)
        {
            base.StartDictionary(name, context);
            this.name = name;
        }
示例#22
0
 public override void StartStruct(string name, string fullName, Udbus.Parsing.BuildContext context)
 {
     base.StartStruct(name, fullName, context);
     this.Declaration.Name = fullname;
 }
示例#23
0
 public override string getNames(Udbus.Parsing.BuildContext context, out string fullName)
 {
     return(Udbus.Parsing.IDLArgumentTypeNameBuilderBase.getNameImpl(context, this.signal.Name, out fullName));
 }
示例#24
0
 public override void StartDictionary(string name, Udbus.Parsing.BuildContext context)
 {
     System.Diagnostics.Debug.WriteLine(string.Format("Starting dictionary {0}", name));
 }
        protected virtual ParamCodeTypeFactory HandleSignalArgument(IDLInterface idlIntf, IDLSignal idlSignal, IDLSignalArgument idlSignalArg)
        {
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLSignalArgumentTypeNameBuilder(idlIntf, idlSignal);
            ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForMethod("in");
            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlSignalArg.Type, context);

            // Arguments
            return paramtypeHolder;
        }
        static Udbus.Serialization.UdbusConnector TestDbusCalls(Udbus.Serialization.IUdbusTransport connection, PreNextActionDelegate preNextAction)
        {
            //int result = -1;
            System.Threading.ManualResetEvent stop = new System.Threading.ManualResetEvent(false);
            //Udbus.v4v.v4vConnection connection = new Udbus.v4v.v4vConnection(Console_io_debug);
            //Udbus.Serialization.ManagedDbusIo dbio;
            //connection.PopulateDbio(ref dbio);

            //Udbus.Core.UdbusFunctions.dbus_auth(ref dbio, "Dude");
            Udbus.Serialization.UdbusConnector connector = Udbus.Serialization.UdbusConnector.CreateAuthorised(connection);

            Udbus.Serialization.UdbusMessageBuilderTracker builder = new Udbus.Serialization.UdbusMessageBuilderTracker();

            // Visitors
            Udbus.Core.IUdbusMessageVisitor visitor = new Udbus.Core.UdbusMessageVisitorDumpXen();
            Udbus.Core.IUdbusMessageVisitor visitorTrack = new Udbus.Core.UdbusMessageVisitorFind(builder);
            Udbus.Core.IUdbusMessageVisitor visitors = new Udbus.Core.UdbusMessageVisitorMulti(visitor, visitorTrack);

            // Udbus.Serialization.NMessageStruct.UdbusMessageHandle recv;

            //preNextAction("Hello");

            //// Hello.
            //using (var msg = builder.UdbusMethodMessage(
            //                    "org.freedesktop.DBus", "/org/freedesktop/DBus",
            //                    "org.freedesktop.DBus", "Hello").Message)
            //{
            //    result = connector.Send(msg);
            //    Console.WriteLine("Hello send result: {0}", result);
            //}
            ////var recv = connector.Receive(out result);
            //result = connector.ReceiveStruct(out recv);
            //Console.WriteLine("Hello recv result: {0}. msg: {1}", result, recv);
            TestDbusHelloImpl(builder, visitors, connector, stop, preNextAction);

            // Get property.
            //TestDbusGetPropertyImpl(builder, visitors, connector, stop, preNextAction);

            #if _LISTVMS
            preNextAction("List VMs");

            using (var msg = builder.UdbusMethodMessage(
                "com.citrix.xenclient.xenmgr", "/",
                "com.citrix.xenclient.xenmgr",
                "list_vms").Message)
            {
                result = connector.Send(msg);
                Console.WriteLine("list_vms send result: {0}", result);
            }
            using (var msg = Udbus.Core.UdbusVisitorFunctions.LoopUdbusFind(connector, visitors, Console.Out, stop).Handle)
            {
                msg.HandleToStructure(out recv);
                Console.WriteLine("list_vms recv result: {0}. msg: {1}", result, recv);

                Udbus.Serialization.UdbusMessageReader reader = new Udbus.Serialization.UdbusMessageReader(msg);
                uint counter = 0;

                foreach (Udbus.Serialization.UdbusMessageReader subreader in reader.ArrayReader(Udbus.Types.dbus_type.DBUS_OBJECTPATH))
                {
                    Udbus.Types.UdbusObjectPath op;
                    result = subreader.ReadObjectPath(out op);
                    if (result != 0)
                    {
                        Console.WriteLine("Error ! {0:d}/0x{0:x8}", result);
                    }
                    Console.WriteLine("Entry {0:d2}: {1}", counter++, op);
                }
            } // Ends using ListNames response

            #endif // _LISTVMS

            // These days GetAllProperties tends to be blocked by firewall
            #if _GETALLPROPERTIES
            preNextAction("GetAllProperties");
            using (var msg = builder.UdbusMethodMessage(
                "com.citrix.xenclient.xenmgr", "/",
                "org.freedesktop.DBus.Properties", "GetAll").Message)
            {
                Udbus.Types.dbus_sig signature = Udbus.Types.dbus_sig.Initialiser;
                signature.a[0] = Udbus.Types.dbus_type.DBUS_STRING;
                signature.a[1] = Udbus.Types.dbus_type.DBUS_INVALID;
                builder.SetSignature(ref signature)
                    .BodyAdd(4096)
                    .BodyAdd_String("com.citrix.xenclient.xenmgr.config")
                ;
                result = connector.Send(msg);
                Console.WriteLine("GetAllProperties send result: {0}", result);
            }
            try
            {
                Udbus.Core.UdbusMessagePair recvData = Udbus.Core.UdbusVisitorFunctions.LoopUdbusFind(connector, visitors, Console.Out, stop);
                recv = recvData.Data;
                if (recv.typefield.type != Udbus.Types.dbus_msg_type.DBUS_TYPE_ERROR)
                {
                    Udbus.Serialization.UdbusMessageReader reader = new Udbus.Serialization.UdbusMessageReader(recvData.Handle);
                    do
                    {
            #if !READASVARIANT
                        Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(new Udbus.Parsing.CodeTypeNoOpHolder());
                        Udbus.Serialization.Variant.UdbusVariantIn variantIn = new Udbus.Serialization.Variant.UdbusVariantIn();
                        Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new Udbus.Parsing.IDLArgumentTypeNameBuilderNoOp();
                        // It's a dictionary of strings -> variants.
                        //IDictionary<string, Udbus.Containers.dbus_union> properties;
                        IEnumerable<KeyValuePair<string, Udbus.Containers.dbus_union>> properties;
                        reader.MarshalDict(Udbus.Serialization.UdbusMessageReader.ReadString,
                            Udbus.Serialization.UdbusMessageReader.ReadVariant,
                            out properties);
                        //Udbus.Types.dbus_sig sig = Udbus.Types.dbus_sig.Initialiser;
                        //result = reader.ReadSignature(ref sig);
                        //Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(variantIn, nameBuilder, sig.a, context);
                        foreach (KeyValuePair<string, Udbus.Containers.dbus_union> entry in properties)
                        {
                            Console.WriteLine("{0} => {1}", entry.Key, entry.Value.ToString());
                        }

            #else // !READASVARIANT
                        Udbus.Types.dbus_sig sig = Udbus.Types.dbus_sig.Initialiser;
                        result = reader.ReadSignature(ref sig);
                        if (result != 0)
                        {
                            Console.WriteLine("Error reading property variant signature: {0}", result);
                            break;
                        }
                        string isopath;
                        result = reader.ReadString(out isopath);
                        if (result != 0)
                        {
                            Console.WriteLine("Error reading property variant string: {0}", result);
                            break;
                        }

                        Console.WriteLine("iso_path: {0}", isopath);
            #endif // READASVARIANT
                    } while (false);
                }
                else
                {
                    Console.WriteLine("Getting the property failed. Boooooo ");
                }
            }
            catch (System.Runtime.InteropServices.SEHException seh)
            {
                Console.WriteLine("Error: " + seh.ToString());
            }
            #endif //_GETALLPROPERTIES

            #if _LISTNAMES
            preNextAction("ListNames");

            // List Names.
            using (var msg = builder.UdbusMethodMessage(
                "org.freedesktop.DBus", "/org/freedesktop/DBus",
                "org.freedesktop.DBus", "ListNames").Message)
            {
                result = connector.Send(msg);
                Console.WriteLine("ListNames send result: {0}", result);
            }

            //result = connector.ReceiveStruct(out recv);
            //Console.WriteLine("ListNames recv result: {0}. msg: {1}", result, recv);

            //using (var msg = connector.ReceiveHandle(out result))
            using(var msg = Udbus.Core.UdbusVisitorFunctions.LoopUdbusFind(connector, visitors, Console.Out, stop).Handle)
            {
                //result = connector.ReceiveStruct(out recv);
                msg.HandleToStructure(out recv);
                Console.WriteLine("ListNames recv result: {0}. msg: {1}", result, recv);

                Udbus.Serialization.UdbusMessageReader reader = new Udbus.Serialization.UdbusMessageReader(msg);
                uint counter = 0;

                foreach (Udbus.Serialization.UdbusMessageReader subreader in reader.ArrayReader(Udbus.Types.dbus_type.DBUS_STRING))
                {
                    string name = subreader.ReadStringValue(out result);
                    if (result != 0)
                    {
                        Console.WriteLine("Error ! {0:d}/0x{0:x8}", result);
                    }
                    Console.WriteLine("Entry {0:d2}: {1}", counter++, name);
                }
            } // Ends using ListNames response
            #endif // _LISTNAMES

            // read_icon
            TestDbusReadIcon(builder, visitors, connector, stop, preNextAction);

            #if _GETSIGNAL
            preNextAction("AddMatch");

            // AddMatch for signal.
            using (var msg = builder.UdbusMethodMessage(
                "org.freedesktop.DBus", "/org/freedesktop/DBus",
                "org.freedesktop.DBus", "AddMatch").Message)
            {
                Udbus.Types.dbus_sig signature = Udbus.Types.dbus_sig.Initialiser;
                signature.a[0] = Udbus.Types.dbus_type.DBUS_STRING;
                signature.a[1] = Udbus.Types.dbus_type.DBUS_INVALID;
                builder.SetSignature(ref signature)
                    .BodyAdd(4096)
                    .BodyAdd_String("type='signal',interface='com.citrix.xenclient.xenmgr.host',member='storage_space_low'")
                    //.BodyAdd_String("type='signal',interface='com.citrix.xenclient.xenmgr.host'")
                ;
                result = connector.Send(msg);
                Console.WriteLine("AddMatch send result: {0}", result);

            }

            preNextAction("LoopSignals");

            // Handle signals and other bits of magic.
            //Console.TreatControlCAsInput = true;
            Console.CancelKeyPress += delegate(Object sender, ConsoleCancelEventArgs consoleargs)
            {
                consoleargs.Cancel = true;
                Console.WriteLine("Setting stop event...");
                stop.Set();
                connection.Cancel();
            };

            try
            {
                Udbus.Core.UdbusVisitorFunctions.LoopUdbus(connector, visitor, Console.Out, stop);
            }
            catch (System.Runtime.InteropServices.SEHException seh)
            {
                Console.WriteLine("Error: " + seh.ToString());
            }
            #endif // _GETSIGNAL

            #if HAVESOMECCODE
            r = 0;
            msg = NULL;
            msg = dbus_msg_new_method_call(serial++,
            "org.freedesktop.DBus", "/org/freedesktop/DBus",
            "org.freedesktop.DBus", "AddMatch");
            if (!msg) {
            dio.io_debug(dio.logpriv, "Unable to create method message for AddMatch\n");
            exit(1);
            }
            MessageInfo::dumpMethodSend(&io_debug, msg);
            dbus_sig signature;
            signature.a[0] = DBUS_STRING;
            signature.a[1] = DBUS_INVALID;
            dbus_msg_set_signature(msg, &signature);
            dbus_msg_body_add(msg, 4096);
            //r |= dbus_msg_body_add_string(msg, "type='signal',interface='com.citrix.xenclient.xenmgr.host'");
            //r |= dbus_msg_body_add_string(msg, "type='method_call'");
            r |= dbus_msg_body_add_string(msg, "type='signal',interface='com.citrix.xenclient.xenmgr.host'");
            r |= dbus_msg_send(&dio, msg);

            loop_dbus(dio, visitor);
            #endif // HAVESOMECCODE
            Console.WriteLine("Press <ENTER> to end connection");
            Console.ReadLine();

            return connector;
        }
示例#27
0
 public override void StartStruct(string name, string fullName, Udbus.Parsing.BuildContext context)
 {
     base.StartStruct(name, fullName, context);
     this.declaration = new CodeTypeDeclaration(name);
 }
        /// <summary>
        /// Given an IDLProperty, generate all the necessaries
        /// </summary>
        /// <remarks>Override to expand functionality or replace it</remarks>
        /// <param name="idlIntf"></param>
        /// <param name="idlProperty"></param>
        /// <returns></returns>
        public virtual CodeTypeMember HandleProperty(IDLInterface idlIntf, IDLProperty idlProperty)
        {
            CodeMemberProperty property = new CodeMemberProperty();
            property.Comments.Add(new CodeCommentStatement(idlProperty.Name));
            property.Name = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
            property.Attributes = MemberAttributes.Abstract;
            IDLMethodArgument idlMethodArgGet = new IDLMethodArgument { Direction = "out", Name = "value", Type = idlProperty.Type };
            IDLMethod idlMethodGet = new IDLMethod
            {
                Arguments = new List<IDLMethodArgument>(new IDLMethodArgument[] { idlMethodArgGet }),
                Name = "get",
            };
            Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLMethodArgumentTypeNameBuilder(idlIntf, idlMethodGet);
            property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlMethodArgGet.Direction, idlMethodArgGet.Name, idlMethodArgGet.Type)));
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            ParamCodeTypeFactory paramtypeHolder = this.CreateParamCodeTypeFactoryForProperty(idlIntf, idlProperty.Name, idlMethodArgGet.Name, idlMethodArgGet.Type, idlMethodArgGet.Direction);
            Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolder, nameBuilder, idlMethodArgGet.Type, context);

            // Arguments.
            CodeParameterDeclarationExpression param = new CodeParameterDeclarationExpression(paramtypeHolder.paramtype.CodeType, idlMethodArgGet.Name);
            property.Type = paramtypeHolder.paramtype.CodeType;
            property.HasGet = CodeBuilderCommon.HasGet(idlProperty);
            property.HasSet = CodeBuilderCommon.HasSet(idlProperty);
            property.Parameters.Add(param);

            return property;
        }
示例#29
0
        public override void GenerateProperties(IDLInterface idlIntf)
        {
            // Properties.
            if (idlIntf.Properties != null && idlIntf.Properties.Count > 0) // If got properties
            {
                int firstPropertyIndex = type.Members.Count - 1;
                Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);

                DictCreatorFactory dictfactoryPropertyOut = new marshal.outward.DictCreatorMarshalOutPropertyFactory();
                CodeTypeFactory codetypefactoryPropertyOut = new CodeTypeFactory(new marshal.outward.StructCreatorMarshalOutFactory(), dictfactoryPropertyOut, dictfactoryPropertyOut);

                foreach (IDLProperty idlProperty in idlIntf.Properties)
                {
                    bool hasGet = CodeBuilderCommon.HasGet(idlProperty);
                    bool hasSet = CodeBuilderCommon.HasSet(idlProperty);

                    if (!hasGet && !hasSet)
                    {
                        continue;
                    }

                    MakeProperty(codetypefactoryPropertyOut, codetypefactoryIn, declarationHolder, idlIntf, type, idlProperty, hasGet, hasSet, context);

                } // Ends loop over properties
            } // Ends if got properties
        }