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-2009 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 G_hmodACPI = NULLHANDLE;
|
---|
52 | ULONG G_ulCount = 0;
|
---|
53 |
|
---|
54 | ACPISTARTAPI *pAcpiStartApi = NULL;
|
---|
55 | ACPIENDAPI *pAcpiEndApi = NULL;
|
---|
56 | ACPIGOTOSLEEP *pAcpiGoToSleep = NULL;
|
---|
57 |
|
---|
58 | /*
|
---|
59 | *@@category: Helpers\Control program helpers\ACPI
|
---|
60 | * See acpih.c.
|
---|
61 | */
|
---|
62 |
|
---|
63 | /*
|
---|
64 | *@@ acpihOpen:
|
---|
65 | * resolves the ACPI entrypoints and loads the ACPI DLL.
|
---|
66 | */
|
---|
67 |
|
---|
68 | APIRET acpihOpen(ACPI_API_HANDLE *phACPI)
|
---|
69 | {
|
---|
70 | APIRET arc = NO_ERROR;
|
---|
71 |
|
---|
72 | if (!G_hmodACPI)
|
---|
73 | if (!(arc = DosLoadModule(NULL,
|
---|
74 | 0,
|
---|
75 | "ACPI32",
|
---|
76 | &G_hmodACPI)))
|
---|
77 | {
|
---|
78 | arc = DosQueryProcAddr(G_hmodACPI,
|
---|
79 | ORD_ACPISTARTAPI,
|
---|
80 | NULL,
|
---|
81 | (PFN *) &pAcpiStartApi);
|
---|
82 | if (!arc)
|
---|
83 | arc = DosQueryProcAddr(G_hmodACPI,
|
---|
84 | ORD_ACPIENDAPI,
|
---|
85 | NULL,
|
---|
86 | (PFN *) &pAcpiEndApi);
|
---|
87 |
|
---|
88 | if (!arc)
|
---|
89 | arc = DosQueryProcAddr(G_hmodACPI,
|
---|
90 | ORD_ACPIGOTOSLEEP,
|
---|
91 | NULL,
|
---|
92 | (PFN *) &pAcpiGoToSleep);
|
---|
93 | if (arc)
|
---|
94 | {
|
---|
95 | DosFreeModule(G_hmodACPI);
|
---|
96 | G_hmodACPI = NULLHANDLE;
|
---|
97 | pAcpiStartApi = NULL;
|
---|
98 | pAcpiEndApi = NULL;
|
---|
99 | pAcpiGoToSleep = NULL;
|
---|
100 | return(arc);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | if (arc)
|
---|
105 | return(arc);
|
---|
106 | else
|
---|
107 | {
|
---|
108 | G_ulCount++;
|
---|
109 | return(pAcpiStartApi(phACPI));
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | /*
|
---|
114 | *@@ acpihClose:
|
---|
115 | * unloads the ACPI DLL.
|
---|
116 | */
|
---|
117 |
|
---|
118 | VOID acpihClose(ACPI_API_HANDLE *phACPI)
|
---|
119 | {
|
---|
120 | if (pAcpiEndApi)
|
---|
121 | {
|
---|
122 | pAcpiEndApi(phACPI);
|
---|
123 | G_ulCount--;
|
---|
124 | }
|
---|
125 |
|
---|
126 | if (!G_ulCount)
|
---|
127 | {
|
---|
128 | DosFreeModule(G_hmodACPI);
|
---|
129 | G_hmodACPI = NULLHANDLE;
|
---|
130 | pAcpiStartApi = NULL;
|
---|
131 | pAcpiEndApi = NULL;
|
---|
132 | pAcpiGoToSleep = NULL;
|
---|
133 | }
|
---|
134 | }
|
---|
135 |
|
---|
136 | /*
|
---|
137 | *@@ acpihGoToSleep:
|
---|
138 | * changes the Power State.
|
---|
139 | */
|
---|
140 |
|
---|
141 | APIRET acpihGoToSleep(ACPI_API_HANDLE *phACPI, UCHAR ucState)
|
---|
142 | {
|
---|
143 | if (pAcpiGoToSleep)
|
---|
144 | return(pAcpiGoToSleep(phACPI, ucState));
|
---|
145 | else
|
---|
146 | return(ERROR_PROTECTION_VIOLATION);
|
---|
147 | }
|
---|
148 |
|
---|