Skip to content

Commit

Permalink
Update example module
Browse files Browse the repository at this point in the history
  • Loading branch information
alip committed Jun 26, 2010
1 parent 387f423 commit 9638d9c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
3 changes: 2 additions & 1 deletion conf/modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ example.so: example.c
$(CC) -fPIC -shared -Wall -W -Wextra \
$(CFLAGS) $(LDFLAGS) \
$(shell pkg-config --cflags --libs glib-2.0) \
$(shell pkg-config --cflags --libs libdaemon) \
$(shell pkg-config --cflags --libs libmpdclient) \
$< -o $@
clean:
rm example.so || true
install:
install -m644 -s example.so ~/.mpdcron/modules
uninstall:
rm ~/.mpdcron/modules/example.so || true
18 changes: 7 additions & 11 deletions conf/modules/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* Compile this file like:
* gcc -fPIC -shared \
* $(pkg-config --cflags --libs glib-2.0) \
* $(pkg-config --cflags --libs libdaemon) \
* $(pkg-config --cflags --libs libmpdclient) \
* example.c -o example.so
* Put it under MPDCRON_DIR/modules where MPDCRON_DIR is ~/.mpdcron by default.
Expand All @@ -32,13 +31,12 @@

/* Define MPDCRON_MODULE before including the file.
*/
#define MPDCRON_MODULE "example"
#define MPDCRON_MODULE "example"
#include <mpdcron/gmodule.h>

#include <stdio.h>

#include <glib.h>
#include <libdaemon/dlog.h>
#include <mpd/client.h>

static int count;
Expand Down Expand Up @@ -71,11 +69,9 @@ int init(G_GNUC_UNUSED const struct mpdcron_config *conf, GKeyFile *fd)
{
GError *parse_error;

/* Use mpdcron_log() as logging function.
* It's a macro around daemon_log that adds MPDCRON_MODULE as a prefix
* to log strings.
/* You may use GLib logging functions to do the logging.
*/
mpdcron_log(LOG_NOTICE, "Hello from example module!");
g_message("Hello from example module!");

/* Parse configuration here. */
parse_error = NULL;
Expand All @@ -88,7 +84,7 @@ int init(G_GNUC_UNUSED const struct mpdcron_config *conf, GKeyFile *fd)
g_error_free(parse_error);
break;
default:
mpdcron_log(LOG_ERR, "Parse error: %s", parse_error->message);
g_critical("Parse error: %s", parse_error->message);
g_error_free(parse_error);
return MPDCRON_INIT_FAILURE;
}
Expand All @@ -107,7 +103,7 @@ int init(G_GNUC_UNUSED const struct mpdcron_config *conf, GKeyFile *fd)
*/
void destroy(void)
{
mpdcron_log(LOG_NOTICE, "Bye from example module!");
g_message("Bye from example module!");
/* Do the cleaning up. */
}

Expand All @@ -134,9 +130,9 @@ int run(G_GNUC_UNUSED const struct mpd_connection *conn, const struct mpd_status
volume = mpd_status_get_volume(status);

if (last_volume < 0)
mpdcron_log(LOG_INFO, "Volume set to: %d%%", volume);
g_message("Volume set to: %d%%", volume);
else
mpdcron_log(LOG_INFO, "Volume %s from: %d to: %d%%",
g_message("Volume %s from: %d to: %d%%",
(last_volume < volume) ? "increased" : "decreased",
last_volume, volume);

Expand Down

0 comments on commit 9638d9c

Please sign in to comment.