Example #1
0
        protected override ParamCodeTypeFactory HandleSignalArgument(IDLInterface idlIntf, IDLSignal idlSignal, IDLSignalArgument idlSignalArg)
        {
            ParamCodeTypeFactory signalArg  = base.HandleSignalArgument(idlIntf, idlSignal, idlSignalArg);
            CodeTypeReference    typerefArg = signalArg.paramtype.CodeType;

            string[] components = CodeBuilderCommon.GetSignalComponents(idlSignalArg.Name);
            string   first      = components[0];

            components    = Array.ConvertAll <string, string>(components, System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase);
            components[0] = first;
            string argFieldName = string.Join("", components);
            CodeFieldReferenceExpression fieldrefArg = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), argFieldName);
            CodeMemberField fieldArg = new CodeMemberField(typerefArg, argFieldName);

            fieldArg.CustomAttributes.Add(CodeBuilderCommon.attribDataMember);
            this.typeSignalArgs.Members.Add(fieldArg);

            CodeMemberProperty propArgField = new CodeMemberProperty();

            propArgField.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            propArgField.Type       = typerefArg;
            propArgField.Name       = argFieldName[0].ToString().ToUpper() + argFieldName.Substring(1);
            propArgField.GetStatements.Add(new CodeMethodReturnStatement(fieldrefArg));
            this.typeSignalArgs.Members.Add(propArgField);

            this.constructorSignalArgs.Parameters.Add(new CodeParameterDeclarationExpression(typerefArg, argFieldName));
            // * this.<signal_arg> = <signal_arg>;
            this.constructorSignalArgs.Statements.Add(new CodeAssignStatement(fieldrefArg, new CodeArgumentReferenceExpression(argFieldName)));
            return(signalArg);
        }
        public override void ProcessNamespaces(IDLInterface idlIntf)
        {
            string nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, this.visitorType);

            this.ifName = CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor());
            ns          = CodeBuilderCommon.AddUsingNamespaces(new CodeNamespace(nsName), this.visitorType);
        }
Example #3
0
        public override void ProcessNamespaces(IDLInterface idlIntf)
        {
            this.InitializeInterface(idlIntf); // TODO: SHOULD BE DONE IN THE MAIN GENERATE METHOD

            this.ns = new CodeNamespace(this.nsServiceName);
            CodeBuilderCommon.AddUsingNamespaces(this.ns, new WCFServiceVisitor());
        }
Example #4
0
        public void InitializeInterface(IDLInterface idlIntf)
        {
            this.bAddNamespace = false;

            this.ifName = CodeBuilderCommon.GetName(idlIntf.Name, null);
            this.nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor());

            this.service            = CodeBuilderCommon.GetName(idlIntf.Name, null);
            this.nsServiceName      = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFServiceVisitor());
            this.nsWCFInterfaceName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFContractVisitor());
            this.wcfinterface       = CodeBuilderCommon.GetName(idlIntf.Name, null);

            this.genInterfaceName       = CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor());
            this.scopedGenInterfaceName = CodeBuilderCommon.GetScopedName(nsName, genInterfaceName);

            this.scopedWCFInterface = CodeBuilderCommon.GetScopedName(this.nsWCFInterfaceName,
                                                                      CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor()));
            this.dbusservice                 = CodeBuilderCommon.GetName(idlIntf.Name, new DBUSServiceVisitor());
            this.scopedDbusServiceName       = CodeBuilderCommon.GetScopedName(this.nsName, this.dbusservice);
            this.callbackInterfaceName       = CodeBuilderCommon.GetSignalCallbackInterfaceName(this.wcfinterface);
            this.scopedCallbackInterfaceName = CodeBuilderCommon.GetScopedName(this.nsWCFInterfaceName, this.callbackInterfaceName);

            this.typerefDbusInterface        = new CodeTypeReference(this.scopedGenInterfaceName);
            this.typerefWCFInterface         = new CodeTypeReference(this.scopedWCFInterface);
            this.typerefDbusMarshal          = new CodeTypeReference(this.scopedDbusServiceName);
            this.typerefexprDbusMarshal      = new CodeTypeReferenceExpression(this.typerefDbusMarshal);
            this.typerefWCFCallbackInterface = new CodeTypeReference(this.scopedCallbackInterfaceName);
        }
        /// <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);
        }
Example #6
0
        private string getScopedNamesResult(ref string fullName, string result)
        {
            result   = CodeBuilderCommon.GetScopedName(this.intf.Name, result);
            fullName = CodeBuilderCommon.GetScopedName(this.intf.Name, result);

            return(result);
        }
Example #7
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)
                                   );
 }
Example #8
0
        public override void ProcessNamespaces(IDLInterface idlIntf)
        {
            name = CodeBuilderCommon.GetName(idlIntf.Name, null);
            string nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor());

            genInterfaceName = CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor());

            // Namespace.
            ns = new CodeNamespace(nsName + ".Proxy");
            CodeBuilderCommon.AddUsingNamespaces(ns, new ProxyVisitor());
        }
Example #9
0
        internal static CodeMemberProperty CreateSignalEventProperty(IDLSignal idlSignal)
        {
            CodeTypeReference typerefEvent = new CodeTypeReference(typeof(System.EventHandler <>));

            typerefEvent.TypeArguments.Add(new CodeTypeReference(CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name)));
            CodeMemberProperty propEventSignal = new CodeMemberProperty();

            propEventSignal.Name = CodeBuilderCommon.GetSignalEventPropertyName(idlSignal.Name);
            propEventSignal.Type = typerefEvent;
            return(propEventSignal);
        }
Example #10
0
        internal static CodeMemberEvent CreateSignalEvent(IDLSignal idlSignal)
        {
            string          eventPropertyName = CodeBuilderCommon.GetSignalEventName(idlSignal.Name);
            CodeMemberEvent eventSignal       = new CodeMemberEvent();

            eventSignal.Attributes = MemberAttributes.Private;
            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;
            return(eventSignal);
        }
Example #11
0
        private CodeNamespace GetClientNamespace(CodeCompileUnit unit, string idlIntfName)
        {
            CodeNamespace nsClient;
            string        nsClientName = CodeBuilderCommon.GetNamespace(idlIntfName, new WCFClientVisitor());

            if (this.dictNSClient.TryGetValue(nsClientName, out nsClient) == false)
            {
                nsClient = new CodeNamespace(nsClientName);
                this.dictNSClient[nsClientName] = nsClient;
                unit.Namespaces.Add(nsClient);
            }
            return(nsClient);
        }
Example #12
0
        public override void GenerateProperties(IDLInterface idlIntf)
        {
            if (idlIntf.Properties != null && idlIntf.Properties.Count > 0) // If got properties
            {
                foreach (IDLProperty idlProperty in idlIntf.Properties)
                {
                    bool hasGet = CodeBuilderCommon.HasGet(idlProperty);
                    bool hasSet = CodeBuilderCommon.HasSet(idlProperty);

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

                    CodeMemberProperty property = new CodeMemberProperty();
                    property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                    property.Name       = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
                    property.HasGet     = hasGet;
                    property.HasSet     = hasSet;
                    property.Type       = CodeBuilderCommon.PropertyType(CodeTypeFactory.Default, idlProperty.Type);

                    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.

                    CodePropertyReferenceExpression proprefTargetProperty = new CodePropertyReferenceExpression(thisProxyFieldRef, property.Name);
                    if (hasGet)
                    {
                        property.GetStatements.Add(
                            new CodeMethodReturnStatement(
                                proprefTargetProperty
                                )
                            );
                    }

                    if (hasSet)
                    {
                        property.SetStatements.Add(
                            new CodeAssignStatement(proprefTargetProperty
                                                    , new CodePropertySetValueReferenceExpression()
                                                    )
                            );
                    }

                    // Finish up.
                    typeProxy.Members.Add(property);
                } // Ends loop over properties
            }     // Ends if got properties
        }
Example #13
0
        private void GenerateProperty(IDLInterface idlIntf, IDLProperty idlProperty
                                      , CodeTypeReference typerefDbusInterface
                                      , CodeTypeReference typerefDbusMarshal
                                      , CodeTypeDeclaration typeProxy)
        {
            bool hasGet = CodeBuilderCommon.HasGet(idlProperty);
            bool hasSet = CodeBuilderCommon.HasSet(idlProperty);

            if (hasGet || hasSet)
            {
                CodeMemberProperty property = new CodeMemberProperty();
                property.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                property.Name       = CodeBuilderCommon.GetCompilableName(idlProperty.Name);
                property.HasGet     = hasGet;
                property.HasSet     = hasSet;
                property.Type       = CodeBuilderCommon.PropertyType(CodeTypeFactory.DefaultProperty, idlProperty.Type);

                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.

                CodeVariableDeclarationStatement vardeclTarget         = this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal);
                CodePropertyReferenceExpression  proprefTargetProperty = new CodePropertyReferenceExpression(varrefTarget, property.Name);
                if (hasGet)
                {
                    property.GetStatements.Add(vardeclTarget);
                    property.GetStatements.Add(
                        new CodeMethodReturnStatement(
                            proprefTargetProperty
                            )
                        );
                }

                if (hasSet)
                {
                    property.SetStatements.Add(vardeclTarget);
                    property.SetStatements.Add(
                        new CodeAssignStatement(proprefTargetProperty
                                                , new CodePropertySetValueReferenceExpression()
                                                )
                        );
                }

                // Finish up.
                typeProxy.Members.Add(property);
            }
        }
Example #14
0
        public override void ProcessNamespaces(IDLInterface idlIntf)
        {
            //Get the necessary names
            this.ifName         = CodeBuilderCommon.GetName(idlIntf.Name, null);
            this.nsName         = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor());
            this.nsContractName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFContractVisitor());
            string nsServiceName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFServiceVisitor()); //Local scope, not needed later

            //Get the necessary scoped names
            this.scopedDbusServiceName = CodeBuilderCommon.GetScopedName(this.nsName, CodeBuilderCommon.GetName(idlIntf.Name, new DBUSServiceVisitor()));
            this.scopedWCFContractName = CodeBuilderCommon.GetScopedName(this.nsContractName, CodeBuilderCommon.GetName(idlIntf.Name, new InterfaceVisitor()));
            this.scopedWCFServiceName  = CodeBuilderCommon.GetScopedName(nsServiceName, CodeBuilderCommon.GetName(idlIntf.Name, new WCFServiceVisitor()));

            //Get our the Host's namespace and give it all the imports it requires
            this.nsHost = new CodeNamespace(CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFHostVisitor()));
            CodeBuilderCommon.AddUsingNamespaces(this.nsHost, new WCFHostVisitor());
        }
Example #15
0
        override protected void PostHandleSignal(IDLInterface idlIntf, IDLSignal idlSignal, CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration typeInterface)
        {
            CodeMemberProperty propEventSignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal);

            typeInterface.Members.Add(propEventSignal);
            propEventSignal.HasGet = true;
            propEventSignal.HasSet = true;

            // * public class <signal_as_type>Args : EventArgs
            this.typeSignalArgs.Name = CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name);
            this.typeSignalArgs.CustomAttributes.Add(CodeBuilderCommon.attribDataContract);
            ns.Types.Add(this.typeSignalArgs);

            // Prepare for next signal.
            this.typeSignalArgs        = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name));
            this.constructorSignalArgs = new CodeConstructor();
            this.InitFields();
        }
Example #16
0
        public override void DeclareCodeType(IDLInterface idlIntf)
        {
            //Declare code type references
            this.typerefWCFService = new CodeTypeReference(this.scopedWCFServiceName);
            CodeTypeReference typerefConstants   = new CodeTypeReference(CodeBuilderCommon.GetScopedName(this.nsName, CodeBuilderCommon.nameConstantsClass));
            CodeTypeReference typerefWCFContract = new CodeTypeReference(this.scopedWCFContractName);
            CodeTypeReference typerefDbusService = new CodeTypeReference(this.scopedDbusServiceName);

            //No idea...
            this.type = BuildMakeServiceHostCreationDataImplementation(this.ifName, this.nsContractName,
                                                                       this.typerefWCFService, typerefWCFContract, typerefDbusService);
            this.nsHost.Types.Add(this.type);
            CodeTypeReference typeref = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsHost.Name, this.type.Name));

            // Idiotic Partial class for initialisation.
            this.typedeclInitHostMakerRegistry            = new CodeTypeDeclaration("InitHostMakerRegistry");
            this.typedeclInitHostMakerRegistry.IsPartial  = true;
            this.typedeclInitHostMakerRegistry.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            this.typerefInitService = new CodeTypeReference(this.typeRegistryListEntry);
            this.typerefInitService.TypeArguments.Add(typeref);
            this.fieldAddInit = new CodeMemberField(typerefRegistryListEntryBase, "add" + typerefWCFService.BaseType.Replace('.', '_'));
        }
Example #17
0
        public override void DeclareCodeType(IDLInterface idlIntf)
        {
            this.type                = new CodeTypeDeclaration(CodeBuilderCommon.GetName(idlIntf.Name, new WCFServiceVisitor()));
            this.type.IsClass        = true;
            this.type.TypeAttributes = System.Reflection.TypeAttributes.Public;

            this.BaseTypes(typerefWCFInterface, this.type);
            this.type.CustomAttributes.Add(attribServiceBehavior);

            // DbusServices field.
            this.DbusServiceTargetField(this.typerefDbusInterface, this.typerefDbusMarshal, this.type.Members);

            // Constructor.
            this.Constructor(this.type, this.typerefDbusInterface);

            // Target retrieval method.
            this.methodGetWCFMethodTarget = this.TargetRetrievalMethod(this.typerefDbusInterface, this.typerefDbusMarshal, this.typerefexprDbusMarshal);
            this.type.Members.Add(this.methodGetWCFMethodTarget);

            this.contextDeclarationHolder = new CodeTypeIgnoredNamespaceDeclarationHolderParams(idlIntf);
            this.declarationHolder        = this.contextDeclarationHolder;
        }
Example #18
0
 public override void GenerateSignals(IDLInterface idlIntf)
 {
     if (idlIntf.Signals != null && idlIntf.Signals.Count > 0) // If got signals
     {
         bAddNamespace = true;
         foreach (IDLSignal idlSignal in idlIntf.Signals)
         {
             // Signal.
             // * public System.EventHandler< <signal>Args > <signal>
             // * {
             // *     get { return this.proxy.<signal>; }
             // *     set { this.proxy.<signal> = value; }
             // * }
             CodeMemberProperty propSignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal);
             propSignal.Attributes = MemberAttributes.Public | MemberAttributes.Final;
             CodePropertyReferenceExpression proprefProxySignal = new CodePropertyReferenceExpression(thisProxyFieldRef, propSignal.Name);
             propSignal.GetStatements.Add(new CodeMethodReturnStatement(proprefProxySignal));
             propSignal.SetStatements.Add(new CodeAssignStatement(proprefProxySignal, new CodePropertySetValueReferenceExpression()));
             typeProxy.Members.Add(propSignal);
         } // Ends loop over signal
     }     // Ends if got signals
 }
