summaryrefslogtreecommitdiff
path: root/libnul.h
diff options
context:
space:
mode:
Diffstat (limited to 'libnul.h')
-rw-r--r--libnul.h123
1 files changed, 77 insertions, 46 deletions
diff --git a/libnul.h b/libnul.h
index 5a27380..3f01a01 100644
--- a/libnul.h
+++ b/libnul.h
@@ -1,4 +1,4 @@
-/* libnul
+/* libnul
* Copyright (C) 2002, 2008 Søren Sandmann (sandmann@daimi.au.dk)
*
* This library is free software; you can redistribute it and/or modify
@@ -46,11 +46,12 @@
#define NUL_COMPILE_TIME_ASSERT(condition,text) \
typedef char nul_error_##text[(condition)? 1 : -1]
-
+
#define NUL_UR G_GNUC_WARN_UNUSED_RESULT
typedef void * nul_ptr_t;
typedef void * const nul_const_ptr_t;
+typedef int nul_bool_t;
/*
* Generic array implementation
@@ -77,7 +78,7 @@ void nul_garray_free (nul_ptr_t array);
#define nul_prefix_array_append(array,member,value) \
_nul_prefix_array_append_impl(array,member,value)
#define nul_prefix_array_remove(array,member,value) \
- _nul_prefix_array_remove_impl(array,member,value)
+ _nul_prefix_array_remove_impl(array,member,value)
#define nul_prefix_array_remove_fast(array,member,value) \
_nul_prefix_array_remove_impl(array,member,value)
#define nul_prefix_array_len(array,member) \
@@ -95,7 +96,7 @@ typedef char nul_string_t;
nul_string_t *nul_string_new (void) NUL_UR;
void nul_string_free (nul_string_t *str);
gsize nul_string_len (const nul_string_t *str);
-gboolean nul_string_empty (const nul_string_t *str);
+nul_bool_t nul_string_empty (const nul_string_t *str);
nul_string_t *nul_string_append_undefined (nul_string_t *string,
gsize n_bytes,
nul_string_t **tail) NUL_UR;
@@ -121,9 +122,9 @@ typedef struct nul_buffer_t nul_buffer_t;
nul_buffer_t * nul_buffer_new (void);
char * nul_buffer_free (nul_buffer_t *queue,
- gboolean free_data);
+ nul_bool_t free_data);
gsize nul_buffer_get_length (nul_buffer_t *queue);
-gboolean nul_buffer_is_empty (nul_buffer_t *queue);
+nul_bool_t nul_buffer_is_empty (nul_buffer_t *queue);
const nul_string_t *nul_buffer_peek (nul_buffer_t *queue,
gsize *n_bytes);
nul_string_t * nul_buffer_steal (nul_buffer_t *queue,
@@ -144,6 +145,35 @@ void nul_buffer_delete_head (nul_buffer_t *queue,
void nul_buffer_delete_tail (nul_buffer_t *queue,
gsize size);
+/*
+ * Hash tables
+ */
+typedef struct nul_hash_t nul_hash_t;
+typedef nul_bool_t (* nul_hash_equal_func_t) (nul_const_ptr_t key1,
+ nul_const_ptr_t key2);
+
+typedef uint32_t (* nul_hash_func_t) (nul_const_ptr_t key);
+
+typedef void (* nul_free_func_t) (nul_ptr_t data);
+
+nul_hash_t *nul_hash_new (nul_hash_func_t hash,
+ nul_hash_equal_func_t equal,
+ nul_free_func_t free_key,
+ nul_free_func_t free_value);
+void nul_hash_insert (nul_hash_t *hash,
+ nul_ptr_t key,
+ nul_ptr_t value);
+nul_bool_t nul_hash_remove (nul_hash_t *hash,
+ nul_ptr_t key);
+nul_ptr_t nul_hash_lookup (nul_hash_t *hash,
+ nul_ptr_t key);
+nul_bool_t nul_hash_has_key (nul_hash_t *hash,
+ nul_ptr_t key);
+void nul_hash_free (nul_hash_t *hash);
+
+/*
+ * Dynamic function calls
+ */
typedef union
{
uint32_t v_uint32;
@@ -152,7 +182,7 @@ typedef union
int16_t v_int16;
uint8_t v_uint8;
int8_t v_int8;
-
+
unsigned int v_uint;
int v_int;
unsigned short v_ushort;
@@ -160,9 +190,9 @@ typedef union
unsigned char v_uchar;
signed char v_schar;
char v_char;
-
+
void * v_pointer;
-
+
float v_float;
double v_double;
} nul_arg_t;
@@ -175,22 +205,22 @@ typedef enum
NUL_TYPE_INT16,
NUL_TYPE_UINT8,
NUL_TYPE_INT8,
-
+
NUL_TYPE_UINT,
NUL_TYPE_INT,
NUL_TYPE_USHORT,
NUL_TYPE_SHORT,
-
+
NUL_TYPE_UCHAR,
NUL_TYPE_SCHAR,
NUL_TYPE_CHAR,
-
+
NUL_TYPE_POINTER,
NUL_TYPE_STRING,
-
+
NUL_TYPE_DOUBLE,
NUL_TYPE_FLOAT,
-
+
NUL_TYPE_VOID
} nul_type_t;
@@ -219,7 +249,7 @@ typedef enum
NUL_POLL_HANGUP = 1 << 2,
NUL_POLL_ERROR = 1 << 3,
NUL_POLL_PRIORITY = 1 << 4,
-
+
NUL_POLL_RESERVED = 1 << 5 /* This and higher bits are reserved */
} nul_poll_event_type_t;
@@ -238,7 +268,7 @@ void nul_poll_remove_fd (nul_poll_t *epoll,
int fd);
gpointer nul_poll_get_fd_data (nul_poll_t *epoll,
int fd);
-gboolean nul_poll_has_fd (nul_poll_t *epoll,
+nul_bool_t nul_poll_has_fd (nul_poll_t *epoll,
int fd);
void nul_poll_reenable_fd (nul_poll_t *epoll,
int fd);
@@ -270,7 +300,7 @@ void nul_fd_set_priority_callback (int fd,
void nul_fd_set_poll_handler (int fd,
WatchCallback poll_handler);
void nul_fd_remove_watch (int fd);
-gboolean nul_fd_is_watched (int fd);
+nul_bool_t nul_fd_is_watched (int fd);
/*
* File utilities
@@ -283,7 +313,7 @@ char *nul_canonicalize_filename (const char *filename);
typedef void (* signal_func_t) (int signo, gpointer data);
/* FIXME: error out is required */
-gboolean nul_signal_set_handler (int signo,
+nul_bool_t nul_signal_set_handler (int signo,
signal_func_t handler,
gpointer data,
GError **err);
@@ -299,32 +329,33 @@ typedef struct nul_dbus_parameter_t nul_dbus_parameter_t;
typedef struct nul_dbus_arg_t nul_dbus_arg_t;
/* Return TRUE for handled, FALSE for not handled */
-typedef gboolean (* nul_dbus_function_t) ();
-
-nul_dbus_service_t * nul_dbus_session_service (const char *name,
- nul_dbus_object_t *object1,
- ...);
-nul_dbus_object_t * nul_dbus_object (const char *name,
- gpointer data,
- nul_dbus_interface_t *interface1,
- ...);
-nul_dbus_interface_t *nul_dbus_interface (const char *name,
- nul_dbus_member_t *member1,
- ...);
-nul_dbus_member_t * nul_dbus_method (const char *name,
- nul_dbus_function_t function,
- nul_dbus_parameter_t *parameter1,
- ...);
-nul_dbus_parameter_t *nul_dbus_parameter_in (const char *name,
- const nul_dbus_type_t *type);
-nul_dbus_parameter_t *nul_dbus_parameter_out (const char *name,
- const nul_dbus_type_t *type);
-gboolean nul_dbus_service_start (nul_dbus_service_t *service);
-void nul_dbus_service_stop (nul_dbus_service_t *service);
-void nul_dbus_service_set_object_data (nul_dbus_service_t *service,
- const char *obj_name,
- gpointer data);
-
+typedef nul_bool_t (* nul_dbus_function_t) ();
+
+nul_dbus_service_t * nul_dbus_session_service (const char *name,
+ nul_dbus_object_t *object1,
+ ...);
+nul_dbus_object_t * nul_dbus_object (const char *name,
+ gpointer data,
+ nul_dbus_interface_t *interface1,
+ ...);
+nul_dbus_interface_t *nul_dbus_interface (const char *name,
+ nul_dbus_member_t *member1,
+ ...);
+nul_dbus_member_t * nul_dbus_method (const char *name,
+ nul_dbus_function_t function,
+ nul_dbus_parameter_t *parameter1,
+ ...);
+nul_dbus_parameter_t *nul_dbus_parameter_in (const char *name,
+ const nul_dbus_type_t *type);
+nul_dbus_parameter_t *nul_dbus_parameter_out (const char *name,
+ const nul_dbus_type_t *type);
+nul_bool_t nul_dbus_service_start (nul_dbus_service_t *service);
+void nul_dbus_service_stop (nul_dbus_service_t *service);
+void nul_dbus_service_set_object_data (nul_dbus_service_t *service,
+ const char *obj_name,
+ gpointer data);
+
+
/* The returned values here are automatically freed at idle. You
* must copy them if you want to keep them around
*/
@@ -380,8 +411,8 @@ void nul_dbus_invoke (nul_dbus_service_t *service,
#define _nul_prefix_array_new_impl(type,member) \
((type *)nul_garray_new_prefix( \
- sizeof(((type *)NULL)->member[0]), \
- NUL_STRUCT_OFFSET(type,member)))
+ sizeof(((type *)NULL)->member[0]), \
+ NUL_STRUCT_OFFSET(type,member)))
#define _nul_prefix_array_append_impl(array,member,value) \
((typeof (array)) \