sic_comm.c File Reference

This file defines the communication API involved in Gildas software. More...

Include dependency graph for sic_comm.c:

Go to the source code of this file.

Classes

struct  sic_sem_t
struct  sic_listener_handler_t
struct  sic_comm_board_t
struct  sic_widget_board_t

Defines

#define SIC_DEBUG_COMM
#define SIC_USE_SEM_OPEN
#define SIGCLD   SIGCHLD
#define SIC_ASSERT(message, condition)   { if (!(condition)) fprintf( stderr, "SIC_ASSERT: %s\n", message); }
#define MAX_ARGC   32
#define MAX_ARGV   256
#define SIC_MAX_WIDGET_ON_BOARD   1000
#define SIC_MAX_SHM_NAME   32
#define SIC_MAX_SEM_NAME_FOR_PORTABILITY   14
#define SIC_MAX_HANDLERS   32
#define SIC_MODIFIED_VARIABLE_EVENT   1
#define SIC_REDRAW_PROMPT_EVENT   2
#define SIC_SEM_ID(x)   ((x)->sem_id)

Functions

void sic_create_comm_board ()
 Initialize a communication board for all sic IPC features.
void sic_destroy_comm_board ()
 Destroy the communication board from main process.
char ** sic_get_static_argv ()
 Get a static buffer for building argv.
int sic_execvp (char *argv[])
 Call execvp.
task_t sic_launch (int(*start_entry)(void *), void *data)
 Launch a procedure in a separate task.
int sic_terminate (task_t task)
 Terminate a task created with sic_launch.
void sic_on_exit ()
 Informs SIC that program will exit.
void sic_do_exit (int status)
 Exit in a clean way.
int sic_get_comm_id ()
 Returns the communication board id.
int sic_open_comm_board (int comm_board_id)
 Open the communication board.
void sic_close_comm_board ()
 Close the communication board from a child process.
task_id_t sic_get_task_id (task_t task)
 Get the unique identifier of a task.
task_t sic_get_master_task ()
 Get the master task.
task_id_t sic_get_master_task_id ()
 Get the master task id.
task_t sic_get_current_task ()
 Get the current task.
task_id_t sic_get_current_task_id ()
 Get the current task id.
void sic_set_ctrlc_handled (int handled)
 Set Ctrl+C handled flag.
void sic_send_ctrlc ()
 Stop the master task (sending a SIGINT).
void sic_post_prompt (const command_line_t *command_line)
 Enable prompt drawing (called by main process).
int sic_wait_prompt (command_line_t *command_line, int timeout)
 Wait to draw the prompt (called by keyboard process).
void sic_get_current_prompt (char prompt[])
 Get the current prompt in the communication board.
int sic_push_command_text (const char *text)
 Push a command to the communication board.
int sic_post_command_from (const command_line_t *command_line, sic_command_from_t from)
 Send a command to the communication board.
int sic_post_command (const command_line_t *command_line)
 Send a command to the communication board.
void sic_post_command_from_prompt (const command_line_t *command_line)
 Post a command after a call to sic_wait_prompt.
int sic_post_command_text_from (const char *text, sic_command_from_t from)
 Send a command to the communication board.
int sic_post_command_text (const char *text)
 Send a command to the communication board.
int sic_post_command_va (const char *args, va_list l)
 Send a command to the communication board with variable argument list.
int sic_post_command_args (const char *args,...)
 Send a command to the communication board with specified format.
void sic_wait_command (command_line_t *command_line, sic_command_from_t *from)
 Wait for a command in the communication board.
void sic_create_widget_board ()
 Create the widget definition board if necessary and start a widget definition task.
void sic_set_widget_global_infos (const char window_title[], const char help_filename[], const char returned_command[])
 Set global widget infos.
void sic_set_widget_returned_command (const char returned_command[])
 Set widget returned command.
void sic_get_widget_returned_command (char returned_command[])
 Get widget returned command.
