Dynamic Probe Class Library

Dynamic Probe Class Library Programming Guide


Chapter 11. Entering and exiting the DPCL main event loop

In order to interface asynchronously with the DPCL system, the analysis tool must enter the DPCL main event loop. It does this by calling the Ais_main_loop function. This function puts execution in the event loop and generally does not return control to the analysis tool.







Ais_main_loop();

Calling the Ais_main_loop function puts execution in a processing loop that monitors file descriptors that represent socket connections to the DPCL daemons. Monitoring these file descriptors enables the analysis tool to receive, and execute user callbacks for, messages from connected DPCL daemons. The Ais_main_loop function also (as described in Chapter 14, Handling signals and file descriptors through the DPCL system) monitors file descriptors and signals that you register with the DPCL system.
Note:If your analysis tool needs to monitor file descriptors for its own purposes unrelated to DPCL, it can either do this in another program thread, or it can instruct the DPCL system to monitor these additional file descriptors.

If the analysis tool does monitor these additional file descriptors in a separate program thread, be aware that this other thread cannot call DPCL functions or reference DPCL data structures. DPCL is not thread safe; all DPCL function calls must be made from within the same program thread.

For more information on instructing the DPCL system to monitor these additional file descriptors, refer to Chapter 14, Handling signals and file descriptors through the DPCL system.

The call to Ais_main_loop is usually placed at the end of the analysis tool's main function because it generally does not return. If your analysis tool code needs to execute code placed after the call to Ais_main_loop, however, it can break out of the DPCL main event loop by calling the Ais_end_main_loop function from an analysis-tool supplied callback routine or signal handler.







Ais_end_main_loop();

Be aware that, once the analysis tool breaks out of its main event loop, it is, for the most part, no longer capable of responding to events asynchronously. The exception to this is the fact that, after a blocking call is issued and the DPCL system is working on the response to this call, it will process any other asynchronous events that occur. In general, however, non-blocking DPCL calls should not be used after breaking out of the DPCL main event loop, unless the analysis tool code will later reenter the DPCL main event loop by calling the Ais_main_loop function again.

The prototype for the Ais_main_loop and Ais_end_main_loop functions are contained in the header file AisMainLoop.h.

For more information on the Ais_main_loop and Ais_end_main_loop functions, refer to their UNIX man pages or their entries in the DPCL Class Reference.


Example: Entering and exiting the DPCL main event loop

In this example, the analysis tool enters the DPCL main event loop:

Ais_main_loop();

While this function generally does not return, the analysis tool code in this example also contains a signal handler that will break processing out of the DPCL main event loop. (The analysis tool has registered this signal handler by calling the Ais_add_signal function as described in Handling signals through the DPCL system.)

This signal handler (for the SIGINT signal) responds to an interrupt signal initiated by the user pressing <Control>-c.

int sighandler(int s){  

 

     Ais_end_main_loop();        

 

 }

Since the preceding signal handler breaks the analysis tool out of the DPCL main loop, execution of the main routine can now continue past its call to the Ais_main_loop function. The code following the Ais_main_loop function attaches to, and kills, the UNIX process represented by the Process object P. Note in the following code, that blocking calls (Process::battach and Process::bdestroy) are used; the analysis tool cannot, since it has exited the DPCL main event loop, process events asynchronously.

Ais_main_loop();

 

AisStatus sts=P.battach();

if (sts.status()==ASC_success){

  printf("battach() was successful\n");

} else {

  printf("battach() FAILED.. %s\n",sts.status_name());

  exit(0);

}

sts=P.bdestroy();

if (sts.status()==ASC_success){

  printf("bdestroy() was successful\n");

  } else {

  printf("bdestroy() FAILED.. %s\n",sts.status_name());

  exit(0);

}

  


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]