Example #1
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);
 }
Example #2
0
        public override void PreProcess()
        {
            DictCreatorFactory dictfactoryIn = new marshal.inward.DictCreatorMarshalInFactory();
            DictCreatorFactory dictfactoryOut = new marshal.outward.DictCreatorMarshalOutFactory();

            codetypefactoryOut = new CodeTypeFactory(new marshal.outward.StructCreatorMarshalOutFactory(), dictfactoryOut, dictfactoryOut);
            codetypefactoryIn = new CodeTypeFactory(new marshal.inward.StructCreatorMarshalInFactory(), dictfactoryIn, dictfactoryIn);

            stmtAssignConnectionParameters = new CodeAssignStatement(fieldrefConnectionParameters, CodeBuilderCommon.argrefConnectionParameters);
            fieldrefDefaultConnectionParams = new CodeFieldReferenceExpression(null, DefaultConnectionParametersName);
            stmtAssignServiceConnectionParameters = new CodeAssignStatement(CodeBuilderCommon.fieldrefServiceConnectionParameters, CodeBuilderCommon.argrefServiceConnectionParameters);

            declarationHolderCustomTypesNs = new Udbus.Parsing.CodeTypeDeferredNamespaceDeclarationHolder(CodeBuilderCommon.nsDbusMarshalCustom);
            // If utilised, this namespace is nested in service's namespace.
            declarationHolderDictionaryMarshalNs = new Udbus.Parsing.CodeTypeDeferredNamespaceDeclarationHolder(CodeBuilderCommon.nsDbusMarshalNested);

            declarationHolder = new Udbus.Parsing.CodeMemberDeferredClassHolder(declarationHolderCustomTypesNs
                , "Marshal"
                , declarationHolderDictionaryMarshalNs
                , CodeBuilderCommon.GetNameMarshalDictionary()
            );
        }
Example #3
0
 protected ParamCodeTypeFactory(CodeTypeFactory codetypeFactory)
     : this(codetypeFactory, FieldDirection.In)
 {
 }
