- Made all changes for moving WINGs headers in the WINGs subdirectory.
[wmaker-crm.git] / WINGs / WINGs / WUtil.h
blobea5bb4c94f8159698d81b35cce77f8c1140b132e
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_TreeNode WMTree;
125 typedef struct W_HashTable WMDictionary;
126 typedef struct W_HashTable WMHashTable;
127 typedef struct W_UserDefaults WMUserDefaults;
128 typedef struct W_Notification WMNotification;
129 typedef struct W_NotificationQueue WMNotificationQueue;
130 typedef struct W_Host WMHost;
131 typedef struct W_Connection WMConnection;
134 typedef int WMCompareDataProc(const void *item1, const void *item2);
136 typedef void WMFreeDataProc(void *data);
138 /* Used by WMBag or WMArray for matching data */
139 typedef int WMMatchDataProc(void *item, void *cdata);
144 typedef struct {
145 int position;
146 int count;
147 } WMRange;
151 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
152 typedef struct {
153 void *table;
154 void *nextItem;
155 int index;
156 } WMHashEnumerator;
159 typedef 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 void *WMBagIterator;
174 #if 0
175 typedef struct {
176 char character; /* the escape character */
177 char *value; /* value to place */
178 } WMSEscapes;
179 #endif
182 /* The connection callbacks */
183 typedef struct ConnectionDelegate {
184 void *data;
186 void (*didCatchException)(struct ConnectionDelegate *self,
187 WMConnection *cPtr);
189 void (*didDie)(struct ConnectionDelegate *self, WMConnection *cPtr);
191 void (*didInitialize)(struct ConnectionDelegate *self, WMConnection *cPtr);
193 void (*didReceiveInput)(struct ConnectionDelegate *self, WMConnection *cPtr);
195 void (*didTimeout)(struct ConnectionDelegate *self, WMConnection *cPtr);
197 } ConnectionDelegate;
200 typedef void WMNotificationObserverAction(void *observerData,
201 WMNotification *notification);
205 /*......................................................................*/
207 typedef void (waborthandler)(int);
209 waborthandler* wsetabort(waborthandler*);
212 /* don't free the returned string */
213 char* wstrerror(int errnum);
215 void wmessage(const char *msg, ...);
216 void wwarning(const char *msg, ...);
217 void wfatal(const char *msg, ...);
218 void wsyserror(const char *msg, ...);
219 void wsyserrorwithcode(int error, const char *msg, ...);
221 char* wfindfile(char *paths, char *file);
223 char* wfindfileinlist(char **path_list, char *file);
225 char* wfindfileinarray(proplist_t array, char *file);
227 char* wexpandpath(char *path);
229 /* don't free the returned string */
230 char* wgethomedir();
232 void* wmalloc(size_t size);
233 void* wrealloc(void *ptr, size_t newsize);
234 void wfree(void *ptr);
237 void wrelease(void *ptr);
238 void* wretain(void *ptr);
240 char* wstrdup(char *str);
242 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
243 * str1 and str2 can be any strings including static and constant strings.
244 * str1 and str2 will not be modified.
245 * Free the returned string when you're done with it. */
246 char* wstrconcat(char *str1, char *str2);
248 /* This will append src to dst, and return dst. dst MUST be either NULL
249 * or a string that was a result of a dynamic allocation (malloc, realloc
250 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
251 * Modifies dst (no new string is created except if dst==NULL in which case
252 * it is equivalent to calling wstrdup(src) ).
253 * The returned address may be different from the original address of dst,
254 * so always assign the returned address to avoid dangling pointers. */
255 char* wstrappend(char *dst, char *src);
258 void wtokensplit(char *command, char ***argv, int *argc);
260 char* wtokennext(char *word, char **next);
262 char* wtokenjoin(char **list, int count);
264 void wtokenfree(char **tokens, int count);
266 char* wtrimspace(char *s);
270 char* wusergnusteppath();
272 char* wdefaultspathfordomain(char *domain);
274 void wusleep(unsigned int microsec);
276 #if 0
277 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
278 int count);
279 #endif
281 /*......................................................................*/
283 /* This function is used _only_ if you create a NON-GUI program.
284 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
285 * This function will handle all input/timer/idle events, then return.
288 void WHandleEvents();
290 /*......................................................................*/
293 WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
295 void WMFreeHashTable(WMHashTable *table);
297 void WMResetHashTable(WMHashTable *table);
299 void* WMHashGet(WMHashTable *table, const void *key);
301 /* put data in table, replacing already existing data and returning
302 * the old value */
303 void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
305 void WMHashRemove(WMHashTable *table, const void *key);
307 /* warning: do not manipulate the table while using these functions */
308 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
310 void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
312 void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
314 unsigned WMCountHashTable(WMHashTable *table);
319 /* some predefined callback sets */
321 extern const WMHashTableCallbacks WMIntHashCallbacks;
322 /* sizeof(keys) are <= sizeof(void*) */
324 extern const WMHashTableCallbacks WMStringHashCallbacks;
325 /* keys are strings. Strings will be copied with wstrdup()
326 * and freed with wfree() */
328 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
329 /* keys are strings, bug they are not copied */
332 /*......................................................................*/
335 * WMArray use an array to store the elements.
336 * Item indexes may be only positive integer numbers.
337 * The array cannot contain holes in it.
339 * Pros:
340 * Fast [O(1)] access to elements
341 * Fast [O(1)] push/pop
343 * Cons:
344 * A little slower [O(n)] for insertion/deletion of elements that
345 * aren't in the end
348 WMArray* WMCreateArray(int initialSize);
350 WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
352 WMArray* WMCreateArrayWithArray(WMArray *array);
354 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
356 void WMEmptyArray(WMArray *array);
358 void WMFreeArray(WMArray *array);
360 int WMGetArrayItemCount(WMArray *array);
362 /* appends other to array. other remains unchanged */
363 void WMAppendArray(WMArray *array, WMArray *other);
365 /* add will place the element at the end of the array */
366 void WMAddToArray(WMArray *array, void *item);
368 #define WMPushInArray(array, item) WMAddToArray(array, item)
370 /* insert will increment the index of elements after it by 1 */
371 void WMInsertInArray(WMArray *array, int index, void *item);
373 /* replace and set will return the old item WITHOUT calling the
374 * destructor on it even if its available. Free the returned item yourself.
376 void* WMReplaceInArray(WMArray *array, int index, void *item);
378 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
380 /* delete and remove will remove the elements and cause the elements
381 * after them to decrement their indexes by 1. Also will call the
382 * destructor on the deleted element if there's one available.
384 int WMDeleteFromArray(WMArray *array, int index);
386 int WMRemoveFromArray(WMArray *array, void *item);
388 void* WMGetFromArray(WMArray *array, int index);
390 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
392 /* pop will return the last element from the array, also removing it
393 * from the array. The destructor is NOT called, even if available.
394 * Free the returned element if needed by yourself
396 void* WMPopFromArray(WMArray *array);
398 int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
400 int WMCountInArray(WMArray *array, void *item);
402 /* comparer must return:
403 * < 0 if a < b
404 * > 0 if a > b
405 * = 0 if a = b
407 void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
409 void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
411 WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
414 /*..........................................................................*/
417 * Tree bags use a red-black tree for storage.
418 * Item indexes may be any integer number.
420 * Pros:
421 * O(lg n) insertion/deletion/search
422 * Good for large numbers of elements with sparse indexes
424 * Cons:
425 * O(lg n) insertion/deletion/search
426 * Slow for storing small numbers of elements
429 #define WMCreateBag(size) WMCreateTreeBag()
431 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
433 WMBag* WMCreateTreeBag(void);
435 WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
437 int WMGetBagItemCount(WMBag *bag);
439 void WMAppendBag(WMBag *bag, WMBag *other);
441 void WMPutInBag(WMBag *bag, void *item);
443 /* insert will increment the index of elements after it by 1 */
444 void WMInsertInBag(WMBag *bag, int index, void *item);
446 /* this is slow */
447 /* erase will remove the element from the bag,
448 * but will keep the index of the other elements unchanged */
449 int WMEraseFromBag(WMBag *bag, int index);
451 /* delete and remove will remove the elements and cause the elements
452 * after them to decrement their indexes by 1 */
453 int WMDeleteFromBag(WMBag *bag, int index);
455 int WMRemoveFromBag(WMBag *bag, void *item);
457 void* WMGetFromBag(WMBag *bag, int index);
459 void* WMReplaceInBag(WMBag *bag, int index, void *item);
461 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
463 /* comparer must return:
464 * < 0 if a < b
465 * > 0 if a > b
466 * = 0 if a = b
468 void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
470 void WMEmptyBag(WMBag *bag);
472 void WMFreeBag(WMBag *bag);
474 void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
476 int WMGetFirstInBag(WMBag *bag, void *item);
478 int WMCountInBag(WMBag *bag, void *item);
480 int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
482 void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
484 void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
486 void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
488 void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
490 void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
492 int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
495 #define WM_ITERATE_BAG(bag, var, i) \
496 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
497 var = WMBagNext(bag, &(i)))
499 #define WM_ETARETI_BAG(bag, var, i) \
500 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
501 var = WMBagPrevious(bag, &(i)))
505 /*-------------------------------------------------------------------------*/
507 /* WMData handling */
509 /* Creating/destroying data */
511 WMData* WMCreateDataWithCapacity(unsigned capacity);
513 WMData* WMCreateDataWithLength(unsigned length);
515 WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
517 /* destructor is a function called to free the data when releasing the data
518 * object, or NULL if no freeing of data is necesary. */
519 WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
520 WMFreeDataProc *destructor);
522 WMData* WMCreateDataWithData(WMData *aData);
524 WMData* WMRetainData(WMData *aData);
526 void WMReleaseData(WMData *aData);
528 /* Adjusting capacity */
530 void WMSetDataCapacity(WMData *aData, unsigned capacity);
532 void WMSetDataLength(WMData *aData, unsigned length);
534 void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
536 /* Accessing data */
538 const void* WMDataBytes(WMData *aData);
540 void WMGetDataBytes(WMData *aData, void *buffer);
542 void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
544 void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
546 WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
548 /* Testing data */
550 Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
552 unsigned WMGetDataLength(WMData *aData);
554 /* Adding data */
556 void WMAppendDataBytes(WMData *aData, void *bytes, unsigned length);
558 void WMAppendData(WMData *aData, WMData *anotherData);
560 /* Modifying data */
562 void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, void *bytes);
564 void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
566 void WMSetData(WMData *aData, WMData *anotherData);
569 void WMSetDataFormat(WMData *aData, unsigned format);
571 unsigned WMGetDataFormat(WMData *aData);
572 /* Storing data */
575 /*--------------------------------------------------------------------------*/
577 /* Generic Tree and TreeNode */
579 WMTreeNode* WMCreateTreeNode(void *data);
581 WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
583 WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
585 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
587 WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
589 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
591 void WMDestroyTreeNode(WMTreeNode *aNode);
593 void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
595 void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
597 void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
599 void* WMGetDataForTreeNode(WMTreeNode *aNode);
601 int WMGetTreeNodeDepth(WMTreeNode *aNode);
603 WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
605 /* Sort only the leaves of the passed node */
606 void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
608 /* Sort all tree recursively starting from the passed node */
609 void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
611 /* Returns the first node which matches node's data with cdata by 'match' */
612 WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
614 /* Returns first tree node that has data == cdata */
615 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(atree, NULL, cdata)
618 /*--------------------------------------------------------------------------*/
620 /* Dictionaries */
622 WMDictionary* WMCreateDictionaryFromElements(void *key, void *value, ...);
624 #define WMGetDictionaryEntryForKey(dict, key) WMHashGet(dict, key)
626 WMArray* WMGetAllDictionaryKeys(WMDictionary *dPtr);
629 /*--------------------------------------------------------------------------*/
632 WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
634 void WMReleaseNotification(WMNotification *notification);
636 WMNotification* WMRetainNotification(WMNotification *notification);
638 void* WMGetNotificationClientData(WMNotification *notification);
640 void* WMGetNotificationObject(WMNotification *notification);
642 const char* WMGetNotificationName(WMNotification *notification);
645 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
646 void *observer, const char *name, void *object);
648 void WMPostNotification(WMNotification *notification);
650 void WMRemoveNotificationObserver(void *observer);
652 void WMRemoveNotificationObserverWithName(void *observer, const char *name,
653 void *object);
655 void WMPostNotificationName(const char *name, void *object, void *clientData);
657 WMNotificationQueue* WMGetDefaultNotificationQueue(void);
659 WMNotificationQueue* WMCreateNotificationQueue(void);
661 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
662 WMNotification *notification,
663 unsigned mask);
665 void WMEnqueueNotification(WMNotificationQueue *queue,
666 WMNotification *notification,
667 WMPostingStyle postingStyle);
669 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
670 WMNotification *notification,
671 WMPostingStyle postingStyle,
672 unsigned coalesceMask);
675 /*......................................................................*/
677 WMUserDefaults* WMGetStandardUserDefaults(void);
679 WMUserDefaults* WMGetDefaultsFromPath(char *path);
681 void WMSynchronizeUserDefaults(WMUserDefaults *database);
683 void WMSaveUserDefaults(WMUserDefaults *database);
685 void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
687 /* Returns a PLArray with all keys in the user defaults database.
688 * Free the returned array with PLRelease() when no longer needed,
689 * but do not free the elements of the array! They're just references. */
690 proplist_t WMGetUDAllKeys(WMUserDefaults *database);
692 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
694 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
695 char *defaultName);
697 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
699 char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
701 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
703 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
705 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
707 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
708 char *defaultName);
710 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
711 char *defaultName);
713 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
714 char *defaultName);
716 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
717 char *defaultName);
719 proplist_t WMGetUDSearchList(WMUserDefaults *database);
721 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
723 extern char *WMUserDefaultsDidChangeNotification;
726 /*-------------------------------------------------------------------------*/
728 /* WMHost: host handling */
730 WMHost* WMGetCurrentHost();
732 WMHost* WMGetHostWithName(char* name);
734 WMHost* WMGetHostWithAddress(char* address);
736 WMHost* WMRetainHost(WMHost *hPtr);
738 void WMReleaseHost(WMHost *hPtr);
741 * Host cache management
742 * If enabled, only one object representing each host will be created, and
743 * a shared instance will be returned by all methods that return a host.
744 * Enabled by default.
746 void WMSetHostCacheEnabled(Bool flag);
748 Bool WMIsHostCacheEnabled();
750 void WMFlushHostCache();
753 * Compare hosts: Hosts are equal if they share at least one address
755 Bool WMIsHostEqualToHost(WMHost* hPtr, WMHost* anotherHost);
758 * Host names.
759 * WMGetHostName() will return first name (official) if a host has several.
760 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
762 char* WMGetHostName(WMHost* hPtr);
764 /* The returned array is R/O. Do not modify it, and do not free it! */
765 WMArray* WMGetHostNames(WMHost* hPtr);
768 * Host addresses.
769 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
770 * WMGetHostAddress() will return an arbitrary address if a host has several.
771 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
773 char* WMGetHostAddress(WMHost* hPtr);
775 /* The returned array is R/O. Do not modify it, and do not free it! */
776 WMArray* WMGetHostAddresses(WMHost* hPtr);
779 /*-------------------------------------------------------------------------*/
781 /* WMConnection functions */
783 WMConnection* WMCreateConnectionAsServerAtAddress(char *host, char *service,
784 char *protocol);
786 WMConnection* WMCreateConnectionToAddress(char *host, char *service,
787 char *protocol);
789 WMConnection* WMCreateConnectionToAddressAndNotify(char *host, char *service,
790 char *protocol);
792 void WMCloseConnection(WMConnection *cPtr);
794 void WMDestroyConnection(WMConnection *cPtr);
796 WMConnection* WMAcceptConnection(WMConnection *listener);
798 /* Release the returned data! */
799 WMData* WMGetConnectionAvailableData(WMConnection *cPtr);
801 int WMSendConnectionData(WMConnection *cPtr, WMData *data);
803 Bool WMEnqueueConnectionData(WMConnection *cPtr, WMData *data);
805 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
807 void WMSetConnectionDelegate(WMConnection *cPtr, ConnectionDelegate *delegate);
809 /* Connection info */
811 char* WMGetConnectionAddress(WMConnection *cPtr);
813 char* WMGetConnectionService(WMConnection *cPtr);
815 char* WMGetConnectionProtocol(WMConnection *cPtr);
817 Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag);
819 Bool WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag);
821 void* WMGetConnectionClientData(WMConnection *cPtr);
823 void WMSetConnectionClientData(WMConnection *cPtr, void *data);
825 unsigned int WMGetConnectionFlags(WMConnection *cPtr);
827 void WMSetConnectionFlags(WMConnection *cPtr, unsigned int flags);
829 int WMGetConnectionSocket(WMConnection *cPtr);
831 WMConnectionState WMGetConnectionState(WMConnection *cPtr);
833 WMConnectionTimeoutState WMGetConnectionTimeoutState(WMConnection *cPtr);
835 WMArray* WMGetConnectionUnsentData(WMConnection *cPtr);
837 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
841 * Passing timeout==0 in the SetTimeout functions below, will reset that
842 * timeout to its default value.
845 /* The default timeout inherited by all WMConnection operations, if none set */
846 void WMSetConnectionDefaultTimeout(unsigned int timeout);
848 /* Global timeout for all WMConnection objects, for opening a new connection */
849 void WMSetConnectionOpenTimeout(unsigned int timeout);
851 /* Connection specific timeout for sending out data */
852 void WMSetConnectionSendTimeout(WMConnection *cPtr, unsigned int timeout);
855 /* Global variables */
857 extern int WCErrorCode;
860 /*-------------------------------------------------------------------------*/
864 #ifdef __cplusplus
866 #endif /* __cplusplus */
869 #endif