1 /* File Table_modMain_Im.c */
#include "Table_modMain_Im.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
/* Runtime lifecycle API */
10 void Table_modMain_Im__INITIALIZE__received
( Table_modMain_Im__context* context )
{
int i;
for( i = 0; i < 5; i++ ){
context->user.Stick[i] = FREE;
}
}
19 void Table_modMain_Im__START__received
( Table_modMain_Im__context* context )
{
ECOA__log msg;
ECOA__return_status erc;
//
erc = Table_modMain_Im_container__set_service_availability( context, Table_modMain_Im_container__service_id__svc_Chopsticks, ECOA__TRUE );
//
msg.current_size = sprintf( msg.data, "\n\tThe Table is laid, the chopsticks are available...\n" );
Table_modMain_Im_container__log_info( context, msg );
}
31 void Table_modMain_Im__STOP__received
( Table_modMain_Im__context* context )
{
/* User Code Here */
}
37 void Table_modMain_Im__SHUTDOWN__received
( Table_modMain_Im__context* context )
{
/* User Code Here */
}
43 void Table_modMain_Im__REINITIALIZE__received
( Table_modMain_Im__context* context )
{
/* User Code Here */
}
49 void Table_modMain_Im__take__request_received
( Table_modMain_Im__context* context,
const ECOA__uint32 ID,
const ECOA__int32 which,
const ECOA__int32 who )
{
ECOA__boolean8 taken = 0;
//
if( context->user.Stick[which] == FREE ){
taken = !0;
context->user.Stick[which] = who;
// fprintf( stderr, "chopstick %d taken by %d...\n", which, who );
}else{
taken = 0;
// fprintf( stderr, "chopstick %d requested by %d busy...\n", which, who );
}
Table_modMain_Im_container__take__response_send( context, ID, taken );
}
68 void Table_modMain_Im__surrender__request_received
( Table_modMain_Im__context* context,
const ECOA__uint32 ID,
const ECOA__int32 which,
const ECOA__int32 who )
{
if( context->user.Stick[which] != who ){
errno = EPERM; perror( "surrender" );
fprintf( stderr, "%d is trying to surrender chopstick %d held by %d...\n", who, which, context->user.Stick[which] );
exit( 4 );
}else{
context->user.Stick[which] = FREE;
}
// Stupid, non-function that must be called...
Table_modMain_Im_container__surrender__response_send( context, ID ); // There is no response !! But this MUST be called....
// fprintf( stderr, "chopstick %d surrendered by %d...\n", which, who );
}