Example #4
0
 public StructCreatorFullName(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
     : base(codetypeFactory, owner)
 {
 }
Example #5
0
 //public StructCreator(IParamCodeTypeHandler owner)
 public StructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
     : base(owner)
 {
     this.codetypeFactory = codetypeFactory;
 }
Example #6
0
 public DictCreatorIn(CodeTypeFactory codetypeFactory)
     : base(codetypeFactory)
 {
 }
 internal override Udbus.Parsing.IStructParamCodeTypeHandler CreateStructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
 {
     return new StructCreatorFullName(codetypeFactory, owner);
 }
Example #8
0
 internal Udbus.Parsing.IStructParamCodeTypeHandler CreateStructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
 {
     return(this.structCreatorFactory.CreateStructCreator(codetypeFactory, owner));
 }
Example #9
0
        static public void PreMakeSignals(CodeTypeDeclaration typeMarshal,
            CodeTypeFactory codetypefactoryOut,
            CodeTypeFactory codetypefactoryIn,
            Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf
            )
        {
            // * private void AddMatchInternal(string matchrule)
            CodeMemberMethod methodAddMatch = MakeMethod(codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, AddMatchInternal, new MarshalBuilderHelperSignalAddMatchMethod());
            methodAddMatch.Name = AddMatchInternalName; // Change the name to prevent name collision.
            methodAddMatch.Attributes = MemberAttributes.Private;
            typeMarshal.Members.Add(methodAddMatch);

            // * protected void RegisterForSignal(string matchrule, Udbus.Core.SignalEntry signalEntry, params Udbus.Core.IRegisterSignalHandlers[] registers)
            // * {
            // *     this.AddMatchInternal(matchrule);
            // *     Udbus.Core.RegisterSignalHandlerFunctions.RegisterForSignal(signalEntry, registers);
            // * }
            CodeMemberMethod methodRegisterForSignal = new CodeMemberMethod();
            methodRegisterForSignal.Name = RegisterForSignal;
            CodeParameterDeclarationExpression paramdeclRegisters = new CodeParameterDeclarationExpression(typerefIRegisterSignalHandlersArray, registers);
            paramdeclRegisters.CustomAttributes.Add(CodeBuilderCommon.attribParams);
            methodRegisterForSignal.Parameters.Add(paramdeclMatchRule);
            methodRegisterForSignal.Parameters.Add(paramdeclSignalEntry);
            methodRegisterForSignal.Parameters.Add(paramdeclRegisters);
            methodRegisterForSignal.Statements.Add(invokeAddMatchInternal);
            methodRegisterForSignal.Statements.Add(invokeRegisterForSignal);
            typeMarshal.Members.Add(methodRegisterForSignal);

            // * protected Udbus.Core.IRegisterSignalHandlers RegisterSignalHandlers { get { return this.serviceConnectionParameters.RegisterSignalHandlers; } }
            CodeMemberProperty propRegisterSignalHandlers = new CodeMemberProperty();
            propRegisterSignalHandlers.Attributes = MemberAttributes.Private | MemberAttributes.Final;
            propRegisterSignalHandlers.Name = proprefRegisterSignalHandlers.PropertyName;

            propRegisterSignalHandlers.Type = typerefIRegisterSignalHandlers;
            propRegisterSignalHandlers.GetStatements.Add(returnServiceParamsRegisterSignalHandlers);
            typeMarshal.Members.Add(propRegisterSignalHandlers);

            // * private static object lockGlobalSignalHandlers = new object();
            CodeMemberField fieldLockGlobalSignalHandlers = new CodeMemberField(typeof(object), "lockGlobalSignalHandlers");
            fieldLockGlobalSignalHandlers.Attributes = MemberAttributes.Static | MemberAttributes.Private;
            fieldLockGlobalSignalHandlers.InitExpression = new CodeObjectCreateExpression(fieldLockGlobalSignalHandlers.Type);
            typeMarshal.Members.Add(fieldLockGlobalSignalHandlers);
            // * private static System.Collections.Generic.Dictionary<Udbus.Serialization.DbusConnectionParameters, <interface>Service> globalSignalHandlers = new System.Collections.Generic.Dictionary<Udbus.Serialization.DbusConnectionParameters, <interface>Service);
            CodeTypeReference typerefGlobalSignalHandlers = new CodeTypeReference(typeof(Dictionary<,>));
            CodeTypeReference typerefMarshal = new CodeTypeReference(typeMarshal.Name);
            typerefGlobalSignalHandlers.TypeArguments.Add(CodeBuilderCommon.typerefConnectionParameters);
            typerefGlobalSignalHandlers.TypeArguments.Add(typerefMarshal);
            CodeMemberField fieldGlobalSignalHandlers = new CodeMemberField(typerefGlobalSignalHandlers, "globalSignalHandlers");
            fieldGlobalSignalHandlers.Attributes = MemberAttributes.Static | MemberAttributes.Private;
            fieldGlobalSignalHandlers.InitExpression = new CodeObjectCreateExpression(fieldGlobalSignalHandlers.Type);
            typeMarshal.Members.Add(fieldGlobalSignalHandlers);

            CodeMemberMethod methodGetSignalHandler = new CodeMemberMethod();
            methodGetSignalHandler.Name = GetSignalHandler;
            methodGetSignalHandler.Attributes = MemberAttributes.Private;
            methodGetSignalHandler.ReturnType = typerefMarshal;
            CodeVariableReferenceExpression varrefLocalSignalHandler = new CodeVariableReferenceExpression("localSignalHandler");
            CodeVariableReferenceExpression varrefLookupSignalHandler = new CodeVariableReferenceExpression("lookupSignalHandler");
            CodeFieldReferenceExpression fieldrefLockGlobalSignalHandlers = new CodeFieldReferenceExpression(null, fieldLockGlobalSignalHandlers.Name);
            CodeFieldReferenceExpression fieldrefGlobalSignalHandlers = new CodeFieldReferenceExpression(null,  fieldGlobalSignalHandlers.Name);

            methodGetSignalHandler.Statements.Add(new CodeVariableDeclarationStatement(typerefMarshal, varrefLocalSignalHandler.VariableName, new CodePrimitiveExpression(null)));
            methodGetSignalHandler.Statements.Add(new CodeVariableDeclarationStatement(typerefMarshal, varrefLookupSignalHandler.VariableName));
            CodeTypeReferenceExpression typerefexprMonitor = new CodeTypeReferenceExpression(typeof(System.Threading.Monitor));
            // * System.Threading.Monitor.Enter(lockGlobalSignalHandlers);
            methodGetSignalHandler.Statements.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(typerefexprMonitor, "Enter", fieldrefLockGlobalSignalHandlers)));

            methodGetSignalHandler.Statements.Add(new CodeTryCatchFinallyStatement(
                new CodeStatement[] // * try {
                {
                    // * if (globalSignalHandlers.TryGetValue(this.ConnectionParameters, out lookupSignalHandler) == false)
                    // * {
                    new CodeConditionStatement(new CodeBinaryOperatorExpression(new CodeMethodInvokeExpression(fieldrefGlobalSignalHandlers, "TryGetValue"
                        , proprefConnectionParameters, new CodeDirectionExpression(FieldDirection.Out, varrefLookupSignalHandler)
                        )
                        , CodeBinaryOperatorType.IdentityEquality
                        , new CodePrimitiveExpression(false)
                        )
                        , new CodeStatement[]
                        {
                            // * globalSignalHandlers[this.ConnectionParameters] = this;
                            new CodeAssignStatement(new CodeIndexerExpression(fieldrefGlobalSignalHandlers, proprefConnectionParameters), new CodeThisReferenceExpression())
                        }
                        , new CodeStatement[] // else
                        {
                            // * localSignalHandler = lookupSignalHandler;
                            new CodeAssignStatement(varrefLocalSignalHandler, varrefLookupSignalHandler)
                        }
                    // * }
                    )
                }
                ,new CodeCatchClause[]{} // * } catch {
                ,new CodeStatement[] // * } finally {
                {
                    // * System.Threading.Monitor.Exit(lockGlobalSignalHandlers);
                    new CodeExpressionStatement(new CodeMethodInvokeExpression(typerefexprMonitor, "Exit", fieldrefLockGlobalSignalHandlers))
                } // * }
            ));

            // * if (localSignalHandler == null)
            methodGetSignalHandler.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(varrefLocalSignalHandler, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null))
                // * localSignalHandler = this;
                , new CodeAssignStatement(varrefLocalSignalHandler, new CodeThisReferenceExpression())
            ));
            // * return localSignalHandler;
            methodGetSignalHandler.Statements.Add(new CodeMethodReturnStatement(varrefLocalSignalHandler));
            typeMarshal.Members.Add(methodGetSignalHandler);
        }
