From 081780c175c6fbcd706ebf37275ae698f3f5b3e9 Mon Sep 17 00:00:00 2001 From: dmaas Date: Wed, 26 Mar 2003 22:48:46 +0000 Subject: [PATCH] add raw1394_new_handle_on_port() convenience function git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@104 53a565d1-3bb7-0310-b661-cf11e63c67ab --- src/main.c | 32 ++++++++++++++++++++++++++++++++ src/raw1394.h | 10 +++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 452d92f..018943d 100644 --- a/src/main.c +++ b/src/main.c @@ -394,6 +394,38 @@ int raw1394_set_port(struct raw1394_handle *handle, int port) } } +/** + * raw1394_new_handle_on_port - create a new handle and bind it to a port + * @port: port to connect to (same as argument to raw1394_set_port()) + * + * Same as raw1394_new_handle(), but also binds the handle to the + * specified 1394 port. Equivalent to raw1394_new_handle() followed by + * raw1394_get_port_info() and raw1394_set_port(). Useful for + * command-line programs that already know what port they want. If + * raw1394_set_port() returns ESTALE, retries automatically. + **/ +raw1394handle_t raw1394_new_handle_on_port(int port) +{ + raw1394handle_t handle = raw1394_new_handle(); + if (!handle) + return NULL; + +tryagain: + if (raw1394_get_port_info(handle, NULL, 0) < 0) + return NULL; + + if (raw1394_set_port(handle, port)) { + if (errno == ESTALE || errno == EINTR) { + goto tryagain; + } else { + raw1394_destroy_handle(handle); + return NULL; + } + } + + return handle; +} + int raw1394_reset_bus_new(struct raw1394_handle *handle, int type) { struct raw1394_request *req = &handle->req; diff --git a/src/raw1394.h b/src/raw1394.h index 15401d2..38ddede 100644 --- a/src/raw1394.h +++ b/src/raw1394.h @@ -156,12 +156,20 @@ int raw1394_errcode_to_errno(raw1394_errcode_t); raw1394handle_t raw1394_new_handle(void); void raw1394_destroy_handle(raw1394handle_t handle); +/* + * Same as raw1394_new_handle(), but also binds the handle to the + * specified 1394 port. Equivalent to raw1394_new_handle() followed by + * raw1394_get_port_info() and raw1394_set_port(). Useful for + * command-line programs that already know what port they want. + */ +raw1394handle_t raw1394_new_handle_on_port(int port); + /* * Switch off/on busreset-notification for handle * return-value: * ==0 success * !=0 failure - * off_on_switch .... RAW1394_NOTIFY_OFF or RAW1394_NOTIFY_ON + * off_on_switch .... RAW1394_NOTIFY_OFF or RAW1394_NOTIFY_ON */ int raw1394_busreset_notify (raw1394handle_t handle, int off_on_switch);