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.
mesg_pre_setup ()
Should be called before the fork.
It registers the subsystem and gets ready for comunication.
mesg_messanger_setup ()
Should be called after the fork on the parent side.
Finishes setting up comunications.
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.
mesg_quit ()
Should be called by all subsystems before quitting.
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.
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.
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.
mesg_callback_register ()
Registers the function func to be called when messages of
type type are received.
mesg_who_am_i ()
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.
mesg_subsystem_name ()
The string returned should not be modified of freed.
mesg_block ()
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.
mesg_unblock ()
gint mesg_unblock (void); |
Restarts normal messaging behaviour after calling mesg_block.