2011-03-02 14:42:56 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: Firebird interface.
|
|
|
|
* MODULE: ImplementHelper.h
|
2011-05-19 18:24:46 +02:00
|
|
|
* DESCRIPTION: Tools to help access plugins.
|
2011-03-02 14:42:56 +01:00
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Alex Peshkov
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010 Alex Peshkov <peshkoff at mail.ru>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FB_COMMON_CLASSES_GET_PLUGINS
|
|
|
|
#define FB_COMMON_CLASSES_GET_PLUGINS
|
|
|
|
|
|
|
|
#include "../common/classes/ImplementHelper.h"
|
|
|
|
#include "../common/config/config.h"
|
|
|
|
|
|
|
|
namespace Firebird {
|
|
|
|
|
|
|
|
// Template to help with loop in the set of plugins
|
2011-06-10 14:53:51 +02:00
|
|
|
template <typename P>
|
2011-03-02 14:42:56 +01:00
|
|
|
class GetPlugins
|
|
|
|
{
|
|
|
|
public:
|
2011-06-10 14:53:51 +02:00
|
|
|
GetPlugins(unsigned int interfaceType, unsigned int desiredVersion,
|
|
|
|
UpgradeInfo* ui, const char* namesList = NULL)
|
|
|
|
: masterInterface(), pluginInterface(masterInterface),
|
2011-06-15 02:47:19 +02:00
|
|
|
pluginSet(pluginInterface->getPlugins(interfaceType,
|
|
|
|
namesList ? namesList : Config::getPlugins(interfaceType),
|
|
|
|
desiredVersion, ui, NULL)),
|
2011-03-02 14:42:56 +01:00
|
|
|
currentPlugin(NULL)
|
|
|
|
{
|
2011-03-31 15:44:22 +02:00
|
|
|
pluginSet->release();
|
2011-03-02 14:42:56 +01:00
|
|
|
getPlugin();
|
|
|
|
}
|
|
|
|
|
2011-06-10 14:53:51 +02:00
|
|
|
GetPlugins(unsigned int interfaceType, unsigned int desiredVersion, UpgradeInfo* ui,
|
2011-03-02 14:42:56 +01:00
|
|
|
Config* knownConfig, const char* namesList = NULL)
|
2011-06-10 14:53:51 +02:00
|
|
|
: masterInterface(), pluginInterface(masterInterface),
|
2011-06-15 02:47:19 +02:00
|
|
|
pluginSet(pluginInterface->getPlugins(interfaceType,
|
|
|
|
namesList ? namesList : Config::getPlugins(interfaceType),
|
|
|
|
desiredVersion, ui, new FirebirdConf(knownConfig))),
|
2011-03-02 14:42:56 +01:00
|
|
|
currentPlugin(NULL)
|
|
|
|
{
|
2011-03-31 15:44:22 +02:00
|
|
|
pluginSet->release();
|
2011-03-02 14:42:56 +01:00
|
|
|
getPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasData()
|
|
|
|
{
|
|
|
|
return currentPlugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name()
|
|
|
|
{
|
2011-04-11 13:12:21 +02:00
|
|
|
return hasData() ? pluginSet->getName() : NULL;
|
2011-03-02 14:42:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* module()
|
|
|
|
{
|
2011-04-11 13:12:21 +02:00
|
|
|
return hasData() ? pluginSet->getModule() : NULL;
|
2011-03-02 14:42:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
P* plugin()
|
|
|
|
{
|
|
|
|
return currentPlugin;
|
|
|
|
}
|
|
|
|
|
|
|
|
void next()
|
|
|
|
{
|
|
|
|
if (hasData())
|
|
|
|
{
|
|
|
|
pluginInterface->releasePlugin(currentPlugin);
|
|
|
|
currentPlugin = NULL;
|
|
|
|
pluginSet->next();
|
|
|
|
getPlugin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void set(const char* newName)
|
|
|
|
{
|
|
|
|
if (hasData())
|
|
|
|
{
|
|
|
|
pluginInterface->releasePlugin(currentPlugin);
|
|
|
|
currentPlugin = NULL;
|
|
|
|
}
|
|
|
|
pluginSet->set(newName);
|
|
|
|
getPlugin();
|
|
|
|
}
|
|
|
|
|
|
|
|
~GetPlugins()
|
|
|
|
{
|
|
|
|
if (hasData())
|
|
|
|
{
|
|
|
|
pluginInterface->releasePlugin(currentPlugin);
|
|
|
|
currentPlugin = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-05-19 18:24:46 +02:00
|
|
|
MasterInterfacePtr masterInterface;
|
|
|
|
PluginManagerInterfacePtr pluginInterface;
|
2011-03-31 15:44:22 +02:00
|
|
|
RefPtr<IPluginSet> pluginSet;
|
2011-03-02 14:42:56 +01:00
|
|
|
P* currentPlugin;
|
|
|
|
|
|
|
|
void getPlugin()
|
|
|
|
{
|
2011-04-11 13:12:21 +02:00
|
|
|
currentPlugin = (P*) pluginSet->getPlugin();
|
2011-03-02 14:42:56 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Firebird
|
|
|
|
|
|
|
|
|
|
|
|
#endif // FB_COMMON_CLASSES_GET_PLUGINS
|