2 Copyright (C) 2003-2015, The AROS Development Team.
6 #include <proto/acpica.h>
7 #include <proto/alib.h>
9 #include <proto/exec.h>
10 #include <proto/muimaster.h>
11 #include <proto/oop.h>
12 #include <proto/utility.h>
13 #include <proto/intuition.h>
15 #include <exec/memory.h>
16 #include <libraries/asl.h>
17 #include <libraries/mui.h>
18 #include <utility/tagitem.h>
19 #include <utility/hooks.h>
21 #include <aros/debug.h>
30 #define APPNAME "ACPITool"
31 #define VERSION "ACPITool 1.0"
33 const char version
[] = "$VER: " VERSION
" (" ADATE
")\n";
35 struct Library
*ACPICABase
;
37 static void ShowError(Object
*application
, Object
*window
, CONST_STRPTR message
, BOOL useIOError
)
40 STRPTR newline
= "\n",
44 /* Never use IO error if it is 0 */
45 if (IoErr() == 0) useIOError
= FALSE
;
49 Fault(IoErr(), NULL
, buffer
, sizeof(buffer
));
50 buffer
[0] = toupper(buffer
[0]);
61 application
, window
, 0, _(MSG_TITLE
), _(MSG_ERROR_OK
),
62 "%s:\n%s%s%s%s", _(MSG_ERROR_HEADER
), message
, newline
, extra
, period
66 void cleanup(CONST_STRPTR message
)
68 Locale_Deinitialize();
72 ShowError(NULL
, NULL
, message
, TRUE
);
76 CloseLibrary(ACPICABase
);
79 Object
*MakeLabel(STRPTR str
)
81 return (MUI_MakeObject(MUIO_Label
, str
, 0));
84 static inline LONG
xget(Object
* obj
, ULONG attr
)
88 GetAttr(attr
, obj
, &x
);
98 Object
*menu_quit
, *menu_dump_parsed
, *menu_dump_raw
;
100 AROS_UFH3(static void, display_function
,
101 AROS_UFHA(struct Hook
*, h
, A0
),
102 AROS_UFHA(const char **, strings
, A2
),
103 AROS_UFHA(const ACPI_TABLE_HEADER
*, table
, A1
))
107 const struct Parser
*t
= FindParser(table
->Signature
);
111 strings
[0] = t
->name
;
115 snprintf(buf
, sizeof(buf
), "%s (%4.4s)", _(MSG_UNKNOWN
), table
->Signature
);
121 static void display_callback(const char *str
)
123 DoMethod(InfoList
, MUIM_List_InsertSingle
, str
, MUIV_List_Insert_Bottom
);
126 AROS_UFH3(static void, select_function
,
127 AROS_UFHA(struct Hook
*, h
, A0
),
128 AROS_UFHA(Object
*, object
, A2
),
129 AROS_UFHA(APTR
, msg
, A1
))
134 const ACPI_TABLE_HEADER
*table
;
135 const struct Parser
*t
;
137 GetAttr(MUIA_Cycle_Active
, ModeCycle
, &mode
);
139 SetAttrs(InfoList
, MUIA_List_Quiet
, TRUE
, TAG_DONE
);
140 DoMethod(InfoList
, MUIM_List_Clear
);
142 GetAttr(MUIA_List_Active
, object
, &active
);
143 if (active
!= MUIV_List_Active_Off
)
145 void (*parser
)() = unknown_parser
;
147 DoMethod(object
, MUIM_List_GetEntry
, active
, &table
);
151 t
= FindParser(table
->Signature
);
156 parser(table
, display_callback
);
159 SetAttrs(InfoList
, MUIA_List_Quiet
, FALSE
, TAG_DONE
);
164 static BPTR
RequestFile(void)
167 struct FileRequester
*req
;
169 req
= MUI_AllocAslRequestTags(ASL_FileRequest
, ASLFR_DoSaveMode
, TRUE
, TAG_DONE
);
173 if (MUI_AslRequest(req
, NULL
))
175 ULONG len
= strlen(req
->fr_Drawer
) + strlen(req
->fr_File
) + 2;
176 STRPTR pathname
= AllocMem(len
, MEMF_ANY
);
180 strcpy(pathname
, req
->fr_Drawer
);
181 AddPart(pathname
, req
->fr_File
, len
);
183 file
= Open(pathname
, MODE_NEWFILE
);
184 FreeMem(pathname
, len
);
187 MUI_FreeAslRequest(req
);
192 AROS_UFH3(static void, save_function
,
193 AROS_UFHA(struct Hook
*, h
, A0
),
194 AROS_UFHA(Object
*, object
, A2
),
195 AROS_UFHA(APTR
, msg
, A1
))
199 BPTR file
= RequestFile();
205 GetAttr(MUIA_List_Entries
, object
, &n
);
207 for (i
= 0; i
< n
; i
++)
211 DoMethod(object
, MUIM_List_GetEntry
, i
, &text
);
224 static void dump_callback(const char *str
)
226 FPuts(DumpFile
, str
);
227 FPutC(DumpFile
, '\n');
230 AROS_UFH3(static IPTR
, dumpFunc
,
231 AROS_UFHA(struct Hook
*, table_hook
, A0
),
232 AROS_UFHA(const ACPI_TABLE_HEADER
*, table
, A2
),
233 AROS_UFHA(BOOL
, parsed
, A1
))
237 void (*parser
)() = unknown_parser
;
241 const struct Parser
*t
= FindParser(table
->Signature
);
247 parser(table
, dump_callback
);
248 FPutC(DumpFile
, '\n');
254 static const struct Hook dumpHook
=
256 .h_Entry
= (APTR
)dumpFunc
259 AROS_UFH3(static void, dump_function
,
260 AROS_UFHA(struct Hook
*, h
, A0
),
261 AROS_UFHA(Object
*, object
, A2
),
262 AROS_UFHA(IPTR
*, args
, A1
))
267 * MUIM_CallHook builds an array from its arguments, and gives us a pointer to this array.
268 * We need to explicitly convert to BOOL, otherwise the value can be padded with garbage,
269 * which will be contained in IPTR's upper unused bytes.
271 BOOL parsed
= args
[0];
273 DumpFile
= RequestFile();
277 for (i
= 0; ParserTable
[i
].name
; i
++)
278 AcpiScanTables(ParserTable
[i
].signature
, &dumpHook
, (APTR
)(IPTR
)parsed
);
286 static const struct Hook display_hook
=
288 .h_Entry
= (APTR
)display_function
291 static const struct Hook select_hook
=
293 .h_Entry
= (APTR
)select_function
296 static const struct Hook save_hook
=
298 .h_Entry
= (APTR
)save_function
301 static const struct Hook dump_hook
=
303 .h_Entry
= (APTR
)dump_function
306 static const char *showModes
[] =
313 static BOOL
GUIinit()
317 app
= ApplicationObject
,
318 MUIA_Application_Title
, (IPTR
)APPNAME
,
319 MUIA_Application_Version
, (IPTR
)VERSION
,
320 MUIA_Application_Copyright
, (IPTR
)"(C) 2004-2011, The AROS Development Team",
321 MUIA_Application_Author
, (IPTR
)"Pavel Fedin",
322 MUIA_Application_Base
, (IPTR
)APPNAME
,
323 MUIA_Application_Description
, __(MSG_DESCRIPTION
),
325 MUIA_Application_Menustrip
, MenustripObject
,
326 MUIA_Family_Child
, MenuObject
,
327 MUIA_Menu_Title
, __(MSG_MENU_PROJECT
),
329 menu_quit
= MenuitemObject
, MUIA_Menuitem_Title
, __(MSG_MENU_QUIT
),
332 MUIA_Family_Child
, MenuObject
,
333 MUIA_Menu_Title
, __(MSG_MENU_DUMP
),
335 menu_dump_parsed
= MenuitemObject
,
336 MUIA_Menuitem_Title
, __(MSG_MENU_DUMP_PARSED
),
339 menu_dump_raw
= MenuitemObject
,
340 MUIA_Menuitem_Title
, __(MSG_MENU_DUMP_RAW
),
345 SubWindow
, MainWindow
= WindowObject
,
346 MUIA_Window_Title
, __(MSG_WINTITLE
),
348 WindowContents
, HGroup
,
349 MUIA_Group_SameWidth
, FALSE
,
351 Child
, ListviewObject
,
352 MUIA_Listview_List
, TablesList
= ListObject
,
354 MUIA_List_AdjustWidth
, TRUE
,
355 MUIA_List_DisplayHook
, &display_hook
,
357 MUIA_CycleChain
, TRUE
,
361 Child
, ListviewObject
,
362 MUIA_Listview_List
, InfoList
= ListObject
,
364 MUIA_Font
, MUIV_Font_Fixed
,
365 MUIA_List_AdjustWidth
, TRUE
,
366 MUIA_List_ConstructHook
, MUIV_List_ConstructHook_String
,
367 MUIA_List_DestructHook
, MUIV_List_DestructHook_String
,
369 MUIA_CycleChain
, TRUE
,
372 Child
, Label(__(MSG_SHOW_MODE
)),
373 Child
, ModeCycle
= CycleObject
,
374 MUIA_Cycle_Entries
, showModes
,
375 MUIA_CycleChain
, TRUE
,
377 Child
, SaveButton
= SimpleButton(__(MSG_SAVE_DATA
)),
380 End
, // WindowContents
382 End
; // ApplicationObject
386 /* Quit application if the windowclosegadget or the esc key is pressed. */
387 DoMethod(MainWindow
, MUIM_Notify
, MUIA_Window_CloseRequest
, TRUE
,
389 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
391 DoMethod(menu_quit
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
393 MUIM_Application_ReturnID
, MUIV_Application_ReturnID_Quit
);
395 DoMethod(TablesList
, MUIM_Notify
, MUIA_List_Active
, MUIV_EveryTime
,
397 MUIM_CallHook
, &select_hook
);
399 DoMethod(ModeCycle
, MUIM_Notify
, MUIA_Cycle_Active
, MUIV_EveryTime
,
401 MUIM_CallHook
, &select_hook
);
403 DoMethod(SaveButton
, MUIM_Notify
, MUIA_Pressed
, FALSE
,
405 MUIM_CallHook
, &save_hook
);
407 DoMethod(menu_dump_parsed
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
409 MUIM_CallHook
, &dump_hook
, TRUE
);
411 DoMethod(menu_dump_raw
, MUIM_Notify
, MUIA_Menuitem_Trigger
, MUIV_EveryTime
,
413 MUIM_CallHook
, &dump_hook
, FALSE
);
421 AROS_UFH3(static IPTR
, tableFunc
,
422 AROS_UFHA(struct Hook
*, table_hook
, A0
),
423 AROS_UFHA(const ACPI_TABLE_HEADER
*, table
, A2
),
424 AROS_UFHA(void *, unused
, A1
))
428 DoMethod(TablesList
, MUIM_List_InsertSingle
, table
, MUIV_List_Insert_Bottom
);
434 static const struct Hook tableHook
=
436 .h_Entry
= (APTR
)tableFunc
439 int __nocommandline
= 1;
445 if (!Locale_Initialize())
446 cleanup(_(MSG_ERROR_LOCALE
));
448 ACPICABase
= OpenLibrary("acpica.library",0);
450 cleanup(_(MSG_ERROR_NO_ACPI
));
454 /* Populate tables list */
455 for (i
= 0; ParserTable
[i
].name
; i
++)
456 AcpiScanTables(ParserTable
[i
].signature
, &tableHook
, NULL
);
458 set(MainWindow
, MUIA_Window_Open
, TRUE
);
460 if (xget(MainWindow
, MUIA_Window_Open
))
465 while (retval
!= MUIV_Application_ReturnID_Quit
)
467 retval
= DoMethod(app
, MUIM_Application_NewInput
, &signals
);
470 signals
= Wait(signals
| SIGBREAKF_CTRL_C
);
472 if (signals
& SIGBREAKF_CTRL_C
)
473 retval
= MUIV_Application_ReturnID_Quit
;
475 set(MainWindow
, MUIA_Window_Open
, FALSE
);