Example #10
0
 static public CodeMemberMethod MakeSignal(CodeNamespace  ns,
     CodeTypeDeclaration typeMarshal,
     CodeTypeFactory codetypefactoryOut,
     Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
     IDLInterface idlIntf,
     IDLSignal idlMethod)
 {
     return MakeSignal(ns, typeMarshal, codetypefactoryOut, declarationHolder, idlIntf, idlMethod, new MarshalBuilderHelperSignal());
 }
Example #11
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;
        }
Example #12
0
 private static CodeMemberProperty MakePropertySet(CodeMemberProperty property, CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn,
     Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
     IDLInterface idlIntf,
     IDLProperty idlProperty,
     Udbus.Parsing.BuildContext context,
     MarshalBuilderHelper codebuilder)
 {
     List<IDLMethodArgument> arguments = new List<IDLMethodArgument>(new IDLMethodArgument[]
     {
         //<arg name="interface_name" type="s"/>
         //<arg name="property_name" type="s"/>
         new IDLMethodArgument{ Name="interface_name", Type="s", Direction="in" },
         new IDLMethodArgument{ Name="property_name", Type="s", Direction="in" },
         //<arg name="value" type="<PropertyType>"/>
         new IDLMethodArgument{ Name="value", Type=idlProperty.Type, Direction="in"}
     }
     );
     MakeMethodParameters(codetypefactoryOut, codetypefactoryIn,
         declarationHolder,
         idlIntf,
         "Set",
         idlProperty.Name,
         arguments,
         new CodeParameterDeclarationExpressionCollection(),
         property.SetStatements,
         context,
         codebuilder
     );
     return property;
 }
