Esempio n. 1
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()
            ));
        }