void sic_set_widget_returned_code (int code)
 Set widget returned code.
int sic_get_widget_returned_code ()
 Get widget returned code.
void sic_add_modified_variable_listener (sic_modified_variable_listener_t l)
 Add a listener for the modified_variable event.
void sic_fire_modified_variable_event (const sic_widget_def_t *widget)
 Trigger a modified_variable event.
void sic_add_redraw_prompt_listener (sic_redraw_prompt_listener_t l)
 Add a listener for the redraw_prompt event.
void sic_fire_redraw_prompt_event (const command_line_t *command_line)
 Trigger a redraw_prompt event.
void sic_suspend_prompt ()
 Suspend the prompt to ensure output goes to a new line of the terminal.
int sic_add_widget_def (sic_widget_def_t *def)
 Add a widget definition.
void sic_set_widget_def (int index, const sic_widget_def_t *widget)
 Set a widget definition.
void sic_destroy_widget_board ()
 Destroy the widget definition board.
int sic_open_widget_board ()
 Open the widget definition board.
void sic_get_widget_global_infos (char window_title[], char help_filename[], char returned_command[])
 Get global widget infos.
void sic_get_widget_def (int index, sic_widget_def_t *widget)
 Get a widget definition.
void sic_close_widget_board ()
 Close the widget definition board from a child process.
void sic_post_widget_created ()
 Post a widget creation event.
void sic_wait_widget_created ()
 Wait for widget creation.


Detailed Description

This file defines the communication API involved in Gildas software.

All inter process communication features are encapsulated inside this API. The main part consists of a communication board which is created by the main process and opened by child processes. This board is defined by a unique integer which is passed to each process. Synchronization between parallel tasks is provided throw post and wait operations. A wait operation is a blocking call until a post operation is performed. A post operation always returns immediatly. As regards asynchronous events, they are handled by listeners and triggers. A event listener must be registered with the specific handler to call when an event is triggered.

Definition in file sic_comm.c.


Define Documentation

#define MAX_ARGC   32

Definition at line 71 of file sic_comm.c.

#define MAX_ARGV   256

Definition at line 72 of file sic_comm.c.

#define SIC_ASSERT ( message,
condition   )     { if (!(condition)) fprintf( stderr, "SIC_ASSERT: %s\n", message); }

Definition at line 65 of file sic_comm.c.

#define SIC_DEBUG_COMM

Definition at line 55 of file sic_comm.c.

#define SIC_MAX_HANDLERS   32

Definition at line 77 of file sic_comm.c.

#define SIC_MAX_SEM_NAME_FOR_PORTABILITY   14

Definition at line 76 of file sic_comm.c.

#define SIC_MAX_SHM_NAME   32

Definition at line 75 of file sic_comm.c.

#define SIC_MAX_WIDGET_ON_BOARD   1000

Definition at line 74 of file sic_comm.c.

#define SIC_MODIFIED_VARIABLE_EVENT   1

Definition at line 80 of file sic_comm.c.

#define SIC_REDRAW_PROMPT_EVENT   2

Definition at line 81 of file sic_comm.c.

#define SIC_SEM_ID (  )     ((x)->sem_id)

Definition at line 92 of file sic_comm.c.

#define SIC_USE_SEM_OPEN

Definition at line 57 of file sic_comm.c.

#define SIGCLD   SIGCHLD

Definition at line 61 of file sic_comm.c.


Function Documentation

void sic_add_modified_variable_listener ( sic_modified_variable_listener_t  l  ) 

Add a listener for the modified_variable event.

Parameters:
[in] l is the handler of the listener.

Definition at line 1474 of file sic_comm.c.

References sic_listener_handler_t::listener, sic_get_current_task(), SIC_MODIFIED_VARIABLE_EVENT, and sic_listener_handler_t::task.

Here is the call graph for this function:

void sic_add_redraw_prompt_listener ( sic_redraw_prompt_listener_t  l  ) 

