more code for proplist handling (almost finished)
[wmaker-crm.git] / WINGs / WINGs / WUtil.h
blob98c6fcf7373a442679ceae7d76abcc38a35e899c
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 /* Returns True if there is a value associated with <key> in the table, in
340 * which case <retKey> and <retItem> will contain the item's internal key
341 * address and the item's value respectively.
342 * If there is no value associated with <key> it will return False and in
343 * this case <retKey> and <retItem> will be undefined.
344 * Use this when you need to perform your own custom retain/release mechanism
345 * which requires access to the keys too.
347 Bool WMHashGetItemAndKey(WMHashTable *table, const void *key,
348 void **retItem, void **retKey);
350 /* put data in table, replacing already existing data and returning
351 * the old value */
352 void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
354 void WMHashRemove(WMHashTable *table, const void *key);
356 /* warning: do not manipulate the table while using the enumerator functions */
357 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
359 void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
361 void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
363 /* Returns True if there is a next element, in which case key and item
364 * will contain the next element's key and value respectively.
365 * If there is no next element available it will return False and in this
366 * case key and item will be undefined.
368 Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator *enumerator,
369 void **item, void **key);
374 /* some predefined callback sets */
376 extern const WMHashTableCallbacks WMIntHashCallbacks;
377 /* sizeof(keys) are <= sizeof(void*) */
379 extern const WMHashTableCallbacks WMStringHashCallbacks;
380 /* keys are strings. Strings will be copied with wstrdup()
381 * and freed with wfree() */
383 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
384 /* keys are strings, bug they are not copied */
387 /*......................................................................*/
390 * WMArray use an array to store the elements.
391 * Item indexes may be only positive integer numbers.
392 * The array cannot contain holes in it.
394 * Pros:
395 * Fast [O(1)] access to elements
396 * Fast [O(1)] push/pop
398 * Cons:
399 * A little slower [O(n)] for insertion/deletion of elements that
400 * aren't in the end
403 WMArray* WMCreateArray(int initialSize);
405 WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
407 WMArray* WMCreateArrayWithArray(WMArray *array);
409 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
411 void WMEmptyArray(WMArray *array);
413 void WMFreeArray(WMArray *array);
415 int WMGetArrayItemCount(WMArray *array);
417 /* appends other to array. other remains unchanged */
418 void WMAppendArray(WMArray *array, WMArray *other);
420 /* add will place the element at the end of the array */
421 void WMAddToArray(WMArray *array, void *item);
423 #define WMPushInArray(array, item) WMAddToArray(array, item)
425 /* insert will increment the index of elements after it by 1 */
426 void WMInsertInArray(WMArray *array, int index, void *item);
428 /* replace and set will return the old item WITHOUT calling the
429 * destructor on it even if its available. Free the returned item yourself.
431 void* WMReplaceInArray(WMArray *array, int index, void *item);
433 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
435 /* delete and remove will remove the elements and cause the elements
436 * after them to decrement their indexes by 1. Also will call the
437 * destructor on the deleted element if there's one available.
439 int WMDeleteFromArray(WMArray *array, int index);
441 #define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
443 int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
445 void* WMGetFromArray(WMArray *array, int index);
447 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
449 /* pop will return the last element from the array, also removing it
450 * from the array. The destructor is NOT called, even if available.
451 * Free the returned element if needed by yourself
453 void* WMPopFromArray(WMArray *array);
455 int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
457 int WMCountInArray(WMArray *array, void *item);
459 /* comparer must return:
460 * < 0 if a < b
461 * > 0 if a > b
462 * = 0 if a = b
464 void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
466 void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
468 WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
470 void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
472 void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
474 /* The following 2 functions assume that the array doesn't change between calls */
475 void* WMArrayNext(WMArray *array, WMArrayIterator *iter);
477 void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
480 /* The following 2 macros assume that the array doesn't change in the for loop */
481 #define WM_ITERATE_ARRAY(array, var, i) \
482 for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
483 var = WMArrayNext(array, &(i)))
485 #define WM_ETARETI_ARRAY(array, var, i) \
486 for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
487 var = WMArrayPrevious(array, &(i)))
489 /*..........................................................................*/
492 * Tree bags use a red-black tree for storage.
493 * Item indexes may be any integer number.
495 * Pros:
496 * O(lg n) insertion/deletion/search
497 * Good for large numbers of elements with sparse indexes
499 * Cons:
500 * O(lg n) insertion/deletion/search
501 * Slow for storing small numbers of elements
504 #define WMCreateBag(size) WMCreateTreeBag()
506 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
508 WMBag* WMCreateTreeBag(void);
510 WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
512 int WMGetBagItemCount(WMBag *bag);
514 void WMAppendBag(WMBag *bag, WMBag *other);
516 void WMPutInBag(WMBag *bag, void *item);
518 /* insert will increment the index of elements after it by 1 */
519 void WMInsertInBag(WMBag *bag, int index, void *item);
521 /* erase will remove the element from the bag,
522 * but will keep the index of the other elements unchanged */
523 int WMEraseFromBag(WMBag *bag, int index);
525 /* delete and remove will remove the elements and cause the elements
526 * after them to decrement their indexes by 1 */
527 int WMDeleteFromBag(WMBag *bag, int index);
529 int WMRemoveFromBag(WMBag *bag, void *item);
531 void* WMGetFromBag(WMBag *bag, int index);
533 void* WMReplaceInBag(WMBag *bag, int index, void *item);
535 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
537 /* comparer must return:
538 * < 0 if a < b
539 * > 0 if a > b
540 * = 0 if a = b
542 void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
544 void WMEmptyBag(WMBag *bag);
546 void WMFreeBag(WMBag *bag);
548 void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
550 int WMGetFirstInBag(WMBag *bag, void *item);
552 int WMCountInBag(WMBag *bag, void *item);
554 int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
556 void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
558 void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
560 /* The following 4 functions assume that the bag doesn't change between calls */
561 void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
563 void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
565 void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
567 int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
570 /* The following 2 macros assume that the bag doesn't change in the for loop */
571 #define WM_ITERATE_BAG(bag, var, i) \
572 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
573 var = WMBagNext(bag, &(i)))
575 #define WM_ETARETI_BAG(bag, var, i) \
576 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
577 var = WMBagPrevious(bag, &(i)))
581 /*-------------------------------------------------------------------------*/
583 /* WMData handling */
585 /* Creating/destroying data */
587 WMData* WMCreateDataWithCapacity(unsigned capacity);
589 WMData* WMCreateDataWithLength(unsigned length);
591 WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
593 /* destructor is a function called to free the data when releasing the data
594 * object, or NULL if no freeing of data is necesary. */
595 WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
596 WMFreeDataProc *destructor);
598 WMData* WMCreateDataWithData(WMData *aData);
600 WMData* WMRetainData(WMData *aData);
602 void WMReleaseData(WMData *aData);
604 /* Adjusting capacity */
606 void WMSetDataCapacity(WMData *aData, unsigned capacity);
608 void WMSetDataLength(WMData *aData, unsigned length);
610 void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
612 /* Accessing data */
614 const void* WMDataBytes(WMData *aData);
616 void WMGetDataBytes(WMData *aData, void *buffer);
618 void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
620 void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
622 WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
624 /* Testing data */
626 Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
628 unsigned WMGetDataLength(WMData *aData);
630 /* Adding data */
632 void WMAppendDataBytes(WMData *aData, void *bytes, unsigned length);
634 void WMAppendData(WMData *aData, WMData *anotherData);
636 /* Modifying data */
638 void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, void *bytes);
640 void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
642 void WMSetData(WMData *aData, WMData *anotherData);
645 void WMSetDataFormat(WMData *aData, unsigned format);
647 unsigned WMGetDataFormat(WMData *aData);
648 /* Storing data */
651 /*--------------------------------------------------------------------------*/
653 /* Generic Tree and TreeNode */
655 WMTreeNode* WMCreateTreeNode(void *data);
657 WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
659 WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
661 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
663 WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
665 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
667 void WMDestroyTreeNode(WMTreeNode *aNode);
669 void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
671 void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
673 void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
675 void* WMGetDataForTreeNode(WMTreeNode *aNode);
677 int WMGetTreeNodeDepth(WMTreeNode *aNode);
679 WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
681 /* Sort only the leaves of the passed node */
682 void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
684 /* Sort all tree recursively starting from the passed node */
685 void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
687 /* Returns the first node which matches node's data with cdata by 'match' */
688 WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
690 /* Returns first tree node that has data == cdata */
691 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(atree, NULL, cdata)
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 void WMInsertPropListArrayElement(WMPropList *plist, WMPropList *item, int index);
763 void WMAppendPropListArrayElement(WMPropList *plist, WMPropList *item);
765 void WMRemovePropListArrayElement(WMPropList *plist, int index);
767 void WMInsertPropListDictionaryEntry(WMPropList *plist, WMPropList *key,
768 WMPropList *value);
770 void WMRemovePropListDictionaryEntry(WMPropList *plist, WMPropList *key);
772 WMPropList* WMMergePropListDictionaries(WMPropList *dest, WMPropList *source);
774 WMPropList* WMRetainPropList(WMPropList *plist);
776 void WMReleasePropList(WMPropList *plist);
778 Bool WMPropListIsString(WMPropList *plist);
780 Bool WMPropListIsData(WMPropList *plist);
782 Bool WMPropListIsArray(WMPropList *plist);
784 Bool WMPropListIsDictionary(WMPropList *plist);
786 Bool WMPropListIsSimple(WMPropList *plist);
788 Bool WMPropListIsCompound(WMPropList *plist);
790 Bool WMIsPropListEqualToPropList(WMPropList *plist, WMPropList *other);
792 int WMGetPropListNumberOfElements(WMPropList *plist);
794 char* WMGetPropListString(WMPropList *plist);
796 WMData* WMGetPropListData(WMPropList *plist);
798 const unsigned char* WMGetPropListDataBytes(WMPropList *plist);
800 int WMGetPropListDataLength(WMPropList *plist);
802 WMPropList* WMGetPropListArrayElement(WMPropList *plist, int index);
804 WMPropList* WMGetPropListDictionaryEntry(WMPropList *plist, WMPropList *key);
806 WMPropList* WMGetPropListAllDictionaryKeys(WMPropList *plist);
808 char* WMGetPropListDescription(WMPropList *plist, Bool indented);
810 Bool WMSavePropListToFile(WMPropList *plist, char *path, Bool atomically);
812 WMPropList* WMShallowCopyPropList(WMPropList *plist);
814 WMPropList* WMDeepCopyPropList(WMPropList *plist);
816 /*......................................................................*/
818 WMUserDefaults* WMGetStandardUserDefaults(void);
820 WMUserDefaults* WMGetDefaultsFromPath(char *path);
822 void WMSynchronizeUserDefaults(WMUserDefaults *database);
824 void WMSaveUserDefaults(WMUserDefaults *database);
826 void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
828 /* Returns a PLArray with all keys in the user defaults database.
829 * Free the returned array with PLRelease() when no longer needed,
830 * but do not free the elements of the array! They're just references. */
831 proplist_t WMGetUDAllKeys(WMUserDefaults *database);
833 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
835 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
836 char *defaultName);
838 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
840 char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
842 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
844 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
846 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
848 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
849 char *defaultName);
851 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
852 char *defaultName);
854 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
855 char *defaultName);
857 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
858 char *defaultName);
860 proplist_t WMGetUDSearchList(WMUserDefaults *database);
862 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
864 extern char *WMUserDefaultsDidChangeNotification;
867 /*-------------------------------------------------------------------------*/
869 /* WMHost: host handling */
871 WMHost* WMGetCurrentHost();
873 WMHost* WMGetHostWithName(char* name);
875 WMHost* WMGetHostWithAddress(char* address);
877 WMHost* WMRetainHost(WMHost *hPtr);
879 void WMReleaseHost(WMHost *hPtr);
882 * Host cache management
883 * If enabled, only one object representing each host will be created, and
884 * a shared instance will be returned by all methods that return a host.
885 * Enabled by default.
887 void WMSetHostCacheEnabled(Bool flag);
889 Bool WMIsHostCacheEnabled();
891 void WMFlushHostCache();
894 * Compare hosts: Hosts are equal if they share at least one address
896 Bool WMIsHostEqualToHost(WMHost* hPtr, WMHost* anotherHost);
899 * Host names.
900 * WMGetHostName() will return first name (official) if a host has several.
901 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
903 char* WMGetHostName(WMHost* hPtr);
905 /* The returned array is R/O. Do not modify it, and do not free it! */
906 WMArray* WMGetHostNames(WMHost* hPtr);
909 * Host addresses.
910 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
911 * WMGetHostAddress() will return an arbitrary address if a host has several.
912 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
914 char* WMGetHostAddress(WMHost* hPtr);
916 /* The returned array is R/O. Do not modify it, and do not free it! */
917 WMArray* WMGetHostAddresses(WMHost* hPtr);
920 /*-------------------------------------------------------------------------*/
922 /* WMConnection functions */
924 WMConnection* WMCreateConnectionAsServerAtAddress(char *host, char *service,
925 char *protocol);
927 WMConnection* WMCreateConnectionToAddress(char *host, char *service,
928 char *protocol);
930 WMConnection* WMCreateConnectionToAddressAndNotify(char *host, char *service,
931 char *protocol);
933 void WMCloseConnection(WMConnection *cPtr);
935 void WMDestroyConnection(WMConnection *cPtr);
937 WMConnection* WMAcceptConnection(WMConnection *listener);
939 /* Release the returned data! */
940 WMData* WMGetConnectionAvailableData(WMConnection *cPtr);
942 int WMSendConnectionData(WMConnection *cPtr, WMData *data);
944 Bool WMEnqueueConnectionData(WMConnection *cPtr, WMData *data);
946 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
948 void WMSetConnectionDelegate(WMConnection *cPtr, ConnectionDelegate *delegate);
950 /* Connection info */
952 char* WMGetConnectionAddress(WMConnection *cPtr);
954 char* WMGetConnectionService(WMConnection *cPtr);
956 char* WMGetConnectionProtocol(WMConnection *cPtr);
958 Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag);
960 Bool WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag);
962 void* WMGetConnectionClientData(WMConnection *cPtr);
964 void WMSetConnectionClientData(WMConnection *cPtr, void *data);
966 unsigned int WMGetConnectionFlags(WMConnection *cPtr);
968 void WMSetConnectionFlags(WMConnection *cPtr, unsigned int flags);
970 int WMGetConnectionSocket(WMConnection *cPtr);
972 WMConnectionState WMGetConnectionState(WMConnection *cPtr);
974 WMConnectionTimeoutState WMGetConnectionTimeoutState(WMConnection *cPtr);
976 WMArray* WMGetConnectionUnsentData(WMConnection *cPtr);
978 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
982 * Passing timeout==0 in the SetTimeout functions below, will reset that
983 * timeout to its default value.
986 /* The default timeout inherited by all WMConnection operations, if none set */
987 void WMSetConnectionDefaultTimeout(unsigned int timeout);
989 /* Global timeout for all WMConnection objects, for opening a new connection */
990 void WMSetConnectionOpenTimeout(unsigned int timeout);
992 /* Connection specific timeout for sending out data */
993 void WMSetConnectionSendTimeout(WMConnection *cPtr, unsigned int timeout);
996 /* Global variables */
998 extern int WCErrorCode;
1001 /*-------------------------------------------------------------------------*/
1005 #ifdef __cplusplus
1007 #endif /* __cplusplus */
1010 #endif