00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsbase/mmsosdpluginhandler.h"
00034
00035 MMSOSDPluginHandler::MMSOSDPluginHandler(MMSPluginData plugindata, bool autoload, IMMSOSDPlugin *_plugin) :
00036 loaded(false),
00037 initialized(false),
00038 plugindata(plugindata),
00039 plugin(_plugin),
00040 handler(NULL),
00041 switcher(NULL) {
00042 if(plugin)
00043 this->loaded = true;
00044 else if(autoload)
00045 this->load();
00046 }
00047
00048 MMSOSDPluginHandler::~MMSOSDPluginHandler() {
00049 if (this->loaded) {
00050 delete this->plugin;
00051 if(this->handler) delete this->handler;
00052 }
00053 }
00054
00055 void MMSOSDPluginHandler::invokeInitialize(void *data) {
00056 if (!this->loaded)
00057 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00058 if (this->initialized)
00059 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is already initialized");
00060
00061 this->calllock.lock();
00062 this->initialized = this->plugin->initialize(this->plugindata, this->switcher);
00063 this->calllock.unlock();
00064 }
00065
00066 void MMSOSDPluginHandler::invokeOnEvent(IMMSEvent event) {
00067 if (!this->loaded)
00068 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00069 if (!this->initialized)
00070 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not initialized");
00071
00072 this->calllock.lock();
00073 this->plugin->onEvent(event);
00074 this->calllock.unlock();
00075 }
00076
00077 void MMSOSDPluginHandler::invokeShutdown(void *data) {
00078 if (!this->loaded)
00079 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00080 if (!this->initialized)
00081 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not initialized");
00082
00083 this->calllock.lock();
00084 this->plugin->shutdown();
00085 this->calllock.unlock();
00086 }
00087
00088 void MMSOSDPluginHandler::invokeShowPreview(void *data) {
00089 if (!this->loaded)
00090 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00091 if (!this->initialized)
00092 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not initialized");
00093
00094 this->calllock.lock();
00095 if (!this->plugin->showPreview(data)) {
00096 this->calllock.unlock();
00097 throw MMSOSDPluginError(1,"OSD Plugin " + this->plugindata.getName() + " has nothing to display (showPreview())");
00098 }
00099 this->calllock.unlock();
00100 }
00101
00102 void MMSOSDPluginHandler::invokeShow(void *data) {
00103 if (!this->loaded)
00104 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00105 if (!this->initialized)
00106 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not initialized");
00107
00108 this->calllock.lock();
00109 if (!this->plugin->show(data)) {
00110 this->calllock.unlock();
00111 throw MMSOSDPluginError(1,"OSD Plugin " + this->plugindata.getName() + " has nothing to display (show())");
00112 }
00113 this->calllock.unlock();
00114 }
00115
00116 bool MMSOSDPluginHandler::isLoaded() {
00117 return this->loaded;
00118 }
00119
00120 bool MMSOSDPluginHandler::isInitialized() {
00121 return this->initialized;
00122 }
00123
00124 void MMSOSDPluginHandler::load() {
00125 if (this->loaded)
00126 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is already loaded");
00127
00128 this->handler = new MMSShlHandler(this->plugindata.getFilename());
00129 this->handler->open();
00130 NEWOSDPLUGIN_PROC newproc = (NEWOSDPLUGIN_PROC)this->handler->getFunction("newOSDPlugin");
00131 this->plugin = newproc();
00132
00133 if (this->plugin)
00134 this->loaded = true;
00135 }
00136
00137 void MMSOSDPluginHandler::unload() {
00138 if (!this->loaded)
00139 throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00140
00141 if(this->plugin) {
00142 delete this->plugin;
00143 this->plugin = NULL;
00144 }
00145
00146 if(this->handler) {
00147 delete this->handler;
00148 this->handler = NULL;
00149 }
00150
00151 this->loaded = false;
00152 this->initialized = false;
00153 }
00154
00155 void MMSOSDPluginHandler::setPluginData(MMSPluginData plugindata) {
00156 this->plugindata = plugindata;
00157 }
00158
00159 MMSPluginData MMSOSDPluginHandler::getPluginData() {
00160 return this->plugindata;
00161 }
00162
00163 void MMSOSDPluginHandler::setSwitcherInterface(IMMSSwitcher *switcher) {
00164 this->switcher = switcher;
00165 }