59 #define VICI_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 ~PlugInFactory()
Destructor.
Definition: plugin.h:110
void regn(const PlugInDetails &details)
Allow a plug-in to register itself.
Definition: plugin.cpp:197
std::unique_ptr< AutoRunPlugIn > AutoRunPlugInPtr
Unique pointer to an AutoRunPlugIn.
Definition: plugin.h:100
void initViciPlugin()
Initialise the plugin.
std::unique_ptr< PlugInFamily > getPlugin(csr name)
Get a plug-in.
Definition: plugin.h:294
Mode getMode()
Get the mode for the entire library.
Definition: plugin.h:223
bool onDemand
True if the library is loaded on demand.
Definition: plugin.h:158
virtual F * make()
Construct a plug-in object.
Definition: plugin.h:147
void closeViciPlugin()
Shutdown the plugin.
The library can be removed after initialisation.
Definition: plugin.h:187
Descriptor for plug-ins that can be used by the application.
Definition: plugin.h:151
Base class for plug ins that are run immediately that the library is loaded.
Definition: plugin.h:92
Template base class for families of plug-in factories.
Definition: plugin.h:128
PlugInFactory * factory
Construct an instance of the plug-in.
Definition: plugin.h:165
void shutdown()
Unload all the libraries prior to exiting the program.
Definition: plugin.cpp:249
std::string description
Some description for users.
Definition: plugin.h:155
virtual PlugIn * make()=0
Construct a plug-in object.
static PlugInMgr & instance()
Get a reference to the singleton object.
Definition: plugin.cpp:67
Base class for factories that create plug-in objects.
Definition: plugin.h:106
Base class for objects loaded from dynamically loaded libraries.
Definition: plugin.h:76
bool inUse()
Test if the library is in use.
Definition: plugin.h:241
Manage the handling of plug-in shared libraries.
Definition: plugin.h:254
Manipulate path strings.
Definition: stringy.h:74
virtual ~PlugInFactoryT()
Destructor.
Definition: plugin.h:146
virtual F * make()=0
Construct a plug-in object.
The library can be removed once its unused.
Definition: plugin.h:188
~PlugInLib()
Destructor.
Definition: plugin.cpp:291
Template class for factories.
Definition: plugin.h:142
bool loadable
False if the library cannot be loaded.
Definition: plugin.h:166
Mode
Control lifetime of the library.
Definition: plugin.h:186
void setMode(Mode m)
Set the lifetime for a plug-in.
Definition: plugin.cpp:310
void load(csr prog)
Load the plug-ins listed in the xini config.
Definition: plugin.cpp:123
void startUsage()
Indicate that the library is being used.
Definition: plugin.cpp:356
VICI::Path library
The shared library's path.
Definition: plugin.h:157
const VICI::Path & getPath()
Get the path to the library.
Definition: plugin.h:247
std::string name
The name as in the xini config.
Definition: plugin.h:154
PlugInDetails()
Constructor to initialise variables.
Definition: plugin.cpp:37
virtual void execute()=0
Called by the PlugInMgr to run the plug-in's code.
const std::string & csr
short cut for string constants
Definition: vici.h:80
void release(PlugInLib *)
Release a library.
Definition: plugin.cpp:221
std::shared_ptr< PlugInLib > PlugInLibPtr
Shared pointer to PlugInLib.
Definition: plugin.h:66
Details of plug-ins as provided by the loaded library.
Definition: plugin.h:163
std::string version
Should match the defined VICI_PLUGIN_VERSION.
Definition: plugin.h:156
std::string pluginFamily
The type of the plug-in.
Definition: plugin.h:153
virtual ~PlugIn()
Destructor.
Definition: plugin.cpp:49
void endUsage()
Advise that a plug-in is no longer using the library.
Definition: plugin.cpp:363
The library is only removed on program termination.
Definition: plugin.h:189
bool loaded()
Check if successfully loaded the library.
Definition: plugin.cpp:318
PlugInLib(const Path &libPath)
Constructor.
Definition: plugin.cpp:275
bool autoRun
True if its run automatically on start.
Definition: plugin.h:159
Manages an instance of a dynamically loaded shared library.
Definition: plugin.h:182