Esempio n. 1
0
static void log_target(mrp_console_t *c, void *user_data,
                       int argc, char **argv)
{
    const char *target;
    const char *targets[32];
    int         i, n;

    MRP_UNUSED(c);
    MRP_UNUSED(user_data);

    if (argc == 2) {
        target = mrp_log_get_target();
        n      = mrp_log_get_targets(targets, MRP_ARRAY_SIZE(targets));

        printf("available log targets:\n");
        for (i = 0; i < n; i++)
            printf("    %s%s\n", targets[i],
                   !strcmp(targets[i], target) ? " (active)" : "");
    }
    else if (argc == 3) {
        target = argv[2];

        if (!mrp_log_set_target(target))
            printf("failed to change logging target to %s", target);
        else {
            printf("changed log target to %s\n", target);
            mrp_log_info("changed log target to %s", target);
        }
    }
    else {
        printf("%s/%s invoked with wrong number of arguments\n",
               argv[0], argv[1]);
    }
}
Esempio n. 2
0
void ping_cb(mrp_console_t *c, void *user_data, int argc, char **argv)
{
    static uint32_t   cnt = 1;
    const char       *domain;
    char             *strings[] = { "foo", "bar", "foobar", "barfoo" };
    uint32_t          uints[]   = { 69, 96, 696, 969 };
    mrp_domctl_arg_t  args[32];
    int               narg, i;

    MRP_UNUSED(user_data);

    if (argc < 3) {
        printf("Usage: %s domain\n", argv[0]);
        return;
    }

    domain = argv[2];
    narg   = MRP_ARRAY_SIZE(args);

    args[0].type = MRP_DOMCTL_UINT32;
    args[0].u32  = cnt++;
    args[1].type = MRP_DOMCTL_ARRAY(STRING);
    args[1].arr  = strings;
    args[1].size = MRP_ARRAY_SIZE(strings);
    args[2].type = MRP_DOMCTL_ARRAY(UINT32);
    args[2].arr  = uints;
    args[2].size = MRP_ARRAY_SIZE(uints);

    for (i = 3; i < narg; i++) {
        if (i + 2 < argc) {
            args[i].type = MRP_DOMCTL_STRING;
            args[i].str  = argv[i + 2];
        }
        else {
            args[i].type = MRP_DOMCTL_UINT32;
            args[i].u32  = i;
        }
    }

    if (!mrp_invoke_domain(c->ctx, domain, "ping", narg, args, pong_cb, c))
        printf("Failed to ping domain '%s'.\n", domain);
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
    mrp_fragbuf_t *buf;
    size_t         chunkstbl[][8] = {
        { 3, 1, 2, 3, 5, 0, 0, 0 },
        { 1, 2, 3, 4, 3, 2, 1, 0 },
        { 1, 5, 3, 4, 2, 1, 1, 0 },
        { 4, 3, 2, 1, 2, 3, 4, 0 },
    };
    size_t *chunks;
    size_t  single[]    = { 1, 0 };
    int     intervals[] = { 1, 2, 3, 4, 5, 0, -1 };
    int     i, j, interval;

    parse_cmdline(argc, argv);

    mrp_log_set_mask(ctx.log_mask);
    mrp_log_set_target(ctx.log_target);

    buf = mrp_fragbuf_create(ctx.framed, 0);

    if (buf == NULL)
        fatal("failed to create data collecting buffer");

    for (i = 0; i < (int)MRP_ARRAY_SIZE(intervals); i++) {
        interval = intervals[i];
        for (j = 0; j < (int)MRP_ARRAY_SIZE(chunkstbl); j++) {
            chunks = &chunkstbl[j][0];
            mrp_log_info("testing with interval %d, chunks #%d", interval, j);
            test(buf, chunks, interval);
            test(buf, single, interval);
            mrp_log_info("testing with interval %d, chunks #%d", -i -2, j);
            test(buf, chunks, -i - 2);
            test(buf, single, -i - 2);
        }
    }

    mrp_fragbuf_destroy(buf);

    return 0;
}
Esempio n. 4
0
static int wrtc_setup(wrtc_t *wrtc)
{
    static srs_client_ops_t ops = {
        .notify_focus   = focus_cb,
        .notify_command = command_cb
    };

    srs_context_t *srs = wrtc->srs;
    char          *cmds[] = {
        (char *)wrtc->config.play,
        (char *)wrtc->config.stop,
        (char *)wrtc->config.pause,
        (char *)wrtc->config.next,
        (char *)wrtc->config.prev
    };
    int         ncmd   = (int)MRP_ARRAY_SIZE(cmds);
    const char *name   = "wrt-media-client";
    const char *appcls = "player";
    const char *id     = "wrt-media-client";

    if (!strcmp(wrtc->config.bus, "session"))
        wrtc->gdbus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
    else if (!strcmp(wrtc->config.bus, "system"))
        wrtc->gdbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
    else {
        int flags = G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION;
        wrtc->gdbus = g_dbus_connection_new_for_address_sync(wrtc->config.bus,
                                                             flags,
                                                             NULL, NULL, NULL);
    }

    if (wrtc->gdbus == NULL)
        return FALSE;

    wrtc->gnrq = g_bus_own_name(G_BUS_TYPE_SESSION, "org.tizen.srs", 0,
                                NULL, name_acquired_cb, name_lost_cb,
                                wrtc, NULL);

    wrtc->c = client_create(srs, SRS_CLIENT_TYPE_BUILTIN,
                            name, appcls, cmds, ncmd, id, &ops, wrtc);

    if (wrtc->c == NULL) {
        wrtc_cleanup(wrtc);

        return FALSE;
    }

    client_request_focus(wrtc->c, SRS_VOICE_FOCUS_SHARED);

    return TRUE;
}
Esempio n. 5
0
static int command_cb(srs_client_t *c, int idx, int ntoken, char **tokens,
                      uint32_t *start, uint32_t *end, srs_audiobuf_t *audio)
{
    static const char *events[] = {
        [CMD_PLAY]  = "play",
        [CMD_STOP]  = "stop",
        [CMD_PAUSE] = "pause",
        [CMD_NEXT]  = "next",
        [CMD_PREV]  = "previous",
    };
    static int nevent = MRP_ARRAY_SIZE(events);

    wrtc_t          *wrtc = (wrtc_t *)c->user_data;
    const char      *event;
    GVariantBuilder *vb;
    GVariant        *args;

    MRP_UNUSED(start);
    MRP_UNUSED(end);
    MRP_UNUSED(audio);
    MRP_UNUSED(tokens);
    MRP_UNUSED(ntoken);

    if (!wrtc->name) {
        mrp_log_error("WRT media client: can't relay, got no D-Bus name.");

        return TRUE;
    }

    if (idx < 0 || idx >= nevent) {
        mrp_log_error("WRT media client: got invalid command #%d.", idx);

        return TRUE;
    }
    else
        event = events[idx];

    mrp_log_info("WRT media client: relaying command %s.", event);

    vb = g_variant_builder_new(G_VARIANT_TYPE("as"));
    g_variant_builder_add(vb, "s", event);
    args = g_variant_new("(as)", vb);
    g_variant_builder_unref(vb);

    g_dbus_connection_emit_signal(wrtc->gdbus, NULL,
                                  "/srs", "org.tizen.srs", "Result",
                                  args, NULL);
    return TRUE;
}
Esempio n. 6
0
static void process_input(brl_t *brl, const char *input, void *user_data)
{
    client_t *c   = (client_t *)user_data;
    int       len = input ? strlen(input) + 1 : 0;
    char      buf[len], *args[64];
    int       narg;

    if (len > 1) {
        brl_add_history(brl, input);
        hide_prompt(c);

        strcpy(buf, input);
        narg = split_input(buf, MRP_ARRAY_SIZE(args), args);
        if (narg > 0)
            execute_user_command(c, narg, &args[0]);
        else
            printf("failed to parse input '%s'\n", input);

        show_prompt(c);
    }
}
Esempio n. 7
0
static void set_client_defaults(client_t *c, const char *argv0)
{
    int i;

    c->app_class    = "player";
    c->app_name     = strrchr(argv0, '/');

    if (c->app_name != NULL)
        c->app_name++;
    else
        c->app_name = argv0;

    c->commands = mrp_allocz(sizeof(default_commands));
    c->ncommand = MRP_ARRAY_SIZE(default_commands);

    for (i = 0; i < c->ncommand; i++) {
        c->commands[i] = mrp_strdup(default_commands[i]);
        if (c->commands[i] == NULL) {
            print(c, "Failed to initialize default command set.");
            exit(1);
        }
    }
}
Esempio n. 8
0
int test(mrp_fragbuf_t *buf, size_t *chunks, int dump_interval)
{
    char *messages[] = {
        "Ticking away the moments",
        "That make up a dull day",
        "Fritter and waste the hours",
        "In an off-hand way",
        "Kicking around on a piece of ground",
        "In your home town",
        "Waiting for someone or something",
        "To show you the way",
        "Tired of lying in the sunshine",
        "Staying home to watch the rain",
        "You are young and life is long",
        "And there is time to kill today",
        "And then the one day you find",
        "Ten years have got behind you",
        "No one told you when to run",
        "You missed the starting gun",
        "And you run and you run",
        "To catch up with the sun",
        "But it's sinking",
        "Racing around",
        "To come up behind you again",
        "The sun is the same",
        "In a relative way",
        "But you're older",
        "Shorter of breath",
        "And one day closer to death",
        "Every year is getting shorter",
        "Never seem to find the time",
        "Plans that either come to naught",
        "Or half a page of scribbled lines",
        "Hanging on in quiet desperation",
        "Is the English way",
        "The time is gone",
        "The song is over",
        "Thought I'd something more to say",
        "Home",
        "Home again",
        "I like to be here",
        "When I can",
        "When I come home",
        "Cold and tired",
        "It's good to warm my bones",
        "Beside the fire",
        "Far away",
        "Across the field",
        "Tolling on the iron bell",
        "Calls the faithful to their knees",
        "To hear the softly spoken magic spell...",
        "test #1",
        "test #2",
        "this is a test #3",
        "message #4",
        "message #5",
        "test message #6",
        "a test #7",
        "the quick brown (#8)",
        "fox (#9)",
        "jumps over the (#10)",
        "lazy dog (#11)",
        "this is another test message (#12)",
        "and here is one more for you (#13)",
        "foo (#14)",
        "bar (#15)",
        "foobar (#16)",
        "barfoo (#17)",
        "xyzzykukkuluuruu (#18)"
    };

    char          *msg, *p;
    uint32_t       size, nbo_size;
    size_t         n, total;
    int            dump, chk, offs, i, j;

    dump = chk = offs = 0;

    for (i = 0; i < (int)MRP_ARRAY_SIZE(messages); i++) {
        msg   = messages[i];
        size  = strlen(msg);

        total = 0;
        p     = msg;

        if (ctx.framed) {
            nbo_size = htobe32(size);
            if (!mrp_fragbuf_push(buf, &nbo_size, sizeof(nbo_size)))
                fatal("failed to push message size to buffer");
        }

        for (j = 0; *p != '\0'; j++) {
            if (!chunks[j])
                j = 0;
            n = chunks[j];
            if (n > strlen(p))
                n = strlen(p);

            mrp_debug("pushing %zd bytes (%*.*s)...", n, (int)n, (int)n, p);

            if (!mrp_fragbuf_push(buf, p, n))
                fatal("failed to push %*.*s to buffer", (int)n, (int)n, p);

            p     += n;
            total += n;

            dump++;

            if (!dump_interval ||
                (dump_interval > 0 && !(dump % dump_interval)))
                dump_buffer(buf, messages, &chk, &offs);
        }

        if (dump_interval < -1) {
            if (i && !(i % -dump_interval))
                dump_buffer(buf, messages, &chk, &offs);
        }
    }

    dump_buffer(buf, messages, &chk, &offs);

    return TRUE;
}
Esempio n. 9
0

