2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Basic functions for ressource 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 tags
= (struct TagItem
*)args
;
104 case RTTO_OpenScreenTagList
:
105 tags
= va_arg (args
, struct TagItem
*);
110 if (!CheckPtr (ns
, NULL_PTR
))
112 kprintf ("OpenScreen(): Illegal NewScreen pointer\n"
113 " NewScreen=%p at %s:%d\n"
115 , rt
->Node
.File
, rt
->Node
.Line
119 else if (!CheckPtr (tags
, NULL_PTR
))
121 kprintf ("OpenScreenTagList(): Illegal TagItem pointer\n"
122 " tagList=%p at %s:%d\n"
124 , rt
->Node
.File
, rt
->Node
.Line
129 rt
->Screen
= OpenScreenTagList (ns
, tags
);
134 return (IPTR
)(rt
->Screen
);
135 } /* RT_OpenScreen */
137 static IPTR
RT_CloseScreen (RTData
* rtd
, ScreenResource
* rt
)
139 if (rt
->Screen
->FirstWindow
)
142 WindowResource
* rtwin
;
143 APTR prtwin
= &rtwin
;
145 kprintf ("CloseScreen(): There are still windows open on this screen\n"
146 " Screen=%p opened at %s:%d\n"
148 , rt
->Node
.File
, rt
->Node
.Line
151 while ((win
= rt
->Screen
->FirstWindow
))
153 if (RT_Search (rtd
, RTT_WINDOW
, (RTNode
**)prtwin
, NULL
) == RT_SEARCH_FOUND
)
155 RT_FreeResource (rtd
, RTT_WINDOW
, (RTNode
*)rtwin
);
159 kprintf (" Window=%p not tracked by the RT system\n"
165 } /* Check for windows */
167 /* Close the screen */
168 CloseScreen (rt
->Screen
);
171 } /* RT_CloseScreen */
173 static IPTR
RT_ShowErrorScreen (RTData
* rtd
, int rtt
, ScreenResource
* rt
,
174 IPTR ret
, int mode
, const char * file
, ULONG line
, va_list args
)
178 const char * modestr
= (mode
== RT_FREE
) ? "Close" : "Check";
181 scr
= va_arg (args
, struct Screen
*);
185 case RT_SEARCH_FOUND
:
186 if (rt
->Node
.Flags
& RTNF_DONT_FREE
)
188 kprintf ("RT%s: Try to free read-only resource: Screen\n"
195 , rt
->Node
.File
, rt
->Node
.Line
201 case RT_SEARCH_NOT_FOUND
:
202 kprintf ("RT%s: Screen not found\n"
216 kprintf ("RTExit: Screen was not closed\n"
219 , rt
->Node
.File
, rt
->Node
.Line
225 } /* RT_ShowErrorScreen */
227 static IPTR
RT_CheckScreen (RTData
* rtd
, int rtt
,
228 const char * file
, ULONG line
,
229 ULONG op
, va_list args
)
234 if (RT_Search (rtd
, rtt
, (RTNode
**)prt
, args
) != RT_SEARCH_FOUND
)
239 case RTTO_ScreenToFront
:
241 struct Screen
* scr
= va_arg (args
, struct Screen
*);
245 kprintf ("ScreenToFont(): Illegal window pointer\n"
246 " Screen=%p at %s:%d\n"
259 case RTTO_ScreenToBack
:
261 struct Screen
* scr
= va_arg (args
, struct Screen
*);
265 kprintf ("ScreenToBack(): Illegal window pointer\n"
266 " Screen=%p at %s:%d\n"
282 } /* RT_CheckScreen */
285 /**************************************
287 **************************************/
289 static IPTR
RT_OpenWindow (RTData
* rtd
, WindowResource
* rt
, va_list args
, BOOL
* success
)
291 struct NewWindow
* nw
;
292 struct TagItem
* tags
= NULL
;
295 op
= va_arg (args
, int);
296 nw
= va_arg (args
, struct NewWindow
*);
300 case RTTO_OpenWindowTags
:
301 tags
= (struct TagItem
*)args
;
304 case RTTO_OpenWindowTagList
:
305 tags
= va_arg (args
, struct TagItem
*);
310 if (!CheckPtr (nw
, NULL_PTR
))
312 kprintf ("OpenWindow(): Illegal NewWindow pointer\n"
313 " NewWindow=%p at %s:%d\n"
315 , rt
->Node
.File
, rt
->Node
.Line
319 else if (!CheckPtr (tags
, NULL_PTR
))
321 kprintf ("OpenWindowTagList(): Illegal TagList pointer\n"
322 " tagList=%p at %s:%d\n"
324 , rt
->Node
.File
, rt
->Node
.Line
329 rt
->Window
= OpenWindowTagList (nw
, tags
);
331 if (rt
->Window
->UserPort
)
332 RT_IntTrack (RTT_PORT
, __FILE__
, __LINE__
, rt
->Window
->UserPort
);
337 return (IPTR
)(rt
->Window
);
338 } /* RT_OpenWindow */
340 static IPTR
RT_CloseWindow (RTData
* rtd
, WindowResource
* rt
)
342 CloseWindow (rt
->Window
);
345 } /* RT_CloseWindow */
347 static IPTR
RT_ShowErrorWindow (RTData
* rtd
, int rtt
, WindowResource
* rt
,
348 IPTR ret
, int mode
, const char * file
, ULONG line
, va_list args
)
352 const char * modestr
= (mode
== RT_FREE
) ? "Close" : "Check";
355 win
= va_arg (args
, struct Window
*);
359 case RT_SEARCH_FOUND
:
360 if (rt
->Node
.Flags
& RTNF_DONT_FREE
)
362 kprintf ("RT%s: Try to free read-only resource: Window\n"
369 , rt
->Node
.File
, rt
->Node
.Line
375 case RT_SEARCH_NOT_FOUND
:
376 kprintf ("RT%s: Window not found\n"
390 kprintf ("RTExit: Window was not closed\n"
393 , rt
->Node
.File
, rt
->Node
.Line
399 } /* RT_ShowErrorWindow */
401 static IPTR
RT_CheckWindow (RTData
* rtd
, int rtt
,
402 const char * file
, ULONG line
,
403 ULONG op
, va_list args
)
408 if (RT_Search (rtd
, rtt
, (RTNode
**)prt
, args
) != RT_SEARCH_FOUND
)
413 case RTTO_WindowToFront
:
415 struct Window
* win
= va_arg (args
, struct Window
*);
419 kprintf ("WindowToFont(): Illegal window pointer\n"
420 " Window=%p at %s:%d\n"
433 case RTTO_WindowToBack
:
435 struct Window
* win
= va_arg (args
, struct Window
*);
439 kprintf ("WindowToBack(): Illegal window pointer\n"
440 " Window=%p at %s:%d\n"
456 } /* RT_CheckWindow */