Rev 90 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 90 | Rev 91 | ||
---|---|---|---|
1 | unit UD2_PluginStatus; |
1 | unit UD2_PluginStatus; |
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | Windows, SysUtils; |
6 | Windows, SysUtils; |
7 | 7 | ||
8 | type |
8 | type |
9 | UD2_STATUSCAT = WORD; |
9 | UD2_STATUSCAT = WORD; |
10 | UD2_STATUSAUTH = TGUID; |
10 | UD2_STATUSAUTH = TGUID; |
11 | UD2_STATUSMSG = DWORD; |
11 | UD2_STATUSMSG = DWORD; |
12 | UD2_STATUSEXTRAINFO = DWORD; |
12 | UD2_STATUSEXTRAINFO = DWORD; |
13 | 13 | ||
14 | UD2_STATUS = packed record |
14 | UD2_STATUS = packed record |
15 | cbSize: BYTE; |
15 | cbSize: BYTE; |
16 | bReserved: BYTE; |
16 | bReserved: BYTE; |
17 | wCategory: UD2_STATUSCAT; |
17 | wCategory: UD2_STATUSCAT; |
18 | grAuthority: UD2_STATUSAUTH; |
18 | grAuthority: UD2_STATUSAUTH; |
19 | dwMessage: UD2_STATUSMSG; |
19 | dwMessage: UD2_STATUSMSG; |
20 | dwExtraInfo: UD2_STATUSEXTRAINFO; |
20 | dwExtraInfo: UD2_STATUSEXTRAINFO; |
21 | end; |
21 | end; |
22 | 22 | ||
23 | const |
23 | const |
24 | // Note: we need to declare non-typed constants first, because we cannot use |
24 | // Note: we need to declare non-typed constants first, because we cannot use |
25 | // typed constants in constant records. |
25 | // typed constants in constant records. |
26 | // http://stackoverflow.com/questions/2714365/delphi-all-constants-are-constant-but-some-are-more-constant-than-others |
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}'; |
27 | UD2_STATUSAUTH_GENERIC_ = '{90F53368-1EFB-4350-A6BC-725C69938B9C}'; |
28 | UD2_STATUSAUTH_GENERIC : UD2_STATUSAUTH = UD2_STATUSAUTH_GENERIC_; |
28 | UD2_STATUSAUTH_GENERIC : UD2_STATUSAUTH = UD2_STATUSAUTH_GENERIC_; |
29 | 29 | ||
30 | UD2_STATUSCAT_SUCCESS = 0; |
30 | UD2_STATUSCAT_SUCCESS = 0; |
31 | UD2_STATUSCAT_NOT_AVAIL = 1; |
31 | UD2_STATUSCAT_NOT_AVAIL = 1; |
32 | UD2_STATUSCAT_FAILED = 2; |
32 | UD2_STATUSCAT_FAILED = 2; |
33 | 33 | ||
34 | (* Success codes *) |
34 | (* Success codes *) |
35 | 35 | ||
36 | UD2_STATUS_OK_UNSPECIFIED: UD2_STATUS = ( |
36 | UD2_STATUS_OK_UNSPECIFIED: UD2_STATUS = ( |
37 | cbSize: SizeOf(UD2_STATUS); |
37 | cbSize: SizeOf(UD2_STATUS); |
38 | bReserved: 0; |
38 | bReserved: 0; |
39 | wCategory: UD2_STATUSCAT_SUCCESS; |
39 | wCategory: UD2_STATUSCAT_SUCCESS; |
40 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
40 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
41 | dwMessage: 0; |
41 | dwMessage: 0; |
42 | dwExtraInfo: 0 |
42 | dwExtraInfo: 0 |
43 | ); |
43 | ); |
44 | UD2_STATUS_OK_SINGLELINE: UD2_STATUS = ( |
44 | UD2_STATUS_OK_SINGLELINE: UD2_STATUS = ( |
45 | cbSize: SizeOf(UD2_STATUS); |
45 | cbSize: SizeOf(UD2_STATUS); |
46 | bReserved: 0; |
46 | bReserved: 0; |
47 | wCategory: UD2_STATUSCAT_SUCCESS; |
47 | wCategory: UD2_STATUSCAT_SUCCESS; |
48 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
48 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
49 | dwMessage: 1; |
49 | dwMessage: 1; |
50 | dwExtraInfo: 0 |
50 | dwExtraInfo: 0 |
51 | ); |
51 | ); |
52 | UD2_STATUS_OK_MULTILINE: UD2_STATUS = ( |
52 | UD2_STATUS_OK_MULTILINE: UD2_STATUS = ( |
53 | cbSize: SizeOf(UD2_STATUS); |
53 | cbSize: SizeOf(UD2_STATUS); |
54 | bReserved: 0; |
54 | bReserved: 0; |
55 | wCategory: UD2_STATUSCAT_SUCCESS; |
55 | wCategory: UD2_STATUSCAT_SUCCESS; |
56 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
56 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
57 | dwMessage: 2; |
57 | dwMessage: 2; |
58 | dwExtraInfo: 0 |
58 | dwExtraInfo: 0 |
59 | ); |
59 | ); |
60 | UD2_STATUS_OK_LICENSED: UD2_STATUS = ( |
60 | UD2_STATUS_OK_LICENSED: UD2_STATUS = ( |
61 | cbSize: SizeOf(UD2_STATUS); |
61 | cbSize: SizeOf(UD2_STATUS); |
62 | bReserved: 0; |
62 | bReserved: 0; |
63 | wCategory: UD2_STATUSCAT_SUCCESS; |
63 | wCategory: UD2_STATUSCAT_SUCCESS; |
64 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
64 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
65 | dwMessage: 3; |
65 | dwMessage: 3; |
66 | dwExtraInfo: 0 |
66 | dwExtraInfo: 0 |
67 | ); |
67 | ); |
68 | 68 | ||
69 | (* "Not available" codes *) |
69 | (* "Not available" codes *) |
70 | 70 | ||
71 | UD2_STATUS_NOTAVAIL_UNSPECIFIED: UD2_STATUS = ( |
71 | UD2_STATUS_NOTAVAIL_UNSPECIFIED: UD2_STATUS = ( |
72 | cbSize: SizeOf(UD2_STATUS); |
72 | cbSize: SizeOf(UD2_STATUS); |
73 | bReserved: 0; |
73 | bReserved: 0; |
74 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
74 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
75 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
75 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
76 | dwMessage: 0; |
76 | dwMessage: 0; |
77 | dwExtraInfo: 0 |
77 | dwExtraInfo: 0 |
78 | ); |
78 | ); |
79 | UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED: UD2_STATUS = ( |
79 | UD2_STATUS_NOTAVAIL_OS_NOT_SUPPORTED: UD2_STATUS = ( |
80 | cbSize: SizeOf(UD2_STATUS); |
80 | cbSize: SizeOf(UD2_STATUS); |
81 | bReserved: 0; |
81 | bReserved: 0; |
82 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
82 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
83 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
83 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
84 | dwMessage: 1; |
84 | dwMessage: 1; |
85 | dwExtraInfo: 0 |
85 | dwExtraInfo: 0 |
86 | ); |
86 | ); |
87 | UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED: UD2_STATUS = ( |
87 | UD2_STATUS_NOTAVAIL_HW_NOT_SUPPORTED: UD2_STATUS = ( |
88 | cbSize: SizeOf(UD2_STATUS); |
88 | cbSize: SizeOf(UD2_STATUS); |
89 | bReserved: 0; |
89 | bReserved: 0; |
90 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
90 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
91 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
91 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
92 | dwMessage: 2; |
92 | dwMessage: 2; |
93 | dwExtraInfo: 0 |
93 | dwExtraInfo: 0 |
94 | ); |
94 | ); |
95 | UD2_STATUS_NOTAVAIL_NO_ENTITIES: UD2_STATUS = ( |
95 | UD2_STATUS_NOTAVAIL_NO_ENTITIES: UD2_STATUS = ( |
96 | cbSize: SizeOf(UD2_STATUS); |
96 | cbSize: SizeOf(UD2_STATUS); |
97 | bReserved: 0; |
97 | bReserved: 0; |
98 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
98 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
99 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
99 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
100 | dwMessage: 3; |
100 | dwMessage: 3; |
101 | dwExtraInfo: 0 |
101 | dwExtraInfo: 0 |
102 | ); |
102 | ); |
103 | UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE: UD2_STATUS = ( |
103 | UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE: UD2_STATUS = ( |
104 | cbSize: SizeOf(UD2_STATUS); |
104 | cbSize: SizeOf(UD2_STATUS); |
105 | bReserved: 0; |
105 | bReserved: 0; |
106 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
106 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
107 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
107 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
108 | dwMessage: 4; |
108 | dwMessage: 4; |
109 | dwExtraInfo: 0 |
109 | dwExtraInfo: 0 |
110 | ); |
110 | ); |
111 | UD2_STATUS_NOTAVAIL_ONLY_ACCEPT_DYNAMIC: UD2_STATUS = ( |
111 | UD2_STATUS_NOTAVAIL_ONLY_ACCEPT_DYNAMIC: UD2_STATUS = ( |
112 | cbSize: SizeOf(UD2_STATUS); |
112 | cbSize: SizeOf(UD2_STATUS); |
113 | bReserved: 0; |
113 | bReserved: 0; |
114 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
114 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
115 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
115 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
116 | dwMessage: 5; |
116 | dwMessage: 5; |
117 | dwExtraInfo: 0 |
117 | dwExtraInfo: 0 |
118 | ); |
118 | ); |
119 | UD2_STATUS_NOTAVAIL_INVALID_INPUT: UD2_STATUS = ( |
119 | UD2_STATUS_NOTAVAIL_INVALID_INPUT: UD2_STATUS = ( |
120 | cbSize: SizeOf(UD2_STATUS); |
120 | cbSize: SizeOf(UD2_STATUS); |
121 | bReserved: 0; |
121 | bReserved: 0; |
122 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
122 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
123 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
123 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
124 | dwMessage: 6; |
124 | dwMessage: 6; |
125 | dwExtraInfo: 0 |
125 | dwExtraInfo: 0 |
126 | ); |
126 | ); |
- | 127 | UD2_STATUS_NOTAVAIL_DOES_NOT_ACCEPT_DYNAMIC_REQUESTS: UD2_STATUS = ( |
|
- | 128 | cbSize: SizeOf(UD2_STATUS); |
|
- | 129 | bReserved: 0; |
|
- | 130 | wCategory: UD2_STATUSCAT_NOT_AVAIL; |
|
- | 131 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
|
- | 132 | dwMessage: 7; |
|
- | 133 | dwExtraInfo: 0 |
|
- | 134 | ); |
|
127 | 135 | ||
128 | (* Failure codes *) |
136 | (* Failure codes *) |
129 | 137 | ||
130 | UD2_STATUS_FAILURE_UNSPECIFIED: UD2_STATUS = ( |
138 | UD2_STATUS_FAILURE_UNSPECIFIED: UD2_STATUS = ( |
131 | cbSize: SizeOf(UD2_STATUS); |
139 | cbSize: SizeOf(UD2_STATUS); |
132 | bReserved: 0; |
140 | bReserved: 0; |
133 | wCategory: UD2_STATUSCAT_FAILED; |
141 | wCategory: UD2_STATUSCAT_FAILED; |
134 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
142 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
135 | dwMessage: 0; |
143 | dwMessage: 0; |
136 | dwExtraInfo: 0 |
144 | dwExtraInfo: 0 |
137 | ); |
145 | ); |
138 | UD2_STATUS_FAILURE_BUFFER_TOO_SMALL: UD2_STATUS = ( |
146 | UD2_STATUS_FAILURE_BUFFER_TOO_SMALL: UD2_STATUS = ( |
139 | cbSize: SizeOf(UD2_STATUS); |
147 | cbSize: SizeOf(UD2_STATUS); |
140 | bReserved: 0; |
148 | bReserved: 0; |
141 | wCategory: UD2_STATUSCAT_FAILED; |
149 | wCategory: UD2_STATUSCAT_FAILED; |
142 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
150 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
143 | dwMessage: 1; |
151 | dwMessage: 1; |
144 | dwExtraInfo: 0 |
152 | dwExtraInfo: 0 |
145 | ); |
153 | ); |
146 | UD2_STATUS_FAILURE_INVALID_ARGS: UD2_STATUS = ( |
154 | UD2_STATUS_FAILURE_INVALID_ARGS: UD2_STATUS = ( |
147 | cbSize: SizeOf(UD2_STATUS); |
155 | cbSize: SizeOf(UD2_STATUS); |
148 | bReserved: 0; |
156 | bReserved: 0; |
149 | wCategory: UD2_STATUSCAT_FAILED; |
157 | wCategory: UD2_STATUSCAT_FAILED; |
150 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
158 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
151 | dwMessage: 2; |
159 | dwMessage: 2; |
152 | dwExtraInfo: 0 |
160 | dwExtraInfo: 0 |
153 | ); |
161 | ); |
154 | UD2_STATUS_FAILURE_PLUGIN_NOT_LICENSED: UD2_STATUS = ( |
162 | UD2_STATUS_FAILURE_PLUGIN_NOT_LICENSED: UD2_STATUS = ( |
155 | cbSize: SizeOf(UD2_STATUS); |
163 | cbSize: SizeOf(UD2_STATUS); |
156 | bReserved: 0; |
164 | bReserved: 0; |
157 | wCategory: UD2_STATUSCAT_FAILED; |
165 | wCategory: UD2_STATUSCAT_FAILED; |
158 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
166 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
159 | dwMessage: 3; |
167 | dwMessage: 3; |
160 | dwExtraInfo: 0 |
168 | dwExtraInfo: 0 |
161 | ); |
169 | ); |
162 | UD2_STATUS_FAILURE_NO_RETURNED_VALUE: UD2_STATUS = ( |
170 | UD2_STATUS_FAILURE_NO_RETURNED_VALUE: UD2_STATUS = ( |
163 | cbSize: SizeOf(UD2_STATUS); |
171 | cbSize: SizeOf(UD2_STATUS); |
164 | bReserved: 0; |
172 | bReserved: 0; |
165 | wCategory: UD2_STATUSCAT_FAILED; |
173 | wCategory: UD2_STATUSCAT_FAILED; |
166 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
174 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
167 | dwMessage: 4; |
175 | dwMessage: 4; |
168 | dwExtraInfo: 0 |
176 | dwExtraInfo: 0 |
169 | ); |
177 | ); |
170 | UD2_STATUS_FAILURE_CATCHED_EXCEPTION: UD2_STATUS = ( |
178 | UD2_STATUS_FAILURE_CATCHED_EXCEPTION: UD2_STATUS = ( |
171 | cbSize: SizeOf(UD2_STATUS); |
179 | cbSize: SizeOf(UD2_STATUS); |
172 | bReserved: 0; |
180 | bReserved: 0; |
173 | wCategory: UD2_STATUSCAT_FAILED; |
181 | wCategory: UD2_STATUSCAT_FAILED; |
174 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
182 | grAuthority: UD2_STATUSAUTH_GENERIC_; |
175 | dwMessage: 5; |
183 | dwMessage: 5; |
176 | dwExtraInfo: 0 |
184 | dwExtraInfo: 0 |
177 | ); |
185 | ); |
178 | 186 | ||
179 | function UD2_STATUS_FormatStatusCode(grStatus: UD2_STATUS): string; |
187 | function UD2_STATUS_FormatStatusCode(grStatus: UD2_STATUS): string; |
180 | function UD2_STATUS_Equal(grStatus1, grStatus2: UD2_STATUS; compareExtraInfo: boolean): boolean; |
188 | function UD2_STATUS_Equal(grStatus1, grStatus2: UD2_STATUS; compareExtraInfo: boolean): boolean; |
181 | function UD2_STATUS_OSError(OSError: DWORD): UD2_STATUS; |
189 | function UD2_STATUS_OSError(OSError: DWORD): UD2_STATUS; |
182 | function UD2_STATUS_HandleException(E: Exception): UD2_STATUS; |
190 | function UD2_STATUS_HandleException(E: Exception): UD2_STATUS; |
183 | 191 | ||
184 | implementation |
192 | implementation |
185 | 193 | ||
186 | function UD2_STATUS_FormatStatusCode(grStatus: UD2_STATUS): string; |
194 | function UD2_STATUS_FormatStatusCode(grStatus: UD2_STATUS): string; |
187 | begin |
195 | begin |
188 | // 00 0000 {44332211-1234-ABCD-EFEF-001122334455} 00000000 00000000 |
196 | // 00 0000 {44332211-1234-ABCD-EFEF-001122334455} 00000000 00000000 |
189 | result := Format('%.2x %.4x %s %.8x %.8x', [ |
197 | result := Format('%.2x %.4x %s %.8x %.8x', [ |
190 | grStatus.bReserved, |
198 | grStatus.bReserved, |
191 | grStatus.wCategory, |
199 | grStatus.wCategory, |
192 | GUIDTostring(grStatus.grAuthority), |
200 | GUIDTostring(grStatus.grAuthority), |
193 | grStatus.dwMessage, |
201 | grStatus.dwMessage, |
194 | grStatus.dwExtraInfo]); |
202 | grStatus.dwExtraInfo]); |
195 | end; |
203 | end; |
196 | 204 | ||
197 | function UD2_STATUS_Equal(grStatus1, grStatus2: UD2_STATUS; compareExtraInfo: boolean): boolean; |
205 | function UD2_STATUS_Equal(grStatus1, grStatus2: UD2_STATUS; compareExtraInfo: boolean): boolean; |
198 | begin |
206 | begin |
199 | result := (grStatus1.bReserved = grStatus2.bReserved) and |
207 | result := (grStatus1.bReserved = grStatus2.bReserved) and |
200 | (grStatus1.wCategory = grStatus2.wCategory) and |
208 | (grStatus1.wCategory = grStatus2.wCategory) and |
201 | IsEqualGUID(grStatus1.grAuthority, grStatus2.grAuthority) and |
209 | IsEqualGUID(grStatus1.grAuthority, grStatus2.grAuthority) and |
202 | (grStatus1.dwMessage = grStatus2.dwMessage); |
210 | (grStatus1.dwMessage = grStatus2.dwMessage); |
203 | if compareExtraInfo and (grStatus1.dwExtraInfo <> grStatus2.dwExtraInfo) then result := false; |
211 | if compareExtraInfo and (grStatus1.dwExtraInfo <> grStatus2.dwExtraInfo) then result := false; |
204 | end; |
212 | end; |
205 | 213 | ||
206 | function UD2_STATUS_OSError(OSError: DWORD): UD2_STATUS; |
214 | function UD2_STATUS_OSError(OSError: DWORD): UD2_STATUS; |
207 | begin |
215 | begin |
208 | result := UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE; |
216 | result := UD2_STATUS_NOTAVAIL_WINAPI_CALL_FAILURE; |
209 | result.dwExtraInfo := OSError; |
217 | result.dwExtraInfo := OSError; |
210 | end; |
218 | end; |
211 | 219 | ||
212 | function UD2_STATUS_HandleException(E: Exception): UD2_STATUS; |
220 | function UD2_STATUS_HandleException(E: Exception): UD2_STATUS; |
213 | begin |
221 | begin |
214 | if E is EOSError then |
222 | if E is EOSError then |
215 | begin |
223 | begin |
216 | result := UD2_STATUS_OSError(EOSError(E).ErrorCode); |
224 | result := UD2_STATUS_OSError(EOSError(E).ErrorCode); |
217 | end |
225 | end |
218 | else |
226 | else |
219 | begin |
227 | begin |
220 | result := UD2_STATUS_FAILURE_CATCHED_EXCEPTION; |
228 | result := UD2_STATUS_FAILURE_CATCHED_EXCEPTION; |
221 | end; |
229 | end; |
222 | end; |
230 | end; |
223 | 231 | ||
224 | end. |
232 | end. |
225 | 233 |