Exemplo n.º 1
0
static int timer_event_cb(void *data)
{
#define MAX_ARG 64

    static char  *rundown = "rundown";

    char         *id    = (char *)data;
    fsif_entry_t *entry = NULL;
    delay_cb_t    cb;
    int           argc;
    char          argt[MAX_ARG + 1];
    void         *argv[MAX_ARG];
    char          name[64];
    char         *str;
    int           ibuf[MAX_ARG];
    int           i, j;

    if ((entry = timer_lookup(id)) != NULL) {
        OHM_DEBUG(DBG_EVENT, "Timer '%s' rundown", id);

        fsif_set_field_by_entry(entry, fldtype_string,  TIMER_STATE, &rundown);
        fsif_get_field_by_entry(entry, fldtype_unsignd, TIMER_ADDRESS, &cb);
        fsif_get_field_by_entry(entry, fldtype_unsignd, TIMER_ARGC, &argc);

        if (cb != NULL) {
            memset(argt, 0, sizeof(argt));

            for (i = 0, j = 0;  i < MAX_ARG && i < argc;  i++) {
                snprintf(name, sizeof(name), TIMER_ARGV, i);

                /* FIXME:
                 * This is really uggly. should be rewritten when we have
                 * some time (ie. supporting function in fsif etc)
                 */
                                /* first we try as string */
                fsif_get_field_by_entry(entry, fldtype_string, name, &str);

                if (str != NULL) {
                    argt[i] = 's';
                    argv[i] = (void *)str;
                    continue;
                }
                                /* next we assume it is an integer */
                fsif_get_field_by_entry(entry, fldtype_integer, name, ibuf+j);

                argt[i] = 'i';
                argv[i] = ibuf+j;
                j++;
            } /* for */

            OHM_DEBUG(DBG_EVENT, "signature '%s'", argt);

            cb(id, argt, argv);
        }
    }

    return FALSE;

#undef MAX_ARG
}
Exemplo n.º 2
0
static void  audio_stream_changed_cb(fsif_entry_t      *entry,
				     char              *name,
				     fsif_fact_watch_e  event,
				     void              *usrdata)
{
    char     *oper    = "<unknown>";
    uint32_t  pid     = 0;
    char     *group   = NULL;
    char     *propnam = "media.name";
    char     *method  = "<unknown>";
    char     *pattern = "<unknown>";

    (void)name;
    (void)usrdata;

    switch (event) {
    case fact_watch_insert:     oper = "register";                      break;
    case fact_watch_remove:     oper = "unregister";                    break;
    default: OHM_ERROR("media: invalid factstore event %d", event);     return;
    }

    fsif_get_field_by_entry(entry, fldtype_integer, "pid"     , &pid    );
    fsif_get_field_by_entry(entry, fldtype_string , "group"   , &group  );
    fsif_get_field_by_entry(entry, fldtype_string , "property", &propnam);
    fsif_get_field_by_entry(entry, fldtype_string , "method"  , &method );
    fsif_get_field_by_entry(entry, fldtype_string , "pattern" , &pattern);

    OHM_DEBUG(DBG_AUDIO, "audio stream %s: pid=%u group='%s' property='%s' "
              "method=%s pattern='%s'", oper, pid, group?group:"<null>",
              propnam, method, pattern);

    if (pid != 0  &&  group != NULL) {
        dbusif_send_audio_stream_info(oper, group, pid,propnam,method,pattern);
    }
}
Exemplo n.º 3
0
static void mute_changed_cb(fsif_entry_t *entry,
                            char         *name,
                            fsif_field_t *fld,
                            void         *usrdata)
{
    (void)name;
    (void)usrdata;

    int  mute;
    int  forced = TRUE;

    if (fld->type == fldtype_integer)
        mute = fld->value.integer;
    else {
        OHM_ERROR("media [%s]: invalid field type", __FUNCTION__);
        return;
    }

    fsif_get_field_by_entry(entry, fldtype_integer, "forced", &forced);

    if (!strcmp(fld->name, "forced"))
        fsif_get_field_by_entry(entry, fldtype_integer, "value" , &mute);
    
    if (forced) {
        OHM_DEBUG(DBG_MUTE, "ignoring forced mute change to '%s'",
                  mute_str(mute));
        return;
    }

    OHM_DEBUG(DBG_MUTE, "mute changed to '%s'", mute_str(mute));

    dbusif_signal_mute(mute, DBUSIF_SEND_NOW);
}
Exemplo n.º 4
0
static void cancel_timer_event_by_entry(fsif_entry_t *entry)
{
    static char  *stopped = "stopped";

    unsigned int  srcid;

    if (timer_active(entry)) {
        fsif_get_field_by_entry(entry, fldtype_unsignd, TIMER_SRCID, &srcid);
        cancel_timer_event_by_srcid(srcid);
        fsif_set_field_by_entry(entry, fldtype_string, TIMER_STATE, &stopped);
    }
}
Exemplo n.º 5
0
static int timer_active(fsif_entry_t *entry)
{
    char *state = NULL;
    int   active;

    if (entry == NULL)
        active = FALSE;
    else {
        fsif_get_field_by_entry(entry, fldtype_string, TIMER_STATE, &state);

        active = (state && !strcmp(state, "active")) ? TRUE : FALSE;
    }

    return active;
}
Exemplo n.º 6
0
static int timer_restart(fsif_entry_t *entry, unsigned int delay,
                         char *cb_name, delay_cb_t cb, char *argt, void **argv)
{
    char *id = 0;
    
    if (!entry || !cb_name || !cb || !argt)
        goto fail;

    fsif_get_field_by_entry(entry, fldtype_string, TIMER_ID, &id);

    if (id == NULL)
        goto fail;

    cancel_timer_event_by_entry(entry);

    if (!fsif_destroy_factstore_entry(entry) ||
        !timer_add(id, delay, cb_name, cb, argt, argv))
        goto fail;
        
    return TRUE;

 fail:
    return FALSE;
}