~schnouki/pustule

e75b73232644a51c24fd5d79049229419b86e37f — Thomas Jost 7 years ago ab68932
Move Guile init to guile.c
3 files changed, 38 insertions(+), 31 deletions(-)

M guile.c
M main.c
M pustule.h
M guile.c => guile.c +35 -0
@@ 27,6 27,27 @@

#include "pustule.h"

/* Exported functions */
struct pustule_exported_func {
    const char* name;
    int req, opt, rst;
    scm_t_subr func;
    const char* doc;
} exported_funcs[] = {
    {"pustule-set-handlers", 2, 0, 0, &pustule_set_handlers,
     "Register two callbacks in pustule: SINK-ADDED and SINK-REMOVED.\n\n"
     "When a sink (i.e. a PulseAudio output) is added (for instance when a\n"
     "new application starts), SINK-ADDED is called with 2 arguments:\n"
     "the sink index (an integer) and an alist of the properties of\n"
     "the sin Likewise, when a sink is removed (playback stops,\n"
     "application closed…), SINK-REMOVED is called with one argument:\n"
     "the sink index."},
    {"pustule-set-volume", 2, 0, 0, &pustule_set_volume,
     "Sets the volume of the sink whose index is SINK-IDX (an integer) to\n"
     "VOLUME (a number between 0 and 1)."},
    {NULL, 0, 0, 0, NULL}
};

/* Global handlers */
SCM sink_added_callback = NULL;
SCM sink_removed_callback = NULL;


@@ 79,3 100,17 @@ SCM scm_from_sink_event(pustule_sink_event_t* event) {
    }
    return info;
}

/* Register functions with Guile */
void pustule_init_guile() {
    SCM key = scm_from_utf8_symbol("documentation");
    struct pustule_exported_func* func;
    for (func = exported_funcs; func->name != NULL; func++) {
        SCM proc = scm_c_define_gsubr(func->name, func->req, func->opt,
                                      func->rst, func->func);
        if (func->doc) {
            SCM doc = scm_from_utf8_string(func->doc);
            scm_set_procedure_property_x(proc, key, doc);
        }
    }
}

M main.c => main.c +2 -31
@@ 27,26 27,6 @@

#include "pustule.h"

struct pustule_exported_func {
    const char* name;
    int req, opt, rst;
    scm_t_subr func;
    const char* doc;
} exported_funcs[] = {
    {"pustule-set-handlers", 2, 0, 0, &pustule_set_handlers,
     "Register two callbacks in pustule: SINK-ADDED and SINK-REMOVED.\n\n"
     "When a sink (i.e. a PulseAudio output) is added (for instance when a\n"
     "new application starts), SINK-ADDED is called with 2 arguments:\n"
     "the sink index (an integer) and an alist of the properties of\n"
     "the sin Likewise, when a sink is removed (playback stops,\n"
     "application closed…), SINK-REMOVED is called with one argument:\n"
     "the sink index."},
    {"pustule-set-volume", 2, 0, 0, &pustule_set_volume,
     "Sets the volume of the sink whose index is SINK-IDX (an integer) to\n"
     "VOLUME (a number between 0 and 1)."},
    {NULL, 0, 0, 0, NULL}
};

/* Get the name of the default configuration file, using environment
   variables */
static char* get_default_config_file() {


@@ 83,17 63,8 @@ static char* get_default_config_file() {
static void* inner_main(void* data) {
    DocoptArgs* args = (DocoptArgs*) data;

    /* Tell Guile about our functions, and document them */
    SCM key = scm_from_utf8_symbol("documentation");
    struct pustule_exported_func* func;
    for (func = exported_funcs; func->name != NULL; func++) {
        SCM proc = scm_c_define_gsubr(func->name, func->req, func->opt,
                                      func->rst, func->func);
        if (func->doc) {
            SCM doc = scm_from_utf8_string(func->doc);
            scm_set_procedure_property_x(proc, key, doc);
        }
    }
    /* Register exported functions with Guile */
    pustule_init_guile();

    /* Run the config file */
    scm_c_primitive_load(args->config);

M pustule.h => pustule.h +1 -0
@@ 48,6 48,7 @@ SCM pustule_set_handlers(SCM sink_added, SCM sink_removed);
SCM pustule_set_volume(SCM idx, SCM volume);

/* Guile helpers */
void pustule_init_guile();
SCM scm_from_sink_event(pustule_sink_event_t* event);

/* Pustule event loop */