diff --git a/src/output/stdout.c b/src/output/stdout.c new file mode 100644 index 0000000..dba6a5c --- /dev/null +++ b/src/output/stdout.c @@ -0,0 +1,60 @@ +/* output/stdout.c - Standard output output-driver + * + * Copyright (C) 2010 Fredric Nilsson + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + */ +#include +#include +#include + +#include "output.h" +#include "../notify/event.h" + +/* + * Init. output-driver. Stdout has nothing + * to setup. + */ +int output_init(dictionary *config) { + printf("Running output_init()\n"); + return 0; +} + +int output_process(notify_event *event) { + + char *event_string; + + printf("Running output_process()\n"); + + switch (event->type) { + case NOTIFY_CREATE: + event_string = "create"; + break; + case NOTIFY_DELETE: + event_string = "delete"; + break; + case NOTIFY_MOVE_FROM: + event_string = "move_from"; + break; + case NOTIFY_MOVE_TO: + event_string = "move_to"; + break; + default: + event_string = "unknown"; + } + + printf("Event: {Path: %s, Filename: %s, Type: %s}\n", event->path, event->filename, event_string); + return 0; +} + +char *output_error(int error) { + return "Some kind of error"; +} + +int output_exit(void) { + printf("Running output_exit()\n"); + return 0; +} diff --git a/test/Makefile b/test/Makefile index fe8fe15..9b527ae 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,7 +3,7 @@ CC=gcc CFLAGS=-g -D__DEBUG__ LDFLAGS=-L/usr/lib64/mysql -lmysqlclient -all : raw_inotify strbuf path rbtree inotify tree indexer mysql queue +all : raw_inotify strbuf path rbtree inotify tree indexer mysql stdout queue raw_inotify : $(CC) -linotifytools t_raw_inotify.c -o test_raw_inotify @@ -71,6 +71,13 @@ mysql : ../src/ini/dictionary.c \ t_mysql.c -o test_mysql +stdout : + $(CC) $(CFLAGS) $(LDFLAGS) \ + ../src/output/stdout.c \ + ../src/ini/iniparser.c \ + ../src/ini/dictionary.c \ + t_stdout.c -o test_stdout + queue : $(CC) $(CFLAGS) ../src/notify/queue.c t_queue.c -o test_queue diff --git a/test/t_stdout.c b/test/t_stdout.c new file mode 100644 index 0000000..7aa6324 --- /dev/null +++ b/test/t_stdout.c @@ -0,0 +1,33 @@ + +#include +#include +#include +#include + +#include "../src/output/output.h" +#include "../src/notify/event.h" + +int main(int argc, char *argv[]) { + + int r; + notify_event ev; + + ev.path = "/home/kalle/bilder"; + ev.filename = "kalle.jpg"; + ev.type = NOTIFY_CREATE; + + output_init(NULL); + + r = output_process(&ev); + + ev.type = NOTIFY_DELETE; + + r = output_process(&ev); + + if (r != 0) + printf("Error: %s\n", output_error(r)); + + output_exit(); + + return 0; +}