f6ae56446ef81b4468a99593472b8528dba98afd
[lms] / lightmediascanner / src / bin / test.c
1 /**
2  * Copyright (C) 2007 by INdT
3  *
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.
8  *
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.
13  *
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.
17  *
18  * @author Gustavo Sverzut Barbieri <gustavo.barbieri@openbossa.org>
19  */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <lightmediascanner.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 void
30 usage(const char *prgname)
31 {
32     fprintf(stderr,
33             "Usage:\n"
34             "\t%s <commit-interval> <slave-timeout> <db-path> <parser> "
35             "<charset> <scan-path>\n"
36             "\n",
37             prgname);
38 }
39
40 int
41 main(int argc, char *argv[])
42 {
43     char *db_path, *parser_name, *charset, *scan_path;
44     lms_t *lms;
45     lms_plugin_t *parser;
46     int commit_interval, slave_timeout;
47
48     if (argc < 6) {
49         usage(argv[0]);
50         return 1;
51     }
52
53     commit_interval = atoi(argv[1]);
54     slave_timeout = atoi(argv[2]);
55     db_path = argv[3];
56     parser_name = argv[4];
57     charset = argv[5];
58     scan_path = argv[6];
59
60     lms = lms_new(db_path);
61     if (!lms) {
62         fprintf(stderr,
63                 "ERROR: could not create light media scanner for DB \"%s\".\n",
64                 db_path);
65         return -1;
66     }
67
68     lms_set_commit_interval(lms, commit_interval);
69     lms_set_slave_timeout(lms, slave_timeout);
70
71     parser = lms_parser_find_and_add(lms, parser_name);
72     if (!parser) {
73         fprintf(stderr, "ERROR: could not create parser \"%s\".\n",
74                 parser_name);
75         lms_free(lms);
76         return -2;
77     }
78
79     if (lms_charset_add(lms, charset) != 0) {
80         fprintf(stderr, "ERROR: could not add charset '%s'\n", charset);
81         lms_free(lms);
82         return -3;
83     }
84
85     if (lms_check(lms, scan_path) != 0) {
86         fprintf(stderr, "ERROR: checking \"%s\".\n", scan_path);
87         lms_free(lms);
88         return -4;
89     }
90
91     if (lms_process(lms, scan_path) != 0) {
92         fprintf(stderr, "ERROR: processing \"%s\".\n", scan_path);
93         lms_free(lms);
94         return -5;
95     }
96
97     if (lms_free(lms) != 0) {
98         fprintf(stderr, "ERROR: could not close light media scanner.\n");
99         return -6;
100     }
101
102     return 0;
103 }