2 * Copyright (C) 2007 by Levi Bard
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 Levi Bard <taktaktaktaktaktaktaktaktaktak@gmail.com>
21 #include "lightmediascanner_parser.h"
30 * Native memory deletion function
35 static VALUE parser_free(VALUE self) {
37 Data_Get_Struct(self, ParserRuby, parser);
40 lms_parser_del(parser->parent, parser->plugin);
52 * Add parser plugin, given its shared object path.
54 * @param name path to shared object (usable by dlopen(3)).
56 * @return A new Parser
59 static VALUE scanner_add_parser(VALUE self, VALUE name) {
61 lms_plugin_t *plugin = NULL;
64 Check_Type(name, T_STRING);
66 Data_Get_Struct(self, lms_t, lms);
67 cname = StringValuePtr(name);
69 if(!(plugin = lms_parser_add(lms, cname))) {
70 plugin = lms_parser_find_and_add(lms, cname);
72 rb_raise(rb_eRuntimeError, "Unable to load plugin '%s'", cname);
76 //wrap and return plugin
77 return lightmediascanner_parser_new(lms, plugin);
78 }// scanner_add_parser
87 * @param parent The Scanner to which the parser belongs
89 * @param name path to shared object (usable by dlopen(3)).
91 * @return A new Parser
94 static VALUE parser_new(VALUE obj, VALUE parent, VALUE name) {
97 ParserRuby *parser = NULL;
98 lms_plugin_t *plugin = NULL;
100 Check_Type(name, T_STRING);
102 Data_Get_Struct(parent, lms_t, lms);
103 cname = StringValuePtr(name);
105 if(!(plugin = lms_parser_add(lms, cname))) {
106 plugin = lms_parser_find_and_add(lms, cname);
108 rb_raise(rb_eRuntimeError, "Unable to load plugin '%s'", cname);
112 parser = (ParserRuby*)malloc(sizeof(ParserRuby));
113 parser->parent = lms;
114 parser->plugin = plugin;
116 return Data_Wrap_Struct(lightmediascanner_parser, 0, parser_free, parser);
120 * LightMediaScanner::Parser is a class to represent
121 * a LightMediaScanner plugin.
123 void Init_lightmediascanner_parser() {
124 lightmediascanner_parser = rb_define_class_under(lightmediascanner_module, "Parser", rb_cObject);
125 rb_define_singleton_method(lightmediascanner_parser, "new", parser_new, 2);
126 }// Init_lightmediaparser_parser