Skip to content

Commit

Permalink
Merge branch 'jb53576' into 'master'
Browse files Browse the repository at this point in the history
Sumbit a pending request from the DBus queue

See merge request mer-core/ofono!279
  • Loading branch information
monich committed Mar 17, 2021
2 parents 8e35a04 + 246cd4e commit 870bac9
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 19 deletions.
44 changes: 29 additions & 15 deletions ofono/src/dbus-queue.c
Expand Up @@ -121,6 +121,30 @@ void __ofono_dbus_queue_request(struct ofono_dbus_queue *q,
}
}

static void __ofono_dbus_queue_submit_next(struct ofono_dbus_queue *q)
{
struct ofono_dbus_queue_request *next = q->requests;

while (next) {
struct ofono_dbus_queue_request *done;
DBusMessage *reply = next->fn(next->msg, next->data);

/* The request has been sent, no reply yet */
if (!reply)
break;

/* The request has completed synchronously */
done = next;
next = done->next;
q->requests = next;
done->next = NULL;

/* Send the reply */
__ofono_dbus_pending_reply(&done->msg, reply);
__ofono_dbus_queue_req_free(done);
}
}

/* Consumes one reference to the reply */
void __ofono_dbus_queue_reply_msg(struct ofono_dbus_queue *q,
DBusMessage *reply)
Expand Down Expand Up @@ -150,20 +174,7 @@ void __ofono_dbus_queue_reply_msg(struct ofono_dbus_queue *q,
__ofono_dbus_queue_req_free(done);

/* Submit the next request if there is any */
while (next && reply) {
reply = next->fn(next->msg, next->data);
if (reply) {
/* The request has completed synchronously */
done = next;
next = done->next;
q->requests = next;
done->next = NULL;

/* Send the reply */
__ofono_dbus_pending_reply(&done->msg, reply);
__ofono_dbus_queue_req_free(done);
}
}
__ofono_dbus_queue_submit_next(q);
}

void __ofono_dbus_queue_reply_ok(struct ofono_dbus_queue *q)
Expand Down Expand Up @@ -250,8 +261,10 @@ void __ofono_dbus_queue_reply_all_fn_param(struct ofono_dbus_queue *q,
* Find all other requests with the same handler and the same data
* and complete those too (except when the handler is NULL)
*/
if (!handler)
if (!handler) {
__ofono_dbus_queue_submit_next(q);
return;
}

prev = NULL;
req = q->requests;
Expand All @@ -274,6 +287,7 @@ void __ofono_dbus_queue_reply_all_fn_param(struct ofono_dbus_queue *q,

req = next;
}
__ofono_dbus_queue_submit_next(q);
}

/*
Expand Down
24 changes: 20 additions & 4 deletions ofono/unit/test-dbus-queue.c
Expand Up @@ -417,7 +417,7 @@ static void test_reply_last_reply(DBusPendingCall *call, void *dbus)
G_CAST(dbus, struct test_reply_data, dbus);

DBG("");
test_dbus_check_error_reply(call, TEST_ERROR_FAILED);
test_dbus_check_empty_reply(call, NULL);
g_main_loop_quit(test->dbus.loop);
}

Expand Down Expand Up @@ -445,6 +445,12 @@ static DBusMessage *test_reply_4(DBusMessage *msg, void *data)
return NULL;
}

static DBusMessage *test_reply_5(DBusMessage *msg, void *data)
{
DBG("");
return dbus_message_new_method_return(msg);
}

static DBusMessage *test_reply_handler(DBusConnection *conn,
DBusMessage *msg, void *data)
{
Expand Down Expand Up @@ -485,10 +491,17 @@ static DBusMessage *test_reply_handler(DBusConnection *conn,
case 6:
__ofono_dbus_queue_request(test->queue, test_reply_4,
msg, NULL);
break;
case 7:
/* Call the same method again */
__ofono_dbus_queue_request(test->queue, test_reply_4,
msg, NULL);
break;
case 7:
case 8:
/* Call the last one */
__ofono_dbus_queue_request(test->queue, test_reply_5,
msg, NULL);

/* This completes the first one, with NULL handler */
__ofono_dbus_queue_reply_all_fn_param(test->queue, NULL, NULL);
g_assert(__ofono_dbus_queue_pending(test->queue));
Expand All @@ -508,10 +521,12 @@ static DBusMessage *test_reply_handler(DBusConnection *conn,
/* This one test_reply_3 with Failed */
__ofono_dbus_queue_reply_all_error(test->queue, NULL);

/* This one test_reply_4 with NotSupported */
/* This one completes all test_reply_4 with NotSupported */
error.type = OFONO_ERROR_TYPE_ERRNO;
error.error = -EOPNOTSUPP;
__ofono_dbus_queue_reply_all_error(test->queue, &error);

/* test_reply_5 must be already completed */
g_assert(!__ofono_dbus_queue_pending(test->queue));

/* And this one does nothing */
Expand Down Expand Up @@ -541,7 +556,8 @@ static void test_reply_start(struct test_dbus_context *dbus)
test_client_call(dbus, 4, test_dbus_expect_empty_reply);
test_client_call(dbus, 5, test_expect_failed);
test_client_call(dbus, 6, test_expect_not_supported);
test_client_call(dbus, 7, test_reply_last_reply);
test_client_call(dbus, 7, test_expect_not_supported);
test_client_call(dbus, 8, test_reply_last_reply);
}

static void test_reply(void)
Expand Down

0 comments on commit 870bac9

Please sign in to comment.