2 * Copyright (C) 2007 by INdT
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
24 * Dummy plugin demonstrating the basic lightmediascanner_plugin API,
25 * it just write paths to /tmp/dummy.log.
32 #define _XOPEN_SOURCE 600
33 #include <lightmediascanner_plugin.h>
34 #include <sys/types.h>
42 static const char _name[] = "dummy";
45 struct lms_plugin plugin;
50 _match(struct plugin *p, const char *path, int len, int base)
56 _parse(struct plugin *plugin, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match)
58 write(plugin->fd, finfo->path, finfo->path_len);
59 write(plugin->fd, "\n", 1);
64 _close(struct plugin *plugin)
71 _setup(struct plugin *plugin, struct lms_context *ctxt)
77 _start(struct plugin *plugin, struct lms_context *ctxt)
79 char logfile[PATH_MAX];
81 snprintf(logfile, sizeof(logfile), "/tmp/dummy-%d.log", getuid());
82 plugin->fd = open(logfile, O_WRONLY | O_CREAT, 0600);
92 _finish(struct plugin *plugin, struct lms_context *ctxt)
94 if (close(plugin->fd) != 0)
102 API struct lms_plugin *
103 lms_plugin_open(void)
105 struct plugin *plugin;
107 plugin = malloc(sizeof(*plugin));
108 plugin->plugin.name = _name;
109 plugin->plugin.match = (lms_plugin_match_fn_t)_match;
110 plugin->plugin.parse = (lms_plugin_parse_fn_t)_parse;
111 plugin->plugin.close = (lms_plugin_close_fn_t)_close;
112 plugin->plugin.setup = (lms_plugin_setup_fn_t)_setup;
113 plugin->plugin.start = (lms_plugin_start_fn_t)_start;
114 plugin->plugin.finish = (lms_plugin_finish_fn_t)_finish;
116 return (struct lms_plugin *)plugin;