const int PluginsInstaller::INSTALLATION_ERROR = -1;
-PluginsInstaller::PluginsInstaller()
- : m_initialized(false)
+PluginsInstaller::PluginsInstaller() :
+ m_initialized(false)
{
LogInfo("PluginsInstaller created.");
}
}
PluginsInstaller::ReturnStatus PluginsInstaller::installPlugin(
- const std::string& libPath)
+ const std::string& libPath)
{
if (!m_initialized) {
LogError("Plugins installer not initialized.");
}
LogInfo("Plugin installation started. Checking path: " << libPath);
- if (!PluginUtils::checkPath(libPath))
+ if (!PluginUtils::checkPath(libPath)) {
return ReturnStatus::WrongPluginPath;
+ }
LogInfo("Plugin path ok. Searching for config file...");
std::string metaFileName = libPath + DIRECTORY_SEPARATOR +
std::string(WrtDB::GlobalConfig::GetPluginMetafileName());
- if (PluginUtils::checkFileExistance(metaFileName))
- {
+ if (PluginUtils::checkFileExistance(metaFileName)) {
return installPluginFromMetafile(libPath, metaFileName);
}
PluginMetafileData pluginInfo;
pluginInfo.m_libraryName = getLibraryName(libPath);
- LogInfo("Config file done. Lib name: " << pluginInfo.m_libraryName
- << ". Searching for installed plugin...");
+ LogInfo(
+ "Config file done. Lib name: " << pluginInfo.m_libraryName
+ <<
+ ". Searching for installed plugin...");
if (WrtDB::PluginDAO::isPluginInstalled(pluginInfo.m_libraryName)) {
LogInfo("Plugin already installed.");
FOREACH(o, *plugin->GetObjects()) {
libraryObjects->addObjects(CAST(*o)->GetParentName(),
- CAST(*o)->GetName());
+ CAST(*o)->GetName());
LogDebug("[Parent << Object] " << CAST(*o)->GetParentName()
- << " << "
- << CAST(*o)->GetName());
+ << " << "
+ << CAST(*o)->GetName());
registerObjects(libraryObjects, plugin->GetObjects());
}
LogInfo("Registration done. Resolving dependencies...");
//TODO: can it be replaced with resolvePluginDependencies(handle)
- if (!registerAndUpdateInstallation(pluginHandle, libraryObjects))
+ if (!registerAndUpdateInstallation(pluginHandle, libraryObjects)) {
return ReturnStatus::InstallationWaiting;
- } Catch (DPL::Exception) {
+ }
+ } Catch(DPL::Exception) {
LogError("Failed to make database entry.");
return ReturnStatus::DatabaseError;
}
}
PluginObjectsPtr PluginsInstaller::loadLibraryFromMetafile(
- const std::string& libName) const
+ const std::string& libName) const
{
LogInfo("Loading library: " << libName);
void *dlHandle = dlopen(libName.c_str(), RTLD_NOW);
- if (dlHandle == NULL ) {
+ if (dlHandle == NULL) {
LogError(
- "Failed to load plugin: " << libName <<
- ". Reason: " << dlerror());
+ "Failed to load plugin: " << libName <<
+ ". Reason: " << dlerror());
ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
}
getWidgetEntityMapProcPtr =
reinterpret_cast<get_widget_entity_map_proc *>(dlsym(dlHandle,
- PLUGIN_GET_CLASS_MAP_PROC_NAME));
+ PLUGIN_GET_CLASS_MAP_PROC_NAME));
if (getWidgetEntityMapProcPtr) {
rawEntityList = (*getWidgetEntityMapProcPtr)();
} else {
rawEntityList =
static_cast<const js_entity_definition_t *>(dlsym(dlHandle,
- PLUGIN_CLASS_MAP_NAME));
+ PLUGIN_CLASS_MAP_NAME));
}
if (rawEntityList == NULL) {
LogInfo("#####");
while (rawEntityListIterator->parent_name != NULL &&
- rawEntityListIterator->object_name != NULL)
+ rawEntityListIterator->object_name != NULL)
{
LogInfo("##### [" << rawEntityListIterator->object_name << "]: ");
LogInfo("##### Parent: " << rawEntityListIterator->parent_name);
LogInfo("#####");
libraryObjects->addObjects(rawEntityListIterator->parent_name,
- rawEntityListIterator->object_name);
+ rawEntityListIterator->object_name);
++rawEntityListIterator;
}
return libraryObjects;
}
-
PluginsInstaller::ReturnStatus PluginsInstaller::installPluginFromMetafile(
- const std::string& path, const std::string& metaFilePath)
+ const std::string& path, const std::string& metaFilePath)
{
if (!m_initialized) {
LogError("Plugins installer not initialized.");
{
pluginData = parseMetafile(metaFilePath);
}
- Catch (PluginInstall::Exceptions::XMLFileParsingException)
+ Catch(PluginInstall::Exceptions::XMLFileParsingException)
{
LogError("Parsing metafile failed.");
return ReturnStatus::MetafileError;
return ReturnStatus::AlreadyInstalled;
}
Try {
-
- LogError("path is: " << path << ", libraryName: " << pluginData->m_libraryName);
+ LogError(
+ "path is: " << path << ", libraryName: " <<
+ pluginData->m_libraryName);
PluginObjectsPtr objects = loadLibraryFromMetafile(
- path + DIRECTORY_SEPARATOR + pluginData->m_libraryName);
+ path + DIRECTORY_SEPARATOR + pluginData->m_libraryName);
PluginHandle pluginHandle =
PluginDAO::registerPlugin(*pluginData, path);
LogInfo("Objects registered. Finishing...");
- if (!registerAndUpdateInstallation(pluginHandle, objects))
+ if (!registerAndUpdateInstallation(pluginHandle, objects)) {
return ReturnStatus::InstallationWaiting;
- } Catch (DPL::Exception) {
+ }
+ } Catch(DPL::Exception) {
LogError("Failed to make database entry.");
return ReturnStatus::DatabaseError;
}
}
LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
- struct dirent* libdir;
+ int return_code;
+ struct dirent libdir;
+ struct dirent* result;
errno = 0;
std::list<std::string> pluginsPaths;
- while ((libdir = readdir(dir)) != 0) {
- if (strcmp(libdir->d_name, ".") == 0 ||
- strcmp(libdir->d_name, "..") == 0) {
+ for (return_code = readdir_r(dir, &libdir, &result);
+ result != NULL && return_code == 0;
+ return_code = readdir_r(dir, &libdir, &result)) {
+ if (strcmp(libdir.d_name, ".") == 0 ||
+ strcmp(libdir.d_name, "..") == 0)
+ {
continue;
}
std::string path = PLUGIN_PATH;
path += "/";
- path += libdir->d_name;
+ path += libdir.d_name;
struct stat tmp;
pluginsPaths.push_back(path);
}
+ if (0 != return_code)
+ LogError("Error while reading directory.");
+
if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
LogError("Failed to close dir: " << PLUGIN_PATH);
}
LogDebug("Plugins to install: " << pluginsPaths.size());
- for (int k = 0; k <= pluginsPaths.size(); ++k)
+ for (size_t k = 0; k <= pluginsPaths.size(); ++k) {
printf(" ");
+ }
printf("]\r[");
int installedPluginsCount = 0;
ReturnStatus ret = ReturnStatus::Unknown;
installedPluginsCount += installWaitingPlugins();
m_registry.UnloadAll();
LogInfo("Installed " << installedPluginsCount
- << " plugins of total: " << pluginsPaths.size());
+ << " plugins of total: " << pluginsPaths.size());
return installedPluginsCount;
}
int pluginsInstalled = 0;
FOREACH(it, *waitingPlugins)
{
- if (resolvePluginDependencies(*it))
+ if (resolvePluginDependencies(*it)) {
++pluginsInstalled;
+ }
}
return pluginsInstalled;
}
void PluginsInstaller::registerObjects(const PluginObjectsPtr& libObj,
const IObjectsListPtr& objects) const
{
- LogDebug("registerObjects invoked");
-
- FOREACH(o, *objects)
- {
- auto children = CAST(*o)->GetChildren();
-
- if(children)
- {
- FOREACH(c, *children)
- {
- libObj->addObjects(CAST(*o)->GetName(), CAST(*c)->GetName());
-
- LogDebug("[Parent << Object] " << CAST(*c)->GetName()
- << " << "
- << CAST(*o)->GetName());
- }
-
- registerObjects(libObj, children);
- }
- }
-}
+ LogDebug("registerObjects invoked");
+ FOREACH(o, *objects)
+ {
+ auto children = CAST(*o)->GetChildren();
+
+ if (children) {
+ FOREACH(c, *children)
+ {
+ libObj->addObjects(CAST(*o)->GetName(), CAST(*c)->GetName());
+
+ LogDebug("[Parent << Object] " << CAST(*c)->GetName()
+ << " << "
+ << CAST(*o)->GetName());
+ }
+
+ registerObjects(libObj, children);
+ }
+ }
+}
PluginsInstaller::OptionalPluginMetafileData PluginsInstaller::parseMetafile(
- const std::string& path) const
+ const std::string& path) const
{
LogInfo("Plugin Config file::" << path);
Try
Catch(ValidationCore::ParserSchemaException::Base) {
LogError("Error during file processing " << path);
ThrowMsg(PluginInstall::Exceptions::XMLFileParsingException,
- "Parsing metafile failed");
+ "Parsing metafile failed");
}
}
std::string pluginPath = dirPath;
size_t indexpos = pluginPath.find_last_of('/');
- if (std::string::npos == indexpos)
- {
+ if (std::string::npos == indexpos) {
indexpos = 0;
- }
- else
- {
+ } else {
indexpos += 1; // move after '/'
}
}
bool PluginsInstaller::registerAndUpdateInstallation(
- const WrtDB::DbPluginHandle& pluginHandle,
- const PluginObjectsPtr& libraries)
+ const WrtDB::DbPluginHandle& pluginHandle,
+ const PluginObjectsPtr& libraries)
{
PluginHandleSetPtr handles = PluginHandleSetPtr(new PluginHandleSet);
{
void *dlHandle = dlopen(filename.c_str(), RTLD_NOW);
if (dlHandle == NULL) {
- LogError("Failed to load plugin: " << filename << ". Reason: " << dlerror());
+ LogError(
+ "Failed to load plugin: " << filename << ". Reason: " << dlerror());
return false;
}
Try
{
ExportedApi* entryPoint =
- static_cast<ExportedApi*> (dlsym(dlHandle, GetExportedSymbolName()));
+ static_cast<ExportedApi*>(dlsym(dlHandle, GetExportedSymbolName()));
if (NULL == entryPoint) {
LogError("Error: " << dlerror());
- ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+ ThrowMsg(PluginInstall::Exceptions::LibraryException,
+ "Library error");
}
// obtain feature -> dev-cap mapping
- feature_mapping_interface_t mappingInterface = {NULL, NULL, NULL};
+ feature_mapping_interface_t mappingInterface = { NULL, NULL, NULL };
entryPoint->GetProvidedFeatures(&mappingInterface);
if (!mappingInterface.featGetter || !mappingInterface.release ||
- !mappingInterface.dcGetter) {
+ !mappingInterface.dcGetter)
+ {
LogError("Failed to obtain mapping interface from .so");
- ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+ ThrowMsg(PluginInstall::Exceptions::LibraryException,
+ "Library error");
}
feature_mapping_t* devcapMapping = mappingInterface.featGetter();
LogDebug("Feature: " << feature.m_name);
const devcaps_t* dc =
- mappingInterface.dcGetter(devcapMapping,
- devcapMapping->features[i].feature_name);
+ mappingInterface.dcGetter(
+ devcapMapping,
+ devcapMapping->features[i].
+ feature_name);
LogDebug("device=cap: " << dc);
}
mappingInterface.release(devcapMapping);
- } Catch (PluginInstall::Exceptions::PluginsInstallerException)
+ } Catch(PluginInstall::Exceptions::PluginsInstallerException)
{
LogError("Exception while feature mapping");
dlclose(dlHandle);
return true;
}
-void PluginsInstaller::registerPluginObjects(const WrtDB::DbPluginHandle& handle,
- const PluginObjectsPtr libObjects) const
+void PluginsInstaller::registerPluginObjects(
+ const WrtDB::DbPluginHandle& handle,
+ const PluginObjectsPtr libObjects)
+const
{
- //register implemented objects
+ //register implemented objects
PluginObjects::ObjectsPtr objects =
libObjects->getImplementedObject();