summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorGravatar dmaas 2003-03-26 22:48:46 +0000
committerGravatar dmaas 2003-03-26 22:48:46 +0000
commit081780c175c6fbcd706ebf37275ae698f3f5b3e9 (patch)
tree319523d71de31c6e09fbaa88b29269a478d3391e /src/main.c
parentUpdates for new rawiso ioctl interface. (diff)
add raw1394_new_handle_on_port() convenience function
git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@104 53a565d1-3bb7-0310-b661-cf11e63c67ab
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c32
1 files changed, 32 insertions, 0 deletions
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;