public void TestRead() { List <ParticipantBuiltinTopicData> data = new List <ParticipantBuiltinTopicData>(); List <SampleInfo> infos = new List <SampleInfo>(); ReturnCode ret = _dr.Read(data, infos); Assert.AreEqual(ReturnCode.NoData, ret); Assert.AreEqual(0, data.Count); Assert.AreEqual(0, infos.Count); DomainParticipantQos qos = new DomainParticipantQos(); qos.UserData.Value = new byte[] { 0x42 }; DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); Thread.Sleep(500); ret = _dr.Read(data, infos); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); Assert.AreEqual(1, data.First().UserData.Value.Count()); Assert.AreEqual(0x42, data.First().UserData.Value.First()); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestTakeNextInstance() { List <ParticipantBuiltinTopicData> data = new List <ParticipantBuiltinTopicData>(); List <SampleInfo> infos = new List <SampleInfo>(); ReturnCode ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.NoData, ret); Assert.AreEqual(0, data.Count); Assert.AreEqual(0, infos.Count); DomainParticipantQos qos = new DomainParticipantQos(); qos.UserData.Value = new byte[] { 0x42 }; DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); Assert.IsTrue(_participant.WaitForParticipants(1, 20_000)); ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); Assert.AreEqual(1, data.First().UserData.Value.Count); Assert.AreEqual(0x42, data.First().UserData.Value.First()); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestTakeNextSample() { ParticipantBuiltinTopicData data = default; SampleInfo infos = new SampleInfo(); ReturnCode ret = _dr.TakeNextSample(ref data, infos); Assert.AreEqual(ReturnCode.NoData, ret); DomainParticipantQos qos = new DomainParticipantQos(); qos.UserData.Value = new byte[] { 0x42 }; DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); Assert.IsTrue(_participant.WaitForParticipants(1, 20_000)); ret = _dr.TakeNextSample(ref data, infos); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.UserData.Value.Count); Assert.AreEqual(0x42, data.UserData.Value.First()); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestLookupInstance() { ParticipantBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); DomainParticipantQos qos = new DomainParticipantQos(); qos.UserData.Value = new byte[] { 0x42 }; DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); Thread.Sleep(500); ReturnCode ret = _dr.ReadNextSample(ref data, info); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.UserData.Value.Count()); Assert.AreEqual(0x42, data.UserData.Value.First()); // Lookup for an existing instance var handle = _dr.LookupInstance(data); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void Dispose() { if (!_disposed) { foreach (ShapeWaitSet waitSet in _shapeWaitSets) { waitSet.Dispose(); } _shapeWaitSets.Clear(); foreach (ShapeDynamic shape in _shapeDynamics) { shape.Dispose(); } _shapeDynamics.Clear(); if (_participant != null) { _participant.DeleteContainedEntities(); _domainFactory.DeleteParticipant(_participant); } TransportRegistry.Instance.Release(); TransportRegistry.Close(); ParticipantService.Instance.Shutdown(); _disposed = true; } }
public void TestReadInstance() { List <SubscriptionBuiltinTopicData> data = new List <SubscriptionBuiltinTopicData>(); List <SampleInfo> infos = new List <SampleInfo>(); ReturnCode ret = _dr.Read(data, infos); Assert.AreEqual(ReturnCode.NoData, ret); Assert.AreEqual(0, data.Count); Assert.AreEqual(0, infos.Count); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName); Assert.IsNotNull(topic); var subscriber = otherParticipant.CreateSubscriber(); Assert.IsNotNull(subscriber); DataReaderQos drQos = TestHelper.CreateNonDefaultDataReaderQos(); DataReader dataReader = subscriber.CreateDataReader(topic, drQos); Assert.IsNotNull(dataReader); Thread.Sleep(500); ret = _dr.ReadNextInstance(data, infos, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); TestHelper.TestNonDefaultSubscriptionData(data.First()); var handle = infos.First().InstanceHandle; data = new List <SubscriptionBuiltinTopicData>(); infos = new List <SampleInfo>(); ret = _dr.ReadInstance(data, infos, handle); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); TestHelper.TestNonDefaultSubscriptionData(data.First()); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestTakeNextInstance() { List <PublicationBuiltinTopicData> data = new List <PublicationBuiltinTopicData>(); List <SampleInfo> infos = new List <SampleInfo>(); ReturnCode ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.NoData, ret); Assert.AreEqual(0, data.Count); Assert.AreEqual(0, infos.Count); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); Assert.IsTrue(_participant.WaitForParticipants(1, 20_000)); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName); Assert.IsNotNull(topic); var publisher = otherParticipant.CreatePublisher(); Assert.IsNotNull(publisher); DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos(); dwQos.Ownership.Kind = OwnershipQosPolicyKind.SharedOwnershipQos; DataWriter dataWriter = publisher.CreateDataWriter(topic, dwQos); Assert.IsNotNull(dataWriter); int count = 200; ret = ReturnCode.NoData; while (ret != ReturnCode.Ok && count > 0) { Thread.Sleep(100); ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); count--; } Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); TestHelper.TestNonDefaultPublicationData(data.First()); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestGetKeyValue() { // Call GetKeyValue with HandleNil PublicationBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); ReturnCode ret = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.BadParameter, ret); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName); Assert.IsNotNull(topic); var publisher = otherParticipant.CreatePublisher(); Assert.IsNotNull(publisher); DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos(); dwQos.Ownership.Kind = OwnershipQosPolicyKind.SharedOwnershipQos; DataWriter dataWriter = publisher.CreateDataWriter(topic, dwQos); Assert.IsNotNull(dataWriter); Thread.Sleep(500); // Get the for an existing instance ret = _dr.ReadNextSample(ref data, info); Assert.AreEqual(ReturnCode.Ok, ret); TestHelper.TestNonDefaultPublicationData(data); PublicationBuiltinTopicData aux = default; ret = _dr.GetKeyValue(ref aux, info.InstanceHandle); Assert.AreEqual(ReturnCode.Ok, ret); for (int i = 0; i < 3; i++) { Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]); } ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestTakeNextInstance() { ReturnCode ret; DomainParticipant otherParticipant = null; Topic topic = null; try { List <TopicBuiltinTopicData> data = new List <TopicBuiltinTopicData>(); List <SampleInfo> infos = new List <SampleInfo>(); ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.NoData, ret); Assert.AreEqual(0, data.Count); Assert.AreEqual(0, infos.Count); otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); TopicQos qos = TestHelper.CreateNonDefaultTopicQos(); topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos); Assert.IsNotNull(topic); int count = 200; ret = ReturnCode.NoData; while (ret != ReturnCode.Ok && count > 0) { Thread.Sleep(100); ret = _dr.TakeNextInstance(data, infos, InstanceHandle.HandleNil); count--; } Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); Assert.AreEqual(typeName, data.First().TypeName); Assert.IsNotNull(data.First().Key); TestHelper.TestNonDefaultTopicData(data.First()); } finally { ret = otherParticipant.DeleteTopic(topic); Assert.AreEqual(ReturnCode.Ok, ret); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); } }
public void TestLookupInstance() { SubscriptionBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName); Assert.IsNotNull(topic); var subscriber = otherParticipant.CreateSubscriber(); Assert.IsNotNull(subscriber); DataReaderQos drQos = TestHelper.CreateNonDefaultDataReaderQos(); DataReader dataReader = subscriber.CreateDataReader(topic, drQos); Assert.IsNotNull(dataReader); int count = 200; ReturnCode ret = ReturnCode.NoData; while (ret != ReturnCode.Ok && count > 0) { Thread.Sleep(100); // Get the for an existing instance ret = _dr.ReadNextSample(ref data, info); count--; } Assert.AreEqual(ReturnCode.Ok, ret); TestHelper.TestNonDefaultSubscriptionData(data); // Lookup for an existing instance var handle = _dr.LookupInstance(data); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestLookupInstance() { ReturnCode ret; DomainParticipant otherParticipant = null; Topic topic = null; try { TopicBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); TopicQos qos = TestHelper.CreateNonDefaultTopicQos(); topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos); Assert.IsNotNull(topic); int count = 200; ret = ReturnCode.NoData; while (ret != ReturnCode.Ok && count > 0) { Thread.Sleep(100); ret = _dr.ReadNextSample(ref data, info); count--; } Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(typeName, data.TypeName); Assert.IsNotNull(data.Key); TestHelper.TestNonDefaultTopicData(data); // Lookup for an existing instance var handle = _dr.LookupInstance(data); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); } finally { ret = otherParticipant.DeleteTopic(topic); Assert.AreEqual(ReturnCode.Ok, ret); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); } }
public void TestCleanup() { if (_participant != null) { ReturnCode result = _participant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, result); } if (AssemblyInitializer.Factory != null) { ReturnCode result = AssemblyInitializer.Factory.DeleteParticipant(_participant); Assert.AreEqual(ReturnCode.Ok, result); } }
public void TestLookupInstance() { PublicationBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName); Assert.IsNotNull(topic); var publisher = otherParticipant.CreatePublisher(); Assert.IsNotNull(publisher); DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos(); dwQos.Ownership.Kind = OwnershipQosPolicyKind.SharedOwnershipQos; DataWriter dataWriter = publisher.CreateDataWriter(topic, dwQos); Assert.IsNotNull(dataWriter); Thread.Sleep(500); ReturnCode ret = _dr.ReadNextSample(ref data, info); Assert.AreEqual(ReturnCode.Ok, ret); // Lookup for an existing instance var handle = _dr.LookupInstance(data); Assert.AreNotEqual(InstanceHandle.HandleNil, handle); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); TestHelper.TestNonDefaultPublicationData(data); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestGetKeyValue() { // Call GetKeyValue with HandleNil TopicBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); ReturnCode ret = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.BadParameter, ret); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindTcpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); TopicQos qos = TestHelper.CreateNonDefaultTopicQos(); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos); Assert.IsNotNull(topic); Thread.Sleep(500); // Get the for an existing instance ret = _dr.ReadNextSample(ref data, info); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(typeName, data.TypeName); Assert.IsNotNull(data.Key); TestHelper.TestNonDefaultTopicData(data); TopicBuiltinTopicData aux = default; ret = _dr.GetKeyValue(ref aux, info.InstanceHandle); Assert.AreEqual(ReturnCode.Ok, ret); for (int i = 0; i < 3; i++) { Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]); } ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestTakeNextSample() { SubscriptionBuiltinTopicData data = default; SampleInfo infos = new SampleInfo(); ReturnCode ret = _dr.TakeNextSample(ref data, infos); Assert.AreEqual(ReturnCode.NoData, ret); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName); Assert.IsNotNull(topic); var subscriber = otherParticipant.CreateSubscriber(); Assert.IsNotNull(subscriber); DataReaderQos drQos = TestHelper.CreateNonDefaultDataReaderQos(); DataReader dataReader = subscriber.CreateDataReader(topic, drQos); Assert.IsNotNull(dataReader); Thread.Sleep(500); ret = _dr.TakeNextSample(ref data, infos); Assert.AreEqual(ReturnCode.Ok, ret); TestHelper.TestNonDefaultSubscriptionData(data); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
public void TestRead() { List <TopicBuiltinTopicData> data = new List <TopicBuiltinTopicData>(); List <SampleInfo> infos = new List <SampleInfo>(); ReturnCode ret = _dr.Read(data, infos); Assert.AreEqual(ReturnCode.NoData, ret); Assert.AreEqual(0, data.Count); Assert.AreEqual(0, infos.Count); DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindTcpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); TopicQos qos = TestHelper.CreateNonDefaultTopicQos(); var topic = otherParticipant.CreateTopic(TestContext.TestName, typeName, qos); Assert.IsNotNull(topic); Thread.Sleep(500); ret = _dr.Read(data, infos); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.Count); Assert.AreEqual(1, infos.Count); Assert.AreEqual(typeName, data.First().TypeName); Assert.IsNotNull(data.First().Key); TestHelper.TestNonDefaultTopicData(data.First()); ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
static void Main(string[] args) { Ace.Init(); DomainParticipantFactory dpf = ParticipantService.Instance.GetDomainParticipantFactory("-DCPSConfigFile", "rtps.ini"); DomainParticipant participant = dpf.CreateParticipant(42); if (participant == null) { throw new Exception("Could not create the participant"); } // Include your program here participant.DeleteContainedEntities(); dpf.DeleteParticipant(participant); ParticipantService.Instance.Shutdown(); Ace.Fini(); }
public void TestGetKeyValue() { // Call GetKeyValue with HandleNil ParticipantBuiltinTopicData data = default; SampleInfo info = new SampleInfo(); ReturnCode ret = _dr.GetKeyValue(ref data, InstanceHandle.HandleNil); Assert.AreEqual(ReturnCode.BadParameter, ret); DomainParticipantQos qos = new DomainParticipantQos(); qos.UserData.Value = new byte[] { 0x42 }; DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN, qos); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); Assert.IsTrue(_participant.WaitForParticipants(1, 20_000)); Assert.IsTrue(otherParticipant.WaitForParticipants(1, 20_000)); // Get the for an existing instance ret = _dr.ReadNextSample(ref data, info); Assert.AreEqual(ReturnCode.Ok, ret); Assert.AreEqual(1, data.UserData.Value.Count); Assert.AreEqual(0x42, data.UserData.Value.First()); ParticipantBuiltinTopicData aux = default; ret = _dr.GetKeyValue(ref aux, info.InstanceHandle); Assert.AreEqual(ReturnCode.Ok, ret); for (int i = 0; i < 3; i++) { Assert.AreEqual(data.Key.Value[i], aux.Key.Value[i]); } ret = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, ret); ret = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, ret); }
static void Main(string[] args) { bool isPublisher = true; if (args != null && args.Length > 0) { isPublisher = !args[0].ToLowerInvariant().Equals("--sub") && !args[0].ToLowerInvariant().Equals("--subscriber"); } Ace.Init(); DomainParticipantFactory dpf = ParticipantService.Instance.GetDomainParticipantFactory("-DCPSConfigFile", "rtps.ini", "-DCPSDebugLevel", "10", "-ORBLogFile", "LogFile.log", "-ORBDebugLevel", "10"); if (dpf == null) { throw new ApplicationException("Domain participant factory could not be created."); } DomainParticipant participant = dpf.CreateParticipant(42); if (dpf == null) { throw new ApplicationException("Domain participant could not be created."); } if (isPublisher) { TestPublisher(participant); } else { TestSubscriber(participant); } Console.WriteLine("Shutting down... that's enough for today."); participant.DeleteContainedEntities(); dpf.DeleteParticipant(participant); ParticipantService.Instance.Shutdown(); Ace.Fini(); }
public void TestCleanup() { if (_participant != null) { ReturnCode result = _participant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, result); } if (AssemblyInitializer.Factory != null) { ReturnCode result = AssemblyInitializer.Factory.DeleteParticipant(_participant); Assert.AreEqual(ReturnCode.Ok, result); } _participant = null; _publisher = null; _subscriber = null; _topic = null; _writer = null; _dataWriter = null; _reader = null; }
public void TestDeleteParticipant() { DomainParticipant participant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(participant); participant.BindRtpsUdpTransportConfig(); Subscriber subscriber = participant.CreateSubscriber(); Assert.IsNotNull(subscriber); ReturnCode result = AssemblyInitializer.Factory.DeleteParticipant(participant); Assert.AreEqual(ReturnCode.PreconditionNotMet, result); result = participant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, result); result = AssemblyInitializer.Factory.DeleteParticipant(participant); Assert.AreEqual(ReturnCode.Ok, result); result = AssemblyInitializer.Factory.DeleteParticipant(null); Assert.AreEqual(ReturnCode.Ok, result); }
static void Main(string[] args) { Ace.Init(); DomainParticipantFactory dpf = ParticipantService.Instance.GetDomainParticipantFactory("-DCPSConfigFile", "rtps.ini"); DomainParticipant participant = dpf.CreateParticipant(42); if (participant == null) { throw new Exception("Could not create the participant"); } MessageTypeSupport support = new MessageTypeSupport(); ReturnCode result = support.RegisterType(participant, support.GetTypeName()); if (result != ReturnCode.Ok) { throw new Exception("Could not register type: " + result.ToString()); } Topic topic = participant.CreateTopic("MessageTopic", support.GetTypeName()); if (topic == null) { throw new Exception("Could not create the message topic"); } Publisher publisher = participant.CreatePublisher(); if (publisher == null) { throw new Exception("Could not create the publisher"); } DataWriter writer = publisher.CreateDataWriter(topic); if (writer == null) { throw new Exception("Could not create the data writer"); } MessageDataWriter messageWriter = new MessageDataWriter(writer); Console.WriteLine("Waiting for a subscriber..."); PublicationMatchedStatus status = new PublicationMatchedStatus(); do { result = messageWriter.GetPublicationMatchedStatus(ref status); System.Threading.Thread.Sleep(500); }while (status.CurrentCount < 1); Console.WriteLine("Subscriber found, writting data...."); messageWriter.Write(new Message { Content = "Hello, I love you, won't you tell me your name?" }); Console.WriteLine("Press a key to exit..."); Console.ReadKey(); participant.DeleteContainedEntities(); dpf.DeleteParticipant(participant); ParticipantService.Instance.Shutdown(); Ace.Fini(); }
public void TestOnPublicationLost() { ManualResetEventSlim evt = new ManualResetEventSlim(false); DomainParticipant domainParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.INFOREPO_DOMAIN); Assert.IsNotNull(domainParticipant); domainParticipant.BindTcpTransportConfig(); Publisher publisher = domainParticipant.CreatePublisher(); Assert.IsNotNull(publisher); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(domainParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic topic = domainParticipant.CreateTopic("TestOnPublicationLostDisconnected", typeName); Assert.IsNotNull(topic); MyDataWriterListener listener = new MyDataWriterListener(); DataWriter writer = publisher.CreateDataWriter(topic, listener); int count = 0; listener.PublicationLost += (w, s) => { Assert.AreEqual(writer, w); Assert.AreEqual(1, s.SubscriptionHandles.Count()); Assert.AreNotEqual(InstanceHandle.HandleNil, s.SubscriptionHandles.First()); count++; evt.Set(); }; SupportProcessHelper supportProcess = new SupportProcessHelper(TestContext); Process process = supportProcess.SpawnSupportProcess(SupportTestKind.PublicationLostTest); try { // Wait for discovery bool found = writer.WaitForSubscriptions(1, 20000); Assert.IsTrue(found); } finally { supportProcess.KillProcess(process); } bool resp = evt.Wait(20000); Assert.IsTrue(resp); Assert.AreEqual(1, count); // Remove the listener to avoid extra messages result = writer.SetListener(null); Assert.AreEqual(ReturnCode.Ok, result); domainParticipant.DeleteContainedEntities(); AssemblyInitializer.Factory.DeleteParticipant(domainParticipant); evt.Dispose(); }
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(); }
public void TestGetMatchedSubscriptionData() { // Initialize entities DataWriterQos dwQos = TestHelper.CreateNonDefaultDataWriterQos(); dwQos.Reliability.Kind = ReliabilityQosPolicyKind.ReliableReliabilityQos; DataWriter writer = _publisher.CreateDataWriter(_topic, dwQos); Assert.IsNotNull(writer); // DCPSInfoRepo-based discovery generates Built-In Topic data once (inside the // info repo process) and therefore all known entities in the domain are // reflected in the Built-In Topics. RTPS discovery, on the other hand, follows // the DDS specification and omits "local" entities from the Built-In Topics. // The definition of "local" means those entities belonging to the same Domain // Participant as the given Built-In Topic Subscriber. // https://github.com/objectcomputing/OpenDDS/blob/master/docs/design/RTPS // OPENDDS ISSUE: GetMatchedSubscriptions returns local entities but GetMatchedSubscriptionData doesn't // because is looking in the Built-in topic. If not found in the built-in, shouldn't try to look locally? // WORKAROUND: Create another particpant for the DataReader. DomainParticipant otherParticipant = AssemblyInitializer.Factory.CreateParticipant(AssemblyInitializer.RTPS_DOMAIN); Assert.IsNotNull(otherParticipant); otherParticipant.BindRtpsUdpTransportConfig(); TestStructTypeSupport support = new TestStructTypeSupport(); string typeName = support.GetTypeName(); ReturnCode result = support.RegisterType(otherParticipant, typeName); Assert.AreEqual(ReturnCode.Ok, result); Topic otherTopic = otherParticipant.CreateTopic(nameof(TestGetMatchedSubscriptionData), typeName); Assert.IsNotNull(otherTopic); Subscriber subscriber = otherParticipant.CreateSubscriber(); Assert.IsNotNull(subscriber); DataReaderQos drQos = TestHelper.CreateNonDefaultDataReaderQos(); DataReader reader = subscriber.CreateDataReader(otherTopic, drQos); Assert.IsNotNull(reader); // Wait for subscriptions bool found = writer.WaitForSubscriptions(1, 5000); Assert.IsTrue(found); // Get the matched subscriptions List <InstanceHandle> list = new List <InstanceHandle>(); result = writer.GetMatchedSubscriptions(list); Assert.AreEqual(ReturnCode.Ok, result); Assert.AreEqual(1, list.Count); // Get the matched subscription data SubscriptionBuiltinTopicData data = default; result = writer.GetMatchedSubscriptionData(list.First(), ref data); Assert.AreEqual(ReturnCode.Ok, result); TestHelper.TestNonDefaultSubscriptionData(data); // Destroy the other participant result = otherParticipant.DeleteContainedEntities(); Assert.AreEqual(ReturnCode.Ok, result); result = AssemblyInitializer.Factory.DeleteParticipant(otherParticipant); Assert.AreEqual(ReturnCode.Ok, result); }
static void Main(string[] args) { Ace.Init(); DomainParticipantFactory dpf = ParticipantService.Instance.GetDomainParticipantFactory("-DCPSConfigFile", "rtps.ini"); DomainParticipant participant = dpf.CreateParticipant(42); if (participant == null) { throw new Exception("Could not create the participant"); } MessageTypeSupport support = new MessageTypeSupport(); ReturnCode result = support.RegisterType(participant, support.GetTypeName()); if (result != ReturnCode.Ok) { throw new Exception("Could not register type: " + result.ToString()); } Topic topic = participant.CreateTopic("MessageTopic", support.GetTypeName()); if (topic == null) { throw new Exception("Could not create the message topic"); } Subscriber subscriber = participant.CreateSubscriber(); if (subscriber == null) { throw new Exception("Could not create the subscriber"); } DataReader reader = subscriber.CreateDataReader(topic); if (reader == null) { throw new Exception("Could not create the message data reader"); } MessageDataReader messageReader = new MessageDataReader(reader); while (true) { StatusMask mask = messageReader.StatusChanges; if ((mask & StatusKind.DataAvailableStatus) != 0) { List <Message> receivedData = new List <Message>(); List <SampleInfo> receivedInfo = new List <SampleInfo>(); result = messageReader.Take(receivedData, receivedInfo); if (result == ReturnCode.Ok) { bool messageReceived = false; for (int i = 0; i < receivedData.Count; i++) { if (receivedInfo[i].ValidData) { Console.WriteLine(receivedData[i].Content); messageReceived = true; } } if (messageReceived) { break; } } } System.Threading.Thread.Sleep(100); } Console.WriteLine("Press a key to exit..."); Console.ReadKey(); participant.DeleteContainedEntities(); dpf.DeleteParticipant(participant); ParticipantService.Instance.Shutdown(); Ace.Fini(); }