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>
22 * @defgroup LMS_Plugin Plugins-API
25 * Plugins should implement the following call that provides required
26 * callbacks (see lightmediascanner_plugin.h):
29 * struct lms_plugin *lms_plugin_open(void)
37 * lms_plugin_match_fn_t match;
38 * lms_plugin_parse_fn_t parse;
39 * lms_plugin_close_fn_t close;
40 * lms_plugin_setup_fn_t setup;
41 * lms_plugin_start_fn_t start;
42 * lms_plugin_finish_fn_t finish;
46 * Users can add their own data to the end of this data
47 * structure. Callbacks and their meanings are:
50 * void *match(lms_plugin_t *p,
56 * Given the file 'path' of 'len' bytes, with base name starting at
57 * 'base' bytes offset inside 'path', return a match. Non-NULL
58 * values means it matched, and this return will be given to
59 * parse() function so any match-time analysis can be reused.
60 * This function will be used in the slave process.
64 * int parse(lms_plugin_t *p,
65 * struct lms_context *ctxt,
66 * const struct lms_file_info *finfo,
70 * Given the parsing context 'ctxt' (contains DB connection,
71 * charset conversion pointers and possible more), parse the file
72 * information 'finfo' using the previously matched data
73 * 'match'. This should return 0 on success or other value for
74 * errors. This will be used in the slave process.
78 * int close(lms_plugin_t *p)
81 * Closes the plugin returned by lms_plugin_open(), this will run
82 * on the master process.
86 * int setup(lms_plugin_t *p, struct lms_context *ctxt)
89 * Prepare parser to be executed. This is the first phase of plugin
90 * initialization on the slave process, it should create database
91 * tables and like, after this function is called, no database
92 * schema changes are allowed!
96 * int start(lms_plugin_t *p, struct lms_context *ctxt)
99 * This is the second phase of plugin initialization on the slave
100 * process. At this point, all database tables should exist and
101 * database schema will not be changed anymore, so one can use this
102 * phase to compile SQL statements for future use.
106 * int finish(lms_plugin_t *p, struct lms_context *ctxt)
109 * Finishes the plugin on slave process.
112 * Although LMS doesn't place any restrictions on what plugins can do and
113 * how they store information, it's good to have standard tables and easy
114 * way to store data on them. For this task we provide
115 * lightmediascanner_db.h with functions to add audios, images, videos,
116 * playlists and possible more. Use should be pretty straightforward, see
117 * existing plugins to see usage examples.
121 #ifndef _LIGHTMEDIASCANNER_PLUGIN_H_
122 #define _LIGHTMEDIASCANNER_PLUGIN_H_ 1
124 #include <lightmediascanner.h>
125 #include <lightmediascanner_charset_conv.h>
127 #include <sys/types.h>
133 struct lms_file_info {
134 const char *path; /**< file path */
135 int path_len; /**< path length */
136 int base; /**< index of basename inside path */
137 int64_t id; /**< database id */
138 time_t mtime; /**< in-disk modification time */
139 time_t dtime; /**< deletion time */
140 size_t size; /**< file size in bytes */
144 sqlite3 *db; /**< database instance */
145 lms_charset_conv_t *cs_conv; /**< charset conversion tool */
148 typedef void *(*lms_plugin_match_fn_t)(lms_plugin_t *p, const char *path, int len, int base);
149 typedef int (*lms_plugin_parse_fn_t)(lms_plugin_t *p, struct lms_context *ctxt, const struct lms_file_info *finfo, void *match);
150 typedef int (*lms_plugin_close_fn_t)(lms_plugin_t *p);
151 typedef int (*lms_plugin_setup_fn_t)(lms_plugin_t *p, struct lms_context *ctxt);
152 typedef int (*lms_plugin_start_fn_t)(lms_plugin_t *p, struct lms_context *ctxt);
153 typedef int (*lms_plugin_finish_fn_t)(lms_plugin_t *p, struct lms_context *ctxt);
156 const char *name; /**< plugin name */
157 lms_plugin_match_fn_t match; /**< check match */
158 lms_plugin_parse_fn_t parse; /**< parse matched file */
159 lms_plugin_close_fn_t close; /**< close plugin */
160 lms_plugin_setup_fn_t setup; /**< setup (1st phase init) */
161 lms_plugin_start_fn_t start; /**< start (2nd phase init) */
162 lms_plugin_finish_fn_t finish; /**< finish plugin */
168 #endif /* _LIGHTMEDIASCANNER_PLUGIN_H_ */