Example #1
0
        public void TestSetQos()
        {
            // Creates a non-default QoS, set it an check it
            DomainParticipantFactoryQos qos = new DomainParticipantFactoryQos();

            qos.EntityFactory.AutoenableCreatedEntities = false;

            ReturnCode result = AssemblyInitializer.Factory.SetQos(qos);

            Assert.AreEqual(ReturnCode.Ok, result);

            qos    = new DomainParticipantFactoryQos();
            result = AssemblyInitializer.Factory.GetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(qos.EntityFactory);
            Assert.IsFalse(qos.EntityFactory.AutoenableCreatedEntities);

            // Put back the default QoS and check it
            qos    = new DomainParticipantFactoryQos();
            result = AssemblyInitializer.Factory.SetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);

            result = AssemblyInitializer.Factory.GetQos(qos);
            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(qos.EntityFactory);
            Assert.IsTrue(qos.EntityFactory.AutoenableCreatedEntities);

            // Test with null parameter
            result = AssemblyInitializer.Factory.SetQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }
Example #2
0
        public void TestNewParticipantFactoryQos()
        {
            DomainParticipantFactoryQos qos = new DomainParticipantFactoryQos();

            Assert.IsNotNull(qos.EntityFactory);
            Assert.IsTrue(qos.EntityFactory.AutoenableCreatedEntities);
        }
Example #3
0
 /// <summary>
 /// This operation replaces the existing set of QoS settings for the DomainParticipantFactory.
 /// </summary>
 /// <remarks>
 /// This operation replaces the existing set of QosPolicy settings for a
 /// DomainParticipantFactory. The parameter qos must contain the struct with
 /// the QosPolicy settings.
 ///
 /// The set of QosPolicy settings specified by the qos parameter are applied on top of
 /// the existing QoS, replacing the values of any policies previously set (provided, the
 /// operation returned Ok).
 /// </remarks>
 /// @param qos The new set of Qos policy settings for the DomainParticipantFactory
 /// @return DDS.ReturnCode Ok - The new DomainParticipantFactoryQos is set
 /// @return DDS.ReturnCode Error - An internal error has occured
 /// @return DDS.ReturnCode OutOfResources - The DDS ran out of resources to complete this operation
 public ReturnCode SetQos(DomainParticipantFactoryQos qos)
 {
     lock (singleton_lock)
     {
         myQos.EntityFactory.AutoenableCreatedEntities = qos.EntityFactory.AutoenableCreatedEntities;
         return(ReturnCode.Ok);
     }
 }
Example #4
0
 /// <summary>
 /// This operation obtains the QoS settings for the DomainParticipantFactory.
 /// </summary>
 /// <remarks>
 /// This operation allows access to the existing set of QoS policies of a
 /// DomainParticipantFactory on which this operation is used. This
 /// DomainParticipantFactoryQos is stored at the location pointed to by the qos
 /// parameter.
 /// </remarks>
 /// @param qos A reference to the destination DomainParticipantFactoryQos,
 ///            in which the Qos policies will be copied
 /// @return DDS.ReturnCode Ok - The new DomainParticipantFactoryQos is set
 /// @return DDS.ReturnCode Error - An internal error has occured
 /// @return DDS.ReturnCode OutOfResources - The DDS ran out of resources to complete this operation
 public ReturnCode GetQos(ref DomainParticipantFactoryQos qos)
 {
     lock (singleton_lock)
     {
         if (qos == null)
         {
             qos = new DomainParticipantFactoryQos();
         }
         if (qos.EntityFactory == null)
         {
             qos.EntityFactory = new EntityFactoryQosPolicy();
         }
         qos.EntityFactory.AutoenableCreatedEntities = myQos.EntityFactory.AutoenableCreatedEntities;
         return(ReturnCode.Ok);
     }
 }
