2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
9 /*****************************************************************************
13 #define AROS_ALMOST_COMPATIBLE
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>
32 extern const struct EmulLibEntry cxIHandler_Gate
;
34 extern struct InputEvent
*cxIHandler();
38 AROS_LH2(CxObj
*, CxBroker
,
42 AROS_LHA(struct NewBroker
*, nb
, A0
),
43 AROS_LHA(LONG
* , error
, D0
),
47 struct Library
*, CxBase
, 6, Commodities
)
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.
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)
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
75 CBERR_VERSION -- the version found in nb_Version is unknown to the
86 SetCxObjPri(), <libraries/commodities.h>
92 ******************************************************************************/
97 LONG myerr
= CBERR_OK
;
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
);
112 if(nb
->nb_Unique
& NBU_NOTIFY
)
114 CheckStatus(temp
, CXCMD_UNIQUE
, CxBase
);
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
)
135 GPB(CxBase
)->cx_Running
= TRUE
;
140 BrokerCommand(NULL
, CXCMD_LIST_CHG
);
143 Enqueue(&GPB(CxBase
)->cx_BrokerList
, (struct Node
*)co
);
144 co
->co_Flags
|= COF_VALID
;
148 myerr
= CBERR_VERSION
;
154 myerr
= CBERR_SYSERR
;
158 ReleaseSemaphore(&GPB(CxBase
)->cx_SignalSemaphore
);
165 D(bug("CxBroker: returning co=%p\n", co
));
173 BOOL
SetupIHandler(struct CommoditiesBase
*CxBase
)
175 D(bug("CxBroker: Setting up input handler.\n"));
177 CxBase
->cx_InputMP
.mp_Node
.ln_Type
= NT_MSGPORT
;
178 CxBase
->cx_InputMP
.mp_Flags
= PA_SIGNAL
;
179 CxBase
->cx_InputMP
.mp_SigBit
= SIGB_SINGLE
;
180 CxBase
->cx_InputMP
.mp_SigTask
= FindTask(NULL
);
181 NEWLIST(&CxBase
->cx_InputMP
.mp_MsgList
);
182 CxBase
->cx_IORequest
.io_Message
.mn_Node
.ln_Type
= NT_REPLYMSG
;
183 CxBase
->cx_IORequest
.io_Message
.mn_Length
= sizeof(struct IOStdReq
);
184 CxBase
->cx_IORequest
.io_Message
.mn_ReplyPort
= &CxBase
->cx_InputMP
;
186 if (OpenDevice("input.device", 0,
187 (struct IORequest
*)&CxBase
->cx_IORequest
, 0) != 0)
189 // kprintf("Input.device didn't open\n");
193 // kprintf("CxBroker: Opened input.device.\n");
195 CxBase
->cx_Interrupt
.is_Code
= (VOID (*)())AROS_ASMSYMNAME(cxIHandler
);
196 CxBase
->cx_Interrupt
.is_Data
= CxBase
;
197 CxBase
->cx_Interrupt
.is_Node
.ln_Pri
= 53;
198 CxBase
->cx_Interrupt
.is_Node
.ln_Name
= CxBase
->cx_Lib
.lib_Node
.ln_Name
;
199 CxBase
->cx_IORequest
.io_Command
= IND_ADDHANDLER
;
200 CxBase
->cx_IORequest
.io_Data
= &CxBase
->cx_Interrupt
;
202 DoIO((struct IORequest
*)&CxBase
->cx_IORequest
);
204 // kprintf("CxBroker: Handler up and running.\n");