revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / commodities / cxbroker.c
blob9feab991b185c4210ad545f18fb7e868f96c9cb6
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*****************************************************************************
11 NAME */
13 #define AROS_ALMOST_COMPATIBLE
15 #ifndef DEBUG
16 #define DEBUG 0
17 #endif
19 #include "cxintern.h"
21 #include <aros/debug.h>
23 #include <devices/input.h>
24 #include <proto/commodities.h>
25 #include <proto/exec.h>
26 #include <devices/inputevent.h>
27 #include <libraries/commodities.h>
28 #include <exec/lists.h>
29 #include <aros/asmcall.h>
31 #ifdef __MORPHOS__
32 extern const struct EmulLibEntry cxIHandler_Gate;
33 #else
34 extern struct InputEvent *cxIHandler();
35 #endif
38 AROS_LH2(CxObj *, CxBroker,
40 /* SYNOPSIS */
42 AROS_LHA(struct NewBroker *, nb , A0),
43 AROS_LHA(LONG * , error, D0),
45 /* LOCATION */
47 struct Library *, CxBase, 6, Commodities)
49 /* FUNCTION
51 Create a commodity broker from the specifications found in the structure
52 pointed to by 'nb'. The NewBroker structure is described in <Libraries/
53 Commodities.h>, see this file for more info. After the call, the
54 NewBroker structure isn't needed anymore and may be discarded.
56 INPUTS
58 nb -- pointer to an initialized NewBroker structure
59 error -- pointer to a LONG where the possible error of the CxBroker
60 function is stored (may be NULL)
62 RESULT
64 A pointer to a commodity broker, or NULL upon failure. If 'error' is
65 NULL, no error information is stored. The possible error types are
67 CBERR_OK -- everything went just fine
69 CBERR_SYSERR -- system problems, typically not enough memory
71 CBERR_DUP -- another broker with the same name already exists
72 (and your nb_Unique indicates that only one is
73 allowed)
75 CBERR_VERSION -- the version found in nb_Version is unknown to the
76 library
78 NOTES
80 EXAMPLE
82 BUGS
84 SEE ALSO
86 SetCxObjPri(), <libraries/commodities.h>
88 INTERNALS
90 HISTORY
92 ******************************************************************************/
95 AROS_LIBFUNC_INIT
97 LONG myerr = CBERR_OK;
98 CxObj *co = NULL;
99 CxObj *temp;
101 D(bug("Entering CxBroker\n"));
103 ObtainSemaphore(&GPB(CxBase)->cx_SignalSemaphore);
105 /* No duplicates allowed? */
106 if (nb->nb_Unique & NBU_UNIQUE)
108 temp = (CxObj *)FindName(&GPB(CxBase)->cx_BrokerList, nb->nb_Name);
110 if (temp != NULL)
112 if(nb->nb_Unique & NBU_NOTIFY)
114 CheckStatus(temp, CXCMD_UNIQUE, CxBase);
117 myerr = CBERR_DUP;
121 if (myerr == CBERR_OK)
123 if ((co = CreateCxObj(CX_BROKER, (IPTR)nb, (IPTR)NULL)) != NULL)
125 if (co->co_Ext.co_BExt->bext_MsgPort != NULL)
127 if (!GPB(CxBase)->cx_Running)
129 if (SetupIHandler((struct CommoditiesBase *)CxBase) == FALSE)
131 goto sysErr;
133 else
135 GPB(CxBase)->cx_Running = TRUE;
138 else
140 BrokerCommand(NULL, CXCMD_LIST_CHG);
143 Enqueue(&GPB(CxBase)->cx_BrokerList, (struct Node *)co);
144 co->co_Flags |= COF_VALID;
146 else
148 // Don't set error because Garshneblanker creates a broker
149 // with nb->nb_Port set to NULL
150 // myerr = CBERR_VERSION;
153 else
155 sysErr:
156 myerr = CBERR_SYSERR;
160 ReleaseSemaphore(&GPB(CxBase)->cx_SignalSemaphore);
162 if (error != NULL)
164 *error = myerr;
167 D(bug("CxBroker: returning co=%p\n", co));
169 return co;
171 AROS_LIBFUNC_EXIT
172 } /* CxBroker */
175 BOOL SetupIHandler(struct CommoditiesBase *CxBase)
177 D(bug("CxBroker: Setting up input handler.\n"));
179 CxBase->cx_InputMP.mp_Node.ln_Type = NT_MSGPORT;
180 CxBase->cx_InputMP.mp_Flags = PA_SIGNAL;
181 CxBase->cx_InputMP.mp_SigBit = SIGB_SINGLE;
182 CxBase->cx_InputMP.mp_SigTask = FindTask(NULL);
183 NEWLIST(&CxBase->cx_InputMP.mp_MsgList);
184 CxBase->cx_IORequest.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
185 CxBase->cx_IORequest.io_Message.mn_Length = sizeof(struct IOStdReq);
186 CxBase->cx_IORequest.io_Message.mn_ReplyPort = &CxBase->cx_InputMP;
188 if (OpenDevice("input.device", 0,
189 (struct IORequest *)&CxBase->cx_IORequest, 0) != 0)
191 // kprintf("Input.device didn't open\n");
192 return FALSE;
195 // kprintf("CxBroker: Opened input.device.\n");
197 CxBase->cx_Interrupt.is_Code = (VOID (*)())AROS_ASMSYMNAME(cxIHandler);
198 CxBase->cx_Interrupt.is_Data = CxBase;
199 CxBase->cx_Interrupt.is_Node.ln_Pri = 53;
200 CxBase->cx_Interrupt.is_Node.ln_Name = CxBase->cx_Lib.lib_Node.ln_Name;
201 CxBase->cx_IORequest.io_Command = IND_ADDHANDLER;
202 CxBase->cx_IORequest.io_Data = &CxBase->cx_Interrupt;
204 DoIO((struct IORequest *)&CxBase->cx_IORequest);
206 // kprintf("CxBroker: Handler up and running.\n");
208 return TRUE;