Messaging

Name

Messaging -- Messaging facility.

Synopsis


struct      message_t;
#define     MESSAGE_MAXSIZE
enum        subsystem_t;
enum        mesg_message_type_t;
enum        misc_message_type_t;
void        (*receive_callback)             (const message_t *m);
gint        mesg_pre_setup                  (subsystem_t subsystem);
gint        mesg_messanger_setup            (subsystem_t subsystem);
gint        mesg_subsystem_setup            (subsystem_t subsystem,
                                             gint flags);
gint        mesg_quit                       (subsystem_t subsystem);
gint        mesg_send                       (subsystem_t dest,
                                             mesg_type_t type,
                                             const gpointer data,
                                             gint size);
gint        mesg_broadcast                  (mesg_type_t type,
                                             const gpointer data,
                                             gint size);
gboolean    mesg_loop                       (void);
gint        mesg_callback_register          (mesg_type_t type,
                                             receive_callback func);
subsystem_t mesg_who_am_i                   (void);
gchar*      mesg_subsystem_name             (subsystem_t subsystem);
gint        mesg_block                      (void);
gint        mesg_unblock                    (void);

Description

This could be seen as another subsystem, and in deed is a different process. It makes comunication between the other subsystem posible in a transparent maner, currently it uses sockets but it could use any means of comunication without modifing any other code.

Details

struct message_t

typedef struct {			/* struct describing a message */
	subsystem_t sender;		/* sender of the message */
	subsystem_t dest;		/* target of the message */
	mesg_type_t type;		/* type of message */
	gint data_size;			/* size of the data */
	gint8 data[MESSAGE_MAXSIZE];	/* data of the message */
} message_t;


MESSAGE_MAXSIZE

#define MESSAGE_MAXSIZE 8	/* maximun size of the data to send in a message */


enum subsystem_t

typedef enum {		/* identification for the subsystems will also be used
			   as the higher byte for message types */
	ALL=-2,		/* broadcast messages */
	NOSUBSYSTEM=-1,	/* used within the messaging code to indicate that
			   there is no subsystem */
	MESG=0,		/* messages to be handled by the messager */
	CPU,		/* CPU subsystem */
	MEM,		/* Memory subsystem */
	IO,		/* I/O subsystem */
	CLOCK,		/* Clock subsystem */
	REQUESTOR,	/* Requestor subsystem */
	N_SUBSYSTEMS,	/* used within the messaging code as the total number
			   of subsystems */
	MISC_MESSAGES	/* messages that don't belong to any subsystem in 
			   particular */
} subsystem_t;


enum mesg_message_type_t

typedef enum {			/* message types to be handled by the
				   messager */
	MESG_QUIT=MESG<<8,	/* each subsystem should send this message
				   to the messenger before quiting */
	MESG_RESET_SYSTEM	/* send by the CPU tells the messager to
				   terminate all subsystems and restart
				   the system */
} mesg_message_type_t;


enum misc_message_type_t

typedef enum {				/* message types not belonging to a
					   particular subsystem */
	MISC_SHOW=MISC_MESSAGES<<8,	/* tells a subsystem to show it's
					   main window */
	MISC_QUIT			/* tells a subsystem to quit */
} misc_message_type_t;


receive_callback ()

void        (*receive_callback)             (const message_t *m);

Function pointer type to be used in mesg_callback_register.

m :message.


mesg_pre_setup ()

gint        mesg_pre_setup                  (subsystem_t subsystem);

Should be called before the fork. It registers the subsystem and gets ready for comunication.

subsystem : the subsystem ID.
Returns : nothing important.


mesg_messanger_setup ()

gint        mesg_messanger_setup            (subsystem_t subsystem);

Should be called after the fork on the parent side. Finishes setting up comunications.

subsystem : the subsystem ID.
Returns : nothing important.


mesg_subsystem_setup ()

gint        mesg_subsystem_setup            (subsystem_t subsystem,
                                             gint flags);

Should be called after the fork on the child side. Finishes setting up comunications.

If flags is MESG_WITH_GTK GTK I/O monitoring facilities will be used.

NOTE: GTK+ I/O monitoring facilities can only be used if the subsystem uses GTK+ and calls gtk_main.

subsystem : the subsystem ID.
flags : could be MESG_WITH_GTK or 0.
Returns : nothing important.


mesg_quit ()

gint        mesg_quit                       (subsystem_t subsystem);

Should be called by all subsystems before quitting.

subsystem : ID of the subsystem.
Returns : nothing important.


mesg_send ()

gint        mesg_send                       (subsystem_t dest,
                                             mesg_type_t type,
                                             const gpointer data,
                                             gint size);

Send a message from one subsystem to another.

dest : target subsystem ID.
type : type for the message.
data : data for the message.
size : size of data.
Returns : nothing important.


mesg_broadcast ()

gint        mesg_broadcast                  (mesg_type_t type,
                                             const gpointer data,
                                             gint size);

Send a message from one subsystem to all the other subsystems.

type : type for the message.
data : data for the message.
size : size of data.
Returns : nothing important.


mesg_loop ()

gboolean    mesg_loop                       (void);

Function to be called last on the messanger process, it will handle messages between the different subsystems and won't return until the system is reset or terminated.

Returns : TRUE if the system should be reset insted of terminated.


mesg_callback_register ()

gint        mesg_callback_register          (mesg_type_t type,
                                             receive_callback func);

Registers the function func to be called when messages of type type are received.

type : message type.
func : function to be called.
Returns : nothing important.


mesg_who_am_i ()

subsystem_t mesg_who_am_i                   (void);

This is usefull so the code which is usable by all subsystems can find out where it is executing.

This is specialy usefull in combination with mesg_subsystem_name.

Returns : the identification number of the current subsystem.


mesg_subsystem_name ()

gchar*      mesg_subsystem_name             (subsystem_t subsystem);

The string returned should not be modified of freed.

subsystem : the identification number of a subsystem.
Returns : a string with the name of the subsystem.


mesg_block ()

gint        mesg_block                      (void);

In case GTK I/O monitoring facilities are not been used, this function can be used to protect critical sections of code from been interrupted by I/O signals.

Returns : nothing important.


mesg_unblock ()

gint        mesg_unblock                    (void);

Restarts normal messaging behaviour after calling mesg_block.

Returns : nothing important.