Merge lp:~zorba-coders/zorba/bug-1188058 into lp:zorba/system-module
- bug-1188058
- Merge into system-module
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 37 | ||||
Proposed branch: | lp:~zorba-coders/zorba/bug-1188058 | ||||
Merge into: | lp:zorba/system-module | ||||
Diff against target: |
718 lines (+217/-140) 8 files modified
src/CMakeLists.txt (+1/-3) src/com/CMakeLists.txt (+0/-14) src/com/zorba-xquery/CMakeLists.txt (+0/-14) src/com/zorba-xquery/www/CMakeLists.txt (+0/-14) src/com/zorba-xquery/www/modules/CMakeLists.txt (+0/-14) src/system.xq (+52/-35) src/system.xq.src/system.cpp (+128/-45) src/system.xq.src/system.h (+36/-1) |
||||
To merge this branch: | bzr merge lp:~zorba-coders/zorba/bug-1188058 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Hillery | Approve | ||
Luis Rodriguez Gonzalez | Approve | ||
Review via email: mp+178905@code.launchpad.net |
Commit message
Update non-core "system" module to Zorba 3.0 standards. Added system:
Description of the change
- 37. By Luis Rodriguez Gonzalez
-
Changes for Zorba 3.0 done
- 38. By Luis Rodriguez Gonzalez
-
Forgot to add SystemModule:
:getKey( )
Luis Rodriguez Gonzalez (kuraru) : | # |
- 39. By Luis Rodriguez Gonzalez
-
Fixed XQDoc
Luis Rodriguez Gonzalez (kuraru) wrote : | # |
> Looks very good, nice work. However, the moduleDocumentation test doesn't
> pass, so there must be a typo somewhere in the XQDoc. Also, I suspect once you
> fix that, it will complain that all those public variable declarations need to
> have XQDoc; you'll probably need to restore the doc from the old version.
> (%private variables, like errors codes, don't need XQDoc, but public ones do
> as far as I know.)
Done.
Chris Hillery (ceejatec) : | # |
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for the following merge proposals:
https:/
Progress dashboard at http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Voting criteria failed for the following merge proposals:
https:/
Votes: {'Approve': 2, 'Needs commit message': 1}
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue result for https:/
Stage "CommitZorba" failed.
Check console output at http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for the following merge proposals:
https:/
Progress dashboard at http://
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue succeeded - proposal merged!
Preview Diff
1 | === modified file 'src/CMakeLists.txt' |
2 | --- src/CMakeLists.txt 2011-07-26 10:43:21 +0000 |
3 | +++ src/CMakeLists.txt 2013-08-08 20:52:48 +0000 |
4 | @@ -14,6 +14,4 @@ |
5 | |
6 | # all external module libraries are generated in the directory |
7 | # of the corresponding .xq file |
8 | -MESSAGE(STATUS "Add com") |
9 | -ADD_SUBDIRECTORY(com) |
10 | -MESSAGE(STATUS "End modules") |
11 | +DECLARE_ZORBA_MODULE (URI "http://zorba.io/modules/system" VERSION 1.0 FILE "system.xq") |
12 | |
13 | === removed directory 'src/com' |
14 | === removed file 'src/com/CMakeLists.txt' |
15 | --- src/com/CMakeLists.txt 2011-10-06 08:19:44 +0000 |
16 | +++ src/com/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
17 | @@ -1,14 +0,0 @@ |
18 | -# Copyright 2006-2008 The FLWOR Foundation. |
19 | -# |
20 | -# Licensed under the Apache License, Version 2.0 (the "License"); |
21 | -# you may not use this file except in compliance with the License. |
22 | -# You may obtain a copy of the License at |
23 | -# |
24 | -# http://www.apache.org/licenses/LICENSE-2.0 |
25 | -# |
26 | -# Unless required by applicable law or agreed to in writing, software |
27 | -# distributed under the License is distributed on an "AS IS" BASIS, |
28 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
29 | -# See the License for the specific language governing permissions and |
30 | -# limitations under the License. |
31 | -ADD_SUBDIRECTORY(zorba-xquery) |
32 | |
33 | === removed directory 'src/com/zorba-xquery' |
34 | === removed file 'src/com/zorba-xquery/CMakeLists.txt' |
35 | --- src/com/zorba-xquery/CMakeLists.txt 2011-10-06 08:19:44 +0000 |
36 | +++ src/com/zorba-xquery/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
37 | @@ -1,14 +0,0 @@ |
38 | -# Copyright 2006-2008 The FLWOR Foundation. |
39 | -# |
40 | -# Licensed under the Apache License, Version 2.0 (the "License"); |
41 | -# you may not use this file except in compliance with the License. |
42 | -# You may obtain a copy of the License at |
43 | -# |
44 | -# http://www.apache.org/licenses/LICENSE-2.0 |
45 | -# |
46 | -# Unless required by applicable law or agreed to in writing, software |
47 | -# distributed under the License is distributed on an "AS IS" BASIS, |
48 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
49 | -# See the License for the specific language governing permissions and |
50 | -# limitations under the License. |
51 | -ADD_SUBDIRECTORY(www) |
52 | |
53 | === removed directory 'src/com/zorba-xquery/www' |
54 | === removed file 'src/com/zorba-xquery/www/CMakeLists.txt' |
55 | --- src/com/zorba-xquery/www/CMakeLists.txt 2011-10-06 08:19:44 +0000 |
56 | +++ src/com/zorba-xquery/www/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
57 | @@ -1,14 +0,0 @@ |
58 | -# Copyright 2006-2008 The FLWOR Foundation. |
59 | -# |
60 | -# Licensed under the Apache License, Version 2.0 (the "License"); |
61 | -# you may not use this file except in compliance with the License. |
62 | -# You may obtain a copy of the License at |
63 | -# |
64 | -# http://www.apache.org/licenses/LICENSE-2.0 |
65 | -# |
66 | -# Unless required by applicable law or agreed to in writing, software |
67 | -# distributed under the License is distributed on an "AS IS" BASIS, |
68 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
69 | -# See the License for the specific language governing permissions and |
70 | -# limitations under the License. |
71 | -ADD_SUBDIRECTORY(modules) |
72 | |
73 | === removed directory 'src/com/zorba-xquery/www/modules' |
74 | === removed file 'src/com/zorba-xquery/www/modules/CMakeLists.txt' |
75 | --- src/com/zorba-xquery/www/modules/CMakeLists.txt 2011-07-01 09:24:04 +0000 |
76 | +++ src/com/zorba-xquery/www/modules/CMakeLists.txt 1970-01-01 00:00:00 +0000 |
77 | @@ -1,14 +0,0 @@ |
78 | -# Copyright 2006-2008 The FLWOR Foundation. |
79 | -# |
80 | -# Licensed under the Apache License, Version 2.0 (the "License"); |
81 | -# you may not use this file except in compliance with the License. |
82 | -# You may obtain a copy of the License at |
83 | -# |
84 | -# http://www.apache.org/licenses/LICENSE-2.0 |
85 | -# |
86 | -# Unless required by applicable law or agreed to in writing, software |
87 | -# distributed under the License is distributed on an "AS IS" BASIS, |
88 | -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
89 | -# See the License for the specific language governing permissions and |
90 | -# limitations under the License. |
91 | -DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/system" VERSION 1.0 FILE "system.xq") |
92 | |
93 | === renamed file 'src/com/zorba-xquery/www/modules/system.xq' => 'src/system.xq' |
94 | --- src/com/zorba-xquery/www/modules/system.xq 2013-06-15 19:49:56 +0000 |
95 | +++ src/system.xq 2013-08-08 20:52:48 +0000 |
96 | @@ -1,4 +1,4 @@ |
97 | -xquery version "3.0"; |
98 | +jsoniq version "1.0"; |
99 | |
100 | (: |
101 | : Copyright 2006-2009 The FLWOR Foundation. |
102 | @@ -18,12 +18,10 @@ |
103 | (:~ |
104 | : The system module allows developers to access system properties. |
105 | : Part of these system properties are environment variables, |
106 | - : local variable to the process running Zorba, and properties defined by Zorba. |
107 | - : <br /> |
108 | + : local variable to the process running Zorba, and properties defined by Zorba.<p/> |
109 | : To avoid conflicts between environment variables and properties defined by Zorba, |
110 | - : all environment variables are prefixed with <i>env.</i>. |
111 | - : <br /> |
112 | - : For instance, the following query: <br /> |
113 | + : all environment variables are prefixed with <i>env.</i>.<p/> |
114 | + : For instance, the following query: <p/> |
115 | : <pre class="ace-static"> |
116 | : import module namespace system = "http://www.zorba-xquery.com/modules/system"; |
117 | : |
118 | @@ -31,19 +29,19 @@ |
119 | : return concat($prop, ": ", system:property($prop), " |
120 | : ") |
121 | : </pre> |
122 | - : <br /> |
123 | + : <p/> |
124 | : Will output: |
125 | : <pre class="ace-static"> |
126 | : env.TERM_PROGRAM: Apple_Terminal |
127 | : ... |
128 | : </pre> |
129 | : In this example, it is important to notice that the environnement variable PATH |
130 | - : with the key env.PATH. |
131 | + : with the key env.PATH.<p/> |
132 | : |
133 | : @author Markus Pilman |
134 | : @project Zorba/Input Output/System |
135 | :) |
136 | -module namespace system = 'http://www.zorba-xquery.com/modules/system'; |
137 | +module namespace system = "http://zorba.io/modules/system"; |
138 | |
139 | declare namespace an = "http://www.zorba-xquery.com/annotations"; |
140 | |
141 | @@ -53,12 +51,12 @@ |
142 | (:~ |
143 | : The name of the operating system (os.name). |
144 | :) |
145 | -declare variable $system:os-name as xs:string := "os.name"; |
146 | +declare variable $system:OS-NAME as xs:string := "os.name"; |
147 | |
148 | (:~ |
149 | : The name of the computer the process is running on (os.node.name). |
150 | :) |
151 | -declare variable $system:os-node-name as xs:string := "os.node.name"; |
152 | +declare variable $system:OS-NODE-NAME as xs:string := "os.node.name"; |
153 | |
154 | (:~ |
155 | : The major version number of the Windows installation or |
156 | @@ -66,7 +64,7 @@ |
157 | : (os.version.major). |
158 | : <b>Works on Windows only.</b> |
159 | :) |
160 | -declare variable $system:os-version-major as xs:string := "os.version.major"; |
161 | +declare variable $system:OS-VERSION-MAJOR as xs:string := "os.version.major"; |
162 | |
163 | (:~ |
164 | : The minor version number of the Windows installation or |
165 | @@ -74,7 +72,7 @@ |
166 | : (os.version.minor). |
167 | : <b>Works on Windows only.</b> |
168 | :) |
169 | -declare variable $system:os-version-minor as xs:string := "os.version.minor"; |
170 | +declare variable $system:OS-VERSION-MINOR as xs:string := "os.version.minor"; |
171 | |
172 | (:~ |
173 | : The build number of the Windows installation or |
174 | @@ -82,7 +80,7 @@ |
175 | : (os.version.build). |
176 | : <b>Works on Windows only.</b> |
177 | :) |
178 | -declare variable $system:os-version-build as xs:string := "os.version.build"; |
179 | +declare variable $system:OS-VERSION-BUILD as xs:string := "os.version.build"; |
180 | |
181 | (:~ |
182 | : The release of this UNIX installation or |
183 | @@ -90,105 +88,108 @@ |
184 | : (os.version.release). |
185 | : <b>Works on UNIX based operating systems only.</b> |
186 | :) |
187 | -declare variable $system:os-version-release as xs:string := "os.version.release"; |
188 | +declare variable $system:OS-VERSION-RELEASE as xs:string := "os.version.release"; |
189 | + |
190 | (:~ |
191 | : The version of this UNIX installation or |
192 | : an empty string if the process does not run on a UNIX/Linux installation |
193 | : (os.version.version). |
194 | : <b>Works on UNIX based operating systems only.</b> |
195 | :) |
196 | -declare variable $system:os-version-version as xs:string := "os.version.version"; |
197 | +declare variable $system:OS-VERSION-VERSION as xs:string := "os.version.version"; |
198 | |
199 | (:~ |
200 | : The version of the Operating System. |
201 | :) |
202 | -declare variable $system:os-version as xs:string := "os.version"; |
203 | +declare variable $system:OS-VERSION as xs:string := "os.version"; |
204 | |
205 | (:~ |
206 | : The name of the processor architecture (os.arch). |
207 | : For example x86 or x86_64. |
208 | :) |
209 | -declare variable $system:os-arch as xs:string := "os.arch"; |
210 | +declare variable $system:OS-ARCH as xs:string := "os.arch"; |
211 | |
212 | (:~ |
213 | : True if system architecture is 64bits (os.is64). |
214 | :) |
215 | -declare variable $system:os-is64 as xs:string := "os.is64"; |
216 | +declare variable $system:OS-IS64 as xs:string := "os.is64"; |
217 | |
218 | (:~ |
219 | : Number of logical processors in the system (hardware.logical.cpu). |
220 | : This information is not available under Mac OS X. |
221 | :) |
222 | -declare variable $system:hardware-logical-cpu as xs:string := "hardware.logical.cpu"; |
223 | +declare variable $system:HARDWARE-LOGICAL-CPU as xs:string := "hardware.logical.cpu"; |
224 | |
225 | (:~ |
226 | - : Number of physical processors in the system (hardware.logical.cpu). |
227 | + : Number of physical processors in the system (hardware.physical.cpu). |
228 | :) |
229 | -declare variable $system:hardware-physical-cpu as xs:string := "hardware.physical.cpu"; |
230 | +declare variable $system:HARDWARE-PHYSICAL-CPU as xs:string := "hardware.physical.cpu"; |
231 | |
232 | (:~ |
233 | : number of logical per physical processors in the system (hardware.logical.per.physical.cpu). |
234 | : This information is not available under Mac OS X. |
235 | :) |
236 | -declare variable $system:hardware-logical-per-physical-cpu as xs:string := "hardware.logical.per.physical.cpu"; |
237 | +declare variable $system:HARDWARE-LOGICAL-PER-PHYSICAL-CPU as xs:string := "hardware.logical.per.physical.cpu"; |
238 | |
239 | (:~ |
240 | : Physical memory available (hardware.physical.memory). |
241 | :) |
242 | -declare variable $system:hardware-physical-memory as xs:string := "hardware.physical.memory"; |
243 | +declare variable $system:HARDWARE-PHSICAL-MEMORY as xs:string := "hardware.physical.memory"; |
244 | + |
245 | (:~ |
246 | : Virtual memory available (hardware.virtual.memory). |
247 | :) |
248 | -declare variable $system:hardware-virtual-memory as xs:string := "hardware.virtual.memory"; |
249 | +declare variable $system:HARDWARE-VIRTUAL-MEMORY as xs:string := "hardware.virtual.memory"; |
250 | + |
251 | (:~ |
252 | : Gets the hardware manufacturer (hardware.manufacturer). |
253 | :) |
254 | -declare variable $system:hardware-manufacturer as xs:string := "hardware.manufacturer"; |
255 | +declare variable $system:HARDWARE-MANUFACTURER as xs:string := "hardware.manufacturer"; |
256 | |
257 | (:~ |
258 | : The Linux distribution, Zorba is running on (linux.distributor). |
259 | : <b>Works on UNIX based operating systems only.</b> |
260 | :) |
261 | -declare variable $system:linux-distributor as xs:string := "linux.distributor"; |
262 | +declare variable $system:LINUX-DISTRIBUTOR as xs:string := "linux.distributor"; |
263 | |
264 | (:~ |
265 | : The version of the Linux distribution, Zorba is running on (linux.distributor.version). |
266 | : <b>Works on UNIX based operating systems only.</b> |
267 | :) |
268 | -declare variable $system:linux-distributor-version as xs:string := "linux.distributor.version"; |
269 | +declare variable $system:LINUX-DISTRIBUTOR-VERSION as xs:string := "linux.distributor.version"; |
270 | |
271 | (:~ |
272 | : The username, with which this process was started (user.name). |
273 | : On Unix, this variable is only available if the USER environment |
274 | : variable is set (e.g. it might not be available in a cronjob). |
275 | :) |
276 | -declare variable $system:user-name as xs:string := "user.name"; |
277 | +declare variable $system:USER-NAME as xs:string := "user.name"; |
278 | |
279 | (:~ |
280 | : The Zorba module path, that is the paths in which Zorba looks |
281 | : for modules (zorba.module.path). |
282 | :) |
283 | -declare variable $system:zorba-module-path as xs:string := "zorba.module.path"; |
284 | +declare variable $system:ZORBA-MODULE-PATH as xs:string := "zorba.module.path"; |
285 | |
286 | (:~ |
287 | : Zorba version in the format Major.Minor.Patch (zorba.version). |
288 | :) |
289 | -declare variable $system:zorba-version as xs:string := "zorba.version"; |
290 | +declare variable $system:ZORBA-VERSION as xs:string := "zorba.version"; |
291 | |
292 | (:~ |
293 | : Zorba major version (zorba.version.major). |
294 | :) |
295 | -declare variable $system:zorba-version-major as xs:string := "zorba.version.major"; |
296 | +declare variable $system:ZORBA-VERSION-MAJOR as xs:string := "zorba.version.major"; |
297 | |
298 | (:~ |
299 | : Zorba minor version (zorba.version.minor). |
300 | :) |
301 | -declare variable $system:zorba-version-minor as xs:string := "zorba.version.minor"; |
302 | +declare variable $system:ZORBA-VERSION-MINOR as xs:string := "zorba.version.minor"; |
303 | |
304 | (:~ |
305 | : Zorba patch version (zorba.version.patch). |
306 | :) |
307 | -declare variable $system:zorba-version-patch as xs:string := "zorba.version.patch"; |
308 | +declare variable $system:ZORBA-VERSION-PATCH as xs:string := "zorba.version.patch"; |
309 | |
310 | (:~ |
311 | : Gets the system property indicated by the specified key. |
312 | @@ -201,7 +202,7 @@ |
313 | (:~ |
314 | : This function retrieves the names of the current system properties. |
315 | : This list includes environment variables, local variable to the process running Zorba, and properties defined by Zorba. |
316 | - : <br /> |
317 | + : <p/> |
318 | : To avoid conflicts between environment variables and properties defined by Zorba, |
319 | : all environment variables are prefixed with <i>env.</i>. |
320 | : |
321 | @@ -209,3 +210,19 @@ |
322 | :) |
323 | declare %an:nondeterministic function system:properties() as xs:string* external; |
324 | |
325 | +(:~ |
326 | + : This function retrieves all names and values from the current system properties. |
327 | + : This list includes environment variables, local variable to the process running Zorba, and properties defined by Zorba. |
328 | + : <p/> |
329 | + : To avoid conflicts between environment variables and properties defined by Zorba, |
330 | + : all environment variables are prefixed with <i>env.</i>. |
331 | + : |
332 | + : @return List of all system properties as a JSONiq Object sequence. |
333 | + :) |
334 | +declare %an:nondeterministic function system:all-properties() as object() { |
335 | + { |
336 | + for $prop in system:properties() |
337 | + return { $prop : system:property($prop) } |
338 | + } |
339 | +}; |
340 | + |
341 | |
342 | === renamed directory 'src/com/zorba-xquery/www/modules/system.xq.src' => 'src/system.xq.src' |
343 | === modified file 'src/system.xq.src/system.cpp' |
344 | --- src/com/zorba-xquery/www/modules/system.xq.src/system.cpp 2012-07-19 12:29:57 +0000 |
345 | +++ src/system.xq.src/system.cpp 2013-08-08 20:52:48 +0000 |
346 | @@ -55,7 +55,33 @@ |
347 | |
348 | namespace zorba { namespace system { |
349 | |
350 | - const String SystemModule::SYSTEM_MODULE_NAMESPACE = "http://www.zorba-xquery.com/modules/system"; |
351 | + const String SystemModule::SYSTEM_MODULE_NAMESPACE = "http://zorba.io/modules/system"; |
352 | + |
353 | + // global keys |
354 | + zorba::Item SystemModule::globalOSName; |
355 | + zorba::Item SystemModule::globalOSNodeName; |
356 | + zorba::Item SystemModule::globalOSVersionMajor; |
357 | + zorba::Item SystemModule::globalOSVersionMinor; |
358 | + zorba::Item SystemModule::globalOSVersionBuild; |
359 | + zorba::Item SystemModule::globalOSVersionRelease; |
360 | + zorba::Item SystemModule::globalOSVersionVersion; |
361 | + zorba::Item SystemModule::globalOSVersion; |
362 | + zorba::Item SystemModule::globalOSArch; |
363 | + zorba::Item SystemModule::globalOSis64; |
364 | + zorba::Item SystemModule::globalHWLogicalCPU; |
365 | + zorba::Item SystemModule::globalHWPhysicalCPU; |
366 | + zorba::Item SystemModule::globalHWLogicalPerPhysicalCPU; |
367 | + zorba::Item SystemModule::globalHWPhysicalMemory; |
368 | + zorba::Item SystemModule::globalHWVirtualMemory; |
369 | + zorba::Item SystemModule::globalHWManufacturer; |
370 | + zorba::Item SystemModule::globalLinuxDistributor; |
371 | + zorba::Item SystemModule::globalLinuxDistributorVersion; |
372 | + zorba::Item SystemModule::globalUserName; |
373 | + zorba::Item SystemModule::globalZorbaModulePath; |
374 | + zorba::Item SystemModule::globalZorbaVersion; |
375 | + zorba::Item SystemModule::globalZorbaVersionMajor; |
376 | + zorba::Item SystemModule::globalZorbaVersionMinor; |
377 | + zorba::Item SystemModule::globalZorbaVersionPatch; |
378 | |
379 | #ifdef WIN32 |
380 | typedef BOOL (WINAPI *LPFN_GLPI)( |
381 | @@ -252,6 +278,30 @@ |
382 | SystemModule::SystemModule() |
383 | : thePropertyFunction(0), thePropertiesFunction(0) |
384 | { |
385 | + globalOSName = Zorba::getInstance(0)->getItemFactory()->createString("os.name"); |
386 | + globalOSNodeName = Zorba::getInstance(0)->getItemFactory()->createString("os.node.name"); |
387 | + globalOSVersionMajor = Zorba::getInstance(0)->getItemFactory()->createString("os.version.major"); |
388 | + globalOSVersionMinor = Zorba::getInstance(0)->getItemFactory()->createString("os.version.minor"); |
389 | + globalOSVersionBuild = Zorba::getInstance(0)->getItemFactory()->createString("os.version.build"); |
390 | + globalOSVersionRelease = Zorba::getInstance(0)->getItemFactory()->createString("os.version.release"); |
391 | + globalOSVersionVersion = Zorba::getInstance(0)->getItemFactory()->createString("os.version.version"); |
392 | + globalOSVersion = Zorba::getInstance(0)->getItemFactory()->createString("os.version"); |
393 | + globalOSArch = Zorba::getInstance(0)->getItemFactory()->createString("os.arch"); |
394 | + globalOSis64 = Zorba::getInstance(0)->getItemFactory()->createString("os.is64"); |
395 | + globalHWLogicalCPU = Zorba::getInstance(0)->getItemFactory()->createString("hardware.logical.cpu"); |
396 | + globalHWPhysicalCPU = Zorba::getInstance(0)->getItemFactory()->createString("hardware.physical.cpu"); |
397 | + globalHWLogicalPerPhysicalCPU = Zorba::getInstance(0)->getItemFactory()->createString("hardware.logical.per.physical.cpu"); |
398 | + globalHWPhysicalMemory = Zorba::getInstance(0)->getItemFactory()->createString("hardware.physical.memory"); |
399 | + globalHWVirtualMemory = Zorba::getInstance(0)->getItemFactory()->createString("hardware.virtual.memory"); |
400 | + globalHWManufacturer = Zorba::getInstance(0)->getItemFactory()->createString("hardware.manufacturer"); |
401 | + globalLinuxDistributor = Zorba::getInstance(0)->getItemFactory()->createString("linux.distributor"); |
402 | + globalLinuxDistributorVersion = Zorba::getInstance(0)->getItemFactory()->createString("linux.distributor.version"); |
403 | + globalUserName = Zorba::getInstance(0)->getItemFactory()->createString("user.name"); |
404 | + globalZorbaModulePath = Zorba::getInstance(0)->getItemFactory()->createString("zorba.module.path"); |
405 | + globalZorbaVersion = Zorba::getInstance(0)->getItemFactory()->createString("zorba.version"); |
406 | + globalZorbaVersionMajor = Zorba::getInstance(0)->getItemFactory()->createString("zorba.version.major"); |
407 | + globalZorbaVersionMinor = Zorba::getInstance(0)->getItemFactory()->createString("zorba.version.minor"); |
408 | + globalZorbaVersionPatch = Zorba::getInstance(0)->getItemFactory()->createString("zorba.version.patch"); |
409 | } |
410 | |
411 | ExternalFunction* SystemModule::getExternalFunction(const String& localName) { |
412 | @@ -276,6 +326,39 @@ |
413 | delete thePropertiesFunction; |
414 | } |
415 | |
416 | + zorba::Item& |
417 | + SystemModule::getGlobalKey(SystemModule::GLOBAL_KEY g) |
418 | + { |
419 | + switch(g) |
420 | + { |
421 | + case OS_NAME: return globalOSName; |
422 | + case OS_NODE_NAME: return globalOSNodeName; |
423 | + case OS_VER_MAJOR: return globalOSVersionMajor; |
424 | + case OS_VER_MINOR: return globalOSVersionMinor; |
425 | + case OS_VER_BUILD: return globalOSVersionBuild; |
426 | + case OS_VER_RELEASE: return globalOSVersionRelease; |
427 | + case OS_VER_VERSION: return globalOSVersionVersion; |
428 | + case OS_VER: return globalOSVersion; |
429 | + case OS_ARCH: return globalOSArch; |
430 | + case OS_IS64: return globalOSis64; |
431 | + case HARDWARE_lOGICAL_CPU: return globalHWLogicalCPU; |
432 | + case HARDWARE_PHYSICAL_CPU: return globalHWPhysicalCPU; |
433 | + case HARDWARE_LOGICAL_PER_PHYSICAL_CPU: return globalHWLogicalPerPhysicalCPU; |
434 | + case HARDWARE_PHYSICAL_MEMORY: return globalHWPhysicalMemory; |
435 | + case HARDWARE_VIRTUAL_MEMORY: return globalHWVirtualMemory; |
436 | + case HARDWARE_MANUFACTURER: return globalHWManufacturer; |
437 | + case LINUX_DISTRIBUTOR: return globalLinuxDistributor; |
438 | + case LINUX_DISTRIBUTOR_VERSION: return globalLinuxDistributorVersion; |
439 | + case USER_NAME: return globalUserName; |
440 | + case ZORBA_MODULE_PATH: return globalZorbaModulePath; |
441 | + case ZORBA_VER: return globalZorbaVersion; |
442 | + case ZORBA_VER_MAJOR: return globalZorbaVersionMajor; |
443 | + case ZORBA_VER_MINOR: return globalZorbaVersionMinor; |
444 | + case ZORBA_VER_PATCH: return globalZorbaVersionPatch; |
445 | + // should never hit this code but still ... |
446 | + default: return globalOSName; |
447 | + } |
448 | + } |
449 | |
450 | SystemFunction::SystemFunction(const ExternalModule* aModule) |
451 | : theModule(aModule), theFactory(Zorba::getInstance(0)->getItemFactory()) |
452 | @@ -291,7 +374,7 @@ |
453 | nodeNameC[i] = static_cast<char>(nodeName[i]); |
454 | } |
455 | nodeNameC[nodeNameLength] = NULL; // Terminate string |
456 | - theProperties.insert(std::make_pair("os.node.name", nodeNameC)); |
457 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_NODE_NAME).getStringValue(), nodeNameC)); |
458 | } |
459 | |
460 | { |
461 | @@ -325,13 +408,13 @@ |
462 | minor = sMinor.str(); |
463 | build = sBuild.str(); |
464 | } |
465 | - theProperties.insert(std::make_pair("os.version.major", major)); |
466 | - theProperties.insert(std::make_pair("os.version.minor", minor)); |
467 | - theProperties.insert(std::make_pair("os.version.build", build)); |
468 | - theProperties.insert(std::make_pair("os.version", major + "." + minor + "." + build)); |
469 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_VER_MAJOR).getStringValue(), major)); |
470 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_VER_MINOR).getStringValue(), minor)); |
471 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_VER_BUILD).getStringValue(), build)); |
472 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_VER).getString(), major + "." + minor + "." + build)); |
473 | // http://msdn.microsoft.com/en-us/library/ms724832(v=VS.85).aspx |
474 | std::string operativeSystem; |
475 | - theProperties.insert(std::make_pair("os.name", "Windows")); |
476 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_NAME).getStringValue(), "Windows")); |
477 | { |
478 | countProcessors(); |
479 | std::stringstream logicalProcessors; |
480 | @@ -340,9 +423,9 @@ |
481 | physicalProcessors << logicalProcessorCount; |
482 | std::stringstream logicalPerPhysicalProcessors; |
483 | logicalPerPhysicalProcessors << (logicalProcessorCount / processorPackageCount ); |
484 | - theProperties.insert(std::make_pair("hardware.physical.cpu", logicalProcessors.str() )); |
485 | - theProperties.insert(std::make_pair("hardware.logical.cpu", physicalProcessors.str() )); |
486 | - theProperties.insert(std::make_pair("hardware.logical.per.physical.cpu", logicalPerPhysicalProcessors.str() )); |
487 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_PHYSICAL_CPU).getStringValue(), logicalProcessors.str() )); |
488 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_lOGICAL_CPU).getStringValue(), physicalProcessors.str() )); |
489 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_LOGICAL_PER_PHYSICAL_CPU).getStringValue(), logicalPerPhysicalProcessors.str() )); |
490 | } |
491 | { |
492 | MEMORYSTATUSEX statex; |
493 | @@ -352,8 +435,8 @@ |
494 | virtualMemory << statex.ullTotalVirtual; |
495 | std::stringstream physicalMemory; |
496 | physicalMemory << statex.ullTotalPhys; |
497 | - theProperties.insert(std::make_pair("hardware.virtual.memory", virtualMemory.str() )); |
498 | - theProperties.insert(std::make_pair("hardware.physical.memory", physicalMemory.str() )); |
499 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_VIRTUAL_MEMORY).getStringValue(), virtualMemory.str() )); |
500 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_PHYSICAL_MEMORY).getStringValue(), physicalMemory.str() )); |
501 | } |
502 | |
503 | } |
504 | @@ -365,20 +448,20 @@ |
505 | for (DWORD i = 0; i < userNameLength; ++i) { |
506 | userNameC[i] = static_cast<char>(userName[i]); |
507 | } |
508 | - theProperties.insert(std::make_pair("user.name", userNameC)); |
509 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::USER_NAME).getStringValue(), userNameC)); |
510 | } |
511 | { |
512 | SYSTEM_INFO info; |
513 | GetSystemInfo(&info); |
514 | if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { |
515 | - theProperties.insert(std::make_pair("os.arch", "x86_64")); |
516 | - theProperties.insert(std::make_pair("os.is64", "true")); |
517 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_ARCH).getStringValue(), "x86_64")); |
518 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_IS64).getStringValue(), "true")); |
519 | } else if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) { |
520 | - theProperties.insert(std::make_pair("os.arch", "ia64")); |
521 | - theProperties.insert(std::make_pair("os.is64", "true")); |
522 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_ARCH).getStringValue(), "ia64")); |
523 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_IS64).getStringValue(), "true")); |
524 | } else if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) { |
525 | - theProperties.insert(std::make_pair("os.arch", "i386")); |
526 | - theProperties.insert(std::make_pair("os.is64", "false")); |
527 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_ARCH).getStringValue(), "i386")); |
528 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_IS64).getStringValue(), "false")); |
529 | } |
530 | } |
531 | |
532 | @@ -395,7 +478,7 @@ |
533 | valueC[i] = static_cast<char>(value[i]); |
534 | } |
535 | if (size > 0) |
536 | - theProperties.insert(std::make_pair("hardware.manufacturer", valueC)); |
537 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_MANUFACTURER).getStringValue(), valueC)); |
538 | } |
539 | RegCloseKey(keyHandle); |
540 | } |
541 | @@ -405,19 +488,19 @@ |
542 | struct utsname osname; |
543 | if (uname(&osname) == 0) |
544 | { |
545 | - theProperties.insert(std::make_pair("os.name", osname.sysname)); |
546 | - theProperties.insert(std::make_pair("os.node.name", osname.nodename)); |
547 | - theProperties.insert(std::make_pair("os.version.release", osname.release)); |
548 | - theProperties.insert(std::make_pair("os.version.version", osname.version)); |
549 | - theProperties.insert(std::make_pair("os.version", osname.release)); |
550 | - theProperties.insert(std::make_pair("os.arch", osname.machine)); |
551 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_NAME).getStringValue(), osname.sysname)); |
552 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_NODE_NAME).getStringValue(), osname.nodename)); |
553 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_VER_RELEASE).getStringValue(), osname.release)); |
554 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_VER_VERSION).getStringValue(), osname.version)); |
555 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_VER).getStringValue(), osname.release)); |
556 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_ARCH).getStringValue(), osname.machine)); |
557 | } |
558 | char* lUser = getenv("USER"); |
559 | if (lUser) |
560 | { |
561 | - theProperties.insert(std::make_pair("user.name", lUser)); |
562 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::USER_NAME).getStringValue(), lUser)); |
563 | } |
564 | - theProperties.insert(std::make_pair("os.is64", "false")); |
565 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::OS_IS64).getStringValue(), "false")); |
566 | { |
567 | #ifdef __APPLE__ |
568 | int mib[2]; |
569 | @@ -429,7 +512,7 @@ |
570 | sysctl(mib, 2, &res, &len, NULL, NULL); |
571 | std::stringstream lStream; |
572 | lStream << res; |
573 | - theProperties.insert(std::make_pair("hardware.physical.cpu", lStream.str())); |
574 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_PHYSICAL_CPU).getStringValue(), lStream.str())); |
575 | #else |
576 | countProcessors(); |
577 | std::stringstream logicalProcessor; |
578 | @@ -438,9 +521,9 @@ |
579 | logicalProcessor << logical; |
580 | physicalProcessor << physical; |
581 | logicalPerPhysicalProcessors << cores; |
582 | - theProperties.insert(std::make_pair("hardware.logical.per.physical.cpu", logicalPerPhysicalProcessors.str() )); |
583 | - theProperties.insert(std::make_pair("hardware.physical.cpu", physicalProcessor.str() )); |
584 | - theProperties.insert(std::make_pair("hardware.logical.cpu", logicalProcessor.str() )); |
585 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_LOGICAL_PER_PHYSICAL_CPU).getStringValue(), logicalPerPhysicalProcessors.str() )); |
586 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_PHYSICAL_CPU).getStringValue(), physicalProcessor.str() )); |
587 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_lOGICAL_CPU).getStringValue(), logicalProcessor.str() )); |
588 | #endif |
589 | } |
590 | { |
591 | @@ -451,8 +534,8 @@ |
592 | memory << sys_info.totalram; |
593 | std::stringstream swap; |
594 | swap << sys_info.totalswap; |
595 | - theProperties.insert(std::make_pair("hardware.virtual.memory", swap.str() )); |
596 | - theProperties.insert(std::make_pair("hardware.physical.memory", memory.str() )); |
597 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_VIRTUAL_MEMORY).getStringValue(), swap.str() )); |
598 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_PHYSICAL_MEMORY).getStringValue(), memory.str() )); |
599 | } |
600 | # elif defined __APPLE__ |
601 | int mib[2]; |
602 | @@ -464,19 +547,19 @@ |
603 | sysctl(mib, 2, &res, &len, NULL, NULL); |
604 | std::stringstream lStream; |
605 | lStream << res; |
606 | - theProperties.insert(std::make_pair("hardware.physical.memory", lStream.str())); |
607 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::HARDWARE_PHYSICAL_MEMORY).getStringValue(), lStream.str())); |
608 | # endif |
609 | } |
610 | |
611 | #endif |
612 | #ifdef LINUX |
613 | - theProperties.insert(std::make_pair("linux.distributor", "")); |
614 | - theProperties.insert(std::make_pair("linux.distributor.version", "")); |
615 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::LINUX_DISTRIBUTOR).getStringValue(), "")); |
616 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::LINUX_DISTRIBUTOR_VERSION).getStringValue(), "")); |
617 | #endif |
618 | - theProperties.insert(std::make_pair("zorba.version", Zorba::version().getVersion())); |
619 | - theProperties.insert(std::make_pair("zorba.version.major", intToString(Zorba::version().getMajorVersion()))); |
620 | - theProperties.insert(std::make_pair("zorba.version.minor", intToString(Zorba::version().getMinorVersion()))); |
621 | - theProperties.insert(std::make_pair("zorba.version.patch", intToString(Zorba::version().getPatchVersion()))); |
622 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::ZORBA_VER).getStringValue(), Zorba::version().getVersion())); |
623 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::ZORBA_VER_MAJOR).getStringValue(), intToString(Zorba::version().getMajorVersion()))); |
624 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::ZORBA_VER_MINOR).getStringValue(), intToString(Zorba::version().getMinorVersion()))); |
625 | + theProperties.insert(std::make_pair(SystemModule::getGlobalKey(SystemModule::ZORBA_VER_PATCH).getStringValue(), intToString(Zorba::version().getPatchVersion()))); |
626 | } |
627 | |
628 | String SystemFunction::intToString(int v) { |
629 | @@ -552,7 +635,7 @@ |
630 | lRes.push_back(lItem); |
631 | } |
632 | // insert the zorba module path |
633 | - lRes.push_back(theFactory->createString("zorba.module.path")); |
634 | + lRes.push_back(SystemModule::getGlobalKey(SystemModule::ZORBA_MODULE_PATH)); |
635 | return ItemSequence_t(new VectorItemSequence(lRes)); |
636 | } |
637 | |
638 | @@ -567,7 +650,7 @@ |
639 | arg0_iter->close(); |
640 | String envS = item.getStringValue(); |
641 | String lRes; |
642 | - if (envS == "zorba.module.path") { |
643 | + if (envS == SystemModule::getGlobalKey(SystemModule::ZORBA_MODULE_PATH).getStringValue().str()) { |
644 | std::vector<String> lModulePaths; |
645 | sctx->getFullModulePaths(lModulePaths); |
646 | if (lModulePaths.size() == 0) |
647 | @@ -587,9 +670,9 @@ |
648 | return ItemSequence_t(new EmptySequence()); |
649 | } |
650 | #ifdef LINUX |
651 | - } else if (envS == "linux.distributor") { |
652 | + } else if (envS == SystemModule::getGlobalKey(SystemModule::LINUX_DISTRIBUTOR).getStringValue().str()) { |
653 | lRes = getDistribution().first; |
654 | - } else if (envS == "linux.distributor.version") { |
655 | + } else if (envS == SystemModule::getGlobalKey(SystemModule::LINUX_DISTRIBUTOR_VERSION).getStringValue().str()) { |
656 | lRes = getDistribution().second; |
657 | #endif |
658 | } else { |
659 | |
660 | === modified file 'src/system.xq.src/system.h' |
661 | --- src/com/zorba-xquery/www/modules/system.xq.src/system.h 2011-08-05 02:22:28 +0000 |
662 | +++ src/system.xq.src/system.h 2013-08-08 20:52:48 +0000 |
663 | @@ -25,19 +25,54 @@ |
664 | |
665 | namespace zorba { namespace system { |
666 | class SystemModule : public ExternalModule { |
667 | + protected: |
668 | + static zorba::Item globalOSName; |
669 | + static zorba::Item globalOSNodeName; |
670 | + static zorba::Item globalOSVersionMajor; |
671 | + static zorba::Item globalOSVersionMinor; |
672 | + static zorba::Item globalOSVersionBuild; |
673 | + static zorba::Item globalOSVersionRelease; |
674 | + static zorba::Item globalOSVersionVersion; |
675 | + static zorba::Item globalOSVersion; |
676 | + static zorba::Item globalOSArch; |
677 | + static zorba::Item globalOSis64; |
678 | + static zorba::Item globalHWLogicalCPU; |
679 | + static zorba::Item globalHWPhysicalCPU; |
680 | + static zorba::Item globalHWLogicalPerPhysicalCPU; |
681 | + static zorba::Item globalHWPhysicalMemory; |
682 | + static zorba::Item globalHWVirtualMemory; |
683 | + static zorba::Item globalHWManufacturer; |
684 | + static zorba::Item globalLinuxDistributor; |
685 | + static zorba::Item globalLinuxDistributorVersion; |
686 | + static zorba::Item globalUserName; |
687 | + static zorba::Item globalZorbaModulePath; |
688 | + static zorba::Item globalZorbaVersion; |
689 | + static zorba::Item globalZorbaVersionMajor; |
690 | + static zorba::Item globalZorbaVersionMinor; |
691 | + static zorba::Item globalZorbaVersionPatch; |
692 | private: |
693 | ExternalFunction* thePropertyFunction; |
694 | ExternalFunction* thePropertiesFunction; |
695 | const static String SYSTEM_MODULE_NAMESPACE; |
696 | public: |
697 | + enum GLOBAL_KEY { OS_NAME, OS_NODE_NAME, OS_VER_MAJOR, OS_VER_MINOR, |
698 | + OS_VER_BUILD, OS_VER_RELEASE, OS_VER_VERSION, OS_VER, |
699 | + OS_ARCH, OS_IS64, HARDWARE_lOGICAL_CPU, HARDWARE_PHYSICAL_CPU, |
700 | + HARDWARE_LOGICAL_PER_PHYSICAL_CPU, HARDWARE_PHYSICAL_MEMORY, |
701 | + HARDWARE_VIRTUAL_MEMORY, HARDWARE_MANUFACTURER, LINUX_DISTRIBUTOR, |
702 | + LINUX_DISTRIBUTOR_VERSION, USER_NAME, ZORBA_MODULE_PATH, ZORBA_VER, ZORBA_VER_MAJOR, |
703 | + ZORBA_VER_MINOR, ZORBA_VER_PATCH }; |
704 | + |
705 | SystemModule(); |
706 | virtual ~SystemModule(); |
707 | - public: |
708 | + |
709 | virtual String getURI() const { return SYSTEM_MODULE_NAMESPACE; } |
710 | |
711 | virtual ExternalFunction* getExternalFunction(const String& localName); |
712 | |
713 | virtual void destroy(); |
714 | + |
715 | + static zorba::Item& getGlobalKey(enum GLOBAL_KEY g); |
716 | }; |
717 | |
718 | class SystemFunction { |
Looks very good, nice work. However, the moduleDocumentation test doesn't pass, so there must be a typo somewhere in the XQDoc. Also, I suspect once you fix that, it will complain that all those public variable declarations need to have XQDoc; you'll probably need to restore the doc from the old version. (%private variables, like errors codes, don't need XQDoc, but public ones do as far as I know.)