2 Copyright © 2012, The AROS Development Team. All rights reserved.
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <clib/alib_protos.h>
9 #include <proto/intuition.h>
10 #include <proto/muimaster.h>
11 #include <proto/utility.h>
12 #include <proto/dos.h>
15 #include "muimaster_intern.h"
17 #include "support_classes.h"
18 #include "process_private.h"
23 #define DELAYTICKS (10)
26 extern struct Library
*MUIMasterBase
;
29 static void my_process(void)
31 // invokes MUIM_Process_Process for the the class/object specified by
32 // MUIA_Process_SourceClass/Object (source class may be NULL)
34 D(bug("[Process.mui] my_process called\n"));
36 struct Task
*thistask
= FindTask(NULL
);
37 struct Process_DATA
*data
= thistask
->tc_UserData
;
39 D(bug("[Process.mui::my_process] data %p sourceclass %p sourceobject %p\n",
40 data
, data
->sourceclass
, data
->sourceobject
));
42 if (data
->sourceclass
)
44 CoerceMethod(data
->sourceclass
, data
->sourceobject
,
45 MUIM_Process_Process
, &data
->kill
, data
->self
);
49 DoMethod(data
->sourceobject
, MUIM_Process_Process
, &data
->kill
,
53 data
->task
= NULL
; // show MUIM_Process_Kill that we're done
55 D(bug("[Process.mui] my_process terminated\n"));
59 IPTR
Process__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
61 struct Process_DATA
*data
;
62 struct TagItem
*tag
, *tags
;
63 struct Task
*thistask
;
65 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
69 data
= INST_DATA(cl
, obj
);
74 data
->autolaunch
= TRUE
;
75 data
->stacksize
= 40000;
76 thistask
= FindTask(NULL
);
77 data
->priority
= thistask
->tc_Node
.ln_Pri
;
79 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
83 case MUIA_Process_AutoLaunch
:
84 data
->autolaunch
= tag
->ti_Data
;
87 case MUIA_Process_Name
:
88 data
->name
= (STRPTR
) tag
->ti_Data
;
91 case MUIA_Process_Priority
:
92 data
->priority
= tag
->ti_Data
;
95 case MUIA_Process_SourceClass
:
96 data
->sourceclass
= (struct IClass
*)tag
->ti_Data
;
99 case MUIA_Process_SourceObject
:
100 data
->sourceobject
= (Object
*) tag
->ti_Data
;
103 case MUIA_Process_StackSize
:
104 data
->stacksize
= tag
->ti_Data
;
109 D(bug("muimaster.library/process.c: Process Object created at 0x%lx\n",
112 if (data
->autolaunch
)
114 DoMethod(obj
, MUIM_Process_Launch
);
121 IPTR
Process__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
123 #define STORE *(msg->opg_Storage)
125 struct Process_DATA
*data
= INST_DATA(cl
, obj
);
129 switch (msg
->opg_AttrID
)
131 case MUIA_Process_Task
:
132 STORE
= (IPTR
) data
->task
;
136 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
141 IPTR
Process__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
143 D(bug("[Process.mui/OM_DISPOSE]\n"));
145 // struct Process_DATA *data = INST_DATA(cl, obj);
147 DoMethod(obj
, MUIM_Process_Kill
, 0);
149 return DoSuperMethodA(cl
, obj
, msg
);
153 IPTR
Process__MUIM_Process_Kill(struct IClass
*cl
, Object
*obj
,
154 struct MUIP_Process_Kill
*msg
)
156 D(bug("[MUIM_Process_Kill] maxdelay %d\n", msg
->maxdelay
));
158 struct Process_DATA
*data
= INST_DATA(cl
, obj
);
162 // send SIGBREAKF_CTRL_C
163 // wait until it has terminated
165 // Stops process' loop (MUIM_Process_Process). If the loop
166 // is not running does nothing.
168 // msg->maxdelay == 0 means "wait forever"
170 data
->kill
= 1; // stops the loop in Class4.c demo
172 // the spawned task sets data->task to NULL on exit
173 while (data
->task
!= NULL
)
175 Signal((struct Task
*)data
->task
, SIGBREAKF_CTRL_C
);
178 D(bug("[MUIM_Process_Kill] delay %d maxdelay %d\n", delay
,
180 if ((msg
->maxdelay
!= 0) && (delay
> msg
->maxdelay
))
182 D(bug("[MUIM_Process_Kill] timeout\n"));
188 D(bug("[MUIM_Process_Kill] retval %d\n", retval
));
194 IPTR
Process__MUIM_Process_Launch(struct IClass
*cl
, Object
*obj
,
195 struct MUIP_Process_Launch
*msg
)
197 D(bug("[MUIM_Process_Launch]\n"));
199 struct Process_DATA
*data
= INST_DATA(cl
, obj
);
201 // Starts process's loop (MUIM_Process_Process). If the loop
202 // is already running does nothing.
204 if (data
->task
== NULL
)
206 struct TagItem tags
[] = {
207 {NP_Entry
, (IPTR
) my_process
},
208 {NP_StackSize
, data
->stacksize
},
209 {data
->name
? NP_Name
: TAG_IGNORE
,
211 {NP_Priority
, data
->priority
},
212 {NP_UserData
, (IPTR
) data
},
216 data
->task
= CreateNewProc(tags
);
225 IPTR
Process__MUIM_Process_Process(struct IClass
*cl
, Object
*obj
,
226 struct MUIP_Process_Process
*msg
)
228 D(bug("[MUIM_Process_Process] kill %p proc %p\n", msg
->kill
,
231 // struct Process_DATA *data = INST_DATA(cl, obj);
233 // Main process method. Terminating condition is passed in message struct.
234 // Proper implementation should wait for a signal to not use 100% cpu.
235 // This is some kind of a virtual function. Sub-class implementators
236 // must overwrite it.
238 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
242 IPTR
Process__MUIM_Process_Signal(struct IClass
*cl
, Object
*obj
,
243 struct MUIP_Process_Signal
*msg
)
245 D(bug("[MUIM_Process_Signal] sigs %u\n", msg
->sigs
));
247 struct Process_DATA
*data
= INST_DATA(cl
, obj
);
249 // just send an arbitrary signal to the spawned process.
252 Signal((struct Task
*)data
->task
, msg
->sigs
);
259 #if ZUNE_BUILTIN_PROCESS
260 BOOPSI_DISPATCHER(IPTR
, Process_Dispatcher
, cl
, obj
, msg
)
262 switch (msg
->MethodID
)
265 return Process__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
267 return Process__OM_SET(cl
, obj
, (struct opSet
*)msg
);
269 return Process__OM_DISPOSE(cl
, obj
, msg
);
270 case MUIM_Process_Kill
:
271 return Process__MUIM_Process_Kill(cl
, obj
,
272 (struct MUIP_Process_Kill
*)msg
);
273 case MUIM_Process_Launch
:
274 return Process__MUIM_Process_Launch(cl
, obj
,
275 (struct MUIP_Process_Launch
*)msg
);
276 case MUIM_Process_Process
:
277 return Process__MUIM_Process_Process(cl
, obj
,
278 (struct MUIP_Process_Process
*)msg
);
279 case MUIM_Process_Signal
:
280 return Process__MUIM_Process_Signal(cl
, obj
,
281 (struct MUIP_Process_Signal
*)msg
);
283 return DoSuperMethodA(cl
, obj
, msg
);
286 BOOPSI_DISPATCHER_END
288 const struct __MUIBuiltinClass _MUI_Process_desc
=
292 sizeof(struct Process_DATA
),
293 (void *) Process_Dispatcher
295 #endif /* ZUNE_BUILTIN_PROCESS */