Example #1
0
static DBusHandlerResult bluez_change(DBusConnection *c,
                                      DBusMessage *msg, void *data)
{
    char *name, *before, *after;

    (void)c;
    (void)data;

    if (!dbus_message_get_args(msg, NULL,
                               DBUS_TYPE_STRING, &name,
                               DBUS_TYPE_STRING, &before,
                               DBUS_TYPE_STRING, &after,
                               DBUS_TYPE_INVALID) ||
        strcmp(name, BLUEZ_DBUS_NAME))
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    
    if (!after[0]) {                              /* bluez gone */
        OHM_INFO("BlueZ is down.");
        bt_delete_all_facts();
        dres_all();
    }
    else
        OHM_INFO("BlueZ is up.");

    return DBUS_HANDLER_RESULT_HANDLED;
}
Example #2
0
/********************
 * select_driver
 ********************/
static void
select_driver(vibra_context_t *ctx, OhmPlugin *plugin)
{
    vibra_driver_t *driver;
    char           *cfgdrv;

    cfgdrv = (char *)ohm_plugin_get_param(plugin, "driver");

    if (cfgdrv == NULL)
        cfgdrv = FALLBACK_DRIVER;

    OHM_INFO("vibra: configured driver '%s'", cfgdrv);
    
    for (driver = drivers; driver->name != NULL; driver++) {
        if (!strcmp(driver->name, cfgdrv) ||
            !strcmp(driver->name, FALLBACK_DRIVER))
            break;
    }
    
    if (driver->name == NULL) {
        OHM_ERROR("vibra: failed to find any usable driver");
        exit(1);
    }
    
    ctx->driver = driver;
    
    OHM_INFO("vibra: selected driver '%s'", driver->name);
}
Example #3
0
static void timestamp_init(void)
{
    char *signature;
  
    signature = (char *)timestamp_add_SIGNATURE;
  
    if (ohm_module_find_method("timestamp", &signature,(void *)&timestamp_add))
        OHM_INFO("playback: timestamping is enabled.");
    else
        OHM_INFO("playback: timestamping is disabled.");
}
Example #4
0
static int profile_save_state(OhmFact *fact)
{
    FILE *fp;
    GSList *l;
    GQuark  q;
    const gchar *key;
    GValue *value;
    int err;
    
    if ((fp = fopen(PROFILE_SAVE_PATH, "w")) == NULL)
        return errno;

    for (l = ohm_fact_get_fields(fact); l != NULL; l = l->next) {
        q = (GQuark)GPOINTER_TO_INT(l->data);
        key = g_quark_to_string(q);
        value = ohm_fact_get(fact, key);

        if ((err = save_field(fp, key, value)) != 0) {
            fclose(fp);
            unlink(PROFILE_SAVE_PATH);
            return err;
        }
    }
    
    fflush(fp);
    /* fdatasync(fileno(fp)); */
    fclose(fp);

    OHM_INFO("Profile state saved.");
    return 0;
}
Example #5
0
static void profile_name_change(const char *profile, void *dummy)
{
    /* Active profile has changed */

    /* get values for the new profile */

    (void)dummy;

    profileval_t *values = NULL;

#if 0
    OHM_INFO("profile: active profile has changed: '%s'", profile);
#endif

    if (!profile)
        return;

    values = profile_get_values(profile);

    /* empty 'values' means that the profile is empty */

    /* change profile data */

    profile_create_fact(profile, values);

    profile_free_values(values);
}
Example #6
0
void dbusif_init(OhmPlugin *plugin)
{
    const char *timeout_str;
    char       *e;

    if ((timeout_str = ohm_plugin_get_param(plugin, "dbus-timeout")) == NULL)
        timeout = -1;           /* 'a sane default timeout' will be used */
    else {
        timeout = strtol(timeout_str, &e, 10);

        if (*e != '\0') {
            OHM_ERROR("media: Invalid value '%s' for 'dbus-timeout'",
                      timeout_str);
            timeout = -1;
        }

        if (timeout < 0)
            timeout = -1;
    }

    OHM_INFO("media: D-Bus message timeout is %dmsec", timeout);

    /*
     * Notes: We get only on the system bus here. Session bus initialization
     *   is delayed until we get the correct address of the bus from our
     *   ohm-session-agent.
     */
    
    system_bus_init();
    resctl_init();
}
Example #7
0
/********************
 * call_register
 ********************/
