2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: Commodities initialization code.
9 #define USE_ZERO_OBJECT 0 /* stegerg: no idea why zero object is/was used at all */
15 #include <utility/utility.h>
16 #include "cxintern.h" /* Must be included after utility.h */
18 #include <aros/debug.h>
20 #include <aros/symbolsets.h>
21 #include <exec/types.h>
22 #include <exec/resident.h>
23 #include <proto/exec.h>
24 #include <devices/timer.h>
26 #include <intuition/classusr.h>
27 #include <exec/libraries.h>
28 #include <exec/alerts.h>
29 #include <libraries/commodities.h>
30 #include <proto/commodities.h>
31 #include LC_LIBDEFS_FILE
33 BOOL
InitCx(struct CommoditiesBase
*CxBase
);
34 BOOL
ShutDownCx(struct CommoditiesBase
*CxBase
);
36 static int Init(struct CommoditiesBase
*CxBase
)
41 This function is single-threaded by exec by calling Forbid.
42 If you break the Forbid() another task may enter this function
43 at the same time. Take care.
46 D(bug("commodities_open: Entering...\n"));
48 CxBase
->cx_TimerMP
.mp_Node
.ln_Type
= NT_MSGPORT
;
49 CxBase
->cx_TimerMP
.mp_Flags
= PA_IGNORE
;
50 NEWLIST(&CxBase
->cx_TimerMP
.mp_MsgList
);
52 CxBase
->cx_TimerIO
.tr_node
.io_Message
.mn_ReplyPort
= &CxBase
->cx_TimerMP
;
53 CxBase
->cx_TimerIO
.tr_node
.io_Message
.mn_Length
= sizeof(struct timerequest
);
55 if (OpenDevice(TIMERNAME
, UNIT_VBLANK
,
56 (struct IORequest
*)&CxBase
->cx_TimerIO
, 0) == 0)
58 CxBase
->cx_TimerBase
=
59 (struct Library
*)(CxBase
->cx_TimerIO
.tr_node
.io_Device
);
61 if (CxBase
->cx_TimerBase
== NULL
)
64 D(bug("commodities_open: Setting up Zero object.\n"));
66 ok
= InitCx((struct CommoditiesBase
*)CxBase
);
70 D(bug("Error: Failed to initialize commodities.library.\n"));
75 D(bug("commodities_open: Library correctly opened.\n"));
81 BOOL
InitCx(struct CommoditiesBase
*CxBase
)
87 InitSemaphore(&CxBase
->cx_SignalSemaphore
);
88 NEWLIST(&CxBase
->cx_BrokerList
);
89 NEWLIST(&CxBase
->cx_MessageList
);
90 NEWLIST(&CxBase
->cx_GeneratedInputEvents
);
92 CxBase
->cx_MsgPort
.mp_Node
.ln_Type
= NT_MSGPORT
;
93 CxBase
->cx_MsgPort
.mp_Flags
= PA_IGNORE
;
94 NEWLIST(&CxBase
->cx_MsgPort
.mp_MsgList
);
97 zero
= CreateCxObj(CX_ZERO
, (IPTR
)NULL
, (IPTR
)NULL
);
104 /* Make sure this object goes LAST in the list */
105 ((struct Node
*)zero
)->ln_Pri
= -128;
107 zero
->co_Flags
|= COF_VALID
;
108 AddHead(&CxBase
->cx_BrokerList
, (struct Node
*)zero
);
115 BOOL
ShutDownCx(struct CommoditiesBase
*CxBase
)
117 struct InputEvent
*temp
;
121 while ((msg
= (CxMsg
*)GetMsg(&CxBase
->cx_MsgPort
)) != NULL
)
123 FreeCxStructure(msg
, CX_MESSAGE
, (struct Library
*)CxBase
);
126 /* Free input events */
127 while (CxBase
->cx_IEvents
!= NULL
)
129 temp
= CxBase
->cx_IEvents
->ie_NextEvent
;
130 FreeCxStructure(CxBase
->cx_IEvents
, CX_INPUTEVENT
,
131 (struct Library
*)CxBase
);
132 CxBase
->cx_IEvents
= temp
;
135 CxBase
->cx_IEvents
= NULL
;
138 /* Remove the ZERO object, in case it exists. */
139 DeleteCxObj((CxObj
*)RemHead(&CxBase
->cx_BrokerList
));
145 ADD2INITLIB(Init
, 0);
146 ADD2EXPUNGELIB(ShutDownCx
, 0);