Example #13
0
 private static CodeMemberProperty MakePropertySet(CodeMemberProperty property, CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn,
     Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
     IDLInterface idlIntf,
     IDLProperty idlProperty,
     Udbus.Parsing.BuildContext context)
 {
     return MakePropertySet(property, codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, idlProperty, context, new MarshalBuilderHelperProperty());
 }
Example #14
0
        private static void MakeProperty(CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn, Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf, CodeTypeDeclaration typeMarshal, IDLProperty idlProperty, bool hasGet, bool hasSet,
            Udbus.Parsing.BuildContext context)
        {
            CodeMemberProperty property = new CodeMemberProperty();
            property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            property.Name = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
            property.HasGet = hasGet;
            property.HasSet = hasSet;

            property.Comments.Add(new CodeCommentStatement(string.Format("{0} {1} \"{2}\"", idlProperty.Access, idlProperty.Name, idlProperty.Type)));
            // Parse the type string for the argument, creating required structs as we go, and returning a type for the argument.
            // We use the out factory because its out types we have to return and they tend to be less forgiving than in types.
            property.Type = CodeBuilderCommon.PropertyType(codetypefactoryOut, idlProperty.Type);

            if (hasGet) // If gettable property
            {
                MakePropertyGet(property, codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, idlProperty, context);

            } // Ends if gettable property

            if (hasSet) // If settable property
            {
                MakePropertySet(property, codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, idlProperty, context);

            } // Ends if settable property

            typeMarshal.Members.Add(property);
        }
        public virtual void MakeInArgument(CodeTypeFactory codetypefactoryIn
            , string idlMethodName
            , ref int nInArgCounter
            , Udbus.Parsing.BuildContext context
            , ref CodeThrowExceptionStatement throwargInPrev
            , IDLMethodArgument idlMethodArg
            , Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder
            , ref ParamCodeTypeHolderMarshalBase paramtypeHolder
            , ref CodeTypeReference typerefParam
            , out CodeConditionStatement condVarResult)
        {
            marshal.inward.ParamCodeTypeHolderMarshalIn paramtypeHolderIn = new marshal.inward.ParamCodeTypeHolderMarshalIn(codetypefactoryIn);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolderIn, nameBuilder, idlMethodArg.Type, context);
            paramtypeHolder = paramtypeHolderIn;
            /*typerefParamIter = */
            typerefParam = paramtypeHolder.paramtype.CodeType;

            condVarResult = new CodeConditionStatement(
                // * if (this.result == 0)
                exprResultOk
                , new CodeStatement[] // True statements
                {
                    // * this.result = builder.Marshal<arg_type>(<marshal_function>, <arg_name>);
                    new CodeAssignStatement(fieldrefResult,
                        paramtypeHolderIn.BuildWriteExpression(varrefBuilder,
                            MarshalArgument(idlMethodName, idlMethodArg)))
                }
                , new CodeStatement[] // False statements
                {
                    throwargInPrev
                }
                );

            throwargInPrev = new CodeThrowExceptionStatement(
                new CodeMethodInvokeExpression(MarshalBuilderHelper.typerefexprArgumentInException, "Create",
                    new CodePrimitiveExpression(nInArgCounter + 1),
                    new CodePrimitiveExpression(idlMethodArg.Name),
                    new CodeTypeOfExpression(typerefParam),
                    fieldrefResult,
                    new CodePrimitiveExpression(idlMethodName),
                    fieldrefConnectionParameters
                )
            );

            ++nInArgCounter;
        }