call_t *
call_register(const char *path)
{
    call_t *call;

    if (path == NULL)
        return NULL;
    
    if ((call = g_new0(call_t, 1)) == NULL) {
        OHM_ERROR("Failed to allocate new call %s.", path);
        return NULL;
    }

    if ((call->path = g_strdup(path)) == NULL) {
        OHM_ERROR("Failed to initialize new call %s.", path);
        g_free(call);
        return NULL;
    }

    call->id    = callid++;
    call->state = STATE_PROCEEDING;

    g_hash_table_insert(calls, call->path, call);
    
    if (IS_CELLULAR(path))
        ncscall++;
    else
        nipcall++;
    
    OHM_INFO("Call %s (#%d) registered.", path, ncscall + nipcall);
    
    return call;
}
Example #8
0
DBusHandlerResult dbusif_session_notification(DBusConnection *syscon,
                                              DBusMessage    *msg,
                                              void           *ud)
{
    char      *address;
    DBusError  error;
    int        success;

    (void)syscon;               /* supposed to be sys_conn */
    (void)ud;                   /* not used */

    do { /* not a loop */
        dbus_error_init(&error);
    
        success = dbus_message_get_args(msg, &error,
                                        DBUS_TYPE_STRING, &address,
                                        DBUS_TYPE_INVALID);

        if (!success) {
            if (!dbus_error_is_set(&error)) {
                OHM_ERROR("auth: failed to parse session bus notification.");
            }
            else {
                OHM_ERROR("auth: failed to parse session bus notification: %s",
                          error.message);
                dbus_error_free(&error);
            }
            break;
        }
                         
        if (!strcmp(address, "<failure>")) {
            OHM_INFO("auth: got session bus failure notification, ignoring");
            break;
        }

        if (sess_conn != NULL)
            session_bus_cleanup();

        OHM_INFO("auth: got session bus notification with address '%s'",
                 address);

        session_bus_init(address);

    } while(0);

    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Example #9
0
void timestamp_init(OhmPlugin *plugin)
{
    char *signature = (char *)_timestamp_add_SIGNATURE;

    (void)plugin;

    ENTER;
 
    ohm_module_find_method("timestamp", &signature, (void *)&_timestamp_add);

    if (_timestamp_add != NULL)
        OHM_INFO("resource: timestamping is enabled.");
    else
        OHM_INFO("resource: timestamping is disabled.");

    LEAVE;
}
Example #10
0
/********************
 * call_activate
 ********************/
static int
call_activate(event_t *event)
{
    call_t *call = event->any.call;
    
    if (call->state == STATE_ON_HOLD) {
        hold(call, FALSE);
        OHM_INFO("REACTIVATE call %s", call->path);
    }
    else
        OHM_INFO("ACCEPT call %s", call->path);
    
    call->state = STATE_ACTIVE;
    policy_call_update(call);

    return 0;
}
Example #11
0
/********************
 * call_destroy
 ********************/
void
call_destroy(call_t *call)
{
    if (call != NULL) {
        OHM_INFO("Destroying call %s.", call->path);
        g_free(call->path);
        g_free(call);
    }
}
/********************
 * console_init
 ********************/
static int
console_init(char *address)
{
    char *signature;
    
#define IMPORT(name, ptr) ({                                            \
            signature = (char *)ptr##_SIGNATURE;                        \
            ohm_module_find_method((name), &signature, (void *)&(ptr)); \
        })

    extension_init();
    
    if (!strcmp(address, "disabled")) {
        OHM_INFO("resolver: console disabled");
        return 0;
    }
    
    if (!IMPORT("console.open", console_open)) {
        OHM_INFO("resolver: no console methods available, console disabled");
        return 0;
    }
    
    IMPORT("console.close" , console_close);
    IMPORT("console.printf", console_printf);
    IMPORT("console.grab"  , console_grab);
    IMPORT("console.ungrab", console_ungrab);

    if (console_close == NULL || console_printf == NULL ||
        console_grab == NULL || console_ungrab == NULL) {
        OHM_WARNING("resolver: missing console methods, console disabled");
        return 0;
    }
    
    
    OHM_INFO("resolver: using console %s", address);
    
    console = console_open(address,
                           console_opened, console_closed, console_input,
                           NULL, FALSE);
    
    return console < 0 ? EINVAL : 0;
