[Bluez-devel] [PATCH 1/3] move common exceptions to common/ directory

fabchevalier
2007-10-28T17:06:04Z

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

Hi Marcel,

This is the first patch for what i have in mind for the dbus errors management:
- org.bluez.Error.xxx : generic errors used by hcid and all services, declared
in common-error.h
- org.bluez.Error.SERVICENAME.yyy : errors that have a meaning only to a local
service.
- org.bluez.core.Error.zzz : errors that have a meaning local to hcid, not
shared with other services.

This is the first patch, that declares the shared by all services.

Regards,

Fabien

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: exceptions-rework-common.diff --]
[-- Type: text/x-patch; name="exceptions-rework-common.diff", Size: 9916 bytes --]

diff -x Entries -u -r -N utils/common/common-error.c utils2/common/common-error.c
--- utils/common/common-error.c 1970-01-01 00:00:00.000000000 +0000
+++ utils2/common/common-error.c 2007-10-27 21:49:12.000000000 +0000
@@ -0,0 +1,140 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2006-2007 Nokia Corporation
+ * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <errno.h>
+
+#include "dbus-helper.h"
+#include "common-error.h"
+
+#define ERROR_INTERFACE "org.bluez.Error"
+
+DBusHandlerResult error_device_unreachable(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".DeviceUnreachable",
+ "Device Unreachable");
+}
+
+DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMessage *msg, int err)
+{
+ return error_common_reply(conn, msg,
+ ERROR_INTERFACE ".ConnectionAttemptFailed",
+ err ? strerror(err) : "Connection attempt failed");
+}
+
+DBusHandlerResult error_already_connected(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_common_reply(conn, msg,
+ ERROR_INTERFACE ".AlreadyConnected",
+ "Already connected to a device");
+}
+
+DBusHandlerResult error_in_progress(DBusConnection *conn, DBusMessage *msg,
+ const char *str)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".InProgress", str);
+}
+
+DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg,
+ const char *descr)
+{
+ return error_common_reply(conn, msg,
+ ERROR_INTERFACE ".InvalidArguments",
+ descr ? descr : "Invalid arguments in method call");
+}
+
+DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".OutOfMemory",
+ "Out of memory");
+}
+
+DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".NotAvailable",
+ "Not available");
+}
+
+DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".NotSupported",
+ "Not supported");
+}
+
+DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".NotConnected",
+ "Not connected");
+}
+
+DBusHandlerResult error_already_exists(DBusConnection *conn, DBusMessage *msg, const char *str)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".AlreadyExists", str);
+}
+
+DBusHandlerResult error_does_not_exist(DBusConnection *conn, DBusMessage *msg, const char *str)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".DoesNotExist", str);
+}
+
+DBusHandlerResult error_device_does_not_exist(DBusConnection *conn, DBusMessage *msg)
+{
+ return error_does_not_exist(conn, msg, "Device does not exist");
+}
+
+DBusHandlerResult error_canceled(DBusConnection *conn, DBusMessage *msg, const char *str)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".Canceled", str);
+}
+
+DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, const char * desc)
+{
+ return error_common_reply(conn, msg, ERROR_INTERFACE ".Failed", desc);
+}
+
+DBusHandlerResult error_failed_errno(DBusConnection *conn, DBusMessage *msg, int err)
+{
+ const char *desc = strerror(err);
+
+ return error_failed(conn, msg, desc);
+}
+
+DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg,
+ const char *name, const char *descr)
+{
+ DBusMessage *derr;
+
+ if (!conn || !msg)
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+ derr = dbus_message_new_error(msg, name, descr);
+ if (!derr)
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+ return dbus_connection_send_and_unref(conn, derr);
+}
diff -x Entries -u -r -N utils/common/common-error.h utils2/common/common-error.h
--- utils/common/common-error.h 1970-01-01 00:00:00.000000000 +0000
+++ utils2/common/common-error.h 2007-10-27 21:38:43.000000000 +0000
@@ -0,0 +1,146 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2006-2007 Nokia Corporation
+ * Copyright (C) 2004-2007 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <dbus/dbus.h>
+
+/**
+ org.bluez.Error.DeviceUnreachable:
+
+ The remote device is either powered down or out of reach.
+*/
+DBusHandlerResult error_device_unreachable(DBusConnection *conn, DBusMessage *msg);
+
+/**
+ org.bluez.Error.ConnectionAttemptFailed:
+
+ An unexpected error (other than DeviceUnreachable) error has occured while
+ attempting a connection to a device
+*/
+DBusHandlerResult error_connection_attempt_failed(DBusConnection *conn, DBusMessage *msg, int err);
+
+/**
+ org.bluez.Error.AlreadyConnected:
+
+ A connection request has been received on an already connected device.
+*/
+DBusHandlerResult error_already_connected(DBusConnection *conn, DBusMessage *msg);
+
+/**
+ org.bluez.Error.NotConnected:
+
+ The remote device is not connected, while the method call
+ would expect it to be, or is not in the expected state to
+ perform the action
+*/
+DBusHandlerResult error_not_connected(DBusConnection *conn, DBusMessage *msg);
+
+/**
+ org.bluez.Error.InProgress:
+
+ The request is already in progress.
+*/
+DBusHandlerResult error_in_progress(DBusConnection *conn, DBusMessage *msg, const char *str);
+
+/**
+ org.bluez.Error.InvalidArguments:
+
+ The DBUS request does not contain the right number of
+ arguments with the right type, or the arguments are there but
+ their value is wrong.
+*/
+DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg, const char *str);
+
+/**
+ org.bluez.Error.OutOfMemory:
+
+ Not much to add
+*/
+DBusHandlerResult error_out_of_memory(DBusConnection *conn, DBusMessage *msg);
+
+/**
+ org.bluez.Error.NotAvailable:
+
+ The requested information is not there.
+ Examples of use: Adapter object when remote info is not available, or Database
+ object record is not found
+*/
+DBusHandlerResult error_not_available(DBusConnection *conn, DBusMessage *msg);
+
+/**
+ org.bluez.Error.NotSupported:
+
+ The remote device does not supopt the expected feature.
+ Examples of use: trying to connect to audio device while audio is not
+ declared in device sdp record.
+*/
+DBusHandlerResult error_not_supported(DBusConnection *conn, DBusMessage *msg);
+
+/**
+ org.bluez.Error.AlreadyExists:
+
+ One of the requested elements already exists
+ Examples of use: Bonding, record, passkey agent, auth agent... already exists
+*/
+DBusHandlerResult error_already_exists(DBusConnection *conn, DBusMessage *msg, const char *str);
+
+/**
+ org.bluez.Error.DoesNotExist:
+
+ One of the requested elements does not exist
+ Examples of use: Bonding, record, passkey agent, auth agent, bluetooth device ... does
+ not exist.
+*/
+DBusHandlerResult error_does_not_exist(DBusConnection *conn, DBusMessage *msg, const char *str);
+
+/**
+ org.bluez.Error.DoesNotExist:
+
+ Same as error_does_not_exist, but with device error message
+*/
+DBusHandlerResult error_device_does_not_exist(DBusConnection *conn, DBusMessage *msg);
+
+/**
+ org.bluez.Error.Canceled:
+*/
+DBusHandlerResult error_canceled(DBusConnection *conn, DBusMessage *msg, const char *str);
+
+/**
+ org.bluez.Error.Failed:
+
+ This is a the most generic error.
+ desc filed is MANDATORY
+*/
+DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, const char *desc);
+
+/**
+ org.bluez.Error.Failed:
+
+ This is a the most generic error, instantiated form a UNIX errno number.
+*/
+DBusHandlerResult error_failed_errno(DBusConnection *conn, DBusMessage *msg, int err);
+
+
+/* Helper function */
+DBusHandlerResult error_common_reply(DBusConnection *conn, DBusMessage *msg,
+ const char *name, const char *descr);
diff -x Entries -u -r -N utils/common/Makefile.am utils2/common/Makefile.am
--- utils/common/Makefile.am 2007-03-20 14:48:01.000000000 +0000
+++ utils2/common/Makefile.am 2007-10-27 15:53:23.000000000 +0000
@@ -26,6 +26,7 @@
libhelper_a_SOURCES = oui.h oui.c dbus.h dbus.c \
textfile.h textfile.c logging.h logging.c \
dbus-helper.h dbus-helper.c \
+ common-error.h common-error.c \
sdp-xml.h sdp-xml.c $(sdp_sources) \
hal.h $(hal_sources) notify.h $(notify_sources)

[-- Attachment #3: Type: text/plain, Size: 314 bytes --]

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/

[-- Attachment #4: Type: text/plain, Size: 164 bytes --]