Add a listener for the redraw_prompt event.

Parameters:
[in] l is the handler of the listener.

Definition at line 1511 of file sic_comm.c.

References sic_listener_handler_t::listener, sic_get_current_task(), SIC_REDRAW_PROMPT_EVENT, and sic_listener_handler_t::task.

Here is the call graph for this function:

int sic_add_widget_def ( sic_widget_def_t def  ) 

Add a widget definition.

Parameters:
[in] def is the widget definition.
Returns:
0 on success, -1 if no space available for new widget.

Definition at line 1555 of file sic_comm.c.

References SIC_MAX_WIDGET_ON_BOARD, sic_widget_board_t::widget_count, and sic_widget_board_t::widgets.

void sic_close_comm_board (  ) 

Close the communication board from a child process.

Definition at line 1095 of file sic_comm.c.

References sic_comm_board_t::comm_board_access, sic_comm_board_t::draw_prompt, sic_comm_board_t::listener_acquit, sic_comm_board_t::read_command, sic_destroy_widget_board(), sic_get_current_task(), sic_comm_board_t::widget_board_access, sic_comm_board_t::widget_created, and sic_comm_board_t::write_command.

Here is the call graph for this function:

void sic_close_widget_board (  ) 

Close the widget definition board from a child process.

Definition at line 1654 of file sic_comm.c.

References sic_comm_board_t::widget_board_access.

void sic_create_comm_board (  ) 

Initialize a communication board for all sic IPC features.

It must be called once by the main process.

Definition at line 757 of file sic_comm.c.

References command_line_t::code, sic_comm_board_t::comm_board_access, sic_comm_board_t::command_line, sic_comm_board_t::draw_prompt, sic_comm_board_t::event_id, sic_comm_board_t::from, sic_comm_board_t::from_prompt, sic_comm_board_t::keyboard_task, command_line_t::line, sic_comm_board_t::listener_acquit, sic_comm_board_t::listener_count, sic_comm_board_t::master_task, command_line_t::nc, command_line_t::prompt, sic_comm_board_t::pushed_command_text, sic_comm_board_t::read_command, sic_get_current_task(), sic_get_current_task_id(), sic_open_comm_board(), SIC_TASK_NULL, sic_comm_board_t::trace_fd, sic_comm_board_t::widget_board_access, sic_comm_board_t::widget_board_id, sic_comm_board_t::widget_created, and sic_comm_board_t::write_command.

Here is the call graph for this function:

void sic_create_widget_board (  ) 

Create the widget definition board if necessary and start a widget definition task.

Definition at line 1394 of file sic_comm.c.

References sic_get_current_task_id(), sic_open_widget_board(), sic_comm_board_t::widget_board_id, and sic_widget_board_t::widget_count.

Here is the call graph for this function:

void sic_destroy_comm_board (  ) 

Destroy the communication board from main process.

Definition at line 795 of file sic_comm.c.

References sic_comm_board_t::comm_board_access, sic_comm_board_t::draw_prompt, sic_comm_board_t::listener_acquit, sic_comm_board_t::read_command, SIC_ASSERT, sic_close_comm_board(), sic_comm_board_t::widget_board_access, sic_comm_board_t::widget_created, and sic_comm_board_t::write_command.

Here is the call graph for this function:

void sic_destroy_widget_board (  ) 

Destroy the widget definition board.

Definition at line 1579 of file sic_comm.c.

References sic_comm_board_t::widget_board_id.

void sic_do_exit ( int  status  ) 

Exit in a clean way.

Parameters:
[in] status is the value returned to the calling process.

Definition at line 1024 of file sic_comm.c.

References sic_on_exit().

Here is the call graph for this function:

int sic_execvp ( char *  argv[]  ) 

Call execvp.

If SIC_DEBUG_COMM flag is set and environnement variable SIC_DEBUG_GDB is set, exec gdb with supplied arguments inside a xterm.

