Merge lp:~zorba-coders/zorba/system_doc into lp:zorba/process-module
- system_doc
- Merge into process-module
Status: | Superseded |
---|---|
Proposed branch: | lp:~zorba-coders/zorba/system_doc |
Merge into: | lp:zorba/process-module |
Diff against target: |
1066 lines (+1014/-0) (has conflicts) 9 files modified
CMakeLists.txt (+29/-0) src/CMakeLists.txt (+19/-0) src/com/CMakeLists.txt (+14/-0) src/com/zorba-xquery/CMakeLists.txt (+14/-0) src/com/zorba-xquery/www/CMakeLists.txt (+14/-0) src/com/zorba-xquery/www/modules/CMakeLists.txt (+14/-0) src/com/zorba-xquery/www/modules/system.xq (+211/-0) src/com/zorba-xquery/www/modules/system.xq.src/system.cpp (+606/-0) src/com/zorba-xquery/www/modules/system.xq.src/system.h (+93/-0) Conflict adding file CMakeLists.txt. Moved existing file to CMakeLists.txt.moved. Conflict adding file src. Moved existing file to src.moved. |
To merge this branch: | bzr merge lp:~zorba-coders/zorba/system_doc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Needs Information | ||
William Candillon | Pending | ||
Review via email: mp+126739@code.launchpad.net |
This proposal has been superseded by a proposal from 2012-09-27.
Commit message
Minor documentation improvement
Description of the change
Minor documentation improvement
Matthias Brantner (matthias-brantner) wrote : | # |
Unmerged revisions
- 35. By William Candillon
-
Minor documentation improvement.
- 34. By Dennis Knochenwefel
-
fixed crash with signal 8: SIGFPE (division by zero). bug #1026594. Approved: Dennis Knochenwefel, Chris Hillery
- 33. By Matthias Brantner
-
fix for bug #978722 (change annotation prefix from "ann" to "an") Approved: William Candillon, Matthias Brantner
- 32. By Chris Hillery
-
Converted all files to correct native EOLs.
- 31. By cezarfx
-
Fix bug when USER is not available as a environment var.
Fix if uname return with error. - 30. By mbrantner
-
fixed typo in the system module
- 29. By mbrantner
-
documentation for system module (provided by William)
- 28. By spungi
-
- improved the speed of "make xqdoc" such that we can add xqdoc as a test
- fixed SF bug #3375604 "Built target cxxdocs" hangs
- make xqdoc does not search the filesystem, instead creates the documentation *only* for the modules that are compiled in the Zorba version used (based on the ZorbaManifest.xml in the build folder)
- implemented the 2 issues that Dana asked for in the email from @coders "core and non-core Zorba modules"
- fixed the link crawler issues in XQDoc reported by Daniel (except the link to xqdoc.org) - 27. By mbrantner
-
added missing license headers
- 26. By spungi
-
XQuery version changes:
- Added XQuery version declarations for all the modules (part of the Zorba core or not).
- fixed the test "moduleDocumentation" that checks if all the modules are well documented:
- this test used to check only the Zorba core modules: now it also checks the external modules.
- added a new rule that makes sure all modules have a XQuery version declarations.XQDoc changes:
- documented some XQDoc variables, params and return values that were missing.
- added support for XQuery version and Encoding in the Zorba XQDoc.
- added a new part called "XQuery version and Encoding for this module:" as the last lines in the module description of the XQDoc documentation.
Preview Diff
1 | === added file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
3 | +++ CMakeLists.txt 2012-09-27 16:59:25 +0000 | |||
4 | @@ -0,0 +1,29 @@ | |||
5 | 1 | # Copyright 2006-2010 The FLWOR Foundation. | ||
6 | 2 | # | ||
7 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
8 | 4 | # you may not use this file except in compliance with the License. | ||
9 | 5 | # You may obtain a copy of the License at | ||
10 | 6 | # | ||
11 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
12 | 8 | # | ||
13 | 9 | # Unless required by applicable law or agreed to in writing, software | ||
14 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
15 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
16 | 12 | # See the License for the specific language governing permissions and | ||
17 | 13 | # limitations under the License. | ||
18 | 14 | |||
19 | 15 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) | ||
20 | 16 | |||
21 | 17 | PROJECT (zorba_system_module) | ||
22 | 18 | ENABLE_TESTING () | ||
23 | 19 | INCLUDE (CTest) | ||
24 | 20 | |||
25 | 21 | LIST (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake_modules") | ||
26 | 22 | |||
27 | 23 | FIND_PACKAGE (Zorba REQUIRED HINTS "${ZORBA_BUILD_DIR}") | ||
28 | 24 | INCLUDE ("${Zorba_USE_FILE}") | ||
29 | 25 | |||
30 | 26 | ADD_TEST_DIRECTORY("${PROJECT_SOURCE_DIR}/test") | ||
31 | 27 | ADD_SUBDIRECTORY("src") | ||
32 | 28 | |||
33 | 29 | DONE_DECLARING_ZORBA_URIS() | ||
34 | 0 | 30 | ||
35 | === renamed file 'CMakeLists.txt' => 'CMakeLists.txt.moved' | |||
36 | === added directory 'src' | |||
37 | === renamed directory 'src' => 'src.moved' | |||
38 | === added file 'src/CMakeLists.txt' | |||
39 | --- src/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
40 | +++ src/CMakeLists.txt 2012-09-27 16:59:25 +0000 | |||
41 | @@ -0,0 +1,19 @@ | |||
42 | 1 | # Copyright 2006-2008 The FLWOR Foundation. | ||
43 | 2 | # | ||
44 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
45 | 4 | # you may not use this file except in compliance with the License. | ||
46 | 5 | # You may obtain a copy of the License at | ||
47 | 6 | # | ||
48 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
49 | 8 | # | ||
50 | 9 | # Unless required by applicable law or agreed to in writing, software | ||
51 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
52 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
53 | 12 | # See the License for the specific language governing permissions and | ||
54 | 13 | # limitations under the License. | ||
55 | 14 | |||
56 | 15 | # all external module libraries are generated in the directory | ||
57 | 16 | # of the corresponding .xq file | ||
58 | 17 | MESSAGE(STATUS "Add com") | ||
59 | 18 | ADD_SUBDIRECTORY(com) | ||
60 | 19 | MESSAGE(STATUS "End modules") | ||
61 | 0 | 20 | ||
62 | === added directory 'src/com' | |||
63 | === added file 'src/com/CMakeLists.txt' | |||
64 | --- src/com/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
65 | +++ src/com/CMakeLists.txt 2012-09-27 16:59:25 +0000 | |||
66 | @@ -0,0 +1,14 @@ | |||
67 | 1 | # Copyright 2006-2008 The FLWOR Foundation. | ||
68 | 2 | # | ||
69 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
70 | 4 | # you may not use this file except in compliance with the License. | ||
71 | 5 | # You may obtain a copy of the License at | ||
72 | 6 | # | ||
73 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
74 | 8 | # | ||
75 | 9 | # Unless required by applicable law or agreed to in writing, software | ||
76 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
77 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
78 | 12 | # See the License for the specific language governing permissions and | ||
79 | 13 | # limitations under the License. | ||
80 | 14 | ADD_SUBDIRECTORY(zorba-xquery) | ||
81 | 0 | 15 | ||
82 | === added directory 'src/com/zorba-xquery' | |||
83 | === added file 'src/com/zorba-xquery/CMakeLists.txt' | |||
84 | --- src/com/zorba-xquery/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
85 | +++ src/com/zorba-xquery/CMakeLists.txt 2012-09-27 16:59:25 +0000 | |||
86 | @@ -0,0 +1,14 @@ | |||
87 | 1 | # Copyright 2006-2008 The FLWOR Foundation. | ||
88 | 2 | # | ||
89 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
90 | 4 | # you may not use this file except in compliance with the License. | ||
91 | 5 | # You may obtain a copy of the License at | ||
92 | 6 | # | ||
93 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
94 | 8 | # | ||
95 | 9 | # Unless required by applicable law or agreed to in writing, software | ||
96 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
97 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
98 | 12 | # See the License for the specific language governing permissions and | ||
99 | 13 | # limitations under the License. | ||
100 | 14 | ADD_SUBDIRECTORY(www) | ||
101 | 0 | 15 | ||
102 | === added directory 'src/com/zorba-xquery/www' | |||
103 | === added file 'src/com/zorba-xquery/www/CMakeLists.txt' | |||
104 | --- src/com/zorba-xquery/www/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
105 | +++ src/com/zorba-xquery/www/CMakeLists.txt 2012-09-27 16:59:25 +0000 | |||
106 | @@ -0,0 +1,14 @@ | |||
107 | 1 | # Copyright 2006-2008 The FLWOR Foundation. | ||
108 | 2 | # | ||
109 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
110 | 4 | # you may not use this file except in compliance with the License. | ||
111 | 5 | # You may obtain a copy of the License at | ||
112 | 6 | # | ||
113 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
114 | 8 | # | ||
115 | 9 | # Unless required by applicable law or agreed to in writing, software | ||
116 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
117 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
118 | 12 | # See the License for the specific language governing permissions and | ||
119 | 13 | # limitations under the License. | ||
120 | 14 | ADD_SUBDIRECTORY(modules) | ||
121 | 0 | 15 | ||
122 | === added directory 'src/com/zorba-xquery/www/modules' | |||
123 | === added file 'src/com/zorba-xquery/www/modules/CMakeLists.txt' | |||
124 | --- src/com/zorba-xquery/www/modules/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
125 | +++ src/com/zorba-xquery/www/modules/CMakeLists.txt 2012-09-27 16:59:25 +0000 | |||
126 | @@ -0,0 +1,14 @@ | |||
127 | 1 | # Copyright 2006-2008 The FLWOR Foundation. | ||
128 | 2 | # | ||
129 | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
130 | 4 | # you may not use this file except in compliance with the License. | ||
131 | 5 | # You may obtain a copy of the License at | ||
132 | 6 | # | ||
133 | 7 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
134 | 8 | # | ||
135 | 9 | # Unless required by applicable law or agreed to in writing, software | ||
136 | 10 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
137 | 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
138 | 12 | # See the License for the specific language governing permissions and | ||
139 | 13 | # limitations under the License. | ||
140 | 14 | DECLARE_ZORBA_MODULE (URI "http://www.zorba-xquery.com/modules/system" VERSION 1.0 FILE "system.xq") | ||
141 | 0 | 15 | ||
142 | === added file 'src/com/zorba-xquery/www/modules/system.xq' | |||
143 | --- src/com/zorba-xquery/www/modules/system.xq 1970-01-01 00:00:00 +0000 | |||
144 | +++ src/com/zorba-xquery/www/modules/system.xq 2012-09-27 16:59:25 +0000 | |||
145 | @@ -0,0 +1,211 @@ | |||
146 | 1 | xquery version "3.0"; | ||
147 | 2 | |||
148 | 3 | (: | ||
149 | 4 | : Copyright 2006-2009 The FLWOR Foundation. | ||
150 | 5 | : | ||
151 | 6 | : Licensed under the Apache License, Version 2.0 (the "License"); | ||
152 | 7 | : you may not use this file except in compliance with the License. | ||
153 | 8 | : You may obtain a copy of the License at | ||
154 | 9 | : | ||
155 | 10 | : http://www.apache.org/licenses/LICENSE-2.0 | ||
156 | 11 | : | ||
157 | 12 | : Unless required by applicable law or agreed to in writing, software | ||
158 | 13 | : distributed under the License is distributed on an "AS IS" BASIS, | ||
159 | 14 | : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
160 | 15 | : See the License for the specific language governing permissions and | ||
161 | 16 | : limitations under the License. | ||
162 | 17 | :) | ||
163 | 18 | (:~ | ||
164 | 19 | : The system module allows developers to access system properties. | ||
165 | 20 | : Part of these system properties are environment variables, | ||
166 | 21 | : local variable to the process running Zorba, and properties defined by Zorba. | ||
167 | 22 | : <br /> | ||
168 | 23 | : To avoid conflicts between environment variables and properties defined by Zorba, | ||
169 | 24 | : all environment variables are prefixed with <i>env.</i>. | ||
170 | 25 | : <br /> | ||
171 | 26 | : For instance, the following query: <br /> | ||
172 | 27 | : <pre class="ace-static"> | ||
173 | 28 | : import module namespace system = "http://www.zorba-xquery.com/modules/system"; | ||
174 | 29 | : | ||
175 | 30 | : for $prop in system:properties() | ||
176 | 31 | : return concat($prop, ": ", system:property($prop), " | ||
177 | 32 | : ") | ||
178 | 33 | : </pre> | ||
179 | 34 | : <br /> | ||
180 | 35 | : Will output: | ||
181 | 36 | : <pre class="ace-static"> | ||
182 | 37 | : env.TERM_PROGRAM: Apple_Terminal | ||
183 | 38 | : ... | ||
184 | 39 | : </pre> | ||
185 | 40 | : In this example, it is important to notice that the environnement variable PATH | ||
186 | 41 | : with the key env.PATH. | ||
187 | 42 | : | ||
188 | 43 | : @author Markus Pilman | ||
189 | 44 | : @project Zorba/IO/System | ||
190 | 45 | :) | ||
191 | 46 | module namespace system = 'http://www.zorba-xquery.com/modules/system'; | ||
192 | 47 | |||
193 | 48 | declare namespace an = "http://www.zorba-xquery.com/annotations"; | ||
194 | 49 | |||
195 | 50 | declare namespace ver = "http://www.zorba-xquery.com/options/versioning"; | ||
196 | 51 | declare option ver:module-version "1.0"; | ||
197 | 52 | |||
198 | 53 | (:~ | ||
199 | 54 | : The name of the operating system (os.name). | ||
200 | 55 | :) | ||
201 | 56 | declare variable $system:os-name as xs:string := "os.name"; | ||
202 | 57 | |||
203 | 58 | (:~ | ||
204 | 59 | : The name of the computer the process is running on (os.node.name). | ||
205 | 60 | :) | ||
206 | 61 | declare variable $system:os-node-name as xs:string := "os.node.name"; | ||
207 | 62 | |||
208 | 63 | (:~ | ||
209 | 64 | : The major version number of the Windows installation or | ||
210 | 65 | : an empty string if the process does not run on a Windows installation | ||
211 | 66 | : (os.version.major). | ||
212 | 67 | : <b>Works on Windows only.</b> | ||
213 | 68 | :) | ||
214 | 69 | declare variable $system:os-version-major as xs:string := "os.version.major"; | ||
215 | 70 | |||
216 | 71 | (:~ | ||
217 | 72 | : The minor version number of the Windows installation or | ||
218 | 73 | : an empty string if the process does not run on a Windows installation | ||
219 | 74 | : (os.version.minor). | ||
220 | 75 | : <b>Works on Windows only.</b> | ||
221 | 76 | :) | ||
222 | 77 | declare variable $system:os-version-minor as xs:string := "os.version.minor"; | ||
223 | 78 | |||
224 | 79 | (:~ | ||
225 | 80 | : The build number of the Windows installation or | ||
226 | 81 | : an empty string if the process does not run on a Windows installation | ||
227 | 82 | : (os.version.build). | ||
228 | 83 | : <b>Works on Windows only.</b> | ||
229 | 84 | :) | ||
230 | 85 | declare variable $system:os-version-build as xs:string := "os.version.build"; | ||
231 | 86 | |||
232 | 87 | (:~ | ||
233 | 88 | : The release of this UNIX installation or | ||
234 | 89 | : an empty string if the process does not run on a UNIX/Linux installation | ||
235 | 90 | : (os.version.release). | ||
236 | 91 | : <b>Works on UNIX based operating systems only.</b> | ||
237 | 92 | :) | ||
238 | 93 | declare variable $system:os-version-release as xs:string := "os.version.release"; | ||
239 | 94 | (:~ | ||
240 | 95 | : The version of this UNIX installation or | ||
241 | 96 | : an empty string if the process does not run on a UNIX/Linux installation | ||
242 | 97 | : (os.version.version). | ||
243 | 98 | : <b>Works on UNIX based operating systems only.</b> | ||
244 | 99 | :) | ||
245 | 100 | declare variable $system:os-version-version as xs:string := "os.version.version"; | ||
246 | 101 | |||
247 | 102 | (:~ | ||
248 | 103 | : The version of the Operating System. | ||
249 | 104 | :) | ||
250 | 105 | declare variable $system:os-version as xs:string := "os.version"; | ||
251 | 106 | |||
252 | 107 | (:~ | ||
253 | 108 | : The name of the processor architecture (os.arch). | ||
254 | 109 | : For example x86 or x86_64. | ||
255 | 110 | :) | ||
256 | 111 | declare variable $system:os-arch as xs:string := "os.arch"; | ||
257 | 112 | |||
258 | 113 | (:~ | ||
259 | 114 | : True if system architecture is 64bits (os.is64). | ||
260 | 115 | :) | ||
261 | 116 | declare variable $system:os-is64 as xs:string := "os.is64"; | ||
262 | 117 | |||
263 | 118 | (:~ | ||
264 | 119 | : Number of logical processors in the system (hardware.logical.cpu). | ||
265 | 120 | : This information is not available under Mac OS X. | ||
266 | 121 | :) | ||
267 | 122 | declare variable $system:hardware-logical-cpu as xs:string := "hardware.logical.cpu"; | ||
268 | 123 | |||
269 | 124 | (:~ | ||
270 | 125 | : Number of physical processors in the system (hardware.logical.cpu). | ||
271 | 126 | :) | ||
272 | 127 | declare variable $system:hardware-physical-cpu as xs:string := "hardware.physical.cpu"; | ||
273 | 128 | |||
274 | 129 | (:~ | ||
275 | 130 | : number of logical per physical processors in the system (hardware.logical.per.physical.cpu). | ||
276 | 131 | : This information is not available under Mac OS X. | ||
277 | 132 | :) | ||
278 | 133 | declare variable $system:hardware-logical-per-physical-cpu as xs:string := "hardware.logical.per.physical.cpu"; | ||
279 | 134 | |||
280 | 135 | (:~ | ||
281 | 136 | : Physical memory available (hardware.physical.memory). | ||
282 | 137 | :) | ||
283 | 138 | declare variable $system:hardware-physical-memory as xs:string := "hardware.physical.memory"; | ||
284 | 139 | (:~ | ||
285 | 140 | : Virtual memory available (hardware.virtual.memory). | ||
286 | 141 | :) | ||
287 | 142 | declare variable $system:hardware-virtual-memory as xs:string := "hardware.virtual.memory"; | ||
288 | 143 | (:~ | ||
289 | 144 | : Gets the hardware manufacturer (hardware.manufacturer). | ||
290 | 145 | :) | ||
291 | 146 | declare variable $system:hardware-manufacturer as xs:string := "hardware.manufacturer"; | ||
292 | 147 | |||
293 | 148 | (:~ | ||
294 | 149 | : The Linux distribution, Zorba is running on (linux.distributor). | ||
295 | 150 | : <b>Works on UNIX based operating systems only.</b> | ||
296 | 151 | :) | ||
297 | 152 | declare variable $system:linux-distributor as xs:string := "linux.distributor"; | ||
298 | 153 | |||
299 | 154 | (:~ | ||
300 | 155 | : The version of the Linux distribution, Zorba is running on (linux.distributor.version). | ||
301 | 156 | : <b>Works on UNIX based operating systems only.</b> | ||
302 | 157 | :) | ||
303 | 158 | declare variable $system:linux-distributor-version as xs:string := "linux.distributor.version"; | ||
304 | 159 | |||
305 | 160 | (:~ | ||
306 | 161 | : The username, with which this process was started (user.name). | ||
307 | 162 | : On Unix, this variable is only available if the USER environment | ||
308 | 163 | : variable is set (e.g. it might not be available in a cronjob). | ||
309 | 164 | :) | ||
310 | 165 | declare variable $system:user-name as xs:string := "user.name"; | ||
311 | 166 | |||
312 | 167 | (:~ | ||
313 | 168 | : The Zorba module path, that is the paths in which Zorba looks | ||
314 | 169 | : for modules (zorba.module.path). | ||
315 | 170 | :) | ||
316 | 171 | declare variable $system:zorba-module-path as xs:string := "zorba.module.path"; | ||
317 | 172 | |||
318 | 173 | (:~ | ||
319 | 174 | : Zorba version in the format Major.Minor.Patch (zorba.version). | ||
320 | 175 | :) | ||
321 | 176 | declare variable $system:zorba-version as xs:string := "zorba.version"; | ||
322 | 177 | |||
323 | 178 | (:~ | ||
324 | 179 | : Zorba major version (zorba.version.major). | ||
325 | 180 | :) | ||
326 | 181 | declare variable $system:zorba-version-major as xs:string := "zorba.version.major"; | ||
327 | 182 | |||
328 | 183 | (:~ | ||
329 | 184 | : Zorba minor version (zorba.version.minor). | ||
330 | 185 | :) | ||
331 | 186 | declare variable $system:zorba-version-minor as xs:string := "zorba.version.minor"; | ||
332 | 187 | |||
333 | 188 | (:~ | ||
334 | 189 | : Zorba patch version (zorba.version.patch). | ||
335 | 190 | :) | ||
336 | 191 | declare variable $system:zorba-version-patch as xs:string := "zorba.version.patch"; | ||
337 | 192 | |||
338 | 193 | (:~ | ||
339 | 194 | : Gets the system property indicated by the specified key. | ||
340 | 195 | : | ||
341 | 196 | : @param $key The name of the system property. | ||
342 | 197 | : @return The string value of the system property, or an empty sequence if there is no property with that key. | ||
343 | 198 | :) | ||
344 | 199 | declare %an:nondeterministic function system:property($key as xs:string) as xs:string? external; | ||
345 | 200 | |||
346 | 201 | (:~ | ||
347 | 202 | : This function retrieves the names of the current system properties. | ||
348 | 203 | : This list includes environment variables, local variable to the process running Zorba, and properties defined by Zorba. | ||
349 | 204 | : <br /> | ||
350 | 205 | : To avoid conflicts between environment variables and properties defined by Zorba, | ||
351 | 206 | : all environment variables are prefixed with <i>env.</i>. | ||
352 | 207 | : | ||
353 | 208 | : @return List of all system properties. | ||
354 | 209 | :) | ||
355 | 210 | declare %an:nondeterministic function system:properties() as xs:string* external; | ||
356 | 211 | |||
357 | 0 | 212 | ||
358 | === added directory 'src/com/zorba-xquery/www/modules/system.xq.src' | |||
359 | === added file 'src/com/zorba-xquery/www/modules/system.xq.src/system.cpp' | |||
360 | --- src/com/zorba-xquery/www/modules/system.xq.src/system.cpp 1970-01-01 00:00:00 +0000 | |||
361 | +++ src/com/zorba-xquery/www/modules/system.xq.src/system.cpp 2012-09-27 16:59:25 +0000 | |||
362 | @@ -0,0 +1,606 @@ | |||
363 | 1 | /* | ||
364 | 2 | * Copyright 2006-2008 The FLWOR Foundation. | ||
365 | 3 | * | ||
366 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
367 | 5 | * you may not use this file except in compliance with the License. | ||
368 | 6 | * You may obtain a copy of the License at | ||
369 | 7 | * | ||
370 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
371 | 9 | * | ||
372 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
373 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
374 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
375 | 13 | * See the License for the specific language governing permissions and | ||
376 | 14 | * limitations under the License. | ||
377 | 15 | */ | ||
378 | 16 | #include <cstdlib> | ||
379 | 17 | #include <cstdio> | ||
380 | 18 | #include <sstream> | ||
381 | 19 | |||
382 | 20 | #ifdef WIN32 | ||
383 | 21 | # include <Windows.h> | ||
384 | 22 | # include <malloc.h> | ||
385 | 23 | # include <stdio.h> | ||
386 | 24 | # include <tchar.h> | ||
387 | 25 | # include <winreg.h> | ||
388 | 26 | #else | ||
389 | 27 | #include <sys/utsname.h> | ||
390 | 28 | # ifndef __APPLE__ | ||
391 | 29 | # include <sys/sysinfo.h> | ||
392 | 30 | # else | ||
393 | 31 | # include <sys/param.h> | ||
394 | 32 | # include <sys/sysctl.h> | ||
395 | 33 | # endif | ||
396 | 34 | #endif | ||
397 | 35 | |||
398 | 36 | #include <zorba/zorba_string.h> | ||
399 | 37 | #include <zorba/singleton_item_sequence.h> | ||
400 | 38 | #include <zorba/vector_item_sequence.h> | ||
401 | 39 | #include <zorba/empty_sequence.h> | ||
402 | 40 | #include <zorba/item_factory.h> | ||
403 | 41 | |||
404 | 42 | |||
405 | 43 | #ifdef LINUX | ||
406 | 44 | #include <iostream> | ||
407 | 45 | #include <string> | ||
408 | 46 | #include <fstream> | ||
409 | 47 | #include <unistd.h> | ||
410 | 48 | extern char** environ; | ||
411 | 49 | #elif defined APPLE | ||
412 | 50 | # include <crt_externs.h> | ||
413 | 51 | #endif | ||
414 | 52 | |||
415 | 53 | #include "system.h" | ||
416 | 54 | |||
417 | 55 | |||
418 | 56 | namespace zorba { namespace system { | ||
419 | 57 | |||
420 | 58 | const String SystemModule::SYSTEM_MODULE_NAMESPACE = "http://www.zorba-xquery.com/modules/system"; | ||
421 | 59 | |||
422 | 60 | #ifdef WIN32 | ||
423 | 61 | typedef BOOL (WINAPI *LPFN_GLPI)( | ||
424 | 62 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION, | ||
425 | 63 | PDWORD); | ||
426 | 64 | |||
427 | 65 | // Helper function to count set bits in the processor mask. | ||
428 | 66 | DWORD CountSetBits(ULONG_PTR bitMask) | ||
429 | 67 | { | ||
430 | 68 | DWORD LSHIFT = sizeof(ULONG_PTR)*8 - 1; | ||
431 | 69 | DWORD bitSetCount = 0; | ||
432 | 70 | ULONG_PTR bitTest = (ULONG_PTR)1 << LSHIFT; | ||
433 | 71 | DWORD i; | ||
434 | 72 | for (i = 0; i <= LSHIFT; ++i) | ||
435 | 73 | { | ||
436 | 74 | bitSetCount += ((bitMask & bitTest)?1:0); | ||
437 | 75 | bitTest/=2; | ||
438 | 76 | } | ||
439 | 77 | |||
440 | 78 | return bitSetCount; | ||
441 | 79 | } | ||
442 | 80 | |||
443 | 81 | DWORD numaNodeCount = 0; | ||
444 | 82 | DWORD processorPackageCount = 0; | ||
445 | 83 | DWORD logicalProcessorCount = 0; | ||
446 | 84 | DWORD processorCoreCount = 0; | ||
447 | 85 | DWORD processorL1CacheCount = 0; | ||
448 | 86 | DWORD processorL2CacheCount = 0; | ||
449 | 87 | DWORD processorL3CacheCount = 0; | ||
450 | 88 | static void countProcessors() { | ||
451 | 89 | LPFN_GLPI glpi; | ||
452 | 90 | BOOL done = FALSE; | ||
453 | 91 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL; | ||
454 | 92 | PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = NULL; | ||
455 | 93 | DWORD returnLength = 0; | ||
456 | 94 | DWORD byteOffset = 0; | ||
457 | 95 | PCACHE_DESCRIPTOR Cache; | ||
458 | 96 | |||
459 | 97 | glpi = (LPFN_GLPI) GetProcAddress(GetModuleHandle(TEXT("kernel32")), "GetLogicalProcessorInformation"); | ||
460 | 98 | if (NULL == glpi) { | ||
461 | 99 | // GetLogicalProcessorInformation is not supported. | ||
462 | 100 | return; | ||
463 | 101 | } | ||
464 | 102 | |||
465 | 103 | while (!done) | ||
466 | 104 | { | ||
467 | 105 | DWORD rc = glpi(buffer, &returnLength); | ||
468 | 106 | if (FALSE == rc) | ||
469 | 107 | { | ||
470 | 108 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) | ||
471 | 109 | { | ||
472 | 110 | if (buffer) | ||
473 | 111 | free(buffer); | ||
474 | 112 | buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(returnLength); | ||
475 | 113 | if (NULL == buffer) | ||
476 | 114 | { | ||
477 | 115 | // Error: Allocation failure | ||
478 | 116 | return; | ||
479 | 117 | } | ||
480 | 118 | } else { | ||
481 | 119 | // Error %d, GetLastError() | ||
482 | 120 | return; | ||
483 | 121 | } | ||
484 | 122 | } else { | ||
485 | 123 | done = TRUE; | ||
486 | 124 | } | ||
487 | 125 | } | ||
488 | 126 | ptr = buffer; | ||
489 | 127 | while (byteOffset + sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION) <= returnLength) | ||
490 | 128 | { | ||
491 | 129 | switch (ptr->Relationship) | ||
492 | 130 | { | ||
493 | 131 | case RelationNumaNode: | ||
494 | 132 | // Non-NUMA systems report a single record of this type. | ||
495 | 133 | numaNodeCount++; | ||
496 | 134 | break; | ||
497 | 135 | case RelationProcessorCore: | ||
498 | 136 | processorCoreCount++; | ||
499 | 137 | // A hyperthreaded core supplies more than one logical processor. | ||
500 | 138 | logicalProcessorCount += CountSetBits(ptr->ProcessorMask); | ||
501 | 139 | break; | ||
502 | 140 | |||
503 | 141 | case RelationCache: | ||
504 | 142 | // Cache data is in ptr->Cache, one CACHE_DESCRIPTOR structure for each cache. | ||
505 | 143 | Cache = &ptr->Cache; | ||
506 | 144 | if (Cache->Level == 1) | ||
507 | 145 | { | ||
508 | 146 | processorL1CacheCount++; | ||
509 | 147 | } | ||
510 | 148 | else if (Cache->Level == 2) | ||
511 | 149 | { | ||
512 | 150 | processorL2CacheCount++; | ||
513 | 151 | } | ||
514 | 152 | else if (Cache->Level == 3) | ||
515 | 153 | { | ||
516 | 154 | processorL3CacheCount++; | ||
517 | 155 | } | ||
518 | 156 | break; | ||
519 | 157 | case RelationProcessorPackage: | ||
520 | 158 | // Logical processors share a physical package. | ||
521 | 159 | processorPackageCount++; | ||
522 | 160 | break; | ||
523 | 161 | default: | ||
524 | 162 | // Error: Unsupported LOGICAL_PROCESSOR_RELATIONSHIP value. | ||
525 | 163 | break; | ||
526 | 164 | } | ||
527 | 165 | byteOffset += sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION); | ||
528 | 166 | ptr++; | ||
529 | 167 | } | ||
530 | 168 | free(buffer); | ||
531 | 169 | return; | ||
532 | 170 | } | ||
533 | 171 | |||
534 | 172 | #endif | ||
535 | 173 | |||
536 | 174 | #ifdef LINUX | ||
537 | 175 | static void trim(std::string& str, char delim) | ||
538 | 176 | { | ||
539 | 177 | std::string::size_type pos = str.find_last_not_of(delim); | ||
540 | 178 | if(pos != std::string::npos) { | ||
541 | 179 | str.erase(pos + 1); | ||
542 | 180 | pos = str.find_first_not_of(delim); | ||
543 | 181 | if(pos != std::string::npos) str.erase(0, pos); | ||
544 | 182 | } | ||
545 | 183 | else str.erase(str.begin(), str.end()); | ||
546 | 184 | } | ||
547 | 185 | |||
548 | 186 | |||
549 | 187 | int logical=0; | ||
550 | 188 | int cores=0; | ||
551 | 189 | int physical=0; | ||
552 | 190 | |||
553 | 191 | |||
554 | 192 | static void countProcessors() { | ||
555 | 193 | logical=0; | ||
556 | 194 | cores=1; // per default: single core processor | ||
557 | 195 | physical=0; | ||
558 | 196 | |||
559 | 197 | std::ifstream in("/proc/cpuinfo"); | ||
560 | 198 | if(in) { | ||
561 | 199 | std::string name; | ||
562 | 200 | std::string value; | ||
563 | 201 | |||
564 | 202 | while(in) { | ||
565 | 203 | getline(in, name, ':'); | ||
566 | 204 | trim (name, ' '); | ||
567 | 205 | trim (name, '\t'); | ||
568 | 206 | trim (name, '\n'); | ||
569 | 207 | getline(in, value); | ||
570 | 208 | trim (value, ' '); | ||
571 | 209 | trim (value, '\t'); | ||
572 | 210 | if (name == "processor") { | ||
573 | 211 | logical++; | ||
574 | 212 | } | ||
575 | 213 | |||
576 | 214 | if (name == "cpu cores") { | ||
577 | 215 | cores = atoi(value.c_str()); | ||
578 | 216 | } | ||
579 | 217 | } | ||
580 | 218 | physical = logical/cores; | ||
581 | 219 | in.close(); | ||
582 | 220 | } | ||
583 | 221 | } | ||
584 | 222 | |||
585 | 223 | |||
586 | 224 | |||
587 | 225 | static std::pair<std::string, std::string> getDistribution() { | ||
588 | 226 | std::pair<std::string, std::string> lRes; | ||
589 | 227 | FILE *pipe; | ||
590 | 228 | const char* command = "lsb_release -r -i"; | ||
591 | 229 | pipe = (FILE*) popen(command, "r"); | ||
592 | 230 | |||
593 | 231 | char line[1024]; | ||
594 | 232 | while (fgets(line, sizeof(line), pipe)) { | ||
595 | 233 | std::stringstream s(line); | ||
596 | 234 | std::string name, value; | ||
597 | 235 | getline(s, name, ':'); | ||
598 | 236 | trim(name, ' '); | ||
599 | 237 | trim(name, '\t'); | ||
600 | 238 | getline(s, value, ':'); | ||
601 | 239 | trim(value, ' '); | ||
602 | 240 | trim(value, '\t'); | ||
603 | 241 | trim(value, '\n'); | ||
604 | 242 | if (name == "Distributor ID") { | ||
605 | 243 | lRes.first = value; | ||
606 | 244 | } else { | ||
607 | 245 | lRes.second = value; | ||
608 | 246 | } | ||
609 | 247 | } | ||
610 | 248 | return lRes; | ||
611 | 249 | } | ||
612 | 250 | #endif | ||
613 | 251 | |||
614 | 252 | SystemModule::SystemModule() | ||
615 | 253 | : thePropertyFunction(0), thePropertiesFunction(0) | ||
616 | 254 | { | ||
617 | 255 | } | ||
618 | 256 | |||
619 | 257 | ExternalFunction* SystemModule::getExternalFunction(const String& localName) { | ||
620 | 258 | if (localName == "properties") { | ||
621 | 259 | if (!thePropertiesFunction) | ||
622 | 260 | thePropertiesFunction = new PropertiesFunction(this); | ||
623 | 261 | return thePropertiesFunction; | ||
624 | 262 | } else if (localName == "property") { | ||
625 | 263 | if (!thePropertyFunction) | ||
626 | 264 | thePropertyFunction = new PropertyFunction(this); | ||
627 | 265 | return thePropertyFunction; | ||
628 | 266 | } | ||
629 | 267 | return 0; | ||
630 | 268 | } | ||
631 | 269 | |||
632 | 270 | void SystemModule::destroy() { | ||
633 | 271 | delete this; | ||
634 | 272 | } | ||
635 | 273 | |||
636 | 274 | SystemModule::~SystemModule() { | ||
637 | 275 | delete thePropertyFunction; | ||
638 | 276 | delete thePropertiesFunction; | ||
639 | 277 | } | ||
640 | 278 | |||
641 | 279 | |||
642 | 280 | SystemFunction::SystemFunction(const ExternalModule* aModule) | ||
643 | 281 | : theModule(aModule), theFactory(Zorba::getInstance(0)->getItemFactory()) | ||
644 | 282 | { | ||
645 | 283 | #ifdef WIN32 | ||
646 | 284 | |||
647 | 285 | { | ||
648 | 286 | DWORD nodeNameLength = MAX_COMPUTERNAME_LENGTH + 1; | ||
649 | 287 | TCHAR nodeName[MAX_COMPUTERNAME_LENGTH + 1]; | ||
650 | 288 | char nodeNameC[MAX_COMPUTERNAME_LENGTH + 1]; | ||
651 | 289 | GetComputerName(nodeName, &nodeNameLength); | ||
652 | 290 | for (DWORD i = 0; i < nodeNameLength; ++i) { | ||
653 | 291 | nodeNameC[i] = static_cast<char>(nodeName[i]); | ||
654 | 292 | } | ||
655 | 293 | nodeNameC[nodeNameLength] = NULL; // Terminate string | ||
656 | 294 | theProperties.insert(std::make_pair("os.node.name", nodeNameC)); | ||
657 | 295 | } | ||
658 | 296 | |||
659 | 297 | { | ||
660 | 298 | DWORD dwVersion = 0; | ||
661 | 299 | DWORD dwMajorVersion = 0; | ||
662 | 300 | DWORD dwMinorVersion = 0; | ||
663 | 301 | DWORD dwBuild = 0; | ||
664 | 302 | |||
665 | 303 | dwVersion = GetVersion(); | ||
666 | 304 | |||
667 | 305 | // Get the Windows version. | ||
668 | 306 | dwMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); | ||
669 | 307 | dwMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); | ||
670 | 308 | |||
671 | 309 | // Get the build number. | ||
672 | 310 | if (dwVersion < 0x80000000) | ||
673 | 311 | dwBuild = (DWORD)(HIWORD(dwVersion)); | ||
674 | 312 | |||
675 | 313 | std::string major; | ||
676 | 314 | std::string minor; | ||
677 | 315 | std::string build; | ||
678 | 316 | { | ||
679 | 317 | std::stringstream sMajor; | ||
680 | 318 | sMajor << dwMajorVersion; | ||
681 | 319 | std::stringstream sMinor; | ||
682 | 320 | sMinor << dwMinorVersion; | ||
683 | 321 | std::stringstream sBuild; | ||
684 | 322 | sBuild << dwBuild; | ||
685 | 323 | |||
686 | 324 | major = sMajor.str(); | ||
687 | 325 | minor = sMinor.str(); | ||
688 | 326 | build = sBuild.str(); | ||
689 | 327 | } | ||
690 | 328 | theProperties.insert(std::make_pair("os.version.major", major)); | ||
691 | 329 | theProperties.insert(std::make_pair("os.version.minor", minor)); | ||
692 | 330 | theProperties.insert(std::make_pair("os.version.build", build)); | ||
693 | 331 | theProperties.insert(std::make_pair("os.version", major + "." + minor + "." + build)); | ||
694 | 332 | // http://msdn.microsoft.com/en-us/library/ms724832(v=VS.85).aspx | ||
695 | 333 | std::string operativeSystem; | ||
696 | 334 | theProperties.insert(std::make_pair("os.name", "Windows")); | ||
697 | 335 | { | ||
698 | 336 | countProcessors(); | ||
699 | 337 | std::stringstream logicalProcessors; | ||
700 | 338 | logicalProcessors << processorPackageCount; | ||
701 | 339 | std::stringstream physicalProcessors; | ||
702 | 340 | physicalProcessors << logicalProcessorCount; | ||
703 | 341 | std::stringstream logicalPerPhysicalProcessors; | ||
704 | 342 | logicalPerPhysicalProcessors << (logicalProcessorCount / processorPackageCount ); | ||
705 | 343 | theProperties.insert(std::make_pair("hardware.physical.cpu", logicalProcessors.str() )); | ||
706 | 344 | theProperties.insert(std::make_pair("hardware.logical.cpu", physicalProcessors.str() )); | ||
707 | 345 | theProperties.insert(std::make_pair("hardware.logical.per.physical.cpu", logicalPerPhysicalProcessors.str() )); | ||
708 | 346 | } | ||
709 | 347 | { | ||
710 | 348 | MEMORYSTATUSEX statex; | ||
711 | 349 | statex.dwLength = sizeof (statex); | ||
712 | 350 | GlobalMemoryStatusEx (&statex); | ||
713 | 351 | std::stringstream virtualMemory; | ||
714 | 352 | virtualMemory << statex.ullTotalVirtual; | ||
715 | 353 | std::stringstream physicalMemory; | ||
716 | 354 | physicalMemory << statex.ullTotalPhys; | ||
717 | 355 | theProperties.insert(std::make_pair("hardware.virtual.memory", virtualMemory.str() )); | ||
718 | 356 | theProperties.insert(std::make_pair("hardware.physical.memory", physicalMemory.str() )); | ||
719 | 357 | } | ||
720 | 358 | |||
721 | 359 | } | ||
722 | 360 | { | ||
723 | 361 | DWORD userNameLength = 1023; | ||
724 | 362 | TCHAR userName[1024]; | ||
725 | 363 | char userNameC[1024]; | ||
726 | 364 | GetUserName(userName, &userNameLength); | ||
727 | 365 | for (DWORD i = 0; i < userNameLength; ++i) { | ||
728 | 366 | userNameC[i] = static_cast<char>(userName[i]); | ||
729 | 367 | } | ||
730 | 368 | theProperties.insert(std::make_pair("user.name", userNameC)); | ||
731 | 369 | } | ||
732 | 370 | { | ||
733 | 371 | SYSTEM_INFO info; | ||
734 | 372 | GetSystemInfo(&info); | ||
735 | 373 | if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { | ||
736 | 374 | theProperties.insert(std::make_pair("os.arch", "x86_64")); | ||
737 | 375 | theProperties.insert(std::make_pair("os.is64", "true")); | ||
738 | 376 | } else if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64) { | ||
739 | 377 | theProperties.insert(std::make_pair("os.arch", "ia64")); | ||
740 | 378 | theProperties.insert(std::make_pair("os.is64", "true")); | ||
741 | 379 | } else if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) { | ||
742 | 380 | theProperties.insert(std::make_pair("os.arch", "i386")); | ||
743 | 381 | theProperties.insert(std::make_pair("os.is64", "false")); | ||
744 | 382 | } | ||
745 | 383 | } | ||
746 | 384 | |||
747 | 385 | { | ||
748 | 386 | HKEY keyHandle; | ||
749 | 387 | TCHAR value [1024]; | ||
750 | 388 | char valueC [1024]; | ||
751 | 389 | DWORD size = 0; | ||
752 | 390 | DWORD Type; | ||
753 | 391 | if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", 0, KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS) | ||
754 | 392 | { | ||
755 | 393 | RegQueryValueEx( keyHandle, L"SystemManufacturer", NULL, &Type, (LPBYTE)value, &size); | ||
756 | 394 | for (DWORD i = 0; i < size; ++i) { | ||
757 | 395 | valueC[i] = static_cast<char>(value[i]); | ||
758 | 396 | } | ||
759 | 397 | if (size > 0) | ||
760 | 398 | theProperties.insert(std::make_pair("hardware.manufacturer", valueC)); | ||
761 | 399 | } | ||
762 | 400 | RegCloseKey(keyHandle); | ||
763 | 401 | } | ||
764 | 402 | |||
765 | 403 | |||
766 | 404 | #else | ||
767 | 405 | struct utsname osname; | ||
768 | 406 | if (uname(&osname) == 0) | ||
769 | 407 | { | ||
770 | 408 | theProperties.insert(std::make_pair("os.name", osname.sysname)); | ||
771 | 409 | theProperties.insert(std::make_pair("os.node.name", osname.nodename)); | ||
772 | 410 | theProperties.insert(std::make_pair("os.version.release", osname.release)); | ||
773 | 411 | theProperties.insert(std::make_pair("os.version.version", osname.version)); | ||
774 | 412 | theProperties.insert(std::make_pair("os.version", osname.release)); | ||
775 | 413 | theProperties.insert(std::make_pair("os.arch", osname.machine)); | ||
776 | 414 | } | ||
777 | 415 | char* lUser = getenv("USER"); | ||
778 | 416 | if (lUser) | ||
779 | 417 | { | ||
780 | 418 | theProperties.insert(std::make_pair("user.name", lUser)); | ||
781 | 419 | } | ||
782 | 420 | theProperties.insert(std::make_pair("os.is64", "false")); | ||
783 | 421 | { | ||
784 | 422 | #ifdef __APPLE__ | ||
785 | 423 | int mib[2]; | ||
786 | 424 | size_t len = 4; | ||
787 | 425 | uint32_t res = 0; | ||
788 | 426 | |||
789 | 427 | mib[0] = CTL_HW; | ||
790 | 428 | mib[1] = HW_NCPU; | ||
791 | 429 | sysctl(mib, 2, &res, &len, NULL, NULL); | ||
792 | 430 | std::stringstream lStream; | ||
793 | 431 | lStream << res; | ||
794 | 432 | theProperties.insert(std::make_pair("hardware.physical.cpu", lStream.str())); | ||
795 | 433 | #else | ||
796 | 434 | countProcessors(); | ||
797 | 435 | std::stringstream logicalProcessor; | ||
798 | 436 | std::stringstream physicalProcessor; | ||
799 | 437 | std::stringstream logicalPerPhysicalProcessors; | ||
800 | 438 | logicalProcessor << logical; | ||
801 | 439 | physicalProcessor << physical; | ||
802 | 440 | logicalPerPhysicalProcessors << cores; | ||
803 | 441 | theProperties.insert(std::make_pair("hardware.logical.per.physical.cpu", logicalPerPhysicalProcessors.str() )); | ||
804 | 442 | theProperties.insert(std::make_pair("hardware.physical.cpu", physicalProcessor.str() )); | ||
805 | 443 | theProperties.insert(std::make_pair("hardware.logical.cpu", logicalProcessor.str() )); | ||
806 | 444 | #endif | ||
807 | 445 | } | ||
808 | 446 | { | ||
809 | 447 | # ifdef LINUX | ||
810 | 448 | struct sysinfo sys_info; | ||
811 | 449 | if(sysinfo(&sys_info) == 0) { | ||
812 | 450 | std::stringstream memory; | ||
813 | 451 | memory << sys_info.totalram; | ||
814 | 452 | std::stringstream swap; | ||
815 | 453 | swap << sys_info.totalswap; | ||
816 | 454 | theProperties.insert(std::make_pair("hardware.virtual.memory", swap.str() )); | ||
817 | 455 | theProperties.insert(std::make_pair("hardware.physical.memory", memory.str() )); | ||
818 | 456 | } | ||
819 | 457 | # elif defined __APPLE__ | ||
820 | 458 | int mib[2]; | ||
821 | 459 | size_t len = 8; | ||
822 | 460 | uint64_t res = 0; | ||
823 | 461 | |||
824 | 462 | mib[0] = CTL_HW; | ||
825 | 463 | mib[1] = HW_MEMSIZE; | ||
826 | 464 | sysctl(mib, 2, &res, &len, NULL, NULL); | ||
827 | 465 | std::stringstream lStream; | ||
828 | 466 | lStream << res; | ||
829 | 467 | theProperties.insert(std::make_pair("hardware.physical.memory", lStream.str())); | ||
830 | 468 | # endif | ||
831 | 469 | } | ||
832 | 470 | |||
833 | 471 | #endif | ||
834 | 472 | #ifdef LINUX | ||
835 | 473 | theProperties.insert(std::make_pair("linux.distributor", "")); | ||
836 | 474 | theProperties.insert(std::make_pair("linux.distributor.version", "")); | ||
837 | 475 | #endif | ||
838 | 476 | theProperties.insert(std::make_pair("zorba.version", Zorba::version().getVersion())); | ||
839 | 477 | theProperties.insert(std::make_pair("zorba.version.major", intToString(Zorba::version().getMajorVersion()))); | ||
840 | 478 | theProperties.insert(std::make_pair("zorba.version.minor", intToString(Zorba::version().getMinorVersion()))); | ||
841 | 479 | theProperties.insert(std::make_pair("zorba.version.patch", intToString(Zorba::version().getPatchVersion()))); | ||
842 | 480 | } | ||
843 | 481 | |||
844 | 482 | String SystemFunction::intToString(int v) { | ||
845 | 483 | std::stringstream ss; | ||
846 | 484 | ss << v; | ||
847 | 485 | return ss.str(); | ||
848 | 486 | } | ||
849 | 487 | |||
850 | 488 | bool SystemFunction::getEnv(const String& name, String& value) const | ||
851 | 489 | { | ||
852 | 490 | char* v = getenv(name.c_str()); | ||
853 | 491 | if (v == NULL) return false; | ||
854 | 492 | value = v; | ||
855 | 493 | return true; | ||
856 | 494 | } | ||
857 | 495 | |||
858 | 496 | void SystemFunction::getEnvNames(std::vector<Item>& names) const | ||
859 | 497 | { | ||
860 | 498 | #ifdef WIN32 | ||
861 | 499 | // put in the environment variables | ||
862 | 500 | TCHAR *l_EnvStr; | ||
863 | 501 | l_EnvStr = GetEnvironmentStrings(); | ||
864 | 502 | |||
865 | 503 | LPTSTR l_str = l_EnvStr; | ||
866 | 504 | |||
867 | 505 | int count = 0; | ||
868 | 506 | while (true) | ||
869 | 507 | { | ||
870 | 508 | if (*l_str == 0) break; | ||
871 | 509 | while (*l_str != 0) l_str++; | ||
872 | 510 | l_str++; | ||
873 | 511 | count++; | ||
874 | 512 | } | ||
875 | 513 | |||
876 | 514 | for (int i = 0; i < count; i++) | ||
877 | 515 | { | ||
878 | 516 | char lStr[1024]; | ||
879 | 517 | memset(lStr, 0, 1024); | ||
880 | 518 | for (int i =0; i<1023 && l_EnvStr[i]; ++i) { | ||
881 | 519 | lStr[i] = (char) l_EnvStr[i]; | ||
882 | 520 | } | ||
883 | 521 | std::string e(lStr); | ||
884 | 522 | std::string name("env."); | ||
885 | 523 | name += e.substr(0, e.find('=')); | ||
886 | 524 | String value = e.substr(e.find('=') + 1); | ||
887 | 525 | if (name != "env.") | ||
888 | 526 | names.push_back(theFactory->createString(name)); | ||
889 | 527 | while(*l_EnvStr != '\0') | ||
890 | 528 | l_EnvStr++; | ||
891 | 529 | l_EnvStr++; | ||
892 | 530 | } | ||
893 | 531 | //FreeEnvironmentStrings(l_EnvStr); | ||
894 | 532 | #else | ||
895 | 533 | # ifdef APPLE | ||
896 | 534 | char** environ = *_NSGetEnviron(); | ||
897 | 535 | # endif // APPLE | ||
898 | 536 | for (int i = 0; environ[i] != NULL; ++i) { | ||
899 | 537 | std::string e(environ[i]); | ||
900 | 538 | String name("env."); | ||
901 | 539 | name += e.substr(0, e.find('=')); | ||
902 | 540 | names.push_back(theFactory->createString(name)); | ||
903 | 541 | } | ||
904 | 542 | #endif | ||
905 | 543 | } | ||
906 | 544 | |||
907 | 545 | ItemSequence_t PropertiesFunction::evaluate( | ||
908 | 546 | const ExternalFunction::Arguments_t& args) const { | ||
909 | 547 | std::vector<Item> lRes; | ||
910 | 548 | getEnvNames(lRes); | ||
911 | 549 | for (std::map<String, String>::const_iterator i = theProperties.begin(); | ||
912 | 550 | i != theProperties.end(); ++i) { | ||
913 | 551 | Item lItem = theFactory->createString(i->first.c_str()); | ||
914 | 552 | lRes.push_back(lItem); | ||
915 | 553 | } | ||
916 | 554 | // insert the zorba module path | ||
917 | 555 | lRes.push_back(theFactory->createString("zorba.module.path")); | ||
918 | 556 | return ItemSequence_t(new VectorItemSequence(lRes)); | ||
919 | 557 | } | ||
920 | 558 | |||
921 | 559 | ItemSequence_t PropertyFunction::evaluate( | ||
922 | 560 | const ExternalFunction::Arguments_t& args, | ||
923 | 561 | const StaticContext* sctx, | ||
924 | 562 | const DynamicContext* dctx) const { | ||
925 | 563 | Item item; | ||
926 | 564 | Iterator_t arg0_iter = args[0]->getIterator(); | ||
927 | 565 | arg0_iter->open(); | ||
928 | 566 | arg0_iter->next(item); | ||
929 | 567 | arg0_iter->close(); | ||
930 | 568 | String envS = item.getStringValue(); | ||
931 | 569 | String lRes; | ||
932 | 570 | if (envS == "zorba.module.path") { | ||
933 | 571 | std::vector<String> lModulePaths; | ||
934 | 572 | sctx->getFullModulePaths(lModulePaths); | ||
935 | 573 | if (lModulePaths.size() == 0) | ||
936 | 574 | return ItemSequence_t(new SingletonItemSequence(theFactory->createString(""))); | ||
937 | 575 | lRes = lModulePaths[0]; | ||
938 | 576 | for (std::vector<String>::iterator i = lModulePaths.begin() + 1; i != lModulePaths.end(); ++i) { | ||
939 | 577 | #ifdef WIN32 | ||
940 | 578 | lRes += ";"; | ||
941 | 579 | #else | ||
942 | 580 | lRes += ":"; | ||
943 | 581 | #endif | ||
944 | 582 | lRes += *i; | ||
945 | 583 | } | ||
946 | 584 | } else if (envS.substr(0,4) == "env.") { | ||
947 | 585 | //Sleep(5000); | ||
948 | 586 | if (!getEnv(envS.substr(4), lRes)) { | ||
949 | 587 | return ItemSequence_t(new EmptySequence()); | ||
950 | 588 | } | ||
951 | 589 | #ifdef LINUX | ||
952 | 590 | } else if (envS == "linux.distributor") { | ||
953 | 591 | lRes = getDistribution().first; | ||
954 | 592 | } else if (envS == "linux.distributor.version") { | ||
955 | 593 | lRes = getDistribution().second; | ||
956 | 594 | #endif | ||
957 | 595 | } else { | ||
958 | 596 | std::map<String, String>::const_iterator i; | ||
959 | 597 | if ((i = theProperties.find(envS.c_str())) != theProperties.end()) { | ||
960 | 598 | lRes = i->second; | ||
961 | 599 | } else { | ||
962 | 600 | return ItemSequence_t(new EmptySequence()); | ||
963 | 601 | } | ||
964 | 602 | } | ||
965 | 603 | return ItemSequence_t(new SingletonItemSequence(theFactory->createString(lRes))); | ||
966 | 604 | } | ||
967 | 605 | }} // namespace zorba, system | ||
968 | 606 | |||
969 | 0 | 607 | ||
970 | === added file 'src/com/zorba-xquery/www/modules/system.xq.src/system.h' | |||
971 | --- src/com/zorba-xquery/www/modules/system.xq.src/system.h 1970-01-01 00:00:00 +0000 | |||
972 | +++ src/com/zorba-xquery/www/modules/system.xq.src/system.h 2012-09-27 16:59:25 +0000 | |||
973 | @@ -0,0 +1,93 @@ | |||
974 | 1 | /* | ||
975 | 2 | * Copyright 2006-2008 The FLWOR Foundation. | ||
976 | 3 | * | ||
977 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
978 | 5 | * you may not use this file except in compliance with the License. | ||
979 | 6 | * You may obtain a copy of the License at | ||
980 | 7 | * | ||
981 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
982 | 9 | * | ||
983 | 10 | * Unless required by applicable law or agreed to in writing, software | ||
984 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
985 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
986 | 13 | * See the License for the specific language governing permissions and | ||
987 | 14 | * limitations under the License. | ||
988 | 15 | */ | ||
989 | 16 | |||
990 | 17 | #ifndef __COM_ZORBA_WWW_MODULES_SYSTEM_H__ | ||
991 | 18 | #define __COM_ZORBA_WWW_MODULES_SYSTEM_H__ | ||
992 | 19 | #include <vector> | ||
993 | 20 | #include <map> | ||
994 | 21 | |||
995 | 22 | #include <zorba/zorba.h> | ||
996 | 23 | #include <zorba/external_module.h> | ||
997 | 24 | #include <zorba/function.h> | ||
998 | 25 | |||
999 | 26 | namespace zorba { namespace system { | ||
1000 | 27 | class SystemModule : public ExternalModule { | ||
1001 | 28 | private: | ||
1002 | 29 | ExternalFunction* thePropertyFunction; | ||
1003 | 30 | ExternalFunction* thePropertiesFunction; | ||
1004 | 31 | const static String SYSTEM_MODULE_NAMESPACE; | ||
1005 | 32 | public: | ||
1006 | 33 | SystemModule(); | ||
1007 | 34 | virtual ~SystemModule(); | ||
1008 | 35 | public: | ||
1009 | 36 | virtual String getURI() const { return SYSTEM_MODULE_NAMESPACE; } | ||
1010 | 37 | |||
1011 | 38 | virtual ExternalFunction* getExternalFunction(const String& localName); | ||
1012 | 39 | |||
1013 | 40 | virtual void destroy(); | ||
1014 | 41 | }; | ||
1015 | 42 | |||
1016 | 43 | class SystemFunction { | ||
1017 | 44 | protected: | ||
1018 | 45 | const ExternalModule* theModule; | ||
1019 | 46 | ItemFactory* theFactory; | ||
1020 | 47 | std::map<String, String> theProperties; | ||
1021 | 48 | public: | ||
1022 | 49 | SystemFunction(const ExternalModule* aModule); | ||
1023 | 50 | protected: | ||
1024 | 51 | String getURI() const { return theModule->getURI(); } | ||
1025 | 52 | bool getEnv(const String& name, String& value) const; | ||
1026 | 53 | void getEnvNames(std::vector<Item>& names) const; | ||
1027 | 54 | String intToString(int v); | ||
1028 | 55 | }; | ||
1029 | 56 | |||
1030 | 57 | class PropertiesFunction : public NonContextualExternalFunction, public SystemFunction { | ||
1031 | 58 | public: | ||
1032 | 59 | PropertiesFunction(const ExternalModule* mod) : SystemFunction(mod) {} | ||
1033 | 60 | |||
1034 | 61 | virtual String getLocalName() const { return "properties"; } | ||
1035 | 62 | |||
1036 | 63 | virtual ItemSequence_t | ||
1037 | 64 | evaluate(const ExternalFunction::Arguments_t& args) const; | ||
1038 | 65 | virtual String getURI() const { return SystemFunction::getURI(); } | ||
1039 | 66 | }; | ||
1040 | 67 | |||
1041 | 68 | class PropertyFunction : public ContextualExternalFunction, public SystemFunction { | ||
1042 | 69 | public: | ||
1043 | 70 | PropertyFunction(const ExternalModule* mod) : SystemFunction(mod) {} | ||
1044 | 71 | |||
1045 | 72 | virtual String getLocalName() const { return "property"; } | ||
1046 | 73 | |||
1047 | 74 | virtual ItemSequence_t | ||
1048 | 75 | evaluate(const ExternalFunction::Arguments_t& args, | ||
1049 | 76 | const StaticContext* sctx, | ||
1050 | 77 | const DynamicContext* dctx) const; | ||
1051 | 78 | virtual String getURI() const { return SystemFunction::getURI(); } | ||
1052 | 79 | }; | ||
1053 | 80 | |||
1054 | 81 | } } // namespace zorba, namespace system | ||
1055 | 82 | |||
1056 | 83 | #ifdef WIN32 | ||
1057 | 84 | # define DLL_EXPORT __declspec(dllexport) | ||
1058 | 85 | #else | ||
1059 | 86 | # define DLL_EXPORT __attribute__ ((visibility("default"))) | ||
1060 | 87 | #endif | ||
1061 | 88 | |||
1062 | 89 | extern "C" DLL_EXPORT zorba::ExternalModule* createModule() { | ||
1063 | 90 | return new zorba::system::SystemModule(); | ||
1064 | 91 | } | ||
1065 | 92 | |||
1066 | 93 | #endif // __COM_ZORBA_WWW_MODULES_SYSTEM_H__ |
You were trying to merge the system into the process module.
Is that on purpose?