#undef IMPORT    
}
Example #13
0
static int lookup_rules(void)
{
    static import_t   imports[] = {
        IMPORT("rule_engine.free", rules_free_result),
        IMPORT("rule_engine.dump", rules_dump_result),
        IMPORT("rule_engine.find", rule_find        ),
        IMPORT("rule_engine.eval", rule_eval        )
    };

    static rule_def_t  ruldefs[] = {
        {"notification_request"   , 2, &notreq  },
        {"notification_events"    , 2, &notevnt },
        {"notification_play_short", 2, &notplsh },
    };

    import_t     *imp;
    rule_def_t   *rd;
    unsigned int  i;
    unsigned int  n;
    int           success;

    for (i = 0, success = TRUE;   i < DIM(imports);   i++) {
        imp = imports + i;

        if (*imp->methptr != NULL)
            continue;
        
        if (!ohm_module_find_method(imp->name, imp->sigptr, imp->methptr)) {
            OHM_ERROR("notification: can't find method '%s'", imp->name);
            success = FALSE;
        }
    }

    if (!success)
        return FALSE;

    for (i = n = 0;  i < DIM(ruldefs);  i++) {
        rd = ruldefs + i;

        if ((*(rd->rule) = rule_find(rd->name, rd->arity)) >= 0)
            n++;
        else {
            OHM_ERROR("notification can't find rule '%s/%d'",
                      rd->name, rd->arity);
            success = FALSE;
        }
    }

    if (n == DIM(ruldefs))
        OHM_INFO("notification: found all rules");

    return success;
}
Example #14
0
static gboolean timer_cb(gpointer data)
{
    (void)data;

    if ((bdata->ev = event_init()) != NULL) {
        OHM_INFO("buttons:  initialization succeeded");
        bdata->tsrc = 0;
        return FALSE;
    }

    return TRUE;
}
/********************
 * console_opened
 ********************/
static void
console_opened(int id, struct sockaddr *peer, int peerlen)
{
    (void)peer;
    (void)peerlen;

    OHM_INFO("new console 0x%x opened", id);

    console_printf(id, "OHM Policy Debug Console\n");
    console_printf(id, "Type help to get a list of available commands.\n\n");
    console_printf(id, CONSOLE_PROMPT);
}
Example #16
0
/********************
 * call_proceed
 ********************/
static int
call_proceed(event_t *event)
{
    call_t *call = event->any.call;

    OHM_INFO("PROCEED call %s", call->path);

    call->state = STATE_PROCEEDING;
    call_reply(event->create.req, TRUE);
    policy_call_update(call);
    
    return 0;
}
Example #17
0
/********************
 * call_hold
 ********************/
static int
call_hold(event_t *event)
{    
    call_t *call = event->any.call;
    int     status;

    OHM_INFO("HOLD call %s", call->path);
    
    status = hold(call, TRUE);
    call->state = STATE_ON_HOLD;
    policy_call_update(call);

    return status;
}
Example #18
0
/********************
 * call_alerting
 ********************/
