public void TestSetQos() { // Create a new Topic using the default QoS TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(_participant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic topic = _participant.CreateTopic(nameof(TestSetQos), typeName); Assert.IsNotNull(topic); Assert.AreEqual(nameof(TestSetQos), topic.Name); Assert.AreEqual(typeName, topic.TypeName); Assert.AreEqual(_participant, topic.Participant); // Get the qos to ensure that is using the default properties TopicQos getQos = new TopicQos(); result = topic.GetQos(getQos); Assert.AreEqual(ReturnCode.Ok, result); TestHelper.TestDefaultTopicQos(getQos); // Try to change an immutable property TopicQos qos = new TopicQos(); qos.DestinationOrder.Kind = DestinationOrderQosPolicyKind.BySourceTimestampDestinationOrderQos; result = topic.SetQos(qos); Assert.AreEqual(ReturnCode.ImmutablePolicy, result); // Change some mutable properties and check them qos = new TopicQos(); qos.Deadline.Period = new Duration { Seconds = 5, NanoSeconds = 0 }; qos.LatencyBudget.Duration = new Duration { Seconds = 5, NanoSeconds = 5 }; qos.Lifespan.Duration = new Duration { Seconds = 5, NanoSeconds = 5 }; qos.TopicData.Value = new List <byte> { 0x5 }; result = topic.SetQos(qos); Assert.AreEqual(ReturnCode.Ok, result); result = topic.GetQos(getQos); Assert.AreEqual(ReturnCode.Ok, result); Assert.IsNotNull(qos); Assert.IsNotNull(qos.Deadline); Assert.IsNotNull(qos.DestinationOrder); Assert.IsNotNull(qos.Durability); Assert.IsNotNull(qos.DurabilityService); Assert.IsNotNull(qos.History); Assert.IsNotNull(qos.LatencyBudget); Assert.IsNotNull(qos.Lifespan); Assert.IsNotNull(qos.Liveliness); Assert.IsNotNull(qos.Ownership); Assert.IsNotNull(qos.Reliability); Assert.IsNotNull(qos.ResourceLimits); Assert.IsNotNull(qos.TopicData); Assert.IsNotNull(qos.TransportPriority); Assert.AreEqual(5, qos.Deadline.Period.Seconds); Assert.AreEqual(Duration.ZeroNanoseconds, qos.Deadline.Period.NanoSeconds); Assert.AreEqual(5, qos.LatencyBudget.Duration.Seconds); Assert.AreEqual((uint)5, qos.LatencyBudget.Duration.NanoSeconds); Assert.AreEqual(5, qos.Lifespan.Duration.Seconds); Assert.AreEqual((uint)5, qos.Lifespan.Duration.NanoSeconds); Assert.AreEqual(1, qos.TopicData.Value.Count()); Assert.AreEqual(0x5, qos.TopicData.Value.First()); // Create a disabled topic and try to set an inconsistent qos DomainParticipantQos pQos = new DomainParticipantQos(); pQos.EntityFactory.AutoenableCreatedEntities = false; _participant.SetQos(pQos); Assert.AreEqual(ReturnCode.Ok, result); Topic otherTopic = _participant.CreateTopic("Other" + nameof(TestSetQos), typeName); Assert.IsNotNull(otherTopic); Assert.AreEqual("Other" + nameof(TestSetQos), otherTopic.Name); Assert.AreEqual(typeName, otherTopic.TypeName); Assert.AreEqual(_participant, otherTopic.Participant); qos = new TopicQos(); qos.History.Kind = HistoryQosPolicyKind.KeepLastHistoryQos; qos.History.Depth = 200; qos.ResourceLimits.MaxSamplesPerInstance = 1; result = otherTopic.SetQos(qos); Assert.AreEqual(ReturnCode.InconsistentPolicy, result); // Test SetQos with null parameter result = topic.SetQos(null); Assert.AreEqual(ReturnCode.BadParameter, result); }
public void TestSetQos() { // Create a new Subscriber using the default QoS Subscriber subscriber = _participant.CreateSubscriber(); // Get the qos to ensure that is using the default properties SubscriberQos qos = new SubscriberQos(); ReturnCode result = subscriber.GetQos(qos); Assert.AreEqual(ReturnCode.Ok, result); TestHelper.TestDefaultSubscriberQos(qos); // Try to change an immutable property qos.Presentation.CoherentAccess = true; qos.Presentation.OrderedAccess = true; qos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.GroupPresentationQos; result = subscriber.SetQos(qos); Assert.AreEqual(ReturnCode.ImmutablePolicy, result); // Change some mutable properties and check them qos = new SubscriberQos(); qos.EntityFactory.AutoenableCreatedEntities = false; qos.GroupData.Value = new List <byte> { 0x42 }; qos.Partition.Name = new List <string> { "TestPartition" }; result = subscriber.SetQos(qos); Assert.AreEqual(ReturnCode.Ok, result); qos = new SubscriberQos(); result = subscriber.GetQos(qos); Assert.AreEqual(ReturnCode.Ok, result); Assert.IsNotNull(qos.EntityFactory); Assert.IsNotNull(qos.GroupData); Assert.IsNotNull(qos.Partition); Assert.IsNotNull(qos.Presentation); Assert.IsFalse(qos.EntityFactory.AutoenableCreatedEntities); Assert.IsNotNull(qos.GroupData.Value); Assert.AreEqual(1, qos.GroupData.Value.Count()); Assert.AreEqual(0x42, qos.GroupData.Value.First()); Assert.IsNotNull(qos.Partition.Name); Assert.AreEqual(1, qos.Partition.Name.Count()); Assert.AreEqual("TestPartition", qos.Partition.Name.First()); Assert.IsFalse(qos.Presentation.CoherentAccess); Assert.IsFalse(qos.Presentation.OrderedAccess); Assert.AreEqual(PresentationQosPolicyAccessScopeKind.InstancePresentationQos, qos.Presentation.AccessScope); // Try to set immutable QoS properties before enable the publisher DomainParticipantQos pQos = new DomainParticipantQos(); pQos.EntityFactory.AutoenableCreatedEntities = false; result = _participant.SetQos(pQos); Assert.AreEqual(ReturnCode.Ok, result); Subscriber otherSubscriber = _participant.CreateSubscriber(); qos = new SubscriberQos(); qos.EntityFactory.AutoenableCreatedEntities = false; qos.GroupData.Value = new List <byte> { 0x42 }; qos.Partition.Name = new List <string> { "TestPartition" }; qos.Presentation.CoherentAccess = true; qos.Presentation.OrderedAccess = true; qos.Presentation.AccessScope = PresentationQosPolicyAccessScopeKind.GroupPresentationQos; result = otherSubscriber.SetQos(qos); Assert.AreEqual(ReturnCode.Ok, result); qos = new SubscriberQos(); result = otherSubscriber.GetQos(qos); Assert.AreEqual(ReturnCode.Ok, result); Assert.IsNotNull(qos.EntityFactory); Assert.IsNotNull(qos.GroupData); Assert.IsNotNull(qos.Partition); Assert.IsNotNull(qos.Presentation); Assert.IsFalse(qos.EntityFactory.AutoenableCreatedEntities); Assert.IsNotNull(qos.GroupData.Value); Assert.AreEqual(1, qos.GroupData.Value.Count()); Assert.AreEqual(0x42, qos.GroupData.Value.First()); Assert.IsNotNull(qos.Partition.Name); Assert.AreEqual(1, qos.Partition.Name.Count()); Assert.AreEqual("TestPartition", qos.Partition.Name.First()); Assert.IsTrue(qos.Presentation.CoherentAccess); Assert.IsTrue(qos.Presentation.OrderedAccess); Assert.AreEqual(PresentationQosPolicyAccessScopeKind.GroupPresentationQos, qos.Presentation.AccessScope); // Test SetQos with null parameter result = subscriber.SetQos(null); Assert.AreEqual(ReturnCode.BadParameter, result); }
static void Main(string[] args) { bool useListener = true; OpenDDSharp.Ace.Init(); ParticipantService participantService = ParticipantService.Instance; DomainParticipantFactory domainFactory = participantService.GetDomainParticipantFactory(args); DomainParticipantQos qos = new DomainParticipantQos(); qos.EntityFactory.AutoenableCreatedEntities = false; qos.UserData.Value = Encoding.UTF8.GetBytes("sometext"); DomainParticipant participant = domainFactory.CreateParticipant(42, qos); if (participant == null) { throw new Exception("Could not create the participant"); } DomainParticipantQos aux = new DomainParticipantQos(); ReturnCode ret = participant.GetQos(aux); aux.EntityFactory.AutoenableCreatedEntities = true; ret = participant.SetQos(aux); if (participant != null) { TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(participant, typeName); if (result != ReturnCode.Ok) { throw new Exception("Could not register the type"); } Topic topic = participant.CreateTopic("TopicName", typeName); Publisher publisher = participant.CreatePublisher(); if (publisher == null) { throw new Exception("Could not create the publisher"); } DataWriter dw = publisher.CreateDataWriter(topic); if (dw == null) { throw new Exception("Could not create the datawriter"); } TestStructDataWriter dataWriter = new TestStructDataWriter(dw); Subscriber subscriber = participant.CreateSubscriber(); if (subscriber == null) { throw new Exception("Could not create the subscribre"); } MyDataListener listener = null; if (useListener) { listener = new MyDataListener(); } DataReader dataReader = subscriber.CreateDataReader(topic, listener, StatusKind.DataAvailableStatus); if (dataReader == null) { throw new Exception("Could not create the datareader"); } WaitSet waitSet = null; StatusCondition statusCondition = null; if (!useListener) { waitSet = new WaitSet(); statusCondition = dataReader.StatusCondition; waitSet.AttachCondition(statusCondition); statusCondition.EnabledStatuses = StatusKind.DataAvailableStatus; new System.Threading.Thread(delegate() { ICollection <Condition> conditions = new List <Condition>(); Duration duration = new Duration { Seconds = Duration.InfiniteSeconds }; waitSet.Wait(conditions, duration); foreach (Condition cond in conditions) { if (cond == statusCondition && cond.TriggerValue) { StatusCondition sCond = (StatusCondition)cond; StatusMask mask = sCond.EnabledStatuses; if ((mask & StatusKind.DataAvailableStatus) != 0) { DataAvailable(dataReader); } } } }).Start(); } TestStruct test = new TestStruct { RawData = "Hello, I love you, won't you tell me your name?" }; test.LongSequence.Add(20); test.LongSequence.Add(10); test.LongSequence.Add(0); test.StringSequence.Add("Hello,"); test.StringSequence.Add("I love you"); test.StringSequence.Add("won't you tell me your name?"); test.LongDoubleType = 1.1; test.LongDoubleSequence.Add(1.1); test.LongDoubleSequence.Add(2.2); test.LongDoubleSequence.Add(3.3); test.LongArray[0, 0] = 1; test.LongArray[0, 1] = 2; test.LongArray[0, 2] = 3; test.LongArray[0, 3] = 4; test.LongArray[1, 0] = 1; test.LongArray[1, 1] = 2; test.LongArray[1, 2] = 3; test.LongArray[1, 3] = 4; test.LongArray[2, 0] = 1; test.LongArray[2, 1] = 2; test.LongArray[2, 2] = 3; test.LongArray[2, 3] = 4; test.StringArray[0, 0] = "Hello,"; test.StringArray[0, 1] = "I love you,"; test.StringArray[1, 0] = "won't you tell me"; test.StringArray[1, 1] = "your name?"; test.StructArray[0, 0] = new BasicTestStruct() { Id = 0 }; test.StructArray[0, 1] = new BasicTestStruct() { Id = 1 }; test.StructArray[1, 0] = new BasicTestStruct() { Id = 2 }; test.StructArray[1, 1] = new BasicTestStruct() { Id = 3 }; test.LongDoubleArray[0, 0] = 1.1; test.LongDoubleArray[0, 1] = 2.2; test.LongDoubleArray[1, 0] = 3.3; test.LongDoubleArray[1, 1] = 4.4; test.StructSequence.Add(new BasicTestStruct() { Id = 1 }); test.StructSequence.Add(new BasicTestStruct() { Id = 2 }); test.StructSequence.Add(new BasicTestStruct() { Id = 3 }); result = dataWriter.Write(test); System.Threading.Thread.Sleep(1000); if (!useListener) { waitSet.DetachCondition(statusCondition); } participant.DeleteContainedEntities(); domainFactory.DeleteParticipant(participant); } participantService.Shutdown(); OpenDDSharp.Ace.Fini(); Console.WriteLine("Press ENTER to finish the test."); Console.ReadLine(); }