~profzoom/ubuntu/quantal/wmaker/bug-1079925

« back to all changes in this revision

Viewing changes to WINGs/WINGs/WUtil.h

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-11-10 14:05:30 UTC
  • Revision ID: james.westby@ubuntu.com-20041110140530-qpd66b5lm38x7apk
Tags: upstream-0.91.0
ImportĀ upstreamĀ versionĀ 0.91.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _WUTIL_H_
 
2
#define _WUTIL_H_
 
3
 
 
4
#include <X11/Xlib.h>
 
5
#include <limits.h>
 
6
#include <sys/types.h>
 
7
 
 
8
/* SunOS 4.x Blargh.... */
 
9
#ifndef NULL
 
10
#define NULL ((void*)0)
 
11
#endif
 
12
 
 
13
 
 
14
#ifndef WMAX
 
15
# define WMAX(a,b)      ((a)>(b) ? (a) : (b))
 
16
#endif
 
17
#ifndef WMIN
 
18
# define WMIN(a,b)      ((a)<(b) ? (a) : (b))
 
19
#endif
 
20
 
 
21
 
 
22
#ifndef __ASSERT_FUNCTION
 
23
# if (!defined (__GNUC__) || (__GNUC__ < 2 && \
 
24
      __GNUC_MINOR__ < (defined (__cplusplus) ? 6 : 4)))
 
25
#  define __ASSERT_FUNCTION       ((char *) 0)
 
26
# else
 
27
#  define __ASSERT_FUNCTION       __PRETTY_FUNCTION__
 
28
# endif
 
29
#endif
 
30
 
 
31
 
 
32
#ifdef NDEBUG
 
33
 
 
34
#define wassertr(expr)          {}
 
35
#define wassertrv(expr, val)    {}
 
36
 
 
37
#else /* !NDEBUG */
 
38
 
 
39
#ifdef DEBUG
 
40
 
 
41
#include <assert.h>
 
42
 
 
43
#define wassertr(expr)  assert(expr)
 
44
 
 
45
#define wassertrv(expr, val)    assert(expr)
 
46
 
 
47
#else /* !DEBUG */
 
48
 
 
49
#define wassertr(expr) \
 
