Control C Interrupt Handler

2 posts / 0 new
Last post
Offline
Last seen: 11 years 3 days ago
Joined: 11/20/2012
Posts: 5
Control C Interrupt Handler

I am currently running my application from the command prompt, and have the need to handle a SIGINT event. I have put the logic/handler in place,  but i am having an issue shutting down DDS cleanly. Is there any to shut down DDS without knowing any participant information.

Keywords:
Gerardo Pardo's picture
Offline
Last seen: 1 day 14 hours ago
Joined: 06/02/2010
Posts: 601

Hi,

You are probably well aware that using signals introduces tricky threading issues. More so if you trying to do things that shutdown the application which involves cleaning memory, deleting objects, mutexes, closing sockets, etc. All of which shutting down DDS will do...  For this reason I assume that you have a dedicated thread on a sigwait() so you can at least control which thread context is used to execute the signal handler.

Given this the only safe way I can think of triggering the shutdown from a signal would be to have the signal handler set some global variable and have all your application threads monitor and synchronize on that global variable so when they detect the shutdown request they suspend their activities. Once you are sure none of your application threads is calling into DDS you need to get a hold of all the DDS DomainParticipant objects and call:

participant->delete_contained_entities();
DomainParticipantFactory::get_instance()->delete_participant(participant);

After you have deleted all the participants as above you can call

DomainParticipantFactory::get_instance()->finalize_instance();

Getting to your question you should be able to call DomainParticipantFactory::get_instance() from any place  because this is a global static function.

As to locating the individual participants unfortunately there is no perfect answer. You may be able to use either

(1)  DomainParticipantFactory::get_instance()->lookup_participant();

(2)  DomainParticipantFactory::get_instance()->lookup_participant_by_name();

Neither will find all domain participants in the general case. But if you know you have just one domain participant per domainId and know the domainId then (1) will work. If you know the names of all the domain participants you can use (2)...  However in the general case you will need to keep a list of the DDS DomainParticipant entities you created so you can clean them up...

What you really need is some call on the DomainParticipantFactory that retrieves the list of DomainParticipant entities. In my opinion this is something that is currently missing from the API.There is already an open RFE (Request For Enhancement) fr this but it is not scheduled as far as I know.

Gerardo