core: add index to CIND helper

This commit is contained in:
Dan Williams
2010-11-28 21:34:00 -06:00
parent 9479c04aec
commit 2dd59c3ddd
3 changed files with 25 additions and 12 deletions

View File

@@ -888,17 +888,19 @@ mm_create_device_identifier (guint vid,
struct CindResponse { struct CindResponse {
char *desc; char *desc;
gint idx;
gint min; gint min;
gint max; gint max;
}; };
static CindResponse * static CindResponse *
cind_response_new (const char *desc, gint min, gint max) cind_response_new (const char *desc, gint idx, gint min, gint max)
{ {
CindResponse *r; CindResponse *r;
char *p; char *p;
g_return_val_if_fail (desc != NULL, NULL); g_return_val_if_fail (desc != NULL, NULL);
g_return_val_if_fail (idx >= 0, NULL);
r = g_malloc0 (sizeof (CindResponse)); r = g_malloc0 (sizeof (CindResponse));
@@ -910,6 +912,7 @@ cind_response_new (const char *desc, gint min, gint max)
desc++; desc++;
} }
r->idx = idx;
r->max = max; r->max = max;
r->min = min; r->min = min;
return r; return r;
@@ -933,10 +936,18 @@ cind_response_get_desc (CindResponse *r)
return r->desc; return r->desc;
} }
gint
cind_response_get_index (CindResponse *r)
{
g_return_val_if_fail (r != NULL, -1);
return r->idx;
}
gint gint
cind_response_get_min (CindResponse *r) cind_response_get_min (CindResponse *r)
{ {
g_return_val_if_fail (r != NULL, 0); g_return_val_if_fail (r != NULL, -1);
return r->min; return r->min;
} }
@@ -944,7 +955,7 @@ cind_response_get_min (CindResponse *r)
gint gint
cind_response_get_max (CindResponse *r) cind_response_get_max (CindResponse *r)
{ {
g_return_val_if_fail (r != NULL, 0); g_return_val_if_fail (r != NULL, -1);
return r->max; return r->max;
} }
@@ -957,6 +968,7 @@ mm_parse_cind_response (const char *reply, GError **error)
GHashTable *hash; GHashTable *hash;
GRegex *r; GRegex *r;
GMatchInfo *match_info; GMatchInfo *match_info;
gint idx = 0;
g_return_val_if_fail (reply != NULL, NULL); g_return_val_if_fail (reply != NULL, NULL);
@@ -992,7 +1004,7 @@ mm_parse_cind_response (const char *reply, GError **error)
max = atoi (tmp); max = atoi (tmp);
g_free (tmp); g_free (tmp);
resp = cind_response_new (desc, min, max); resp = cind_response_new (desc, idx++, min, max);
if (resp) if (resp)
g_hash_table_insert (hash, g_strdup (resp->desc), resp); g_hash_table_insert (hash, g_strdup (resp->desc), resp);

View File

@@ -72,6 +72,7 @@ char *mm_create_device_identifier (guint vid,
typedef struct CindResponse CindResponse; typedef struct CindResponse CindResponse;
GHashTable *mm_parse_cind_response (const char *reply, GError **error); GHashTable *mm_parse_cind_response (const char *reply, GError **error);
const char *cind_response_get_desc (CindResponse *r); const char *cind_response_get_desc (CindResponse *r);
gint cind_response_get_index (CindResponse *r);
gint cind_response_get_min (CindResponse *r); gint cind_response_get_min (CindResponse *r);
gint cind_response_get_max (CindResponse *r); gint cind_response_get_max (CindResponse *r);

View File

@@ -1103,13 +1103,13 @@ test_cind_results (const char *desc,
for (i = 0; i < expected_results_len; i++) { for (i = 0; i < expected_results_len; i++) {
CindEntry *expected = &expected_results[i]; CindEntry *expected = &expected_results[i];
CindEntry *compare; CindResponse *compare;
compare = g_hash_table_lookup (results, expected->desc); compare = g_hash_table_lookup (results, expected->desc);
g_assert (compare); g_assert (compare);
g_assert_cmpint (i, ==, cind_response_get_index (compare));
g_assert_cmpint (expected->min, ==, compare->min); g_assert_cmpint (expected->min, ==, cind_response_get_min (compare));
g_assert_cmpint (expected->max, ==, compare->max); g_assert_cmpint (expected->max, ==, cind_response_get_max (compare));
} }
g_hash_table_destroy (results); g_hash_table_destroy (results);