Example #19
0
        private CodeTypeDeclaration BuildMakeServiceHostCreationDataImplementation(string ifName,
                                                                                   string nsWCFContractsName,
                                                                                   CodeTypeReference typerefWCFService, CodeTypeReference typerefWCFContract,
                                                                                   CodeTypeReference typerefService)
        {
            string nsWCFHost = CodeBuilderCommon.typeServiceHostCreationData.Namespace;
            string scopedWCFServiceParams = CodeBuilderCommon.GetScopedName(nsWCFHost, nameWCFServiceParams);

            CodeTypeReferenceExpression     typerefexprWCFService = new CodeTypeReferenceExpression(typerefWCFService);
            CodeArgumentReferenceExpression argrefUriBase         = new CodeArgumentReferenceExpression(nameUriBaseArg);
            CodeTypeReference           typerefConstants          = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsWCFContractsName, CodeBuilderCommon.nameConstantsClass));
            CodeTypeReferenceExpression typerefexprConstants      = new CodeTypeReferenceExpression(typerefConstants);
            Type typeIMakeServiceHostCreationData = typeof(Udbus.WCF.Service.Host.IMakeServiceHostCreationData);

            CodeTypeDeclaration typeImpl = new CodeTypeDeclaration(string.Format("MakeServiceHostCreationData{0}", ifName));

            typeImpl.Attributes = MemberAttributes.Public;
            typeImpl.BaseTypes.Add(new CodeTypeReference(typeIMakeServiceHostCreationData));
            CodeTypeReference typerefImpl = new CodeTypeReference(typeImpl.Name);

            CodeMethodInvokeExpression invokeGetDbusServiceCreationParams = new CodeMethodInvokeExpression(null, GetDbusServiceCreationParams);
            CodeTypeOfExpression       typeofWCFService = new CodeTypeOfExpression(typerefWCFService);

            // CreateService()
            CodeMemberMethod methodCreateService = this.CreateService(typerefWCFService, typerefService);

            CodeMemberMethod methodCreateServiceCreationData = new CodeMemberMethod();

            methodCreateServiceCreationData.Name       = "CreateServiceCreationData";
            methodCreateServiceCreationData.Attributes = MemberAttributes.Static;
            CodeTypeReference typerefServiceCreationData = new CodeTypeReference(typeof(Udbus.WCF.Service.Host.WCFServiceCreationData <,>));

            typerefServiceCreationData.TypeArguments.Add(typerefWCFService);
            typerefServiceCreationData.TypeArguments.Add(CodeBuilderCommon.typerefWCFServiceParams);
            methodCreateServiceCreationData.ReturnType = typerefServiceCreationData;
            methodCreateServiceCreationData.Statements.Add(new CodeMethodReturnStatement(
                                                               new CodeObjectCreateExpression(typerefServiceCreationData
                                                                                              // CreateService // Static creation method in this class
                                                                                              , new CodeMethodReferenceExpression(null, CreateServiceName)
                                                                                              // GetDbusServiceCreationParams()
                                                                                              , invokeGetDbusServiceCreationParams
                                                                                              //// <wcf_contracts>.Constants.DbusServiceRelativeAddress
                                                                                              //, new CodeFieldReferenceExpression(typerefexprConstants, CodeBuilderCommon.nameRelativeAddress)
                                                                                              //// typeof(<contract>)
                                                                                              //, new CodeTypeOfExpression(typerefWCFContract)
                                                                                              )));

            //         static Udbus.WCF.Host.DbusServiceCreationParams GetDbusServiceCreationParams()
            //{
            //    return new Udbus.WCF.Host.DbusServiceCreationParams(org.freedesktop.DBus.Properties.wcf.Contracts.Constants.DbusServiceRelativeAddress, typeof(org.freedesktop.DBus.Properties.wcf.Contracts.IProperties));
            //}

            CodeMemberMethod methodGetDbusServiceCreationParams = new CodeMemberMethod();

            methodGetDbusServiceCreationParams.Name       = GetDbusServiceCreationParams;
            methodGetDbusServiceCreationParams.Attributes = MemberAttributes.Static;
            methodGetDbusServiceCreationParams.ReturnType = CodeBuilderCommon.typerefDbusServiceCreationParams;
            methodGetDbusServiceCreationParams.Statements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression(
                                                                                                CodeBuilderCommon.typerefDbusServiceCreationParams
                                                                                                // <wcf_contracts>.Constants.DbusServiceRelativeAddress
                                                                                                , new CodeFieldReferenceExpression(typerefexprConstants, CodeBuilderCommon.nameRelativeAddress)
                                                                                                // typeof(<contract>)
                                                                                                , new CodeTypeOfExpression(typerefWCFContract)
                                                                                                )));

            CodeMemberMethod methodContainsService = new CodeMemberMethod();

            methodContainsService.Name       = ContainsService;
            methodContainsService.ReturnType = CodeBuilderCommon.typerefBool;
            CodeParameterDeclarationExpression paramdeclServiceTypes = new CodeParameterDeclarationExpression(typeof(Type[]), ServiceTypesArg);

            paramdeclServiceTypes.CustomAttributes.Add(CodeBuilderCommon.attribParams);
            methodContainsService.Parameters.Add(paramdeclServiceTypes);
            methodContainsService.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            methodContainsService.Statements.Add(new CodeMethodReturnStatement(
                                                     new CodeMethodInvokeExpression(new CodeArgumentReferenceExpression(ServiceTypesArg),
                                                                                    "Contains",
                                                                                    typeofWCFService
                                                                                    )
                                                     ));

            // * public Udbus.WCF.Service.Host.ServiceHostCreationData MakeServiceHostCreationData(Udbus.WCF.Host.WCFServiceParams wcfserviceparams, params System.Uri[] uriBase)
            // * {
            // *     Udbus.WCF.Service.Host.ServiceHostCreationData create = Udbus.WCF.Service.Host.DbusServiceHost.CreateWithData< <wcf_service>, Udbus.WCF.Host.WCFServiceParams>(wcfserviceparams, CreateServiceCreationData, uriBase);
            // *     return create;
            // * }
            CodeMethodInvokeExpression invokeCreateWithData = new CodeMethodInvokeExpression(CodeBuilderCommon.typerefexprDbusServiceHost, CodeBuilderCommon.nameDbusServiceHostCreateWithDataMethod
                                                                                             // wcfserviceparams
                                                                                             , argrefWCFServiceParams
                                                                                             // CreateServiceCreationData
                                                                                             , new CodeMethodReferenceExpression(null, methodCreateServiceCreationData.Name)
                                                                                             //, uriBase)
                                                                                             , argrefUriBase
                                                                                             );

            invokeCreateWithData.Method.TypeArguments.Add(typerefWCFService);
            invokeCreateWithData.Method.TypeArguments.Add(CodeBuilderCommon.typerefWCFServiceParams);

            CodeMemberMethod methodMakeServiceCreationData = new CodeMemberMethod();

            methodMakeServiceCreationData.Name       = MakeServiceHostCreationData;
            methodMakeServiceCreationData.ReturnType = CodeBuilderCommon.typerefServiceHostCreationData;
            methodMakeServiceCreationData.Parameters.Add(new CodeParameterDeclarationExpression(CodeBuilderCommon.typerefWCFServiceParams, nameWCFServiceParamsArg));
            CodeParameterDeclarationExpression paramdeclUriBase = new CodeParameterDeclarationExpression(typeof(System.Uri[]), nameUriBaseArg);

            paramdeclUriBase.CustomAttributes.Add(CodeBuilderCommon.attribParams);
            methodMakeServiceCreationData.Parameters.Add(paramdeclUriBase);
            methodMakeServiceCreationData.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            methodMakeServiceCreationData.Statements.Add(
                new CodeVariableDeclarationStatement(CodeBuilderCommon.typerefServiceHostCreationData, "create",
                                                     invokeCreateWithData
                                                     )
                );
            methodMakeServiceCreationData.Statements.Add(new CodeMethodReturnStatement(new CodeVariableReferenceExpression("create")));

            CodeMemberMethod methodGetHostDbusServiceRegistrationParams = BuildGetDbusServiceRegistrationParamsMethod(GetHostDbusServiceRegistrationParams);

            methodGetHostDbusServiceRegistrationParams.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            methodGetHostDbusServiceRegistrationParams.Statements.Add(new CodeMethodReturnStatement(new CodeObjectCreateExpression(
                                                                                                        CodeBuilderCommon.typerefRegistrationParams
                                                                                                        , invokeGetDbusServiceCreationParams
                                                                                                        , typeofWCFService
                                                                                                        )));

            CodeMemberMethod methodGetDbusServiceRegistrationParams = BuildGetDbusServiceRegistrationParamsMethod("GetDbusServiceRegistrationParams");

            methodGetDbusServiceRegistrationParams.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            methodGetDbusServiceRegistrationParams.Statements.Add(new CodeMethodReturnStatement(new CodeMethodInvokeExpression(null, GetHostDbusServiceRegistrationParams)));

            typeImpl.Members.Add(methodCreateService);
            typeImpl.Members.Add(methodCreateServiceCreationData);
            typeImpl.Members.Add(methodGetDbusServiceCreationParams);
            typeImpl.Members.Add(methodGetHostDbusServiceRegistrationParams);
            string regionIMakeServiceHostCreationData = string.Format("{0} functions", typeIMakeServiceHostCreationData.FullName);

            methodContainsService.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, regionIMakeServiceHostCreationData));
            typeImpl.Members.Add(methodContainsService);
            typeImpl.Members.Add(methodGetDbusServiceRegistrationParams);
            typeImpl.Members.Add(methodMakeServiceCreationData);
            methodMakeServiceCreationData.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, regionIMakeServiceHostCreationData));

            return(typeImpl);
        }
