1 |
|
---|
2 | /*
|
---|
3 | *@@sourcefile apcih.c:
|
---|
4 | * contains helpers for accessing ACPI.
|
---|
5 | *
|
---|
6 | * Usage: All OS/2 programs.
|
---|
7 | *
|
---|
8 | * Function prefixes:
|
---|
9 | * -- acpih* ACPI helper functions
|
---|
10 | *
|
---|
11 | * Note: Version numbering in this file relates to XWorkplace version
|
---|
12 | * numbering.
|
---|
13 | *
|
---|
14 | *@@header "helpers\acpih.h"
|
---|
15 | *@@added V1.0.5 (2006-06-26) [pr]
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*
|
---|
19 | * Copyright (C) 2006 Paul Ratcliffe.
|
---|
20 | * This file is part of the "XWorkplace helpers" source package.
|
---|
21 | * This is free software; you can redistribute it and/or modify
|
---|
22 | * it under the terms of the GNU General Public License as published
|
---|
23 | * by the Free Software Foundation, in version 2 as it comes in the
|
---|
24 | * "COPYING" file of the XWorkplace main distribution.
|
---|
25 | * This program is distributed in the hope that it will be useful,
|
---|
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
28 | * GNU General Public License for more details.
|
---|
29 | */
|
---|
30 |
|
---|
31 | #define OS2EMX_PLAIN_CHAR
|
---|
32 | // this is needed for "os2emx.h"; if this is defined,
|
---|
33 | // emx will define PSZ as _signed_ char, otherwise
|
---|
34 | // as unsigned char
|
---|
35 |
|
---|
36 | #define INCL_DOSMODULEMGR
|
---|
37 | #define INCL_DOSERRORS
|
---|
38 | #include <os2.h>
|
---|
39 |
|
---|
40 | #include "setup.h" // code generation and debugging options
|
---|
41 |
|
---|
42 | #include "helpers\acpih.h"
|
---|
43 | #include "helpers\standards.h"
|
---|
44 |
|
---|
45 | /* ******************************************************************
|
---|
46 | *
|
---|
47 | * Globals
|
---|
48 | *
|
---|
49 | ********************************************************************/
|
---|
50 |
|
---|
51 | HMODULE hmodACPI = NULLHANDLE;
|
---|
52 |
|
---|
53 | ACPISTARTAPI *pAcpiStartApi = NULL;
|
---|
54 | ACPIENDAPI *pAcpiEndApi = NULL;
|
---|
55 | ACPIGOTOSLEEP *pAcpiGoToSleep = NULL;
|
---|
56 |
|
---|
57 | /*
|
---|
58 | *@@category: Helpers\Control program helpers\ACPI
|
---|
59 | * See acpih.c.
|
---|
60 | */
|
---|
61 |
|
---|
62 | /*
|
---|
63 | *@@ acpihOpen:
|
---|
64 | * resolves the ACPI entrypoints and loads the ACPI DLL.
|
---|
65 | */
|
---|
66 |
|
---|
67 | APIRET acpihOpen(ACPI_API_HANDLE *phACPI)
|
---|
68 | {
|
---|
69 | APIRET arc = NO_ERROR;
|
---|
70 |
|
---|
71 | if (!hmodACPI)
|
---|
72 | if (!(arc = DosLoadModule(NULL,
|
---|
73 | 0,
|
---|
74 | "ACPI32",
|
---|
75 | &hmodACPI)))
|
---|
76 | {
|
---|
77 | arc = DosQueryProcAddr(hmodACPI,
|
---|
78 | ORD_ACPISTARTAPI,
|
---|
79 | NULL,
|
---|
80 | (PFN *) &pAcpiStartApi);
|
---|
81 | if (!arc)
|
---|
82 | arc = DosQueryProcAddr(hmodACPI,
|
---|
83 | ORD_ACPIENDAPI,
|
---|
84 | NULL,
|
---|
85 | (PFN *) &pAcpiEndApi);
|
---|
86 |
|
---|
87 | if (!arc)
|
---|
88 | arc = DosQueryProcAddr(hmodACPI,
|
---|
89 | ORD_ACPIGOTOSLEEP,
|
---|
90 | NULL,
|
---|
91 | (PFN *) &pAcpiGoToSleep);
|
---|
92 | if (arc)
|
---|
93 | {
|
---|
94 | DosFreeModule(hmodACPI);
|
---|
95 | hmodACPI = NULLHANDLE;
|
---|
96 | pAcpiStartApi = NULL;
|
---|
97 | pAcpiEndApi = NULL;
|
---|
98 | pAcpiGoToSleep = NULL;
|
---|
99 | return(arc);
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | if (arc)
|
---|
104 | return(arc);
|
---|
105 | else
|
---|
106 | return(pAcpiStartApi(phACPI));
|
---|
107 | }
|
---|
108 |
|
---|
109 | /*
|
---|
110 | *@@ acpihClose:
|
---|
111 | * unloads the ACPI DLL.
|
---|
112 | */
|
---|
113 |
|
---|
114 | VOID acpihClose(ACPI_API_HANDLE *phACPI)
|
---|
115 | {
|
---|
116 | if (pAcpiEndApi)
|
---|
117 | pAcpiEndApi(phACPI);
|
---|
118 | }
|
---|
119 |
|
---|
120 | /*
|
---|
121 | *@@ acpihGoToSleep:
|
---|
122 | * changes the Power State.
|
---|
123 | */
|
---|
124 |
|
---|
125 | APIRET acpihGoToSleep(ACPI_API_HANDLE *phACPI, UCHAR ucState)
|
---|
126 | {
|
---|
127 | if (pAcpiGoToSleep)
|
---|
128 | return(pAcpiGoToSleep(phACPI, ucState));
|
---|
129 | else
|
---|
130 | return(ERROR_PROTECTION_VIOLATION);
|
---|
131 | }
|
---|
132 |
|
---|