Example #5
0
        public void TestGetQos()
        {
            DomainParticipantFactoryQos qos = new DomainParticipantFactoryQos();

            qos.EntityFactory.AutoenableCreatedEntities = false;

            ReturnCode result = AssemblyInitializer.Factory.GetQos(qos);

            Assert.AreEqual(ReturnCode.Ok, result);
            Assert.IsNotNull(qos.EntityFactory);
            Assert.IsTrue(qos.EntityFactory.AutoenableCreatedEntities);

            // Test with null parameter
            result = AssemblyInitializer.Factory.GetQos(null);
            Assert.AreEqual(ReturnCode.BadParameter, result);
        }
        public ReturnCode SetQos(DomainParticipantFactoryQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    // Invoke the corresponding gapi function.
                    result = OpenSplice.Gapi.DomainParticipantFactory.set_qos(GapiPeer, marshaler.GapiPtr);
                }
            }

            return(result);
        }
        public ReturnCode GetQos(ref DomainParticipantFactoryQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler marshaler =
                       new OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler())
            {
                // Invoke the corresponding gapi function.
                result = OpenSplice.Gapi.DomainParticipantFactory.get_qos(GapiPeer, marshaler.GapiPtr);

                // When no error occured, copy the QoS settings from the gapi Qos representation.
                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return(result);
        }
        public ReturnCode GetQos(ref DomainParticipantFactoryQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler marshaler = 
                    new OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler())
            {
                // Invoke the corresponding gapi function.
                result = OpenSplice.Gapi.DomainParticipantFactory.get_qos(GapiPeer, marshaler.GapiPtr);

                // When no error occured, copy the QoS settings from the gapi Qos representation.
                if (result == ReturnCode.Ok)
                {
                    marshaler.CopyOut(ref qos);
                }
            }

            return result;
        }
        public ReturnCode SetQos(DomainParticipantFactoryQos qos)
        {
            ReturnCode result;

            using (OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler marshaler = 
                    new OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler())
            {
                result = marshaler.CopyIn(qos);
                if (result == ReturnCode.Ok)
                {
                    // Invoke the corresponding gapi function.
                    result = OpenSplice.Gapi.DomainParticipantFactory.set_qos(GapiPeer, marshaler.GapiPtr);
                }
            }

            return result;
        }