Example #20
0
 internal static string GetSignalProxyName(string idlInterfaceName)
 {
     return(CodeBuilderCommon.GetSignalCompilableName(idlInterfaceName) + "Proxy");
 }
Example #21
0
 internal static string GetSignalCallbackMethodName(string idlSignalName)
 {
     return("On" + CodeBuilderCommon.GetSignalCompilableName(idlSignalName));
 }
Example #22
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
        }
 protected override CodeNamespace CreateNamespace()
 {
     return(new CodeNamespace(CodeBuilderCommon.GetParamsNamespaceName(this.intf)));
 }
Example #24
0
        override protected void PostHandleSignal(IDLInterface idlIntf, IDLSignal idlSignal, CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration typeInterface)
        {
            string nsName, intf;
            int    lastDot = idlIntf.Name.LastIndexOf('.');

            intf   = idlIntf.Name.Substring(lastDot + 1);
            nsName = CodeBuilderCommon.GetNamespace(idlIntf.Name, new InterfaceVisitor());
            CodeFieldReferenceExpression fieldrefCallback = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CodeBuilderCommon.callback);
            CodeFieldReferenceExpression fieldrefTarget   = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), CodeBuilderCommon.targetName);
            CodeNamespace nsClient      = this.GetClientNamespace(unit, idlIntf.Name);
            CodeNamespace nsClientTypes = nsClient;

            if (this.typedeclCallbackInterface == null) // If no callback interface yet
            {
                CodeTypeReference typerefInterface = new CodeTypeReference(typeInterface.Name);

                // Declare callback interface and hold onto it in field.
                // * public interface I<interface>Callback
                // * {
                string nsWCFName, intfWCF;
                nsWCFName = CodeBuilderCommon.GetNamespace(idlIntf.Name, this.visitorType);
                intfWCF   = CodeBuilderCommon.GetName(idlIntf.Name, null);
                string callbackInterfaceName = CodeBuilderCommon.GetSignalCallbackInterfaceName(intfWCF);
                typedeclCallbackInterface             = new CodeTypeDeclaration(callbackInterfaceName);
                typedeclCallbackInterface.Attributes  = MemberAttributes.Public;
                typedeclCallbackInterface.IsInterface = true;
                ns.Types.Add(typedeclCallbackInterface);

                // * class <interface>CallbackClient : I<interface>Callback
                string            wcfCallbackClientName    = CodeBuilderCommon.GetSignalCompilableName(intfWCF) + "CallbackClient";
                CodeTypeReference typerefCallbackInterface = new CodeTypeReference(typedeclCallbackInterface.Name);

                CodeAttributeDeclaration attribdeclServiceContract = new CodeAttributeDeclaration(CodeBuilderCommon.typerefServiceContract,
                                                                                                  new CodeAttributeArgument("CallbackContract", new CodeTypeOfExpression(typerefCallbackInterface))
                                                                                                  );
                typeInterface.CustomAttributes.Add(attribdeclServiceContract);

                //string scopedCallbackInterfaceName = CodeBuilderCommon.GetScopedName(nsWCFName, proxyInterfaceName);
                //typedeclCallbackClient = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalCallbackName(intf));
                typedeclCallbackClient = new CodeTypeDeclaration(wcfCallbackClientName);
                CodeTypeReference typerefWCFCallbackInterface = new CodeTypeReference(typedeclCallbackInterface.Name);
                typedeclCallbackClient.BaseTypes.Add(typerefWCFCallbackInterface);

                nsClientTypes.Types.Add(typedeclCallbackClient);

                // * public class <interface>Proxy : Udbus.WCF.Client.CallbackProxy< <wcf_contracts.interface>, <interface>CallbackClient >
                this.typedeclProxy = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalProxyName(intfWCF));
                CodeTypeReference typerefCallbackProxy  = new CodeTypeReference(typeof(Udbus.WCF.Client.CallbackProxy <,>));
                CodeTypeReference typerefCallbackClient = new CodeTypeReference(typedeclCallbackClient.Name);
                typerefCallbackProxy.TypeArguments.Add(typerefInterface);
                typerefCallbackProxy.TypeArguments.Add(typerefCallbackClient);
                this.typedeclProxy.BaseTypes.Add(typerefCallbackProxy);

                AddProxyConstructors(this.typedeclProxy);

                nsClientTypes.Types.Add(this.typedeclProxy);
            } // Ends if no callback interface yet

            // Add signal property to Proxy.
            CodeMemberProperty propProxySignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal);

            propProxySignal.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            CodePropertyReferenceExpression proprefProxyInterface     = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "ProxyInterface");
            CodePropertyReferenceExpression proprefProxyCallback      = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Callback");
            CodePropertyReferenceExpression proprefProxyCallbackEvent = new CodePropertyReferenceExpression(proprefProxyCallback, propProxySignal.Name);

            propProxySignal.GetStatements.Add(new CodeMethodReturnStatement(proprefProxyCallbackEvent));
            propProxySignal.SetStatements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(proprefProxyCallbackEvent, CodeBinaryOperatorType.IdentityEquality, new CodePrimitiveExpression(null))
                                                                         , new CodeExpressionStatement(new CodeMethodInvokeExpression(proprefProxyInterface, CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name)))
                                                                         ));
            propProxySignal.SetStatements.Add(new CodeAssignStatement(proprefProxyCallbackEvent, new CodePropertySetValueReferenceExpression()));
            this.typedeclProxy.Members.Add(propProxySignal);

            // Add callback method to callback interface.
            // * [System.ServiceModel.OperationContract(IsOneWay=true)]
            // * void On<signal>(<interface_ns>.<signal>Args args);
            CodeMemberMethod methodOnSignal = new CodeMemberMethod();

            methodOnSignal.Name = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name);
            string signalArgsTypeName       = CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name);
            string scopedSignalArgsTypeName = CodeBuilderCommon.GetScopedName(nsName, signalArgsTypeName);
            CodeParameterDeclarationExpression paramdeclSignalArgs = new CodeParameterDeclarationExpression(scopedSignalArgsTypeName,
                                                                                                            CodeBuilderCommon.SignalArgsName);

            methodOnSignal.Parameters.Add(paramdeclSignalArgs);
            methodOnSignal.CustomAttributes.Add(CodeBuilderCommon.attribOperationContractOneWay);
            typedeclCallbackInterface.Members.Add(methodOnSignal);

            // Add registration method to wcf interface.
            // * [System.ServiceModel.OperationContract]
            // * void RegisterForStorageSpaceLow();
            CodeMemberMethod methodRegister = new CodeMemberMethod();

            methodRegister.Name = CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name);
            methodRegister.CustomAttributes.Add(CodeBuilderCommon.attribOperationContract);
            typeInterface.Members.Add(methodRegister);

            // Add event to callback client implementation.

            // * private event System.EventHandler< <signal>Args > <signal>Event;
            CodeMemberEvent eventSignal = CodeBuilderCommon.CreateSignalEvent(idlSignal);

            typedeclCallbackClient.Members.Add(eventSignal);

            // * public virtual System.EventHandler< <signal>Args > <signal>
            // * {
            // *     get { return this.<signal>Event; }
            // *     set { this.<signal>Event = value; }
            // * }
            CodeMemberProperty propSignal = CodeBuilderCommon.CreateSignalEventProperty(idlSignal);

            propSignal.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            CodeEventReferenceExpression eventrefSignal = new CodeEventReferenceExpression(new CodeThisReferenceExpression(), eventSignal.Name);

            propSignal.GetStatements.Add(new CodeMethodReturnStatement(eventrefSignal));
            propSignal.SetStatements.Add(new CodeAssignStatement(eventrefSignal, new CodePropertySetValueReferenceExpression()));
            typedeclCallbackClient.Members.Add(propSignal);

            // * public void On<signal>(<ns>.<signal>Args args)
            // * {
            // *     if (this.<signal> != null)
            // *     {
            // *         this.<signal>(this, args);
            // *     }
            //}
            CodeMemberMethod methodSignal = new CodeMemberMethod();

            methodSignal.Name       = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name);
            methodSignal.Attributes = MemberAttributes.Public;
            methodSignal.Parameters.Add(paramdeclSignalArgs);
            CodePropertyReferenceExpression proprefSignal = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), propSignal.Name);

            methodSignal.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(eventrefSignal, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null))
                                                                   , new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), eventrefSignal.EventName, new CodeThisReferenceExpression(), new CodeArgumentReferenceExpression(paramdeclSignalArgs.Name)))
                                                                   ));
            typedeclCallbackClient.Members.Add(methodSignal);
        }
