#include <dpl/exception.h>
#include <dpl/log/log.h>
#include <dpl/wrt-dao-ro/global_config.h>
+#include <sys/stat.h>
+#include <dirent.h>
using namespace WrtDB;
return true;
}
+
+PluginPathListPtr getPluginPaths()
+{
+ PluginPathListPtr pluginsPaths;
+ std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
+ LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
+
+ DIR *dir;
+ dir = opendir(PLUGIN_PATH.c_str());
+ if (dir) {
+ struct dirent* libdir;
+
+ errno = 0;
+
+ pluginsPaths.reset(new PluginPathList());
+ while ((libdir = readdir(dir)) != 0) {
+ if (strcmp(libdir->d_name, ".") == 0 ||
+ strcmp(libdir->d_name, "..") == 0) {
+ continue;
+ }
+
+ std::string path = PLUGIN_PATH;
+ path += "/";
+ path += libdir->d_name;
+
+ struct stat tmp;
+
+ if (stat(path.c_str(), &tmp) == -1) {
+ LogError("Failed to open file" << path);
+ continue;
+ }
+
+ if (!S_ISDIR(tmp.st_mode)) {
+ LogError("Not a directory" << path);
+ continue;
+ }
+
+ pluginsPaths->push_back(path);
+ }
+ if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
+ LogError("Failed to close dir: " << dir);
+ }
+ }
+ return pluginsPaths;
+}
} //namespace PluginUtils
#define PLUGIN_UTILS_H
#include <string>
-#include <sys/stat.h>
+#include <list>
+#include <memory>
namespace PluginUtils {
struct FileState
};
};
+typedef std::list<std::string> PluginPathList;
+typedef std::shared_ptr<PluginPathList> PluginPathListPtr;
+
bool lockPluginInstallation();
bool unlockPluginInstallation();
bool checkPluginInstallationRequired();
bool removeInstallationRequiredFlag();
FileState::Type checkFile(const std::string& filename);
bool removeFile(const std::string& filename);
+PluginPathListPtr getPluginPaths();
}
#endif // PLUGIN_UTILS_H
*/
#include "wrt_installer.h"
-#include "plugin_utils.h"
#include <cstdlib>
#include <string>
PluginInstallerData* privateData = new PluginInstallerData;
privateData->wrtInstaller = this;
- if (!(*m_pluginsPaths).empty()) {
- privateData->pluginPath = (*m_pluginsPaths).front();
- (*m_pluginsPaths).pop_front();
+ if (m_pluginsPaths) {
+ privateData->pluginPath = m_pluginsPaths->front();
+ m_pluginsPaths->pop_front();
wrt_install_plugin(privateData->pluginPath.c_str(),
static_cast<void*>(privateData),
return;
}
- std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
-
- DIR *dir;
- dir = opendir(PLUGIN_PATH.c_str());
-
- if (!dir) {
+ PluginUtils::PluginPathListPtr pluginPaths = PluginUtils::getPluginPaths();
+ if (!pluginPaths) {
return;
}
- LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
- struct dirent* libdir;
-
- errno = 0;
-
- std::list<std::string> pluginsPaths;
-
- while ((libdir = readdir(dir)) != 0) {
- if (strcmp(libdir->d_name, ".") == 0 ||
- strcmp(libdir->d_name, "..") == 0)
- {
- continue;
- }
-
- std::string path = PLUGIN_PATH;
- path += "/";
- path += libdir->d_name;
-
- struct stat tmp;
-
- if (stat(path.c_str(), &tmp) == -1) {
- LogError("Failed to open file" << path);
- continue;
- }
-
- if (!S_ISDIR(tmp.st_mode)) {
- LogError("Not a directory" << path);
- continue;
- }
-
- pluginsPaths.push_back(path);
- }
-
//set nb of plugins to install
//this value indicate how many callbacks are expected
- m_numPluginsToInstall = pluginsPaths.size();
+ m_numPluginsToInstall = pluginPaths->size();
LogInfo("Plugins to install: " << m_numPluginsToInstall);
- m_pluginsPaths = pluginsPaths;
+ m_pluginsPaths = pluginPaths;
m_totalPlugins = m_numPluginsToInstall;
DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
::PostEvent(WRTInstallerNS::InstallPluginEvent());
-
- if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
- LogError("Failed to close dir: " << dir);
- }
}
//void WrtInstaller::uninstallStep()
#include <string>
//#include <utilX.h>
#include <wrt_installer_api.h>
+#include "plugin_utils.h"
//#include <pkgmgr_installer.h>
namespace WRTInstallerNS { //anonymous
std::string m_webAppIcon;
typedef std::list<std::string> PluginPathList;
- DPL::Optional<PluginPathList> m_pluginsPaths;
+ PluginUtils::PluginPathListPtr m_pluginsPaths;
};
#endif // WRT_CLIENT_H
#include <dpl/wrt-dao-ro/WrtDatabase.h>
#include <vcore/VCore.h>
#include <installer_main_thread.h>
+#include "plugin_utils.h"
using namespace WrtDB;
LogWarning("Opening installation request file failed");
}
- std::string PLUGIN_PATH =
- std::string(GlobalConfig::GetDevicePluginPath());
-
- DIR *dir;
- dir = opendir(PLUGIN_PATH.c_str());
- if (!dir) {
+ PluginUtils::PluginPathListPtr pluginPaths =
+ PluginUtils::getPluginPaths();
+ if (!pluginPaths) {
DPL::Semaphore::Remove(PLUGIN_INSTALL_SEMAPHORE);
return;
}
- LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
- struct dirent* libdir;
-
- errno = 0;
-
- std::list<std::string> pluginsPaths;
-
- while ((libdir = readdir(dir)) != 0) {
- if (strcmp(libdir->d_name, ".") == 0 ||
- strcmp(libdir->d_name, "..") == 0)
- {
- continue;
- }
-
- std::string path = PLUGIN_PATH;
- path += "/";
- path += libdir->d_name;
-
- struct stat tmp;
-
- if (stat(path.c_str(), &tmp) == -1) {
- LogError("Failed to open file" << path);
- continue;
- }
-
- if (!S_ISDIR(tmp.st_mode)) {
- LogError("Not a directory" << path);
- continue;
- }
-
- pluginsPaths.push_back(path);
- }
-
- wrt_count_plugin = pluginsPaths.size();
+ wrt_count_plugin = pluginPaths->size();
- FOREACH(it, pluginsPaths) {
+ for (auto it = pluginPaths->begin(); it != pluginPaths->end(); ++it) {
wrt_plugin_data *plugin_data = new wrt_plugin_data;
plugin_data->plugin_installed_cb = installed_cb;
plugin_install_progress_cb);
}
- if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
- LogError("Failed to close dir: " << PLUGIN_PATH);
- }
-
if (0 != unlink(installRequest.c_str())) {
LogError("Failed to remove file initializing plugin "
"installation");