Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / commodities / brokercommand.c
blob089a4321b327dea8045e2792d84f3bb2673e0de8
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*****************************************************************************
11 NAME */
13 #ifndef DEBUG
14 #define DEBUG 0
15 #endif
17 #include "cxintern.h"
19 #include <aros/debug.h>
21 #include <dos/dos.h>
22 #include <proto/exec.h>
23 #include <libraries/commodities.h>
25 AROS_LH2(ULONG, BrokerCommand,
27 /* SYNOPSIS */
29 AROS_LHA(STRPTR, name , A0),
30 AROS_LHA(ULONG , command, D0),
32 /* LOCATION */
34 struct Library *, CxBase, 33, Commodities)
36 /* FUNCTION
38 Notify a task connected to a certain broker of a state change.
40 INPUTS
42 name -- The name of the broker
43 command -- What to tell the task
45 RESULT
47 0 if everything was OK, a negative value otherwise:
48 -1 -- Unknown broker 'name'
49 -2 -- No broker message port
50 -3 -- No memory for operation
52 NOTES
54 This function is present in AmigaOS too but undocumented.
56 EXAMPLE
58 BUGS
60 SEE ALSO
62 INTERNALS
64 HISTORY
66 ******************************************************************************/
69 AROS_LIBFUNC_INIT
71 static char Exg[] = "Exchange";
73 ULONG error;
74 CxObj *co;
76 if (name == NULL)
78 name = Exg;
81 D(bug("Notifying %s\n", name));
83 ObtainSemaphore(&GPB(CxBase)->cx_SignalSemaphore);
85 co = (CxObj *)FindName(&GPB(CxBase)->cx_BrokerList, name);
86 error = CheckStatus(co, command, CxBase);
88 ReleaseSemaphore(&GPB(CxBase)->cx_SignalSemaphore);
90 D(bug("Notification done!\n"));
92 return error;
94 AROS_LIBFUNC_EXIT
95 } /* BrokerCommand */
98 ULONG CheckStatus(CxObj *broker, ULONG command, struct Library *CxBase)
100 CxMsg *msg;
102 if (broker == NULL)
104 return -1;
107 if (broker->co_Ext.co_BExt->bext_MsgPort == NULL)
109 if (command == CXCMD_KILL && broker->co_Ext.co_BExt->bext_Task != NULL)
111 /* Tell the task to shut itself down */
112 Signal(broker->co_Ext.co_BExt->bext_Task, SIGBREAKF_CTRL_E);
114 return 0;
117 return -2;
120 msg = (CxMsg *)AllocCxStructure(CX_MESSAGE, CXM_SINGLE, CxBase);
122 if (msg == NULL)
124 return -3;
127 msg->cxm_ID = command;
128 PutMsg(broker->co_Ext.co_BExt->bext_MsgPort, (struct Message *)msg);
130 return 0;