static void plugin_exit(mrp_plugin_t *plugin)
{
    mrp_plugin_arg_t *args = plugin->args;

    if (args[ARG_RESOLVER].bln)
        mrp_unregister_interpreter(LUAR_INTERPRETER_NAME);
}


#define PLUGIN_DESCRIPTION "Lua bindings for Murphy."
#define PLUGIN_HELP        "Enable Lua bindings for Murphy."
#define PLUGIN_AUTHORS     "Krisztian Litkey <*****@*****.**>"
#define PLUGIN_VERSION     MRP_VERSION_INT(0, 0, 1)

#define DEFAULT_CONFIG  "/etc/murphy/murphy.lua"

static mrp_plugin_arg_t plugin_args[] = {
    MRP_PLUGIN_ARGIDX(ARG_CONFIG  , STRING,  "config",  DEFAULT_CONFIG),
    MRP_PLUGIN_ARGIDX(ARG_RESOLVER, BOOL  , "resolver",TRUE),
};

MURPHY_REGISTER_PLUGIN("lua",
                       PLUGIN_VERSION, PLUGIN_DESCRIPTION, PLUGIN_AUTHORS,
                       PLUGIN_HELP, MRP_SINGLETON, plugin_init, plugin_exit,
                       plugin_args, MRP_ARRAY_SIZE(plugin_args),
                       NULL, 0,
                       NULL, 0,
                       NULL);
