summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2011-01-12 23:53:38 -0600
committerDenis Kenzior <denkenz@gmail.com>2011-01-12 23:53:38 -0600
commitfebb9014ca9056dda4e99ba8dfeb80ec77644b9a (patch)
treeae0db018d636d279eb5a59e64564538530cba313 /drivers
parent492f0629ca9e01d9d0bc10be331003b792caf5e8 (diff)
downloadofono-febb9014ca9056dda4e99ba8dfeb80ec77644b9a.tar.bz2
atutil: Break out attribute parser into atutil
Diffstat (limited to 'drivers')
-rw-r--r--drivers/atmodem/atutil.c43
-rw-r--r--drivers/atmodem/atutil.h3
-rw-r--r--drivers/atmodem/devinfo.c46
3 files changed, 53 insertions, 39 deletions
diff --git a/drivers/atmodem/atutil.c b/drivers/atmodem/atutil.c
index 427b0987..0726da0f 100644
--- a/drivers/atmodem/atutil.c
+++ b/drivers/atmodem/atutil.c
@@ -438,3 +438,46 @@ gboolean at_util_parse_cscs_query(GAtResult *result,
return FALSE;
}
+
+static const char *at_util_fixup_return(const char *line, const char *prefix)
+{
+ if (g_str_has_prefix(line, prefix) == FALSE)
+ return line;
+
+ line += strlen(prefix);
+
+ while (line[0] == ' ')
+ line++;
+
+ return line;
+}
+
+gboolean at_util_parse_attr(GAtResult *result, const char *prefix,
+ const char **out_attr)
+{
+ int numlines = g_at_result_num_response_lines(result);
+ GAtResultIter iter;
+ const char *line;
+ int i;
+
+ if (numlines == 0)
+ return FALSE;
+
+ g_at_result_iter_init(&iter, result);
+
+ /*
+ * We have to be careful here, sometimes a stray unsolicited
+ * notification will appear as part of the response and we
+ * cannot rely on having a prefix to recognize the actual
+ * response line. So use the last line only as the response
+ */
+ for (i = 0; i < numlines; i++)
+ g_at_result_iter_next(&iter, NULL);
+
+ line = g_at_result_iter_raw_line(&iter);
+
+ if (out_attr)
+ *out_attr = at_util_fixup_return(line, prefix);
+
+ return TRUE;
+}
diff --git a/drivers/atmodem/atutil.h b/drivers/atmodem/atutil.h
index 39018016..3d13b84c 100644
--- a/drivers/atmodem/atutil.h
+++ b/drivers/atmodem/atutil.h
@@ -71,6 +71,9 @@ gboolean at_util_parse_cscs_supported(GAtResult *result, int *supported);
gboolean at_util_parse_cscs_query(GAtResult *result,
enum at_util_charset *charset);
+gboolean at_util_parse_attr(GAtResult *result, const char *prefix,
+ const char **out_attr);
+
struct cb_data {
void *cb;
void *data;
diff --git a/drivers/atmodem/devinfo.c b/drivers/atmodem/devinfo.c
index 84ff8988..8d0830b7 100644
--- a/drivers/atmodem/devinfo.c
+++ b/drivers/atmodem/devinfo.c
@@ -35,29 +35,13 @@
#include "atmodem.h"
-static const char *fixup_return(const char *line, const char *prefix)
-{
- if (g_str_has_prefix(line, prefix) == FALSE)
- return line;
-
- line = line + strlen(prefix);
-
- while (line[0] == ' ')
- line++;
-
- return line;
-}
-
static void attr_cb(gboolean ok, GAtResult *result, gpointer user_data)
{
struct cb_data *cbd = user_data;
ofono_devinfo_query_cb_t cb = cbd->cb;
const char *prefix = cbd->user;
struct ofono_error error;
- int numlines = g_at_result_num_response_lines(result);
- GAtResultIter iter;
- const char *line;
- int i;
+ const char *attr;
decode_at_error(&error, g_at_result_final_response(result));
@@ -66,24 +50,12 @@ static void attr_cb(gboolean ok, GAtResult *result, gpointer user_data)
return;
}
- if (numlines == 0) {
+ if (at_util_parse_attr(result, prefix, &attr) == FALSE) {
CALLBACK_WITH_FAILURE(cb, NULL, cbd->data);
return;
}
- g_at_result_iter_init(&iter, result);
-
- /* We have to be careful here, sometimes a stray unsolicited
- * notification will appear as part of the response and we
- * cannot rely on having a prefix to recognize the actual
- * response line. So use the last line only as the response
- */
- for (i = 0; i < numlines; i++)
- g_at_result_iter_next(&iter, NULL);
-
- line = g_at_result_iter_raw_line(&iter);
-
- cb(&error, fixup_return(line, prefix), cbd->data);
+ cb(&error, attr, cbd->data);
}
static void at_query_manufacturer(struct ofono_devinfo *info,
@@ -97,8 +69,7 @@ static void at_query_manufacturer(struct ofono_devinfo *info,
cbd->user = "+CGMI:";
- if (g_at_chat_send(chat, "AT+CGMI", NULL,
- attr_cb, cbd, g_free) > 0)
+ if (g_at_chat_send(chat, "AT+CGMI", NULL, attr_cb, cbd, g_free) > 0)
return;
error:
@@ -118,8 +89,7 @@ static void at_query_model(struct ofono_devinfo *info,
cbd->user = "+CGMM:";
- if (g_at_chat_send(chat, "AT+CGMM", NULL,
- attr_cb, cbd, g_free) > 0)
+ if (g_at_chat_send(chat, "AT+CGMM", NULL, attr_cb, cbd, g_free) > 0)
return;
error:
@@ -139,8 +109,7 @@ static void at_query_revision(struct ofono_devinfo *info,
cbd->user = "+CGMR:";
- if (g_at_chat_send(chat, "AT+CGMR", NULL,
- attr_cb, cbd, g_free) > 0)
+ if (g_at_chat_send(chat, "AT+CGMR", NULL, attr_cb, cbd, g_free) > 0)
return;
error:
@@ -160,8 +129,7 @@ static void at_query_serial(struct ofono_devinfo *info,
cbd->user = "+CGSN:";
- if (g_at_chat_send(chat, "AT+CGSN", NULL,
- attr_cb, cbd, g_free) > 0)
+ if (g_at_chat_send(chat, "AT+CGSN", NULL, attr_cb, cbd, g_free) > 0)
return;
error: