2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
9 #include <aros/debug.h>
11 #include <exec/types.h>
12 #include <exec/memory.h>
13 #include <intuition/classes.h>
14 #include <libraries/mui.h>
16 #include <proto/exec.h>
17 #include <proto/dos.h>
18 #include <proto/intuition.h>
19 #include <proto/icon.h>
21 #include "desktop_intern.h"
25 #include "desktop_intern_protos.h"
26 #include "worker_protos.h"
27 #include "iconcontainerobserver.h"
36 void startedMessage(void)
40 m
= (struct Message
*) AllocVec(sizeof(struct Message
), MEMF_ANY
);
41 m
->mn_Node
.ln_Type
= NT_MESSAGE
;
42 m
->mn_ReplyPort
= DesktopBase
->db_HandlerPort
;
43 m
->mn_Length
= sizeof(struct Message
);
45 PutMsg((struct MsgPort
*) ((struct Process
*) FindTask(NULL
))->pr_Task
.
49 ULONG
desktopHandler(void)
51 struct DesktopInternMsg
*msg
,
53 ULONG handlerState
= HS_STARTING
;
59 struct MinList workingMessages
;
61 NEWLIST((struct List
*) &workingMessages
);
63 // The library's OPEN vector gets a mutex on the library
64 // base. Trouble will come our way if someone started this
66 DesktopBase
->db_HandlerPort
= CreateMsgPort();
68 kprintf("--- starting desktop handler\n");
70 // let the creater know that it's now safe to send the handler
74 kprintf("--- desktop handler accepting messages\n");
78 WaitPort(DesktopBase
->db_HandlerPort
);
80 ((struct DesktopInternMsg
*)
81 GetMsg(DesktopBase
->db_HandlerPort
))))
83 if (msg
->di_Message
.mn_Node
.ln_Type
== NT_MESSAGE
)
85 if (handlerState
== HS_STARTING
)
87 switch (msg
->di_Command
)
92 handlerState
= HS_RUNNING
;
98 else if (handlerState
== HS_STOPPING
)
100 switch (msg
->di_Command
)
105 handlerState
= HS_RUNNING
;
111 else if (handlerState
== HS_RUNNING
)
113 switch (msg
->di_Command
)
123 kprintf("--- DIMC_SUBUSER\n");
125 if (userCount
== 0 && appCount
== 0)
127 kprintf("--- time to exit...\n");
128 handlerState
= HS_STOPPING
;
130 kprintf("--- attempting semaphore\n");
132 (&DesktopBase
->db_BaseMutex
))
135 (&DesktopBase
->db_HandlerSafety
))
142 ReleaseSemaphore(&DesktopBase
->
148 case DIMC_SCANDIRECTORY
:
150 struct HandlerScanRequest
*scanMsg
=
151 (struct HandlerScanRequest
*) msg
;
152 struct WorkingMessageNode
*wmn
;
156 (struct WorkingMessageNode
),
159 (struct DesktopInternMsg
*) scanMsg
;
160 wmn
->wm_ID
= ++idCount
;
161 AddTail((struct List
*) &workingMessages
,
162 (struct Node
*) wmn
);
165 startScannerWorker(idCount
,
166 scanMsg
->hsr_DirLock
,
181 struct HandlerTopLevelRequest
*htl
=
182 (struct HandlerTopLevelRequest
*) msg
;
188 struct SingleResult
*sr
;
193 dl
= LockDosList(htl
->htl_Types
| LDF_READ
);
196 (dl
= NextDosEntry(dl
, htl
->htl_Types
))
199 ULONG length
= strlen(dl
->dol_Ext
.dol_AROS
.dol_DevName
) + 1;
201 tn
= (struct TempNode
*) AllocVec
203 sizeof(struct TempNode
), MEMF_ANY
205 tn
->t_Name
= AllocVec
209 strlcpy(tn
->t_Name
, dl
->dol_Ext
.dol_AROS
.dol_DevName
, length
);
210 AddTail(&tnList
, (struct Node
*) tn
);
214 UnLockDosList(htl
->htl_Types
| LDF_READ
);
216 sr
= (struct SingleResult
*)
217 AllocVec(sizeof(struct SingleResult
) * i
,
220 while (tn
->t_Node
.ln_Succ
)
222 ULONG length
= strlen(tn
->t_Name
) + 2;
224 sr
[j
].sr_Name
= tn
->t_Name
;
226 fullPath
= AllocVec(length
+ 2, MEMF_ANY
);
228 strlcpy(fullPath
, tn
->t_Name
, length
);
229 strlcat(fullPath
, ":", length
);
231 sr
[j
].sr_DiskObject
= GetDiskObjectNew
235 tn
= (struct TempNode
*) tn
->t_Node
.ln_Succ
;
241 htl
->htl_Application
,
242 MUIM_Application_PushMethod
,
243 htl
->htl_CallBack
, 3,
255 ReplyMsg((struct Message
*) msg
);
257 else if (msg
->di_Message
.mn_Node
.ln_Type
== NT_REPLYMSG
)
259 struct WorkerMessage
*wm
= (struct WorkerMessage
*) msg
;
261 switch (wm
->w_Action
)
265 struct WorkerMessage
*newMsg
;
266 struct WorkingMessageNode
*wmn
;
267 struct WorkerScanRequest
*wsr
=
268 (struct WorkerScanRequest
*) wm
;
271 findWorkedMessage(&workingMessages
,
272 wsr
->wsr_WMessage
.w_ID
);
274 DoMethod(((struct HandlerScanRequest
*) wmn
->
275 wm_Working
)->hsr_Application
,
276 MUIM_Application_PushMethod
,
277 ((struct HandlerScanRequest
*) wmn
->
278 wm_Working
)->hsr_CallBack
, 3,
279 ICOM_AddIcons
, wsr
->wsr_Results
,
280 wsr
->wsr_ResultsArray
);
281 DoMethod(((struct HandlerScanRequest
*) wmn
->
282 wm_Working
)->hsr_Application
,
283 MUIM_Application_PushMethod
,
284 ((struct HandlerScanRequest
*) wmn
->
285 wm_Working
)->hsr_CallBack
, 2,
286 OM_FreeList_Add
, wsr
->wsr_ExAllBuffer
);
291 createWorkerScanMessage(WM_RESUME
,
298 (struct Message
*) newMsg
);
302 Remove((struct Node
*) wmn
);
303 ReplyMsg((struct Message
*) wmn
->wm_Working
);
316 kprintf("deleting port\n");
317 DeleteMsgPort(DesktopBase
->db_HandlerPort
);
318 DesktopBase
->db_HandlerPort
= NULL
;
320 kprintf("releasing semaphores\n");
321 ReleaseSemaphore(&DesktopBase
->db_HandlerSafety
);
322 ReleaseSemaphore(&DesktopBase
->db_BaseMutex
);
324 kprintf("replying to msg\n");
325 ReplyMsg((struct Message
*) finalMsg
);
327 kprintf("--- shutting down desktop handler\n");