summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTobias Grimm <tobias@e-tobi.loc>2009-02-14 23:25:05 +0100
committerTobias Grimm <tobias@e-tobi.loc>2009-02-14 23:25:05 +0100
commit2bae6457006474655f971891a92341b1ae34840e (patch)
tree30a813fdbb1c096a08d7c35dd59fafc3f65154f4 /src
downloadvdr-plugin-scripting-2bae6457006474655f971891a92341b1ae34840e.tar.gz
vdr-plugin-scripting-2bae6457006474655f971891a92341b1ae34840e.tar.bz2
Initial commitv0.0.1branches/v0.0.1
Diffstat (limited to 'src')
-rw-r--r--src/OsdMessage.cc27
-rw-r--r--src/OsdMessage.h30
-rw-r--r--src/PluginManager.cc21
-rw-r--r--src/PluginManager.h33
-rw-r--r--src/RubyObjectTracker.cc112
-rw-r--r--src/RubyObjectTracker.h55
-rw-r--r--src/ScriptingPlugin.cc235
-rw-r--r--src/ScriptingPlugin.h64
-rw-r--r--src/Version.h26
9 files changed, 603 insertions, 0 deletions
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