First implementation of new error reporting API.

git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@49 53a565d1-3bb7-0310-b661-cf11e63c67ab
This commit is contained in:
aeb 2001-01-19 01:11:48 +00:00
parent 2b61e222ea
commit e6015ce5e9
7 changed files with 133 additions and 27 deletions

View File

@ -1,7 +1,7 @@
# process this file with autoconf to get a configure script
AC_INIT(Makefile.am)
AM_INIT_AUTOMAKE(libraw1394, 0.8.2)
AM_INIT_AUTOMAKE(libraw1394, 0.9pre)
AM_CONFIG_HEADER(config.h)
AC_PROG_CC
@ -9,11 +9,13 @@ AM_PROG_LIBTOOL
AC_PROG_INSTALL
AC_CHECK_SIZEOF(void *, 8)
AC_C_CONST
AC_C_BIGENDIAN
# set the libtool so version numbers
lt_major=5
lt_revision=0
lt_age=1
lt_revision=1
lt_age=0
AC_SUBST(lt_major)
AC_SUBST(lt_revision)

88
src/errors.c Normal file
View File

@ -0,0 +1,88 @@
/*
* libraw1394 - library for raw access to the 1394 bus with the Linux subsystem.
*
* Copyright (C) 1999,2000 Andreas Bombe
*
* This library is licensed under the GNU Lesser General Public License (LGPL),
* version 2.1 or later. See the file COPYING.LIB in the distribution for
* details.
*/
#include <config.h>
#include <errno.h>
#include "raw1394.h"
#include "kernel-raw1394.h"
#include "raw1394_private.h"
raw1394_errcode_t raw1394_get_errcode(struct raw1394_handle *handle)
{
return handle->err;
}
int raw1394_errcode_to_errno(raw1394_errcode_t errcode)
{
static const int ack2errno[16] = {
0xdead, /* invalid ack code */
0, /* ack_complete */
0xdead, /* ack_pending, should not be used here */
EAGAIN, /* busy_x, busy_a and busy_b acks */
EAGAIN,
EAGAIN,
0xdead, /* invalid ack codes */
0xdead,
0xdead,
0xdead,
0xdead,
0xdead,
0xdead,
EREMOTEIO, /* ack_data_error */
EPERM, /* ack_type_error */
0xdead /* invalid ack code */
};
static const int rcode2errno[16] = {
0, /* rcode_complete */
0xdead, /* invalid rcodes */
0xdead,
0xdead,
EAGAIN, /* rcode_conflict_error */
EREMOTEIO, /* rcode_data_error */
EPERM, /* rcode_type_error */
EINVAL, /* rcode_address_error */
0xdead, /* invalid rcodes */
0xdead,
0xdead,
0xdead,
0xdead,
0xdead,
0xdead,
0xdead
};
if (!raw1394_internal_err(errcode)) {
if (raw1394_get_ack(errcode) == L1394_ACK_PENDING)
return rcode2errno[raw1394_get_rcode(errcode)];
else
return ack2errno[raw1394_get_ack(errcode)];
}
switch (raw1394_get_internal(errcode)) {
case RAW1394_ERROR_GENERATION:
case RAW1394_ERROR_SEND_ERROR:
case RAW1394_ERROR_ABORTED:
case RAW1394_ERROR_TIMEOUT:
return EAGAIN;
case RAW1394_ERROR_MEMFAULT:
return EFAULT;
case RAW1394_ERROR_COMPAT:
case RAW1394_ERROR_STATE_ORDER:
case RAW1394_ERROR_INVALID_ARG:
case RAW1394_ERROR_ALREADY:
case RAW1394_ERROR_EXCESSIVE:
case RAW1394_ERROR_UNTIDY_LEN:
default:
return EINVAL;
}
}

View File