Parameters:
[in] argv is an array of argument strings.
Returns:
0 on success, -1 otherwise.

Definition at line 873 of file sic_comm.c.

References MAX_ARGC, MAX_ARGV, and sic_do_exit().

Here is the call graph for this function:

void sic_fire_modified_variable_event ( const sic_widget_def_t widget  ) 

Trigger a modified_variable event.

Parameters:
[in] widget contains informations on the modified widget.

Definition at line 1496 of file sic_comm.c.

References sic_widget_board_t::modified_widget, sic_close_widget_board(), SIC_MODIFIED_VARIABLE_EVENT, and sic_open_widget_board().

Here is the call graph for this function:

void sic_fire_redraw_prompt_event ( const command_line_t command_line  ) 

Trigger a redraw_prompt event.

Parameters:
[in] command_line the prompt to draw.

Definition at line 1533 of file sic_comm.c.

References sic_comm_board_t::command_line, and SIC_REDRAW_PROMPT_EVENT.

int sic_get_comm_id (  ) 

Returns the communication board id.

Definition at line 1034 of file sic_comm.c.

void sic_get_current_prompt ( char  prompt[]  ) 

Get the current prompt in the communication board.

Parameters:
[out] prompt is returned.

Definition at line 1245 of file sic_comm.c.

References sic_comm_board_t::command_line, PROMPT, and command_line_t::prompt.

task_t sic_get_current_task (  ) 

Get the current task.

Returns:
the task.

Definition at line 1164 of file sic_comm.c.

task_id_t sic_get_current_task_id (  ) 

Get the current task id.

Returns:
the id.

Definition at line 1178 of file sic_comm.c.

References sic_get_current_task(), and sic_get_task_id().

Here is the call graph for this function:

task_t sic_get_master_task (  ) 

Get the master task.

Returns:
the task.

Definition at line 1139 of file sic_comm.c.

References sic_comm_board_t::master_task.

task_id_t sic_get_master_task_id (  ) 

Get the master task id.

Returns:
the id.

Definition at line 1154 of file sic_comm.c.

References sic_get_master_task(), and sic_get_task_id().

Here is the call graph for this function:

char** sic_get_static_argv (  ) 

Get a static buffer for building argv.

Definition at line 853 of file sic_comm.c.

References MAX_ARGC, and MAX_ARGV.

task_id_t sic_get_task_id ( task_t  task  ) 

Get the unique identifier of a task.

Parameters:
[in] task is a task returned by a call to sic_launch.
Returns:
the identifier of task.

Definition at line 1125 of file sic_comm.c.

void sic_get_widget_def ( int  index,
sic_widget_def_t widget 
)

Get a widget definition.

Parameters:
[in] index of the widget.
[out] widget to be filled with the definition.

Definition at line 1646 of file sic_comm.c.

References sic_widget_board_t::widgets.

void sic_get_widget_global_infos ( char  window_title[],
char  help_filename[],
char  returned_command[] 
)

Get global widget infos.

Parameters:
[out] window_title must be of size TITLELENGTH
[out] help_filename must be of size HLPFILELNGTH
[out] returned_command must be of size COMMANDLENGTH

Definition at line 1628 of file sic_comm.c.

References sic_widget_board_t::help_filename, sic_widget_board_t::returned_command, and sic_widget_board_t::window_title.

int sic_get_widget_returned_code (  ) 

Get widget returned code.

Returns:
the id of the widget ending the dialog.

Definition at line 1464 of file sic_comm.c.

References sic_widget_board_t::returned_code.

void sic_get_widget_returned_command ( char  returned_command[]  ) 

Get widget returned command.

Parameters:
[out] returned_command. 

Definition at line 1439 of file sic_comm.c.

References sic_widget_board_t::returned_command.

task_t sic_launch ( int(*)(void *)  start_entry,
void *  data 
)

Launch a procedure in a separate task.

Parameters:
[in] start_entry is the procedure to launch.
[in] data is a pointer passed as argument to the procedure.