Example #16
0
        static public void MakeSignalParameters(CodeTypeDeclaration typedeclArgs,
            CodeTypeFactory codetypefactoryOut,
            Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf,
            string methodName,
            string idlSignalName,
            IList<IDLSignalArgument> arguments,
            CodeParameterDeclarationExpressionCollection parameters,
            CodeStatementCollection statements,
            Udbus.Parsing.BuildContext context,
            MarshalBuilderHelper codebuilder)
        {
            CodeStatementCollection statementsTryRecv = new CodeStatementCollection();
            int nOutArgCounter = 0;
            List<CodeMethodInvokeExpression> invokemethodsBuild = new List<CodeMethodInvokeExpression>();
            CodeConditionStatement condOut = null; // Root if statement for out parameters.
            CodeConditionStatement condOutIter = null; // Most nested if statement for out parameters.
            CodeStatementCollection stmtsFinishResult = new CodeStatementCollection();
            CodeTypeReference typerefParamIter = CodeBuilderCommon.typerefUnknownParameters;
            string argNameIter = arguments != null && arguments.Count > 0 ? arguments[0].Name : "UnknownParameters";

            CodeThrowExceptionStatement throwargOutPrev = codebuilder.CreateArgumentOutException(idlSignalName);

            // WAXME
            //CodeConstructor constructorArgs = new CodeConstructor();
            //constructorArgs.Attributes = MemberAttributes.Public;
            foreach (IDLSignalArgument idlSignalArg in arguments)
            {
                argNameIter = idlSignalArg.Name;

                // 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, idlMethodArg);
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLArgumentTypeNameBuilder(idlIntf, methodName);
                ParamCodeTypeHolderMarshalBase paramtypeHolder = null;
                CodeTypeReference typerefParam = null;
                if (condOut == null)
                {
                    codebuilder.PrefixOutParams(ref condOut, ref condOutIter, idlSignalName, ref nOutArgCounter, ref throwargOutPrev);
                }

                // Handle the signal argument in the message.
                CodeConditionStatement condVarResult;
                codebuilder.MakeOutArgument(statements
                    , stmtsFinishResult
                    , idlSignalName
                    , codetypefactoryOut // Yeah I messed up the naming
                    , ref nOutArgCounter
                    , context
                    , ref throwargOutPrev
                    , idlSignalArg
                    , nameBuilder
                    , ref paramtypeHolder
                    , ref typerefParam
                    , out condVarResult
                );

                codebuilder.StoreCondIterator(ref condOut, ref condOutIter, condVarResult);

                // WAXME
                // Add a field to the <signal>Args class.
                //string argFieldName = CodeBuilderCommon.GetSignalArgFieldName(idlSignalArg.Name);
                //CodeFieldReferenceExpression fielrefdRefArgField = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), argFieldName);
                //typedeclArgs.Members.Add(new CodeMemberField(paramtypeHolder.paramtype.CodeType, argFieldName));
                //CodeMemberProperty propArgField = new CodeMemberProperty();
                //propArgField.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                //propArgField.Type = paramtypeHolder.paramtype.CodeType;
                //propArgField.Name = PropertyNameFromFieldName(argFieldName);
                //propArgField.GetStatements.Add(new CodeMethodReturnStatement(fielrefdRefArgField));
                //typedeclArgs.Members.Add(propArgField);
                //constructorArgs.Parameters.Add(new CodeParameterDeclarationExpression(paramtypeHolder.paramtype.CodeType, argFieldName));
                //// * this.<signal_arg> = <signal_arg>;
                //constructorArgs.Statements.Add(new CodeAssignStatement(fielrefdRefArgField, new CodeArgumentReferenceExpression(argFieldName)));

            } // Ends loop over arguments

            //typedeclArgs.Members.Add(constructorArgs);

            codebuilder.AssignResults(statementsTryRecv, condOut, condOutIter, stmtsFinishResult, throwargOutPrev
                , idlSignalName, ref nOutArgCounter
            );
            List<CodeStatement> statementsReponse = new List<CodeStatement>();

            // Now receive the response.
            // Create message reader.
            // * Udbus.Core.UdbusMessageReader reader = new Udbus.Core.UdbusMessageReader(msgHandleResp);
            statementsTryRecv.Insert(0, codebuilder.CreateMessageReader());
            statementsReponse.AddRange(statementsTryRecv.Cast<CodeStatement>());
            statements.Add(new CodeConditionStatement(exprResultOk, statementsReponse.ToArray()));
        }
Example #17
0
 internal virtual Udbus.Parsing.IStructParamCodeTypeHandler CreateStructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
 {
     return(new StructCreator(codetypeFactory, owner));
 }
