예제 #1
0
        internal TypeSupportFactory GetTypeSupportFactory(string registeredName)
        {
            TypeSupportFactory tsFactory = null;

            IntPtr gapiPtr = Gapi.DomainParticipant.get_typesupport(
                GapiPeer,
                registeredName);

            if (gapiPtr != IntPtr.Zero)
            {
                tsFactory = TypeSupportFactory.fromUserData(gapiPtr);
            }

            return(tsFactory);
        }
예제 #2
0
        internal static TypeSupportFactory fromUserData(IntPtr gapiPtr)
        {
            TypeSupportFactory tsFactory = null;

            // Check whether the gapiPtr contains a valid pointer.
            if (gapiPtr != IntPtr.Zero)
            {
                // get the user data out of the gapi object
                IntPtr managedIntPtr = Gapi.Entity.get_user_data(gapiPtr);

                // Check whether the userData contains a valid pointer.
                if (managedIntPtr != IntPtr.Zero)
                {
                    // If so, get the relevant C# Object.
                    GCHandle tmpGCHandle = GCHandle.FromIntPtr(managedIntPtr);
                    tsFactory = tmpGCHandle.Target as TypeSupportFactory;
                }
            }

            return(tsFactory);
        }
예제 #3
0
        /*
         * Constructor for a TypeSupport that uses the specified (custom) Marshaler.
         */
        public TypeSupport(Type dataType, TypeSupportFactory tsFactory)
        {
            this.dataType = dataType;

            System.Text.StringBuilder descriptor = new System.Text.StringBuilder();
            foreach (string s in Description)
            {
                descriptor.Append(s);
            }

            this.dummyOperationDelegate = new DummyOperationDelegate(DummyOperation);
            this.gapiPeer = Gapi.FooTypeSupport.alloc(
                TypeName,                   // Original IDL type name
                KeyList,
                descriptor.ToString(),
                IntPtr.Zero,                // type_load
                dummyOperationDelegate,     // copyIn: delay initialization until marshaler present
                dummyOperationDelegate,     // copyOut: delay initialization until marshaler present
                0,                          // alloc_size
                IntPtr.Zero,                // alloc buffer
                IntPtr.Zero,                // writer copy
                dummyOperationDelegate);    // reader copy: delay initialization until marshaler present

            // Base class handles everything.
            if (GapiPeer != IntPtr.Zero)
            {
                tsFactory.SetPeer(GapiPeer);
            }
            else
            {
                // Gapi already logged that the TypeSupport has not been created
                // successfully. Now create a deliberate null pointer exception
                // to let the current constructor fail.
                throw new System.NullReferenceException("gapi_fooTypeSupport__alloc returned a NULL pointer.");
            }
        }
예제 #4
0
        /*
         * Constructor for a TypeSupport that uses the specified (custom) Marshaler.
         */
        public TypeSupport(Type dataType, TypeSupportFactory tsFactory)
        {
            this.dataType = dataType;
            
            System.Text.StringBuilder descriptor = new System.Text.StringBuilder();
            foreach (string s in Description) {
               descriptor.Append(s);
            }

            this.dummyOperationDelegate = new DummyOperationDelegate(DummyOperation);
            this.gapiPeer = Gapi.FooTypeSupport.alloc(
               TypeName,                    // Original IDL type name
               KeyList,
               descriptor.ToString(),
               IntPtr.Zero,                 // type_load
               dummyOperationDelegate,      // copyIn: delay initialization until marshaler present
               dummyOperationDelegate,      // copyOut: delay initialization until marshaler present
               0,                           // alloc_size
               IntPtr.Zero,                 // alloc buffer
               IntPtr.Zero,                 // writer copy
               dummyOperationDelegate);     // reader copy: delay initialization until marshaler present

            // Base class handles everything.
            if (GapiPeer != IntPtr.Zero)
            {
                tsFactory.SetPeer(GapiPeer);
            }
            else
            {
                // Gapi already logged that the TypeSupport has not been created
                // successfully. Now create a deliberate null pointer exception
                // to let the current constructor fail.
                throw new System.NullReferenceException("gapi_fooTypeSupport__alloc returned a NULL pointer.");
            }
        }