static int
call_alerting(event_t *event)
{
    call_t *call = event->any.call;
    
    OHM_INFO("ALERTING call %s", call->path);

    if (event->type == EVENT_CALLREQ)
        call_reply(event->create.req, TRUE);
    call->state = STATE_ALERTING;
    policy_call_update(call);    
    
    return 0;
}
Example #19
0
static void session_bus_cleanup(void)
{
    OHM_INFO("auth: cleaning up session bus connection");

    if (sess_conn != NULL) {
        /*
         * Notes: Hmm... we could keep track of all pending queries
         *     on the session bus and dbus_pending_call_cancel them
         *     here. Currently we let them fail by timing out.
         */
        dbus_connection_unref(sess_conn);
        sess_conn = NULL;
    }
}
Example #20
0
static void plugin_exit(OhmPlugin *plugin)
{
    (void)plugin;

    OHM_INFO("buttons: exit ...");

    if (bdata != NULL) {
        if (bdata->tsrc)
            g_source_remove(bdata->tsrc);

        event_exit(bdata->ev);

        free(bdata);
    }
}
Example #21
0
static void plugin_init(OhmPlugin *plugin)
{
    (void)plugin;

    OHM_DEBUG_INIT(buttons);

    OHM_INFO("buttons: init ...");

    if ((bdata = malloc(sizeof(*bdata))) == NULL)
        OHM_ERROR("buttons: Can't allocate memory for 'buttons'");
    else {
        memset(bdata, 0, sizeof(*bdata));
        bdata->tsrc = g_timeout_add(STARTUP_BLOCK_TIME, timer_cb, NULL);
    }
}
Example #22
0
/********************
 * call_unregister
 ********************/
int
call_unregister(const char *path)
{
    if (path == NULL || !g_hash_table_remove(calls, path))
        return ENOENT;
    
    OHM_INFO("Call %s (#%d) unregistered.", path, ncscall + nipcall);

    if (!strncmp(path, TP_RING_PREFIX, sizeof(TP_RING_PREFIX) - 1))
        ncscall--;
    else
        nipcall--;
    
    return 0;
}
Example #23
0
/********************
 * call_release
 ********************/
static int
call_release(event_t *event)
{
    call_t *call    = event->any.call;
    int     rqstate = event->any.state;
    
    OHM_INFO("RELEASE call %s", call->path);
    
    if (rqstate == STATE_PROCEEDING)
        call_reply(event->create.req, FALSE);
    
    policy_call_delete(call);
    call_unregister(call->path);
    
    return 0;
}
Example #24
0
static int profile_load_state(void)
{
    OhmFactStore *fs = ohm_fact_store_get_fact_store();
    OhmFact *fact;
    GSList *l, *n;
    gchar key[128];
    GValue *value;
    FILE *fp;
    int err;
    
    if ((fp = fopen(PROFILE_SAVE_PATH, "r")) == NULL) {
        if (errno != ENOENT)
            OHM_ERROR("profile: could not load saved state from %s (%d: %s)",
                      PROFILE_SAVE_PATH, errno, strerror(errno));
        return errno;
    }

    /* remove any old profile facts */
    l = ohm_fact_store_get_facts_by_name(fs, FACTSTORE_PROFILE);
    while (l != NULL) {
        n = l->next;
        ohm_fact_store_remove(fs, l->data);
        l = n;
    }
    
    /* create new fact and populate it with saved fields */
    if ((fact = ohm_fact_new(FACTSTORE_PROFILE)) == NULL) {
        OHM_ERROR("profile: failed to create fact %s", FACTSTORE_PROFILE);
        fclose(fp);
        return ENOMEM;
    }
    
    while ((err = load_field(fp, key, sizeof(key), &value)) == 0)
        ohm_fact_set(fact, key, value);
    
    fclose(fp);
    
    if (err != ENOENT) {
        g_object_unref(fact);
        OHM_ERROR("profile: failed to load saved state");
        return err;
    }

    ohm_fact_store_insert(fs, fact);
    OHM_INFO("profile: saved state loaded");
    return 0;
}
Example #25
0
/********************
 * plugin_init
 ********************/
