59 #define SASSY_PLUGIN_VERSION "0.1"
131 virtual F *
make() = 0;
141 template <
class F,
class P >
147 virtual F *
make() {
return new P; }
241 bool inUse() {
return usageCounter > 0; }
258 std::map< std::string, PlugInDetails > plugins;
263 std::map< Path, std::shared_ptr< PlugInLib > > libs;
266 std::list< PlugInLib * > pending;
269 void getDetails(
csr);
284 void getDetails( std::vector< PlugInDescriptor > & plugins );
293 template <
class PlugInFamily >
297 auto P = plugins.find( name );
298 if ( P == plugins.end() )
return nullptr;
299 if ( ! P->second.loadable )
return nullptr;
302 auto L = libs.find(P->second.library);
303 if ( L == libs.end() || ! L->second->loaded())
310 if ( ! loadLibrary( P->second.library, mode ) )
312 P->second.loadable =
false;
316 L = libs.find(P->second.library);
323 if ( pif == 0)
return nullptr;
327 std::unique_ptr<PlugInFamily> up(pif->
make() );
328 up->setLib(L->second);
virtual ~PlugIn()
Destructor.
Definition: plugin.cpp:49
virtual F * make()=0
Construct a plug-in object.
virtual PlugIn * make()=0
Construct a plug-in object.
Mode
Control lifetime of the library.
Definition: plugin.h:186
void initSassyPlugin()
Initialise the plugin.
~PlugInLib()
Destructor.
Definition: plugin.cpp:289
Manage the handling of plug-in shared libraries.
Definition: plugin.h:254
void shutdown()
Unload all the libraries prior to exiting the program.
Definition: plugin.cpp:247
Mode getMode()
Get the mode for the entire library.
Definition: plugin.h:223
void release(PlugInLib *)
Release a library.
Definition: plugin.cpp:219
Details of plug-ins as provided by the loaded library.
Definition: plugin.h:163
The library can be removed after initialisation.
Definition: plugin.h:187
std::string pluginFamily
The type of the plug-in.
Definition: plugin.h:153
Base class for factories that create plug-in objects.
Definition: plugin.h:106
Manipulate path strings.
Definition: stringy.h:67
PlugInDetails()
Constructor to initialise variables.
Definition: plugin.cpp:37
const SASSY::Path & getPath()
Get the path to the library.
Definition: plugin.h:247
bool onDemand
True if the library is loaded on demand.
Definition: plugin.h:158
void load(csr prog)
Load the plug-ins listed in the xini config.
Definition: plugin.cpp:121
Template base class for families of plug-in factories.
Definition: plugin.h:128
void setMode(Mode m)
Set the lifetime for a plug-in.
Definition: plugin.cpp:308
std::string description
Some description for users.
Definition: plugin.h:155
bool loadable
False if the library cannot be loaded.
Definition: plugin.h:166
PlugInLib(const Path &libPath)
Constructor.
Definition: plugin.cpp:273
Base class for plug ins that are run immediately that the library is loaded.
Definition: plugin.h:92
std::shared_ptr< PlugInLib > PlugInLibPtr
Shared pointer to PlugInLib.
Definition: plugin.h:66
SASSY::Path library
The shared library's path.
Definition: plugin.h:157
static PlugInMgr & instance()
Get a reference to the singleton object.
Definition: plugin.cpp:65
Template class for factories.
Definition: plugin.h:142
void startUsage()
Indicate that the library is being used.
Definition: plugin.cpp:354
Manages an instance of a dynamically loaded shared library.
Definition: plugin.h:182
std::string version
Should match the defined SASSY_PLUGIN_VERSION.
Definition: plugin.h:156
virtual ~PlugInFactoryT()
Destructor.
Definition: plugin.h:146
void closeSassyPlugin()
Shutdown the plugin.
PlugInFactory * factory
Construct an instance of the plug-in.
Definition: plugin.h:165
bool loaded()
Check if successfully loaded the library.
Definition: plugin.cpp:316
bool autoRun
True if its run automatically on start.
Definition: plugin.h:159
const std::string & csr
Save some time typing and shorten parameter lines.
Definition: stringy.h:35
void regn(const PlugInDetails &details)
Allow a plug-in to register itself.
Definition: plugin.cpp:195
std::unique_ptr< PlugInFamily > getPlugin(csr name)
Get a plug-in.
Definition: plugin.h:294
virtual ~PlugInFactory()
Destructor.
Definition: plugin.h:110
std::string name
The name as in the xini config.
Definition: plugin.h:154
virtual F * make()
Construct a plug-in object.
Definition: plugin.h:147
The library can be removed once its unused.
Definition: plugin.h:188
Base class for objects loaded from dynamically loaded libraries.
Definition: plugin.h:76
void endUsage()
Advise that a plug-in is no longer using the library.
Definition: plugin.cpp:361
Descriptor for plug-ins that can be used by the application.
Definition: plugin.h:151
The library is only removed on program termination.
Definition: plugin.h:189
std::unique_ptr< AutoRunPlugIn > AutoRunPlugInPtr
Unique pointer to an AutoRunPlugIn.
Definition: plugin.h:100
bool inUse()
Test if the library is in use.
Definition: plugin.h:241
virtual void execute()=0
Called by the PlugInMgr to run the plug-in's code.