hal/libhal libhal.c,1.52,1.53 libhal.h,1.28,1.29
David Zeuthen
david at freedesktop.org
Thu Jul 21 12:03:36 PDT 2005
Update of /cvs/hal/hal/libhal
In directory gabe:/tmp/cvs-serv31761/libhal
Modified Files:
libhal.c libhal.h
Log Message:
2005-07-21 David Zeuthen <davidz at redhat.com>
* libhal-storage/libhal-storage.c, libhal/libhal.[ch]: Patch from
Danny Kukawka <danny.kukawka at web.de>: here the new patch with a
macro instead of always the same codeblock in so many funtions.
Index: libhal.c
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- libhal.c 21 Jul 2005 13:54:11 -0000 1.52
+++ libhal.c 21 Jul 2005 19:03:34 -0000 1.53
@@ -224,12 +224,7 @@
dbus_bool_t
libhal_ctx_set_user_data(LibHalContext *ctx, void *user_data)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->user_data = user_data;
return TRUE;
}
@@ -243,12 +238,7 @@
void*
libhal_ctx_get_user_data(LibHalContext *ctx)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return NULL;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
return ctx->user_data;
}
@@ -350,6 +340,8 @@
LibHalPropertySet *
libhal_device_get_all_properties (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter reply_iter;
@@ -357,13 +349,6 @@
LibHalPropertySet *result;
LibHalProperty *p_last;
DBusError _error;
-
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return NULL;
- }
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
@@ -929,19 +914,14 @@
char **
libhal_get_all_devices (LibHalContext *ctx, int *num_devices, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter_array, reply_iter;
char **hal_device_names;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return hal_device_names;
- }
-
*num_devices = 0;
message = dbus_message_new_method_call ("org.freedesktop.Hal",
@@ -1000,19 +980,14 @@
LibHalPropertyType
libhal_device_get_property_type (LibHalContext *ctx, const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, LIBHAL_PROPERTY_TYPE_INVALID); // or return NULL?
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
int type;
DBusError _error;
-
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return LIBHAL_PROPERTY_TYPE_INVALID; // or NULL?
- }
-
+
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"GetPropertyType");
@@ -1066,18 +1041,13 @@
char **
libhal_device_get_property_strlist (LibHalContext *ctx, const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, iter_array, reply_iter;
char **our_strings;
DBusError _error;
-
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return NULL;
- }
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
@@ -1141,6 +1111,8 @@
libhal_device_get_property_string (LibHalContext *ctx,
const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
@@ -1148,13 +1120,6 @@
char *dbus_str;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return NULL;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"GetPropertyString");
@@ -1221,19 +1186,14 @@
libhal_device_get_property_int (LibHalContext *ctx,
const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, -1);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
dbus_int32_t value;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return -1;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"GetPropertyInteger");
@@ -1295,19 +1255,14 @@
libhal_device_get_property_uint64 (LibHalContext *ctx,
const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, -1);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
dbus_uint64_t value;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return -1;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"GetPropertyInteger");
@@ -1368,19 +1323,14 @@
libhal_device_get_property_double (LibHalContext *ctx,
const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, -1.0);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
double value;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return -1.0;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"GetPropertyDouble");
@@ -1441,19 +1391,14 @@
libhal_device_get_property_bool (LibHalContext *ctx,
const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
dbus_bool_t value;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"GetPropertyBoolean");
@@ -1515,17 +1460,12 @@
dbus_bool_t bool_value,
DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
char *method_name = NULL;
-
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
/** @todo sanity check incoming params */
switch (type) {
@@ -1748,17 +1688,12 @@
const char *value,
DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"StringListAppend");
@@ -1805,17 +1740,12 @@
const char *value,
DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"StringListPrepend");
@@ -1862,17 +1792,12 @@
unsigned int index,
DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"StringListRemoveIndex");
@@ -1918,17 +1843,12 @@
const char *key,
const char *value, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"StringListRemove");
@@ -1977,17 +1897,12 @@
const char *reason_to_lock,
char **reason_why_locked, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessageIter iter;
DBusMessage *reply;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
if (reason_why_locked != NULL)
*reason_why_locked = NULL;
@@ -2048,16 +1963,11 @@
libhal_device_unlock (LibHalContext *ctx,
const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
udi,
"org.freedesktop.Hal.Device",
@@ -2107,19 +2017,14 @@
char *
libhal_new_device (LibHalContext *ctx, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter reply_iter;
char *value;
char *dbus_str;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return NULL;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
@@ -2195,16 +2100,11 @@
libhal_device_commit_to_gdl (LibHalContext *ctx,
const char *temp_udi, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
-
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
@@ -2255,17 +2155,12 @@
dbus_bool_t
libhal_remove_device (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
@@ -2309,19 +2204,14 @@
dbus_bool_t
libhal_device_exists (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
dbus_bool_t value;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
@@ -2383,19 +2273,14 @@
libhal_device_property_exists (LibHalContext *ctx,
const char *udi, const char *key, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
dbus_bool_t value;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"PropertyExists");
@@ -2455,17 +2340,12 @@
libhal_merge_properties (LibHalContext *ctx,
const char *target_udi, const char *source_udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
@@ -2525,19 +2405,14 @@
const char *udi1, const char *udi2,
const char *property_namespace, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, reply_iter;
dbus_bool_t value;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
@@ -2599,18 +2474,13 @@
dbus_bool_t
libhal_device_print (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
int type;
char *key;
LibHalPropertySet *pset;
LibHalPropertySetIterator i;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
printf ("device_id = %s\n", udi);
if ((pset = libhal_device_get_all_properties (ctx, udi, error)) == NULL)
@@ -2689,19 +2559,14 @@
const char *key,
const char *value, int *num_devices, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, iter_array, reply_iter;
char **hal_device_names;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return NULL;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
@@ -2764,17 +2629,12 @@
libhal_device_add_capability (LibHalContext *ctx,
const char *udi, const char *capability, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"AddCapability");
@@ -2821,17 +2681,12 @@
dbus_bool_t
libhal_device_query_capability (LibHalContext *ctx, const char *udi, const char *capability, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
char **caps;
unsigned int i;
dbus_bool_t ret;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
ret = FALSE;
caps = libhal_device_get_property_strlist (ctx, udi, "info.capabilities", error);
@@ -2862,19 +2717,14 @@
libhal_find_device_by_capability (LibHalContext *ctx,
const char *capability, int *num_devices, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, NULL);
+
DBusMessage *message;
DBusMessage *reply;
DBusMessageIter iter, iter_array, reply_iter;
char **hal_device_names;
DBusError _error;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return NULL;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
"/org/freedesktop/Hal/Manager",
"org.freedesktop.Hal.Manager",
@@ -2932,12 +2782,7 @@
dbus_bool_t
libhal_device_property_watch_all (LibHalContext *ctx, DBusError *error)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
dbus_bus_add_match (ctx->connection,
"type='signal',"
@@ -2965,15 +2810,10 @@
dbus_bool_t
libhal_device_add_property_watch (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
char buf[512];
-
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
+
snprintf (buf, 512,
"type='signal',"
"interface='org.freedesktop.Hal.Device',"
@@ -2998,15 +2838,10 @@
dbus_bool_t
libhal_device_remove_property_watch (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
char buf[512];
-
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
+
snprintf (buf, 512,
"type='signal',"
"interface='org.freedesktop.Hal.Device',"
@@ -3064,12 +2899,7 @@
dbus_bool_t
libhal_ctx_set_cache (LibHalContext *ctx, dbus_bool_t use_cache)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->cache_enabled = use_cache;
return TRUE;
@@ -3085,12 +2915,7 @@
dbus_bool_t
libhal_ctx_set_dbus_connection (LibHalContext *ctx, DBusConnection *conn)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
if (conn == NULL)
return FALSE;
@@ -3110,16 +2935,11 @@
dbus_bool_t
libhal_ctx_init (LibHalContext *ctx, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusError _error;
dbus_bool_t hald_exists;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
if (ctx->connection == NULL)
return FALSE;
@@ -3204,15 +3024,10 @@
dbus_bool_t
libhal_ctx_shutdown (LibHalContext *ctx, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusError myerror;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
if (ctx->is_direct) {
/* for some reason dbus_connection_set_exit_on_disconnect doesn't work yet so don't unref */
/*dbus_connection_unref (ctx->connection);*/
@@ -3261,12 +3076,7 @@
dbus_bool_t
libhal_ctx_set_device_added (LibHalContext *ctx, LibHalDeviceAdded callback)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->device_added = callback;
return TRUE;
@@ -3282,12 +3092,7 @@
dbus_bool_t
libhal_ctx_set_device_removed (LibHalContext *ctx, LibHalDeviceRemoved callback)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->device_removed = callback;
return TRUE;
@@ -3304,12 +3109,7 @@
dbus_bool_t
libhal_ctx_set_device_new_capability (LibHalContext *ctx, LibHalDeviceNewCapability callback)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->device_new_capability = callback;
return TRUE;
@@ -3326,12 +3126,7 @@
dbus_bool_t
libhal_ctx_set_device_lost_capability (LibHalContext *ctx, LibHalDeviceLostCapability callback)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->device_lost_capability = callback;
return TRUE;
@@ -3348,12 +3143,7 @@
dbus_bool_t
libhal_ctx_set_device_property_modified (LibHalContext *ctx, LibHalDevicePropertyModified callback)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->device_property_modified = callback;
return TRUE;
@@ -3369,12 +3159,7 @@
dbus_bool_t
libhal_ctx_set_device_condition (LibHalContext *ctx, LibHalDeviceCondition callback)
{
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
ctx->device_condition = callback;
return TRUE;
@@ -3402,18 +3187,13 @@
dbus_bool_t
libhal_device_rescan (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessageIter reply_iter;
DBusMessage *reply;
dbus_bool_t result;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi,
"org.freedesktop.Hal.Device",
"Rescan");
@@ -3456,18 +3236,13 @@
dbus_bool_t
libhal_device_reprobe (LibHalContext *ctx, const char *udi, DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessageIter reply_iter;
DBusMessage *reply;
dbus_bool_t result;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
udi,
"org.freedesktop.Hal.Device",
@@ -3525,19 +3300,14 @@
const char *condition_details,
DBusError *error)
{
+ LIBHAL_CHECK_LIBHALCONTEXT(ctx, FALSE);
+
DBusMessage *message;
DBusMessageIter iter;
DBusMessageIter reply_iter;
DBusMessage *reply;
dbus_bool_t result;
- if (ctx == NULL) {
- fprintf (stderr,
- "%s %d : LibHalContext *ctx is NULL\n",
- __FILE__, __LINE__);
- return FALSE;
- }
-
message = dbus_message_new_method_call ("org.freedesktop.Hal",
udi,
"org.freedesktop.Hal.Device",
Index: libhal.h
===================================================================
RCS file: /cvs/hal/hal/libhal/libhal.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- libhal.h 8 Jul 2005 23:02:29 -0000 1.28
+++ libhal.h 21 Jul 2005 19:03:34 -0000 1.29
@@ -35,6 +35,17 @@
#endif
#endif
+/** Checks if LibHalContext *ctx == NULL */
+#define LIBHAL_CHECK_LIBHALCONTEXT(_ctx_, _ret_) \
+ do { \
+ if (_ctx_ == NULL) { \
+ fprintf (stderr, \
+ "%s %d : LibHalContext *ctx is NULL\n", \
+ __FILE__, __LINE__); \
+ return _ret_; \
+ } \
+ } while(0)
+
/**
* @addtogroup LibHal
*
More information about the hal-commit
mailing list