summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2007-02-15 22:51:50 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2007-02-15 22:51:50 +0000
commit650143b29ba46b74030563c94ef24caaa0f94ff2 (patch)
tree245088ff7bbdcf1de8f4f5ac5a9cc98c68bb419c /audio
parent9332d6301f60d708d94e5956fe3981576f6dfde2 (diff)
Cleanup headset event parsing functions
Diffstat (limited to 'audio')
-rw-r--r--audio/headset.c53
1 files changed, 34 insertions, 19 deletions
diff --git a/audio/headset.c b/audio/headset.c
index 9ce11d10..395136a7 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -59,12 +59,12 @@
#define AUDIO_MANAGER_PATH "/org/bluez/audio"
#define AUDIO_HEADSET_PATH_BASE "/org/bluez/audio/headset"
-struct pending_connect {
- int ch;
- DBusConnection *conn;
- DBusMessage *msg;
- GIOChannel *io;
-};
+typedef enum {
+ HEADSET_EVENT_KEYPRESS,
+ HEADSET_EVENT_GAIN,
+ HEADSET_EVENT_UNKNOWN,
+ HEADSET_EVENT_INVALID
+} headset_event_t;
typedef enum {
HEADSET_STATE_UNAUTHORIZED,
@@ -75,6 +75,13 @@ typedef enum {
HEADSET_STATE_PLAYING,
} headset_state_t;
+struct pending_connect {
+ int ch;
+ DBusConnection *conn;
+ DBusMessage *msg;
+ GIOChannel *io;
+};
+
struct headset {
char object_path[128];
bdaddr_t bda;
@@ -244,29 +251,26 @@ static void hs_signal(struct headset *hs, const char *name)
send_message_and_unref(connection, signal);
}
-static int parse_headset_event(const char *buf, char *rsp, int rsp_len)
+static headset_event_t parse_headset_event(const char *buf, char *rsp, int rsp_len)
{
- int rv = 0;
-
printf("Received: %s\n", buf);
/* Return an error if this is not a proper AT command */
if (strncmp(buf, "AT", 2)) {
snprintf(rsp, rsp_len, "\r\nERROR\r\n");
- return rv;
+ return HEADSET_EVENT_INVALID;
}
buf += 2;
- if (!strncmp(buf, "+CKPD", 5))
- rv = 0;
- else if (!strncmp(buf, "+VG", 3))
- rv = 1;
-
snprintf(rsp, rsp_len, "\r\nOK\r\n");
- /* return 1 if gain event */
- return rv;
+ if (!strncmp(buf, "+CKPD", 5))
+ return HEADSET_EVENT_KEYPRESS;
+ else if (!strncmp(buf, "+VG", 3))
+ return HEADSET_EVENT_GAIN;
+ else
+ return HEADSET_EVENT_UNKNOWN;
}
static gboolean rfcomm_io_cb(GIOChannel *chan, GIOCondition cond,
@@ -318,10 +322,21 @@ static gboolean rfcomm_io_cb(GIOChannel *chan, GIOCondition cond,
memset(rsp, 0, sizeof(rsp));
/* FIXME: make a better parse function */
- if (parse_headset_event(&hs->buf[hs->data_start], rsp, sizeof(rsp)) == 1)
+ switch (parse_headset_event(&hs->buf[hs->data_start], rsp, sizeof(rsp))) {
+ case HEADSET_EVENT_GAIN:
hs_signal_gain_setting(hs, &hs->buf[hs->data_start] + 2);
- else
+ break;
+
+ case HEADSET_EVENT_KEYPRESS:
hs_signal(hs, "AnswerRequested");
+ break;
+
+ case HEADSET_EVENT_INVALID:
+ case HEADSET_EVENT_UNKNOWN:
+ default:
+ debug("Unknown headset event");
+ break;
+ }
count = strlen(rsp);
total_bytes_written = bytes_written = 0;