more code for proplist handling
[wmaker-crm.git] / WINGs / WINGs / WUtil.h
blob0e6ec4b30f5b5d095cf8c47fab5ef137d58a8e4c
1 #ifndef _WUTIL_H_
2 #define _WUTIL_H_
4 #include <X11/Xlib.h>
5 #include <limits.h>
6 #include <sys/types.h>
8 /* SunOS 4.x Blargh.... */
9 #ifndef NULL
10 #define NULL ((void*)0)
11 #endif
14 * Warning: proplist.h #defines BOOL which will clash with the
15 * typedef BOOL in Xmd.h
16 * proplist.h should use Bool (which is a #define in Xlib.h) instead.
19 #include <proplist.h>
22 #ifndef WMAX
23 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
24 #endif
25 #ifndef WMIN
26 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
27 #endif
30 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
31 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
32 #define __ASSERT_FUNCTION ((char *) 0)
33 #else
34 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
35 #endif
38 #ifdef NDEBUG
40 #define wassertr(expr) {}
41 #define wassertrv(expr, val) {}
43 #else /* !NDEBUG */
45 #ifdef DEBUG
47 #include <assert.h>
49 #define wassertr(expr) assert(expr)
51 #define wassertrv(expr, val) assert(expr)
53 #else /* !DEBUG */
55 #define wassertr(expr) \
56 if (!(expr)) { \
57 wwarning("%s line %i (%s): assertion %s failed",\
58 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
59 return;\
62 #define wassertrv(expr, val) \
63 if (!(expr)) { \
64 wwarning("%s line %i (%s): assertion %s failed",\
65 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
66 return (val);\
68 #endif /* !DEBUG */
70 #endif /* !NDEBUG */
73 #ifdef __cplusplus
74 extern "C" {
75 #endif /* __cplusplus */
78 typedef enum {
79 WMPostWhenIdle = 1,
80 WMPostASAP = 2,
81 WMPostNow = 3
82 } WMPostingStyle;
85 typedef enum {
86 WNCNone = 0,
87 WNCOnName = 1,
88 WNCOnSender = 2
89 } WMNotificationCoalescing;
92 /* The possible states for connections */
93 typedef enum {
94 WCNotConnected=0,
95 WCListening,
96 WCInProgress,
97 WCFailed,
98 WCConnected,
99 WCTimedOut,
100 WCDied,
101 WCClosed
102 } WMConnectionState;
105 /* The possible states for connection timeouts */
106 typedef enum {
107 WCTNone=0,
108 WCTWhileOpening,
109 WCTWhileSending
110 } WMConnectionTimeoutState;
114 enum {
115 WBNotFound = INT_MIN, /* element was not found in WMBag */
116 WANotFound = -1 /* element was not found in WMArray */
120 typedef struct W_Array WMArray;
121 typedef struct W_Bag WMBag;
122 typedef struct W_Data WMData;
123 typedef struct W_TreeNode WMTreeNode;
124 typedef struct W_HashTable WMHashTable;
125 typedef struct W_UserDefaults WMUserDefaults;
126 typedef struct W_Notification WMNotification;
127 typedef struct W_NotificationQueue WMNotificationQueue;
128 typedef struct W_Host WMHost;
129 typedef struct W_Connection WMConnection;
130 typedef struct W_PropList WMPropList;
134 /* Some typedefs for the handler stuff */
135 typedef void *WMHandlerID;
137 typedef void WMCallback(void *data);
139 typedef void WMInputProc(int fd, int mask, void *clientData);
143 typedef int WMCompareDataProc(const void *item1, const void *item2);
145 typedef void WMFreeDataProc(void *data);
147 /* Used by WMBag or WMArray for matching data */
148 typedef int WMMatchDataProc(void *item, void *cdata);
152 typedef struct {
153 int position;
154 int count;
155 } WMRange;
159 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
160 typedef struct {
161 void *table;
162 void *nextItem;
163 int index;
164 } WMHashEnumerator;
167 typedef struct {
168 /* NULL is pointer hash */
169 unsigned (*hash)(const void *);
170 /* NULL is pointer compare */
171 Bool (*keyIsEqual)(const void *, const void *);
172 /* NULL does nothing */
173 void* (*retainKey)(const void *);
174 /* NULL does nothing */
175 void (*releaseKey)(const void *);
176 } WMHashTableCallbacks;
179 typedef int WMArrayIterator;
180 typedef void *WMBagIterator;
183 #if 0
184 typedef struct {
185 char character; /* the escape character */
186 char *value; /* value to place */
187 } WMSEscapes;
188 #endif
191 /* The connection callbacks */
192 typedef struct ConnectionDelegate {
193 void *data;
195 void (*didCatchException)(struct ConnectionDelegate *self,
196 WMConnection *cPtr);
198 void (*didDie)(struct ConnectionDelegate *self, WMConnection *cPtr);
200 void (*didInitialize)(struct ConnectionDelegate *self, WMConnection *cPtr);
202 void (*didReceiveInput)(struct ConnectionDelegate *self, WMConnection *cPtr);
204 void (*didTimeout)(struct ConnectionDelegate *self, WMConnection *cPtr);
206 } ConnectionDelegate;
209 typedef void WMNotificationObserverAction(void *observerData,
210 WMNotification *notification);
214 /*......................................................................*/
216 typedef void (waborthandler)(int);
218 waborthandler* wsetabort(waborthandler*);
221 /* don't free the returned string */
222 char* wstrerror(int errnum);
224 void wmessage(const char *msg, ...);
225 void wwarning(const char *msg, ...);
226 void wfatal(const char *msg, ...);
227 void wsyserror(const char *msg, ...);
228 void wsyserrorwithcode(int error, const char *msg, ...);
230 char* wfindfile(char *paths, char *file);
232 char* wfindfileinlist(char **path_list, char *file);
234 char* wfindfileinarray(proplist_t array, char *file);
236 char* wexpandpath(char *path);
238 /* don't free the returned string */
239 char* wgethomedir();
241 void* wmalloc(size_t size);
242 void* wrealloc(void *ptr, size_t newsize);
243 void wfree(void *ptr);
246 void wrelease(void *ptr);
247 void* wretain(void *ptr);
249 char* wstrdup(char *str);
251 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
252 * str1 and str2 can be any strings including static and constant strings.
253 * str1 and str2 will not be modified.
254 * Free the returned string when you're done with it. */
255 char* wstrconcat(char *str1, char *str2);
257 /* This will append src to dst, and return dst. dst MUST be either NULL
258 * or a string that was a result of a dynamic allocation (malloc, realloc
259 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
260 * Modifies dst (no new string is created except if dst==NULL in which case
261 * it is equivalent to calling wstrdup(src) ).
262 * The returned address may be different from the original address of dst,
263 * so always assign the returned address to avoid dangling pointers. */
264 char* wstrappend(char *dst, char *src);
267 void wtokensplit(char *command, char ***argv, int *argc);
269 char* wtokennext(char *word, char **next);
271 char* wtokenjoin(char **list, int count);
273 void wtokenfree(char **tokens, int count);
275 char* wtrimspace(char *s);
278 WMRange wmkrange(int start, int count);
279 #ifdef ANSI_C_DOESNT_LIKE_IT_THIS_WAY
280 #define wmkrange(position, count) (WMRange){(position), (count)}
281 #endif
284 char* wusergnusteppath();
286 char* wdefaultspathfordomain(char *domain);
288 void wusleep(unsigned int microsec);
290 #if 0
291 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
292 int count);
293 #endif
295 /*......................................................................*/
297 /* Event handlers: timer, idle, input */
299 WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback *callback,
300 void *cdata);
302 WMHandlerID WMAddPersistentTimerHandler(int milliseconds, WMCallback *callback,
303 void *cdata);
305 void WMDeleteTimerWithClientData(void *cdata);
307 void WMDeleteTimerHandler(WMHandlerID handlerID);
309 WMHandlerID WMAddIdleHandler(WMCallback *callback, void *cdata);
311 void WMDeleteIdleHandler(WMHandlerID handlerID);
313 WMHandlerID WMAddInputHandler(int fd, int condition, WMInputProc *proc,
314 void *clientData);
316 void WMDeleteInputHandler(WMHandlerID handlerID);
319 /* This function is used _only_ if you create a non-GUI program.
320 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
321 * This function will handle all input/timer/idle events, then return.
324 void WHandleEvents();
326 /*......................................................................*/
329 WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
331 void WMFreeHashTable(WMHashTable *table);
333 void WMResetHashTable(WMHashTable *table);
335 unsigned WMCountHashTable(WMHashTable *table);
337 void* WMHashGet(WMHashTable *table, const void *key);
339 /* put data in table, replacing already existing data and returning
340 * the old value */
341 void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
343 void WMHashRemove(WMHashTable *table, const void *key);
345 /* warning: do not manipulate the table while using the enumerator functions */
346 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
348 void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
350 void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
352 /* Returns True if there is a next element, in which case key and item
353 * will contain the next element's key and value respectively.
354 * If there is no next element available it will return False and in this
355 * case key and item will be undefined.
357 Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator *enumerator,
358 void **item, void **key);
363 /* some predefined callback sets */
365 extern const WMHashTableCallbacks WMIntHashCallbacks;
366 /* sizeof(keys) are <= sizeof(void*) */
368 extern const WMHashTableCallbacks WMStringHashCallbacks;
369 /* keys are strings. Strings will be copied with wstrdup()
370 * and freed with wfree() */
372 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
373 /* keys are strings, bug they are not copied */
376 /*......................................................................*/
379 * WMArray use an array to store the elements.
380 * Item indexes may be only positive integer numbers.
381 * The array cannot contain holes in it.
383 * Pros:
384 * Fast [O(1)] access to elements
385 * Fast [O(1)] push/pop
387 * Cons:
388 * A little slower [O(n)] for insertion/deletion of elements that
389 * aren't in the end
392 WMArray* WMCreateArray(int initialSize);
394 WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
396 WMArray* WMCreateArrayWithArray(WMArray *array);
398 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
400 void WMEmptyArray(WMArray *array);
402 void WMFreeArray(WMArray *array);
404 int WMGetArrayItemCount(WMArray *array);
406 /* appends other to array. other remains unchanged */
407 void WMAppendArray(WMArray *array, WMArray *other);
409 /* add will place the element at the end of the array */
410 void WMAddToArray(WMArray *array, void *item);
412 #define WMPushInArray(array, item) WMAddToArray(array, item)
414 /* insert will increment the index of elements after it by 1 */
415 void WMInsertInArray(WMArray *array, int index, void *item);
417 /* replace and set will return the old item WITHOUT calling the
418 * destructor on it even if its available. Free the returned item yourself.
420 void* WMReplaceInArray(WMArray *array, int index, void *item);
422 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
424 /* delete and remove will remove the elements and cause the elements
425 * after them to decrement their indexes by 1. Also will call the
426 * destructor on the deleted element if there's one available.
428 int WMDeleteFromArray(WMArray *array, int index);
430 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
432 int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
434 void* WMGetFromArray(WMArray *array, int index);
436 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
438 /* pop will return the last element from the array, also removing it
439 * from the array. The destructor is NOT called, even if available.
440 * Free the returned element if needed by yourself
442 void* WMPopFromArray(WMArray *array);
444 int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
446 int WMCountInArray(WMArray *array, void *item);
448 /* comparer must return:
449 * < 0 if a < b
450 * > 0 if a > b
451 * = 0 if a = b
453 void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
455 void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
457 WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
459 void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
461 void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
463 /* The following 2 functions assume that the array doesn't change between calls */
464 void* WMArrayNext(WMArray *array, WMArrayIterator *iter);
466 void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
469 /* The following 2 macros assume that the array doesn't change in the for loop */
470 #define WM_ITERATE_ARRAY(array, var, i) \
471 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
472 var = WMArrayNext(array, &(i)))
474 #define WM_ETARETI_ARRAY(array, var, i) \
475 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
476 var = WMArrayPrevious(array, &(i)))
478 /*..........................................................................*/
481 * Tree bags use a red-black tree for storage.
482 * Item indexes may be any integer number.
484 * Pros:
485 * O(lg n) insertion/deletion/search
486 * Good for large numbers of elements with sparse indexes
488 * Cons:
489 * O(lg n) insertion/deletion/search
490 * Slow for storing small numbers of elements
493 #define WMCreateBag(size) WMCreateTreeBag()
495 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
497 WMBag* WMCreateTreeBag(void);
499 WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
501 int WMGetBagItemCount(WMBag *bag);
503 void WMAppendBag(WMBag *bag, WMBag *other);
505 void WMPutInBag(WMBag *bag, void *item);
507 /* insert will increment the index of elements after it by 1 */
508 void WMInsertInBag(WMBag *bag, int index, void *item);
510 /* erase will remove the element from the bag,
511 * but will keep the index of the other elements unchanged */
512 int WMEraseFromBag(WMBag *bag, int index);
514 /* delete and remove will remove the elements and cause the elements
515 * after them to decrement their indexes by 1 */
516 int WMDeleteFromBag(WMBag *bag, int index);
518 int WMRemoveFromBag(WMBag *bag, void *item);
520 void* WMGetFromBag(WMBag *bag, int index);
522 void* WMReplaceInBag(WMBag *bag, int index, void *item);
524 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
526 /* comparer must return:
527 * < 0 if a < b
528 * > 0 if a > b
529 * = 0 if a = b
531 void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
533 void WMEmptyBag(WMBag *bag);
535 void WMFreeBag(WMBag *bag);
537 void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
539 int WMGetFirstInBag(WMBag *bag, void *item);
541 int WMCountInBag(WMBag *bag, void *item);
543 int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
545 void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
547 void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
549 /* The following 4 functions assume that the bag doesn't change between calls */
550 void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
552 void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
554 void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
556 int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
559 /* The following 2 macros assume that the bag doesn't change in the for loop */
560 #define WM_ITERATE_BAG(bag, var, i) \
561 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
562 var = WMBagNext(bag, &(i)))
564 #define WM_ETARETI_BAG(bag, var, i) \
565 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
566 var = WMBagPrevious(bag, &(i)))
570 /*-------------------------------------------------------------------------*/
572 /* WMData handling */
574 /* Creating/destroying data */
576 WMData* WMCreateDataWithCapacity(unsigned capacity);
578 WMData* WMCreateDataWithLength(unsigned length);
580 WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
582 /* destructor is a function called to free the data when releasing the data
583 * object, or NULL if no freeing of data is necesary. */
584 WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
585 WMFreeDataProc *destructor);
587 WMData* WMCreateDataWithData(WMData *aData);
589 WMData* WMRetainData(WMData *aData);
591 void WMReleaseData(WMData *aData);
593 /* Adjusting capacity */
595 void WMSetDataCapacity(WMData *aData, unsigned capacity);
597 void WMSetDataLength(WMData *aData, unsigned length);
599 void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
601 /* Accessing data */
603 const void* WMDataBytes(WMData *aData);
605 void WMGetDataBytes(WMData *aData, void *buffer);
607 void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
609 void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
611 WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
613 /* Testing data */
615 Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
617 unsigned WMGetDataLength(WMData *aData);
619 /* Adding data */
621 void WMAppendDataBytes(WMData *aData, void *bytes, unsigned length);
623 void WMAppendData(WMData *aData, WMData *anotherData);
625 /* Modifying data */
627 void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, void *bytes);
629 void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
631 void WMSetData(WMData *aData, WMData *anotherData);
634 void WMSetDataFormat(WMData *aData, unsigned format);
636 unsigned WMGetDataFormat(WMData *aData);
637 /* Storing data */
640 /*--------------------------------------------------------------------------*/
642 /* Generic Tree and TreeNode */
644 WMTreeNode* WMCreateTreeNode(void *data);
646 WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
648 WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
650 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
652 WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
654 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
656 void WMDestroyTreeNode(WMTreeNode *aNode);
658 void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
660 void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
662 void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
664 void* WMGetDataForTreeNode(WMTreeNode *aNode);
666 int WMGetTreeNodeDepth(WMTreeNode *aNode);
668 WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
670 /* Sort only the leaves of the passed node */
671 void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
673 /* Sort all tree recursively starting from the passed node */
674 void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
676 /* Returns the first node which matches node's data with cdata by 'match' */
677 WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
679 /* Returns first tree node that has data == cdata */
680 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(atree, NULL, cdata)
683 /*--------------------------------------------------------------------------*/
685 /* Dictionaries */
687 WMDictionary* WMCreateDictionaryFromElements(void *key, void *value, ...);
689 #define WMGetDictionaryEntryForKey(dict, key) WMHashGet(dict, key)
691 WMArray* WMGetAllDictionaryKeys(WMDictionary *dPtr);
694 /*--------------------------------------------------------------------------*/
697 WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
699 void WMReleaseNotification(WMNotification *notification);
701 WMNotification* WMRetainNotification(WMNotification *notification);
703 void* WMGetNotificationClientData(WMNotification *notification);
705 void* WMGetNotificationObject(WMNotification *notification);
707 const char* WMGetNotificationName(WMNotification *notification);
710 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
711 void *observer, const char *name, void *object);
713 void WMPostNotification(WMNotification *notification);
715 void WMRemoveNotificationObserver(void *observer);
717 void WMRemoveNotificationObserverWithName(void *observer, const char *name,
718 void *object);
720 void WMPostNotificationName(const char *name, void *object, void *clientData);
722 WMNotificationQueue* WMGetDefaultNotificationQueue(void);
724 WMNotificationQueue* WMCreateNotificationQueue(void);
726 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
727 WMNotification *notification,
728 unsigned mask);
730 void WMEnqueueNotification(WMNotificationQueue *queue,
731 WMNotification *notification,
732 WMPostingStyle postingStyle);
734 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
735 WMNotification *notification,
736 WMPostingStyle postingStyle,
737 unsigned coalesceMask);
740 /*......................................................................*/
742 /* Property Lists handling */
744 void WMSetPropListStringComparer(WMCompareDataProc *comparer);
746 WMPropList* WMCreatePropListString(char *str);
748 WMPropList* WMCreatePropListDataWithBytes(unsigned char *bytes,
749 unsigned int length);
750 WMPropList* WMCreatePropListDataWithBytesNoCopy(unsigned char *bytes,
751 unsigned int length,
752 WMFreeDataProc *destructor);
754 WMPropList* WMCreatePropListDataWithData(WMData *data);
756 WMPropList* WMCreatePropListArrayFromElements(WMPropList *elem, ...);
758 WMPropList* WMCreatePropListDictionaryFromEntries(WMPropList *key,
759 WMPropList *value, ...);
761 WMPropList* WMRetainPropList(WMPropList *plist);
763 void WMReleasePropList(WMPropList *plist);
765 Bool WMPropListIsString(WMPropList *plist);
767 Bool WMPropListIsData(WMPropList *plist);
769 Bool WMPropListIsArray(WMPropList *plist);
771 Bool WMPropListIsDictionary(WMPropList *plist);
773 Bool WMPropListIsSimple(WMPropList *plist);
775 Bool WMPropListIsCompound(WMPropList *plist);
777 Bool WMArePropListsEqual(WMPropList *plist, WMPropList *other);
780 /*......................................................................*/
782 WMUserDefaults* WMGetStandardUserDefaults(void);
784 WMUserDefaults* WMGetDefaultsFromPath(char *path);
786 void WMSynchronizeUserDefaults(WMUserDefaults *database);
788 void WMSaveUserDefaults(WMUserDefaults *database);
790 void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
792 /* Returns a PLArray with all keys in the user defaults database.
793 * Free the returned array with PLRelease() when no longer needed,
794 * but do not free the elements of the array! They're just references. */
795 proplist_t WMGetUDAllKeys(WMUserDefaults *database);
797 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
799 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
800 char *defaultName);
802 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
804 char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
806 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
808 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
810 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
812 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
813 char *defaultName);
815 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
816 char *defaultName);
818 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
819 char *defaultName);
821 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
822 char *defaultName);
824 proplist_t WMGetUDSearchList(WMUserDefaults *database);
826 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
828 extern char *WMUserDefaultsDidChangeNotification;
831 /*-------------------------------------------------------------------------*/
833 /* WMHost: host handling */
835 WMHost* WMGetCurrentHost();
837 WMHost* WMGetHostWithName(char* name);
839 WMHost* WMGetHostWithAddress(char* address);
841 WMHost* WMRetainHost(WMHost *hPtr);
843 void WMReleaseHost(WMHost *hPtr);
846 * Host cache management
847 * If enabled, only one object representing each host will be created, and
848 * a shared instance will be returned by all methods that return a host.
849 * Enabled by default.
851 void WMSetHostCacheEnabled(Bool flag);
853 Bool WMIsHostCacheEnabled();
855 void WMFlushHostCache();
858 * Compare hosts: Hosts are equal if they share at least one address
860 Bool WMIsHostEqualToHost(WMHost* hPtr, WMHost* anotherHost);
863 * Host names.
864 * WMGetHostName() will return first name (official) if a host has several.
865 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
867 char* WMGetHostName(WMHost* hPtr);
869 /* The returned array is R/O. Do not modify it, and do not free it! */
870 WMArray* WMGetHostNames(WMHost* hPtr);
873 * Host addresses.
874 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
875 * WMGetHostAddress() will return an arbitrary address if a host has several.
876 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
878 char* WMGetHostAddress(WMHost* hPtr);
880 /* The returned array is R/O. Do not modify it, and do not free it! */
881 WMArray* WMGetHostAddresses(WMHost* hPtr);
884 /*-------------------------------------------------------------------------*/
886 /* WMConnection functions */
888 WMConnection* WMCreateConnectionAsServerAtAddress(char *host, char *service,
889 char *protocol);
891 WMConnection* WMCreateConnectionToAddress(char *host, char *service,
892 char *protocol);
894 WMConnection* WMCreateConnectionToAddressAndNotify(char *host, char *service,
895 char *protocol);
897 void WMCloseConnection(WMConnection *cPtr);
899 void WMDestroyConnection(WMConnection *cPtr);
901 WMConnection* WMAcceptConnection(WMConnection *listener);
903 /* Release the returned data! */
904 WMData* WMGetConnectionAvailableData(WMConnection *cPtr);
906 int WMSendConnectionData(WMConnection *cPtr, WMData *data);
908 Bool WMEnqueueConnectionData(WMConnection *cPtr, WMData *data);
910 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
912 void WMSetConnectionDelegate(WMConnection *cPtr, ConnectionDelegate *delegate);
914 /* Connection info */
916 char* WMGetConnectionAddress(WMConnection *cPtr);
918 char* WMGetConnectionService(WMConnection *cPtr);
920 char* WMGetConnectionProtocol(WMConnection *cPtr);
922 Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag);
924 Bool WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag);
926 void* WMGetConnectionClientData(WMConnection *cPtr);
928 void WMSetConnectionClientData(WMConnection *cPtr, void *data);
930 unsigned int WMGetConnectionFlags(WMConnection *cPtr);
932 void WMSetConnectionFlags(WMConnection *cPtr, unsigned int flags);
934 int WMGetConnectionSocket(WMConnection *cPtr);
936 WMConnectionState WMGetConnectionState(WMConnection *cPtr);
938 WMConnectionTimeoutState WMGetConnectionTimeoutState(WMConnection *cPtr);
940 WMArray* WMGetConnectionUnsentData(WMConnection *cPtr);
942 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
946 * Passing timeout==0 in the SetTimeout functions below, will reset that
947 * timeout to its default value.
950 /* The default timeout inherited by all WMConnection operations, if none set */
951 void WMSetConnectionDefaultTimeout(unsigned int timeout);
953 /* Global timeout for all WMConnection objects, for opening a new connection */
954 void WMSetConnectionOpenTimeout(unsigned int timeout);
956 /* Connection specific timeout for sending out data */
957 void WMSetConnectionSendTimeout(WMConnection *cPtr, unsigned int timeout);
960 /* Global variables */
962 extern int WCErrorCode;
965 /*-------------------------------------------------------------------------*/
969 #ifdef __cplusplus
971 #endif /* __cplusplus */
974 #endif