Ejemplo n.º 1
0
bool PluginThread::initPlugin()
{
    PluginManager* manager = Carbon::get()->getPluginManager();

    //For new plugins, executable denotes the executable plugin, class mainScript the plugin caption and secondary script the plugin type (as integer)
    AbstractPlugin* plugin = manager->findPlugin(getTaskDefinition().getFirst(), getTaskDefinition().getSecond(),
        getTaskDefinition().getThird().compare("") == 0 ? -1 : getTaskDefinition().getThird().toInt());

    if (plugin == 0)
    {
        LOG_ERROR() << "Could not initialize PluginThread because plugin to start with was not found.";
        mPlugin = 0;
        return false;
    }

    if (plugin->getPluginType() == PT_FRAME)
    {
        LOG_ERROR() << "Could not initialize PluginThread because plugin is of type AttachableFrame. AttachableFrame plugins can only be started in the main thread.";
        mPlugin = 0;
        return false;
    }

    if (plugin->getExecutionType() == AbstractPlugin::ET_NEVER)
    {
        LOG_ERROR() << "Could not initialize PluginThread because the plugin is not executable. It has to have an execution type of ONCE, LOOP or ANY.";
        mPlugin = 0;
        return false;
    }

    mPlugin = plugin;

    if (mPlugin->isQObject())
    {
        //Connect to plugin update functions
        connect(mPlugin->getQObject(), SIGNAL(paused()), this, SLOT(pluginPaused()));
        connect(mPlugin->getQObject(), SIGNAL(running()), this, SLOT(pluginRunning()));
        connect(mPlugin->getQObject(), SIGNAL(finished()), this, SLOT(pluginFinished()));
    }

    return true;
}