diff options
author | Janos Kovacs <janos.f.kovacs@nokia.com> | 2010-08-17 01:05:26 +0300 |
---|---|---|
committer | Janos Kovacs <janos.f.kovacs@nokia.com> | 2010-08-17 01:05:26 +0300 |
commit | fd1b37800f294592d6f2ecc1b6f0c915b0a0cdfd (patch) | |
tree | b02ea96a389dcafc23660d0af2d40792b46cee2c | |
parent | fcdac3aba5bc7b2c394852cb4770304447a38684 (diff) |
don't anser messages with 'no reply' on
flood command for resource-client
-rw-r--r-- | client/client.c | 69 | ||||
-rw-r--r-- | src/dbus-proto.c | 12 |
2 files changed, 72 insertions, 9 deletions
diff --git a/client/client.c b/client/client.c index 83c3aca..c5adcce 100644 --- a/client/client.c +++ b/client/client.c @@ -120,6 +120,8 @@ static resset_t *rset; static uint32_t rid; static uint32_t reqno; static resmsg_type_t reqtyp[REQHASH_DIM]; +static int flood; +static int count; int main(int argc, char **argv) { @@ -280,10 +282,21 @@ static void parse_input(void) char *value; int i; resmsg_t msg; + char *e; if (!strncmp(str, "help", 4)) { str = skip_whitespaces(str + 4); + print_message( + " acquire\n" + " release\n" + " update all:opt:share:shmask where all,opt,share and shmask " + "are comma separated resources\n" + " audio group pid prop-name:prop-value\n" + " disconnect\n" + " flood count\n" + " stop" + ); } else if (!strncmp(str, "acquire", 7)) { str = skip_whitespaces(str + 7); @@ -378,8 +391,31 @@ static void parse_input(void) } while (0); } else if (!strncmp(str, "disconnect", 10)) { + str = skip_whitespaces(str + 10); disconnect_from_manager(); } + else if (!strncmp(str, "flood", 5)) { + str = skip_whitespaces(str + 5); + + flood = strtoul(str, &e, 10); + + if (*e || flood < 1 || flood > 1000) { + if (*e || e == str) + print_message("invalid count '%s'", str); + else + print_message("invalid count %d: range is 1-1000", flood); + flood = count = 0; + } + else { + memset(&msg, 0, sizeof(resmsg_t)); + msg.possess.type = RESMSG_ACQUIRE; + manager_send_message(&msg); + } + } + else if (!strncmp(str, "stop", 4)) { + str = skip_whitespaces(str + 4); + flood = count = 0; + } else { print_message("invalid input '%s'", input.buf); return; @@ -579,7 +615,8 @@ static void manager_status(resset_t *rset, resmsg_t *msg) static void manager_receive_message(resmsg_t *msg, resset_t *rs, void *data) { - char buf[80]; + resmsg_t req; + char buf[80]; (void)data; @@ -595,11 +632,31 @@ static void manager_receive_message(resmsg_t *msg, resset_t *rs, void *data) case RESMSG_GRANT: resmsg_res_str(msg->notify.resrc, buf, sizeof(buf)); - if (config.verbose) - print_message("manager granted the resources: %s", buf); - else - print_message("granted: %s", buf); - print_input(); + if (!flood) { + if (config.verbose) + print_message("manager granted the resources: %s", buf); + else + print_message("granted: %s", buf); + + print_input(); + } + else { + memset(&req, 0, sizeof(resmsg_t)); + if (msg->notify.resrc == 0) + req.possess.type = RESMSG_ACQUIRE; + else { + print_message("granted %d: %s", ++count, buf); + + if (count >= flood) { + flood = count = 0; + print_message("flood done"); + break; + } + + req.possess.type = RESMSG_RELEASE; + } + manager_send_message(&req); + } break; case RESMSG_ADVICE: diff --git a/src/dbus-proto.c b/src/dbus-proto.c index 93652b7..46f01cf 100644 --- a/src/dbus-proto.c +++ b/src/dbus-proto.c @@ -210,6 +210,7 @@ static int send_message(resset_t *rset,resmsg_t *rmsg,resproto_status_t status) } } + dbus_message_set_no_reply(dmsg, !need_reply); if (!need_reply) success = dbus_connection_send(dcon, dmsg, NULL); @@ -245,10 +246,15 @@ static int send_error(resset_t *rset, resmsg_t *resreply, void *data) DBusConnection *dcon = rcon->dbus.conn; DBusMessage *dbusmsg = (DBusMessage *)data; dbus_uint32_t serial = dbus_message_get_serial(dbusmsg); - DBusMessage *dbusreply = resmsg_dbus_reply_message(dbusmsg, resreply); + dbus_bool_t noreply = dbus_message_get_no_reply(dbusmsg); + DBusMessage *dbusreply; + + if (!noreply) { + dbusreply = resmsg_dbus_reply_message(dbusmsg, resreply); + dbus_connection_send(dcon, dbusreply, &serial); + dbus_message_unref(dbusreply); + } - dbus_connection_send(dcon, dbusreply, &serial); - dbus_message_unref(dbusreply); dbus_message_unref(dbusmsg); return TRUE; |