Esempio n. 10
0
void invoke_cb(mrp_console_t *c, void *user_data, int argc, char **argv)
{
    const char       *domain, *method, *type, *value;
    mrp_domctl_arg_t  args[32];
    int               tlen, narg, i;

    MRP_UNUSED(user_data);

    if (argc < 4) {
        printf("Usage: %s %s <domain> <method> [args]\n", argv[0], argv[1]);
        return;
    }

    domain = argv[2];
    method = argv[3];
    narg   = MRP_ARRAY_SIZE(args);

    for (i = 4, narg = 0;
         i < argc && narg < (int)MRP_ARRAY_SIZE(args);
         i++, narg++) {
        type  = argv[i];
        value = strchr(type, ':');

        if (value == NULL) {
            value = type;
            type  = "string";
            tlen  = 6;
        }
        else {
            tlen  = value - type;
            value++;
        }

        if (!strncmp(type, "string", tlen)) {
            args[narg].type = MRP_DOMCTL_STRING;
            args[narg].str  = value;
        }
        else if (!strncmp(type, "u16"     , tlen) ||
                 !strncmp(type, "uint16_t", tlen)) {
            args[narg].type = MRP_DOMCTL_UINT16;
            args[narg].u16  = (uint16_t)strtoul(value, NULL, 0);
        }
        else if (!strncmp(type, "u16"     , tlen) ||
                 !strncmp(type, "uint16_t", tlen)) {
            args[narg].type = MRP_DOMCTL_INT16;
            args[narg].s16  = (int16_t)strtol(value, NULL, 0);
        }
        else if (!strncmp(type, "u32"     , tlen) ||
                 !strncmp(type, "uint32_t", tlen)) {
            args[narg].type = MRP_DOMCTL_UINT32;
            args[narg].u32  = (uint32_t)strtoul(value, NULL, 0);
        }
        else if (!strncmp(type, "u32"     , tlen) ||
                 !strncmp(type, "uint32_t", tlen)) {
            args[narg].type = MRP_DOMCTL_INT32;
            args[narg].s32  = (int32_t)strtol(value, NULL, 0);
        }
        else {
            printf("invalid typecast in %s\n", argv[i]);
            return;
        }
    }

    printf("Invoking domain method '%s.%s' with %d args...\n", domain, method,
           narg);

    if (!mrp_invoke_domain(c->ctx, domain, method, narg, args, invoke_reply, c))
        printf("Failed to invoke '%s.%s'.\n", domain, method);
}