diff options
author | Tobias Grimm <tobias@e-tobi.loc> | 2009-02-14 23:25:05 +0100 |
---|---|---|
committer | Tobias Grimm <tobias@e-tobi.loc> | 2009-02-14 23:25:05 +0100 |
commit | 2bae6457006474655f971891a92341b1ae34840e (patch) | |
tree | 30a813fdbb1c096a08d7c35dd59fafc3f65154f4 | |
download | vdr-plugin-scripting-2bae6457006474655f971891a92341b1ae34840e.tar.gz vdr-plugin-scripting-2bae6457006474655f971891a92341b1ae34840e.tar.bz2 |
Initial commitv0.0.1branches/v0.0.1
45 files changed, 2176 insertions, 0 deletions
@@ -0,0 +1,3 @@ +2009-02-14: Version 0.0.1 + +- Initial proof-of-concept release diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e23ba48 --- /dev/null +++ b/Makefile @@ -0,0 +1,150 @@ +# +# Makefile for the Scripting VDR plugin +# +PLUGIN = scripting + +### The version number of this plugin (taken from the main source file): + +VERSION = $(shell grep 'static const char VERSION\[\] =' src/Version.h | \ + awk '{ print $$6 }' | sed -e 's/[";]//g') + +### The C++ compiler and options: + +CXX ?= g++ +CXXFLAGS ?= -fPIC -O2 -Wall -Woverloaded-virtual + +### The Ruby interpreter to be used: + +RUBY ?= /usr/bin/ruby1.8 + +### The directory environment: + +DVBDIR = ../../../../DVB +VDRDIR = ../../.. +LIBDIR = ../../lib +TMPDIR = /tmp + +### Conditionals: +#DEBUG=1 + +### Allow user defined options to overwrite defaults: + +-include $(VDRDIR)/Make.config + +### The version number of VDR's plugin API (taken from VDR's "config.h"): + +APIVERSION = $(shell sed -ne '/define APIVERSION/s/^.*"\(.*\)".*$$/\1/p' \ + $(VDRDIR)/config.h) + +### The name of the distribution archive: + +ARCHIVE = $(PLUGIN)-$(VERSION) +PACKAGE = vdr-$(ARCHIVE) + +### SWIG stuff: + +SWIG ?= swig +SWIGOPT = -Wall -w473 -ruby -c++ -Iswig -Iswig/custom -autorename + +### Includes and Defines (add further entries here): + +INCLUDES += -I. -I$(VDRDIR)/include -I$(DVBDIR)/include +INCLUDES += `$(RUBY) ruby-config.rb --cflags` + +DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +DEFINES += -DRUBY_EMBEDDED + +LIBS += `$(RUBY) ruby-config.rb --libs` + +ifdef DEBUG + DEFINES += -DDEBUG +endif + +### The source files (add further files here): + +-include sources.mk +-include swig.mk + +### The object files + +OBJS := $(addsuffix .o,$(basename ${SRCS})) + +### The SWIG wrappers + +OBJS += $(addsuffix _wrap.o,$(basename ${INTERFACES})) + +### Implicit rules: + +.PRECIOUS: %_wrap.cc +%_wrap.cc: %.i + $(SWIG) $(SWIGOPT) -o $@.in $< + $(RUBY) swig-postprocess.rb $@.in $@ + +swigrubyrun.h: + $(SWIG) -ruby -external-runtime + +%.o: %.cc + $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< -o $@ + +# Dependencies: + +MAKEDEP = $(CXX) -MM +BUILD_DEPFILE = .dependencies + +$(BUILD_DEPFILE): Makefile swigrubyrun.h + @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(SRCS) \ + | sed "s/.*: \([^ ]*\/\).*/\1\0/" > $@ + @$(SWIG) $(SWIGOPT) -MM $(INTERFACES) >> $@ + +-include $(BUILD_DEPFILE) + +### Internationalization (I18N): + +PODIR = po +LOCALEDIR = $(VDRDIR)/locale +I18Npo = $(wildcard $(PODIR)/*.po) +I18Nmsgs = $(addprefix $(LOCALEDIR)/, $(addsuffix /LC_MESSAGES/vdr-$(PLUGIN).mo, $(notdir $(foreach file, $(I18Npo), $(basename $(file)))))) +I18Npot = $(PODIR)/$(PLUGIN).pot + +%.mo: %.po + msgfmt -c -o $@ $< + +$(I18Npot): $(SRCS) + xgettext -C -cTRANSLATORS --no-wrap --no-location -k -ktr -ktrNOOP --msgid-bugs-address='<tg@e-tobi.net>' -o $@ $^ + +%.po: $(I18Npot) + msgmerge -U --no-wrap --no-location --backup=none -q $@ $< + @touch $@ + +$(I18Nmsgs): $(LOCALEDIR)/%/LC_MESSAGES/vdr-$(PLUGIN).mo: $(PODIR)/%.mo + @mkdir -p $(dir $@) + mv $< $@ + +.PHONY: i18n +i18n: $(I18Nmsgs) + +### Targets: + +all: libvdr-$(PLUGIN).so i18n + +test: + spec -c -fs . + +libvdr-$(PLUGIN).so: $(OBJS) + $(CXX) $(CXXFLAGS) -shared $(OBJS) -L. $(LIBS) -o $@ + @cp $@ $(LIBDIR)/$@.$(APIVERSION) + +dist: test clean + @-rm -rf $(TMPDIR)/$(ARCHIVE) + @mkdir $(TMPDIR)/$(ARCHIVE) + @cp -a * $(TMPDIR)/$(ARCHIVE) + @tar czf $(PACKAGE).tar.gz -C $(TMPDIR) --exclude debian --exclude .git \ + --exclude .svn --exclude tools --exclude .cproject --exclude .project \ + --exclude .settings $(ARCHIVE) + @-rm -rf $(TMPDIR)/$(ARCHIVE) + @echo Distribution package created as $(PACKAGE).tar.gz + +clean: + @-rm -f $(BUILD_DEPFILE) *.so* *.tar.gz core* *~ + @-rm -f swig/*_wrap.* swigrubyrun.h + @-find . -name \*.\o -exec rm -f {} \; @@ -0,0 +1,54 @@ +vdr-scripting +============= + +(C) 2009 Tobias Grimm <vdr@e-tobi.net> + +Project's homepage: + http://projects.vdr-developer.org/projects/show/plg-scripting + +Latest version available at: + http://projects.vdr-developer.org/projects/list_files/plg-scripting + +License: + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + at your option) any later version. + See the file COPYING for more information. + + +Description +----------- + +vdr-scripting is a VDR plug-in, which hosts other plug-ins written in +a dynamic scripting language. Currently only Ruby is supported. + + +Limitations +----------- + +Currently this is just a proof-of-concept release with only a very +limited set of functionality! + + +Installation +------------ + +To compile vdr-scripting Ruby 1.8.6 or 1.9 and with the Ruby heades and +libraries is required. + +Besides the VDR plugin you must install the libraries from lib/ to VDR's +configuration directory: + + <vdr-config-dir>/plugins/scripting/libs + + +Usage +----- + +Ruby plug-ins must me located in: + + <vdr-config-dir>/plugins/scripting/plugins + +You will find some sample plug-ins in the examples directory. Just +copy the *.rb files from there to the above directory and restart VDR. @@ -0,0 +1 @@ +- %initstack - see CHANGES in SWIG diff --git a/examples/HelloWorld.rb b/examples/HelloWorld.rb new file mode 100644 index 0000000..0f4e50a --- /dev/null +++ b/examples/HelloWorld.rb @@ -0,0 +1,71 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +include Vdr::Osd + +class MyPlugin + def main_menu_entries + [ + ['Greet The World', Proc.new { greet_the_world }], + ['Greet The Universe', Proc.new { greet_the_universe }], + ['Greet Your Favorite Starship Captain', Proc.new { select_a_starship_captain }] + ] + end + + def invoke_menu_item(proc) + return proc.call + end + + def greet_the_world + OsdMessage.Show("Hello World!", 3); + nil + end + + def greet_the_universe + OsdMessage.Show("Hello Universe!", 3); + nil + end + + CAPTAINS = + [ + {:name => 'Picard', :first_name => 'Jean Luc'}, + {:name => 'Janeway', :first_name => 'Kathryn'}, + {:name => 'Sisko', :first_name => 'Benjamin'}, + {:name => 'Archer', :first_name => 'Jonathan'}, + {:name => 'Solo', :first_name => 'Han'}, + {:name => 'Leela', :first_name => 'Turange'}, + {:name => 'Future', :first_name => 'Curtis'} + ] + + def select_a_starship_captain + return Menu.new("Select your favorit starship captain") do |menu| + for captain in CAPTAINS + item = menu.add_new_item("Captain #{captain[:name]}") + item.context = captain + item.on_select do |cpt| + OsdMessage.Show("Hello #{cpt.context[:first_name]}!!!") + menu.close + end + end + end + end +end + +Vdr::PLUGINS << MyPlugin.new diff --git a/examples/RssReader.rb b/examples/RssReader.rb new file mode 100644 index 0000000..794a8a3 --- /dev/null +++ b/examples/RssReader.rb @@ -0,0 +1,66 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require 'rubygems' +require 'simple-rss' +require 'open-uri' + +class HelloWorld + def main_menu_entries + [ + ["Open RSS Feed", :openRssFeed] + ] + end + + def invoke_menu_item(tag) + case tag + when :openRssFeed + rss = SimpleRSS.parse open('http://rss.golem.de/rss.php?feed=RSS2.0') + menu = Vdr::Osd::Menu.new("RSS Feed") + for item in rss.items + rssItem = Vdr::Osd::Item.new(item.title) + rssItem.context = item + rssItem.on_select do |i| + menu.open_sub_menu(Vdr::Osd::TextView.new(i.context.title, html_to_text(i.context.description))) + end + menu.add_item(rssItem) + end + return menu + end + end + + def html_to_text(html) + text = html + text.gsub!(/&/, "&") + text.gsub!(/</, "<") + text.gsub!(/>/, ">") + text.gsub!(/&#(\d)+;/) {|m| $1.to_i.chr} + text.gsub!(/&/, "&") + text.gsub!(/</, "<") + text.gsub!(/>/, ">") + text.gsub!(/<br\/>/, "") + text.gsub!(/<\/p>\n/, "\n") + text.gsub!(/<\/p>/, "\n") + text.gsub!(/<[^>]*>/, '') + return text + end +end + +Vdr::PLUGINS << HelloWorld.new diff --git a/lib/vdr.rb b/lib/vdr.rb new file mode 100644 index 0000000..1346894 --- /dev/null +++ b/lib/vdr.rb @@ -0,0 +1,22 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require 'vdr/osd' +require 'vdr/pluginmanager'
\ No newline at end of file diff --git a/lib/vdr/osd.rb b/lib/vdr/osd.rb new file mode 100644 index 0000000..29af09e --- /dev/null +++ b/lib/vdr/osd.rb @@ -0,0 +1,24 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require 'vdr/osd/menu' +require 'vdr/osd/item' +require 'vdr/osd/osdmessage' +require 'vdr/osd/textview' diff --git a/lib/vdr/osd/item.rb b/lib/vdr/osd/item.rb new file mode 100644 index 0000000..4c78040 --- /dev/null +++ b/lib/vdr/osd/item.rb @@ -0,0 +1,48 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +module Vdr + module Osd + class Item < Vdr::Swig::COsdItem + attr_reader :text + attr_accessor :context + + def initialize(text = nil) + @text = text + super(text) + end + + def on_select(&block) + @select = block + end + + def process_key(key) + state = super(key) + if key == Vdr::Swig::KOk + if @select + @select.call(self) + end + return Vdr::Swig::OsUnknown + end + return state + end + end + end +end diff --git a/lib/vdr/osd/menu.rb b/lib/vdr/osd/menu.rb new file mode 100644 index 0000000..5284726 --- /dev/null +++ b/lib/vdr/osd/menu.rb @@ -0,0 +1,76 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +module Vdr + module Osd + class Menu < Vdr::Swig::COsdMenu + attr_reader :title + def initialize(title=nil) + @title = title + super(@title) + @items = [] + yield(self) if block_given? + end + + def title=(title) + @title = title + set_title(@title) + end + + def add_item(item) + @items << item + add(item) + end + + def [](index) + return @items[index] + end + + def open_sub_menu(menu) + add_sub_menu(menu) + end + + def process_key(key) + state = super(key) + case @close_request + when :close + return Vdr::Swig::OsBack + when :close_all + return Vdr::Swig::OsEnd + end + return state + end + + def close + @close_request = :close + end + + def close_all + @close_request = :close_all + end + + def add_new_item(title) + item = Item.new(title) + add_item(item) + return item + end + end + end +end diff --git a/lib/vdr/osd/osdmessage.rb b/lib/vdr/osd/osdmessage.rb new file mode 100644 index 0000000..c6cfe8d --- /dev/null +++ b/lib/vdr/osd/osdmessage.rb @@ -0,0 +1,29 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +module Vdr + module Osd + class OsdMessage + def OsdMessage.Show(message, seconds=5) + Vdr::Swig::COsdMessage.confirm(message, seconds, false) + end + end + end +end diff --git a/lib/vdr/osd/textview.rb b/lib/vdr/osd/textview.rb new file mode 100644 index 0000000..87bce65 --- /dev/null +++ b/lib/vdr/osd/textview.rb @@ -0,0 +1,29 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +module Vdr + module Osd + class TextView < Vdr::Swig::CMenuText + def initialize(title, text) + super(title, text) + end + end + end +end diff --git a/lib/vdr/pluginmanager.rb b/lib/vdr/pluginmanager.rb new file mode 100644 index 0000000..182eb51 --- /dev/null +++ b/lib/vdr/pluginmanager.rb @@ -0,0 +1,64 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require 'vdr/osd' + +module Vdr + PLUGINS = [] + class PluginManager < Vdr::Swig::PluginManager + @@plugin_directory = File.expand_path(File.dirname(__FILE__) + '/../../plugins') + def self.plugin_directory + return @@plugin_directory + end + + def self.plugin_directory=(directory) + @@plugin_directory = directory + end + + def initialize + super + load_plugins + end + + def load_plugins + for pluginFile in Dir[@@plugin_directory + '/*.rb'] + Kernel::load(pluginFile, true) + end + end + + def plugin_menu + menu = Vdr::Osd::Menu.new('Script Plug-ins') + for plugin in PLUGINS + for mainMenuEntry, context in plugin.main_menu_entries + item = Vdr::Osd::Item.new(mainMenuEntry) + item.context = {:plugin => plugin, :context => context} + item.on_select do |selected_item| + sub_menu = selected_item.context[:plugin].invoke_menu_item(selected_item.context[:context]) + if (sub_menu) + menu.open_sub_menu(sub_menu) + end + end + menu.add_item(item) + end + end + return menu + end + end +end diff --git a/ruby-config.rb b/ruby-config.rb new file mode 100644 index 0000000..ab23d51 --- /dev/null +++ b/ruby-config.rb @@ -0,0 +1,15 @@ +require 'rbconfig' + +if ARGV.include?('--cflags') + if Config::CONFIG["rubyhdrdir"] + rubyhdrdir = Config::CONFIG["rubyhdrdir"] + arch = Config::CONFIG["arch"] + puts "-I#{rubyhdrdir} -I#{rubyhdrdir}/#{arch}" + else + puts '-I' + Config::CONFIG["archdir"] + end +end + +if ARGV.include?('--libs') + puts Config::CONFIG["LIBRUBYARG"] || "-l" + Config::CONFIG["ruby_install_name"] +end diff --git a/sources.mk b/sources.mk new file mode 100644 index 0000000..86d3aa5 --- /dev/null +++ b/sources.mk @@ -0,0 +1,5 @@ +SRCS = \ + src/OsdMessage.cc \ + src/RubyObjectTracker.cc \ + src/ScriptingPlugin.cc \ + src/PluginManager.cc \ diff --git a/spec/helper.rb b/spec/helper.rb new file mode 100644 index 0000000..cf389b7 --- /dev/null +++ b/spec/helper.rb @@ -0,0 +1,24 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib/' + +require File.dirname(__FILE__) + '/vdrswig-fakewrapper' + diff --git a/spec/vdr/_sample-plugins/plugin1.rb b/spec/vdr/_sample-plugins/plugin1.rb new file mode 100644 index 0000000..b5bbdf5 --- /dev/null +++ b/spec/vdr/_sample-plugins/plugin1.rb @@ -0,0 +1,27 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +class Plugin + def main_menu_entries + return [['plugin 1.a', :a], ['plugin 1.b', :b]] + end +end + +Vdr::PLUGINS << Plugin.new diff --git a/spec/vdr/_sample-plugins/plugin2.rb b/spec/vdr/_sample-plugins/plugin2.rb new file mode 100644 index 0000000..96eead2 --- /dev/null +++ b/spec/vdr/_sample-plugins/plugin2.rb @@ -0,0 +1,27 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +class Plugin + def main_menu_entries + return [['plugin 2.a', :a], ['plugin 2.b', :b]] + end +end + +Vdr::PLUGINS << Plugin.new diff --git a/spec/vdr/osd/item_spec.rb b/spec/vdr/osd/item_spec.rb new file mode 100644 index 0000000..27d226b --- /dev/null +++ b/spec/vdr/osd/item_spec.rb @@ -0,0 +1,57 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require File.expand_path(File.dirname(__FILE__) + '/../../helper') +require 'vdr/osd/item' + +describe Vdr::Osd::Item do + before(:each) do + @item = Vdr::Osd::Item.new('text') + end + + it 'should set the item text in the ctor' do + @item.text.should == 'text' + @item.cosditem_ctor_arguments[0].should == 'text' + end + + it 'should have an assignable context' do + @item.context = :context + @item.context.should == :context + end + + describe 'when the Ok key is pressed on the item' do + it 'should trigger the select event' do + item_was_selected = false; + @item.on_select do |i| + item_was_selected = true + i.should == @item + end + + @item.process_key(Vdr::Swig::KOk) + + item_was_selected.should == true + end + + it 'should return osUnknown' do + @item.process_key(Vdr::Swig::KOk).should == Vdr::Swig::OsUnknown + end + end + +end diff --git a/spec/vdr/osd/menu_spec.rb b/spec/vdr/osd/menu_spec.rb new file mode 100644 index 0000000..dff9b31 --- /dev/null +++ b/spec/vdr/osd/menu_spec.rb @@ -0,0 +1,88 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require File.expand_path(File.dirname(__FILE__) + '/../../helper') +require 'vdr/osd' + +describe Vdr::Osd::Menu do + before(:each) do + @menu = Vdr::Osd::Menu.new('Title') + end + + describe 'when creating' do + it 'should set the menu title' do + @menu.title.should == 'Title' + @menu.cosdmenu_ctor_arguments[0].should == 'Title' + end + + it 'should configure the menu' do + menu = Vdr::Osd::Menu.new do |m| + m.title = 'new title' + end + menu.title.should == 'new title' + end + end + + it 'should set the menu title' do + @menu.should_receive(:set_title).with('NewTitle') + @menu.title='NewTitle' + @menu.title.should == 'NewTitle' + end + + it 'should add an item to the menu' do + item = Vdr::Osd::Item.new + @menu.should_receive(:add).with(item) + @menu.add_item(item) + end + + it 'should provide a list of menu items' do + item1 = Vdr::Osd::Item.new + item2 = Vdr::Osd::Item.new + @menu.add_item(item1) + @menu.add_item(item2) + @menu[0].should == item1 + @menu[1].should == item2 + end + + it 'should add a sub menu when opening a sub menu' do + sub_menu = Vdr::Osd::Menu.new + @menu.should_receive(:add_sub_menu).with(sub_menu) + @menu.open_sub_menu(sub_menu) + end + + it 'should return the parents result from process_key' do + @menu.process_key(Vdr::Swig::KOk).should == Vdr::Swig::OsUnknown + end + + it 'should return OsBack from process_key when requesting to close the menu' do + @menu.close + @menu.process_key(Vdr::Swig::KOk).should == Vdr::Swig::OsBack + end + + it 'should return OsEnd from process_key when requesting to close all menus' do + @menu.close_all + @menu.process_key(Vdr::Swig::KOk).should == Vdr::Swig::OsEnd + end + + it 'should add a new menu item' do + @menu.add_new_item('item') + @menu[0].text.should == 'item' + end +end diff --git a/spec/vdr/osd/osdmessage_spec.rb b/spec/vdr/osd/osdmessage_spec.rb new file mode 100644 index 0000000..1b33d34 --- /dev/null +++ b/spec/vdr/osd/osdmessage_spec.rb @@ -0,0 +1,29 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require File.expand_path(File.dirname(__FILE__) + '/../../helper') +require 'vdr/osd' + +describe Vdr::Osd::OsdMessage do + it 'should show the message' do + Vdr::Swig::COsdMessage.should_receive(:confirm).with("message", 5, false) + Vdr::Osd::OsdMessage.Show("message", 5) + end +end
\ No newline at end of file diff --git a/spec/vdr/osd/textview_spec.rb b/spec/vdr/osd/textview_spec.rb new file mode 100644 index 0000000..833dcba --- /dev/null +++ b/spec/vdr/osd/textview_spec.rb @@ -0,0 +1,32 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require File.expand_path(File.dirname(__FILE__) + '/../../helper') +require 'vdr/osd/textview' + +describe Vdr::Osd::TextView do + describe 'when created' do + it 'should set title and text of the text view' do + text_view = Vdr::Osd::TextView.new('title', 'text') + text_view.CMenuText_title.should == 'title' + text_view.CMenuText_text.should == 'text' + end + end +end diff --git a/spec/vdr/pluginmanager_spec.rb b/spec/vdr/pluginmanager_spec.rb new file mode 100644 index 0000000..f21c771 --- /dev/null +++ b/spec/vdr/pluginmanager_spec.rb @@ -0,0 +1,70 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +require File.expand_path(File.dirname(__FILE__) + '/../helper') +require 'vdr/pluginmanager' +require 'pathname' + +describe Vdr::PluginManager do + before(:each) do + Vdr::PLUGINS.clear + Vdr::PluginManager::plugin_directory = File.dirname(__FILE__) + '/_sample-plugins' + @pluginManager = Vdr::PluginManager.new + end + + describe 'when loading a plugin throws an exception' do + it 'should log the exception' + it 'should not load the plugin' + end + + describe 'when created' do + it 'should load all plugins in the plugin directory' do + Vdr::PLUGINS.should have(2).things + end + + it 'should provide a menu containing the main menu entries of all plugins' do + menu = @pluginManager.plugin_menu + menu[0].text.should == "plugin 1.a" + menu[1].text.should == "plugin 1.b" + menu[2].text.should == "plugin 2.a" + menu[3].text.should == "plugin 2.b" + end + end + + describe 'when selecting an item' do + before(:each) do + @menu = @pluginManager.plugin_menu + end + + it 'should inform the plugin' do + Vdr::PLUGINS[0].should_receive(:invoke_menu_item).with(:a) + Vdr::PLUGINS[1].should_receive(:invoke_menu_item).with(:b) + @menu[0].process_key(Vdr::Swig::KOk) + @menu[3].process_key(Vdr::Swig::KOk) + end + + it 'should switch to the menu eventually provided by the plugin' do + returned_menu = Vdr::Osd::Menu.new + Vdr::PLUGINS[1].stub!(:invoke_menu_item).and_return(returned_menu) + @menu.should_receive(:open_sub_menu).with(returned_menu) + @menu[2].process_key(Vdr::Swig::KOk) + end + end +end diff --git a/spec/vdrswig-fakewrapper.rb b/spec/vdrswig-fakewrapper.rb new file mode 100644 index 0000000..a004ac3 --- /dev/null +++ b/spec/vdrswig-fakewrapper.rb @@ -0,0 +1,78 @@ +# +# vdr-scripting - A plugin for the Linux Video Disk Recorder +# Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# + +module Vdr + module Swig + + OsUnknown = :OsUnknown + OsContinue = :OsContinue + OsBack = :OsBack + OsEnd = :OsEnd + + KOk = 1 + class COsdMenu + attr_reader :cosdmenu_ctor_arguments, :current + + def initialize(*args) + @cosdmenu_ctor_arguments = args + end + + def set_title(title) + end + + def add(item) + end + + def process_key(key) + return OsUnknown + end + + def simulate_select(index) + @current = index + process_key(Vdr::Swig::KOk) + end + end + + class COsdItem + attr_reader :cosditem_ctor_arguments + def initialize(*args) + @cosditem_ctor_arguments = args + end + + def process_key(key) + end + end + + class PluginManager + end + + class COsdMessage + end + + class CMenuText + attr_reader :CMenuText_title, :CMenuText_text + + def initialize(title, text) + @CMenuText_title = title + @CMenuText_text = text + end + end + end +end diff --git a/src/OsdMessage.cc b/src/OsdMessage.cc new file mode 100644 index 0000000..58716b5 --- /dev/null +++ b/src/OsdMessage.cc @@ -0,0 +1,27 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "OsdMessage.h" +#include <vdr/interface.h> + +bool cOsdMessage::Confirm(const char* message, int seconds, bool waitForTimeout) +{ + return Interface->Confirm(message, seconds, waitForTimeout); +} diff --git a/src/OsdMessage.h b/src/OsdMessage.h new file mode 100644 index 0000000..6a2a1eb --- /dev/null +++ b/src/OsdMessage.h @@ -0,0 +1,30 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __OSDMESSAGE_H__ +#define __OSDMESSAGE_H__ + +class cOsdMessage +{ + public: + static bool Confirm(const char* message, int seconds = 10, bool waitForTimeout = false); +}; + +#endif diff --git a/src/PluginManager.cc b/src/PluginManager.cc new file mode 100644 index 0000000..92e6b99 --- /dev/null +++ b/src/PluginManager.cc @@ -0,0 +1,21 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "PluginManager.h" diff --git a/src/PluginManager.h b/src/PluginManager.h new file mode 100644 index 0000000..b3b6f53 --- /dev/null +++ b/src/PluginManager.h @@ -0,0 +1,33 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __PLUGINMANAGER__ +#define __PLUGINMANAGER__ + +#include <vdr/osdbase.h> + +class PluginManager +{ + public: + virtual ~PluginManager() {}; + virtual cOsdMenu* PluginMenu() = 0; +}; + +#endif diff --git a/src/RubyObjectTracker.cc b/src/RubyObjectTracker.cc new file mode 100644 index 0000000..78450b0 --- /dev/null +++ b/src/RubyObjectTracker.cc @@ -0,0 +1,112 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "RubyObjectTracker.h" + +#ifdef DEBUG_RUBY_OBJECT_TRACKER +#include <iostream> +#endif + +using namespace std; + +TrackedRubyObject::TrackedRubyObject() + :_rubyObject(Qnil), _keepAlive(false) +{ +} + +TrackedRubyObject::TrackedRubyObject(VALUE rubyObject, bool keepAlive) + :_rubyObject(rubyObject), _keepAlive(keepAlive) +{ +} + +VALUE TrackedRubyObject::RubyObject() +{ + return _rubyObject; +} + +void TrackedRubyObject::KeepAlive(bool keepAlive) +{ + _keepAlive = keepAlive; +} + +void TrackedRubyObject::Mark() +{ + if (_keepAlive) + { +#ifdef DEBUG_RUBY_OBJECT_TRACKER + cerr << "RubyObjectTracker::Mark(" << _rubyObject << ")" << endl; +#endif + rb_gc_mark(_rubyObject); + } +} + +void RubyObjectTracker::Track(void* cppPointer, VALUE rubyObject) +{ +#ifdef DEBUG_RUBY_OBJECT_TRACKER + cerr << "RubyObjectTracker::Track(" << rubyObject << ")" << endl; +#endif + _map[cppPointer] = TrackedRubyObject(rubyObject, false); +} + +void RubyObjectTracker::Untrack(void* cppPointer) +{ +#ifdef DEBUG_RUBY_OBJECT_TRACKER + map<void*, TrackedRubyObject>::iterator i = _map.find(cppPointer); + if (i != _map.end()) + { + cerr << "RubyObjectTracker::Untrack(" << i->second.RubyObject() << ")" << endl; + } +#endif + _map.erase(cppPointer); +} + +VALUE RubyObjectTracker::GetTrackedRubyObject(void* cppPointer) +{ + if (_map.find(cppPointer) == _map.end()) + { + return Qnil; + } + else + { + return _map.find(cppPointer)->second.RubyObject(); + } +} + +void RubyObjectTracker::KeepRubyObjectAlive(void* cppPointer) +{ + map<void*, TrackedRubyObject>::iterator i = _map.find(cppPointer); + if (i != _map.end()) + { + i->second.KeepAlive(true); + } +} + +void RubyObjectTracker::MarkTrackedRubyObjects() +{ + for ( map<void*, TrackedRubyObject>::iterator i = _map.begin() ; i != _map.end(); i++ ) + { + i->second.Mark(); + } +} + +void RubyObjectTracker::MarkTrackedRubyObjects(void* self) +{ + ((RubyObjectTracker*) self)->MarkTrackedRubyObjects(); +} diff --git a/src/RubyObjectTracker.h b/src/RubyObjectTracker.h new file mode 100644 index 0000000..aff6768 --- /dev/null +++ b/src/RubyObjectTracker.h @@ -0,0 +1,55 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __RUBY_OBJECT_TRACKER_H +#define __RUBY_OBJECT_TRACKER_H + +#include<map> +#include<ruby.h> + +class TrackedRubyObject +{ + private: + VALUE _rubyObject; + bool _keepAlive; + + public: + TrackedRubyObject(); + TrackedRubyObject(VALUE rubyObject, bool keepAlive); + VALUE RubyObject(); + void KeepAlive(bool keepAlive); + void Mark(); +}; + +class RubyObjectTracker +{ + private: + std::map<void*, TrackedRubyObject> _map; + + public: + void Track(void* cppPointer, VALUE rubyObject); + void Untrack(void* cppPointer); + VALUE GetTrackedRubyObject(void* cppPointer); + void KeepRubyObjectAlive(void* cppPointer); + void MarkTrackedRubyObjects(); + static void MarkTrackedRubyObjects(void* self); +}; + +#endif diff --git a/src/ScriptingPlugin.cc b/src/ScriptingPlugin.cc new file mode 100644 index 0000000..214af26 --- /dev/null +++ b/src/ScriptingPlugin.cc @@ -0,0 +1,235 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include <ruby.h> + +#include "ScriptingPlugin.h" +#include <vdr/tools.h> +#include <iostream> +#include "swigrubyrun.h" +#include "RubyObjectTracker.h" + +using namespace std; + +extern "C" void Init_swig(); +extern RubyObjectTracker rubyObjectTracker; + +VALUE require_pluginmanager_wrap(VALUE arg) +{ + return rb_require("vdr/pluginmanager"); +} + +VALUE new_pluginmanager_wrap(VALUE arg) +{ + VALUE module = rb_const_get(rb_cObject, rb_intern("Vdr")); + VALUE klass = rb_const_get(module, rb_intern("PluginManager")); + return rb_class_new_instance(0 ,0, klass); +} + +ScriptingPlugin::ScriptingPlugin() +{ + // Initialize any member variables here. + // DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL + // VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT! +} + +ScriptingPlugin::~ScriptingPlugin() +{ + ruby_finalize(); +} + +const char *ScriptingPlugin::CommandLineHelp() +{ + // Return a string that describes all known command line options. + return NULL; +} + +bool ScriptingPlugin::ProcessArgs(int argc, char *argv[]) +{ + // Implement command line argument processing here if applicable. + return true; +} + +bool ScriptingPlugin::Initialize() +{ + // Initialize any background activities the plugin shall perform. + + const char* configDir = cPlugin::ConfigDirectory(Name()); + + RUBY_INIT_STACK; + ruby_init(); + ruby_init_loadpath(); + ruby_incpush(cString::sprintf("%s/lib", configDir)); + ruby_script("vdr-plugin-ruby"); + Init_swig(); + + rb_eval_string("STDERR.puts $LOAD_PATH"); + + int error; + VALUE result = rb_protect(require_pluginmanager_wrap, 0, &error); + if (IsRubyError(error)) + { + return true; + } + + //rb_require("vdr/pluginmanager"); + + VALUE rbPluginManager = rb_protect(new_pluginmanager_wrap, 0, &error); + if (IsRubyError(error)) + { + return true; + } + + if (rbPluginManager == Qnil) + { + cerr << "rbPluginManger is nil" << endl; + } + + Data_Get_Struct(rbPluginManager, PluginManager, _pluginManager); + + if (!_pluginManager) + { + cerr << "no plugin manager" << endl; + } + + return true; +} + +bool ScriptingPlugin::Start() +{ + // Start any background activities the plugin shall perform. + return true; +} + +void ScriptingPlugin::Stop() +{ + // Stop any background activities the plugin is performing. +} + +void ScriptingPlugin::Housekeeping() +{ + VALUE gc_wrap(VALUE arg); + // Perform any cleanup or other regular tasks. +} + +void ScriptingPlugin::MainThreadHook() +{ + // Perform actions in the context of the main program thread. + // WARNING: Use with great care - see PLUGINS.html! +} + +cString ScriptingPlugin::Active() +{ + // Return a message string if shutdown should be postponed + return NULL; +} + +time_t ScriptingPlugin::WakeupTime() +{ + // Return custom wakeup time for shutdown script + return 0; +} + +cOsdObject *ScriptingPlugin::MainMenuAction() +{ + if (!_pluginManager) + { + cerr << "NO PLUGINMANAGER" << endl; + return NULL; + } + + cOsdObject* osdObject = _pluginManager->PluginMenu(); + + if (!osdObject) + { + cerr << "NO MENU" << endl; + return NULL; + } + + rubyObjectTracker.KeepRubyObjectAlive(osdObject); + return osdObject; +} + +cMenuSetupPage *ScriptingPlugin::SetupMenu() +{ + // Return a setup menu in case the plugin supports one. + return NULL; +} + +bool ScriptingPlugin::SetupParse(const char *Name, const char *Value) +{ + // Parse your own setup parameters and store their values. + return false; +} + +bool ScriptingPlugin::Service(const char *Id, void *Data) +{ + // Handle custom service requests from other plugins + return false; +} + +const char **ScriptingPlugin::SVDRPHelpPages() +{ + // Return help text for SVDRP commands this plugin implements + return NULL; +} + +cString ScriptingPlugin::SVDRPCommand(const char *Command, const char *Option, int &ReplyCode) +{ + // Process SVDRP commands this plugin implements + return NULL; +} + + +VALUE gc_wrap(VALUE arg) +{ + rb_gc(); + return Qnil; +} + +void ScriptingPlugin::ForceGarbageCollect() +{ + int status; + rb_protect(gc_wrap, 0, &status); +// IsRubyError(status); +} + + +bool ScriptingPlugin::IsRubyError(int error) +{ + if (error) + { + VALUE lasterr = rb_gv_get("$!"); + + VALUE klass = rb_class_path(CLASS_OF(lasterr)); + cerr << "class = " << RSTRING(klass)->ptr << endl; + + VALUE message = rb_obj_as_string(lasterr); + cerr << "message = " << RSTRING(message)->ptr << endl; + + return true; + } + else + { + return false; + } +} + +VDRPLUGINCREATOR(ScriptingPlugin); // Don't touch this! diff --git a/src/ScriptingPlugin.h b/src/ScriptingPlugin.h new file mode 100644 index 0000000..0caf557 --- /dev/null +++ b/src/ScriptingPlugin.h @@ -0,0 +1,64 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __RUBYPLUGIN_H +#define __RUBYPLUGIN_H + +#include <vdr/plugin.h> +#include <ruby.h> +#include "Version.h" +#include "PluginManager.h" + +static const char *DESCRIPTION = "A plug-in allowing to write sub-plug-ins in a dynamic language"; +static const char *MAINMENUENTRY = "Script Plug-ins"; + +class ScriptingPlugin : public cPlugin +{ + private: + PluginManager* _pluginManager; + + public: + ScriptingPlugin(); + virtual ~ScriptingPlugin(); + virtual const char *Version() { return VERSION; } + virtual const char *Description() { return DESCRIPTION; } + virtual const char *CommandLineHelp(); + virtual bool ProcessArgs(int argc, char *argv[]); + virtual bool Initialize(); + virtual bool Start(); + virtual void Stop(); + virtual void Housekeeping(); + virtual void MainThreadHook(); + virtual cString Active(); + virtual time_t WakeupTime(); + virtual const char *MainMenuEntry() { return MAINMENUENTRY; } + virtual cOsdObject *MainMenuAction(); + virtual cMenuSetupPage *SetupMenu(); + virtual bool SetupParse(const char *Name, const char *Value); + virtual bool Service(const char *Id, void *Data = NULL); + virtual const char **SVDRPHelpPages(); + virtual cString SVDRPCommand(const char *Command, const char *Option, int &ReplyCode); + + private: + void ForceGarbageCollect(); + bool IsRubyError(int error); +}; + +#endif diff --git a/src/Version.h b/src/Version.h new file mode 100644 index 0000000..1c921c3 --- /dev/null +++ b/src/Version.h @@ -0,0 +1,26 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef ___VERSION_H +#define ___VERSION_H + +static const char VERSION[] = "0.0.1"; + +#endif diff --git a/swig-postprocess.rb b/swig-postprocess.rb new file mode 100644 index 0000000..26dd268 --- /dev/null +++ b/swig-postprocess.rb @@ -0,0 +1,37 @@ +AUTOUNLINK = [ "COsdItem", "COsdMenu", "CMenuText" ] + +################################################################################ + +# +# Add auto unlink code to SWIG director destructors like: +# +# SwigDirector_<class>::~SwigDirector_<class>() { +# SWIG_RubyUnlinkObjects(this); +# SWIG_RubyRemoveTracking(this); +# } +# +# With this code, when a C++ instance is delete, it will automatically remove +# itself from the list of tracked objects and unlink itself from the Ruby object +# it is used by. This means, that any call to a method of the C++ class from the +# Ruby object will now throw an ObjectPreviouslyDeleted exception. +# +def add_auto_unlink_code + for klass in AUTOUNLINK + @swig_code.gsub!(/(SwigDirector_#{klass}::~SwigDirector_#{klass}\(\) \{\n)(\})/m, + "\\1 SWIG_RubyUnlinkObjects(this);\n SWIG_RubyRemoveTracking(this);\n\\2") + end +end + +def improve_overloaded_error + @swig_code.gsub!(/("%s )(for overloaded.*msg,)( method, prototypes)/m, + '\1(%d) \2 argc-1,\3') +end + +## main ## + +@swig_code = IO.read(ARGV[0]) + +add_auto_unlink_code if ! AUTOUNLINK.empty? +improve_overloaded_error + +File.new(ARGV[1], "w").write(@swig_code) @@ -0,0 +1,2 @@ +INTERFACES = \ + swig/vdr.i \ diff --git a/swig/PluginManager.i b/swig/PluginManager.i new file mode 100644 index 0000000..3afb9b4 --- /dev/null +++ b/swig/PluginManager.i @@ -0,0 +1,27 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%{ +#include "src/PluginManager.h" +%} + +%feature("director") PluginManager; + +%include "src/PluginManager.h" diff --git a/swig/cMenuText.i b/swig/cMenuText.i new file mode 100644 index 0000000..2ce158c --- /dev/null +++ b/swig/cMenuText.i @@ -0,0 +1,30 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%{ +#include <vdr/menu.h> +%} + +class cMenuText : public cOsdMenu +{ + public: + cMenuText(const char *Title, const char *Text); + virtual ~cMenuText(); +}; diff --git a/swig/cOsdItem.i b/swig/cOsdItem.i new file mode 100644 index 0000000..c50181c --- /dev/null +++ b/swig/cOsdItem.i @@ -0,0 +1,36 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%include "eOSState.i" + +%{ +#include <vdr/osdbase.h> +%} + +%feature("director") cOsdItem; + +class cOsdItem +{ + public: + cOsdItem(eOSState State = osUnknown); + virtual ~cOsdItem(); + cOsdItem(const char *Text, eOSState State = osUnknown, bool Selectable = true); + virtual eOSState ProcessKey(eKeys Key); +}; diff --git a/swig/cOsdMenu.i b/swig/cOsdMenu.i new file mode 100644 index 0000000..ecc4678 --- /dev/null +++ b/swig/cOsdMenu.i @@ -0,0 +1,55 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%include "eKeys.i" +%include "eOSState.i" +%include "typemaps.i" + +%{ +#include <vdr/osdbase.h> +%} + +%feature("director") cOsdMenu; + +// +// When adding an item to a menu, the menu becomes it's owner and is +// responsible for deleting it. +// +%apply SWIGTYPE* TRANSFER_DELETE_RESPONSIBILITY {cOsdItem* foo}; + +// +// When adding an submenu to a menu, the menu becomes it's owner and is +// responsible for deleting it. +// +%apply SWIGTYPE* TRANSFER_DELETE_RESPONSIBILITY {cOsdMenu* foo}; + +class cOsdMenu +{ + protected: + eOSState AddSubMenu(cOsdMenu *SubMenu); + + public: + cOsdMenu(const char *Title, int c0 = 0, int c1 = 0, int c2 = 0, int c3 = 0, int c4 = 0); + virtual ~cOsdMenu(); + int Current(void) const; + void Add(cOsdItem *Item, bool Current = false, cOsdItem *After = NULL); + void Ins(cOsdItem *Item, bool Current = false, cOsdItem *Before = NULL); + virtual eOSState ProcessKey(eKeys Key); +}; diff --git a/swig/cOsdMessage.i b/swig/cOsdMessage.i new file mode 100644 index 0000000..ca14bd2 --- /dev/null +++ b/swig/cOsdMessage.i @@ -0,0 +1,25 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%{ +#include "src/OsdMessage.h" +%} + +%include "src/OsdMessage.h" diff --git a/swig/custom/rubytracking.swg b/swig/custom/rubytracking.swg new file mode 100644 index 0000000..1495975 --- /dev/null +++ b/swig/custom/rubytracking.swg @@ -0,0 +1,69 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "src/RubyObjectTracker.h" + +RubyObjectTracker rubyObjectTracker; + +#ifdef __cplusplus +extern "C" { +#endif + +SWIGRUNTIME void SWIG_RubyInitializeTrackings(void) +{ + VALUE rubyObjectTrackerClass = rb_define_class_under(_mSWIG, "RubyObjectTrackings", rb_cObject); + + // The object tracker is allocated on the stack, so no free function is needed. + // But a mark function is required to keep the tracked ruby objects alive + VALUE rbRubyObjectTracker = Data_Wrap_Struct(rubyObjectTrackerClass, RubyObjectTracker::MarkTrackedRubyObjects, 0, + &rubyObjectTracker); + + // To keep the RubyObjectTracker alive itself, put it into a variable under the SWIG module: + VALUE rubyObjectTrackerSymbol = rb_intern("@ruby_object_tracker"); + rb_ivar_set(_mSWIG, rubyObjectTrackerSymbol, rbRubyObjectTracker); +} + +SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) +{ + rubyObjectTracker.Track(ptr, object); +} + +SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) +{ + return rubyObjectTracker.GetTrackedRubyObject(ptr); +} + +SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) +{ + rubyObjectTracker.Untrack(ptr); +} + +SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) +{ + VALUE object = SWIG_RubyInstanceFor(ptr); + + if (object != Qnil) { + DATA_PTR(object) = 0; + } +} + +#ifdef __cplusplus +} +#endif diff --git a/swig/eKeys.i b/swig/eKeys.i new file mode 100644 index 0000000..c530fca --- /dev/null +++ b/swig/eKeys.i @@ -0,0 +1,76 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%module vdr + +%{ +#include <vdr/keys.h> +%} + +enum eKeys +{ + // "Up" and "Down" must be the first two keys! + kUp, + kDown, + kMenu, + kOk, + kBack, + kLeft, + kRight, + kRed, + kGreen, + kYellow, + kBlue, + k0, k1, k2, k3, k4, k5, k6, k7, k8, k9, + kInfo, + kPlay, + kPause, + kStop, + kRecord, + kFastFwd, + kFastRew, + kNext, + kPrev, + kPower, + kChanUp, + kChanDn, + kChanPrev, + kVolUp, + kVolDn, + kMute, + kAudio, + kSubtitles, + kSchedule, + kChannels, + kTimers, + kRecordings, + kSetup, + kCommands, + kUser1, kUser2, kUser3, kUser4, kUser5, kUser6, kUser7, kUser8, kUser9, + kNone, + kKbd, + // The following codes are used internally: + k_Plugin, + k_Setup, + // The following flags are OR'd with the above codes: + k_Repeat = 0x8000, + k_Release = 0x4000, + k_Flags = k_Repeat | k_Release, +}; diff --git a/swig/eOSState.i b/swig/eOSState.i new file mode 100644 index 0000000..02cca5b --- /dev/null +++ b/swig/eOSState.i @@ -0,0 +1,58 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%module vdr + +%{ +#include <vdr/osdbase.h> +%} + +enum eOSState +{ + osUnknown, + osContinue, + osSchedule, + osChannels, + osTimers, + osRecordings, + osPlugin, + osSetup, + osCommands, + osPause, + osRecord, + osReplay, + osStopRecord, + osStopReplay, + osCancelEdit, + osSwitchDvb, + osBack, + osEnd, + os_User, // the following values can be used locally + osUser1, + osUser2, + osUser3, + osUser4, + osUser5, + osUser6, + osUser7, + osUser8, + osUser9, + osUser10, +}; diff --git a/swig/typemaps.i b/swig/typemaps.i new file mode 100644 index 0000000..919ca0c --- /dev/null +++ b/swig/typemaps.i @@ -0,0 +1,30 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%typemap(in, noblock=1) SWIGTYPE* TRANSFER_DELETE_RESPONSIBILITY(void *argp = 0, int res = 0) +{ + res = SWIG_ConvertPtr($input, &argp,$descriptor, $disown | %convertptr_flags); + if (!SWIG_IsOK(res)) + { + %argument_fail(res, "$type", $symname, $argnum); + } + $1 = %reinterpret_cast(argp, $ltype); + rubyObjectTracker.KeepRubyObjectAlive($1); +} diff --git a/swig/vdr.i b/swig/vdr.i new file mode 100644 index 0000000..69d5a7a --- /dev/null +++ b/swig/vdr.i @@ -0,0 +1,39 @@ +/* + * vdr-scripting - A plugin for the Linux Video Disk Recorder + * Copyright (c) 2009 Tobias Grimm <vdr@e-tobi.net> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +%module(directors="1", allprotected="1") "vdr::swig" + +%{ +#include <iostream> +using namespace std; +%} + +%feature("director:except") { + VALUE klass = rb_class_path(CLASS_OF($error)); + VALUE message = rb_obj_as_string($error); + cerr << "vdr-scripting Error: " << RSTRING_PTR(klass) << " - " << RSTRING_PTR(message) << endl; + throw Swig::DirectorMethodException($error); +}; + +%include "PluginManager.i" +%include "cOsdItem.i" +%include "cOsdMenu.i" +%include "cOsdMessage.i" +%include "cMenuText.i" |