/// <summary> /// Creates a DomainParticipant, Topic, Subscriber and DataReader<HelloWorld>. /// </summary> public HelloWorldSubscriber(int domainId) { // Enable network capture. // This must be called before any other network capture function, and // before creating any participant for which we want to capture traffic. NetworkCapture.Enable(); // Start communicating in a domain, usually one participant per application // Load QoS profile from USER_QOS_PROFILES.xml file participant = DomainParticipantFactory.Instance.CreateParticipant(domainId); // A Topic has a name and a datatype. Topic <HelloWorld> topic = participant.CreateTopic <HelloWorld>( "Network capture shared memory example"); // Create a subscriber Subscriber subscriber = participant.CreateSubscriber(); // Create a DataReader, loading QoS profile from USER_QOS_PROFILES.xml. reader = subscriber.CreateDataReader(topic); // Obtain the DataReader's Status Condition StatusCondition statusCondition = reader.StatusCondition; // Enable the 'data available' status. statusCondition.EnabledStatuses = StatusMask.DataAvailable; // Associate an event handler with the status condition. // This will run when the condition is triggered, in the context of // the dispatch call (see below) statusCondition.Triggered += ProcessData; // Create a WaitSet and attach the StatusCondition waitset.AttachCondition(statusCondition); }
/// <summary> /// Publishes the data /// </summary> public void Run(int sampleCount) { // Start capturing traffic for all participants. NetworkCapture capture = NetworkCapture.Start("publisher"); var sample = new HelloWorld(); for (int count = 0; count < sampleCount && continueRunning; count++) { // Modify the data to be sent here sample.msg = $"Hello {count}"; Console.WriteLine($"Writing HelloWorld, count {count}"); if (count == 4) { Console.WriteLine("Pausing the capture at sample 4"); capture.Pause(); } else if (count == 6) { Console.WriteLine("Resuming the capture at sample 6"); capture.Resume(); } writer.Write(sample); Thread.Sleep(1000); } }
/// <summary> /// Disposes all DDS entities created by this application. /// </summary> public void Dispose() { participant.Dispose(); // Disable network capture. // This must be the last network capture operation that is called. NetworkCapture.Disable(); }
/// <summary> /// Processes the data received by the DataReader. /// </summary> public void Run(int sampleCount) { // Start capturing traffic for one participant. NetworkCapture capture = NetworkCapture.Start( participant, "subscriber"); while (samplesRead < sampleCount && continueRunning) { // Dispatch will call the handlers associated to the WaitSet // conditions when they activate Console.WriteLine("HelloWorld subscriber sleeping for 4 sec..."); waitset.Dispatch(Duration.FromSeconds(4)); } }
/// <summary> /// Creates a DomainParticipant, Topic, Publisher and DataWriter<HelloWorld>. /// </summary> public HelloWorldPublisher(int domainId) { // Enable network capture. // This must be called before any other network capture function, and // before creating any participant for which we want to capture traffic. NetworkCapture.Enable(); // Start communicating in a domain, usually one participant per application // Load QoS profile from USER_QOS_PROFILES.xml file participant = DomainParticipantFactory.Instance.CreateParticipant(domainId); // A Topic has a name and a datatype. Topic <HelloWorld> topic = participant.CreateTopic <HelloWorld>( "Network capture shared memory example"); // Create a Publisher Publisher publisher = participant.CreatePublisher(); // Create a DataWriter, loading QoS profile from USER_QOS_PROFILES.xml, and writer = publisher.CreateDataWriter(topic); }