Recording Service Converter Application Timing

5 posts / 0 new
Last post
Offline
Last seen: 1 month 1 week ago
Joined: 11/11/2024
Posts: 3
Recording Service Converter Application Timing

Hello,

I am trying to write an application for Recording Service Converter in C++ (although my question is language agnostic). 

In the ServiceAsLib examples, https://github.com/rticommunity/rticonnextdds-examples/blob/master/examples/recording_service/service_as_lib/c%2B%2B11/ServiceAsLibExample.cxx, the embedded_service calls start(), waits, and then calls stop().

I have modified this example to introduce a Converter role which should work very similarly. However, if stop is called too quickly after start, then the program does not have a chance to process all of the topics from the recording. Depending on the size of the recorded data, the number of topics, and the sleep time, it could miss some of the data. 

There are some ways to tune this. I have added more threads in the service tag of the config file which helps alleviate the issue when the recording size is small. However, it's not deterministic. 

Is there some way to check the processing state of the service? something like the following:

embedded_service.start();

while(!embedded_service.done()){// wait}

embedded_service.stop();

It seems like the command-line tool rticonverter does this and somehow waits for all data to be processed before returning. But I don't understand how since I cannot see the source code.

Howard's picture
Offline
Last seen: 5 days 23 hours ago
Joined: 11/29/2012
Posts: 618

I think you need to use the "HookFunc" in the constructor of the Service to get notified when the conversion is terminated (this is the same as replay).

See this doc

https://community.rti.com/static/documentation/connext-dds/current/doc/api/recording_service/api_cpp/classrti_1_1recording_1_1Service.html#a98ce14210a948e1bb97d916c09fe7741

 

Offline
Last seen: 1 month 1 week ago
Joined: 11/11/2024
Posts: 3

Thank you. I gave this a try.

If I create the HookFunc, it seems like there is a race condition. The following does not result in conversion files created:

 bool my_flag = false;
rti::recording::Service service(service_property, FlagShutdownHook(my_flag));
service.start();
while(!my_flag){}
service.stop();
 

This seems to be working but I'm a little weary about repeatability:

 bool my_flag = false;
rti::recording::Service service(service_property, FlagShutdownHook(my_flag));
service.start();
while(!my_flag){
   std::this_thread::sleep_for(std::chrono::seconds(1)); // <-- This small sleep is required otherwise the service will flip the flag without saving files
}
service.stop();
 
Any thoughts on this? Thanks for your help so far.
Howard's picture
Offline
Last seen: 5 days 23 hours ago
Joined: 11/29/2012
Posts: 618

Well, I don't think a spinlock loop is the best way to check to see if a flag is set.  Usually, you will want to put some sort of sleep or something in the loop and only poll for the flag value at a periodic rate.

You can also just use a semaphore so that the main thread blocks for a semaphore that's given by the shutdown hook.

Offline
Last seen: 1 month 1 week ago
Joined: 11/11/2024
Posts: 3

Yeah - I switched to using a mutex instead of the bool flag. Works great. Thank you!