Belarusian
[AROS.git] / rom / intuition / screennotifytask.c
blobfff3621ed533ff435de94d7c266f94a10b494d69
1 /*
2 Copyright 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/exec.h>
7 #include <proto/intuition.h>
8 #include <proto/alib.h>
9 #include <proto/layers.h>
10 #include <exec/memory.h>
11 #include <exec/alerts.h>
12 #include <exec/interrupts.h>
13 #include <exec/ports.h>
14 #include <intuition/intuition.h>
15 #include <intuition/intuitionbase.h>
16 #include "intuition_intern.h"
18 #include "screennotifytask.h"
20 #undef DEBUG
21 #define DEBUG 0
22 #include <aros/debug.h>
24 void DefaultScreennotifyHandler(struct ScreennotifyTaskParams *taskparams);
26 /**************************************************************************************************/
27 /******************************
28 ** CreateScreennotifyHandlerTask() **
29 ******************************/
30 struct Task *CreateScreennotifyHandlerTask(APTR taskparams, struct IntuitionBase *IntuitionBase)
32 struct Task *task;
33 APTR stack;
35 task = AllocMem(sizeof (struct Task), MEMF_PUBLIC|MEMF_CLEAR);
36 if (task)
38 NEWLIST(&task->tc_MemEntry);
39 task->tc_Node.ln_Type = NT_TASK;
40 task->tc_Node.ln_Name = SCREENNOTIFYTASK_NAME;
41 task->tc_Node.ln_Pri = SCREENNOTIFYTASK_PRIORITY;
43 stack = AllocMem(SCREENNOTIFYTASK_STACKSIZE, MEMF_PUBLIC);
44 if(stack != NULL)
46 task->tc_SPLower=stack;
47 task->tc_SPUpper=(UBYTE *)stack + SCREENNOTIFYTASK_STACKSIZE;
50 struct TagItem tags[] =
52 {TASKTAG_ARG1, (IPTR)taskparams },
53 {TAG_DONE }
56 #if AROS_STACK_GROWS_DOWNWARDS
57 task->tc_SPReg = (UBYTE *)task->tc_SPUpper-SP_OFFSET;
58 #else
59 task->tc_SPReg=(UBYTE *)task->tc_SPLower+SP_OFFSET;
60 #endif
62 if(NewAddTask(task, DefaultScreennotifyHandler, NULL, tags) != NULL)
64 /* Everything went OK */
65 return (task);
69 FreeMem(stack, SCREENNOTIFYTASK_STACKSIZE);
71 } /* if(stack != NULL) */
72 FreeMem(task,sizeof(struct Task));
74 } /* if (task) */
75 return (NULL);
81 /**************************************************************************************************/
83 /***************************
84 ** DefaultScreennotifyHandler() **
85 ***************************/
86 void DefaultScreennotifyHandler(struct ScreennotifyTaskParams *taskparams)
88 struct IntuitionBase *IntuitionBase = taskparams->intuitionBase;
89 struct MsgPort *port = NULL;
90 BOOL success = FALSE;
92 if ((port = AllocMem(sizeof(struct MsgPort), MEMF_PUBLIC | MEMF_CLEAR)))
94 port->mp_Node.ln_Type = NT_MSGPORT;
95 port->mp_Flags = PA_SIGNAL;
96 port->mp_SigBit = AllocSignal(-1);
97 port->mp_SigTask = FindTask(0);
98 NEWLIST(&port->mp_MsgList);
100 success = TRUE;
102 } /* if ((mem = AllocMem(sizeof(struct MsgPort), MEMF_PUBLIC | MEMF_CLEAR))) */
104 if (success)
106 taskparams->ScreennotifyHandlerPort = port;
107 taskparams->success = TRUE;
110 Signal(taskparams->Caller, SIGF_INTUITION);
112 if (!success)
114 D(bug("DefaultScreennotifyHandler: initialization failed. waiting for parent task to kill me.\n"));
115 Wait(0);
118 D(bug("DefaultScreennotifyHandler: initialization ok. Now waiting for messages from Intuition.\n"));
120 for(;;)
122 struct ScreenNotifyMessage *msg;
124 WaitPort(port);
125 while((msg = (struct ScreenNotifyMessage *) GetMsg(port)))
127 FreeMem((APTR) msg, sizeof(struct ScreenNotifyMessage));
128 } /* while((msg = (struct ScreenNotifyMessage *)GetMsg(port))) */
130 } /* for(;;) */
133 /**************************************************************************************************/
135 /*******************************
136 ** InitDefaultScreennotifyHandler() **
137 *******************************/
138 BOOL InitDefaultScreennotifyHandler(struct IntuitionBase *IntuitionBase)
140 struct ScreennotifyTaskParams params;
141 struct Task *task;
142 BOOL result = FALSE;
144 params.intuitionBase = IntuitionBase;
145 params.Caller = FindTask(NULL);
146 params.success = FALSE;
148 SetSignal(0, SIGF_INTUITION);
150 if ((task = CreateScreennotifyHandlerTask(&params, IntuitionBase)))
152 Wait(SIGF_INTUITION);
154 if (params.success)
156 result = TRUE;
157 GetPrivIBase(IntuitionBase)->ScreenNotifyReplyPort = params.ScreennotifyHandlerPort;
159 else
161 RemTask(task);
164 } /* if ((task = CreateScreennotifyHandlerTask(&params, IntuitionBase))) */
166 return result;