PluginManager.cc
3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* -*- Base: 10 ; Mode: C++ -*- */
/*------------------------------------------------------------------------
**
FOST project
**
--------------------------------------------------------------------------
--------------------------------------------------------------------------
FILE LOG
$Revision: 1.3 $ $Date: 2012-06-15 13:04:40 $
--------------------------------------------------------------------------
CREATION
F.CASIMIR
SUMMARY
DESCRIPTION
The main function performs the following actions :
<ul>
<li>
</ul>
------------------------------------------------------------------------*/
//=============================================================================
//
// History of code
//
// creation
//
// modification
//=============================================================================
/**
*/
//=============================================================================
// Include section
//=============================================================================
// Standard libraries include files
//-----------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include <libgen.h>
#include <regex.h>
#include <sys/stat.h>
#include <cerrno>
#include <iostream>
#include <sstream>
#include <vector>
#include "log4cxx/logger.h"
#include "Helper.hh"
// Module Kernel include files
//-----------------------------------------------------------------------------
#include <PluginManager.hh>
namespace AMDA {
namespace Plugins {
log4cxx::LoggerPtr gLogger = log4cxx::Logger::getLogger("AMDA-Kernel.Plugins");
//=============================================================================
// Methods of Class PluginManager
//=============================================================================
//=============================================================================
// Other Methods
void PluginManager::registerPlugin( const std::string &pluginName, const std::string &pluginPath)
{
try {
LOG4CXX_DEBUG(gLogger, "PluginManager::registerPlugin :: attempt to load: " << pluginPath << pluginName );
Plugin plugin( pluginPath+"/"+pluginName);
_loadedPlugins.insert(PluginMap::value_type( pluginName, plugin)).first->second.registerPlugin(*this);
//PluginWatcher::getInstance()->addPluginToWatch(pluginPath);
LOG4CXX_INFO(gLogger, "PluginManager::loadPlugin :: " << pluginName << " plugin load successfully" );
}
catch( AMDA::AMDA_exception & e ) {
LOG4CXX_WARN(gLogger, "PluginManager::registerPlugin exception resume: " << boost::diagnostic_information(e));
} catch( ...) {
LOG4CXX_WARN(gLogger, "Problem in loadPlugin " << pluginPath);
}
}
/**
*/
void PluginManager::loadPlugin(const std::string &sPluginName)
{
if(_loadedPlugins.find(sPluginName) == _loadedPlugins.end())
{
registerPlugin( sPluginName+".so", std::string(getenv(sPluginName.c_str()))+"/lib/");
}
}
void PluginManager::loadPlugin(const std::string &path, const std::string &sPluginName)
{
int soPos = sPluginName.find(".so");
if ( soPos > 1 )
{
registerPlugin( sPluginName, path);
}
}
void PluginManager::loadPluginFromPath(const std::string& pluginPath) {
if ( ! pluginPath.empty()) {
const char *myDir = pluginPath.c_str();
struct stat myStat;
if ((stat(myDir, &myStat) == 0) && (((myStat.st_mode) & S_IFMT) == S_IFDIR)) {
// myDir exists and is a directory.
std::vector<std::string> files = std::vector<std::string>();
AMDA::Helpers::Helper::getMatchFiles(pluginPath.c_str(), files, ".*.so$");
for (unsigned int i = 0; i < files.size(); i++) {
loadPlugin(std::string(pluginPath), files[i]);
}
files.clear();
}
}
}
} // namespace Plugins
} // namespace AMDA