static void
plugin_init(OhmPlugin *plugin)
{
    if (!OHM_DEBUG_INIT(vibra))
        OHM_WARNING("vibra: failed to register for debugging");
    
    if (signaling_register == NULL || signaling_unregister == NULL) {
        OHM_ERROR("vibra: signaling interface not available");
        exit(1);
    }

    select_driver(&context, plugin);
    
    ep_init(&context, signaling_register);
    context.driver->init(&context, plugin);
    
    OHM_INFO("vibra: plugin ready...");
}
Example #26
0
void action_init(OhmPlugin *plugin)
{
    char *register_name        = "signaling.register_enforcement_point";
    char *unregister_name      = "signaling.unregister_enforcement_point";
    char *register_signature   = (char *)register_ep_SIGNATURE;
    char *unregister_signature = (char *)unregister_ep_SIGNATURE;
    char *signals[]            = {"dsp_actions", NULL};

    (void)plugin;

    ENTER;

    ohm_module_find_method(register_name,
                           &register_signature,
                           (void *)&register_ep);
    ohm_module_find_method(unregister_name,
                           &unregister_signature,
                           (void *)&unregister_ep);

    if (!register_ep || !unregister_ep) {
        OHM_ERROR("dspep: can't find mandatory signaling methods. "
                  "DSP enforcement point disabled");
    }
    else {
        if ((conn = register_ep("dspep", signals)) == NULL) {
            OHM_ERROR("dspep: failed to register to receive '%s' signals. "
                      "DSP enforcement point disabled", signals[0]);
        }
        else {
            factstore    = ohm_fact_store_get_fact_store();

            decision_id  = g_signal_connect(conn, "on-decision",
                                            G_CALLBACK(decision_signal_cb),
                                            NULL);
            keychange_id = g_signal_connect(conn, "on-key-change",
                                            G_CALLBACK(key_change_signal_cb),
                                            NULL);            

            OHM_INFO("dspep: DSP enforcement point enabled");
        }
    }

    LEAVE;
}
Example #27
0
static int init_shfile(int fd, size_t size)
{
    char        buf[4096];
    size_t      junk;
    int         written;
    videoipc_t *vip;

    OHM_INFO("videoep: initiate shared memory object '%s'",
             VIDEOIPC_SHARED_OBJECT);

    memset(buf, 0, sizeof(buf));
    vip = (videoipc_t *)buf;

    vip->version.major = VIDEOIPC_MAJOR_VERSION;
    vip->version.minor = VIDEOIPC_MINOR_VERSION;

    while (size > 0) {
        junk  = (size > sizeof(buf)) ? sizeof(buf) : size;
        size -= junk;

        do {
            if ((written = write(fd, buf, junk)) <= 0) {
                if (errno == EINTR)
                    continue;

                OHM_ERROR("videoep: error during shared memory "
                          "initialization: %s", strerror(errno));

                return FALSE;
            }

            junk -= written;

        } while (junk > 0);

        vip->version.major = 0;
        vip->version.minor = 0;
    }

    return TRUE;
}
/********************
 * plugin_init
 ********************/
static void
plugin_init(OhmPlugin *plugin)
{
    if (!OHM_DEBUG_INIT(backlight))
        OHM_WARNING("backlight: failed to register for debugging");
    
    if (signaling_register == NULL || signaling_unregister == NULL) {
        OHM_ERROR("backlight: signaling interface not available");
        exit(1);
    }

    context.resolve      = resolve;
    context.process_info = process_info;
    
    BACKLIGHT_SAVE_STATE(&context, "off");

    ep_init(&context, signaling_register);

    select_driver(&context, plugin);
    context.driver->init(&context, plugin);
    
    OHM_INFO("backlight: plugin ready...");
}
Example #29
0
/********************
 * bus_new_session
 ********************/
