- Now when Window Maker calls wmsetbg to set the background, it will pass the
[wmaker-crm.git] / WINGs / WINGs / WUtil.h
blob085450f0ff20e063baf2505deb02167a1fac25ca
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;
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;
157 #define wmkrange(position, count) (WMRange){(position), (count)}
161 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
162 typedef struct {
163 void *table;
164 void *nextItem;
165 int index;
166 } WMHashEnumerator;
169 typedef struct {
170 /* NULL is pointer hash */
171 unsigned (*hash)(const void *);
172 /* NULL is pointer compare */
173 Bool (*keyIsEqual)(const void *, const void *);
174 /* NULL does nothing */
175 void* (*retainKey)(const void *);
176 /* NULL does nothing */
177 void (*releaseKey)(const void *);
178 } WMHashTableCallbacks;
181 typedef void *WMBagIterator;
184 #if 0
185 typedef struct {
186 char character; /* the escape character */
187 char *value; /* value to place */
188 } WMSEscapes;
189 #endif
192 /* The connection callbacks */
193 typedef struct ConnectionDelegate {
194 void *data;
196 void (*didCatchException)(struct ConnectionDelegate *self,
197 WMConnection *cPtr);
199 void (*didDie)(struct ConnectionDelegate *self, WMConnection *cPtr);
201 void (*didInitialize)(struct ConnectionDelegate *self, WMConnection *cPtr);
203 void (*didReceiveInput)(struct ConnectionDelegate *self, WMConnection *cPtr);
205 void (*didTimeout)(struct ConnectionDelegate *self, WMConnection *cPtr);
207 } ConnectionDelegate;
210 typedef void WMNotificationObserverAction(void *observerData,
211 WMNotification *notification);
215 /*......................................................................*/
217 typedef void (waborthandler)(int);
219 waborthandler* wsetabort(waborthandler*);
222 /* don't free the returned string */
223 char* wstrerror(int errnum);
225 void wmessage(const char *msg, ...);
226 void wwarning(const char *msg, ...);
227 void wfatal(const char *msg, ...);
228 void wsyserror(const char *msg, ...);
229 void wsyserrorwithcode(int error, const char *msg, ...);
231 char* wfindfile(char *paths, char *file);
233 char* wfindfileinlist(char **path_list, char *file);
235 char* wfindfileinarray(proplist_t array, char *file);
237 char* wexpandpath(char *path);
239 /* don't free the returned string */
240 char* wgethomedir();
242 void* wmalloc(size_t size);
243 void* wrealloc(void *ptr, size_t newsize);
244 void wfree(void *ptr);
247 void wrelease(void *ptr);
248 void* wretain(void *ptr);
250 char* wstrdup(char *str);
252 /* Concatenate str1 with str2 and return that in a newly malloc'ed string.
253 * str1 and str2 can be any strings including static and constant strings.
254 * str1 and str2 will not be modified.
255 * Free the returned string when you're done with it. */
256 char* wstrconcat(char *str1, char *str2);
258 /* This will append src to dst, and return dst. dst MUST be either NULL
259 * or a string that was a result of a dynamic allocation (malloc, realloc
260 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
261 * Modifies dst (no new string is created except if dst==NULL in which case
262 * it is equivalent to calling wstrdup(src) ).
263 * The returned address may be different from the original address of dst,
264 * so always assign the returned address to avoid dangling pointers. */
265 char* wstrappend(char *dst, char *src);
268 void wtokensplit(char *command, char ***argv, int *argc);
270 char* wtokennext(char *word, char **next);
272 char* wtokenjoin(char **list, int count);
274 void wtokenfree(char **tokens, int count);
276 char* wtrimspace(char *s);
280 char* wusergnusteppath();
282 char* wdefaultspathfordomain(char *domain);
284 void wusleep(unsigned int microsec);
286 #if 0
287 int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
288 int count);
289 #endif
291 /*......................................................................*/
293 /* Event handlers: timer, idle, input */
295 WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback *callback,
296 void *cdata);
298 WMHandlerID WMAddPersistentTimerHandler(int milliseconds, WMCallback *callback,
299 void *cdata);
301 void WMDeleteTimerWithClientData(void *cdata);
303 void WMDeleteTimerHandler(WMHandlerID handlerID);
305 WMHandlerID WMAddIdleHandler(WMCallback *callback, void *cdata);
307 void WMDeleteIdleHandler(WMHandlerID handlerID);
309 WMHandlerID WMAddInputHandler(int fd, int condition, WMInputProc *proc,
310 void *clientData);
312 void WMDeleteInputHandler(WMHandlerID handlerID);
315 /* This function is used _only_ if you create a non-GUI program.
316 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
317 * This function will handle all input/timer/idle events, then return.
320 void WHandleEvents();
322 /*......................................................................*/
325 WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
327 void WMFreeHashTable(WMHashTable *table);
329 void WMResetHashTable(WMHashTable *table);
331 void* WMHashGet(WMHashTable *table, const void *key);
333 /* put data in table, replacing already existing data and returning
334 * the old value */
335 void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
337 void WMHashRemove(WMHashTable *table, const void *key);
339 /* warning: do not manipulate the table while using these functions */
340 WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
342 void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
344 void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
346 unsigned WMCountHashTable(WMHashTable *table);
351 /* some predefined callback sets */
353 extern const WMHashTableCallbacks WMIntHashCallbacks;
354 /* sizeof(keys) are <= sizeof(void*) */
356 extern const WMHashTableCallbacks WMStringHashCallbacks;
357 /* keys are strings. Strings will be copied with wstrdup()
358 * and freed with wfree() */
360 extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
361 /* keys are strings, bug they are not copied */
364 /*......................................................................*/
367 * WMArray use an array to store the elements.
368 * Item indexes may be only positive integer numbers.
369 * The array cannot contain holes in it.
371 * Pros:
372 * Fast [O(1)] access to elements
373 * Fast [O(1)] push/pop
375 * Cons:
376 * A little slower [O(n)] for insertion/deletion of elements that
377 * aren't in the end
380 WMArray* WMCreateArray(int initialSize);
382 WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
384 WMArray* WMCreateArrayWithArray(WMArray *array);
386 #define WMDuplicateArray(array) WMCreateArrayWithArray(array)
388 void WMEmptyArray(WMArray *array);
390 void WMFreeArray(WMArray *array);
392 int WMGetArrayItemCount(WMArray *array);
394 /* appends other to array. other remains unchanged */
395 void WMAppendArray(WMArray *array, WMArray *other);
397 /* add will place the element at the end of the array */
398 void WMAddToArray(WMArray *array, void *item);
400 #define WMPushInArray(array, item) WMAddToArray(array, item)
402 /* insert will increment the index of elements after it by 1 */
403 void WMInsertInArray(WMArray *array, int index, void *item);
405 /* replace and set will return the old item WITHOUT calling the
406 * destructor on it even if its available. Free the returned item yourself.
408 void* WMReplaceInArray(WMArray *array, int index, void *item);
410 #define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
412 /* delete and remove will remove the elements and cause the elements
413 * after them to decrement their indexes by 1. Also will call the
414 * destructor on the deleted element if there's one available.
416 int WMDeleteFromArray(WMArray *array, int index);
418 int WMRemoveFromArray(WMArray *array, void *item);
420 void* WMGetFromArray(WMArray *array, int index);
422 #define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
424 /* pop will return the last element from the array, also removing it
425 * from the array. The destructor is NOT called, even if available.
426 * Free the returned element if needed by yourself
428 void* WMPopFromArray(WMArray *array);
430 int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
432 int WMCountInArray(WMArray *array, void *item);
434 /* comparer must return:
435 * < 0 if a < b
436 * > 0 if a > b
437 * = 0 if a = b
439 void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
441 void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
443 WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
446 /*..........................................................................*/
449 * Tree bags use a red-black tree for storage.
450 * Item indexes may be any integer number.
452 * Pros:
453 * O(lg n) insertion/deletion/search
454 * Good for large numbers of elements with sparse indexes
456 * Cons:
457 * O(lg n) insertion/deletion/search
458 * Slow for storing small numbers of elements
461 #define WMCreateBag(size) WMCreateTreeBag()
463 #define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
465 WMBag* WMCreateTreeBag(void);
467 WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
469 int WMGetBagItemCount(WMBag *bag);
471 void WMAppendBag(WMBag *bag, WMBag *other);
473 void WMPutInBag(WMBag *bag, void *item);
475 /* insert will increment the index of elements after it by 1 */
476 void WMInsertInBag(WMBag *bag, int index, void *item);
478 /* erase will remove the element from the bag,
479 * but will keep the index of the other elements unchanged */
480 int WMEraseFromBag(WMBag *bag, int index);
482 /* delete and remove will remove the elements and cause the elements
483 * after them to decrement their indexes by 1 */
484 int WMDeleteFromBag(WMBag *bag, int index);
486 int WMRemoveFromBag(WMBag *bag, void *item);
488 void* WMGetFromBag(WMBag *bag, int index);
490 void* WMReplaceInBag(WMBag *bag, int index, void *item);
492 #define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
494 /* comparer must return:
495 * < 0 if a < b
496 * > 0 if a > b
497 * = 0 if a = b
499 void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
501 void WMEmptyBag(WMBag *bag);
503 void WMFreeBag(WMBag *bag);
505 void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
507 int WMGetFirstInBag(WMBag *bag, void *item);
509 int WMCountInBag(WMBag *bag, void *item);
511 int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
513 void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
515 void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
517 void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
519 void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
521 void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
523 int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
526 #define WM_ITERATE_BAG(bag, var, i) \
527 for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
528 var = WMBagNext(bag, &(i)))
530 #define WM_ETARETI_BAG(bag, var, i) \
531 for (var = WMBagLast(bag, &(i)); (i) != NULL; \
532 var = WMBagPrevious(bag, &(i)))
536 /*-------------------------------------------------------------------------*/
538 /* WMData handling */
540 /* Creating/destroying data */
542 WMData* WMCreateDataWithCapacity(unsigned capacity);
544 WMData* WMCreateDataWithLength(unsigned length);
546 WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
548 /* destructor is a function called to free the data when releasing the data
549 * object, or NULL if no freeing of data is necesary. */
550 WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
551 WMFreeDataProc *destructor);
553 WMData* WMCreateDataWithData(WMData *aData);
555 WMData* WMRetainData(WMData *aData);
557 void WMReleaseData(WMData *aData);
559 /* Adjusting capacity */
561 void WMSetDataCapacity(WMData *aData, unsigned capacity);
563 void WMSetDataLength(WMData *aData, unsigned length);
565 void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
567 /* Accessing data */
569 const void* WMDataBytes(WMData *aData);
571 void WMGetDataBytes(WMData *aData, void *buffer);
573 void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
575 void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
577 WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
579 /* Testing data */
581 Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
583 unsigned WMGetDataLength(WMData *aData);
585 /* Adding data */
587 void WMAppendDataBytes(WMData *aData, void *bytes, unsigned length);
589 void WMAppendData(WMData *aData, WMData *anotherData);
591 /* Modifying data */
593 void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, void *bytes);
595 void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
597 void WMSetData(WMData *aData, WMData *anotherData);
600 void WMSetDataFormat(WMData *aData, unsigned format);
602 unsigned WMGetDataFormat(WMData *aData);
603 /* Storing data */
606 /*--------------------------------------------------------------------------*/
608 /* Generic Tree and TreeNode */
610 WMTreeNode* WMCreateTreeNode(void *data);
612 WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
614 WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
616 #define WMAddItemToTree(parent, item) WMInsertItemInTree(parent, -1, item)
618 WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
620 #define WMAddNodeToTree(parent, aNode) WMInsertNodeInTree(parent, -1, aNode)
622 void WMDestroyTreeNode(WMTreeNode *aNode);
624 void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
626 void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
628 void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
630 void* WMGetDataForTreeNode(WMTreeNode *aNode);
632 int WMGetTreeNodeDepth(WMTreeNode *aNode);
634 WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
636 /* Sort only the leaves of the passed node */
637 void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
639 /* Sort all tree recursively starting from the passed node */
640 void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
642 /* Returns the first node which matches node's data with cdata by 'match' */
643 WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
645 /* Returns first tree node that has data == cdata */
646 #define WMGetFirstInTree(aTree, cdata) WMFindInTree(atree, NULL, cdata)
649 /*--------------------------------------------------------------------------*/
651 /* Dictionaries */
653 WMDictionary* WMCreateDictionaryFromElements(void *key, void *value, ...);
655 #define WMGetDictionaryEntryForKey(dict, key) WMHashGet(dict, key)
657 WMArray* WMGetAllDictionaryKeys(WMDictionary *dPtr);
660 /*--------------------------------------------------------------------------*/
663 WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
665 void WMReleaseNotification(WMNotification *notification);
667 WMNotification* WMRetainNotification(WMNotification *notification);
669 void* WMGetNotificationClientData(WMNotification *notification);
671 void* WMGetNotificationObject(WMNotification *notification);
673 const char* WMGetNotificationName(WMNotification *notification);
676 void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
677 void *observer, const char *name, void *object);
679 void WMPostNotification(WMNotification *notification);
681 void WMRemoveNotificationObserver(void *observer);
683 void WMRemoveNotificationObserverWithName(void *observer, const char *name,
684 void *object);
686 void WMPostNotificationName(const char *name, void *object, void *clientData);
688 WMNotificationQueue* WMGetDefaultNotificationQueue(void);
690 WMNotificationQueue* WMCreateNotificationQueue(void);
692 void WMDequeueNotificationMatching(WMNotificationQueue *queue,
693 WMNotification *notification,
694 unsigned mask);
696 void WMEnqueueNotification(WMNotificationQueue *queue,
697 WMNotification *notification,
698 WMPostingStyle postingStyle);
700 void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
701 WMNotification *notification,
702 WMPostingStyle postingStyle,
703 unsigned coalesceMask);
706 /*......................................................................*/
708 WMUserDefaults* WMGetStandardUserDefaults(void);
710 WMUserDefaults* WMGetDefaultsFromPath(char *path);
712 void WMSynchronizeUserDefaults(WMUserDefaults *database);
714 void WMSaveUserDefaults(WMUserDefaults *database);
716 void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
718 /* Returns a PLArray with all keys in the user defaults database.
719 * Free the returned array with PLRelease() when no longer needed,
720 * but do not free the elements of the array! They're just references. */
721 proplist_t WMGetUDAllKeys(WMUserDefaults *database);
723 proplist_t WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
725 void WMSetUDObjectForKey(WMUserDefaults *database, proplist_t object,
726 char *defaultName);
728 void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
730 char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
732 int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
734 float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
736 Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
738 void WMSetUDStringForKey(WMUserDefaults *database, char *value,
739 char *defaultName);
741 void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
742 char *defaultName);
744 void WMSetUDFloatForKey(WMUserDefaults *database, float value,
745 char *defaultName);
747 void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
748 char *defaultName);
750 proplist_t WMGetUDSearchList(WMUserDefaults *database);
752 void WMSetUDSearchList(WMUserDefaults *database, proplist_t list);
754 extern char *WMUserDefaultsDidChangeNotification;
757 /*-------------------------------------------------------------------------*/
759 /* WMHost: host handling */
761 WMHost* WMGetCurrentHost();
763 WMHost* WMGetHostWithName(char* name);
765 WMHost* WMGetHostWithAddress(char* address);
767 WMHost* WMRetainHost(WMHost *hPtr);
769 void WMReleaseHost(WMHost *hPtr);
772 * Host cache management
773 * If enabled, only one object representing each host will be created, and
774 * a shared instance will be returned by all methods that return a host.
775 * Enabled by default.
777 void WMSetHostCacheEnabled(Bool flag);
779 Bool WMIsHostCacheEnabled();
781 void WMFlushHostCache();
784 * Compare hosts: Hosts are equal if they share at least one address
786 Bool WMIsHostEqualToHost(WMHost* hPtr, WMHost* anotherHost);
789 * Host names.
790 * WMGetHostName() will return first name (official) if a host has several.
791 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
793 char* WMGetHostName(WMHost* hPtr);
795 /* The returned array is R/O. Do not modify it, and do not free it! */
796 WMArray* WMGetHostNames(WMHost* hPtr);
799 * Host addresses.
800 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
801 * WMGetHostAddress() will return an arbitrary address if a host has several.
802 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
804 char* WMGetHostAddress(WMHost* hPtr);
806 /* The returned array is R/O. Do not modify it, and do not free it! */
807 WMArray* WMGetHostAddresses(WMHost* hPtr);
810 /*-------------------------------------------------------------------------*/
812 /* WMConnection functions */
814 WMConnection* WMCreateConnectionAsServerAtAddress(char *host, char *service,
815 char *protocol);
817 WMConnection* WMCreateConnectionToAddress(char *host, char *service,
818 char *protocol);
820 WMConnection* WMCreateConnectionToAddressAndNotify(char *host, char *service,
821 char *protocol);
823 void WMCloseConnection(WMConnection *cPtr);
825 void WMDestroyConnection(WMConnection *cPtr);
827 WMConnection* WMAcceptConnection(WMConnection *listener);
829 /* Release the returned data! */
830 WMData* WMGetConnectionAvailableData(WMConnection *cPtr);
832 int WMSendConnectionData(WMConnection *cPtr, WMData *data);
834 Bool WMEnqueueConnectionData(WMConnection *cPtr, WMData *data);
836 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
838 void WMSetConnectionDelegate(WMConnection *cPtr, ConnectionDelegate *delegate);
840 /* Connection info */
842 char* WMGetConnectionAddress(WMConnection *cPtr);
844 char* WMGetConnectionService(WMConnection *cPtr);
846 char* WMGetConnectionProtocol(WMConnection *cPtr);
848 Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag);
850 Bool WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag);
852 void* WMGetConnectionClientData(WMConnection *cPtr);
854 void WMSetConnectionClientData(WMConnection *cPtr, void *data);
856 unsigned int WMGetConnectionFlags(WMConnection *cPtr);
858 void WMSetConnectionFlags(WMConnection *cPtr, unsigned int flags);
860 int WMGetConnectionSocket(WMConnection *cPtr);
862 WMConnectionState WMGetConnectionState(WMConnection *cPtr);
864 WMConnectionTimeoutState WMGetConnectionTimeoutState(WMConnection *cPtr);
866 WMArray* WMGetConnectionUnsentData(WMConnection *cPtr);
868 #define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
872 * Passing timeout==0 in the SetTimeout functions below, will reset that
873 * timeout to its default value.
876 /* The default timeout inherited by all WMConnection operations, if none set */
877 void WMSetConnectionDefaultTimeout(unsigned int timeout);
879 /* Global timeout for all WMConnection objects, for opening a new connection */
880 void WMSetConnectionOpenTimeout(unsigned int timeout);
882 /* Connection specific timeout for sending out data */
883 void WMSetConnectionSendTimeout(WMConnection *cPtr, unsigned int timeout);
886 /* Global variables */
888 extern int WCErrorCode;
891 /*-------------------------------------------------------------------------*/
895 #ifdef __cplusplus
897 #endif /* __cplusplus */
900 #endif