@ -45,6 +45,9 @@ int raw1394_loop_iterate(struct raw1394_handle *handle)
case RAW1394_REQ_ISO_RECEIVE:
channel = (handle->buffer[0] >> 8) & 0x3f;
#ifndef WORDS_BIGENDIAN
/* swap(buffer[0]); */
#endif
if (handle->iso_handler[channel]) {
retval = handle->iso_handler[channel](handle, channel,

View File

@ -76,7 +76,7 @@ static unsigned int init_rawdevice(struct raw1394_handle *h)
}
struct raw1394_handle *raw1394_get_handle(void)
struct raw1394_handle *raw1394_new_handle(void)
{
struct raw1394_handle *handle;
@ -99,6 +99,7 @@ struct raw1394_handle *raw1394_get_handle(void)
return NULL;
}
handle->err = 0;
handle->bus_reset_handler = bus_reset_default;
handle->tag_handler = tag_handler_default;
memset(handle->iso_handler, 0, sizeof(handle->iso_handler));

View File

@ -8,21 +8,28 @@ typedef u_int64_t octlet_t;
typedef u_int64_t nodeaddr_t;
typedef u_int16_t nodeid_t;
typedef struct raw1394_handle *raw1394handle_t;
#ifdef __cplusplus
extern "C" {
//extern "C" {
#endif
typedef int raw1394_errcode_t;
#define raw1394_make_errcode(ack, rcode) (((ack) << 16) | rcode)
#define raw1394_internal_err(errcode) ((errcode) < 0)
#define raw1394_get_ack(errcode) ((errcode) >> 16)
#define raw1394_get_rcode(errcode) ((errcode) & 0xf)
#define raw1394_get_internal(errcode) (errcode)
raw1394_errcode_t raw1394_get_errcode(raw1394handle_t);
int raw1394_errcode_to_errno(raw1394_errcode_t);
/*
* Required as initialization. One handle can control one port, it is possible
* to use multiple handles. raw1394_get_handle returns NULL for failure,
* raw1394_destroy_handle accepts NULL. If raw1394_get_handle returns NULL and
* to use multiple handles. raw1394_new_handle returns NULL for failure,
* raw1394_destroy_handle accepts NULL. If raw1394_new_handle returns NULL and
* errno is 0, this version of libraw1394 is incompatible with the kernel.
*/
raw1394handle_t raw1394_get_handle(void);
raw1394handle_t raw1394_new_handle(void);
void raw1394_destroy_handle(raw1394handle_t handle);
/*
@ -96,7 +103,8 @@ bus_reset_handler_t raw1394_set_bus_reset_handler(raw1394handle_t handle,
* The default action is to call the callback in the raw1394_reqhandle pointed
* to by tag. Returns old handler.
*/
typedef int (*tag_handler_t)(raw1394handle_t, unsigned long tag, int errcode);
typedef int (*tag_handler_t)(raw1394handle_t, unsigned long tag,
raw1394_errcode_t err);
tag_handler_t raw1394_set_tag_handler(raw1394handle_t handle,
tag_handler_t new_h);
@ -132,7 +140,8 @@ fcp_handler_t raw1394_set_fcp_handler(raw1394handle_t, fcp_handler_t);
* when a request completes, it calls the callback and passes it the data
* pointer and the error code of the request.
*/
typedef int (*req_callback_t)(raw1394handle_t, void *data, int errcode);
typedef int (*req_callback_t)(raw1394handle_t, void *data,
raw1394_errcode_t err);
struct raw1394_reqhandle {
req_callback_t callback;
void *data;
@ -146,10 +155,10 @@ int raw1394_start_read(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
size_t length, quadlet_t *buffer, unsigned long tag);
int raw1394_start_write(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
size_t length, quadlet_t *data, unsigned long tag);
int raw1394_start_lock(struct raw1394_handle *handle, nodeid_t node,
nodeaddr_t addr, unsigned int extcode, quadlet_t data,
quadlet_t arg, quadlet_t *result, unsigned long tag);
int raw1394_start_iso_write(struct raw1394_handle *handle, unsigned int channel,
int raw1394_start_lock(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
unsigned int extcode, quadlet_t data, quadlet_t arg,
quadlet_t *result, unsigned long tag);
int raw1394_start_iso_write(raw1394handle_t handle, unsigned int channel,
unsigned int tag, unsigned int sy,
unsigned int speed, size_t length, quadlet_t *data,
unsigned long rawtag);
@ -163,10 +172,10 @@ int raw1394_read(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
size_t length, quadlet_t *buffer);
int raw1394_write(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
size_t length, quadlet_t *data);
int raw1394_lock(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr,
int raw1394_lock(raw1394handle_t handle, nodeid_t node, nodeaddr_t addr,
unsigned int extcode, quadlet_t data, quadlet_t arg,
quadlet_t *result);
int raw1394_iso_write(struct raw1394_handle *handle, unsigned int channel,
int raw1394_iso_write(raw1394handle_t handle, unsigned int channel,
unsigned int tag, unsigned int sy, unsigned int speed,
size_t length, quadlet_t *data);

View File

@ -11,6 +11,9 @@ struct raw1394_handle {
int num_of_nodes;
nodeid_t irm_id;
raw1394_errcode_t err;
void *userdata;
bus_reset_handler_t bus_reset_handler;
tag_handler_t tag_handler;
fcp_handler_t fcp_handler;
@ -18,8 +21,6 @@ struct raw1394_handle {
struct raw1394_request req;
quadlet_t buffer[2048];
void *userdata;
};
struct sync_cb_data {

View File

@ -120,14 +120,16 @@ int raw1394_start_iso_write(struct raw1394_handle *handle, unsigned int channel,
struct sync_cb_data sd = { 0, 0 }; \
struct raw1394_reqhandle rh = { (req_callback_t)_raw1394_sync_cb, \
&sd }; \
int err
int err = 0
#define SYNCFUNC_BODY \
while (!sd.done) { \
if (err < 0) return err; \
err = raw1394_loop_iterate(handle); \
} \
return sd.errcode
#define SYNCFUNC_BODY \
while (!sd.done) { \
if (err < 0) return err; \
err = raw1394_loop_iterate(handle); \
} \
handle->err = sd.errcode; \
errno = raw1394_errcode_to_errno(sd.errcode); \
return (errno ? -1 : 0)
int raw1394_read(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr,
size_t length, quadlet_t *buffer)