summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamr7 <samr7@126591fb-c623-4b62-a76d-97a8e4f34109>2008-11-29 00:40:01 +0000
committersamr7 <samr7@126591fb-c623-4b62-a76d-97a8e4f34109>2008-11-29 00:40:01 +0000
commit34c5e90c0159ab63b2636c596cceeea9f5613537 (patch)
treec5d644a565a85545bd61ae9be8b79d7fea2731ec
parenta3c1f8d92c3bc56993ac9d15a4a980a87cb154bb (diff)
downloadnohands-34c5e90c0159ab63b2636c596cceeea9f5613537.tar.gz
Minor SoundIo backend cleanups.
- Make SetNonBlock() common. - Fix handling of Create/GetDeviceList calls when backend is deconfigured. git-svn-id: http://nohands.svn.sourceforge.net/svnroot/nohands/trunk@48 126591fb-c623-4b62-a76d-97a8e4f34109
-rw-r--r--include/libhfp/bt.h2
-rw-r--r--include/libhfp/events.h2
-rw-r--r--libhfp/bt.cpp16
-rw-r--r--libhfp/events.cpp18
-rw-r--r--libhfp/soundio-alsa.cpp27
-rw-r--r--libhfp/soundio-oss.cpp81
6 files changed, 92 insertions, 54 deletions
diff --git a/include/libhfp/bt.h b/include/libhfp/bt.h
index c1450be..9065f15 100644
--- a/include/libhfp/bt.h
+++ b/include/libhfp/bt.h
@@ -36,8 +36,6 @@
namespace libhfp {
-extern bool SetNonBlock(int fh, bool nonblock);
-
/**
* @defgroup hfp Bluetooth Hands-Free Profile Implementation
*
diff --git a/include/libhfp/events.h b/include/libhfp/events.h
index 2e285c8..5d53036 100644
--- a/include/libhfp/events.h
+++ b/include/libhfp/events.h
@@ -50,6 +50,8 @@ namespace libhfp {
* condition through multiple layers of method calls.
*/
+extern bool SetNonBlock(int fh, bool nonblock);
+
/**
* @brief Dynamic-sized formatted string buffer
diff --git a/libhfp/bt.cpp b/libhfp/bt.cpp
index 40658f6..b5a6dc9 100644
--- a/libhfp/bt.cpp
+++ b/libhfp/bt.cpp
@@ -50,22 +50,6 @@
namespace libhfp {
-bool
-SetNonBlock(int fh, bool nonblock)
-{
- int flags = fcntl(fh, F_GETFL);
- if (nonblock) {
- if (flags & O_NONBLOCK) { return true; }
- flags |= O_NONBLOCK;
- } else {
- if (!(flags & O_NONBLOCK)) { return true; }
- flags &= ~O_NONBLOCK;
- }
-
- return (fcntl(fh, F_SETFL, flags) >= 0);
-}
-
-
/*
* Communicating with SDP servers requires a lot more parsing logic
* than using the HCI command/event interfaces. The libbluetooth SDP
diff --git a/libhfp/events.cpp b/libhfp/events.cpp
index c3850b9..e885f0c 100644
--- a/libhfp/events.cpp
+++ b/libhfp/events.cpp
@@ -18,6 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <unistd.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -28,6 +30,22 @@
namespace libhfp {
+bool
+SetNonBlock(int fh, bool nonblock)
+{
+ int flags = fcntl(fh, F_GETFL);
+ if (nonblock) {
+ if (flags & O_NONBLOCK) { return true; }
+ flags |= O_NONBLOCK;
+ } else {
+ if (!(flags & O_NONBLOCK)) { return true; }
+ flags &= ~O_NONBLOCK;
+ }
+
+ return (fcntl(fh, F_SETFL, flags) >= 0);
+}
+
+
bool StringBuffer::
Enlarge(void)
{
diff --git a/libhfp/soundio-alsa.cpp b/libhfp/soundio-alsa.cpp
index 3211079..128370a 100644
--- a/libhfp/soundio-alsa.cpp
+++ b/libhfp/soundio-alsa.cpp
@@ -908,8 +908,13 @@ public:
if (m_rec_nonblock != nonblock) {
err = snd_pcm_nonblock(m_alsa.m_rec_handle, nonblock);
if (err < 0) {
- m_alsa.m_ei->LogWarn("ALSA set nonblock: "
+ m_alsa.m_ei->LogWarn(&error,
+ LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_SYSCALL,
+ "ALSA set rec nonblock: "
"%ld", err);
+ BufAbort(m_alsa.m_ei, error);
+ return;
}
m_rec_nonblock = nonblock;
}
@@ -974,8 +979,13 @@ public:
if (m_play_nonblock != nonblock) {
err = snd_pcm_nonblock(m_alsa.m_play_handle, nonblock);
if (err < 0) {
- m_alsa.m_ei->LogWarn("ALSA set nonblock: "
+ m_alsa.m_ei->LogWarn(&error,
+ LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_SYSCALL,
+ "ALSA set play nonblock: "
"%zd", err);
+ BufAbort(m_alsa.m_ei, error);
+ return;
}
m_play_nonblock = nonblock;
}
@@ -1640,13 +1650,22 @@ SoundIoGetDeviceListAlsa(ErrorInfo *error)
#else /* defined(USE_ALSA_SOUNDIO) */
SoundIo *
-SoundIoCreateAlsa(DispatchInterface *dip, const char *devspec)
+SoundIoCreateAlsa(DispatchInterface *dip, const char *devspec,
+ ErrorInfo *error)
{
+ if (error)
+ error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED,
+ "Support for ALSA omitted");
return 0;
}
SoundIoDeviceList *
-SoundIoGetDeviceListAlsa(void)
+SoundIoGetDeviceListAlsa(ErrorInfo *error)
{
+ if (error)
+ error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED,
+ "Support for ALSA omitted");
return 0;
}
#endif /* defined(USE_ALSA_SOUNDIO) */
diff --git a/libhfp/soundio-oss.cpp b/libhfp/soundio-oss.cpp
index b811dc2..add3686 100644
--- a/libhfp/soundio-oss.cpp
+++ b/libhfp/soundio-oss.cpp
@@ -44,21 +44,6 @@ namespace libhfp {
#if defined(USE_OSS_SOUNDIO)
-static bool
-SetNonBlock(int fh, bool nonblock)
-{
- int flags = fcntl(fh, F_GETFL);
- if (nonblock) {
- if (flags & O_NONBLOCK) { return true; }
- flags |= O_NONBLOCK;
- } else {
- if (!(flags & O_NONBLOCK)) { return true; }
- flags &= ~O_NONBLOCK;
- }
-
- return (fcntl(fh, F_SETFL, flags) >= 0);
-}
-
/*
* Sound I/O routines for deprecated OSS. Don't use this unless you have to.
*/
@@ -81,16 +66,10 @@ class OssSoundIo : public SoundIoBufferBase {
SocketNotifier *m_not;
public:
- OssSoundIo(DispatchInterface *eip,
- const char *play_dev, const char *rec_dev)
+ OssSoundIo(DispatchInterface *eip, char *play_dev, char *rec_dev)
: m_play_fh(-1), m_rec_fh(-1),
- m_play_path(NULL), m_rec_path(NULL), m_obuf_size(0),
+ m_play_path(play_dev), m_rec_path(rec_dev), m_obuf_size(0),
m_ei(eip), m_not(NULL) {
- if (play_dev)
- m_play_path = strdup(play_dev);
- if (rec_dev)
- m_rec_path = strdup(rec_dev);
-
/* Set a default format */
memset(&m_format, 0, sizeof(m_format));
m_format.sampletype = SIO_PCM_S16_LE;
@@ -219,7 +198,7 @@ public:
m_ei->LogWarn(error,
LIBHFP_ERROR_SUBSYS_SOUNDIO,
LIBHFP_ERROR_SOUNDIO_SYSCALL,
- "OSS get output space: %s",
+ "OSS GETOSPACE: %s",
strerror(errno));
return false;
}
@@ -376,8 +355,13 @@ public:
if (m_rec_nonblock != nonblock) {
if (!SetNonBlock(m_rec_fh, nonblock)) {
- m_ei->LogWarn("OSS set rec nonblock: %s",
+ m_ei->LogWarn(&error,
+ LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_SYSCALL,
+ "OSS set rec nonblock: %s",
strerror(errno));
+ BufAbort(m_ei, error);
+ return;
}
m_rec_nonblock = nonblock;
if (m_play_fh == m_rec_fh)
@@ -417,8 +401,13 @@ public:
if (m_play_nonblock != nonblock) {
if (!SetNonBlock(m_play_fh, nonblock)) {
- m_ei->LogWarn("OSS set play nonblock "
- "failed");
+ m_ei->LogWarn(&error,
+ LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_SYSCALL,
+ "OSS set play nonblock: %s",
+ strerror(errno));
+ BufAbort(m_ei, error);
+ return;
}
m_play_nonblock = nonblock;
if (m_play_fh == m_rec_fh)
@@ -461,7 +450,7 @@ public:
if (m_play_fh >= 0) {
if (ioctl(m_play_fh, SNDCTL_DSP_GETODELAY,
&delay) < 0) {
- m_ei->LogWarn("OSS GETOSPACE: %s",
+ m_ei->LogWarn("OSS GETODELAY: %s",
strerror(errno));
delay = m_hw_outq;
} else {
@@ -610,14 +599,33 @@ SoundIoCreateOss(DispatchInterface *dip, const char *driveropts,
tok = strtok_r(NULL, "&", &save);
}
- ossp = new OssSoundIo(dip, outd, ind);
+ tmp = strdup(outd);
+ if (!outd) {
+ free(tmp);
+ if (error)
+ error->SetNoMem();
+ ossp = 0;
+ goto failed;
+ }
+
+ tok = strdup(ind);
+ if (!tok) {
+ if (error)
+ error->SetNoMem();
+ ossp = 0;
+ goto failed;
+ }
+ ossp = new OssSoundIo(dip, tmp, tok);
if (!ossp) {
+ free(tmp);
+ free(tok);
if (error)
error->SetNoMem();
- return 0;
+ goto failed;
}
+failed:
if (opts)
free(opts);
return ossp;
@@ -667,13 +675,22 @@ SoundIoGetDeviceListOss(ErrorInfo *error)
#else /* defined(USE_OSS_SOUNDIO) */
SoundIo *
-SoundIoCreateOss(DispatchInterface *dip, const char *driveropts)
+SoundIoCreateOss(DispatchInterface *dip, const char *driveropts,
+ ErrorInfo *error)
{
+ if (error)
+ error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED,
+ "Support for OSS omitted");
return 0;
}
SoundIoDeviceList *
-SoundIoGetDeviceInfoOss(void)
+SoundIoGetDeviceInfoOss(ErrorInfo *error)
{
+ if (error)
+ error->Set(LIBHFP_ERROR_SUBSYS_SOUNDIO,
+ LIBHFP_ERROR_SOUNDIO_NOT_SUPPORTED,
+ "Support for OSS omitted");
return 0;
}
#endif /* defined(USE_OSS_SOUNDIO) */