Rev 81 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
71 | daniel-mar | 1 | unit UD2_PluginStatus; |
2 | |||
3 | interface |
||
4 | |||
5 | uses |
||
6 | Windows, SysUtils; |
||
7 | |||
8 | type |
||
9 | UD2_STATUSCAT = WORD; |
||
10 | UD2_STATUSAUTH = TGUID; |
||
11 | UD2_STATUSMSG = DWORD; |
||
12 | UD2_STATUSEXTRAINFO = DWORD; |
||
13 | |||
14 | UD2_STATUS = packed record |
||
15 | cbSize: BYTE; |
||
16 | bReserved: BYTE; |
||
17 | wCategory: UD2_STATUSCAT; |
||
18 | grAuthority: UD2_STATUSAUTH; |
||
19 | dwMessage: UD2_STATUSMSG; |
||
20 | dwExtraInfo: UD2_STATUSEXTRAINFO; |
||
21 | end; |
||
22 | |||
23 | const |
||
24 | // Note: we need to declare non-typed constants first, because we cannot use |
||
25 | // typed constants in constant records. |
||
26 | // http://stackoverflow.com/questions/2714365/delphi-all-constants-are-constant-but-some-are-more-constant-than-others |
||
27 | UD2_STATUSAUTH_GENERIC_ = '{90F53368-1EFB-4350-A6BC-725C69938B9C}'; |
||
28 | UD2_STATUSAUTH_GENERIC : UD2_STATUSAUTH = UD2_STATUSAUTH_GENERIC_; |
||
29 | |||
30 | UD2_STATUSCAT_SUCCESS = 0; |
||
31 | UD2_STATUSCAT_NOT_AVAIL = 1; |
||
32 | UD2_STATUSCAT_FAILED = 2; |
||
33 | |||
34 | (* Success codes *) |
||
35 | |||
36 | UD2_STATUS_OK_UNSPECIFIED: UD2_STATUS = ( |
||
37 | cbSize: SizeOf(UD2_STATUS); |
||
38 | bReserved: 0; |
||
39 | wCategory: UD2_STATUSCAT_SUCCESS; |
||
40 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
41 | dwMessage: 0; |
||
42 | dwExtraInfo: 0 |
||
43 | ); |
||
44 | UD2_STATUS_OK_SINGLELINE: UD2_STATUS = ( |
||
45 | cbSize: SizeOf(UD2_STATUS); |
||
46 | bReserved: 0; |
||
47 | wCategory: UD2_STATUSCAT_SUCCESS; |
||
48 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
49 | dwMessage: 1; |
||
50 | dwExtraInfo: 0 |
||
51 | ); |
||
52 | UD2_STATUS_OK_MULTILINE: UD2_STATUS = ( |
||
53 | cbSize: SizeOf(UD2_STATUS); |
||
54 | bReserved: 0; |
||
55 | wCategory: UD2_STATUSCAT_SUCCESS; |
||
56 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
57 | dwMessage: 2; |
||
58 | dwExtraInfo: 0 |
||
59 | ); |
||
60 | UD2_STATUS_OK_LICENSED: UD2_STATUS = ( |
||
61 | cbSize: SizeOf(UD2_STATUS); |
||
62 | bReserved: 0; |
||
63 | wCategory: UD2_STATUSCAT_SUCCESS; |
||
64 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
65 | dwMessage: 3; |
||
66 | dwExtraInfo: 0 |
||
67 | ); |
||
68 | |||
69 | (* "Not available" codes *) |
||
70 | |||
71 | UD2_STATUS_NOTAVAIL_UNSPECIFIED: UD2_STATUS = ( |
||
72 | cbSize: SizeOf(UD2_STATUS); |
||
73 | bReserved: 0; |
||
74 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
||
75 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
76 | dwMessage: 0; |
||
77 | dwExtraInfo: 0 |
||
78 | ); |
||
79 | UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED: UD2_STATUS = ( |
||
80 | cbSize: SizeOf(UD2_STATUS); |
||
81 | bReserved: 0; |
||
82 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
||
83 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
84 | dwMessage: 1; |
||
85 | dwExtraInfo: 0 |
||
86 | ); |
||
87 | UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED: UD2_STATUS = ( |
||
88 | cbSize: SizeOf(UD2_STATUS); |
||
89 | bReserved: 0; |
||
90 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
||
91 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
92 | dwMessage: 2; |
||
93 | dwExtraInfo: 0 |
||
94 | ); |
||
95 | UD2_STATUS_NOTAVAIL_NO_ENTITIES: UD2_STATUS = ( |
||
96 | cbSize: SizeOf(UD2_STATUS); |
||
97 | bReserved: 0; |
||
98 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
||
99 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
100 | dwMessage: 3; |
||
101 | dwExtraInfo: 0 |
||
102 | ); |
||
103 | UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE: UD2_STATUS = ( |
||
104 | cbSize: SizeOf(UD2_STATUS); |
||
105 | bReserved: 0; |
||
106 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
||
107 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
108 | dwMessage: 4; |
||
109 | dwExtraInfo: 0 |
||
110 | ); |
||
111 | |||
112 | (* Failure codes *) |
||
113 | |||
114 | UD2_STATUS_FAILURE_UNSPECIFIED: UD2_STATUS = ( |
||
115 | cbSize: SizeOf(UD2_STATUS); |
||
116 | bReserved: 0; |
||
117 | wCategory: UD2_STATUSCAT_FAILED; |
||
118 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
119 | dwMessage: 0; |
||
120 | dwExtraInfo: 0 |
||
121 | ); |
||
122 | UD2_STATUS_FAILURE_BUFFER_TOO_SMALL: UD2_STATUS = ( |
||
123 | cbSize: SizeOf(UD2_STATUS); |
||
124 | bReserved: 0; |
||
125 | wCategory: UD2_STATUSCAT_FAILED; |
||
126 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
127 | dwMessage: 1; |
||
128 | dwExtraInfo: 0 |
||
129 | ); |
||
130 | UD2_STATUS_FAILURE_INVALID_ARGS: UD2_STATUS = ( |
||
131 | cbSize: SizeOf(UD2_STATUS); |
||
132 | bReserved: 0; |
||
133 | wCategory: UD2_STATUSCAT_FAILED; |
||
134 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
135 | dwMessage: 2; |
||
136 | dwExtraInfo: 0 |
||
137 | ); |
||
138 | UD2_STATUS_FAILURE_PLUGIN_NOT_LICENSED: UD2_STATUS = ( |
||
139 | cbSize: SizeOf(UD2_STATUS); |
||
140 | bReserved: 0; |
||
141 | wCategory: UD2_STATUSCAT_FAILED; |
||
142 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
||
143 | dwMessage: 3; |
||
144 | dwExtraInfo: 0 |
||
145 | ); |
||
146 | |||
147 | function UD2_STATUS_FormatStatusCode(grStatus: UD2_STATUS): string; |
||
148 | function UD2_STATUS_Equal(grStatus1, grStatus2: UD2_STATUS; compareExtraInfo: boolean): boolean; |
||
149 | function UD2_STATUS_OSError(OSError: DWORD): UD2_STATUS; |
||
150 | |||
151 | implementation |
||
152 | |||
153 | function UD2_STATUS_FormatStatusCode(grStatus: UD2_STATUS): string; |
||
154 | begin |
||
155 | // 00 0000 {44332211-1234-ABCD-EFEF-001122334455} 00000000 00000000 |
||
156 | result := Format('%.2x %.4x %s %.8x %.8x', [ |
||
157 | grStatus.bReserved, |
||
158 | grStatus.wCategory, |
||
159 | GUIDTostring(grStatus.grAuthority), |
||
160 | grStatus.dwMessage, |
||
161 | grStatus.dwExtraInfo]); |
||
162 | end; |
||
163 | |||
164 | function UD2_STATUS_Equal(grStatus1, grStatus2: UD2_STATUS; compareExtraInfo: boolean): boolean; |
||
165 | begin |
||
166 | result := (grStatus1.bReserved = grStatus2.bReserved) and |
||
167 | (grStatus1.wCategory = grStatus2.wCategory) and |
||
168 | IsEqualGUID(grStatus1.grAuthority, grStatus2.grAuthority) and |
||
169 | (grStatus1.dwMessage = grStatus2.dwMessage); |
||
170 | if compareExtraInfo and (grStatus1.dwExtraInfo <> grStatus2.dwExtraInfo) then result := false; |
||
171 | end; |
||
172 | |||
173 | function UD2_STATUS_OSError(OSError: DWORD): UD2_STATUS; |
||
174 | begin |
||
175 | result := UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE; |
||
176 | result.dwExtraInfo := OSError; |
||
177 | end; |
||
178 | |||
179 | end. |