Example #25
0
 private string getScopedNameImpl(string name)
 {
     return(CodeBuilderCommon.GetScopedName(this.intf.Name, name));
 }
Example #26
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());
 }
Example #27
0
        private void GenerateSignals(IDLInterface idlIntf, string nsName
                                     , CodeTypeReference typerefDbusInterface
                                     , CodeTypeReference typerefDbusMarshal
                                     , CodeTypeReference typerefWCFCallbackInterface
                                     , CodeTypeDeclaration typeProxy)
        {
            #region list of callbacks
            // Callbacks field.
            // * LinkedList<I<interface>Callback> callbacks = null;
            CodeTypeReference typerefCallbacksLinkedList = new CodeTypeReference(typeof(LinkedList <>));
            typerefCallbacksLinkedList.TypeArguments.Add(typerefWCFCallbackInterface);
            CodeMemberField fieldCallbacks = new CodeMemberField(typerefCallbacksLinkedList, callbacks);
            fieldCallbacks.InitExpression = new CodePrimitiveExpression(null);
            typeProxy.Members.Add(fieldCallbacks);
            #endregion

            #region Method: OnCallBackClosing
            // Write:
            //   private void OnCallbackClosing(object sender, System.EventArgs e)
            //   {
            //        RemoveCallback(sender, this.callbacks);
            //   }
            CodeMemberMethod methodOnCallbackClosing = new CodeMemberMethod();
            methodOnCallbackClosing.Attributes = MemberAttributes.Private;
            methodOnCallbackClosing.Name       = "OnCallbackClosing";
            CodeParameterDeclarationExpression paramdeclSender    = new CodeParameterDeclarationExpression(typerefObject, "sender");
            CodeArgumentReferenceExpression    argrefSender       = new CodeArgumentReferenceExpression(paramdeclSender.Name);
            CodeParameterDeclarationExpression paramdeclEventArgs = new CodeParameterDeclarationExpression(typeof(System.EventArgs), "e");
            CodeArgumentReferenceExpression    argrefEventArgs    = new CodeArgumentReferenceExpression(paramdeclEventArgs.Name);
            methodOnCallbackClosing.Parameters.Add(paramdeclSender);
            methodOnCallbackClosing.Parameters.Add(paramdeclEventArgs);
            methodOnCallbackClosing.Statements.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(null, RemoveCallback, argrefSender, fieldrefCallbacks)));
            typeProxy.Members.Add(methodOnCallbackClosing);
            #endregion

            #region Method: AddCallBack
            // AddCallback().
            // * private void AddCallback(I<interface>Callback callback)
            CodeParameterDeclarationExpression paramdeclCallback = new CodeParameterDeclarationExpression(typerefWCFCallbackInterface, CodeBuilderCommon.callback);
            CodeArgumentReferenceExpression    argrefCallback    = new CodeArgumentReferenceExpression(paramdeclCallback.Name);
            CodeMemberMethod methodAddCallback = new CodeMemberMethod();
            methodAddCallback.Attributes = MemberAttributes.Private;
            methodAddCallback.Name       = AddCallback;
            methodAddCallback.Parameters.Add(paramdeclCallback);
            CodeArrayCreateExpression arraycreatexprCallbacks = new CodeArrayCreateExpression(typerefWCFCallbackInterface);
            arraycreatexprCallbacks.Initializers.Add(argrefCallback);
            CodeVariableReferenceExpression varrefRegisterComms = new CodeVariableReferenceExpression("registerComms");
            // * bool registerComms = true;
            methodAddCallback.Statements.Add(new CodeVariableDeclarationStatement(typeof(bool)
                                                                                  , varrefRegisterComms.VariableName
                                                                                  , new CodePrimitiveExpression(true)));

            CodeTypeReference typerefCallbackEnumerator = new CodeTypeReference(typeof(System.Collections.Generic.IEnumerator <>));
            typerefCallbackEnumerator.TypeArguments.Add(typerefWCFCallbackInterface);
            CodeVariableReferenceExpression  varrefCallbackEnumerator  = new CodeVariableReferenceExpression(callbackEnumerator);
            CodeVariableDeclarationStatement vardeclCallbackEnumerator = new CodeVariableDeclarationStatement(typerefCallbackEnumerator, varrefCallbackEnumerator.VariableName,
                                                                                                              new CodeMethodInvokeExpression(fieldrefCallbacks, "GetEnumerator"));
            CodePropertyReferenceExpression  proprefCallbackEnumeratorCurrent  = new CodePropertyReferenceExpression(varrefCallbackEnumerator, "Current");
            CodeMethodInvokeExpression       invokeCallbackEnumeratorMoveNext  = new CodeMethodInvokeExpression(varrefCallbackEnumerator, "MoveNext");
            CodeVariableDeclarationStatement vardeclCallbackEnumeratorMoveNext = new CodeVariableDeclarationStatement(typeof(bool), callbackEnumeratorMoveNext, invokeCallbackEnumeratorMoveNext);
            CodeVariableReferenceExpression  varrefCallbackEnumeratorMoveNext  = new CodeVariableReferenceExpression(vardeclCallbackEnumeratorMoveNext.Name);
            CodeAssignStatement assignCallbackEnumeratorMoveNext = new CodeAssignStatement(varrefCallbackEnumeratorMoveNext, invokeCallbackEnumeratorMoveNext);

            methodAddCallback.Statements.Add(
                // * if (this.callbacks == null)
                new CodeConditionStatement(new CodeBinaryOperatorExpression(fieldrefCallbacks
                                                                            , CodeBinaryOperatorType.IdentityEquality
                                                                            , new CodePrimitiveExpression(null))
                                           , new CodeStatement[]
            {
                // * this.callbacks = new LinkedList<I<interface>Callback>(new I<interface>Callback[] { callback });
                new CodeAssignStatement(fieldrefCallbacks
                                        , new CodeObjectCreateExpression(typerefCallbacksLinkedList
                                                                         , arraycreatexprCallbacks)
                                        )
            }
                                           // * else
                                           , new CodeStatement[]
            {
                // * IEnumerator<[callback_interface]> callbacksEnumerator = this.callbacks.GetEnumerator();
                vardeclCallbackEnumerator
                // * for (bool callbackEnumeratorMoveNext = callbackEnumerator.MoveNext(); callbackEnumeratorMoveNext; callbackEnumeratorMoveNext = callbackEnumerator.MoveNext())
                // * {
                , new CodeIterationStatement(vardeclCallbackEnumeratorMoveNext
                                             , new CodeBinaryOperatorExpression(varrefCallbackEnumeratorMoveNext
                                                                                , CodeBinaryOperatorType.BooleanAnd
                                                                                , varrefRegisterComms)
                                             , assignCallbackEnumeratorMoveNext
                                             // * if (callbacksEnumerator.Current.Equals(callback))
                                             // * {
                                             , new CodeConditionStatement(new CodeMethodInvokeExpression(proprefCallbackEnumeratorCurrent
                                                                                                         , "Equals"
                                                                                                         , argrefCallback)
                                                                          , new CodeStatement[]       // True
                {
                    // * registerComms = false;
                    new CodeAssignStatement(varrefRegisterComms, new CodePrimitiveExpression(false))
                }
                                                                          )
                                             )
                // * if (registerComms)
                , new CodeConditionStatement(varrefRegisterComms
                                             // * this.callbacks.AddLast(callback);
                                             , new CodeExpressionStatement(new CodeMethodInvokeExpression(fieldrefCallbacks
                                                                                                          , "AddLast"
                                                                                                          , argrefCallback))
                                             )
            }
                                           ));

            // * System.ServiceModel.ICommunicationObject commsCallback = callback as System.ServiceModel.ICommunicationObject;

            // * if (registerComms && (typeof(System.ServiceModel.ICommunicationObject).IsInstanceOfType(callback) != false))
            // * {
            // * commsCallback.Closing += this.OnCallbackClosing;
            // * }
            CodeTypeReference typerefICommunicationObject           = new CodeTypeReference(typeof(System.ServiceModel.ICommunicationObject));
            CodeVariableDeclarationStatement vardeclCallbackAsComms = new CodeVariableDeclarationStatement(typerefICommunicationObject
                                                                                                           , "commsCallback"
                                                                                                           , new CodeCastExpression(typerefICommunicationObject, argrefCallback)
                                                                                                           );
            CodeVariableReferenceExpression varrefCallbackAsComms = new CodeVariableReferenceExpression(vardeclCallbackAsComms.Name);
            methodAddCallback.Statements.Add(new CodeConditionStatement(new CodeBinaryOperatorExpression(
                                                                            varrefRegisterComms
                                                                            , CodeBinaryOperatorType.BooleanAnd
                                                                            , new CodeBinaryOperatorExpression(
                                                                                new CodeMethodInvokeExpression(new CodeTypeOfExpression(typerefICommunicationObject), "IsInstanceOfType", argrefCallback)
                                                                                , CodeBinaryOperatorType.IdentityInequality
                                                                                , new CodePrimitiveExpression(false)
                                                                                )
                                                                            )
                                                                        , vardeclCallbackAsComms
                                                                        , new CodeAttachEventStatement(varrefCallbackAsComms, "Closing", new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), methodOnCallbackClosing.Name))
                                                                        ));
            typeProxy.Members.Add(methodAddCallback);
            #endregion

            #region Method: RemoveCallBack
            // RemoveCallback().
            /// * static private void RemoveCallback<T>(object callback, LinkedList<T> callbacks)
            /// *     where T: class
            /// * {
            CodeMemberMethod methodRemoveCallback = new CodeMemberMethod();
            methodRemoveCallback.Attributes = MemberAttributes.Static | MemberAttributes.Private;
            methodRemoveCallback.Name       = RemoveCallback;
            CodeTypeParameter typeparamCallback    = new CodeTypeParameter("TCallback");
            CodeTypeReference typerefCallbackParam = new CodeTypeReference(typeparamCallback.Name);
            CodeParameterDeclarationExpression paramdeclRemoveCallback = new CodeParameterDeclarationExpression(typerefObject, CodeBuilderCommon.callback);
            CodeTypeReference typerefLinkedListRemoveCallback          = new CodeTypeReference(typeof(System.Collections.Generic.LinkedList <>));
            typerefLinkedListRemoveCallback.TypeArguments.Add(typerefCallbackParam);
            CodeTypeReference typerefLinkedListNodeRemoveCallback = new CodeTypeReference(typeof(System.Collections.Generic.LinkedListNode <>));
            typerefLinkedListNodeRemoveCallback.TypeArguments.Add(typerefCallbackParam);

            CodeParameterDeclarationExpression paramdeclRemoveCallbacks = new CodeParameterDeclarationExpression(typerefLinkedListRemoveCallback, callbacks);
            CodeArgumentReferenceExpression    argrefCallbacks          = new CodeArgumentReferenceExpression(paramdeclRemoveCallbacks.Name);
            typeparamCallback.Constraints.Add(new CodeTypeReference(" class")); // Space before "class" bloody important, stupid CodeDOM and CSharp.
            methodRemoveCallback.TypeParameters.Add(typeparamCallback);
            methodRemoveCallback.Parameters.Add(paramdeclRemoveCallback);
            methodRemoveCallback.Parameters.Add(paramdeclRemoveCallbacks);

            CodeVariableDeclarationStatement vardeclIteratorNode = new CodeVariableDeclarationStatement(
                typerefLinkedListNodeRemoveCallback, "iteratorNode"
                , new CodePropertyReferenceExpression(argrefCallbacks, "First")
                );
            CodeVariableReferenceExpression  varrefIteratorNode = new CodeVariableReferenceExpression(vardeclIteratorNode.Name);
            CodeVariableDeclarationStatement vardeclRemoveNode  = new CodeVariableDeclarationStatement(
                typerefLinkedListNodeRemoveCallback, "removeNode"
                , varrefIteratorNode
                );
            CodeVariableReferenceExpression varrefRemoveNode   = new CodeVariableReferenceExpression(vardeclRemoveNode.Name);
            CodeAssignStatement             assignIteratorNode = new CodeAssignStatement(varrefIteratorNode, new CodePropertyReferenceExpression(varrefIteratorNode, "Next"));

            // * for (LinkedListNode<string> n = l.First; n != null; )
            // * {
            methodRemoveCallback.Statements.Add(new CodeIterationStatement(vardeclIteratorNode
                                                                           , new CodeBinaryOperatorExpression(varrefIteratorNode
                                                                                                              , CodeBinaryOperatorType.IdentityInequality
                                                                                                              , new CodePrimitiveExpression(null))
                                                                           , new CodeSnippetStatement(string.Empty) // Don't increment
                                                                                                                    // * if (iteratorNode.Value == callback)
                                                                                                                    // * {
                                                                           , new CodeConditionStatement(
                                                                               new CodeBinaryOperatorExpression(new CodePropertyReferenceExpression(varrefIteratorNode, "Value")
                                                                                                                , CodeBinaryOperatorType.IdentityEquality
                                                                                                                , argrefCallback)
                                                                               , new CodeStatement[] // True
            {
                // * LinkedListNode<string> removeNode = iteratorNode;
                vardeclRemoveNode
                // * iteratorNode = iteratorNode.Next;
                , assignIteratorNode
                // * l.Remove(removeNode);
                , new CodeExpressionStatement(new CodeMethodInvokeExpression(argrefCallbacks, "Remove", varrefRemoveNode))
                // * }
            }
                                                                               // * else
                                                                               // * {
                                                                               , new CodeStatement[] // False
            {
                // * iteratorNode = iteratorNode.Next;
                assignIteratorNode
                // * }
            }
                                                                               // * }
                                                                               // * }
                                                                               )));
            typeProxy.Members.Add(methodRemoveCallback);
            #endregion

            foreach (IDLSignal idlSignal in idlIntf.Signals)
            {
                #region Write method which will call every registered
                // Add private event handler function which delegates to callback interfaces.
                // * private void On<signal>(object sender, <signal_interface_ns>.<signal>Args e)
                string            signalArgsName         = CodeBuilderCommon.GetSignalEventTypeName(idlSignal.Name);
                string            scopedSignalArgsName   = CodeBuilderCommon.GetScopedName(nsName, signalArgsName);
                string            signalEventMethodName  = CodeBuilderCommon.GetSignalCallbackMethodName(idlSignal.Name);
                CodeTypeReference typerefSignalEventArgs = new CodeTypeReference(scopedSignalArgsName);
                CodeParameterDeclarationExpression paramdeclSignalEventArgs = new CodeParameterDeclarationExpression(typerefSignalEventArgs, eventArgsParamName);
                CodeArgumentReferenceExpression    argrefSignalEventArgs    = new CodeArgumentReferenceExpression(paramdeclSignalEventArgs.Name);
                CodeMemberMethod methodOnSignal = new CodeMemberMethod();

                methodOnSignal.Attributes = MemberAttributes.Private;
                methodOnSignal.Name       = signalEventMethodName;
                methodOnSignal.Parameters.Add(paramdeclSender);
                methodOnSignal.Parameters.Add(paramdeclSignalEventArgs);
                methodOnSignal.Statements.Add(new CodeConditionStatement(
                                                  // * if (this.callbacks != null)
                                                  new CodeBinaryOperatorExpression(fieldrefCallbacks, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null))
                                                  // * IEnumerator< <interface>Callback > callbackEnumerator = this.callbacks.GetEnumerator();
                                                  , vardeclCallbackEnumerator
                                                  // * for (bool callbackEnumeratorMoveNext = callbackEnumerator.MoveNext(); callbackEnumeratorMoveNext; callbackEnumeratorMoveNext = callbackEnumerator.MoveNext())
                                                  , new CodeIterationStatement(vardeclCallbackEnumeratorMoveNext, varrefCallbackEnumeratorMoveNext, assignCallbackEnumeratorMoveNext
                                                                               , new CodeExpressionStatement(new CodeMethodInvokeExpression(proprefCallbackEnumeratorCurrent, signalEventMethodName, argrefSignalEventArgs))
                                                                               //// * callbackEnumerator.Current.On<signal>(e);
                                                                               //, new CodeExpressionStatement(new CodeMethodInvokeExpression(arrayindexCallbacks, signalEventMethodName, argrefSignalEventArgs))
                                                                               )));
                typeProxy.Members.Add(methodOnSignal);
                #endregion

                #region Write method to register for a signal
                // * public void RegisterFor<signal>()
                CodeMethodReferenceExpression methodrefGetCallbackChannel = new CodeMethodReferenceExpression(proprefOperationContextCurrent, "GetCallbackChannel", typerefWCFCallbackInterface);
                CodeMethodReferenceExpression methodrefOnSignal           = new CodeMethodReferenceExpression(new CodeThisReferenceExpression(), methodOnSignal.Name);
                CodeMemberMethod methodRegisterForSignal = new CodeMemberMethod();
                methodRegisterForSignal.Attributes = MemberAttributes.Public;
                methodRegisterForSignal.Name       = CodeBuilderCommon.GetSignalRegisterFunction(idlSignal.Name);
                // * <interface> target = this.GetWCFMethodTarget();
                methodRegisterForSignal.Statements.Add(this.DeclareTargetVariable(typerefDbusInterface, typerefDbusMarshal));
                // * AddCallback(System.ServiceModel.OperationContext.Current.GetCallbackChannel<I<interface>Callback>());
                methodRegisterForSignal.Statements.Add(new CodeExpressionStatement(new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), methodAddCallback.Name
                                                                                                                  , new CodeMethodInvokeExpression(methodrefGetCallbackChannel))
                                                                                   ));
                CodePropertyReferenceExpression proprefDbusServiceSignal = new CodePropertyReferenceExpression(fieldrefDbusServices, CodeBuilderCommon.GetSignalEventPropertyName(idlSignal.Name));
                CodeAttachEventStatement        attacheventSignal        = new CodeAttachEventStatement(new CodeEventReferenceExpression(varrefTarget, CodeBuilderCommon.GetSignalEventPropertyName(idlSignal.Name)), methodrefOnSignal);
                methodRegisterForSignal.Statements.Add(attacheventSignal);

                typeProxy.Members.Add(methodRegisterForSignal);
                #endregion
            } // Ends loop over signals
        }
