- }
- UNHANDLED_EXCEPTION_HANDLER_END
- }
-
- EXPORT_API void wrt_install_all_plugins(
- WrtAllPluginInstalledCallback installed_cb,
- void *user_param)
- {
- UNHANDLED_EXCEPTION_HANDLER_BEGIN
- {
- std::string installRequest =
- std::string(GlobalConfig::GetPluginInstallInitializerName());
-
- LogDebug("Install new plugins");
-
- Try {
- DPL::Semaphore lock(PLUGIN_INSTALL_SEMAPHORE);
- }
- Catch(DPL::Semaphore::Exception::Base){
- LogError("Failed to create installation lock");
- return;
- }
-
- struct stat tmp;
-
- if (-1 == stat(installRequest.c_str(), &tmp) ||
- !S_ISREG(tmp.st_mode))
- {
- if (ENOENT == errno) {
- LogDebug("Plugin installation not required");
-
- LogDebug("Call SetAllinstallPluginCallback");
- installed_cb(user_param);
-
- DPL::Semaphore::Remove(PLUGIN_INSTALL_SEMAPHORE);
- return;
- }
- LogWarning("Opening installation request file failed");
- }
-
- std::string PLUGIN_PATH =
- std::string(GlobalConfig::GetDevicePluginPath());
-
- DIR *dir;
- dir = opendir(PLUGIN_PATH.c_str());
- if (!dir) {
- 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();
-
- FOREACH(it, pluginsPaths) {
- wrt_plugin_data *plugin_data = new wrt_plugin_data;
-
- plugin_data->plugin_installed_cb = installed_cb;
- plugin_data->plugin_path = const_cast<char*>(it->c_str());
- plugin_data->user_data = user_param;
-
- wrt_install_plugin(
- it->c_str(), static_cast<void*>(plugin_data),
- plugin_install_status_cb,
- plugin_install_progress_cb);
- }
-
- if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
- LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
- << DPL::GetErrnoString());
- }
-
- if (0 != unlink(installRequest.c_str())) {
- LogError("Failed to remove file initializing plugin "
- "installation");
- }
-
- Try {
- DPL::Semaphore::Remove(PLUGIN_INSTALL_SEMAPHORE);
- }
- Catch(DPL::Semaphore::Exception::Base){
- LogInfo("Failed to remove installation lock");
- }
- }
- UNHANDLED_EXCEPTION_HANDLER_END