8 /* SunOS 4.x Blargh.... */
10 #define NULL ((void*)0)
15 * Warning: proplist.h #defines BOOL which will clash with the
16 * typedef BOOL in Xmd.h
17 * proplist.h should use Bool (which is a #define in Xlib.h) instead.
24 # define WMAX(a,b) ((a)>(b) ? (a) : (b))
27 # define WMIN(a,b) ((a)<(b) ? (a) : (b))
31 #if (!defined (__GNUC__) || __GNUC__ < 2 || \
32 __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4))
33 #define __ASSERT_FUNCTION ((char *) 0)
35 #define __ASSERT_FUNCTION __PRETTY_FUNCTION__
41 #define wassertr(expr) {}
42 #define wassertrv(expr, val) {}
50 #define wassertr(expr) assert(expr)
52 #define wassertrv(expr, val) assert(expr)
56 #define wassertr(expr) \
58 wwarning("%s line %i (%s): assertion %s failed",\
59 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
63 #define wassertrv(expr, val) \
65 wwarning("%s line %i (%s): assertion %s failed",\
66 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
76 #endif /* __cplusplus */
90 } WMNotificationCoalescing
;
93 /* The possible states for connections */
106 typedef struct W_Bag WMBag
; /* equivalent to a linked list or array */
107 typedef struct W_Data WMData
;
108 typedef struct W_HashTable WMHashTable
;
109 typedef struct W_UserDefaults WMUserDefaults
;
110 typedef struct W_Notification WMNotification
;
111 typedef struct W_NotificationQueue WMNotificationQueue
;
112 typedef struct W_Host WMHost
;
113 typedef struct W_Connection WMConnection
;
124 /* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
133 /* NULL is pointer hash */
134 unsigned (*hash
)(const void *);
135 /* NULL is pointer compare */
136 Bool (*keyIsEqual
)(const void *, const void *);
137 /* NULL does nothing */
138 void* (*retainKey
)(const void *);
139 /* NULL does nothing */
140 void (*releaseKey
)(const void *);
141 } WMHashTableCallbacks
;
147 char character
; /* the escape character */
148 char *value
; /* value to place */
153 /* The connection callbacks */
154 typedef struct ConnectionDelegate
{
157 void (*didCatchException
)(struct ConnectionDelegate
*self
,
160 void (*didDie
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
162 void (*didInitialize
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
164 void (*didReceiveInput
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
166 void (*didTimeout
)(struct ConnectionDelegate
*self
, WMConnection
*cPtr
);
168 } ConnectionDelegate
;
171 typedef void WMNotificationObserverAction(void *observerData
,
172 WMNotification
*notification
);
176 /*......................................................................*/
178 typedef void (waborthandler
)(int);
180 waborthandler
*wsetabort(waborthandler
*);
183 /* don't free the returned string */
184 char *wstrerror(int errnum
);
186 void wfatal(const char *msg
, ...);
187 void wwarning(const char *msg
, ...);
188 void wsyserror(const char *msg
, ...);
189 void wsyserrorwithcode(int error
, const char *msg
, ...);
191 char *wfindfile(char *paths
, char *file
);
193 char *wfindfileinlist(char **path_list
, char *file
);
195 char *wfindfileinarray(proplist_t array
, char *file
);
197 char *wexpandpath(char *path
);
199 /* don't free the returned string */
202 void *wmalloc(size_t size
);
203 void *wrealloc(void *ptr
, size_t newsize
);
204 void wfree(void *ptr
);
207 void wrelease(void *ptr
);
208 void *wretain(void *ptr
);
210 char *wstrdup(char *str
);
212 char *wstrappend(char *dst
, char *src
);
214 char *wusergnusteppath();
216 char *wdefaultspathfordomain(char *domain
);
218 void wusleep(unsigned int microsec
);
221 int wsprintesc(char *buffer
, int length
, char *format
, WMSEscapes
**escapes
,
225 /*......................................................................*/
227 /* This function is used _only_ if you create a NON-GUI program.
228 * For GUI based programs use WMNextEvent()/WMHandleEvent() instead.
229 * This function will handle all input/timer/idle events, then return.
232 void WHandleEvents();
234 /*......................................................................*/
237 WMHashTable
*WMCreateHashTable(WMHashTableCallbacks callbacks
);
239 void WMFreeHashTable(WMHashTable
*table
);
241 void WMResetHashTable(WMHashTable
*table
);
243 void *WMHashGet(WMHashTable
*table
, const void *key
);
245 /* put data in table, replacing already existing data and returning
247 void *WMHashInsert(WMHashTable
*table
, void *key
, void *data
);
249 void WMHashRemove(WMHashTable
*table
, const void *key
);
251 /* warning: do not manipulate the table while using these functions */
252 WMHashEnumerator
WMEnumerateHashTable(WMHashTable
*table
);
254 void *WMNextHashEnumeratorItem(WMHashEnumerator
*enumerator
);
256 unsigned WMCountHashTable(WMHashTable
*table
);
261 /* some predefined callback sets */
263 extern const WMHashTableCallbacks WMIntHashCallbacks
;
264 /* sizeof(keys) are <= sizeof(void*) */
266 extern const WMHashTableCallbacks WMStringHashCallbacks
;
267 /* keys are strings. Strings will be copied with wstrdup()
268 * and freed with free() */
270 extern const WMHashTableCallbacks WMStringPointerHashCallbacks
;
271 /* keys are strings, bug they are not copied */
274 /*......................................................................*/
277 WMBag
*WMCreateBag(int size
);
279 int WMGetBagItemCount(WMBag
*bag
);
281 void WMAppendBag(WMBag
*bag
, WMBag
*appendedBag
);
283 void WMPutInBag(WMBag
*bag
, void *item
);
285 void WMInsertInBag(WMBag
*bag
, int index
, void *item
);
287 int WMGetFirstInBag(WMBag
*bag
, void *item
);
289 int WMGetLastInBag(WMBag
*bag
, void *item
);
291 void WMRemoveFromBag(WMBag
*bag
, void *item
);
293 void WMDeleteFromBag(WMBag
*bag
, int index
);
295 void *WMGetFromBag(WMBag
*bag
, int index
);
297 int WMCountInBag(WMBag
*bag
, void *item
);
299 void *WMReplaceInBag(WMBag
*bag
, int index
, void *item
);
301 /* comparer must return:
306 void WMSortBag(WMBag
*bag
, int (*comparer
)(const void*, const void*));
308 void WMEmptyBag(WMBag
*bag
);
310 void WMFreeBag(WMBag
*bag
);
312 WMBag
*WMMapBag(WMBag
*bag
, void* (*function
)(void*));
314 /*-------------------------------------------------------------------------*/
316 /* WMData handling */
318 /* Creating/destroying data */
320 WMData
* WMCreateDataWithCapacity(unsigned capacity
);
322 WMData
* WMCreateDataWithLength(unsigned length
);
324 WMData
* WMCreateDataWithBytes(void *bytes
, unsigned length
);
326 WMData
* WMCreateDataWithBytesNoCopy(void *bytes
, unsigned length
);
328 WMData
* WMCreateDataWithData(WMData
*aData
);
330 WMData
* WMRetainData(WMData
*aData
);
332 void WMReleaseData(WMData
*aData
);
334 /* Adjusting capacity */
336 void WMSetDataCapacity(WMData
*aData
, unsigned capacity
);
338 void WMSetDataLength(WMData
*aData
, unsigned length
);
340 void WMIncreaseDataLengthBy(WMData
*aData
, unsigned extraLength
);
344 const void* WMDataBytes(WMData
*aData
);
346 void WMGetDataBytes(WMData
*aData
, void *buffer
);
348 void WMGetDataBytesWithLength(WMData
*aData
, void *buffer
, unsigned length
);
350 void WMGetDataBytesWithRange(WMData
*aData
, void *buffer
, WMRange aRange
);
352 WMData
* WMGetSubdataWithRange(WMData
*aData
, WMRange aRange
);
356 Bool
WMIsDataEqualToData(WMData
*aData
, WMData
*anotherData
);
358 unsigned WMGetDataLength(WMData
*aData
);
360 unsigned WMGetDataHash(WMData
*aData
);
364 void WMAppendDataBytes(WMData
*aData
, void *bytes
, unsigned length
);
366 void WMAppendData(WMData
*aData
, WMData
*anotherData
);
370 void WMReplaceDataBytesInRange(WMData
*aData
, WMRange aRange
, void *bytes
);
372 void WMResetDataBytesInRange(WMData
*aData
, WMRange aRange
);
374 void WMSetData(WMData
*aData
, WMData
*anotherData
);
379 /*--------------------------------------------------------------------------*/
382 WMNotification
*WMCreateNotification(char *name
, void *object
, void *clientData
);
384 void WMReleaseNotification(WMNotification
*notification
);
386 WMNotification
*WMRetainNotification(WMNotification
*notification
);
388 void *WMGetNotificationClientData(WMNotification
*notification
);
390 void *WMGetNotificationObject(WMNotification
*notification
);
392 char *WMGetNotificationName(WMNotification
*notification
);
395 void WMAddNotificationObserver(WMNotificationObserverAction
*observerAction
,
396 void *observer
, char *name
, void *object
);
398 void WMPostNotification(WMNotification
*notification
);
400 void WMRemoveNotificationObserver(void *observer
);
402 void WMRemoveNotificationObserverWithName(void *observer
, char *name
,
405 void WMPostNotificationName(char *name
, void *object
, void *clientData
);
407 WMNotificationQueue
*WMGetDefaultNotificationQueue(void);
409 WMNotificationQueue
*WMCreateNotificationQueue(void);
411 void WMDequeueNotificationMatching(WMNotificationQueue
*queue
,
412 WMNotification
*notification
,
415 void WMEnqueueNotification(WMNotificationQueue
*queue
,
416 WMNotification
*notification
,
417 WMPostingStyle postingStyle
);
419 void WMEnqueueCoalesceNotification(WMNotificationQueue
*queue
,
420 WMNotification
*notification
,
421 WMPostingStyle postingStyle
,
422 unsigned coalesceMask
);
425 /*......................................................................*/
427 WMUserDefaults
*WMGetStandardUserDefaults(void);
429 WMUserDefaults
*WMGetDefaultsFromPath(char *path
);
431 void WMSynchronizeUserDefaults(WMUserDefaults
*database
);
433 void WMSaveUserDefaults(WMUserDefaults
*database
);
435 proplist_t
WMGetUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
437 void WMSetUDObjectForKey(WMUserDefaults
*database
, proplist_t object
,
440 void WMRemoveUDObjectForKey(WMUserDefaults
*database
, char *defaultName
);
442 /* you can free the returned string */
443 char *WMGetUDStringForKey(WMUserDefaults
*database
, char *defaultName
);
445 int WMGetUDIntegerForKey(WMUserDefaults
*database
, char *defaultName
);
447 float WMGetUDFloatForKey(WMUserDefaults
*database
, char *defaultName
);
449 Bool
WMGetUDBoolForKey(WMUserDefaults
*database
, char *defaultName
);
451 void WMSetUDStringForKey(WMUserDefaults
*database
, char *value
,
454 void WMSetUDIntegerForKey(WMUserDefaults
*database
, int value
,
457 void WMSetUDFloatForKey(WMUserDefaults
*database
, float value
,
460 void WMSetUDBoolForKey(WMUserDefaults
*database
, Bool value
,
463 proplist_t
WMGetUDSearchList(WMUserDefaults
*database
);
465 void WMSetUDSearchList(WMUserDefaults
*database
, proplist_t list
);
468 /*-------------------------------------------------------------------------*/
470 /* WMHost: host handling */
472 WMHost
* WMGetCurrentHost();
474 WMHost
* WMGetHostWithName(char* name
);
476 WMHost
* WMGetHostWithAddress(char* address
);
478 WMHost
* WMRetainHost(WMHost
*hPtr
);
480 void WMReleaseHost(WMHost
*hPtr
);
483 * Host cache management
484 * If enabled, only one object representing each host will be created, and
485 * a shared instance will be returned by all methods that return a host.
486 * Enabled by default.
488 void WMSetHostCacheEnabled(Bool flag
);
490 Bool
WMIsHostCacheEnabled();
492 void WMFlushHostCache();
495 * Compare hosts: Hosts are equal if they share at least one address
497 Bool
WMIsHostEqualToHost(WMHost
* hPtr
, WMHost
* anotherHost
);
501 * WMGetHostName() will return first name (official) if a host has several.
502 * WMGetHostNames() will return a R/O WMBag with all the names of the host.
504 char* WMGetHostName(WMHost
* hPtr
);
506 /* The returned bag is R/O. Do not modify it, and do not free it! */
507 WMBag
* WMGetHostNames(WMHost
* hPtr
);
511 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
512 * WMGetHostAddress() will return an arbitrary address if a host has several.
513 * WMGetHostAddresses() will return a R/O WMBag with all addresses of the host.
515 char* WMGetHostAddress(WMHost
* hPtr
);
517 /* The returned bag is R/O. Do not modify it, and do not free it! */
518 WMBag
* WMGetHostAddresses(WMHost
* hPtr
);
521 /*-------------------------------------------------------------------------*/
523 /* WMConnection functions */
525 WMConnection
* WMCreateConnectionAsServerAtAddress(char *host
, char *service
,
528 WMConnection
* WMCreateConnectionToAddress(char *host
, char *service
,
531 WMConnection
* WMCreateConnectionToAddressAndNotify(char *host
, char *service
,
534 void WMCloseConnection(WMConnection
*cPtr
);
536 void WMDestroyConnection(WMConnection
*cPtr
);
538 WMConnection
* WMAcceptConnection(WMConnection
*listener
);
540 /* Release the returned data! */
541 WMData
* WMGetConnectionAvailableData(WMConnection
*cPtr
);
543 int WMSendConnectionData(WMConnection
*cPtr
, WMData
*data
);
545 Bool
WMEnqueueConnectionData(WMConnection
*cPtr
, WMData
*data
);
547 #define WMFlushConnection(cPtr) WMSendConnectionData((cPtr), NULL)
549 void WMSetConnectionDelegate(WMConnection
*cPtr
, ConnectionDelegate
*delegate
);
551 /* Connection info */
553 char* WMGetConnectionAddress(WMConnection
*cPtr
);
555 char* WMGetConnectionService(WMConnection
*cPtr
);
557 char* WMGetConnectionProtocol(WMConnection
*cPtr
);
559 void WMSetConnectionNonBlocking(WMConnection
*cPtr
, Bool flag
);
561 void* WMGetConnectionClientData(WMConnection
*cPtr
);
563 void WMSetConnectionClientData(WMConnection
*cPtr
, void *data
);
565 unsigned int WMGetConnectionFlags(WMConnection
*cPtr
);
567 void WMSetConnectionFlags(WMConnection
*cPtr
, unsigned int flags
);
569 int WMGetConnectionSocket(WMConnection
*cPtr
);
571 WMConnectionState
WMGetConnectionState(WMConnection
*cPtr
);
573 void WMSetConnectionSendTimeout(WMConnection
*cPtr
, unsigned int timeout
);
576 /* Global variables */
578 extern int WCErrorCode
;
581 /*-------------------------------------------------------------------------*/
587 #endif /* __cplusplus */