Example #10
0
        public void Run()
        {
#if DBCallTests
            DDS.Test.DatabaseTests();
#endif

            Console.WriteLine("Press enter to enter...");
            Console.ReadLine();
            Data.DataTest detectionData = new Data.DataTest();
            detectionData.TestId    = 3214;
            detectionData.Emergency = true;
            detectionData.TestStr   = "not really";
            //detectionData.SeqInt[3] = 23;
#if TestMarshaling
            //Tactical.DetectionTypeSupport support = new Tactical.DetectionTypeSupport();
            //Tactical.Detection cachedObj = new Tactical.Detection();
            //support.Copy(cachedObj, detectionData);

            //SampleMarshaler marshaler = SampleMarshalerFactory.CreateMarshaler(detectionData);

            //using (SampleMarshalHelper helper = new SampleMarshalHelper(marshaler))
            //{
            //    DDS.OpenSplice.Gapi.Test.test_detection(helper.GapiPtr);

            //    Tactical.Detection detectionData2 = new Tactical.Detection();
            //    SampleMarshaler marshaler2 = SampleMarshalerFactory.CreateMarshaler(detectionData2);
            //    marshaler2.CopyOut(helper.GapiPtr, 0);
            //}

            //Duration d = new Duration(234, 2343);
            //int sec;
            //uint nanosec;
            //DDS.OpenSplice.Gapi.Test.test_duration(d, out sec, out nanosec);

            //LivelinessChangedStatus status;
            //DDS.OpenSplice.Gapi.Test.get_liveliness_changed_status(out status);

            //Time t = new Time(1, 2);
            //int size = Marshal.SizeOf(t);
            //IntPtr ptr = Marshal.AllocHGlobal(size);
            //Marshal.StructureToPtr(t, ptr, true);
#endif

            //DDS.Test.TestDataReaderQos();
            //DDS.Test.TestTopicQos();

            // Create a DomainParticipantFactory
            DomainParticipantFactory dpf = DomainParticipantFactory.Instance;
            Console.WriteLine("DomainParticipantFactory: " + dpf);

            // Tailor the DomainPartipantFactoryQos;
            DomainParticipantFactoryQos dpfQos = null;
            ReturnCode result = dpf.GetQos(ref dpfQos);
            Console.WriteLine("DomainParticipantFactory.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantFactoryQos.entity_factory.autoenable_created_entities: " + dpfQos.EntityFactory.AutoenableCreatedEntities);

            dpfQos.EntityFactory.AutoenableCreatedEntities = false;
            result = dpf.SetQos(dpfQos);
            Console.WriteLine("DomainParticipantFactory.set_qos: {0}", result);

            // Get the QOS settings for the Factory...  Check values without additional changes
            DomainParticipantFactoryQos dpf2Qos = null;
            result = dpf.GetQos(ref dpf2Qos);
            Console.WriteLine("DomainParticipantFactory.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantFactoryQos.entity_factory.autoenable_created_entities: " + dpf2Qos.EntityFactory.AutoenableCreatedEntities);

            // Create the domainParticipant itself.
            DomainParticipantQos dpQos = new DomainParticipantQos();
            dpQos.UserData.Value = new byte[] { (byte)1, (byte)2, (byte)3 };
            dpQos.EntityFactory.AutoenableCreatedEntities        = true;
            dpQos.ListenerScheduling.SchedulingClass.Kind        = SchedulingClassQosPolicyKind.ScheduleDefault;
            dpQos.ListenerScheduling.SchedulingPriorityKind.Kind = SchedulingPriorityQosPolicyKind.PriorityRelative;
            dpQos.ListenerScheduling.SchedulingPriority          = 0;
            dpQos.WatchdogScheduling.SchedulingClass.Kind        = SchedulingClassQosPolicyKind.ScheduleDefault;
            dpQos.WatchdogScheduling.SchedulingPriorityKind.Kind = SchedulingPriorityQosPolicyKind.PriorityRelative;
            dpQos.WatchdogScheduling.SchedulingPriority          = 4;

            IDomainParticipant dp = dpf.CreateParticipant(null, dpQos);
            Console.Write("DomainParticipant: ");
            Console.WriteLine(dp != null ? "yes" : "no");


            if (dp.ContainsEntity(0))
            {
                Console.WriteLine("contains_entity with nil handle incorrect");
            }
            if (dp.ContainsEntity(100))
            {
                Console.WriteLine("contains_entity with incorrect handle incorrect");
            }

            Time currentTime;
            dp.GetCurrentTime(out currentTime);
            Console.WriteLine("Current Local Time: {0}", currentTime.ToDatetime().ToLocalTime());

            // And look up this DomainParticipant.
            IDomainParticipant dp2 = dpf.LookupParticipant(null);

            DomainParticipantQos dp2Qos = null;

            Console.Write("lookup DomainParticipant: ");
            Console.WriteLine(dp2 != null ? "Success" : "Fail");
            result = dp2.GetQos(ref dp2Qos);
            Console.WriteLine("DomainParticipant.get_qos: {0}", result);
            Console.WriteLine("DomainParticipantQos.entity_factory.autoenable_created_entities: " + dp2Qos.EntityFactory.AutoenableCreatedEntities);

            // Create a new PublisherQos and set some values...
            PublisherQos publisherQos = new PublisherQos();
            publisherQos.EntityFactory.AutoenableCreatedEntities = true;
            publisherQos.Partition.Name = new string[] { "howdy" }; //, "neighbor", "partition" };

            // true not supported in 4.1 ??
            publisherQos.Presentation.OrderedAccess = false;

            // Create the Publisher
            dp.Enable();
            IPublisher publisher = dp.CreatePublisher(publisherQos);
            Console.WriteLine("Create Publisher: {0}", publisher);

            //DataWriterQos dwQos;
            //publisher.GetDefaultDataWriterQos(out dwQos);


            // Create a Detection Type Support and register it's type
            Data.DataTestTypeSupport support = new Data.DataTestTypeSupport();

            string test2 = support.TypeName;
            Console.WriteLine("Register Typesupport");
            result = support.RegisterType(dp, support.TypeName);
            Console.WriteLine("Register Typesupport Result: {0}", result);

            // Create a topic for the Detection type
            TopicQos topicQos = null;
            result = dp.GetDefaultTopicQos(ref topicQos);

            //topicQos.Ownership.Kind = OwnershipQosPolicyKind.ExclusiveOwnershipQos;

            //DDS.Test.TestTopicQos2(ref topicQos);

            // Add a listener to the topic
            ITopic topic = dp.CreateTopic("Data_DataTest", support.TypeName, topicQos,
                                          this, StatusKind.InconsistentTopic);

            topicQos.History.Depth = 5;

            ITopic topic2 = dp.CreateTopic("Data_DataTest", support.TypeName, topicQos);

            //			ErrorCode errorCode;
            //			string msg;
            //			result = ErrorInfo.Update();
            //			result = ErrorInfo.GetCode(out errorCode);
            //			result = ErrorInfo.GetMessage(out msg);

            // Create a DataWriter for the topic
            Data.IDataTestDataWriter dataWriter = publisher.CreateDataWriter(topic) as Data.IDataTestDataWriter;

            // Create a SubscriberQos object and set the partition name
            SubscriberQos subscriberQos = null;
            result = dp.GetDefaultSubscriberQos(ref subscriberQos);
            subscriberQos.Partition.Name = new string[] { "howdy" };

            // Create the subscriber
            ISubscriber sub = dp.CreateSubscriber(subscriberQos);
            // Verify that the subsciber was created...
            if (sub == null)
            {
                Console.WriteLine("Subscriber not created");
                return;
            }

            DDS.DataReaderQos readerQos = null;
            sub.GetDefaultDataReaderQos(ref readerQos);

            //readerQos.SubscriptionKeys.KeyList = new string[] { "test" };
            //readerQos.Durability.Kind = DurabilityQosPolicyKind.TransientDurabilityQos;
            //readerQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos;

            // Create a DataReader for the Detection topic
            Data.IDataTestDataReader dataReader = sub.CreateDataReader(topic, readerQos, this, StatusKind.DataAvailable)
                                                  as Data.IDataTestDataReader;

            // Create a filtered detection topic (only read detections that have an id != 4)
            IContentFilteredTopic filteredTopic = dp.CreateContentFilteredTopic("Another", topic, "TestId <> %0", "4");

            string[] testParams = null;
            result = filteredTopic.GetExpressionParameters(ref testParams);
            result = filteredTopic.SetExpressionParameters("hello", "test");
            result = filteredTopic.GetExpressionParameters(ref testParams);

            // Create a DataReader to read the filtered topic
            IDataReader reader2 = sub.CreateDataReader(filteredTopic);

            IQueryCondition queryCondition = dataReader.CreateQueryCondition(
                "TestId = %0",
                "234");

            // just for testing...
            //GC.Collect();

            // WaitSet
            WaitSet waitSet = new WaitSet();

            // either use status conditions...or
            IStatusCondition sc = reader2.StatusCondition;
            sc.SetEnabledStatuses(StatusKind.DataAvailable);
            waitSet.AttachCondition(sc);

            IStatusCondition sc2 = reader2.StatusCondition;

            // read conditions...
            // IReadCondition readCond = reader2.CreateReadCondition();
            // waitSet.AttachCondition(readCond);

            ICondition[] cond = null;
            //waitSet.Wait(ref cond, Duration.Infinite);


            Console.WriteLine("Press enter to write data");
            Console.ReadLine();

            detectionData.SequenceTest = new int[1];// new System.Collections.Generic.List<int>();
            //detectionData.SequenceTest.Add(4);
            detectionData.SequenceTest[0] = 4;

            // Write detection data
            result = dataWriter.Write(detectionData);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 234;
            dataWriter.Write(detectionData, InstanceHandle.Nil);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 235;
            dataWriter.Write(detectionData);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 236;
            dataWriter.Write(detectionData);

            detectionData        = new Data.DataTest();
            detectionData.TestId = 237;
            dataWriter.Write(detectionData);

            Console.WriteLine("Press enter to read data");
            Console.ReadLine();

            // Read the data
            SampleInfo[]    infos      = null;
            Data.DataTest[] dataValues = null;

//            result = dataReader.ReadWithCondition(ref dataValues, ref infos, DDS.Length.Unlimited, queryCondition);

            result = dataReader.Read(ref dataValues, ref infos);
            Console.WriteLine("dataReader: {0}", dataReader);

            if (dataValues != null)
            {
                Console.WriteLine("Number of samples received: {0}", dataValues.Length);
                for (int index = 0; index < dataValues.Length; index++)
                {
                    Console.WriteLine("TestId: {0}, ProviderId: {1}, Emergency: {2}, TestStr: {3}", dataValues[index].TestId,
                                      dataValues[index].ProviderId, dataValues[index].Emergency, dataValues[index].TestStr);
                    Console.WriteLine("info: ValidData: {0},  InstHandle: {1},  PubHandle:{2},  SourceTS: {3}, ArrivalTS: {4}, sample: {5}, view: {6}, instance: {7}",
                                      infos[index].ValidData,
                                      infos[index].InstanceHandle, infos[index].PublicationHandle,
                                      infos[index].SourceTimestamp, infos[index].ArrivalTimestamp,
                                      infos[index].SampleState, infos[index].ViewState, infos[index].InstanceState);
                }
            }
            Console.WriteLine("Press enter to cleanup");
            Console.ReadLine();

            Console.WriteLine("DeleteContainedEntities");
            result = dp.DeleteContainedEntities();

            // If you don't use DeleteContainedEntities then you must delete everything that was created
            //result = sub.DeleteDataReader(dataReader);
            //result = publisher.DeleteDataWriter(dataWriter);

            //result = dp.DeleteTopic(topic);
            //result = dp.DeletePublisher(publisher);

            //result = dp.DeleteSubscriber(sub);

            Console.WriteLine("DeleteParticipant");
            result = dpf.DeleteParticipant(dp);

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
        public IDomainParticipant CreateParticipant(
            string domainId,
            IDomainParticipantListener listener,
            StatusKind mask)
        {
            IDomainParticipant participant = null;

            if (listener != null)
            {
                OpenSplice.Gapi.gapi_domainParticipantListener gapiListener;
                DomainParticipantListenerHelper listenerHelper = new DomainParticipantListenerHelper();
                listenerHelper.Listener = listener;
                listenerHelper.CreateListener(out gapiListener);
                using (DomainParticipantListenerMarshaler listenerMarshaler =
                           new DomainParticipantListenerMarshaler(ref gapiListener))
                {
                    // Invoke the corresponding gapi function.
                    IntPtr gapiParticipant = OpenSplice.Gapi.DomainParticipantFactory.create_participant(
                        GapiPeer,
                        domainId,
                        OpenSplice.Gapi.NativeConstants.GapiParticipantQosDefault,
                        listenerMarshaler.GapiPtr,
                        mask,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        IntPtr.Zero);
                    if (gapiParticipant != IntPtr.Zero)
                    {
                        participant = new OpenSplice.DomainParticipant(gapiParticipant, listenerHelper);
                    }
                }
            }
            else
            {
                // Invoke the corresponding gapi function.
                IntPtr gapiParticipant = OpenSplice.Gapi.DomainParticipantFactory.create_participant(
                    GapiPeer,
                    domainId,
                    OpenSplice.Gapi.NativeConstants.GapiParticipantQosDefault,
                    IntPtr.Zero,
                    mask,
                    IntPtr.Zero,
                    IntPtr.Zero,
                    IntPtr.Zero);

                if (gapiParticipant != IntPtr.Zero)
                {
                    participant = new OpenSplice.DomainParticipant(gapiParticipant);
                }
            }

            if (participant != null)
            {
                DomainParticipantFactoryQos dpfQos = null;
                ReturnCode result = GetQos(ref dpfQos);
                if (result == ReturnCode.Ok)
                {
                    if (dpfQos.EntityFactory.AutoenableCreatedEntities)
                    {
                        participant.Enable();
                    }
                }
            }

            return(participant);
        }
 internal void CopyOut(ref DomainParticipantFactoryQos to)
 {
     CopyOut(GapiPtr, ref to);
 }
 internal DDS.ReturnCode CopyIn(DomainParticipantFactoryQos from)
 {
     cleanupRequired = true;
     return CopyIn(from, GapiPtr);
 }
 internal static void CopyOut(IntPtr from, ref DomainParticipantFactoryQos to)
 {
     if (to == null) to = new DomainParticipantFactoryQos();
     EntityFactoryQosPolicyMarshaler.CopyOut(from, ref to.EntityFactory, offset_entity_factory);
 }
 internal static DDS.ReturnCode CopyIn(DomainParticipantFactoryQos from, IntPtr to)
 {
     DDS.ReturnCode result;
     if (from != null) {
         result = EntityFactoryQosPolicyMarshaler.CopyIn(from.EntityFactory, to, offset_entity_factory);
     } else {
         result = DDS.ReturnCode.BadParameter;
         DDS.OpenSplice.OS.Report(
                 DDS.OpenSplice.ReportType.OS_ERROR,
                 "DDS.OpenSplice.CustomMarshalers.DomainParticipantFactoryQosMarshaler.CopyIn",
                 "DDS/OpenSplice/CustomMarshalers/QosToplevelMarshalers.cs",
                 DDS.ErrorCode.InvalidValue,
                 "DomainParticipantFactoryQos attribute may not be a null pointer.");
     }
     return result;
 }