Fixed a mem leak in WMList
[wmaker-crm.git] / WINGs / WINGs / WUtil.h
blobaf28a40f1753c2aea49450a827286bd3fb76bff1
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 WMDictionary;
125 typedef struct W_HashTable WMHashTable;
126 typedef struct W_UserDefaults WMUserDefaults;
127 typedef struct W_Notification WMNotification;
128 typedef struct W_NotificationQueue WMNotificationQueue;
129 typedef struct W_Host WMHost;
130 typedef struct W_Connection WMConnection;
133 typedef int WMCompareDataProc(const void *item1, const void *item2);
135 typedef void WMFreeDataProc(void *data);
137 /* Used by WMBag or WMArray for matching data */
138 typedef int WMMatchDataProc(void *item, void *cdata);
143 typedef struct {
144 int position;
145 int count;
146 } WMRange;
150 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
151 typedef struct {
152 void *table;
153 void *nextItem;
154 int index;
155 } WMHashEnumerator;
158 typedef struct {
159 /* NULL is pointer hash */
160 unsigned (*hash)(const void *);
161 /* NULL is pointer compare */
162 Bool (*keyIsEqual)(const void *, const void *);
163 /* NULL does nothing */
164 void* (*retainKey)(const void *);
165 /* NULL does nothing */
166 void (*releaseKey)(const void *);
167 } WMHashTableCallbacks;
170 typedef void *WMBagIterator;
173 #if 0
174 typedef struct {
175 char character; /* the escape character */
176 char *value; /* value to place */
177 } WMSEscapes;
178 #endif
181 /* The connection callbacks */
182 typedef struct ConnectionDelegate {
183 void *data;
185 void (*didCatchException)(struct ConnectionDelegate *self,
186 WMConnection *cPtr);
188 void (*didDie)(struct ConnectionDelegate *self, WMConnection *cPtr);
190 void (*didInitialize)(struct ConnectionDelegate *self, WMConnection *cPtr);
192 void (*didReceiveInput)(struct ConnectionDelegate *self, WMConnection *cPtr);
194 void (*didTimeout)(struct ConnectionDelegate *self, WMConnection *cPtr);
196 } ConnectionDelegate;
199 typedef void WMNotificationObserverAction(void *observerData,
200 WMNotification *notification);
204 /*......................................................................*/
206 typedef void (waborthandler)(int);
208 waborthandler* wsetabort(waborthandler*);
211 /* don't free the returned string */
212 char* wstrerror(int errnum);
214 void wmessage(const char *msg, ...);
215 void wwarning(const char *msg, ...);
216 void wfatal(const char *msg, ...);
217 void wsyserror(const char *msg, ...);
218 void wsyserrorwithcode(int error, const char *msg, ...);
220 char* wfindfile(char *paths, char *file);
222 char* wfindfileinlist(char **path_list, char *file);
224 char* wfindfileinarray(proplist_t array, char *file);
226 char* wexpandpath(char *path);
228 /* don't free the returned string */
229 char* wgethomedir();
231 void* wmalloc(size_t size);
232 void* wrealloc(void *ptr, size_t newsize);
233 void wfree(void *ptr);
236 void wrelease(void *ptr);
237 void* wretain(void *ptr);
239 char* wstrdup(char *str);
241 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
242 * str1 and str2 can be any strings including static and constant strings.
243 * str1 and str2 will not be modified.
244 * Free the returned string when you're done with it. */
245 char* wstrconcat(char *str1, char *str2);
247 /* This will append src to dst, and return dst. dst MUST be either NULL
248 * or a string that was a result of a dynamic allocation (malloc, realloc
249 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
250 * Modifies dst (no new string is created except if dst==NULL in which case
251 * it is equivalent to calling wstrdup(src) ).
252 * The returned address may be different from the original address of dst,
253 * so always assign the returned address to avoid dangling pointers. */
254 char* wstrappend(char *dst, char *src);
257 void wtokensplit(char *command, char ***argv, int *argc);
259 char* wtokennext(char *word, char **next);
261 char* wtokenjoin(char **list, int count);
263 void wtokenfree(char **tokens, int count);
265 char* wtrimspace(char *s);
269 char* wusergnusteppath();
271 char* wdefaultspathfordomain(char *domain);
273 void wusleep(unsigned int microsec);
275 #if 0
276 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
277 int count);
278 #endif
280 /*......................................................................*/
282 /* This function is used _only_ if you create a NON-GUI program.
283 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
284 * This function will handle all input/timer/idle events, then return.
287 void WHandleEvents();
289 /*......................................................................*/
292 WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
294 void WMFreeHashTable(WMHashTable *table);
296 void WMResetHashTable(WMHashTable *table);
298 void* WMHashGet(WMHashTable *table, const void *key);
300 /* put data in table, replacing already existing data and returning
301 * the old value */
302 void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
304 void WMHashRemove(WMHashTable *table, const void *key);
306 /* warning: do not manipulate the table while using these functions */
307 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
309 void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
311 void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
313 unsigned WMCountHashTable(WMHashTable *table);
318 /* some predefined callback sets */
320 extern const WMHashTableCallbacks WMIntHashCallbacks;
321 /* sizeof(keys) are <= sizeof(void*) */
323 extern const WMHashTableCallbacks WMStringHashCallbacks;
324 /* keys are strings. Strings will be copied with wstrdup()
325 * and freed with wfree() */
327 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
328 /* keys are strings, bug they are not copied */
331 /*......................................................................*/
334 * WMArray use an array to store the elements.
335 * Item indexes may be only positive integer numbers.
336 * The array cannot contain holes in it.
338 * Pros:
339 * Fast [O(1)] access to elements
340 * Fast [O(1)] push/pop
342 * Cons:
343 * A little slower [O(n)] for insertion/deletion of elements that
344 * aren't in the end
347 WMArray* WMCreateArray(int initialSize);
349 WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
351 WMArray* WMCreateArrayWithArray(WMArray *array);
353 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
355 void WMEmptyArray(WMArray *array);
357 void WMFreeArray(WMArray *array);
359 int WMGetArrayItemCount(WMArray *array);
361 /* appends other to array. other remains unchanged */
362 void WMAppendArray(WMArray *array, WMArray *other);
364 /* add will place the element at the end of the array */
365 void WMAddToArray(WMArray *array, void *item);
367 #define WMPushInArray(array, item) WMAddToArray(array, item)
369 /* insert will increment the index of elements after it by 1 */
370 void WMInsertInArray(WMArray *array, int index, void *item);
372 /* replace and set will return the old item WITHOUT calling the
373 * destructor on it even if its available. Free the returned item yourself.
375 void* WMReplaceInArray(WMArray *array, int index, void *item);
377 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
379 /* delete and remove will remove the elements and cause the elements
380 * after them to decrement their indexes by 1. Also will call the
381 * destructor on the deleted element if there's one available.
383 int WMDeleteFromArray(WMArray *array, int index);
385 int WMRemoveFromArray(WMArray *array, void *item);
387 void* WMGetFromArray(WMArray *array, int index);
389 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
391 /* pop will return the last element from the array, also removing it
392 * from the array. The destructor is NOT called, even if available.
393 * Free the returned element if needed by yourself
395 void* WMPopFromArray(WMArray *array);
397 int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
399 int WMCountInArray(WMArray *array, void *item);
401 /* comparer must return:
402 * < 0 if a < b
403 * > 0 if a > b
404 * = 0 if a = b
406 void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
408 void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
410 WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
413 /*..........................................................................*/
416 * Tree bags use a red-black tree for storage.
417 * Item indexes may be any integer number.
419 * Pros:
420 * O(lg n) insertion/deletion/search
421 * Good for large numbers of elements with sparse indexes
423 * Cons:
424 * O(lg n) insertion/deletion/search
425 * Slow for storing small numbers of elements
428 #define WMCreateBag(size) WMCreateTreeBag()
430 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
432 WMBag* WMCreateTreeBag(void);
434 WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
436 int WMGetBagItemCount(WMBag *bag);
438 void WMAppendBag(WMBag *bag, WMBag *other);
440 void WMPutInBag(WMBag *bag, void *item);
442 /* insert will increment the index of elements after it by 1 */
443 void WMInsertInBag(WMBag *bag, int index, void *item);
445 /* this is slow */
446 /* erase will remove the element from the bag,
447 * but will keep the index of the other elements unchanged */
448 int WMEraseFromBag(WMBag *bag, int index);
450 /* delete and remove will remove the elements and cause the elements
451 * after them to decrement their indexes by 1 */
452 int WMDeleteFromBag(WMBag *bag, int index);
454 int WMRemoveFromBag(WMBag *bag, void *item);
456 void* WMGetFromBag(WMBag *bag, int index);
458 void* WMReplaceInBag(WMBag *bag, int index, void *item);
460 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
462 /* comparer must return:
463 * < 0 if a < b
464 * > 0 if a > b
465 * = 0 if a = b
467 void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
469 void WMEmptyBag(WMBag *bag);
471 void WMFreeBag(WMBag *bag);
473 void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
475 int WMGetFirstInBag(WMBag *bag, void *item);
477 int WMCountInBag(WMBag *bag, void *item);
479 int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
481 void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
483 void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
485 void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
487 void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
489 void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
491 int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
494 #define WM_ITERATE_BAG(bag, var, i) \
495 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
496 var = WMBagNext(bag, &(i)))
498 #define WM_ETARETI_BAG(bag, var, i) \
499 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
500 var = WMBagPrevious(bag, &(i)))
504 /*-------------------------------------------------------------------------*/
506 /* WMData handling */
508 /* Creating/destroying data */
510 WMData* WMCreateDataWithCapacity(unsigned capacity);
512 WMData* WMCreateDataWithLength(unsigned length);
514 WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
516 /* destructor is a function called to free the data when releasing the data
517 * object, or NULL if no freeing of data is necesary. */
518 WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
519 WMFreeDataProc *destructor);
521 WMData* WMCreateDataWithData(WMData *aData);
523 WMData* WMRetainData(WMData *aData);
525 void WMReleaseData(WMData *aData);
527 /* Adjusting capacity */
529 void WMSetDataCapacity(WMData *aData, unsigned capacity);
531 void WMSetDataLength(WMData *aData, unsigned length);
533 void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
535 /* Accessing data */
537 const void* WMDataBytes(WMData *aData);
539 void WMGetDataBytes(WMData *aData, void *buffer);
541 void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
543 void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
545 WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
547 /* Testing data */
549 Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
551 unsigned WMGetDataLength(WMData *aData);
553 /* Adding data */
555 void WMAppendDataBytes(WMData *aData, void *bytes, unsigned length);
557 void WMAppendData(WMData *aData, WMData *anotherData);
559 /* Modifying data */
561 void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, void *bytes);
563 void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
565 void WMSetData(WMData *aData, WMData *anotherData);
568 void WMSetDataFormat(WMData *aData, unsigned format);
570 unsigned WMGetDataFormat(WMData *aData);
571 /* Storing data */
574 /*--------------------------------------------------------------------------*/
576 /* Generic Tree and TreeNode */
578 WMTreeNode* WMCreateTreeNode(void *data);
580 WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
582 WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
584 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
586 WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
588 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
590 void WMDestroyTreeNode(WMTreeNode *aNode);
592 void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
594 void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
596 void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
598 void* WMGetDataForTreeNode(WMTreeNode *aNode);
600 int WMGetTreeNodeDepth(WMTreeNode *aNode);
602 WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
604 /* Sort only the leaves of the passed node */
605 void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
607 /* Sort all tree recursively starting from the passed node */
608 void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
610 /* Returns the first node which matches node's data with cdata by 'match' */
611 WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
613 /* Returns first tree node that has data == cdata */
614 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(atree, NULL, cdata)
617 /*--------------------------------------------------------------------------*/
619 /* Dictionaries */
621 WMDictionary* WMCreateDictionaryFromElements(void *key, void *value, ...);
623 #define WMGetDictionaryEntryForKey(dict, key) WMHashGet(dict, key)
625 WMArray* WMGetAllDictionaryKeys(WMDictionary *dPtr);
628 /*--------------------------------------------------------------------------*/
631 WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
633 void WMReleaseNotification(WMNotification *notification);
635 WMNotification* WMRetainNotification(WMNotification *notification);
637 void* WMGetNotificationClientData(WMNotification *notification);
639 void* WMGetNotificationObject(WMNotification *notification);
641 const char* WMGetNotificationName(WMNotification *notification);
644 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
645 void *observer, const char *name, void *object);
647 void WMPostNotification(WMNotification *notification);
649 void WMRemoveNotificationObserver(void *observer);
651 void WMRemoveNotificationObserverWithName(void *observer, const char *name,
652 void *object);
654 void WMPostNotificationName(const char *name, void *object, void *clientData);
656 WMNotificationQueue* WMGetDefaultNotificationQueue(void);
658 WMNotificationQueue* WMCreateNotificationQueue(void);
660 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
661 WMNotification *notification,
662 unsigned mask);
664 void WMEnqueueNotification(WMNotificationQueue *queue,
665 WMNotification *notification,
666 WMPostingStyle postingStyle);
668 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
669 WMNotification *notification,
670 WMPostingStyle postingStyle,
671 unsigned coalesceMask);
674 /*......................................................................*/
676 WMUserDefaults* WMGetStandardUserDefaults(void);
678 WMUserDefaults* WMGetDefaultsFromPath(char *path);
680 void WMSynchronizeUserDefaults(WMUserDefaults *database);
682 void WMSaveUserDefaults(WMUserDefaults *database);
684 void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
686 /* Returns a PLArray with all keys in the user defaults database.
687 * Free the returned array with PLRelease() when no longer needed,
688 * but do not free the elements of the array! They're just references. */
689 proplist_t WMGetUDAllKeys(WMUserDefaults *database);
691 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
693 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
694 char *defaultName);
696 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
698 char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
700 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
702 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
704 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
706 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
707 char *defaultName);
709 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
710 char *defaultName);
712 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
713 char *defaultName);
715 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
716 char *defaultName);
718 proplist_t WMGetUDSearchList(WMUserDefaults *database);
720 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
722 extern char *WMUserDefaultsDidChangeNotification;
725 /*-------------------------------------------------------------------------*/
727 /* WMHost: host handling */
729 WMHost* WMGetCurrentHost();
731 WMHost* WMGetHostWithName(char* name);
733 WMHost* WMGetHostWithAddress(char* address);
735 WMHost* WMRetainHost(WMHost *hPtr);
737 void WMReleaseHost(WMHost *hPtr);
740 * Host cache management
741 * If enabled, only one object representing each host will be created, and
742 * a shared instance will be returned by all methods that return a host.
743 * Enabled by default.
745 void WMSetHostCacheEnabled(Bool flag);
747 Bool WMIsHostCacheEnabled();
749 void WMFlushHostCache();
752 * Compare hosts: Hosts are equal if they share at least one address
754 Bool WMIsHostEqualToHost(WMHost* hPtr, WMHost* anotherHost);
757 * Host names.
758 * WMGetHostName() will return first name (official) if a host has several.
759 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
761 char* WMGetHostName(WMHost* hPtr);
763 /* The returned array is R/O. Do not modify it, and do not free it! */
764 WMArray* WMGetHostNames(WMHost* hPtr);
767 * Host addresses.
768 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
769 * WMGetHostAddress() will return an arbitrary address if a host has several.
770 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
772 char* WMGetHostAddress(WMHost* hPtr);
774 /* The returned array is R/O. Do not modify it, and do not free it! */
775 WMArray* WMGetHostAddresses(WMHost* hPtr);
778 /*-------------------------------------------------------------------------*/
780 /* WMConnection functions */
782 WMConnection* WMCreateConnectionAsServerAtAddress(char *host, char *service,
783 char *protocol);
785 WMConnection* WMCreateConnectionToAddress(char *host, char *service,
786 char *protocol);
788 WMConnection* WMCreateConnectionToAddressAndNotify(char *host, char *service,
789 char *protocol);
791 void WMCloseConnection(WMConnection *cPtr);
793 void WMDestroyConnection(WMConnection *cPtr);
795 WMConnection* WMAcceptConnection(WMConnection *listener);
797 /* Release the returned data! */
798 WMData* WMGetConnectionAvailableData(WMConnection *cPtr);
800 int WMSendConnectionData(WMConnection *cPtr, WMData *data);
802 Bool WMEnqueueConnectionData(WMConnection *cPtr, WMData *data);
804 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
806 void WMSetConnectionDelegate(WMConnection *cPtr, ConnectionDelegate *delegate);
808 /* Connection info */
810 char* WMGetConnectionAddress(WMConnection *cPtr);
812 char* WMGetConnectionService(WMConnection *cPtr);
814 char* WMGetConnectionProtocol(WMConnection *cPtr);
816 Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag);
818 Bool WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag);
820 void* WMGetConnectionClientData(WMConnection *cPtr);
822 void WMSetConnectionClientData(WMConnection *cPtr, void *data);
824 unsigned int WMGetConnectionFlags(WMConnection *cPtr);
826 void WMSetConnectionFlags(WMConnection *cPtr, unsigned int flags);
828 int WMGetConnectionSocket(WMConnection *cPtr);
830 WMConnectionState WMGetConnectionState(WMConnection *cPtr);
832 WMConnectionTimeoutState WMGetConnectionTimeoutState(WMConnection *cPtr);
834 WMArray* WMGetConnectionUnsentData(WMConnection *cPtr);
836 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
840 * Passing timeout==0 in the SetTimeout functions below, will reset that
841 * timeout to its default value.
844 /* The default timeout inherited by all WMConnection operations, if none set */
845 void WMSetConnectionDefaultTimeout(unsigned int timeout);
847 /* Global timeout for all WMConnection objects, for opening a new connection */
848 void WMSetConnectionOpenTimeout(unsigned int timeout);
850 /* Connection specific timeout for sending out data */
851 void WMSetConnectionSendTimeout(WMConnection *cPtr, unsigned int timeout);
854 /* Global variables */
856 extern int WCErrorCode;
859 /*-------------------------------------------------------------------------*/
863 #ifdef __cplusplus
865 #endif /* __cplusplus */
868 #endif