Definition at line 944 of file sic_comm.c.

References sic_perror().

Here is the call graph for this function:

void sic_on_exit (  ) 

Informs SIC that program will exit.

Definition at line 1002 of file sic_comm.c.

References sic_close_comm_board(), and sic_destroy_comm_board().

Here is the call graph for this function:

int sic_open_comm_board ( int  comm_board_id  ) 

Open the communication board.

It must be called once by each child process.

Parameters:
[in] comm_board_id is the identifier of the communication board.
Returns:
0 on success, -1 otherwise.

Definition at line 1046 of file sic_comm.c.

References sic_comm_board_t::comm_board_access, sic_comm_board_t::draw_prompt, sic_comm_board_t::listener_acquit, sic_comm_board_t::read_command, SIC_ASSERT, SIC_DEBUG_COMM, sic_comm_board_t::trace_fd, sic_comm_board_t::widget_board_access, sic_comm_board_t::widget_created, and sic_comm_board_t::write_command.

int sic_open_widget_board (  ) 

Open the widget definition board.

It must be called once by each child process.

Returns:
the count of widgets.

Definition at line 1599 of file sic_comm.c.

References sic_comm_board_t::widget_board_access, sic_comm_board_t::widget_board_id, and sic_widget_board_t::widget_count.

int sic_post_command ( const command_line_t command_line  ) 

Send a command to the communication board.

Parameters:
[in] command_line is the command.
Returns:
0 on success, -1 if timeout has been reached.

Definition at line 1291 of file sic_comm.c.

References SIC_DEFAULT, and sic_post_command_from().

Here is the call graph for this function:

int sic_post_command_args ( const char *  args,
  ... 
)

Send a command to the communication board with specified format.

Parameters:
[in] args is a format like printf first argument.
Returns:
0 on success, -1 if timeout has been reached.

Definition at line 1353 of file sic_comm.c.

References sic_post_command_va().

Here is the call graph for this function:

int sic_post_command_from ( const command_line_t command_line,
sic_command_from_t  from 
)

Send a command to the communication board.

Parameters:
[in] command_line is the command.
[in] from is the type of the caller.
Returns:
0 on success, -1 if timeout has been reached.

Definition at line 1280 of file sic_comm.c.

Referenced by sic_post_command(), and sic_post_command_text_from().

Here is the caller graph for this function:

void sic_post_command_from_prompt ( const command_line_t command_line  ) 

Post a command after a call to sic_wait_prompt.

Parameters:
[in] command_line is the command.

Definition at line 1301 of file sic_comm.c.

References SIC_KEYBOARD.

int sic_post_command_text ( const char *  text  ) 

Send a command to the communication board.

Parameters:
[in] text is the command.
Returns:
0 on success, -1 if timeout has been reached.

Definition at line 1328 of file sic_comm.c.

References command_line_t::code, command_line_t::line, MAXBUF, command_line_t::nc, command_line_t::prompt, SIC_DEFAULT, sic_post_command(), and sic_post_command_text_from().

Here is the call graph for this function:

int sic_post_command_text_from ( const char *  text,
sic_command_from_t  from 
)

Send a command to the communication board.

Parameters:
[in] text is the command.
[in] from is the type of the caller.
Returns:
0 on success, -1 if timeout has been reached.

Definition at line 1313 of file sic_comm.c.

References sic_post_command_from().

Referenced by sic_post_command_text().

Here is the call graph for this function:

Here is the caller graph for this function:

int sic_post_command_va ( const char *  args,
va_list  l 
)

Send a command to the communication board with variable argument list.

Parameters:
[in] args is a format like printf first argument.
Returns:
0 on success, -1 if timeout has been reached.

Definition at line 1339 of file sic_comm.c.

References MAXBUF, and sic_post_command_text().

Here is the call graph for this function:

void sic_post_prompt ( const command_line_t command_line  ) 

Enable prompt drawing (called by main process).