Example #28
0
 private string getParamScopedNameImpl(string name)
 {
     return(CodeBuilderCommon.GetScopedName(CodeBuilderCommon.GetParamsNamespaceName(this.intf.Name), name));
 }
Example #29
0
        override protected void PostHandleInterface(IDLInterface idlIntf, CodeCompileUnit unit, CodeNamespace ns, CodeTypeDeclaration typeInterface)
        {
            if (idlIntf.Signals == null || idlIntf.Signals.Count == 0) // If no signals
            {
                typeInterface.CustomAttributes.Add(CodeBuilderCommon.attribServiceContract);
            } // Ends if no signals

            // Add DbusServiceRelativeAddress constant to Constants class.
            // * public partial class Constants {
            CodeTypeDeclaration typedeclConstants = new CodeTypeDeclaration(CodeBuilderCommon.nameConstantsClass);

            typedeclConstants.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            typedeclConstants.IsPartial  = true;
            // *    public const string DbusServiceRelativeAddress = "<contract_name>";
            // * }

            CodeMemberField fieldRelativeAddress = new CodeMemberField(typeof(string), CodeBuilderCommon.nameRelativeAddress);

            fieldRelativeAddress.Attributes     = MemberAttributes.Const | MemberAttributes.Public;
            fieldRelativeAddress.InitExpression = new CodePrimitiveExpression(idlIntf.Name.Replace('.', '/'));
            typedeclConstants.Members.Add(fieldRelativeAddress);

            ns.Types.Add(typedeclConstants);

            CodeTypeReference typerefInterface      = new CodeTypeReference(CodeBuilderCommon.GetScopedName(ns.Name, typeInterface.Name));
            CodeTypeReference typerefInterfaceProxy = new CodeTypeReference(typeof(Udbus.WCF.Client.Proxy <>));

            typerefInterfaceProxy.TypeArguments.Add(typerefInterface);

            CodeTypeReference typerefProxy; // Worked out in following code...

            if (this.typedeclProxy == null) // If no proxy type defined yet
            {
                // Just knock up a nice vanilla one for consistency's sake.
                string nsWCFName, intfWCF;
                nsWCFName = CodeBuilderCommon.GetNamespace(idlIntf.Name, this.visitorType);
                intfWCF   = CodeBuilderCommon.GetName(idlIntf.Name, null);

                CodeTypeDeclaration typedeclProxy = new CodeTypeDeclaration(CodeBuilderCommon.GetSignalProxyName(intfWCF));
                typedeclProxy.BaseTypes.Add(typerefInterfaceProxy);

                AddProxyConstructors(typedeclProxy);

                CodeNamespace nsClient = this.GetClientNamespace(unit, idlIntf.Name);
                nsClient.Types.Add(typedeclProxy);

                typerefProxy = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsClient.Name, typedeclProxy.Name));
            }    // Ends if no proxy type defined yet
            else // Else added proxy type
            {
                // Grab holder of scoped type reference.
                string nsWCFClient = CodeBuilderCommon.GetNamespace(idlIntf.Name, new WCFClientVisitor());
                typerefProxy = new CodeTypeReference(CodeBuilderCommon.GetScopedName(nsWCFClient, this.typedeclProxy.Name));
            } // Ends else added proxy type

            // Reset helper types for next time.
            this.typedeclCallbackInterface = null;
            this.typedeclCallbackClient    = null;
            this.typedeclProxy             = null;

            // Add Proxy creation function to ProxyBuilder class via extension method.
            CodeTypeReference           typerefEndpointComponents     = new CodeTypeReference(typeof(Udbus.WCF.Client.DbusEndpointUriComponents));
            CodeTypeReferenceExpression typerefexprEndpointComponents = new CodeTypeReferenceExpression(typerefEndpointComponents);
            CodeTypeReference           typerefProxyManager           = new CodeTypeReference(typeof(Udbus.WCF.Client.ProxyManager));
            CodeTypeReferenceExpression typerefexprProxyManager       = new CodeTypeReferenceExpression(typerefProxyManager);
            CodeTypeReference           typerefProxyBuilder           = new CodeTypeReference(typeof(Udbus.WCF.Client.ProxyBuilder));
            CodeTypeReference           typerefProxyBuilderExtension  = new CodeTypeReference("this " + typerefProxyBuilder.BaseType); // No CodeDom support for extension methods. Awesome.
            CodeTypeReferenceExpression typerefexprProxyBuilder       = new CodeTypeReferenceExpression(typerefProxyBuilder);

            CodeTypeReferenceExpression        typerefexprConstants           = new CodeTypeReferenceExpression(CodeBuilderCommon.GetScopedName(ns.Name, typedeclConstants.Name));
            CodeParameterDeclarationExpression paramdeclInterfaceProxy        = new CodeParameterDeclarationExpression(typerefInterfaceProxy, proxy);
            CodeParameterDeclarationExpression paramdeclProxyManagerExtension = new CodeParameterDeclarationExpression(typerefProxyBuilderExtension, proxyBuilder);
            CodeParameterDeclarationExpression paramdeclEndpointUri           = new CodeParameterDeclarationExpression(typerefEndpointComponents, dbusEndpointUri);
            CodeArgumentReferenceExpression    argrefProxy       = new CodeArgumentReferenceExpression(proxy);
            CodeArgumentReferenceExpression    argrefEndpointUri = new CodeArgumentReferenceExpression(paramdeclEndpointUri.Name);
            CodeExpression exprRelativeAddress = new CodeFieldReferenceExpression(typerefexprConstants, fieldRelativeAddress.Name);
            CodeArgumentReferenceExpression argrefProxyBuilder    = new CodeArgumentReferenceExpression(proxyBuilder);
            CodePropertyReferenceExpression proprefBindingFactory = new CodePropertyReferenceExpression(argrefProxyBuilder, BindingFactory);

            // * static public partial class ProxyBuilderExtensions
            // * {
            CodeTypeDeclaration typedeclProxyBuilderExtensions = new CodeTypeDeclaration(CodeBuilderCommon.nameProxyBuilderExtensionsClass);

            typedeclProxyBuilderExtensions.Attributes = MemberAttributes.Public | MemberAttributes.Static;
            typedeclProxyBuilderExtensions.IsPartial  = true;
            // http://stackoverflow.com/questions/6308310/creating-extension-method-using-codedom
            typedeclProxyBuilderExtensions.Attributes = MemberAttributes.Public;
            typedeclProxyBuilderExtensions.StartDirectives.Add(new CodeRegionDirective(CodeRegionMode.Start, Environment.NewLine + "\tstatic"));
            typedeclProxyBuilderExtensions.EndDirectives.Add(new CodeRegionDirective(CodeRegionMode.End, string.Empty));

            // *     static public void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out Udbus.WCF.Client.Proxy< <wcf_contract> > proxy
            // *         , Udbus.WCF.Client.DbusEndpointUriComponents dbusEndpointUri)
            // *     {
            // *         proxy = Udbus.WCF.Client.ProxyManager.Create< <wcf_contract> >(
            // *             dbusEndpointUri.CreateUri(<wcf_namespace>.wcf.Contracts.Constants.DbusServiceRelativeAddress)
            // *             , proxyBuilder.BindingFactory
            // *         );
            // *     }
            CodeMemberMethod methodCreateInterfaceProxyWithEndpoint = new CodeMemberMethod();

            methodCreateInterfaceProxyWithEndpoint.Name       = "Create";
            methodCreateInterfaceProxyWithEndpoint.Attributes = MemberAttributes.Static | MemberAttributes.Public;
            paramdeclInterfaceProxy.Direction = FieldDirection.Out;
            methodCreateInterfaceProxyWithEndpoint.Parameters.Add(paramdeclProxyManagerExtension);
            methodCreateInterfaceProxyWithEndpoint.Parameters.Add(paramdeclInterfaceProxy);
            methodCreateInterfaceProxyWithEndpoint.Parameters.Add(paramdeclEndpointUri);
            // * dbusEndpointUri.CreateUri(<ns>.wcf.Contracts.Constants.DbusServiceRelativeAddress)
            CodeMethodInvokeExpression invokeCreateUri          = new CodeMethodInvokeExpression(argrefEndpointUri, CreateUri, exprRelativeAddress);
            CodeMethodInvokeExpression invokeProxyManagerCreate = new CodeMethodInvokeExpression(typerefexprProxyManager, "Create", invokeCreateUri, proprefBindingFactory);

            invokeProxyManagerCreate.Method.TypeArguments.Add(typerefInterface);
            methodCreateInterfaceProxyWithEndpoint.Statements.Add(
                new CodeAssignStatement(
                    argrefProxy
                    , invokeProxyManagerCreate
                    )
                );
            typedeclProxyBuilderExtensions.Members.Add(methodCreateInterfaceProxyWithEndpoint);

            // *     static public void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out Udbus.WCF.Client.Proxy< <wcf_contract> > proxy)
            // *     {
            // *         proxyBuilder.Create(out proxy, Udbus.WCF.Client.DbusEndpointUriComponents.Create(proxyBuilder.AbsoluteUribuilder));
            // *     }
            CodeMemberMethod methodCreateInterfaceProxy = new CodeMemberMethod();

            methodCreateInterfaceProxy.Name       = "Create";
            methodCreateInterfaceProxy.Attributes = MemberAttributes.Static | MemberAttributes.Public;
            methodCreateInterfaceProxy.Parameters.Add(paramdeclProxyManagerExtension);
            methodCreateInterfaceProxy.Parameters.Add(paramdeclInterfaceProxy);
            CodeMethodInvokeExpression invokeProxyManagerExtensionCreate = new CodeMethodInvokeExpression(
                argrefProxyBuilder
                , "Create"
                , new CodeDirectionExpression(FieldDirection.Out, argrefProxy)
                , new CodeMethodInvokeExpression(
                    typerefexprEndpointComponents
                    , "Create"
                    , new CodePropertyReferenceExpression(argrefProxyBuilder, AbsoluteUribuilder)
                    )
                );

            methodCreateInterfaceProxy.Statements.Add(invokeProxyManagerExtensionCreate);
            typedeclProxyBuilderExtensions.Members.Add(methodCreateInterfaceProxy);

            CodeParameterDeclarationExpression paramdeclProxy = new CodeParameterDeclarationExpression(typerefProxy, proxy);

            paramdeclProxy.Direction = FieldDirection.Out;

            // * public static void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out <namespace>.Contracts.Clients.<interface>Proxy proxy, Udbus.WCF.Client.DbusEndpointUriComponents dbusEndpointUri)
            // * {
            // *     proxy = new <wcf_namespace>.Contracts.Clients.<interface>Proxy(proxyBuilder.BindingFactory, dbusEndpointUri.CreateUri(<namespace>.wcf.Contracts.Constants.DbusServiceRelativeAddress));
            // * }
            CodeMemberMethod methodCreateProxyWithEndpoint = new CodeMemberMethod();

            methodCreateProxyWithEndpoint.Name       = "Create";
            methodCreateProxyWithEndpoint.Attributes = MemberAttributes.Static | MemberAttributes.Public;
            methodCreateProxyWithEndpoint.Parameters.Add(paramdeclProxyManagerExtension);
            methodCreateProxyWithEndpoint.Parameters.Add(paramdeclProxy);
            methodCreateProxyWithEndpoint.Parameters.Add(paramdeclEndpointUri);
            methodCreateProxyWithEndpoint.Statements.Add(new CodeAssignStatement(
                                                             argrefProxy
                                                             , new CodeObjectCreateExpression(typerefProxy
                                                                                              , proprefBindingFactory
                                                                                              , invokeCreateUri
                                                                                              )
                                                             ));
            typedeclProxyBuilderExtensions.Members.Add(methodCreateProxyWithEndpoint);

            // * public static void Create(this Udbus.WCF.Client.ProxyBuilder proxyBuilder, out <namespace>.Contracts.Clients.<interface>Proxy proxy)
            // * {
            // *     proxyBuilder.Create(out proxy, Udbus.WCF.Client.DbusEndpointUriComponents.Create(proxyBuilder.AbsoluteUribuilder));
            // * }
            CodeMemberMethod methodCreateProxy = new CodeMemberMethod();

            methodCreateProxy.Name       = "Create";
            methodCreateProxy.Attributes = MemberAttributes.Static | MemberAttributes.Public;
            methodCreateProxy.Parameters.Add(paramdeclProxyManagerExtension);
            methodCreateProxy.Parameters.Add(paramdeclProxy);
            methodCreateProxy.Statements.Add(invokeProxyManagerExtensionCreate);
            typedeclProxyBuilderExtensions.Members.Add(methodCreateProxy);

            CodeNamespace nsClientExtensions = new CodeNamespace(CodeBuilderCommon.nsClientExtensions);

            nsClientExtensions.Types.Add(typedeclProxyBuilderExtensions);
            unit.Namespaces.Add(nsClientExtensions);
            // * }
        }