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(ParserRuby *parser) {
38 lms_parser_del(parser->parent, parser->plugin);
51 * Add parser plugin, given its shared object path.
53 * * p1 (name) path to shared object (usable by dlopen(3)).
55 * * return A new Parser
58 static VALUE scanner_add_parser(VALUE self, VALUE name) {
60 lms_plugin_t *plugin = NULL;
63 Check_Type(name, T_STRING);
65 Data_Get_Struct(self, lms_t, lms);
66 cname = StringValuePtr(name);
68 if(!(plugin = lms_parser_add(lms, cname))) {
69 plugin = lms_parser_find_and_add(lms, cname);
71 rb_raise(rb_eRuntimeError, "Unable to load plugin '%s'", cname);
75 //wrap and return plugin
76 return lightmediascanner_parser_new(lms, plugin);
77 }// scanner_add_parser
86 * * p1 (parent) The Scanner to which the parser belongs
88 * * p2 (name) path to shared object (usable by dlopen(3)).
90 * * return A new Parser
93 static VALUE parser_new(VALUE obj, VALUE parent, VALUE name) {
96 ParserRuby *parser = NULL;
97 lms_plugin_t *plugin = NULL;
99 Check_Type(name, T_STRING);
101 Data_Get_Struct(parent, lms_t, lms);
102 cname = StringValuePtr(name);
104 if(!(plugin = lms_parser_add(lms, cname))) {
105 plugin = lms_parser_find_and_add(lms, cname);
107 rb_raise(rb_eRuntimeError, "Unable to load plugin '%s'", cname);
111 parser = (ParserRuby*)malloc(sizeof(ParserRuby));
112 parser->parent = lms;
113 parser->plugin = plugin;
115 return Data_Wrap_Struct(obj, NULL, parser_free, parser);
119 * LightMediaScanner::Parser is a class to represent
120 * a LightMediaScanner plugin.
122 void Init_lightmediascanner_parser() {
123 lightmediascanner_parser = rb_define_class_under(lightmediascanner_module, "Parser", rb_cObject);
124 rb_define_singleton_method(lightmediascanner_parser, "new", parser_new, 2);
125 }// Init_lightmediaparser_parser