From: fabchevalier@free.fr
To: marcel@holtmann.org, bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] [PATCH 1/3] move common exceptions to common/ directory
Date: Sun, 28 Oct 2007 18:06:04 +0100 [thread overview]
Message-ID: <1193591164.4724c17c545eb@imp.free.fr> (raw)
[-- 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 --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next reply other threads:[~2007-10-28 17:06 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-28 17:06 fabchevalier [this message]
2007-10-28 18:16 ` [Bluez-devel] [PATCH 1/3] move common exceptions to common/ directory Marcel Holtmann
2007-10-28 18:01 ` fabchevalier
2007-10-28 18:15 ` fabchevalier
2007-10-28 19:40 ` Marcel Holtmann
2007-10-28 19:06 ` fabchevalier
2007-10-28 20:46 ` Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1193591164.4724c17c545eb@imp.free.fr \
--to=fabchevalier@free.fr \
--cc=bluez-devel@lists.sourceforge.net \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox