156 lines
3.5 KiB
C
156 lines
3.5 KiB
C
|
|
|||
|
#include <stdlib.h>
|
|||
|
#include <string.h>
|
|||
|
#include <msg.h>
|
|||
|
|
|||
|
/*------------------------------------------------------------------------------------------*/
|
|||
|
/* Fonction principale du programme */
|
|||
|
/*------------------------------------------------------------------------------------------*/
|
|||
|
void main ( void )
|
|||
|
{
|
|||
|
MSGT_Port * My_Port;
|
|||
|
MSGT_Message * Msg;
|
|||
|
int End_Process;
|
|||
|
|
|||
|
|
|||
|
/* Ouverture de la librairie LIBMSG */
|
|||
|
|
|||
|
if (MSG_Library_Open (NULL, NULL, MSGD_OPEN) != MSGS_OK)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/* Ouverture / cr<63>ation du port de messages priv<69> */
|
|||
|
|
|||
|
if (MSG_Port_Open (<PORT_NAME>, &My_Port, <OPEN_MODE>) != MSGS_OK)
|
|||
|
/*
|
|||
|
<PORT_NAME> = nom du port priv<EFBFBD> (sans espace)
|
|||
|
<OPEN_MODE> = MSGD_OPEN ou MSGD_CREATE
|
|||
|
*/
|
|||
|
{
|
|||
|
MSG_Library_Close (MSGD_CLOSE);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/* Boucle principale du programme */
|
|||
|
|
|||
|
End_Process = FALSE;
|
|||
|
|
|||
|
while (End_Proces == FALSE)
|
|||
|
{
|
|||
|
/* Ecoute du port de messages priv<69> */
|
|||
|
|
|||
|
int rc = MSG_Message_Receive (My_Port, <RECEIVE_TYPE>, &Msg, <RECEIVE_MODE>);
|
|||
|
/*
|
|||
|
<RECEIVE_MODE> = MSGD_WAIT ou MSGD_NO_WAIT
|
|||
|
<RECEIVE_TYPE> = MSGD_NO_TYPE ou type pr<EFBFBD>d<EFBFBD>fini ou type utilisateur
|
|||
|
*/
|
|||
|
|
|||
|
switch (rc)
|
|||
|
{
|
|||
|
case MSGS_OK:
|
|||
|
|
|||
|
/* Message re<72>u */
|
|||
|
|
|||
|
Message_Process (Msg);
|
|||
|
|
|||
|
break;
|
|||
|
|
|||
|
case MSGS_NO_MSG:
|
|||
|
|
|||
|
/* Aucun message pr<70>sent (en mode MSGD_NO_WAIT seulement) */
|
|||
|
|
|||
|
...
|
|||
|
|
|||
|
break;
|
|||
|
|
|||
|
case MSGS_BAD_TYPE:
|
|||
|
|
|||
|
/* Aucun message du type demand<6E> (en mode MSGD_NO_WAIT seulement) */
|
|||
|
|
|||
|
...
|
|||
|
|
|||
|
break;
|
|||
|
|
|||
|
case MSGS_SIGNAL:
|
|||
|
|
|||
|
/* Ecoute interrompue par l'interception d'un signal */
|
|||
|
|
|||
|
...
|
|||
|
|
|||
|
break;
|
|||
|
|
|||
|
default:
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
/* Traitement propre au programme */
|
|||
|
|
|||
|
...
|
|||
|
|
|||
|
} /* Fin de la boucle principale */
|
|||
|
|
|||
|
|
|||
|
/* Fermeture du port de messages priv<69> */
|
|||
|
|
|||
|
if (MSG_Port_Close (My_Port, <CLOSE_MODE>) != MSGS_OK) /* <CLOSE_MODE> = MSGD_CLOSE ou MSGD_DESTROY */
|
|||
|
{
|
|||
|
MSG_Library_Close (MSGD_CLOSE);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/* Fermeture de la librairie LIBMSG */
|
|||
|
|
|||
|
MSG_Library_Close (MSGD_CLOSE);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/*------------------------------------------------------------------------------------------*/
|
|||
|
/* Fonction de traitement d'un message re<72>u sur le port priv<69> */
|
|||
|
/*------------------------------------------------------------------------------------------*/
|
|||
|
|
|||
|
void Message_Process ( MSGT_Message * Msg )
|
|||
|
{
|
|||
|
/* Quel est le type du message ? */
|
|||
|
|
|||
|
switch ( (int)(Msg->Type) )
|
|||
|
{
|
|||
|
case <TYPE1>:
|
|||
|
|
|||
|
...
|
|||
|
|
|||
|
case <TYPE2>:
|
|||
|
|
|||
|
/* Traitement selon le message */
|
|||
|
|
|||
|
...
|
|||
|
|
|||
|
/* R<>ponse au message */
|
|||
|
|
|||
|
if (Msg->Size > strlen ("Message bien re<72>u"))
|
|||
|
{
|
|||
|
/* R<>ponse au message re<72>u */
|
|||
|
|
|||
|
strcpy ((char *)(Msg->Data), "Message bien re<72>u");
|
|||
|
|
|||
|
/* Retour <20> l'envoyeur */
|
|||
|
|
|||
|
if (MSG_Message_Reply (Msg) == MSGS_OK) return;
|
|||
|
}
|
|||
|
|
|||
|
break;
|
|||
|
|
|||
|
default:
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
/* Si on n'a pas r<>pondu au message, on le supprime */
|
|||
|
|
|||
|
MSG_Message_Free (Msg);
|
|||
|
}
|