Definition at line 1208 of file sic_comm.c.

References sic_comm_board_t::command_line, and sic_comm_board_t::draw_prompt.

void sic_post_widget_created (  ) 

Post a widget creation event.

Definition at line 1668 of file sic_comm.c.

References sic_comm_board_t::widget_created.

int sic_push_command_text ( const char *  text  ) 

Push a command to the communication board.

Parameters:
[in] text is the command.
Returns:
0 on success, -1 if a command has already been pushed.

Definition at line 1256 of file sic_comm.c.

References MAXBUF, sic_comm_board_t::pushed_command_text, and sic_comm_board_t::read_command.

void sic_send_ctrlc (  ) 

Stop the master task (sending a SIGINT).

Definition at line 1196 of file sic_comm.c.

References sic_do_exit(), and sic_get_master_task().

Here is the call graph for this function:

void sic_set_ctrlc_handled ( int  handled  ) 

Set Ctrl+C handled flag.

Parameters:
[in] handled 1 if true, 0 otherwise.

Definition at line 1188 of file sic_comm.c.

void sic_set_widget_def ( int  index,
const sic_widget_def_t widget 
)

Set a widget definition.

Parameters:
[in] index of the widget.
[in] widget to defined.

Definition at line 1571 of file sic_comm.c.

References sic_widget_board_t::widgets.

void sic_set_widget_global_infos ( const char  window_title[],
const char  help_filename[],
const char  returned_command[] 
)

Set global widget infos.

Parameters:
[in] window_title. 
[in] help_filename. 
[in] returned_command. 

Definition at line 1412 of file sic_comm.c.

References sic_widget_board_t::help_filename, sic_widget_board_t::returned_command, and sic_widget_board_t::window_title.

void sic_set_widget_returned_code ( int  code  ) 

Set widget returned code.

Parameters:
[in] code is the id of the widget ending the dialog.

Definition at line 1449 of file sic_comm.c.

References sic_widget_board_t::returned_code.

void sic_set_widget_returned_command ( const char  returned_command[]  ) 

Set widget returned command.

Parameters:
[in] returned_command. 

Definition at line 1424 of file sic_comm.c.

References sic_widget_board_t::returned_command.

void sic_suspend_prompt (  ) 

Suspend the prompt to ensure output goes to a new line of the terminal.

Definition at line 1544 of file sic_comm.c.

References sic_comm_board_t::command_line, and command_line_t::line.

int sic_terminate ( task_t  task  ) 

Terminate a task created with sic_launch.

Parameters:
[in] task is a task returned by a call to sic_launch.
Returns:
0 on success, -1 otherwise.

Definition at line 983 of file sic_comm.c.

References sic_pwarning().

Here is the call graph for this function:

void sic_wait_command ( command_line_t command_line,
sic_command_from_t from 
)

Wait for a command in the communication board.

Parameters:
[out] command_line contains the command.
[out] from informs about the sender of the command.

Definition at line 1371 of file sic_comm.c.

References sic_comm_board_t::command_line, sic_comm_board_t::from, command_line_t::line, command_line_t::prompt, sic_comm_board_t::pushed_command_text, sic_comm_board_t::read_command, SIC_DEFAULT, and sic_comm_board_t::write_command.

int sic_wait_prompt ( command_line_t command_line,
int  timeout 
)

Wait to draw the prompt (called by keyboard process).

Parameters:
[out] command_line contains the prompt and optionally a command line.
[in] timeout given in milliseconds.
Returns:
0 on success, -1 if timeout has been reached.

Definition at line 1222 of file sic_comm.c.

References sic_comm_board_t::command_line, and sic_comm_board_t::draw_prompt.

void sic_wait_widget_created (  ) 

Wait for widget creation.

Definition at line 1677 of file sic_comm.c.

References sic_comm_board_t::widget_created.


Generated on Tue Mar 13 15:19:48 2007 for SIC by  doxygen 1.5.1