static DBusHandlerResult
bus_new_session(DBusConnection *c, DBusMessage *msg, void *data)
{
    char      *address;
    DBusError  error;
    
    (void)c;
    (void)data;

    dbus_error_init(&error);
    
    if (!dbus_message_get_args(msg, &error,
                               DBUS_TYPE_STRING, &address,
                               DBUS_TYPE_INVALID)) {
        if (dbus_error_is_set(&error)) {
            OHM_ERROR("Failed to parse session bus notification: %s.",
                      error.message);
            dbus_error_free(&error);
        }
        else
            OHM_ERROR("Failed to parse session bus notification.");
        
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }

    if (!strcmp(address, "<failure>")) {
        OHM_INFO("profile: got session bus failure notification");
#ifndef __TEST__
        OHM_INFO("profile: requesting ohm restart");
        ohm_restart(0);
#else
        OHM_INFO("profile: ignoring");
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
#endif
    }

    if (bus_conn != NULL) {
        OHM_INFO("profile: received new session bus address \"%s\".", address);
        dbus_connection_unref(bus_conn);
        bus_conn = NULL;
    }
    else
        OHM_INFO("profile: received session bus address \"%s\".", address);
    
    if ((bus_conn = dbus_connection_open(address, &error)) == NULL ||
        !dbus_bus_register(bus_conn, &error)) {
        if (dbus_error_is_set(&error)) {
            OHM_ERROR("Failed to connect to DBUS %s (%s).", address,
                      error.message);
            dbus_error_free(&error);
        }
        else
            OHM_ERROR("Failed to connect to DBUS %s.", address);
        
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
    }

    if (profile_plugin_p == NULL) {
        profile_plugin_p = init_profile();

        if (profile_plugin_p != NULL)
            OHM_INFO("profile: initialized with session bus.");
        else
            OHM_ERROR("profile: failed to initialize with session bus.");
    }
    else {
        reconnect_profile();
        OHM_INFO("profile: reinitialized with new session bus.");
    }
    
    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
Example #30
0
static void plugin_init(OhmPlugin *plugin)
{
    (void)plugin;

    GObject       *conn = NULL;
    gulong         decision_cb;
    gulong         keychange_cb;
    const char    *port_str;
    char          *e;
    unsigned short port;
    char *signals[] = {
        "video_actions",
        NULL
    };

    OHM_DEBUG_INIT(video);

    OHM_INFO("Video EP: init ...");

    do {

        if (!(port_str = ohm_plugin_get_param(plugin, "notification-port")))
            port = VIDEOEP_NOTIFICATION_PORT;
        else {
            port = strtoul(port_str, &e, 10);

            if (*e != '\0') {
                OHM_ERROR("videoep: invalid notification port '%s'", port_str);
                port = VIDEOEP_NOTIFICATION_PORT;
            }
        }

        if (register_ep == NULL) {
            OHM_ERROR("videoep: 'signaling.register_enforcement_point()' "
                      "not found");
            break;
        }

        if ((conn = register_ep("videoep", signals)) == NULL) {
            OHM_ERROR("videoep: Failed to initialize VieoEP");
            break;
        }

        if ((videoep = malloc(sizeof(*videoep))) == NULL) {
            OHM_ERROR("videoep: Can't allocate memory for 'videoep'");
            break;
        }

        decision_cb  = g_signal_connect(conn, "on-decision",
                                        G_CALLBACK(decision_signal_cb),
                                        (gpointer)videoep);
        keychange_cb = g_signal_connect(conn, "on-key-change",
                                        G_CALLBACK(key_change_signal_cb),
                                        (gpointer)videoep);
        

        memset(videoep, 0, sizeof(*videoep));
        videoep->fs   = ohm_fact_store_get_fact_store();
        videoep->conn = conn;
        videoep->decision_cb  = decision_cb;
        videoep->keychange_cb = keychange_cb; 
        videoep->xr = xrt_init(":0");
        videoep->notif = notify_init(port);

        xrt_connect_to_xserver(videoep->xr);

        return;                 /* everything went OK */

    } while(0);

    /* Something failed */
    if (conn != NULL)
        unregister_ep(videoep->conn);

    free(videoep);
}