예제 #5
0
        public IDataReader CreateDataReader(
            ITopicDescription topic,
            IDataReaderListener listener,
            StatusKind mask)
        {
            DataReader dataReader = null;

            if (topic != null)
            {
                SacsSuperClass superObj = (SacsSuperClass)topic;

                if (listener != null)
                {
                    OpenSplice.Gapi.gapi_dataReaderListener gapiListener;
                    DataReaderListenerHelper listenerHelper = new DataReaderListenerHelper();
                    listenerHelper.Listener = listener;
                    listenerHelper.CreateListener(out gapiListener);
                    using (DataReaderListenerMarshaler listenerMarshaler =
                               new DataReaderListenerMarshaler(ref gapiListener))
                    {
                        IntPtr gapiPtr = Gapi.Subscriber.create_datareader(
                            GapiPeer,
                            superObj.GapiPeer,
                            IntPtr.Zero,
                            listenerMarshaler.GapiPtr,
                            mask);
                        if (gapiPtr != IntPtr.Zero)
                        {
                            DDS.OpenSplice.DomainParticipant participantImpl;

                            participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                            TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                            dataReader = tsFactory.CreateDataReader(gapiPtr);
                            dataReader.SetListener(listenerHelper);
                        }
                    }
                }
                else
                {
                    IntPtr gapiPtr = Gapi.Subscriber.create_datareader(
                        GapiPeer,
                        superObj.GapiPeer,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        StatusKind.Any);
                    if (gapiPtr != IntPtr.Zero)
                    {
                        DDS.OpenSplice.DomainParticipant participantImpl;

                        participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                        TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                        dataReader = tsFactory.CreateDataReader(gapiPtr);
                    }
                }
            }

            if (dataReader != null)
            {
                SubscriberQos subQos = null;
                ReturnCode    result = GetQos(ref subQos);
                if (result == ReturnCode.Ok)
                {
                    if (subQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        dataReader.Enable();
                    }
                }
            }

            return(dataReader);
        }
예제 #6
0
        public IDataWriter CreateDataWriter(
            ITopic topic,
            IDataWriterListener listener,
            StatusKind mask)
        {
            DataWriter dataWriter = null;
            Topic      topicObj   = topic as Topic;

            if (listener != null)
            {
                // Note: we use the same gapi lister as the DataWriter since the
                // publisher doesn't add anything unique
                OpenSplice.Gapi.gapi_publisherDataWriterListener gapiListener;
                PublisherDataWriterListenerHelper listenerHelper = new PublisherDataWriterListenerHelper();
                listenerHelper.Listener = listener;
                listenerHelper.CreateListener(out gapiListener);
                using (PublisherDataWriterListenerMarshaler listenerMarshaler =
                           new PublisherDataWriterListenerMarshaler(ref gapiListener))
                {
                    IntPtr gapiPtr = Gapi.Publisher.create_datawriter(
                        GapiPeer,
                        topicObj.GapiPeer,
                        Gapi.NativeConstants.GapiDataWriterQosDefault,
                        listenerMarshaler.GapiPtr,
                        mask);
                    if (gapiPtr != IntPtr.Zero)
                    {
                        DDS.OpenSplice.DomainParticipant participantImpl;

                        participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                        TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                        dataWriter = tsFactory.CreateDataWriter(gapiPtr);
                        dataWriter.SetListener(listenerHelper);
                    }
                }
            }
            else
            {
                IntPtr gapiPtr = Gapi.Publisher.create_datawriter(
                    GapiPeer,
                    topicObj.GapiPeer,
                    Gapi.NativeConstants.GapiDataWriterQosDefault,
                    IntPtr.Zero,
                    mask);
                if (gapiPtr != IntPtr.Zero)
                {
                    DDS.OpenSplice.DomainParticipant participantImpl;

                    participantImpl = topic.Participant as DDS.OpenSplice.DomainParticipant;
                    TypeSupportFactory tsFactory = participantImpl.GetTypeSupportFactory(topic.TypeName);
                    dataWriter = tsFactory.CreateDataWriter(gapiPtr);
                }
            }

            if (dataWriter != null)
            {
                PublisherQos pubQos = null;
                ReturnCode   result = GetQos(ref pubQos);
                if (result == ReturnCode.Ok)
                {
                    if (pubQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        dataWriter.Enable();
                    }
                }
            }

            return(dataWriter);
        }