|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 /* |
|
18 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
19 * contributor license agreements. See the NOTICE file distributed with |
|
20 * this work for additional information regarding copyright ownership. |
|
21 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
22 * (the "License"); you may not use this file except in compliance with |
|
23 * the License. You may obtain a copy of the License at |
|
24 * |
|
25 * http://www.apache.org/licenses/LICENSE-2.0 |
|
26 * |
|
27 * Unless required by applicable law or agreed to in writing, software |
|
28 * distributed under the License is distributed on an "AS IS" BASIS, |
|
29 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
30 * See the License for the specific language governing permissions and |
|
31 * limitations under the License. |
|
32 */ |
|
33 |
|
34 /* |
|
35 * $Id: PlatformUtils.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
36 */ |
|
37 |
|
38 |
|
39 #if !defined(PLATFORMUTILS_HPP) |
|
40 #define PLATFORMUTILS_HPP |
|
41 |
|
42 #include <xercesc/util/XMLException.hpp> |
|
43 #include <xercesc/util/PanicHandler.hpp> |
|
44 |
|
45 XERCES_CPP_NAMESPACE_BEGIN |
|
46 |
|
47 class XMLMsgLoader; |
|
48 class XMLNetAccessor; |
|
49 class XMLTransService; |
|
50 class MemoryManager; |
|
51 class XMLMutex; |
|
52 |
|
53 // |
|
54 // For internal use only |
|
55 // |
|
56 // This class provides a simple abstract API via which lazily evaluated |
|
57 // data can be cleaned up. |
|
58 // |
|
59 class XMLUTIL_EXPORT XMLDeleter |
|
60 { |
|
61 public : |
|
62 virtual ~XMLDeleter(); |
|
63 |
|
64 protected : |
|
65 XMLDeleter(); |
|
66 |
|
67 private : |
|
68 XMLDeleter(const XMLDeleter&); |
|
69 XMLDeleter& operator=(const XMLDeleter&); |
|
70 }; |
|
71 |
|
72 |
|
73 /** |
|
74 * Utilities that must be implemented in a platform-specific way. |
|
75 * |
|
76 * This class contains methods that must be implemented in a platform |
|
77 * specific manner. The actual implementations of these methods are |
|
78 * available in the per-platform files indide <code>src/util/Platforms |
|
79 * </code>. |
|
80 */ |
|
81 class XMLUTIL_EXPORT XMLPlatformUtils |
|
82 { |
|
83 public : |
|
84 |
|
85 /** @name Public Static Data */ |
|
86 //@{ |
|
87 |
|
88 /** The network accessor |
|
89 * |
|
90 * This is provided by the per-platform driver, so each platform can |
|
91 * choose what actual implementation it wants to use. The object must |
|
92 * be dynamically allocated. |
|
93 * |
|
94 * <i>Note that you may optionally, if your platform driver does not |
|
95 * install a network accessor, set it manually from your client code |
|
96 * after calling Initialize(). This works because this object is |
|
97 * not required during initialization, and only comes into play during |
|
98 * actual XML parsing.</i> |
|
99 */ |
|
100 static XMLNetAccessor* fgNetAccessor; |
|
101 |
|
102 /** The transcoding service. |
|
103 * |
|
104 * This is provided by the per platform driver, so each platform can |
|
105 * choose what implemenation it wants to use. When the platform |
|
106 * independent initialization code needs to get a transcoding service |
|
107 * object, it will call <code>makeTransService()</code> to ask the |
|
108 * per-platform code to create one. Only one transcoding service |
|
109 * object is reqeusted per-process, so it is shared and synchronized |
|
110 * among parser instances within that process. |
|
111 */ |
|
112 static XMLTransService* fgTransService; |
|
113 #ifdef OS390 |
|
114 static XMLTransService* fgTransService2; |
|
115 #endif |
|
116 |
|
117 /** The Panic Handler |
|
118 * |
|
119 * This is the application provided panic handler. |
|
120 */ |
|
121 static PanicHandler* fgUserPanicHandler; |
|
122 |
|
123 /** The Panic Handler |
|
124 * |
|
125 * This is the default panic handler. |
|
126 */ |
|
127 static PanicHandler* fgDefaultPanicHandler; |
|
128 |
|
129 /** The configurable memory manager |
|
130 * |
|
131 * This is the pluggable memory manager. If it is not provided by an |
|
132 * application, a default implementation is used. |
|
133 */ |
|
134 static MemoryManager* fgMemoryManager; |
|
135 |
|
136 /** The array-allocating memory manager |
|
137 * |
|
138 * This memory manager always allocates memory by calling the |
|
139 * global new[] operator. It may be used to allocate memory |
|
140 * where such memory needs to be deletable by calling delete []. |
|
141 * Since this allocator is always guaranteed to do the same thing |
|
142 * there is no reason, nor facility, to override it. |
|
143 */ |
|
144 static MemoryManager* fgArrayMemoryManager; |
|
145 |
|
146 static XMLMutex* fgAtomicMutex; |
|
147 |
|
148 //@} |
|
149 |
|
150 |
|
151 /** @name Initialization amd Panic methods */ |
|
152 //@{ |
|
153 |
|
154 /** Perform per-process parser initialization |
|
155 * |
|
156 * Initialization <b>must</b> be called first in any client code. |
|
157 * |
|
158 * The locale is set iff the Initialize() is invoked for the very first time, |
|
159 * to ensure that each and every message loaders, in the process space, share |
|
160 * the same locale. |
|
161 * |
|
162 * All subsequent invocations of Initialize(), with a different locale, have |
|
163 * no effect on the message loaders, either instantiated, or to be instantiated. |
|
164 * |
|
165 * To set to a different locale, client application needs to Terminate() (or |
|
166 * multiple Terminate() in the case where multiple Initialize() have been invoked |
|
167 * before), followed by Initialize(new_locale). |
|
168 * |
|
169 * The default locale is "en_US". |
|
170 * |
|
171 * nlsHome: user specified location where MsgLoader retrieves error message files. |
|
172 * the discussion above with regard to locale, applies to this nlsHome |
|
173 * as well. |
|
174 * |
|
175 * panicHandler: application's panic handler, application owns this handler. |
|
176 * Application shall make sure that the plugged panic handler persists |
|
177 * through the call to XMLPlatformUtils::terminate(). |
|
178 * |
|
179 * memoryManager: plugged-in memory manager which is owned by user |
|
180 * applications. Applications must make sure that the |
|
181 * plugged-in memory manager persist through the call to |
|
182 * XMLPlatformUtils::terminate() |
|
183 */ |
|
184 static void Initialize(const char* const locale = XMLUni::fgXercescDefaultLocale |
|
185 , const char* const nlsHome = 0 |
|
186 , PanicHandler* const panicHandler = 0 |
|
187 , MemoryManager* const memoryManager = 0 |
|
188 , bool toInitStatics = false); |
|
189 |
|
190 /** Perform per-process parser termination |
|
191 * |
|
192 * The termination call is currently optional, to aid those dynamically |
|
193 * loading the parser to clean up before exit, or to avoid spurious |
|
194 * reports from leak detectors. |
|
195 */ |
|
196 static void Terminate(); |
|
197 |
|
198 /** The panic mechanism. |
|
199 * |
|
200 * If, during initialization, we cannot even get far enough along |
|
201 * to get transcoding up or get message loading working, we call |
|
202 * this method.</p> |
|
203 * |
|
204 * Each platform can implement it however they want. This method will |
|
205 * delegate the panic handling to a user specified panic handler or |
|
206 * in the absence of it, the default panic handler. |
|
207 * |
|
208 * In case the default panic handler does not support a particular |
|
209 * platform, the platform specific panic hanlding shall be implemented |
|
210 * here </p>. |
|
211 * |
|
212 * @param reason The enumeration that defines the cause of the failure |
|
213 */ |
|
214 static void panic |
|
215 ( |
|
216 const PanicHandler::PanicReasons reason |
|
217 ); |
|
218 |
|
219 //@} |
|
220 |
|
221 /** @name File Methods */ |
|
222 //@{ |
|
223 |
|
224 /** Get the current file position |
|
225 * |
|
226 * This must be implemented by the per-platform driver, which should |
|
227 * use local file services to deterine the current position within |
|
228 * the passed file. |
|
229 * |
|
230 * Since the file API provided here only reads, if the host platform |
|
231 * supports separate read/write positions, only the read position is |
|
232 * of any interest, and hence should be the one returned. |
|
233 * |
|
234 * @param theFile The file handle |
|
235 * @param manager The MemoryManager to use to allocate objects |
|
236 */ |
|
237 static unsigned int curFilePos(FileHandle theFile |
|
238 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
239 |
|
240 /** Closes the file handle |
|
241 * |
|
242 * This must be implemented by the per-platform driver, which should |
|
243 * use local file services to close the passed file handle, and to |
|
244 * destroy the passed file handle and any allocated data or system |
|
245 * resources it contains. |
|
246 * |
|
247 * @param theFile The file handle to close |
|
248 * @param manager The MemoryManager to use to allocate objects |
|
249 */ |
|
250 static void closeFile(FileHandle theFile |
|
251 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
252 |
|
253 /** Returns the file size |
|
254 * |
|
255 * This must be implemented by the per-platform driver, which should |
|
256 * use local file services to determine the current size of the file |
|
257 * represented by the passed handle. |
|
258 * |
|
259 * @param theFile The file handle whose size you want |
|
260 * @param manager The MemoryManager to use to allocate objects |
|
261 * @return Returns the size of the file in bytes |
|
262 */ |
|
263 static unsigned int fileSize(FileHandle theFile |
|
264 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
265 |
|
266 /** Opens the file |
|
267 * |
|
268 * This must be implemented by the per-platform driver, which should |
|
269 * use local file services to open passed file. If it fails, a |
|
270 * null handle pointer should be returned. |
|
271 * |
|
272 * @param fileName The string containing the name of the file |
|
273 * @param manager The MemoryManager to use to allocate objects |
|
274 * @return The file handle of the opened file |
|
275 */ |
|
276 static FileHandle openFile(const char* const fileName |
|
277 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
278 |
|
279 /** Opens a named file |
|
280 * |
|
281 * This must be implemented by the per-platform driver, which should |
|
282 * use local file services to open the passed file. If it fails, a |
|
283 * null handle pointer should be returned. |
|
284 * |
|
285 * @param fileName The string containing the name of the file |
|
286 * @param manager The MemoryManager to use to allocate objects |
|
287 * @return The file handle of the opened file |
|
288 */ |
|
289 static FileHandle openFile(const XMLCh* const fileName |
|
290 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
291 |
|
292 /** Open a named file to write |
|
293 * |
|
294 * This must be implemented by the per-platform driver, which should |
|
295 * use local file services to open passed file. If it fails, a |
|
296 * null handle pointer should be returned. |
|
297 * |
|
298 * @param fileName The string containing the name of the file |
|
299 * @param manager The MemoryManager to use to allocate objects |
|
300 * @return The file handle of the opened file |
|
301 */ |
|
302 static FileHandle openFileToWrite(const char* const fileName |
|
303 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
304 |
|
305 /** Open a named file to write |
|
306 * |
|
307 * This must be implemented by the per-platform driver, which should |
|
308 * use local file services to open the passed file. If it fails, a |
|
309 * null handle pointer should be returned. |
|
310 * |
|
311 * @param fileName The string containing the name of the file |
|
312 * @param manager The MemoryManager to use to allocate objects |
|
313 * @return The file handle of the opened file |
|
314 */ |
|
315 static FileHandle openFileToWrite(const XMLCh* const fileName |
|
316 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
317 |
|
318 /** Opens the standard input as a file |
|
319 * |
|
320 * This must be implemented by the per-platform driver, which should |
|
321 * use local file services to open a handle to the standard input. |
|
322 * It should be a copy of the standard input handle, since it will |
|
323 * be closed later! |
|
324 * |
|
325 * @param manager The MemoryManager to use to allocate objects |
|
326 * @return The file handle of the standard input stream |
|
327 */ |
|
328 static FileHandle openStdInHandle(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
329 |
|
330 /** Reads the file buffer |
|
331 * |
|
332 * This must be implemented by the per-platform driver, which should |
|
333 * use local file services to read up to 'toRead' bytes of data from |
|
334 * the passed file, and return those bytes in the 'toFill' buffer. It |
|
335 * is not an error not to read the requested number of bytes. When the |
|
336 * end of file is reached, zero should be returned. |
|
337 * |
|
338 * @param theFile The file handle to be read from. |
|
339 * @param toRead The maximum number of byte to read from the current |
|
340 * position |
|
341 * @param toFill The byte buffer to fill |
|
342 * @param manager The MemoryManager to use to allocate objects |
|
343 * |
|
344 * @return Returns the number of bytes read from the stream or file |
|
345 */ |
|
346 static unsigned int readFileBuffer |
|
347 ( |
|
348 FileHandle theFile |
|
349 , const unsigned int toRead |
|
350 , XMLByte* const toFill |
|
351 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
352 ); |
|
353 |
|
354 /** Writes the buffer to the file |
|
355 * |
|
356 * This must be implemented by the per-platform driver, which should |
|
357 * use local file services to write up to 'toWrite' bytes of data to |
|
358 * the passed file. Unless exception raised by local file services, |
|
359 * 'toWrite' bytes of data is to be written to the passed file. |
|
360 * |
|
361 * @param theFile The file handle to be written to. |
|
362 * @param toWrite The maximum number of byte to write from the current |
|
363 * position |
|
364 * @param toFlush The byte buffer to flush |
|
365 * @param manager The MemoryManager to use to allocate objects |
|
366 * @return void |
|
367 */ |
|
368 static void writeBufferToFile |
|
369 ( |
|
370 FileHandle const theFile |
|
371 , long toWrite |
|
372 , const XMLByte* const toFlush |
|
373 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
374 ); |
|
375 |
|
376 /** Resets the file handle |
|
377 * |
|
378 * This must be implemented by the per-platform driver which will use |
|
379 * local file services to reset the file position to the start of the |
|
380 * the file. |
|
381 * |
|
382 * @param theFile The file handle that you want to reset |
|
383 * @param manager The MemoryManager to use to allocate objects |
|
384 */ |
|
385 static void resetFile(FileHandle theFile |
|
386 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
387 |
|
388 //@} |
|
389 |
|
390 |
|
391 /** @name File System Methods */ |
|
392 //@{ |
|
393 /** Gets the full path from a relative path |
|
394 * |
|
395 * This must be implemented by the per-platform driver. It should |
|
396 * complete a relative path using the 'current directory', or whatever |
|
397 * the local equivalent of a current directory is. If the passed |
|
398 * source path is actually fully qualified, then a straight copy of it |
|
399 * will be returned. |
|
400 * |
|
401 * @param srcPath The path of the file for which you want the full path |
|
402 * |
|
403 * @param manager Pointer to the memory manager to be used to |
|
404 * allocate objects. |
|
405 * |
|
406 * @return Returns the fully qualified path of the file name including |
|
407 * the file name. This is dyanmically allocated and must be |
|
408 * deleted by the caller when its no longer needed! The memory |
|
409 * returned will beallocated using the static memory manager, if |
|
410 * user do not supply a memory manager. Users then need to make |
|
411 * sure to use either the default or user specific memory manager |
|
412 * to deallocate the memory. |
|
413 */ |
|
414 static XMLCh* getFullPath |
|
415 ( |
|
416 const XMLCh* const srcPath |
|
417 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
418 ); |
|
419 |
|
420 /** Gets the current working directory |
|
421 * |
|
422 * This must be implemented by the per-platform driver. It returns |
|
423 * the current working directory is. |
|
424 * @param manager The MemoryManager to use to allocate objects |
|
425 * @return Returns the current working directory. |
|
426 * This is dyanmically allocated and must be deleted |
|
427 * by the caller when its no longer needed! The memory returned |
|
428 * will be allocated using the static memory manager, if users |
|
429 * do not supply a memory manager. Users then need to make sure |
|
430 * to use either the default or user specific memory manager to |
|
431 * deallocate the memory. |
|
432 */ |
|
433 static XMLCh* getCurrentDirectory |
|
434 ( |
|
435 MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
436 ); |
|
437 |
|
438 /** Check if a charater is a slash |
|
439 * |
|
440 * This must be implemented by the per-platform driver. |
|
441 * |
|
442 * @param c the character to be examined |
|
443 * |
|
444 * @return true if the character examined is a slash |
|
445 * false otherwise |
|
446 */ |
|
447 static inline bool isAnySlash(XMLCh c); |
|
448 |
|
449 /** Remove occurences of the pair of dot slash |
|
450 * |
|
451 * To remove the sequence, dot slash if it is part of the sequence, |
|
452 * slash dot slash. |
|
453 * |
|
454 * @param srcPath The path for which you want to remove the dot slash sequence. |
|
455 * @param manager The MemoryManager to use to allocate objects |
|
456 * @return |
|
457 */ |
|
458 static void removeDotSlash(XMLCh* const srcPath |
|
459 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
460 |
|
461 /** Remove occurences of the dot dot slash |
|
462 * |
|
463 * To remove the sequence, slash dot dot slash and its preceding path segment |
|
464 * if and only if the preceding path segment is not slash dot dot slash. |
|
465 * |
|
466 * @param srcPath The path for which you want to remove the slash dot |
|
467 * dot slash sequence and its preceding path segment. |
|
468 * @param manager The MemoryManager to use to allocate objects |
|
469 * @return |
|
470 */ |
|
471 static void removeDotDotSlash(XMLCh* const srcPath |
|
472 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
473 |
|
474 /** Determines if a path is relative or absolute |
|
475 * |
|
476 * This must be implemented by the per-platform driver, which should |
|
477 * determine whether the passed path is relative or not. The concept |
|
478 * of relative and absolute might be... well relative on different |
|
479 * platforms. But, as long as the determination is made consistently |
|
480 * and in coordination with the weavePaths() method, it should work |
|
481 * for any platform. |
|
482 * |
|
483 * @param toCheck The file name which you want to check |
|
484 * @param manager The MemoryManager to use to allocate objects |
|
485 * @return Returns true if the filename appears to be relative |
|
486 */ |
|
487 static bool isRelative(const XMLCh* const toCheck |
|
488 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
489 ); |
|
490 |
|
491 /** Utility to join two paths |
|
492 * |
|
493 * This must be implemented by the per-platform driver, and should |
|
494 * weave the relative path part together with the base part and return |
|
495 * a new path that represents this combination. |
|
496 * |
|
497 * If the relative part turns out to be fully qualified, it will be |
|
498 * returned as is. If it is not, then it will be woven onto the |
|
499 * passed base path, by removing one path component for each leading |
|
500 * "../" (or whatever is the equivalent in the local system) in the |
|
501 * relative path. |
|
502 * |
|
503 * @param basePath The string containing the base path |
|
504 * @param relativePath The string containing the relative path |
|
505 * @param manager The MemoryManager to use to allocate objects |
|
506 * @return Returns a string containing the 'woven' path. It should |
|
507 * be dynamically allocated and becomes the responsibility of the |
|
508 * caller to delete. |
|
509 */ |
|
510 static XMLCh* weavePaths |
|
511 ( |
|
512 const XMLCh* const basePath |
|
513 , const XMLCh* const relativePath |
|
514 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
515 ); |
|
516 //@} |
|
517 |
|
518 /** @name Timing Methods */ |
|
519 //@{ |
|
520 |
|
521 /** Gets the system time in milliseconds |
|
522 * |
|
523 * This must be implemented by the per-platform driver, which should |
|
524 * use local services to return the current value of a running |
|
525 * millisecond timer. Note that the value returned is only as accurate |
|
526 * as the millisecond time of the underyling host system. |
|
527 * |
|
528 * @return Returns the system time as an unsigned long |
|
529 */ |
|
530 static unsigned long getCurrentMillis(); |
|
531 //@} |
|
532 |
|
533 /** @name Mutex Methods */ |
|
534 //@{ |
|
535 |
|
536 /** Closes a mutex handle |
|
537 * |
|
538 * Each per-platform driver must implement this. Only it knows what |
|
539 * the actual content of the passed mutex handle is. |
|
540 * |
|
541 * @param mtxHandle The mutex handle that you want to close |
|
542 */ |
|
543 static void closeMutex(void* const mtxHandle); |
|
544 |
|
545 /** Locks a mutex handle |
|
546 * |
|
547 * Each per-platform driver must implement this. Only it knows what |
|
548 * the actual content of the passed mutex handle is. |
|
549 * |
|
550 * @param mtxHandle The mutex handle that you want to lock |
|
551 */ |
|
552 static void lockMutex(void* const mtxHandle); |
|
553 |
|
554 /** Make a new mutex |
|
555 * |
|
556 * Each per-platform driver must implement this. Only it knows what |
|
557 * the actual content of the passed mutex handle is. The returned |
|
558 * handle pointer will be eventually passed to closeMutex() which is |
|
559 * also implemented by the platform driver. |
|
560 * |
|
561 * @param manager The MemoryManager to use to allocate objects |
|
562 */ |
|
563 static void* makeMutex(MemoryManager* manager = XMLPlatformUtils::fgMemoryManager); |
|
564 |
|
565 /** Unlocks a mutex |
|
566 * |
|
567 * Each per-platform driver must implement this. Only it knows what |
|
568 * the actual content of the passed mutex handle is. |
|
569 * |
|
570 * Note that, since the underlying system synchronization services |
|
571 * are used, Xerces cannot guarantee that lock/unlock operations are |
|
572 * correctly enforced on a per-thread basis or that incorrect nesting |
|
573 * of lock/unlock operations will be caught. |
|
574 * |
|
575 * @param mtxHandle The mutex handle that you want to unlock |
|
576 */ |
|
577 static void unlockMutex(void* const mtxHandle); |
|
578 |
|
579 //@} |
|
580 |
|
581 |
|
582 /** @name External Message Support */ |
|
583 //@{ |
|
584 |
|
585 /** Loads the message set from among the available domains |
|
586 * |
|
587 * The returned object must be dynamically allocated and the caller |
|
588 * becomes responsible for cleaning it up. |
|
589 * |
|
590 * @param msgDomain The message domain which you want to load |
|
591 */ |
|
592 static XMLMsgLoader* loadMsgSet(const XMLCh* const msgDomain); |
|
593 |
|
594 //@} |
|
595 |
|
596 /** @name Miscellaneous synchronization methods */ |
|
597 //@{ |
|
598 |
|
599 /** Conditionally updates or returns a single word variable atomically |
|
600 * |
|
601 * This must be implemented by the per-platform driver. The |
|
602 * compareAndSwap subroutine performs an atomic operation which |
|
603 * compares the contents of a single word variable with a stored old |
|
604 * value. If the values are equal, a new value is stored in the single |
|
605 * word variable and TRUE is returned; otherwise, the old value is set |
|
606 * to the current value of the single word variable and FALSE is |
|
607 * returned. |
|
608 * |
|
609 * The compareAndSwap subroutine is useful when a word value must be |
|
610 * updated only if it has not been changed since it was last read. |
|
611 * |
|
612 * Note: The word containing the single word variable must be aligned |
|
613 * on a full word boundary. |
|
614 * |
|
615 * @param toFill Specifies the address of the single word variable |
|
616 * @param newValue Specifies the new value to be conditionally assigned |
|
617 * to the single word variable. |
|
618 * @param toCompare Specifies the address of the old value to be checked |
|
619 * against (and conditionally updated with) the value of the single word |
|
620 * variable. |
|
621 * |
|
622 * @return Returns the new value assigned to the single word variable |
|
623 */ |
|
624 static void* compareAndSwap |
|
625 ( |
|
626 void** toFill |
|
627 , const void* const newValue |
|
628 , const void* const toCompare |
|
629 ); |
|
630 |
|
631 //@} |
|
632 |
|
633 |
|
634 /** @name Atomic Increment and Decrement */ |
|
635 //@{ |
|
636 |
|
637 /** Increments a single word variable atomically. |
|
638 * |
|
639 * This must be implemented by the per-platform driver. The |
|
640 * atomicIncrement subroutine increments one word in a single atomic |
|
641 * operation. This operation is useful when a counter variable is shared |
|
642 * between several threads or processes. When updating such a counter |
|
643 * variable, it is important to make sure that the fetch, update, and |
|
644 * store operations occur atomically (are not interruptible). |
|
645 * |
|
646 * @param location Specifies the address of the word variable to be |
|
647 * incremented. |
|
648 * |
|
649 * @return The function return value is positive if the result of the |
|
650 * operation was positive. Zero if the result of the operation was zero. |
|
651 * Negative if the result of the operation was negative. Except for the |
|
652 * zero case, the value returned may differ from the actual result of |
|
653 * the operation - only the sign and zero/nonzero state is guaranteed |
|
654 * to be correct. |
|
655 */ |
|
656 static int atomicIncrement(int& location); |
|
657 |
|
658 /** Decrements a single word variable atomically. |
|
659 * |
|
660 * This must be implemented by the per-platform driver. The |
|
661 * atomicDecrement subroutine increments one word in a single atomic |
|
662 * operation. This operation is useful when a counter variable is shared |
|
663 * between several threads or processes. When updating such a counter |
|
664 * variable, it is important to make sure that the fetch, update, and |
|
665 * store operations occur atomically (are not interruptible). |
|
666 * |
|
667 * @param location Specifies the address of the word variable to be |
|
668 * decremented. |
|
669 * |
|
670 * @return The function return value is positive if the result of the |
|
671 * operation was positive. Zero if the result of the operation was zero. |
|
672 * Negative if the result of the operation was negative. Except for the |
|
673 * zero case, the value returned may differ from the actual result of the |
|
674 * operation - only the sign and zero/nonzero state is guaranteed to be |
|
675 * correct. |
|
676 */ |
|
677 static int atomicDecrement(int& location); |
|
678 |
|
679 //@} |
|
680 |
|
681 /** @name NEL Character Handling */ |
|
682 //@{ |
|
683 /** |
|
684 * This function enables the recognition of NEL(0x85) char and LSEP (0x2028) as newline chars |
|
685 * which is disabled by default. |
|
686 * It is only called once per process. Once it is set, any subsequent calls |
|
687 * will result in exception being thrown. |
|
688 * |
|
689 * Note: 1. Turning this option on will make the parser non compliant to XML 1.0. |
|
690 * 2. This option has no effect to document conforming to XML 1.1 compliant, |
|
691 * which always recognize these two chars (0x85 and 0x2028) as newline characters. |
|
692 * |
|
693 */ |
|
694 static void recognizeNEL(bool state |
|
695 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
|
696 |
|
697 /** |
|
698 * Return the value of fgNEL flag. |
|
699 */ |
|
700 static bool isNELRecognized(); |
|
701 //@} |
|
702 |
|
703 /** @name Strict IANA Encoding Checking */ |
|
704 //@{ |
|
705 /** |
|
706 * This function enables/disables strict IANA encoding names checking. |
|
707 * |
|
708 * The strict checking is disabled by default. |
|
709 * |
|
710 * @param state If true, a strict IANA encoding name check is performed, |
|
711 * otherwise, no checking. |
|
712 * |
|
713 */ |
|
714 static void strictIANAEncoding(const bool state); |
|
715 |
|
716 /** |
|
717 * Returns whether a strict IANA encoding name check is enabled or |
|
718 * disabled. |
|
719 */ |
|
720 static bool isStrictIANAEncoding(); |
|
721 //@} |
|
722 |
|
723 /** |
|
724 * Aligns the specified pointer per platform block allocation |
|
725 * requirements. |
|
726 * |
|
727 * The results of this function may be altered by defining |
|
728 * XML_PLATFORM_NEW_BLOCK_ALIGNMENT. |
|
729 */ |
|
730 static inline size_t alignPointerForNewBlockAllocation(size_t ptrSize); |
|
731 |
|
732 private : |
|
733 // ----------------------------------------------------------------------- |
|
734 // Unimplemented constructors and operators |
|
735 // ----------------------------------------------------------------------- |
|
736 XMLPlatformUtils(); |
|
737 |
|
738 /** @name Private static methods */ |
|
739 //@{ |
|
740 |
|
741 /** Loads a message set from the available domains |
|
742 * |
|
743 * @param msgDomain The message domain containing the message to be |
|
744 * loaded |
|
745 */ |
|
746 static XMLMsgLoader* loadAMsgSet(const XMLCh* const msgDomain); |
|
747 |
|
748 /** Creates a net accessor object. |
|
749 * |
|
750 * Each per-platform driver must implement this method. However, |
|
751 * having a Net Accessor is optional and this method can return a |
|
752 * null pointer if remote access via HTTP and FTP URLs is not required. |
|
753 * |
|
754 * @return An object derived from XMLNetAccessor. It must be dynamically |
|
755 * allocated, since it will be deleted later. |
|
756 */ |
|
757 static XMLNetAccessor* makeNetAccessor(); |
|
758 |
|
759 /** Creates a Transoding service |
|
760 * |
|
761 * Each per-platform driver must implement this method and return some |
|
762 * derivative of the XMLTransService class. This object serves as the |
|
763 * transcoder factory for this process. The object must be dynamically |
|
764 * allocated and the caller is responsible for cleaning it up. |
|
765 * |
|
766 * @return A dynamically allocated object of some class derived from |
|
767 * the XMLTransService class. |
|
768 */ |
|
769 static XMLTransService* makeTransService(); |
|
770 |
|
771 /** Does initialization for a particular platform |
|
772 * |
|
773 * Each per-platform driver must implement this to do any low level |
|
774 * system initialization required. It <b>cannot</b> use any XML |
|
775 * parser or utilities services! |
|
776 */ |
|
777 static void platformInit(); |
|
778 |
|
779 /** Does termination for a particular platform |
|
780 * |
|
781 * Each per-platform driver must implement this to do any low level |
|
782 * system resource cleanup required. It <b>cannot</b> use any XML |
|
783 * parser or utilities services! |
|
784 */ |
|
785 static void platformTerm(); |
|
786 |
|
787 /** Search for sequence, slash dot dot slash |
|
788 * |
|
789 * @param srcPath the path to search |
|
790 * |
|
791 * @return the position of the first occurence of slash dot dot slash |
|
792 * -1 if no such sequence is found |
|
793 */ |
|
794 static int searchSlashDotDotSlash(XMLCh* const srcPath); |
|
795 |
|
796 //@} |
|
797 |
|
798 /** @name Private static methods */ |
|
799 //@{ |
|
800 |
|
801 /** |
|
802 * Indicates whether the memory manager was supplied by the user |
|
803 * or not. Users own the memory manager, and if none is supplied, |
|
804 * Xerces uses a default one that it owns and is responsible for |
|
805 * deleting in Terminate(). |
|
806 */ |
|
807 static bool fgMemMgrAdopted; |
|
808 |
|
809 //@} |
|
810 }; |
|
811 |
|
812 |
|
813 MakeXMLException(XMLPlatformUtilsException, XMLUTIL_EXPORT) |
|
814 |
|
815 |
|
816 // --------------------------------------------------------------------------- |
|
817 // XMLPlatformUtils: alignPointerForNewBlockAllocation |
|
818 // --------------------------------------------------------------------------- |
|
819 // Calculate alignment required by platform for a new |
|
820 // block allocation. We use this in our custom allocators |
|
821 // to ensure that returned blocks are properly aligned. |
|
822 // Note that, although this will take a pointer and return the position |
|
823 // at which it should be placed for correct alignment, in our code |
|
824 // we normally use size_t parameters to discover what the alignment |
|
825 // of header blocks should be. Thus, if this is to be |
|
826 // used for the former purpose, to make compilers happy |
|
827 // some casting will be necessary - neilg. |
|
828 // |
|
829 // Note: XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be specified on a |
|
830 // per-architecture basis to dictate the alignment requirements |
|
831 // of the architecture. In the absense of this specification, |
|
832 // this routine guesses at the correct alignment value. |
|
833 // |
|
834 // A XML_PLATFORM_NEW_BLOCK_ALIGNMENT value of zero is illegal. |
|
835 // If a platform requires absolutely no alignment, a value |
|
836 // of 1 should be specified ("align pointers on 1 byte boundaries"). |
|
837 // |
|
838 inline size_t |
|
839 XMLPlatformUtils::alignPointerForNewBlockAllocation(size_t ptrSize) |
|
840 { |
|
841 // Macro XML_PLATFORM_NEW_BLOCK_ALIGNMENT may be defined |
|
842 // as needed to dictate alignment requirements on a |
|
843 // per-architecture basis. In the absense of that we |
|
844 // take an educated guess. |
|
845 #ifdef XML_PLATFORM_NEW_BLOCK_ALIGNMENT |
|
846 size_t alignment = XML_PLATFORM_NEW_BLOCK_ALIGNMENT; |
|
847 #else |
|
848 size_t alignment = (sizeof(void*) >= sizeof(double)) ? sizeof(void*) : sizeof(double); |
|
849 #endif |
|
850 |
|
851 // Calculate current alignment of pointer |
|
852 size_t current = ptrSize % alignment; |
|
853 |
|
854 // Adjust pointer alignment as needed |
|
855 return (current == 0) |
|
856 ? ptrSize |
|
857 : (ptrSize + alignment - current); |
|
858 } |
|
859 |
|
860 |
|
861 |
|
862 // --------------------------------------------------------------------------- |
|
863 // XMLDeleter: Public Destructor |
|
864 // --------------------------------------------------------------------------- |
|
865 inline XMLDeleter::~XMLDeleter() |
|
866 { |
|
867 } |
|
868 |
|
869 // --------------------------------------------------------------------------- |
|
870 // XMLDeleter: Hidden constructors and operators |
|
871 // --------------------------------------------------------------------------- |
|
872 inline XMLDeleter::XMLDeleter() |
|
873 { |
|
874 } |
|
875 |
|
876 XERCES_CPP_NAMESPACE_END |
|
877 |
|
878 #endif |