8 /* SunOS 4.x Blargh.... */
10 #define NULL ((void*)0)
15 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
18 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
22 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
23 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
24 #define __ASSERT_FUNCTION ((char *) 0)
26 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
32 #define wassertr(expr) {}
33 #define wassertrv(expr, val) {}
41 #define wassertr(expr) assert(expr)
43 #define wassertrv(expr, val) assert(expr)
47 #define wassertr(expr) \
49 wwarning("%s line %i (%s): assertion %s failed",\
50 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
54 #define wassertrv(expr, val) \
56 wwarning("%s line %i (%s): assertion %s failed",\
57 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
67 #endif /* __cplusplus */
81 } WMNotificationCoalescing
;
84 /* The possible states for connections */
97 /* The possible states for connection timeouts */
102 } WMConnectionTimeoutState
;
107 WBNotFound
= INT_MIN
, /* element was not found in WMBag */
108 WANotFound
= -1 /* element was not found in WMArray */
112 typedef struct W_Array WMArray
;
113 typedef struct W_Bag WMBag
;
114 typedef struct W_Data WMData
;
115 typedef struct W_TreeNode WMTreeNode
;
116 typedef struct W_HashTable WMHashTable
;
117 typedef struct W_UserDefaults WMUserDefaults
;
118 typedef struct W_Notification WMNotification
;
119 typedef struct W_NotificationQueue WMNotificationQueue
;
120 typedef struct W_Host WMHost
;
121 typedef struct W_Connection WMConnection
;
122 typedef struct W_PropList WMPropList
;
126 /* Some typedefs for the handler stuff */
127 typedef void *WMHandlerID
;
129 typedef void WMCallback(void *data
);
131 typedef void WMInputProc(int fd
, int mask
, void *clientData
);
135 typedef int WMCompareDataProc(const void *item1
, const void *item2
);
137 typedef void WMFreeDataProc(void *data
);
139 /* Used by WMBag or WMArray for matching data */
140 typedef int WMMatchDataProc(void *item
, void *cdata
);
151 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
160 /* NULL is pointer hash */
161 unsigned (*hash
)(const void *);
162 /* NULL is pointer compare */
163 Bool (*keyIsEqual
)(const void *, const void *);
164 /* NULL does nothing */
165 void* (*retainKey
)(const void *);
166 /* NULL does nothing */
167 void (*releaseKey
)(const void *);
168 } WMHashTableCallbacks
;
171 typedef int WMArrayIterator
;
172 typedef void *WMBagIterator
;
177 char character
; /* the escape character */
178 char *value
; /* value to place */
183 /* The connection callbacks */
184 typedef struct ConnectionDelegate
{
187 void (*didCatchException
)(struct ConnectionDelegate
*self
,
190 void (*didDie
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
192 void (*didInitialize
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
194 void (*didReceiveInput
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
196 void (*didTimeout
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
198 } ConnectionDelegate
;
201 typedef void WMNotificationObserverAction(void *observerData
,
202 WMNotification
*notification
);
206 /*......................................................................*/
208 typedef void (waborthandler
)(int);
210 waborthandler
* wsetabort(waborthandler
*);
213 /* don't free the returned string */
214 char* wstrerror(int errnum
);
216 void wmessage(const char *msg
, ...);
217 void wwarning(const char *msg
, ...);
218 void wfatal(const char *msg
, ...);
219 void wsyserror(const char *msg
, ...);
220 void wsyserrorwithcode(int error
, const char *msg
, ...);
222 char* wfindfile(char *paths
, char *file
);
224 char* wfindfileinlist(char **path_list
, char *file
);
226 char* wfindfileinarray(WMPropList
* array
, char *file
);
228 char* wexpandpath(char *path
);
230 /* don't free the returned string */
233 void* wmalloc(size_t size
);
234 void* wrealloc(void *ptr
, size_t newsize
);
235 void wfree(void *ptr
);
238 void wrelease(void *ptr
);
239 void* wretain(void *ptr
);
241 char* wstrdup(char *str
);
243 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
244 * str1 and str2 can be any strings including static and constant strings.
245 * str1 and str2 will not be modified.
246 * Free the returned string when you're done with it. */
247 char* wstrconcat(char *str1
, char *str2
);
249 /* This will append src to dst, and return dst. dst MUST be either NULL
250 * or a string that was a result of a dynamic allocation (malloc, realloc
251 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
252 * Modifies dst (no new string is created except if dst==NULL in which case
253 * it is equivalent to calling wstrdup(src) ).
254 * The returned address may be different from the original address of dst,
255 * so always assign the returned address to avoid dangling pointers. */
256 char* wstrappend(char *dst
, char *src
);
259 void wtokensplit(char *command
, char ***argv
, int *argc
);
261 char* wtokennext(char *word
, char **next
);
263 char* wtokenjoin(char **list
, int count
);
265 void wtokenfree(char **tokens
, int count
);
267 char* wtrimspace(char *s
);
270 WMRange
wmkrange(int start
, int count
);
271 #ifdef ANSI_C_DOESNT_LIKE_IT_THIS_WAY
272 #define wmkrange(position, count) (WMRange){(position), (count)}
276 char* wusergnusteppath();
278 char* wdefaultspathfordomain(char *domain
);
280 void wusleep(unsigned int microsec
);
283 int wsprintesc(char *buffer
, int length
, char *format
, WMSEscapes
**escapes
,
287 /*......................................................................*/
289 /* Event handlers: timer, idle, input */
291 WMHandlerID
WMAddTimerHandler(int milliseconds
, WMCallback
*callback
,
294 WMHandlerID
WMAddPersistentTimerHandler(int milliseconds
, WMCallback
*callback
,
297 void WMDeleteTimerWithClientData(void *cdata
);
299 void WMDeleteTimerHandler(WMHandlerID handlerID
);
301 WMHandlerID
WMAddIdleHandler(WMCallback
*callback
, void *cdata
);
303 void WMDeleteIdleHandler(WMHandlerID handlerID
);
305 WMHandlerID
WMAddInputHandler(int fd
, int condition
, WMInputProc
*proc
,
308 void WMDeleteInputHandler(WMHandlerID handlerID
);
311 /* This function is used _only_ if you create a non-GUI program.
312 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
313 * This function will handle all input/timer/idle events, then return.
316 void WHandleEvents();
318 /*......................................................................*/
321 WMHashTable
* WMCreateHashTable(WMHashTableCallbacks callbacks
);
323 void WMFreeHashTable(WMHashTable
*table
);
325 void WMResetHashTable(WMHashTable
*table
);
327 unsigned WMCountHashTable(WMHashTable
*table
);
329 void* WMHashGet(WMHashTable
*table
, const void *key
);
331 /* Returns True if there is a value associated with <key> in the table, in
332 * which case <retKey> and <retItem> will contain the item's internal key
333 * address and the item's value respectively.
334 * If there is no value associated with <key> it will return False and in
335 * this case <retKey> and <retItem> will be undefined.
336 * Use this when you need to perform your own custom retain/release mechanism
337 * which requires access to the keys too.
339 Bool
WMHashGetItemAndKey(WMHashTable
*table
, const void *key
,
340 void **retItem
, void **retKey
);
342 /* put data in table, replacing already existing data and returning
344 void* WMHashInsert(WMHashTable
*table
, const void *key
, const void *data
);
346 void WMHashRemove(WMHashTable
*table
, const void *key
);
348 /* warning: do not manipulate the table while using the enumerator functions */
349 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
351 void* WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
353 void* WMNextHashEnumeratorKey(WMHashEnumerator
*enumerator
);
355 /* Returns True if there is a next element, in which case key and item
356 * will contain the next element's key and value respectively.
357 * If there is no next element available it will return False and in this
358 * case key and item will be undefined.
360 Bool
WMNextHashEnumeratorItemAndKey(WMHashEnumerator
*enumerator
,
361 void **item
, void **key
);
366 /* some predefined callback sets */
368 extern const WMHashTableCallbacks WMIntHashCallbacks
;
369 /* sizeof(keys) are <= sizeof(void*) */
371 extern const WMHashTableCallbacks WMStringHashCallbacks
;
372 /* keys are strings. Strings will be copied with wstrdup()
373 * and freed with wfree() */
375 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
376 /* keys are strings, bug they are not copied */
379 /*......................................................................*/
382 * WMArray use an array to store the elements.
383 * Item indexes may be only positive integer numbers.
384 * The array cannot contain holes in it.
387 * Fast [O(1)] access to elements
388 * Fast [O(1)] push/pop
391 * A little slower [O(n)] for insertion/deletion of elements that
395 WMArray
* WMCreateArray(int initialSize
);
397 WMArray
* WMCreateArrayWithDestructor(int initialSize
, WMFreeDataProc
*destructor
);
399 WMArray
* WMCreateArrayWithArray(WMArray
*array
);
401 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
403 void WMEmptyArray(WMArray
*array
);
405 void WMFreeArray(WMArray
*array
);
407 int WMGetArrayItemCount(WMArray
*array
);
409 /* appends other to array. other remains unchanged */
410 void WMAppendArray(WMArray
*array
, WMArray
*other
);
412 /* add will place the element at the end of the array */
413 void WMAddToArray(WMArray
*array
, void *item
);
415 #define WMPushInArray(array, item) WMAddToArray(array, item)
417 /* insert will increment the index of elements after it by 1 */
418 void WMInsertInArray(WMArray
*array
, int index
, void *item
);
420 /* replace and set will return the old item WITHOUT calling the
421 * destructor on it even if its available. Free the returned item yourself.
423 void* WMReplaceInArray(WMArray
*array
, int index
, void *item
);
425 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
427 /* delete and remove will remove the elements and cause the elements
428 * after them to decrement their indexes by 1. Also will call the
429 * destructor on the deleted element if there's one available.
431 int WMDeleteFromArray(WMArray
*array
, int index
);
433 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
435 int WMRemoveFromArrayMatching(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
437 void* WMGetFromArray(WMArray
*array
, int index
);
439 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
441 /* pop will return the last element from the array, also removing it
442 * from the array. The destructor is NOT called, even if available.
443 * Free the returned element if needed by yourself
445 void* WMPopFromArray(WMArray
*array
);
447 int WMFindInArray(WMArray
*array
, WMMatchDataProc
*match
, void *cdata
);
449 int WMCountInArray(WMArray
*array
, void *item
);
451 /* comparer must return:
456 void WMSortArray(WMArray
*array
, WMCompareDataProc
*comparer
);
458 void WMMapArray(WMArray
*array
, void (*function
)(void*, void*), void *data
);
460 WMArray
* WMGetSubarrayWithRange(WMArray
* array
, WMRange aRange
);
462 void* WMArrayFirst(WMArray
*array
, WMArrayIterator
*iter
);
464 void* WMArrayLast(WMArray
*array
, WMArrayIterator
*iter
);
466 /* The following 2 functions assume that the array doesn't change between calls */
467 void* WMArrayNext(WMArray
*array
, WMArrayIterator
*iter
);
469 void* WMArrayPrevious(WMArray
*array
, WMArrayIterator
*iter
);
472 /* The following 2 macros assume that the array doesn't change in the for loop */
473 #define WM_ITERATE_ARRAY(array, var, i) \
474 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
475 var = WMArrayNext(array, &(i)))
477 #define WM_ETARETI_ARRAY(array, var, i) \
478 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
479 var = WMArrayPrevious(array, &(i)))
481 /*..........................................................................*/
484 * Tree bags use a red-black tree for storage.
485 * Item indexes may be any integer number.
488 * O(lg n) insertion/deletion/search
489 * Good for large numbers of elements with sparse indexes
492 * O(lg n) insertion/deletion/search
493 * Slow for storing small numbers of elements
496 #define WMCreateBag(size) WMCreateTreeBag()
498 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
500 WMBag
* WMCreateTreeBag(void);
502 WMBag
* WMCreateTreeBagWithDestructor(WMFreeDataProc
*destructor
);
504 int WMGetBagItemCount(WMBag
*bag
);
506 void WMAppendBag(WMBag
*bag
, WMBag
*other
);
508 void WMPutInBag(WMBag
*bag
, void *item
);
510 /* insert will increment the index of elements after it by 1 */
511 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
513 /* erase will remove the element from the bag,
514 * but will keep the index of the other elements unchanged */
515 int WMEraseFromBag(WMBag
*bag
, int index
);
517 /* delete and remove will remove the elements and cause the elements
518 * after them to decrement their indexes by 1 */
519 int WMDeleteFromBag(WMBag
*bag
, int index
);
521 int WMRemoveFromBag(WMBag
*bag
, void *item
);
523 void* WMGetFromBag(WMBag
*bag
, int index
);
525 void* WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
527 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
529 /* comparer must return:
534 void WMSortBag(WMBag
*bag
, WMCompareDataProc
*comparer
);
536 void WMEmptyBag(WMBag
*bag
);
538 void WMFreeBag(WMBag
*bag
);
540 void WMMapBag(WMBag
*bag
, void (*function
)(void*, void*), void *data
);
542 int WMGetFirstInBag(WMBag
*bag
, void *item
);
544 int WMCountInBag(WMBag
*bag
, void *item
);
546 int WMFindInBag(WMBag
*bag
, WMMatchDataProc
*match
, void *cdata
);
548 void* WMBagFirst(WMBag
*bag
, WMBagIterator
*ptr
);
550 void* WMBagLast(WMBag
*bag
, WMBagIterator
*ptr
);
552 /* The following 4 functions assume that the bag doesn't change between calls */
553 void* WMBagNext(WMBag
*bag
, WMBagIterator
*ptr
);
555 void* WMBagPrevious(WMBag
*bag
, WMBagIterator
*ptr
);
557 void* WMBagIteratorAtIndex(WMBag
*bag
, int index
, WMBagIterator
*ptr
);
559 int WMBagIndexForIterator(WMBag
*bag
, WMBagIterator ptr
);
562 /* The following 2 macros assume that the bag doesn't change in the for loop */
563 #define WM_ITERATE_BAG(bag, var, i) \
564 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
565 var = WMBagNext(bag, &(i)))
567 #define WM_ETARETI_BAG(bag, var, i) \
568 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
569 var = WMBagPrevious(bag, &(i)))
573 /*-------------------------------------------------------------------------*/
575 /* WMData handling */
577 /* Creating/destroying data */
579 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
581 WMData
* WMCreateDataWithLength(unsigned length
);
583 WMData
* WMCreateDataWithBytes(void *bytes
, unsigned length
);
585 /* destructor is a function called to free the data when releasing the data
586 * object, or NULL if no freeing of data is necesary. */
587 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
,
588 WMFreeDataProc
*destructor
);
590 WMData
* WMCreateDataWithData(WMData
*aData
);
592 WMData
* WMRetainData(WMData
*aData
);
594 void WMReleaseData(WMData
*aData
);
596 /* Adjusting capacity */
598 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
600 void WMSetDataLength(WMData
*aData
, unsigned length
);
602 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
606 const void* WMDataBytes(WMData
*aData
);
608 void WMGetDataBytes(WMData
*aData
, void *buffer
);
610 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
612 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
614 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
618 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
620 unsigned WMGetDataLength(WMData
*aData
);
624 void WMAppendDataBytes(WMData
*aData
, void *bytes
, unsigned length
);
626 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
630 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, void *bytes
);
632 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
634 void WMSetData(WMData
*aData
, WMData
*anotherData
);
637 void WMSetDataFormat(WMData
*aData
, unsigned format
);
639 unsigned WMGetDataFormat(WMData
*aData
);
643 /*--------------------------------------------------------------------------*/
645 /* Generic Tree and TreeNode */
647 WMTreeNode
* WMCreateTreeNode(void *data
);
649 WMTreeNode
* WMCreateTreeNodeWithDestructor(void *data
, WMFreeDataProc
*destructor
);
651 WMTreeNode
* WMInsertItemInTree(WMTreeNode
*parent
, int index
, void *item
);
653 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
655 WMTreeNode
* WMInsertNodeInTree(WMTreeNode
*parent
, int index
, WMTreeNode
*aNode
);
657 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
659 void WMDestroyTreeNode(WMTreeNode
*aNode
);
661 void WMDeleteLeafForTreeNode(WMTreeNode
*aNode
, int index
);
663 void WMRemoveLeafForTreeNode(WMTreeNode
*aNode
, void *leaf
);
665 void* WMReplaceDataForTreeNode(WMTreeNode
*aNode
, void *newData
);
667 void* WMGetDataForTreeNode(WMTreeNode
*aNode
);
669 int WMGetTreeNodeDepth(WMTreeNode
*aNode
);
671 WMTreeNode
* WMGetParentForTreeNode(WMTreeNode
*aNode
);
673 /* Sort only the leaves of the passed node */
674 void WMSortLeavesForTreeNode(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
676 /* Sort all tree recursively starting from the passed node */
677 void WMSortTree(WMTreeNode
*aNode
, WMCompareDataProc
*comparer
);
679 /* Returns the first node which matches node's data with cdata by 'match' */
680 WMTreeNode
* WMFindInTree(WMTreeNode
*aTree
, WMMatchDataProc
*match
, void *cdata
);
682 /* Returns first tree node that has data == cdata */
683 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(atree, NULL, cdata)
686 /*--------------------------------------------------------------------------*/
689 WMNotification
* WMCreateNotification(const char *name
, void *object
, void *clientData
);
691 void WMReleaseNotification(WMNotification
*notification
);
693 WMNotification
* WMRetainNotification(WMNotification
*notification
);
695 void* WMGetNotificationClientData(WMNotification
*notification
);
697 void* WMGetNotificationObject(WMNotification
*notification
);
699 const char* WMGetNotificationName(WMNotification
*notification
);
702 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
703 void *observer
, const char *name
, void *object
);
705 void WMPostNotification(WMNotification
*notification
);
707 void WMRemoveNotificationObserver(void *observer
);
709 void WMRemoveNotificationObserverWithName(void *observer
, const char *name
,
712 void WMPostNotificationName(const char *name
, void *object
, void *clientData
);
714 WMNotificationQueue
* WMGetDefaultNotificationQueue(void);
716 WMNotificationQueue
* WMCreateNotificationQueue(void);
718 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
719 WMNotification
*notification
,
722 void WMEnqueueNotification(WMNotificationQueue
*queue
,
723 WMNotification
*notification
,
724 WMPostingStyle postingStyle
);
726 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
727 WMNotification
*notification
,
728 WMPostingStyle postingStyle
,
729 unsigned coalesceMask
);
732 /*......................................................................*/
734 /* Property Lists handling */
736 void WMPLSetCaseSensitive(Bool caseSensitive
);
738 WMPropList
* WMCreatePLString(char *str
);
740 WMPropList
* WMCreatePLData(WMData
*data
);
742 WMPropList
* WMCreatePLDataWithBytes(unsigned char *bytes
, unsigned int length
);
744 WMPropList
* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes
,
746 WMFreeDataProc
*destructor
);
748 WMPropList
* WMCreatePLArray(WMPropList
*elem
, ...);
750 WMPropList
* WMCreatePLDictionary(WMPropList
*key
, WMPropList
*value
, ...);
752 WMPropList
* WMRetainPropList(WMPropList
*plist
);
754 void WMReleasePropList(WMPropList
*plist
);
756 /* Objects inserted in arrays and dictionaries will be retained,
757 * so you can safely release them after insertion.
758 * For dictionaries both the key and value are retained.
759 * Objects removed from arrays or dictionaries are released */
760 void WMInsertInPLArray(WMPropList
*plist
, int index
, WMPropList
*item
);
762 void WMAddToPLArray(WMPropList
*plist
, WMPropList
*item
);
764 void WMDeleteFromPLArray(WMPropList
*plist
, int index
);
766 void WMRemoveFromPLArray(WMPropList
*plist
, WMPropList
*item
);
768 void WMPutInPLDictionary(WMPropList
*plist
, WMPropList
*key
, WMPropList
*value
);
770 void WMRemoveFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
772 /* It inserts all key/value pairs from source into dest, overwriting
773 * the values with the same keys from dest, keeping all values with keys
774 * only present in dest unchanged */
775 WMPropList
* WMMergePLDictionaries(WMPropList
*dest
, WMPropList
*source
);
777 int WMGetPropListItemCount(WMPropList
*plist
);
779 Bool
WMIsPLString(WMPropList
*plist
);
781 Bool
WMIsPLData(WMPropList
*plist
);
783 Bool
WMIsPLArray(WMPropList
*plist
);
785 Bool
WMIsPLDictionary(WMPropList
*plist
);
787 Bool
WMIsPropListEqualTo(WMPropList
*plist
, WMPropList
*other
);
789 /* Returns a reference. Do not free it! */
790 char* WMGetFromPLString(WMPropList
*plist
);
792 /* Returns a reference. Do not free it! */
793 WMData
* WMGetFromPLData(WMPropList
*plist
);
795 /* Returns a reference. Do not free it! */
796 const unsigned char* WMGetPLDataBytes(WMPropList
*plist
);
798 int WMGetPLDataLength(WMPropList
*plist
);
800 /* Returns a reference. */
801 WMPropList
* WMGetFromPLArray(WMPropList
*plist
, int index
);
803 /* Returns a reference. */
804 WMPropList
* WMGetFromPLDictionary(WMPropList
*plist
, WMPropList
*key
);
806 /* Returns a PropList array with all the dictionary keys. Release it when
807 * you're done. Keys in array are retained from the original dictionary
808 * not copied and need NOT to be released individually. */
809 WMPropList
* WMGetPLDictionaryKeys(WMPropList
*plist
);
811 /* Creates only the first level deep object. All the elements inside are
812 * retained from the original */
813 WMPropList
* WMShallowCopyPropList(WMPropList
*plist
);
815 /* Makes a completely separate replica of the original proplist */
816 WMPropList
* WMDeepCopyPropList(WMPropList
*plist
);
818 WMPropList
* WMCreatePropListFromDescription(char *desc
);
820 /* Free the returned string when you no longer need it */
821 char* WMGetPropListDescription(WMPropList
*plist
, Bool indented
);
823 WMPropList
* WMReadPropListFromFile(char *file
);
825 Bool
WMWritePropListToFile(WMPropList
*plist
, char *path
, Bool atomically
);
827 /*......................................................................*/
829 WMUserDefaults
* WMGetStandardUserDefaults(void);
831 WMUserDefaults
* WMGetDefaultsFromPath(char *path
);
833 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
835 void WMSaveUserDefaults(WMUserDefaults
*database
);
837 void WMEnableUDPeriodicSynchronization(WMUserDefaults
*database
, Bool enable
);
839 /* Returns a WMPropList array with all the keys in the user defaults database.
840 * Free the array with WMReleasePropList() when no longer needed.
841 * Keys in array are just retained references to the original keys */
842 WMPropList
* WMGetUDKeys(WMUserDefaults
*database
);
844 WMPropList
* WMGetUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
846 void WMSetUDObjectForKey(WMUserDefaults
*database
, WMPropList
*object
,
849 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
851 char* WMGetUDStringForKey(WMUserDefaults
*database
, char *defaultName
);
853 int WMGetUDIntegerForKey(WMUserDefaults
*database
, char *defaultName
);
855 float WMGetUDFloatForKey(WMUserDefaults
*database
, char *defaultName
);
857 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, char *defaultName
);
859 void WMSetUDStringForKey(WMUserDefaults
*database
, char *value
,
862 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
865 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
868 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
871 WMPropList
* WMGetUDSearchList(WMUserDefaults
*database
);
873 void WMSetUDSearchList(WMUserDefaults
*database
, WMPropList
*list
);
875 extern char *WMUserDefaultsDidChangeNotification
;
878 /*-------------------------------------------------------------------------*/
880 /* WMHost: host handling */
882 WMHost
* WMGetCurrentHost();
884 WMHost
* WMGetHostWithName(char* name
);
886 WMHost
* WMGetHostWithAddress(char* address
);
888 WMHost
* WMRetainHost(WMHost
*hPtr
);
890 void WMReleaseHost(WMHost
*hPtr
);
893 * Host cache management
894 * If enabled, only one object representing each host will be created, and
895 * a shared instance will be returned by all methods that return a host.
896 * Enabled by default.
898 void WMSetHostCacheEnabled(Bool flag
);
900 Bool
WMIsHostCacheEnabled();
902 void WMFlushHostCache();
905 * Compare hosts: Hosts are equal if they share at least one address
907 Bool
WMIsHostEqualToHost(WMHost
* hPtr
, WMHost
* anotherHost
);
911 * WMGetHostName() will return first name (official) if a host has several.
912 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
914 char* WMGetHostName(WMHost
* hPtr
);
916 /* The returned array is R/O. Do not modify it, and do not free it! */
917 WMArray
* WMGetHostNames(WMHost
* hPtr
);
921 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
922 * WMGetHostAddress() will return an arbitrary address if a host has several.
923 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
925 char* WMGetHostAddress(WMHost
* hPtr
);
927 /* The returned array is R/O. Do not modify it, and do not free it! */
928 WMArray
* WMGetHostAddresses(WMHost
* hPtr
);
931 /*-------------------------------------------------------------------------*/
933 /* WMConnection functions */
935 WMConnection
* WMCreateConnectionAsServerAtAddress(char *host
, char *service
,
938 WMConnection
* WMCreateConnectionToAddress(char *host
, char *service
,
941 WMConnection
* WMCreateConnectionToAddressAndNotify(char *host
, char *service
,
944 void WMCloseConnection(WMConnection
*cPtr
);
946 void WMDestroyConnection(WMConnection
*cPtr
);
948 WMConnection
* WMAcceptConnection(WMConnection
*listener
);
950 /* Release the returned data! */
951 WMData
* WMGetConnectionAvailableData(WMConnection
*cPtr
);
953 int WMSendConnectionData(WMConnection
*cPtr
, WMData
*data
);
955 Bool
WMEnqueueConnectionData(WMConnection
*cPtr
, WMData
*data
);
957 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
959 void WMSetConnectionDelegate(WMConnection
*cPtr
, ConnectionDelegate
*delegate
);
961 /* Connection info */
963 char* WMGetConnectionAddress(WMConnection
*cPtr
);
965 char* WMGetConnectionService(WMConnection
*cPtr
);
967 char* WMGetConnectionProtocol(WMConnection
*cPtr
);
969 Bool
WMSetConnectionNonBlocking(WMConnection
*cPtr
, Bool flag
);
971 Bool
WMSetConnectionCloseOnExec(WMConnection
*cPtr
, Bool flag
);
973 void* WMGetConnectionClientData(WMConnection
*cPtr
);
975 void WMSetConnectionClientData(WMConnection
*cPtr
, void *data
);
977 unsigned int WMGetConnectionFlags(WMConnection
*cPtr
);
979 void WMSetConnectionFlags(WMConnection
*cPtr
, unsigned int flags
);
981 int WMGetConnectionSocket(WMConnection
*cPtr
);
983 WMConnectionState
WMGetConnectionState(WMConnection
*cPtr
);
985 WMConnectionTimeoutState
WMGetConnectionTimeoutState(WMConnection
*cPtr
);
987 WMArray
* WMGetConnectionUnsentData(WMConnection
*cPtr
);
989 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
993 * Passing timeout==0 in the SetTimeout functions below, will reset that
994 * timeout to its default value.
997 /* The default timeout inherited by all WMConnection operations, if none set */
998 void WMSetConnectionDefaultTimeout(unsigned int timeout
);
1000 /* Global timeout for all WMConnection objects, for opening a new connection */
1001 void WMSetConnectionOpenTimeout(unsigned int timeout
);
1003 /* Connection specific timeout for sending out data */
1004 void WMSetConnectionSendTimeout(WMConnection
*cPtr
, unsigned int timeout
);
1007 /* Global variables */
1009 extern int WCErrorCode
;
1012 /*-------------------------------------------------------------------------*/
1018 #endif /* __cplusplus */