home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
languages
/
c
/
oslib
/
Examples
/
p2-632
< prev
next >
Wrap
Text File
|
1994-09-26
|
3KB
|
103 lines
#include <string.h>
#include "econet.h"
#include "os.h"
#include "osbyte.h"
#include "osmodule.h"
#include "osword.h"
#define RPC_SEND_TIME 42 /*some number, unique for this net*/
typedef struct clock_list clock_list;
struct clock_list {clock_list *next; econet_tx_cb tx; os_date_and_time clock;};
extern byte Command_Port;
extern clock_list *Tx_List;
extern int Reply_Count, Reply_Delay;
extern byte Buffer [80];
extern void Event_Veneer (void);
extern bool Claimed_Flag;
os_error *start (void)
{ os_error *error = NULL;
if ((error = xos_claim (EventV, (void *) &Event_Veneer, NULL)) != NULL)
goto finish;
Claimed_Flag = TRUE;
if ((error = xos_byte (osbyte_ENABLE_EVENT, Event_EconetUserRPC, SKIP,
NULL, NULL)) != NULL)
goto finish;
if ((error = xos_byte (osbyte_ENABLE_EVENT, Event_EconetTx, SKIP,
NULL, NULL)) != NULL)
goto finish;
finish:
/*If error != NULL, should disable enabled events and release EventV (if
claimed) here.*/
return error;
}
os_error *event (int *event, byte *args, int rpc, byte station, byte net)
/*or (int *event, econet_tx_cb tx, int status)*/
/*The mechanism by which Event_Veneer() calls event() is not
detailed here. Assume that if event is set to -1 on exit, the call is
claimed.*/
{ os_error *error = NULL;
clock_list *clock_ptr;
oswordreadclock_utc_block utc;
switch (*event)
{ case Event_EconetUserRPC:
if (rpc == RPC_SEND_TIME && args [0] == 1)
{ if ((error = xosmodule_alloc (sizeof *clock_ptr,
(void **) &clock_ptr)) != NULL)
goto finish;
utc.op = oswordreadclock_OP_UTC;
if ((error = xoswordreadclock_utc (&utc)) != NULL)
goto finish;
memcpy (clock_ptr->clock, utc.utc, sizeof (os_date_and_time));
if ((error = xeconet_start_transmit (0, args [1], station,
net, (byte *) &clock_ptr->clock, sizeof clock_ptr->clock,
Reply_Count, Reply_Delay, &clock_ptr->tx, NULL)) !=
NULL)
goto finish;
/*Add the list to new record.*/
clock_ptr->next = Tx_List;
Tx_List = clock_ptr;
/*claim vector*/
*event = -1;
}
break;
case Event_EconetTx:
{ econet_tx_cb tx = (econet_tx_cb) args;
clock_list **t;
for (t = &Tx_List; *t != NULL; t = &(*t)->next)
if ((*t)->tx == tx)
{ /*Remove from the list*/
*t = (*t)->next;
(void) xeconet_abandon_transmit (tx, NULL);
(void) xosmodule_free ((byte *) *t);
}
/*claim vector*/
*event = -1;
}
break;
}
finish:
return error;
}