Example #18
0
 static public CodeMemberMethod MakeMethod(CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn,
     Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
     IDLInterface idlIntf,
     IDLMethod idlMethod)
 {
     return MakeMethod(codetypefactoryOut, codetypefactoryIn, declarationHolder, idlIntf, idlMethod, new MarshalBuilderHelperMethod());
 }
Example #19
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
        }
Example #20
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;
        }
Example #21
0
 internal Udbus.Parsing.IStructParamCodeTypeHandler CreateStructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
 {
     return this.structCreatorFactory.CreateStructCreator(codetypeFactory, owner);
 }
Example #22
0
 public StructCreatorFullName(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
     : base(codetypeFactory, owner)
 {
 }
Example #23
0
 public DictCreatorOutProperty(CodeTypeFactory codetypeFactory)
     : base(codetypeFactory)
 {
 }
Example #24
0
 public DictCreator(CodeTypeFactory codetypeFactory)
 {
     this.codetypeFactory = codetypeFactory;
 }
Example #25
0
 internal FieldHandler(CodeTypeFactory codetypeFactory, Udbus.Parsing.StructCreatorBase owner)
     : base(codetypeFactory)
 {
     this.owner = owner;
 }
Example #26
0
 public DictCreatorIn(CodeTypeFactory codetypeFactory)
     : base(codetypeFactory)
 {
 }
Example #27
0
 public DictCreator(CodeTypeFactory codetypeFactory)
 {
     this.codetypeFactory = codetypeFactory;
 }
Example #28
0
 public DictCreatorOutProperty(CodeTypeFactory codetypeFactory)
     : base(codetypeFactory)
 {
 }
Example #29
0
 public ParamCodeTypeFactory(CodeTypeFactory codetypeFactory, FieldDirection fieldDirection)
     : base(fieldDirection)
 {
     this.codetypeFactory = codetypeFactory;
 }
Example #30
0
 //public StructCreator(IParamCodeTypeHandler owner)
 public StructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
     : base(owner)
 {
     this.codetypeFactory = codetypeFactory;
 }
Example #31
0
 public ArrayParamCodeTypeHolder(Udbus.Parsing.IParamCodeTypeHandler owner, CodeTypeFactory codetypeFactory, FieldDirection fieldDirection)
     : base(codetypeFactory, fieldDirection)
 {
     this.owner = owner;
 }
Example #32
0
 internal FieldHandler(CodeTypeFactory codetypeFactory, Udbus.Parsing.StructCreatorBase owner)
     : base(codetypeFactory)
 {
     this.owner = owner;
 }
        public virtual void MakeOutArgument(CodeStatementCollection statements
            , CodeStatementCollection stmtsFinishResult
            , string idlMethodName
            , CodeTypeFactory codetypeFactoryOut
            , ref int nOutArgCounter
            , Udbus.Parsing.BuildContext context
            , ref CodeThrowExceptionStatement throwargOutPrev
            , IDLArgument idlMethodArg
            //, IDLMethodArgument idlMethodArg
            , Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder
            , ref ParamCodeTypeHolderMarshalBase paramtypeHolder
            , ref CodeTypeReference typerefParam
            , out CodeConditionStatement condVarResult)
        {
            marshal.outward.ParamCodeTypeHolderMarshalOut paramtypeHolderOut = new marshal.outward.ParamCodeTypeHolderMarshalOut(codetypeFactoryOut);
            Udbus.Parsing.CodeBuilderHelper.BuildCodeParamType(paramtypeHolderOut, nameBuilder, idlMethodArg.Type, context);
            paramtypeHolder = paramtypeHolderOut;
            typerefParam = paramtypeHolder.paramtype.CodeType;

            // Initialise out parameter.
            this.AssignOutParamDefault(statements, idlMethodArg, typerefParam);

            // Read out parameter from message into temporary.
            string argResultVar = idlMethodArg.Name + "Result";
            CodeVariableReferenceExpression varrefResultVar = new CodeVariableReferenceExpression(argResultVar);

            condVarResult = new CodeConditionStatement(
                // * if (this.result == 0)
                exprResultOk,
                new CodeStatement[] // True statements
                {
                    // * <param_type> <arg_name>Result;
                    new CodeVariableDeclarationStatement(typerefParam, argResultVar),
                    // * this.result = reader.Marshal<type>(<marshal_function>, out <arg_name>Result);
                    new CodeAssignStatement(fieldrefResult,
                        paramtypeHolderOut.BuildReadExpression(varrefReader,
                            new CodeDirectionExpression(FieldDirection.Out, varrefResultVar)))
                }
                , new CodeStatement[] // False statements
                {
                    throwargOutPrev
                }
                );

            throwargOutPrev = this.ThrowArgOutException(idlMethodName, nOutArgCounter, idlMethodArg.Name, typerefParam);

            // * <arg_name> = <arg_name>Result;
            this.FinishArgument(idlMethodName, stmtsFinishResult, idlMethodArg, varrefResultVar);
            ++nOutArgCounter;
        }
 public ParamCodeTypeHolderMarshalBase(CodeTypeFactory codetypeFactory, FieldDirection fieldDirection)
     : base(codetypeFactory, fieldDirection)
 {
 }
Example #35
0
 internal override Udbus.Parsing.IStructParamCodeTypeHandler CreateStructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
 {
     return(new StructCreatorFullName(codetypeFactory, owner));
 }
Example #36
0
 internal virtual Udbus.Parsing.IStructParamCodeTypeHandler CreateStructCreator(CodeTypeFactory codetypeFactory, Udbus.Parsing.IParamCodeTypeHandler owner)
 {
     return new StructCreator(codetypeFactory, owner);
 }
 public ParamCodeTypeHolderMarshalBase(CodeTypeFactory codetypeFactory, FieldDirection fieldDirection)
     : base(codetypeFactory, fieldDirection)
 {
 }
Example #38
0
        static public void MakeMethodParameters(CodeTypeFactory codetypefactoryOut, CodeTypeFactory codetypefactoryIn,
            Udbus.Parsing.CodeMemberDeferredClassHolder declarationHolder,
            IDLInterface idlIntf,
            string methodName,
            string idlMethodName,
            IList<IDLMethodArgument> arguments,
            CodeParameterDeclarationExpressionCollection parameters,
            CodeStatementCollection statements,
            Udbus.Parsing.BuildContext context,
            MarshalBuilderHelper codebuilder)
        {
            CodeStatementCollection statementsTryRecv = new CodeStatementCollection();
            CodeConditionStatement condMethodSignature = new CodeConditionStatement(
                exprResultOk
                , new CodeStatement[]
                {
                    codebuilder.SetSignature() 
                }
                , new CodeStatement[]
                {
                    // * throw Udbus.Core.Exceptions.UdbusMessageBuilderException.Create("BodyAdd", serial, "<method_name>", this.result, this.ConnectionParameters);
                    codebuilder.ThrowMessageBuilderException(idlMethodName, "BodyAdd")
                }
            );

            // Check for in parameters.
            bool bInParameters = codebuilder.InitialiseSignature(arguments, statements);

            int nInArgSigCounter = 0;
            int nInArgCounter = 0;
            int nOutArgCounter = 0;
            List<CodeMethodInvokeExpression> invokemethodsBuild = new List<CodeMethodInvokeExpression>();
            CodeConditionStatement condOut = null; // Root if statement for out parameters.
            CodeConditionStatement condOutIter = null; // Most nested if statement for out parameters.
            CodeConditionStatement condIn = null; // Root if statement for in parameters.
            CodeConditionStatement condInIter = null; // Most nested if statement for in parameters.
            CodeStatementCollection stmtsFinishResult = new CodeStatementCollection();
            //Udbus.Parsing.BuildContext context = new Udbus.Parsing.BuildContext(declarationHolder);
            CodeTypeReference typerefParamIter = CodeBuilderCommon.typerefUnknownParameters;
            string argNameIter = arguments != null && arguments.Count > 0 ? arguments[0].Name : "UnknownParameters";

            CodeThrowExceptionStatement throwargOutPrev = codebuilder.CreateArgumentOutException(idlMethodName);

            CodeThrowExceptionStatement throwargInPrev = codebuilder.ThrowMessageBuilderException(idlMethodName, "SetSignature");

            foreach (IDLMethodArgument idlMethodArg in arguments)
            {
                argNameIter = idlMethodArg.Name;

                // 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, idlMethodArg);
                Udbus.Parsing.IDLArgumentTypeNameBuilderBase nameBuilder = new IDLArgumentTypeNameBuilder(idlIntf, methodName);
                ParamCodeTypeHolderMarshalBase paramtypeHolder = null;
                CodeParameterDeclarationExpression param = null;
                CodeTypeReference typerefParam = null;
                if (idlMethodArg.Direction == "out") // If output parameter
                {
                    if (condOut == null)
                    {
                        codebuilder.PrefixOutParams(ref condOut, ref condOutIter, idlMethodName, ref nOutArgCounter, ref throwargOutPrev);
                    }

                    CodeConditionStatement condVarResult;
                    codebuilder.MakeOutArgument(statements
                        , stmtsFinishResult
                        , idlMethodName
                        , codetypefactoryOut // Yeah I messed up the naming
                        , ref nOutArgCounter
                        , context
                        , ref throwargOutPrev
                        , idlMethodArg
                        , nameBuilder
                        , ref paramtypeHolder
                        , ref typerefParam
                        , out condVarResult
                    );

                    codebuilder.StoreCondIterator(ref condOut, ref condOutIter, condVarResult);

                } // Ends if output parameter
                else // Else not output parameter
                {
                    // Add signature for argument.
                    nInArgSigCounter = codebuilder.DeclareSignature(statements, nInArgSigCounter, idlMethodArg.Type);

                    CodeConditionStatement condVarResult;
                    codebuilder.MakeInArgument(codetypefactoryIn // Yeah I messed up the naming
                        //, method.Statements
                        , idlMethodName
                        , ref nInArgCounter
                        , context
                        , ref throwargInPrev
                        , idlMethodArg
                        , nameBuilder
                        , ref paramtypeHolder
                        , ref typerefParam
                        , out condVarResult
                    );

                    codebuilder.StoreCondIterator(ref condIn, ref condInIter, condVarResult);

                } // Ends else not output parameter

                param = codebuilder.AddParameter(parameters, idlMethodArg.Name, idlMethodArg.Direction, typerefParam);

            } // Ends loop over arguments

            codebuilder.AssignResults(statementsTryRecv, condOut, condOutIter, stmtsFinishResult, throwargOutPrev
                ,idlMethodName, ref nOutArgCounter
            );
            codebuilder.TerminateSignature(statements, bInParameters, nInArgSigCounter);
            codebuilder.AddSerialNumber(statements);
            codebuilder.InitialiseMessageBuilder(statements);
            codebuilder.DeclareMessageHandle(statements);

            CodeStatement stmtBuildMethod = codebuilder.InvokeBuild(statements, methodName);

            condIn = codebuilder.FinishInArguments(idlMethodName, codebuilder, condMethodSignature, condIn, condInIter, throwargInPrev);

            // Add a using statement ??? Nope. Add a try/finally statement. Ahhh CodeDOM is there no construct you can't mangle ?
            CodeVariableReferenceExpression varrefSendHandle = codebuilder.DeclareSendHandle();
            CodeStatementCollection statementsTrySend = new CodeStatementCollection();
#if !USE_FLUID_MESSAGE_BUILDER
            // Use individual statements to build message.
            statementsTrySend.Add(stmtBuildMethod);

            if (condIn != null)
            {
                statementsTrySend.Add(condIn);
            }
            else
            {
                // Need to set the signature even for methods with no parameters (?).
                //statementsTrySend.Add(condMethodSignature);
            }
#endif // !USE_FLUID_MESSAGE_BUILDER


            codebuilder.CallSend(idlMethodName, varrefSendHandle, statementsTrySend);

            codebuilder.TryCatchSend(statements, varrefSendHandle, statementsTrySend);

            List<CodeStatement> statementsReponse = new List<CodeStatement>();

            // Now receive the response.
            codebuilder.HandleResponse(idlMethodName, statementsTryRecv, statementsReponse);

            statements.Add(new CodeConditionStatement(exprResultOk,
                statementsReponse.ToArray()
            ));
        }