Beispiel #1
0
int dbusif_send_signal(struct tonegend *tonegend, const char *intf, const char *name,
                       int first_arg_type, ...)
{
    struct dbusif *dbusif = tonegend->dbus_ctx;
    DBusMessage   *msg;
    va_list        ap;
    dbus_bool_t    success = FALSE;

    if (name == NULL) {
        N_ERROR(LOG_CAT "%s(): Called with invalid argument", __FUNCTION__);
        errno   = EINVAL;
        return -1;
    }

    if (intf == NULL)
        intf = TELEPHONY_TONES_SERVICE;

    if ((msg = dbus_message_new_signal(TELEPHONY_TONES_PATH, intf, name)) == NULL) {
        errno = ENOMEM;
        return -1;
    }

    va_start(ap, first_arg_type);

    if (dbus_message_append_args_valist(msg, first_arg_type, ap)) {
        success = dbus_connection_send(dbusif->conn, msg, NULL);
    }

    va_end(ap);

    dbus_message_unref(msg);

    return success ? 0 : -1;
}
Beispiel #2
0
static int
n_core_parse_events (NCore *core)
{
    gchar         *path       = NULL;
    DIR           *parent_dir = NULL;
    struct dirent *walk       = NULL;
    gchar         *filename   = NULL;

    /* find all the events within the given path */

    path = g_build_filename (core->conf_path, EVENT_CONF_PATH, NULL);
    parent_dir = opendir (path);
    if (!parent_dir) {
        N_ERROR (LOG_CAT "failed to open event path '%s'", path);
        g_free (path);
        return FALSE;
    }

    while ((walk = readdir (parent_dir)) != NULL) {
        if (walk->d_type & DT_REG) {
            filename = g_build_filename (path, walk->d_name, NULL);
            n_core_parse_events_from_file (core, filename);
            g_free (filename);
        }
    }

    closedir (parent_dir);
    g_free   (path);

    return TRUE;
}
Beispiel #3
0
struct dbusif *dbusif_create(struct tonegend *tonegend)
{
    struct dbusif   *dbusif = NULL;
    DBusConnection  *conn   = NULL;
    DBusError        err;

    if ((dbusif = (struct dbusif *) calloc(1, sizeof(struct dbusif))) == NULL) {
        N_ERROR(LOG_CAT "%s(): Can't allocate memory", __FUNCTION__);
        goto failed;
    }

    dbus_error_init(&err);

    if ((conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err)) == NULL) {
        N_ERROR(LOG_CAT "%s(): Can't connect to D-Bus daemon: %s",
                __FUNCTION__, err.message);
        dbus_error_free(&err);
        goto failed;
    }

    /*
     * The following will make us zombie if the system bus goes down.
     * However, for 'clean' shutdown operation it is useful, ie. the
     * shutdown sequence should not assure that we go before D-Bus go
     */
    dbus_connection_set_exit_on_disconnect(conn, FALSE);

    dbus_connection_setup_with_g_main(conn, NULL);

    dbusif->tonegend = tonegend;
    dbusif->conn   = conn;

    N_DEBUG(LOG_CAT "D-Bus setup OK");

    return dbusif;

failed:
    if (dbusif != NULL)
        free(dbusif);

    return NULL;
}
Beispiel #4
0
static NPlugin*
n_core_load_plugin (NCore *core, const char *plugin_name)
{
    g_assert (core != NULL);
    g_assert (plugin_name != NULL);

    NPlugin *plugin    = NULL;
    gchar   *filename  = NULL;
    gchar   *full_path = NULL;

    filename  = g_strdup_printf ("libngfd_%s.so", plugin_name);
    full_path = g_build_filename (core->plugin_path, filename, NULL);

    if (!(plugin = n_plugin_load (full_path)))
        goto done;

    plugin->core   = core;
    plugin->params = n_core_load_params (core, plugin_name);

    if (!plugin->load (plugin))
        goto done;

    N_DEBUG (LOG_CAT "loaded plugin '%s'", plugin_name);

    g_free (full_path);
    g_free (filename);

    return plugin;

done:
    N_ERROR (LOG_CAT "unable to load plugin '%s'", plugin_name);

    if (plugin)
        n_plugin_unload (plugin);

    g_free (full_path);
    g_free (filename);

    return NULL;
}
Beispiel #5
0
int
n_core_initialize (NCore *core)
{
    g_assert (core != NULL);
    g_assert (core->conf_path != NULL);
    g_assert (core->plugin_path != NULL);

    NSinkInterface  **sink   = NULL;
    NInputInterface **input  = NULL;
    NPlugin          *plugin = NULL;
    GList            *p      = NULL;

    /* setup hooks */

    n_hook_init (&core->hooks[N_CORE_HOOK_INIT_DONE]);
    n_hook_init (&core->hooks[N_CORE_HOOK_TRANSFORM_PROPERTIES]);
    n_hook_init (&core->hooks[N_CORE_HOOK_FILTER_SINKS]);

    /* load the default configuration. */

    if (!n_core_parse_configuration (core))
        goto failed_init;

    /* check for required plugins. */

    if (!core->required_plugins && !core->optional_plugins) {
        N_ERROR (LOG_CAT "no plugins to load defined in configuration");
        goto failed_init;
    }

    /* load events from the given event path. */

    if (!n_core_parse_events (core))
        goto failed_init;

    /* load all plugins */

    /* first mandatory plugins */
    for (p = g_list_first (core->required_plugins); p; p = g_list_next (p)) {
        if (!(plugin = n_core_load_plugin (core, (const char*) p->data)))
            goto failed_init;

        core->plugins = g_list_append (core->plugins, plugin);
    }

    /* then optional plugins */
    for (p = g_list_first (core->optional_plugins); p; p = g_list_next (p)) {
        if ((plugin = n_core_load_plugin (core, (const char*) p->data)))
            core->plugins = g_list_append (core->plugins, plugin);

        if (!plugin)
            N_INFO (LOG_CAT "optional plugin %s not loaded.", p->data);
    }

    /* setup the sink priorities based on the sink-order */

    n_core_set_sink_priorities (core->sinks, core->sink_order);

    /* initialize all sinks. if no sinks, we're done. */

    if (!core->sinks) {
        N_ERROR (LOG_CAT "no plugin has registered sink interface");
        goto failed_init;
    }

    for (sink = core->sinks; *sink; ++sink) {
        if ((*sink)->funcs.initialize && !(*sink)->funcs.initialize (*sink)) {
            N_ERROR (LOG_CAT "sink '%s' failed to initialize", (*sink)->name);
            goto failed_init;
        }
    }

    /* initialize all inputs. */

    if (!core->inputs) {
        N_ERROR (LOG_CAT "no plugin has registered input interface");
        goto failed_init;
    }

    for (input = core->inputs; *input; ++input) {
        if ((*input)->funcs.initialize && !(*input)->funcs.initialize (*input)) {
            N_ERROR (LOG_CAT "input '%s' failed to initialize", (*input)->name);
            goto failed_init;
        }
    }

    /* fire the init done hook. */

    n_core_fire_hook (core, N_CORE_HOOK_INIT_DONE, NULL);

    return TRUE;

failed_init:
    return FALSE;
}