2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Basic functions for resource tracking
11 #define ENABLE_RT 0 /* no RT inside this file */
15 #include <exec/lists.h>
16 #include <aros/system.h>
17 #include <exec/tasks.h>
18 #include <exec/ports.h>
19 #include <exec/memory.h>
20 #include <exec/execbase.h>
24 #include <proto/alib.h>
27 #include <proto/exec.h>
28 #include <proto/arossupport.h>
29 #include <proto/intuition.h>
34 struct Screen
* Screen
;
41 struct Window
* Window
;
45 static IPTR
RT_OpenScreen (RTData
* rtd
, ScreenResource
* rt
, va_list args
, BOOL
* success
);
46 static IPTR
RT_CloseScreen (RTData
* rtd
, ScreenResource
* rt
);
47 static IPTR
RT_ShowErrorScreen (RTData
* rtd
, int, ScreenResource
*, IPTR
, int, const char * file
, ULONG line
, va_list);
48 static IPTR
RT_CheckScreen (RTData
* rtd
, int desc
, const char * file
, ULONG line
, ULONG op
, va_list args
);
50 static IPTR
RT_OpenWindow (RTData
* rtd
, WindowResource
* rt
, va_list args
, BOOL
* success
);
51 static IPTR
RT_CloseWindow (RTData
* rtd
, WindowResource
* rt
);
52 static IPTR
RT_ShowErrorWindow (RTData
* rtd
, int, WindowResource
*, IPTR
, int, const char * file
, ULONG line
, va_list);
53 static IPTR
RT_CheckWindow (RTData
* rtd
, int desc
, const char * file
, ULONG line
, ULONG op
, va_list args
);
55 static const RTDesc RT_IntuitionResources
[] =
58 sizeof (ScreenResource
),
59 (RT_AllocFunc
) RT_OpenScreen
,
60 (RT_FreeFunc
) RT_CloseScreen
,
62 (RT_ShowError
) RT_ShowErrorScreen
,
63 (RT_CheckFunc
) RT_CheckScreen
,
66 sizeof (WindowResource
),
67 (RT_AllocFunc
) RT_OpenWindow
,
68 (RT_FreeFunc
) RT_CloseWindow
,
70 (RT_ShowError
) RT_ShowErrorWindow
,
71 (RT_CheckFunc
) RT_CheckWindow
,
75 void RT_InitIntuition (void)
77 RT_Resources
[RTT_SCREEN
] = &RT_IntuitionResources
[0];
78 RT_Resources
[RTT_WINDOW
] = &RT_IntuitionResources
[1];
81 void RT_ExitIntuition (void)
85 /**************************************
87 **************************************/
89 static IPTR
RT_OpenScreen (RTData
* rtd
, ScreenResource
* rt
, va_list args
, BOOL
* success
)
91 struct NewScreen
* ns
;
92 struct TagItem
* tags
= NULL
;
95 op
= va_arg (args
, int);
96 ns
= va_arg (args
, struct NewScreen
*);
100 case RTTO_OpenScreenTags
:
101 #ifdef AROS_SLOWSTACKTAGS
103 Tag t
= va_arg(args
, Tag
);
104 tags
= GetTagsFromStack(t
, args
);
107 tags
= (struct TagItem
*)args
;
111 case RTTO_OpenScreenTagList
:
112 tags
= va_arg (args
, struct TagItem
*);
117 if (!CheckPtr (ns
, NULL_PTR
))
119 kprintf ("OpenScreen(): Illegal NewScreen pointer\n"
120 " NewScreen=%p at %s:%d\n"
122 , rt
->Node
.File
, rt
->Node
.Line
126 else if (!CheckPtr (tags
, NULL_PTR
))
128 kprintf ("OpenScreenTagList(): Illegal TagItem pointer\n"
129 " tagList=%p at %s:%d\n"
131 , rt
->Node
.File
, rt
->Node
.Line
136 rt
->Screen
= OpenScreenTagList (ns
, tags
);
138 #ifdef AROS_SLOWSTACKTAGS
139 if (op
== RTTO_OpenScreenTags
)
140 FreeTagsFromStack(tags
);
146 return (IPTR
)(rt
->Screen
);
147 } /* RT_OpenScreen */
149 /* To safely pass an empty va_list, we need to use
150 * the following wrapper.
152 static inline IPTR
RT_Search_ap(RTData
*rtd
, int type
, RTNode
**prtwin
, ...)
157 va_start(ap
, prtwin
);
159 ret
= RT_Search(rtd
, type
, prtwin
, ap
);
166 static IPTR
RT_CloseScreen (RTData
* rtd
, ScreenResource
* rt
)
168 if (rt
->Screen
->FirstWindow
)
171 WindowResource
* rtwin
;
172 APTR prtwin
= &rtwin
;
174 kprintf ("CloseScreen(): There are still windows open on this screen\n"
175 " Screen=%p opened at %s:%d\n"
177 , rt
->Node
.File
, rt
->Node
.Line
180 while ((win
= rt
->Screen
->FirstWindow
))
182 if (RT_Search_ap (rtd
, RTT_WINDOW
, (RTNode
**)prtwin
) == RT_SEARCH_FOUND
)
184 RT_FreeResource (rtd
, RTT_WINDOW
, (RTNode
*)rtwin
);
188 kprintf (" Window=%p not tracked by the RT system\n"
194 } /* Check for windows */
196 /* Close the screen */
197 CloseScreen (rt
->Screen
);
200 } /* RT_CloseScreen */
202 static IPTR
RT_ShowErrorScreen (RTData
* rtd
, int rtt
, ScreenResource
* rt
,
203 IPTR ret
, int mode
, const char * file
, ULONG line
, va_list args
)
207 const char * modestr
= (mode
== RT_FREE
) ? "Close" : "Check";
210 scr
= va_arg (args
, struct Screen
*);
214 case RT_SEARCH_FOUND
:
215 if (rt
->Node
.Flags
& RTNF_DONT_FREE
)
217 kprintf ("RT%s: Try to free read-only resource: Screen\n"
224 , rt
->Node
.File
, rt
->Node
.Line
230 case RT_SEARCH_NOT_FOUND
:
231 kprintf ("RT%s: Screen not found\n"
245 kprintf ("RTExit: Screen was not closed\n"
248 , rt
->Node
.File
, rt
->Node
.Line
254 } /* RT_ShowErrorScreen */
256 static IPTR
RT_CheckScreen (RTData
* rtd
, int rtt
,
257 const char * file
, ULONG line
,
258 ULONG op
, va_list args
)
263 if (RT_Search (rtd
, rtt
, (RTNode
**)prt
, args
) != RT_SEARCH_FOUND
)
268 case RTTO_ScreenToFront
:
270 struct Screen
* scr
= va_arg (args
, struct Screen
*);
274 kprintf ("ScreenToFont(): Illegal window pointer\n"
275 " Screen=%p at %s:%d\n"
288 case RTTO_ScreenToBack
:
290 struct Screen
* scr
= va_arg (args
, struct Screen
*);
294 kprintf ("ScreenToBack(): Illegal window pointer\n"
295 " Screen=%p at %s:%d\n"
311 } /* RT_CheckScreen */
314 /**************************************
316 **************************************/
318 static IPTR
RT_OpenWindow (RTData
* rtd
, WindowResource
* rt
, va_list args
, BOOL
* success
)
320 struct NewWindow
* nw
;
321 struct TagItem
* tags
= NULL
;
324 op
= va_arg (args
, int);
325 nw
= va_arg (args
, struct NewWindow
*);
329 case RTTO_OpenWindowTags
:
330 #ifdef AROS_SLOWSTACKTAGS
332 Tag t
= va_arg (args
, Tag
);
333 tags
= GetTagsFromStack(t
, args
);
336 tags
= (struct TagItem
*)args
;
340 case RTTO_OpenWindowTagList
:
341 tags
= va_arg (args
, struct TagItem
*);
346 if (!CheckPtr (nw
, NULL_PTR
))
348 kprintf ("OpenWindow(): Illegal NewWindow pointer\n"
349 " NewWindow=%p at %s:%d\n"
351 , rt
->Node
.File
, rt
->Node
.Line
355 else if (!CheckPtr (tags
, NULL_PTR
))
357 kprintf ("OpenWindowTagList(): Illegal TagList pointer\n"
358 " tagList=%p at %s:%d\n"
360 , rt
->Node
.File
, rt
->Node
.Line
365 rt
->Window
= OpenWindowTagList (nw
, tags
);
367 if (rt
->Window
->UserPort
)
368 RT_IntTrack (RTT_PORT
, __FILE__
, __LINE__
, rt
->Window
->UserPort
);
373 #ifdef AROS_SLOWSTACKTAGS
374 if (op
== RTTO_OpenWindowTags
)
375 FreeTagsFromStack(tags
);
378 return (IPTR
)(rt
->Window
);
379 } /* RT_OpenWindow */
381 static IPTR
RT_CloseWindow (RTData
* rtd
, WindowResource
* rt
)
383 CloseWindow (rt
->Window
);
386 } /* RT_CloseWindow */
388 static IPTR
RT_ShowErrorWindow (RTData
* rtd
, int rtt
, WindowResource
* rt
,
389 IPTR ret
, int mode
, const char * file
, ULONG line
, va_list args
)
393 const char * modestr
= (mode
== RT_FREE
) ? "Close" : "Check";
396 win
= va_arg (args
, struct Window
*);
400 case RT_SEARCH_FOUND
:
401 if (rt
->Node
.Flags
& RTNF_DONT_FREE
)
403 kprintf ("RT%s: Try to free read-only resource: Window\n"
410 , rt
->Node
.File
, rt
->Node
.Line
416 case RT_SEARCH_NOT_FOUND
:
417 kprintf ("RT%s: Window not found\n"
431 kprintf ("RTExit: Window was not closed\n"
434 , rt
->Node
.File
, rt
->Node
.Line
440 } /* RT_ShowErrorWindow */
442 static IPTR
RT_CheckWindow (RTData
* rtd
, int rtt
,
443 const char * file
, ULONG line
,
444 ULONG op
, va_list args
)
449 if (RT_Search (rtd
, rtt
, (RTNode
**)prt
, args
) != RT_SEARCH_FOUND
)
454 case RTTO_WindowToFront
:
456 struct Window
* win
= va_arg (args
, struct Window
*);
460 kprintf ("WindowToFont(): Illegal window pointer\n"
461 " Window=%p at %s:%d\n"
474 case RTTO_WindowToBack
:
476 struct Window
* win
= va_arg (args
, struct Window
*);
480 kprintf ("WindowToBack(): Illegal window pointer\n"
481 " Window=%p at %s:%d\n"
497 } /* RT_CheckWindow */