grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / camd / receiverproc.c
blobbb5fb1db15b84a1f9f7641f768653240513e09a1
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/dos.h>
7 #include <proto/exec.h>
8 #include <dos/dostags.h>
9 #include <dos/dos.h>
10 #include <proto/utility.h>
12 #include "camd_intern.h"
15 struct DriverData *driverdatatemp=NULL;
17 SAVEDS void ReceiverFunc(void){
18 ULONG sig;
19 struct DriverData *driverdata=driverdatatemp;
21 driverdata->ReceiverSig=AllocSignal(-1);
22 if(driverdata->ReceiverSig==-1){
23 driverdata->isReceiverProcessAlive=2;
24 return;
27 driverdata->isReceiverProcessAlive=1;
29 for(;;){
30 sig=Wait(
31 1L<<driverdata->ReceiverSig |
32 SIGBREAKF_CTRL_C
35 if(sig&1L<<driverdata->ReceiverSig){
36 while(driverdata->unpicked>0){
37 Receiver_first(driverdata);
40 if(sig&SIGBREAKF_CTRL_C) break;
43 FreeSignal(driverdata->ReceiverSig);
45 driverdata->isReceiverProcessAlive=0;
50 /* CL_Linkages must be locked first (exclusive). */
52 BOOL CreateReceiverProc(
53 struct DriverData *driverdata,
54 char *inname,
55 LONG portnum,
56 ULONG *ErrorCode,
57 struct CamdBase *CamdBase
59 struct Process *process;
60 char *name;
62 name=AllocVec(mystrlen(inname)+70,MEMF_ANY | MEMF_PUBLIC);
63 if(name==NULL){
64 if(ErrorCode!=NULL){
65 *ErrorCode=CME_NoMem;
67 return FALSE;
70 mysprintf(CamdBase,name,"CAMD ReceiverProc %s %ld",inname,portnum);
73 driverdatatemp=driverdata;
75 driverdata->isReceiverProcessAlive=0;
77 process=CreateNewProcTags(
78 NP_Entry, (IPTR) ReceiverFunc,
79 NP_Name, (IPTR) name,
80 NP_Priority,36,
81 TAG_END
83 if(process==NULL){
84 if(ErrorCode!=NULL){
85 *ErrorCode=CME_NoMem;
87 FreeVec(name);
88 return FALSE;
91 while(driverdata->isReceiverProcessAlive == 0){
92 Delay(1);
95 if(driverdata->isReceiverProcessAlive==2){
96 driverdata->isReceiverProcessAlive=0;
97 if(ErrorCode!=NULL){
98 *ErrorCode=CME_NoSignals;
100 FreeVec(name);
101 return FALSE;
104 driverdata->ReceiverProc=process;
105 driverdata->ReceiverProcName=name;
107 return TRUE;
110 /* CL_Linkages must be locked first. */
112 void EndReceiverProc(
113 struct DriverData *driverdata,
114 struct CamdBase *CamdBase
116 Signal((struct Task *)driverdata->ReceiverProc,SIGBREAKF_CTRL_C);
117 while(driverdata->isReceiverProcessAlive==1) Delay(1);
118 FreeVec(driverdata->ReceiverProcName);