50
    if (!(expr)) { \
 
51
        wwarning("%s line %i (%s): assertion %s failed",\
 
52
                 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
 
53
        return;\
 
54
    }
 
55
 
 
56
#define wassertrv(expr, val) \
 
57
    if (!(expr)) { \
 
58
        wwarning("%s line %i (%s): assertion %s failed",\
 
59
                 __FILE__, __LINE__, __ASSERT_FUNCTION, #expr);\
 
60
        return (val);\
 
61
    }
 
62
#endif /* !DEBUG */
 
63
 
 
64
#endif /* !NDEBUG */
 
65
 
 
66
 
 
67
#ifdef __cplusplus
 
68
extern "C" {
 
69
#endif /* __cplusplus */
 
70
 
 
71
 
 
72
typedef enum {
 
73
    WMPostWhenIdle = 1,
 
74
    WMPostASAP = 2,
 
75
    WMPostNow = 3
 
76
} WMPostingStyle;
 
77
 
 
78
 
 
79
typedef enum {
 
80
    WNCNone = 0,
 
81
    WNCOnName = 1,
 
82
    WNCOnSender = 2
 
83
} WMNotificationCoalescing;
 
84
 
 
85
 
 
86
/* The possible states for connections */
 
87
typedef enum {
 
88
    WCNotConnected=0,
 
89
    WCListening,
 
90
    WCInProgress,
 
91
    WCFailed,
 
92
    WCConnected,
 
93
    WCTimedOut,
 
94
    WCDied,
 
95
    WCClosed
 
96
} WMConnectionState;
 
97
 
 
98
 
 
99
/* The possible states for connection timeouts */
 
100
typedef enum {
 
101
    WCTNone=0,
 
102
    WCTWhileOpening,
 
103
    WCTWhileSending
 
104
} WMConnectionTimeoutState;
 
105
 
 
106
 
 
107
 
 
108
enum {
 
109
    WBNotFound = INT_MIN, /* element was not found in WMBag   */
 
110
    WANotFound = -1       /* element was not found in WMArray */
 
111
};
 
112
 
 
113
 
 
114
typedef struct W_Array WMArray;
 
115
typedef struct W_Bag WMBag;
 
116
typedef struct W_Data WMData;
 
117
typedef struct W_TreeNode WMTreeNode;
 
118
typedef struct W_HashTable WMHashTable;
 
119
typedef struct W_UserDefaults WMUserDefaults;
 
120
typedef struct W_Notification WMNotification;
 
121
typedef struct W_NotificationQueue WMNotificationQueue;
 
122
typedef struct W_Host WMHost;
 
123
typedef struct W_Connection WMConnection;
 
124
typedef struct W_PropList WMPropList;
 
125
 
 
126
 
 
127
 
 
128
/* Some typedefs for the handler stuff */
 
129
typedef void *WMHandlerID;
 
130
 
 
131
typedef void WMCallback(void *data);
 
132
 
 
133
typedef void WMInputProc(int fd, int mask, void *clientData);
 
134
 
 
135
 
 
136
 
 
137
typedef int WMCompareDataProc(const void *item1, const void *item2);
 
138
 
 
139
typedef void WMFreeDataProc(void *data);
 
140
 
 
141
/* Used by WMBag or WMArray for matching data */
 
142
typedef int WMMatchDataProc(void *item, void *cdata);
 
143
 
 
144
 
 
145
 
 
146
typedef struct {
 
147
    int position;
 
148
    int count;
 
149
} WMRange;
 
150
 
 
151
 
 
152
 
 
153
/* DO NOT ACCESS THE CONTENTS OF THIS STRUCT */
 
154
typedef struct {
 
155
    void *table;
 
156
    void *nextItem;
 
157
    int index;
 
158
} WMHashEnumerator;
 
159
 
 
160
 
 
161
typedef struct {
 
162
    /* NULL is pointer hash */
 
163
    unsigned    (*hash)(const void *);
 
164
    /* NULL is pointer compare */
 
165
    Bool        (*keyIsEqual)(const void *, const void *);
 
166
    /* NULL does nothing */
 
167
    void*       (*retainKey)(const void *);
 
168
    /* NULL does nothing */
 
169
    void        (*releaseKey)(const void *);
 
170
} WMHashTableCallbacks;
 
171
 
 
172
 
 
173
typedef int WMArrayIterator;
 
174
typedef void *WMBagIterator;
 
175
 
 
176
 
 
177
#if 0
 
178
typedef struct {
 
179
    char character;                    /* the escape character */
 
180
    char *value;                       /* value to place */
 
181
} WMSEscapes;
 
182
#endif
 
183
 
 
184
 
 
185
/* The connection callbacks */
 
186
typedef struct ConnectionDelegate {
 
187
    void *data;
 
188
 
 
189
    void (*canResumeSending)(struct ConnectionDelegate *self, WMConnection *cPtr);
 
190
 
 
191
    void (*didCatchException)(struct ConnectionDelegate *self, WMConnection *cPtr);
 
192
 
 
193
    void (*didDie)(struct ConnectionDelegate *self, WMConnection *cPtr);
 
194
 
 
195
    void (*didInitialize)(struct ConnectionDelegate *self, WMConnection *cPtr);
 
196
 
 
197
    void (*didReceiveInput)(struct ConnectionDelegate *self, WMConnection *cPtr);
 
198
 
 
199
    void (*didTimeout)(struct ConnectionDelegate *self, WMConnection *cPtr);
 
200
 
 
201
} ConnectionDelegate;
 
202
 
 
203
 
 
204
typedef void WMNotificationObserverAction(void *observerData,
 
205
                                          WMNotification *notification);
 
206
 
 
207
 
 
208
 
 
209
/*......................................................................*/
 
210
 
 
211
typedef void waborthandler(int);
 
212
 
 
213
waborthandler* wsetabort(waborthandler* handler);
 
214
 
 
215
 
 
216
/* don't free the returned string */
 
217
char* wstrerror(int errnum);
 
218
 
 
219
void wmessage(const char *msg, ...);
 
220
void wwarning(const char *msg, ...);
 
221
void wfatal(const char *msg, ...);
 
222
void wsyserror(const char *msg, ...);
 
223
void wsyserrorwithcode(int error, const char *msg, ...);
 
224
 
 
225
char* wfindfile(char *paths, char *file);
 
226
 
 
227
char* wfindfileinlist(char **path_list, char *file);
 
228
 
 
229
char* wfindfileinarray(WMPropList* array, char *file);
 
230
 
 
231
char* wexpandpath(char *path);
 
232
 
 
233
/* don't free the returned string */
 
234
char* wgethomedir();
 
235
 
 
236
void* wmalloc(size_t size);
 
237
void* wrealloc(void *ptr, size_t newsize);
 
238
void wfree(void *ptr);
 
239
 
 
240
 
 
241
void wrelease(void *ptr);
 
242
void* wretain(void *ptr);
 
243
 
 
244
char* wstrdup(char *str);
 
245
char* wstrndup(char *str, size_t len);
 
246
 
 
247
/* Concatenate str1 with str2 and return that in a newly malloc'ed string.
 
248
 * str1 and str2 can be any strings including static and constant strings.
 
249
 * str1 and str2 will not be modified.
 
250
 * Free the returned string when you're done with it. */
 
251
char* wstrconcat(char *str1, char *str2);
 
252
 
 
253
/* This will append src to dst, and return dst. dst MUST be either NULL
 
254
 * or a string that was a result of a dynamic allocation (malloc, realloc
 
255
 * wmalloc, wrealloc, ...). dst CANNOT be a static or a constant string!
 
256
 * Modifies dst (no new string is created except if dst==NULL in which case
 
257
 * it is equivalent to calling wstrdup(src) ).
 
258
 * The returned address may be different from the original address of dst,
 
259
 * so always assign the returned address to avoid dangling pointers. */
 
260
char* wstrappend(char *dst, char *src);
 
261
 
 
262
 
 
263
void wtokensplit(char *command, char ***argv, int *argc);
 
264
 
 
265
char* wtokennext(char *word, char **next);
 
266
 
 
267
char* wtokenjoin(char **list, int count);
 
268
 
 
269
void wtokenfree(char **tokens, int count);
 
270
 
 
271
char* wtrimspace(char *s);
 
272
 
 
273
 
 
274
WMRange wmkrange(int start, int count);
 
275
#ifdef ANSI_C_DOESNT_LIKE_IT_THIS_WAY
 
276
#define wmkrange(position, count) (WMRange){(position), (count)}
 
277
#endif
 
278
 
 
279
 
 
280
char* wusergnusteppath();
 
281
 
 
282
char* wdefaultspathfordomain(char *domain);
 
283
 
 
284
void wusleep(unsigned int microsec);
 
285
 
 
286
#if 0
 
287
int wsprintesc(char *buffer, int length, char *format, WMSEscapes **escapes,
 
288
               int count);
 
289
#endif
 
290
 
 
291
/*......................................................................*/
 
292
 
 
293
/* Event handlers: timer, idle, input */
 
294
 
 
295
WMHandlerID WMAddTimerHandler(int milliseconds, WMCallback *callback,
 
296
                              void *cdata);
 
297
 
 
298
WMHandlerID WMAddPersistentTimerHandler(int milliseconds, WMCallback *callback,
 
299
                                        void *cdata);
 
300
 
 
301
void WMDeleteTimerWithClientData(void *cdata);
 
302
 
 
303
void WMDeleteTimerHandler(WMHandlerID handlerID);
 
304
 
 
305
WMHandlerID WMAddIdleHandler(WMCallback *callback, void *cdata);
 
306
 
 
307
void WMDeleteIdleHandler(WMHandlerID handlerID);
 
308
 
 
309
WMHandlerID WMAddInputHandler(int fd, int condition, WMInputProc *proc,
 
310
                              void *clientData);
 
311
 
 
312
void WMDeleteInputHandler(WMHandlerID handlerID);
 
313
 
 
314
 
 
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.
 
318
 */
 
319
 
 
320
void WHandleEvents();
 
321
 
 
322
/*......................................................................*/
 
323
 
 
324
 
 
325
WMHashTable* WMCreateHashTable(WMHashTableCallbacks callbacks);
 
326
 
 
327
void WMFreeHashTable(WMHashTable *table);
 
328
 
 
329
void WMResetHashTable(WMHashTable *table);
 
330
 
 
331
unsigned WMCountHashTable(WMHashTable *table);
 
332
 
 
333
void* WMHashGet(WMHashTable *table, const void *key);
 
334
 
 
335
/* Returns True if there is a value associated with <key> in the table, in
 
336
 * which case <retKey> and <retItem> will contain the item's internal key
 
337
 * address and the item's value respectively.
 
338
 * If there is no value associated with <key> it will return False and in
 
339
 * this case <retKey> and <retItem> will be undefined.
 
340
 * Use this when you need to perform your own custom retain/release mechanism
 
341
 * which requires access to the keys too.
 
342
 */
 
343
Bool WMHashGetItemAndKey(WMHashTable *table, const void *key,
 
344
                         void **retItem, void **retKey);
 
345
 
 
346
/* put data in table, replacing already existing data and returning
 
347
 * the old value */
 
348
void* WMHashInsert(WMHashTable *table, const void *key, const void *data);
 
349
 
 
350
void WMHashRemove(WMHashTable *table, const void *key);
 
351
 
 
352
/* warning: do not manipulate the table while using the enumerator functions */
 
353
WMHashEnumerator WMEnumerateHashTable(WMHashTable *table);
 
354
 
 
355
void* WMNextHashEnumeratorItem(WMHashEnumerator *enumerator);
 
356
 
 
357
void* WMNextHashEnumeratorKey(WMHashEnumerator *enumerator);
 
358
 
 
359
/* Returns True if there is a next element, in which case key and item
 
360
 * will contain the next element's key and value respectively.
 
361
 * If there is no next element available it will return False and in this
 
362
 * case key and item will be undefined.
 
363
 */
 
364
Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator *enumerator,
 
365
                                    void **item, void **key);
 
366
 
 
367
 
 
368
 
 
369
 
 
370
/* some predefined callback sets */
 
371
 
 
372
extern const WMHashTableCallbacks WMIntHashCallbacks;
 
373
/* sizeof(keys) are <= sizeof(void*) */
 
374
 
 
375
extern const WMHashTableCallbacks WMStringHashCallbacks;
 
376
/* keys are strings. Strings will be copied with wstrdup()
 
377
 * and freed with wfree() */
 
378
 
 
379
extern const WMHashTableCallbacks WMStringPointerHashCallbacks;
 
380
/* keys are strings, but they are not copied */
 
381
 
 
382
 
 
383
/*......................................................................*/
 
384
 
 
385
/*
 
386
 * WMArray use an array to store the elements.
 
387
 * Item indexes may be only positive integer numbers.
 
388
 * The array cannot contain holes in it.
 
389
 *
 
390
 * Pros:
 
391
 * Fast [O(1)] access to elements
 
392
 * Fast [O(1)] push/pop
 
393
 *
 
394
 * Cons:
 
395
 * A little slower [O(n)] for insertion/deletion of elements that
 
396
 *      aren't in the end
 
397
 */
 
398
 
 
399
WMArray* WMCreateArray(int initialSize);
 
400
 
 
401
WMArray* WMCreateArrayWithDestructor(int initialSize, WMFreeDataProc *destructor);
 
402
 
 
403
WMArray* WMCreateArrayWithArray(WMArray *array);
 
404
 
 
405
#define WMDuplicateArray(array) WMCreateArrayWithArray(array)
 
406
 
 
407
void WMEmptyArray(WMArray *array);
 
408
 
 
409
void WMFreeArray(WMArray *array);
 
410
 
 
411
int WMGetArrayItemCount(WMArray *array);
 
412
 
 
413
/* appends other to array. other remains unchanged */
 
414
void WMAppendArray(WMArray *array, WMArray *other);
 
415
 
 
416
/* add will place the element at the end of the array */
 
417
void WMAddToArray(WMArray *array, void *item);
 
418
 
 
419
#define WMPushInArray(array, item) WMAddToArray(array, item)
 
420
 
 
421
/* insert will increment the index of elements after it by 1 */
 
422
void WMInsertInArray(WMArray *array, int index, void *item);
 
423
 
 
424
/* replace and set will return the old item WITHOUT calling the
 
425
 * destructor on it even if its available. Free the returned item yourself.
 
426
 */
 
427
void* WMReplaceInArray(WMArray *array, int index, void *item);
 
428
 
 
429
#define WMSetInArray(array, index, item) WMReplaceInArray(array, index, item)
 
430
 
 
431
/* delete and remove will remove the elements and cause the elements
 
432
 * after them to decrement their indexes by 1. Also will call the
 
433
 * destructor on the deleted element if there's one available.
 
434
 */
 
435
int WMDeleteFromArray(WMArray *array, int index);
 
436
 
 
437
#define WMRemoveFromArray(array, item) WMRemoveFromArrayMatching(array, NULL, item)
 
438
 
 
439
int WMRemoveFromArrayMatching(WMArray *array, WMMatchDataProc *match, void *cdata);
 
440
 
 
441
void* WMGetFromArray(WMArray *array, int index);
 
442
 
 
443
#define WMGetFirstInArray(array, item) WMFindInArray(array, NULL, item)
 
444
 
 
445
/* pop will return the last element from the array, also removing it
 
446
 * from the array. The destructor is NOT called, even if available.
 
447
 * Free the returned element if needed by yourself
 
448
 */
 
449
void* WMPopFromArray(WMArray *array);
 
450
 
 
451
int WMFindInArray(WMArray *array, WMMatchDataProc *match, void *cdata);
 
452
 
 
453
int WMCountInArray(WMArray *array, void *item);
 
454
 
 
455
/* comparer must return:
 
456
 * < 0 if a < b
 
457
 * > 0 if a > b
 
458
 * = 0 if a = b
 
459
 */
 
460
void WMSortArray(WMArray *array, WMCompareDataProc *comparer);
 
461
 
 
462
void WMMapArray(WMArray *array, void (*function)(void*, void*), void *data);
 
463
 
 
464
WMArray* WMGetSubarrayWithRange(WMArray* array, WMRange aRange);
 
465
 
 
466
void* WMArrayFirst(WMArray *array, WMArrayIterator *iter);
 
467
 
 
468
void* WMArrayLast(WMArray *array, WMArrayIterator *iter);
 
469
 
 
470
/* The following 2 functions assume that the array doesn't change between calls */
 
471
void* WMArrayNext(WMArray *array, WMArrayIterator *iter);
 
472
 
 
473
void* WMArrayPrevious(WMArray *array, WMArrayIterator *iter);
 
474
 
 
475
 
 
476
/* The following 2 macros assume that the array doesn't change in the for loop */
 
477
#define WM_ITERATE_ARRAY(array, var, i) \
 
478
    for (var = WMArrayFirst(array, &(i)); (i) != WANotFound; \
 
479
    var = WMArrayNext(array, &(i)))
 
480
 
 
481
#define WM_ETARETI_ARRAY(array, var, i) \
 
482
    for (var = WMArrayLast(array, &(i)); (i) != WANotFound; \
 
483
    var = WMArrayPrevious(array, &(i)))
 
484
 
 
485
/*..........................................................................*/
 
486
 
 
487
/*
 
488
 * Tree bags use a red-black tree for storage.
 
489
 * Item indexes may be any integer number.
 
490
 *
 
491
 * Pros:
 
492
 * O(lg n) insertion/deletion/search
 
493
 * Good for large numbers of elements with sparse indexes
 
494
 *
 
495
 * Cons:
 
496
 * O(lg n) insertion/deletion/search
 
497
 * Slow for storing small numbers of elements
 
498
 */
 
499
 
 
500
#define WMCreateBag(size) WMCreateTreeBag()
 
501
 
 
502
#define WMCreateBagWithDestructor(size, d) WMCreateTreeBagWithDestructor(d)
 
503
 
 
504
WMBag* WMCreateTreeBag(void);
 
505
 
 
506
WMBag* WMCreateTreeBagWithDestructor(WMFreeDataProc *destructor);
 
507
 
 
508
int WMGetBagItemCount(WMBag *bag);
 
509
 
 
510
void WMAppendBag(WMBag *bag, WMBag *other);
 
511
 
 
512
void WMPutInBag(WMBag *bag, void *item);
 
513
 
 
514
/* insert will increment the index of elements after it by 1 */
 
515
void WMInsertInBag(WMBag *bag, int index, void *item);
 
516
 
 
517
/* erase will remove the element from the bag,
 
518
 * but will keep the index of the other elements unchanged */
 
519
int WMEraseFromBag(WMBag *bag, int index);
 
520
 
 
521
/* delete and remove will remove the elements and cause the elements
 
522
 * after them to decrement their indexes by 1 */
 
523
int WMDeleteFromBag(WMBag *bag, int index);
 
524
 
 
525
int WMRemoveFromBag(WMBag *bag, void *item);
 
526
 
 
527
void* WMGetFromBag(WMBag *bag, int index);
 
528
 
 
529
void* WMReplaceInBag(WMBag *bag, int index, void *item);
 
530
 
 
531
#define WMSetInBag(bag, index, item) WMReplaceInBag(bag, index, item)
 
532
 
 
533
/* comparer must return:
 
534
 * < 0 if a < b
 
535
 * > 0 if a > b
 
536
 * = 0 if a = b
 
537
 */
 
538
void WMSortBag(WMBag *bag, WMCompareDataProc *comparer);
 
539
 
 
540
void WMEmptyBag(WMBag *bag);
 
541
 
 
542
void WMFreeBag(WMBag *bag);
 
543
 
 
544
void WMMapBag(WMBag *bag, void (*function)(void*, void*), void *data);
 
545
 
 
546
int WMGetFirstInBag(WMBag *bag, void *item);
 
547
 
 
548
int WMCountInBag(WMBag *bag, void *item);
 
549
 
 
550
int WMFindInBag(WMBag *bag, WMMatchDataProc *match, void *cdata);
 
551
 
 
552
void* WMBagFirst(WMBag *bag, WMBagIterator *ptr);
 
553
 
 
554
void* WMBagLast(WMBag *bag, WMBagIterator *ptr);
 
555
 
 
556
/* The following 4 functions assume that the bag doesn't change between calls */
 
557
void* WMBagNext(WMBag *bag, WMBagIterator *ptr);
 
558
 
 
559
void* WMBagPrevious(WMBag *bag, WMBagIterator *ptr);
 
560
 
 
561
void* WMBagIteratorAtIndex(WMBag *bag, int index, WMBagIterator *ptr);
 
562
 
 
563
int WMBagIndexForIterator(WMBag *bag, WMBagIterator ptr);
 
564
 
 
565
 
 
566
/* The following 2 macros assume that the bag doesn't change in the for loop */
 
567
#define WM_ITERATE_BAG(bag, var, i) \
 
568
    for (var = WMBagFirst(bag, &(i)); (i) != NULL; \
 
569
    var = WMBagNext(bag, &(i)))
 
570
 
 
571
#define WM_ETARETI_BAG(bag, var, i) \
 
572
    for (var = WMBagLast(bag, &(i)); (i) != NULL; \
 
573
    var = WMBagPrevious(bag, &(i)))
 
574
 
 
575
 
 
576
 
 
577
/*-------------------------------------------------------------------------*/
 
578
 
 
579
/* WMData handling */
 
580
 
 
581
/* Creating/destroying data */
 
582
 
 
583
WMData* WMCreateDataWithCapacity(unsigned capacity);
 
584
 
 
585
WMData* WMCreateDataWithLength(unsigned length);
 
586
 
 
587
WMData* WMCreateDataWithBytes(void *bytes, unsigned length);
 
588
 
 
589
/* destructor is a function called to free the data when releasing the data
 
590
 * object, or NULL if no freeing of data is necesary. */
 
591
WMData* WMCreateDataWithBytesNoCopy(void *bytes, unsigned length,
 
592
                                    WMFreeDataProc *destructor);
 
593
 
 
594
WMData* WMCreateDataWithData(WMData *aData);
 
595
 
 
596
WMData* WMRetainData(WMData *aData);
 
597
 
 
598
void WMReleaseData(WMData *aData);
 
599
 
 
600
/* Adjusting capacity */
 
601
 
 
602
void WMSetDataCapacity(WMData *aData, unsigned capacity);
 
603
 
 
604
void WMSetDataLength(WMData *aData, unsigned length);
 
605
 
 
606
void WMIncreaseDataLengthBy(WMData *aData, unsigned extraLength);
 
607
 
 
608
/* Accessing data */
 
609
 
 
610
const void* WMDataBytes(WMData *aData);
 
611
 
 
612
void WMGetDataBytes(WMData *aData, void *buffer);
 
613
 
 
614
void WMGetDataBytesWithLength(WMData *aData, void *buffer, unsigned length);
 
615
 
 
616
void WMGetDataBytesWithRange(WMData *aData, void *buffer, WMRange aRange);
 
617
 
 
618
WMData* WMGetSubdataWithRange(WMData *aData, WMRange aRange);
 
619
 
 
620
/* Testing data */
 
621
 
 
622
Bool WMIsDataEqualToData(WMData *aData, WMData *anotherData);
 
623
 
 
624
unsigned WMGetDataLength(WMData *aData);
 
625
 
 
626
/* Adding data */
 
627
 
 
628
void WMAppendDataBytes(WMData *aData, void *bytes, unsigned length);
 
629
 
 
630
void WMAppendData(WMData *aData, WMData *anotherData);
 
631
 
 
632
/* Modifying data */
 
633
 
 
634
void WMReplaceDataBytesInRange(WMData *aData, WMRange aRange, void *bytes);
 
635
 
 
636
void WMResetDataBytesInRange(WMData *aData, WMRange aRange);
 
637
 
 
638
void WMSetData(WMData *aData, WMData *anotherData);
 
639
 
 
640
 
 
641
void WMSetDataFormat(WMData *aData, unsigned format);
 
642
 
 
643
unsigned WMGetDataFormat(WMData *aData);
 
644
/* Storing data */
 
645
 
 
646
 
 
647
/*--------------------------------------------------------------------------*/
 
648
 
 
649
/* Generic Tree and TreeNode */
 
650
 
 
651
WMTreeNode* WMCreateTreeNode(void *data);
 
652
 
 
653
WMTreeNode* WMCreateTreeNodeWithDestructor(void *data, WMFreeDataProc *destructor);
 
654
 
 
655
WMTreeNode* WMInsertItemInTree(WMTreeNode *parent, int index, void *item);
 
656
 
 
657
#define WMAddItemToTree(parent, item)  WMInsertItemInTree(parent, -1, item)
 
658
 
 
659
WMTreeNode* WMInsertNodeInTree(WMTreeNode *parent, int index, WMTreeNode *aNode);
 
660
 
 
661
#define WMAddNodeToTree(parent, aNode)  WMInsertNodeInTree(parent, -1, aNode)
 
662
 
 
663
void WMDestroyTreeNode(WMTreeNode *aNode);
 
664
 
 
665
void WMDeleteLeafForTreeNode(WMTreeNode *aNode, int index);
 
666
 
 
667
void WMRemoveLeafForTreeNode(WMTreeNode *aNode, void *leaf);
 
668
 
 
669
void* WMReplaceDataForTreeNode(WMTreeNode *aNode, void *newData);
 
670
 
 
671
void* WMGetDataForTreeNode(WMTreeNode *aNode);
 
672
 
 
673
int WMGetTreeNodeDepth(WMTreeNode *aNode);
 
674
 
 
675
WMTreeNode* WMGetParentForTreeNode(WMTreeNode *aNode);
 
676
 
 
677
/* Sort only the leaves of the passed node */
 
678
void WMSortLeavesForTreeNode(WMTreeNode *aNode, WMCompareDataProc *comparer);
 
679
 
 
680
/* Sort all tree recursively starting from the passed node */
 
681
void WMSortTree(WMTreeNode *aNode, WMCompareDataProc *comparer);
 
682
 
 
683
/* Returns the first node which matches node's data with cdata by 'match' */
 
684
WMTreeNode* WMFindInTree(WMTreeNode *aTree, WMMatchDataProc *match, void *cdata);
 
685
 
 
686
/* Returns first tree node that has data == cdata */
 
687
#define WMGetFirstInTree(aTree, cdata) WMFindInTree(aTree, NULL, cdata)
 
688
 
 
689
 
 
690
/*--------------------------------------------------------------------------*/
 
691
 
 
692
 
 
693
WMNotification* WMCreateNotification(const char *name, void *object, void *clientData);
 
694
 
 
695
void WMReleaseNotification(WMNotification *notification);
 
696
 
 
697
WMNotification* WMRetainNotification(WMNotification *notification);
 
698
 
 
699
void* WMGetNotificationClientData(WMNotification *notification);
 
700
 
 
701
void* WMGetNotificationObject(WMNotification *notification);
 
702
 
 
703
const char* WMGetNotificationName(WMNotification *notification);
 
704
 
 
705
 
 
706
void WMAddNotificationObserver(WMNotificationObserverAction *observerAction,
 
707
                               void *observer, const char *name, void *object);
 
708
 
 
709
void WMPostNotification(WMNotification *notification);
 
710
 
 
711
void WMRemoveNotificationObserver(void *observer);
 
712
 
 
713
void WMRemoveNotificationObserverWithName(void *observer, const char *name,
 
714
                                          void *object);
 
715
 
 
716
void WMPostNotificationName(const char *name, void *object, void *clientData);
 
717
 
 
718
WMNotificationQueue* WMGetDefaultNotificationQueue(void);
 
719
 
 
720
WMNotificationQueue* WMCreateNotificationQueue(void);
 
721
 
 
722
void WMDequeueNotificationMatching(WMNotificationQueue *queue,
 
723
                                   WMNotification *notification,
 
724
                                   unsigned mask);
 
725
 
 
726
void WMEnqueueNotification(WMNotificationQueue *queue,
 
727
                           WMNotification *notification,
 
728
                           WMPostingStyle postingStyle);
 
729
 
 
730
void WMEnqueueCoalesceNotification(WMNotificationQueue *queue,
 
731
                                   WMNotification *notification,
 
732
                                   WMPostingStyle postingStyle,
 
733
                                   unsigned coalesceMask);
 
734
 
 
735
 
 
736
/*......................................................................*/
 
737
 
 
738
/* Property Lists handling */
 
739
 
 
740
void WMPLSetCaseSensitive(Bool caseSensitive);
 
741
 
 
742
WMPropList* WMCreatePLString(char *str);
 
743
 
 
744
WMPropList* WMCreatePLData(WMData *data);
 
745
 
 
746
WMPropList* WMCreatePLDataWithBytes(unsigned char *bytes, unsigned int length);
 
747
 
 
748
WMPropList* WMCreatePLDataWithBytesNoCopy(unsigned char *bytes,
 
749
                                          unsigned int length,
 
750
                                          WMFreeDataProc *destructor);
 
751
 
 
752
WMPropList* WMCreatePLArray(WMPropList *elem, ...);
 
753
 
 
754
WMPropList* WMCreatePLDictionary(WMPropList *key, WMPropList *value, ...);
 
755
 
 
756
WMPropList* WMRetainPropList(WMPropList *plist);
 
757
 
 
758
void WMReleasePropList(WMPropList *plist);
 
759
 
 
760
/* Objects inserted in arrays and dictionaries will be retained,
 
761
 * so you can safely release them after insertion.
 
762
 * For dictionaries both the key and value are retained.
 
763
 * Objects removed from arrays or dictionaries are released */
 
764
void WMInsertInPLArray(WMPropList *plist, int index, WMPropList *item);
 
765
 
 
766
void WMAddToPLArray(WMPropList *plist, WMPropList *item);
 
767
 
 
768
void WMDeleteFromPLArray(WMPropList *plist, int index);
 
769
 
 
770
void WMRemoveFromPLArray(WMPropList *plist, WMPropList *item);
 
771
 
 
772
void WMPutInPLDictionary(WMPropList *plist, WMPropList *key, WMPropList *value);
 
773
 
 
774
void WMRemoveFromPLDictionary(WMPropList *plist, WMPropList *key);
 
775
 
 
776
/* It will insert all key/value pairs from source into dest, overwriting
 
777
 * the values with the same keys from dest, keeping all values with keys
 
778
 * only present in dest unchanged */
 
779
WMPropList* WMMergePLDictionaries(WMPropList *dest, WMPropList *source,
 
780
                                  Bool recursive);
 
781
 
 
782
/* It will remove all key/value pairs from dest for which there is an
 
783
 * identical key/value present in source. Entires only present in dest, or
 
784
 * which have different values in dest than in source will be preserved. */
 
785
WMPropList* WMSubtractPLDictionaries(WMPropList *dest, WMPropList *source,
 
786
                                     Bool recursive);
 
787
 
 
788
int WMGetPropListItemCount(WMPropList *plist);
 
789
 
 
790
Bool WMIsPLString(WMPropList *plist);
 
791
 
 
792
Bool WMIsPLData(WMPropList *plist);
 
793
 
 
794
Bool WMIsPLArray(WMPropList *plist);
 
795
 
 
796
Bool WMIsPLDictionary(WMPropList *plist);
 
797
 
 
798
Bool WMIsPropListEqualTo(WMPropList *plist, WMPropList *other);
 
799
 
 
800
/* Returns a reference. Do not free it! */
 
801
char* WMGetFromPLString(WMPropList *plist);
 
802
 
 
803
/* Returns a reference. Do not free it! */
 
804
WMData* WMGetFromPLData(WMPropList *plist);
 
805
 
 
806
/* Returns a reference. Do not free it! */
 
807
const unsigned char* WMGetPLDataBytes(WMPropList *plist);
 
808
 
 
809
int WMGetPLDataLength(WMPropList *plist);
 
810
 
 
811
/* Returns a reference. */
 
812
WMPropList* WMGetFromPLArray(WMPropList *plist, int index);
 
813
 
 
814
/* Returns a reference. */
 
815
WMPropList* WMGetFromPLDictionary(WMPropList *plist, WMPropList *key);
 
816
 
 
817
/* Returns a PropList array with all the dictionary keys. Release it when
 
818
 * you're done. Keys in array are retained from the original dictionary
 
819
 * not copied and need NOT to be released individually. */
 
820
WMPropList* WMGetPLDictionaryKeys(WMPropList *plist);
 
821
 
 
822
/* Creates only the first level deep object. All the elements inside are
 
823
 * retained from the original */
 
824
WMPropList* WMShallowCopyPropList(WMPropList *plist);
 
825
 
 
826
/* Makes a completely separate replica of the original proplist */
 
827
WMPropList* WMDeepCopyPropList(WMPropList *plist);
 
828
 
 
829
WMPropList* WMCreatePropListFromDescription(char *desc);
 
830
 
 
831
/* Free the returned string when you no longer need it */
 
832
char* WMGetPropListDescription(WMPropList *plist, Bool indented);
 
833
 
 
834
WMPropList* WMReadPropListFromFile(char *file);
 
835
 
 
836
Bool WMWritePropListToFile(WMPropList *plist, char *path, Bool atomically);
 
837
 
 
838
/*......................................................................*/
 
839
 
 
840
WMUserDefaults* WMGetStandardUserDefaults(void);
 
841
 
 
842
WMUserDefaults* WMGetDefaultsFromPath(char *path);
 
843
 
 
844
void WMSynchronizeUserDefaults(WMUserDefaults *database);
 
845
 
 
846
void WMSaveUserDefaults(WMUserDefaults *database);
 
847
 
 
848
void WMEnableUDPeriodicSynchronization(WMUserDefaults *database, Bool enable);
 
849
 
 
850
/* Returns a WMPropList array with all the keys in the user defaults database.
 
851
 * Free the array with WMReleasePropList() when no longer needed.
 
852
 * Keys in array are just retained references to the original keys */
 
853
WMPropList* WMGetUDKeys(WMUserDefaults *database);
 
854
 
 
855
WMPropList* WMGetUDObjectForKey(WMUserDefaults *database, char *defaultName);
 
856
 
 
857
void WMSetUDObjectForKey(WMUserDefaults *database, WMPropList *object,
 
858
                         char *defaultName);
 
859
 
 
860
void WMRemoveUDObjectForKey(WMUserDefaults *database, char *defaultName);
 
861
 
 
862
char* WMGetUDStringForKey(WMUserDefaults *database, char *defaultName);
 
863
 
 
864
int WMGetUDIntegerForKey(WMUserDefaults *database, char *defaultName);
 
865
 
 
866
float WMGetUDFloatForKey(WMUserDefaults *database, char *defaultName);
 
867
 
 
868
Bool WMGetUDBoolForKey(WMUserDefaults *database, char *defaultName);
 
869
 
 
870
void WMSetUDStringForKey(WMUserDefaults *database, char *value,
 
871
                         char *defaultName);
 
872
 
 
873
void WMSetUDIntegerForKey(WMUserDefaults *database, int value,
 
874
                          char *defaultName);
 
875
 
 
876
void WMSetUDFloatForKey(WMUserDefaults *database, float value,
 
877
                        char *defaultName);
 
878
 
 
879
void WMSetUDBoolForKey(WMUserDefaults *database, Bool value,
 
880
                       char *defaultName);
 
881
 
 
882
WMPropList* WMGetUDSearchList(WMUserDefaults *database);
 
883
 
 
884
void WMSetUDSearchList(WMUserDefaults *database, WMPropList *list);
 
885
 
 
886
extern char *WMUserDefaultsDidChangeNotification;
 
887
 
 
888
 
 
889
/*-------------------------------------------------------------------------*/
 
890
 
 
891
/* WMHost: host handling */
 
892
 
 
893
WMHost* WMGetCurrentHost();
 
894
 
 
895
WMHost* WMGetHostWithName(char* name);
 
896
 
 
897
WMHost* WMGetHostWithAddress(char* address);
 
898
 
 
899
WMHost* WMRetainHost(WMHost *hPtr);
 
900
 
 
901
void WMReleaseHost(WMHost *hPtr);
 
902
 
 
903
/*
 
904
 * Host cache management
 
905
 * If enabled, only one object representing each host will be created, and
 
906
 * a shared instance will be returned by all methods that return a host.
 
907
 * Enabled by default.
 
908
 */
 
909
void WMSetHostCacheEnabled(Bool flag);
 
910
 
 
911
Bool WMIsHostCacheEnabled();
 
912
 
 
913
void WMFlushHostCache();
 
914
 
 
915
/*
 
916
 * Compare hosts: Hosts are equal if they share at least one address
 
917
 */
 
918
Bool WMIsHostEqualToHost(WMHost* hPtr, WMHost* anotherHost);
 
919
 
 
920
/*
 
921
 * Host names.
 
922
 * WMGetHostName() will return first name (official) if a host has several.
 
923
 * WMGetHostNames() will return a R/O WMArray with all the names of the host.
 
924
 */
 
925
char* WMGetHostName(WMHost* hPtr);
 
926
 
 
927
/* The returned array is R/O. Do not modify it, and do not free it! */
 
928
WMArray* WMGetHostNames(WMHost* hPtr);
 
929
 
 
930
/*
 
931
 * Host addresses.
 
932
 * Addresses are represented as "Dotted Decimal" strings, e.g. "192.42.172.1"
 
933
 * WMGetHostAddress() will return an arbitrary address if a host has several.
 
934
 * WMGetHostAddresses() will return a R/O WMArray with all addresses of the host.
 
935
 */
 
936
char* WMGetHostAddress(WMHost* hPtr);
 
937
 
 
938
/* The returned array is R/O. Do not modify it, and do not free it! */
 
939
WMArray* WMGetHostAddresses(WMHost* hPtr);
 
940
 
 
941
 
 
942
/*-------------------------------------------------------------------------*/
 
943
 
 
944
/* WMConnection functions */
 
945
 
 
946
WMConnection* WMCreateConnectionAsServerAtAddress(char *host, char *service,
 
947
                                                  char *protocol);
 
948
 
 
949
WMConnection* WMCreateConnectionToAddress(char *host, char *service,
 
950
                                          char *protocol);
 
951
 
 
952
WMConnection* WMCreateConnectionToAddressAndNotify(char *host, char *service,
 
953
                                                   char *protocol);
 
954
 
 
955
void WMCloseConnection(WMConnection *cPtr);
 
956
 
 
957
void WMDestroyConnection(WMConnection *cPtr);
 
958
 
 
959
WMConnection* WMAcceptConnection(WMConnection *listener);
 
960
 
 
961
/* Release the returned data! */
 
962
WMData* WMGetConnectionAvailableData(WMConnection *cPtr);
 
963
 
 
964
int WMSendConnectionData(WMConnection *cPtr, WMData *data);
 
965
 
 
966
Bool WMEnqueueConnectionData(WMConnection *cPtr, WMData *data);
 
967
 
 
968
#define WMFlushConnection(cPtr)  WMSendConnectionData((cPtr), NULL)
 
969
 
 
970
void WMSetConnectionDelegate(WMConnection *cPtr, ConnectionDelegate *delegate);
 
971
 
 
972
/* Connection info */
 
973
 
 
974
char* WMGetConnectionAddress(WMConnection *cPtr);
 
975
 
 
976
char* WMGetConnectionService(WMConnection *cPtr);
 
977
 
 
978
char* WMGetConnectionProtocol(WMConnection *cPtr);
 
979
 
 
980
Bool WMSetConnectionNonBlocking(WMConnection *cPtr, Bool flag);
 
981
 
 
982
Bool WMSetConnectionCloseOnExec(WMConnection *cPtr, Bool flag);
 
983
 
 
984
void WMSetConnectionShutdownOnClose(WMConnection *cPtr, Bool flag);
 
985
 
 
986
void* WMGetConnectionClientData(WMConnection *cPtr);
 
987
 
 
988
void WMSetConnectionClientData(WMConnection *cPtr, void *data);
 
989
 
 
990
unsigned int WMGetConnectionFlags(WMConnection *cPtr);
 
991
 
 
992
void WMSetConnectionFlags(WMConnection *cPtr, unsigned int flags);
 
993
 
 
994
int WMGetConnectionSocket(WMConnection *cPtr);
 
995
 
 
996
WMConnectionState WMGetConnectionState(WMConnection *cPtr);
 
997
 
 
998
WMConnectionTimeoutState WMGetConnectionTimeoutState(WMConnection *cPtr);
 
999
 
 
1000
WMArray* WMGetConnectionUnsentData(WMConnection *cPtr);
 
1001
 
 
1002
#define WMGetConnectionQueuedData(cPtr) WMGetConnectionUnsentData(cPtr)
 
1003
 
 
1004
 
 
1005
/*
 
1006
 * Passing timeout==0 in the SetTimeout functions below, will reset that
 
1007
 * timeout to its default value.
 
1008
 */
 
1009
 
 
1010
/* The default timeout inherited by all WMConnection operations, if none set */
 
1011
void WMSetConnectionDefaultTimeout(unsigned int timeout);
 
1012
 
 
1013
/* Global timeout for all WMConnection objects, for opening a new connection */
 
1014
void WMSetConnectionOpenTimeout(unsigned int timeout);
 
1015
 
 
1016
/* Connection specific timeout for sending out data */
 
1017
void WMSetConnectionSendTimeout(WMConnection *cPtr, unsigned int timeout);
 
1018
 
 
1019
 
 
1020
/* Global variables */
 
1021
 
 
1022
extern int WCErrorCode;
 
1023
 
 
1024
 
 
1025
/*-------------------------------------------------------------------------*/
 
1026
 
 
1027
 
 
1028
 
 
1029
#ifdef __cplusplus
 
1030
}
 
1031
#endif /* __cplusplus */
 
1032
 
 
1033
 
 
1034
#endif