+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* @file wrt_installer.cpp
+ * @version 1.0
+ * @brief Implementation file for installer
+ */
+
+#include "wrt_installer.h"
+#include "plugin_utils.h"
+
+#include <cstdlib>
+#include <string>
+#include <fstream>
+#include <unistd.h>
+#include <sys/resource.h>
+#include <dpl/optional.h>
+#include <dpl/scoped_free.h>
+#include <dpl/optional_typedefs.h>
+#include <dpl/exception.h>
+#include <dpl/sstream.h>
+#include <vconf.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-ro/config_parser_data.h>
+#include <dpl/localization/localization_utils.h>
+#include <dpl/popup/popup_controller.h>
+#include <dpl/optional_typedefs.h>
+#include <dpl/string.h>
+#include <dpl/abstract_waitable_input_adapter.h>
+#include <dpl/abstract_waitable_output_adapter.h>
+#include <dpl/zip_input.h>
+#include <dpl/scoped_ptr.h>
+#include <dpl/binary_queue.h>
+#include <dpl/copy.h>
+#include <dpl/utils/wrt_global_settings.h>
+#include "option_parser.h"
+#include <parser_runner.h>
+#include <widget_parser.h>
+#include <root_parser.h>
+//#include <pkg-manager/pkgmgr_signal.h>
+
+#define NOFILE_CNT_FOR_INSTALLER 9999
+
+using namespace WrtDB;
+
+namespace { // anonymous
+const char AUL_ARG_KEY[] = "widget_arg";
+const char * const PKGMGR_INSTALL_MSG = "Install widget";
+const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
+
+const double BASE_LAYOUT_W = 720.0f;
+const double BASE_LAYOUT_H = 1280.0f;
+
+const char * const CONFIG_XML = "config.xml";
+
+struct PluginInstallerData
+{
+ void* wrtInstaller;
+ std::string pluginPath;
+};
+} // namespace anonymous
+
+WrtInstaller::WrtInstaller(int argc, char **argv) :
+ Application(argc, argv, "backend", false),
+ DPL::TaskDecl<WrtInstaller>(this),
+ m_packagePath(),
+ m_handle(-1),
+ m_initialized(false),
+ m_numPluginsToInstall(0),
+ m_totalPlugins(0),
+ m_returnStatus(-1),
+// m_installByPkgmgr(false),
+ m_quiet(true),
+// m_popup(NULL),
+ m_startupPluginInstallation(false)
+{
+ Touch();
+ LogDebug("App Created");
+}
+
+WrtInstaller::~WrtInstaller()
+{
+ LogDebug("App Finished");
+}
+
+void WrtInstaller::OnStop()
+{
+ LogInfo("Stopping Dummy Client");
+}
+
+void WrtInstaller::OnCreate()
+{
+ LogInfo("Creating DummyClient");
+
+ AddStep(&WrtInstaller::initStep);
+
+ std::string arg = m_argv[0];
+
+ if (arg.empty()) {
+ return showHelpAndQuit();
+ }
+
+ installNewPlugins();
+
+ if (arg.find("wrt-installer") != std::string::npos)
+ {
+ if (m_argc <= 1) {
+ return showHelpAndQuit();
+ }
+
+ arg = m_argv[1];
+ if (arg == "-h" || arg == "--help") {
+ if (m_argc != 2) {
+ return showHelpAndQuit();
+ }
+
+ // Just show help
+ return showHelpAndQuit();
+ } else if (arg == "-p" || arg == "--install-plugins") {
+ if (m_argc != 2) {
+ return showHelpAndQuit();
+ }
+ if (!m_startupPluginInstallation) {
+ AddStep(&WrtInstaller::installPluginsStep);
+ } else {
+ LogInfo("Plugin installation alredy started");
+ }
+ }
+ else
+ {
+ LogError("Unknown option");
+ return showHelpAndQuit();
+ }
+ }
+
+ AddStep(&WrtInstaller::shutdownStep);
+ DPL::Event::ControllerEventHandler<
+ WRTInstallerNS::NextStepEvent>::PostEvent(
+ WRTInstallerNS::NextStepEvent());
+}
+
+//void WrtInstaller::OnReset(bundle *b)
+//{
+// const char * bundledVal = bundle_get_val(b, AUL_ARG_KEY);
+// if (bundledVal != NULL) {
+// m_bundleValue = bundledVal;
+// LogInfo("Bundled value for (" << AUL_ARG_KEY << ") key received: " <<
+// m_bundleValue);
+// }
+//}
+
+int WrtInstaller::getReturnStatus() const
+{
+ if (!m_returnStatus) {
+ return RE_SUCCESS;
+ } else {
+ return RE_FAIL;
+ }
+}
+
+void WrtInstaller::OnTerminate()
+{
+ LogDebug("Wrt Shutdown now");
+ PluginUtils::unlockPluginInstallation();
+ if (m_initialized) {
+ wrt_installer_shutdown();
+ }
+// delete m_popup;
+}
+
+void WrtInstaller::showHelpAndQuit()
+{
+ printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/GUID/PATH]...\n"
+ "Operate with WebRuntime daemon: install, uninstall"
+ " and launch widgets.\n"
+ "Query list of installed widgets and setup up debugging support.\n"
+ "\n"
+ "Exactly one option must be selected.\n"
+ "Mandatory arguments to long options are mandatory for short "
+ "options too.\n"
+ " -h, --help show this help\n"
+ " -p, --install-plugins install plugins\n"
+ "\n");
+
+ Quit();
+}
+
+void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
+{
+ LogDebug("Quiting");
+
+ if (m_initialized) {
+ LogDebug("Wrt Shutdown now");
+ SwitchToStep(&WrtInstaller::shutdownStep);
+ DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::PostEvent(
+ WRTInstallerNS::NextStepEvent());
+ } else {
+ LogDebug("Quiting application");
+ return Quit();
+ }
+}
+
+void WrtInstaller::OnEventReceived(
+ const WRTInstallerNS::NextStepEvent& /*event*/)
+{
+ LogDebug("Executing next step");
+ NextStep();
+}
+
+void WrtInstaller::OnEventReceived(
+ const WRTInstallerNS::InstallPluginEvent& /*event*/)
+{
+ PluginInstallerData* privateData = new PluginInstallerData;
+ privateData->wrtInstaller = this;
+
+ if (!(*m_pluginsPaths).empty()) {
+ privateData->pluginPath = (*m_pluginsPaths).front();
+ (*m_pluginsPaths).pop_front();
+
+ wrt_install_plugin(privateData->pluginPath.c_str(),
+ static_cast<void*>(privateData),
+ &staticWrtPluginInstallationCallback,
+ &staticWrtPluginInstallProgressCb);
+ } else {
+ delete privateData;
+ }
+}
+
+void WrtInstaller::initStep()
+{
+ wrt_installer_init(this, staticWrtInitCallback);
+}
+
+//void WrtInstaller::installStep()
+//{
+// LogDebug("Installing widget ...");
+// DPL::ScopedFree<char> packagePath(canonicalize_file_name(
+// m_packagePath.c_str()));
+//
+// wrt_install_widget(packagePath ? packagePath.Get() : m_packagePath.c_str(),
+// this, &staticWrtStatusCallback,
+// (!m_quiet || m_installByPkgmgr)
+// ? &staticWrtInstallProgressCallback : NULL,
+// m_installPolicy,
+// m_quiet);
+//}
+
+void WrtInstaller::installPluginsStep()
+{
+ LogDebug("Installing plugins ...");
+
+ if (m_startupPluginInstallation) {
+ LogInfo("Plugin installation started because new plugin package found");
+ } else if (!PluginUtils::lockPluginInstallation()) {
+ LogError("Failed to open plugin installation lock file"
+ " Plugins are currently installed by other process");
+ staticWrtPluginInstallationCallback(WRT_PLUGIN_INSTALLER_ERROR_LOCK,
+ this);
+ return;
+ }
+
+ std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
+
+ DIR *dir;
+ dir = opendir(PLUGIN_PATH.c_str());
+
+ if (!dir) {
+ 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();
+ LogInfo("Plugins to install: " << m_numPluginsToInstall);
+ m_pluginsPaths = pluginsPaths;
+
+ 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()
+//{
+// LogDebug("Uninstalling widget ...");
+// wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
+// (!m_quiet || m_installByPkgmgr)
+// ? &staticWrtUninstallProgressCallback : NULL);
+//}
+
+//void WrtInstaller::uninstallPkgNameStep()
+//{
+// LogDebug("Uninstalling widget ...");
+// WrtErrStatus status = wrt_get_widget_by_pkgname(m_name, &m_handle);
+// if (status == WRT_SUCCESS) {
+// LogDebug("Get Widget Handle by package name : " << m_handle);
+// wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
+// (!m_quiet || m_installByPkgmgr)
+// ? &staticWrtUninstallProgressCallback : NULL);
+// } else {
+// printf("failed: can not uninstall widget\n");
+// LogError("Fail to uninstalling widget... ");
+// m_returnStatus = -1;
+// DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+// WRTInstallerNS::QuitEvent());
+// }
+//}
+
+//void WrtInstaller::uninstallGuidStep()
+//{
+// LogDebug("Uninstalling widget ...");
+// WrtErrStatus status = wrt_get_widget_by_guid(m_name, &m_handle);
+// if (status == WRT_SUCCESS) {
+// LogDebug("Get Widget Handle by guid : " << m_handle);
+// wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
+// !m_quiet ? &staticWrtUninstallProgressCallback : NULL);
+// } else {
+// printf("failed: can not uninstall widget\n");
+// LogError("Fail to uninstalling widget... ");
+// m_returnStatus = -1;
+// DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+// WRTInstallerNS::QuitEvent());
+// }
+//}
+//
+//void WrtInstaller::unistallWgtFileStep()
+//{
+// LogDebug("Uninstalling widget ...");
+//
+// Try {
+// // Parse config
+// ParserRunner parser;
+// ConfigParserData configInfo;
+//
+// // Open zip file
+// DPL::ScopedPtr<DPL::ZipInput> zipFile(
+// new DPL::ZipInput(m_packagePath));
+//
+// // Open config.xml file
+// DPL::ScopedPtr<DPL::ZipInput::File> configFile(
+// zipFile->OpenFile(CONFIG_XML));
+//
+// // Extract config
+// DPL::BinaryQueue buffer;
+// DPL::AbstractWaitableInputAdapter inputAdapter(configFile.Get());
+// DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
+// DPL::Copy(&inputAdapter, &outputAdapter);
+// parser.Parse(&buffer,
+// ElementParserPtr(
+// new RootParser<WidgetParser>(configInfo,
+// DPL::FromUTF32String(
+// L"widget"))));
+//
+// DPL::OptionalString widgetGUID = configInfo.widget_id;
+//
+// std::string guid = DPL::ToUTF8String(*widgetGUID);
+//
+// WrtErrStatus status = wrt_get_widget_by_guid(guid, &m_handle);
+// if (status == WRT_SUCCESS) {
+// LogDebug("Get Widget Handle by guid : " << m_handle);
+// wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
+// !m_quiet ? &staticWrtUninstallProgressCallback : NULL);
+// } else {
+// LogError("Fail to uninstalling widget... ");
+// m_returnStatus = -1;
+// DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+// WRTInstallerNS::QuitEvent());
+// }
+// }
+// Catch(DPL::ZipInput::Exception::OpenFailed)
+// {
+// LogError("Failed to open widget package");
+// printf("failed: widget package does not exist\n");
+// m_returnStatus = -1;
+// DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+// WRTInstallerNS::QuitEvent());
+// }
+// Catch(DPL::ZipInput::Exception::OpenFileFailed)
+// {
+// printf("failed: widget config file does not exist\n");
+// LogError("Failed to open config.xml file");
+// m_returnStatus = -1;
+// DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+// WRTInstallerNS::QuitEvent());
+// }
+// Catch(ElementParser::Exception::ParseError)
+// {
+// printf("failed: can not parse config file\n");
+// LogError("Failed to parse config.xml file");
+// m_returnStatus = -1;
+// DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+// WRTInstallerNS::QuitEvent());
+// }
+//}
+
+void WrtInstaller::shutdownStep()
+{
+ LogDebug("Closing Wrt connection ...");
+ if (m_initialized) {
+ wrt_installer_shutdown();
+ m_initialized = false;
+ DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+ WRTInstallerNS::QuitEvent());
+ }
+}
+
+void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
+ void* userdata)
+{
+ WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
+ Assert(This);
+
+ if (status == WRT_SUCCESS) {
+ LogDebug("Init succesfull");
+ This->m_initialized = true;
+ This->m_returnStatus = 0;
+
+// if (!This->m_quiet) {
+// This->m_popup = new InstallerPopup;
+// This->m_popup->init();
+// }
+
+ This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
+ ::PostEvent(WRTInstallerNS::NextStepEvent());
+ } else {
+ LogError("Init unsuccesfull");
+ This->m_returnStatus = -1;
+ This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
+ WRTInstallerNS::QuitEvent());
+ }
+}
+//
+//void WrtInstaller::staticWrtStatusCallback(int handle,
+// WrtErrStatus status,
+// void* userdata)
+//{
+// WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
+// Assert(This);
+//
+// Step current = This->GetCurrentStep();
+// DPL::String resultMsg;
+// std::string printMsg;
+//
+// if (current == &WrtInstaller::installStep)
+// {
+// resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
+// printMsg = "installed";
+// } else if (current == &WrtInstaller::uninstallStep ||
+// current == &WrtInstaller::uninstallPkgNameStep ||
+// current == &WrtInstaller::uninstallGuidStep ||
+// current == &WrtInstaller::unistallWgtFileStep)
+// {
+// resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
+// printMsg = "uninstalled";
+// }
+//
+// if (WRT_SUCCESS != status) {
+// // Failure
+// LogDebug("Step failed");
+// This->m_returnStatus = -1;
+//
+// if (!This->m_quiet) {
+// resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
+// This->m_popup->showPopup(This, resultMsg, failResultCallback);
+// } else {
+// This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
+// ::PostEvent(WRTInstallerNS::QuitEvent());
+// }
+//
+// switch (status) {
+// case WRT_INSTALLER_ERROR_INVALID_WIDGET_PACKAGE:
+// This->m_returnStatus = 1; //this status is specific
+// printf("failed: invalid widget package\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_WIDGET_DOES_NOT_EXIST:
+// printf("failed: widget package does not exist\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_FACTORY_WIDGET:
+// printf("failed: factory widget\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_ALREADY_UNINSTALLING:
+// printf("failed: already uninstalling\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_OUT_OUT_DISK_SPACE:
+// printf("failed: out of disk space\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_INVALID_CERTIFICATE:
+// printf("failed: invalid certificate\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_ALREADY_INSTALLED:
+// printf("failed: already installed\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_INTERNAL:
+// printf("failed: internal error\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_NOT_ALLOWED:
+// printf("failed: installation or update not allowed; invalid"
+// " mode\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_DEFERRED:
+// printf("deferred: widget update will continue after the widget"
+// " has been stopped\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_DATABASE_FAILURE:
+// printf("failed: database failure\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_OSPSVC:
+// printf("failed: during installation or uninstallation osp service\n");
+// break;
+//
+// case WRT_INSTALLER_ERROR_UNKNOWN:
+// printf("failed: unknown error\n");
+// break;
+//
+// default:
+// break;
+// }
+// } else {
+//
+// printf("%s : %d\n", printMsg.c_str(), handle);
+// LogDebug("Status succesfull");
+// This->m_handle = handle;
+// This->m_returnStatus = 0;
+// resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
+//
+// if (!This->m_quiet) {
+// This->m_popup->showPopup(This, resultMsg, showResultCallback);
+// } else {
+// This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
+// ::PostEvent(WRTInstallerNS::NextStepEvent());
+// }
+// }
+//}
+
+void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
+ void* userdata)
+{
+ Assert(userdata);
+
+ PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
+
+ WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
+
+ std::string path = std::string(data->pluginPath);
+ delete data;
+
+ This->m_numPluginsToInstall--;
+ LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
+
+ if (This->m_numPluginsToInstall < 1) {
+ LogDebug("All plugins installation completed");
+
+ //remove installation request
+ if (!PluginUtils::removeInstallationRequiredFlag()) {
+ LogInfo("Failed to remove file initializing plugin installation");
+ }
+
+ //remove lock file
+ if (!PluginUtils::unlockPluginInstallation()) {
+ LogInfo("Failed to remove installation lock");
+ }
+
+// if (!This->m_quiet) {
+// This->m_popup->init();
+// elm_progressbar_value_set(This->m_popup->m_progressbar, 100.0);
+// evas_object_show(This->m_popup->m_popup);
+// }
+
+ This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
+ ::PostEvent(WRTInstallerNS::NextStepEvent());
+ } else {
+// if (!This->m_quiet) {
+// This->m_popup->init();
+// float percent = (This->m_totalPlugins - This->m_numPluginsToInstall)/(float)This->m_totalPlugins;
+// elm_progressbar_value_set(This->m_popup->m_progressbar, percent);
+// evas_object_show(This->m_popup->m_popup);
+// }
+
+ This->DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>::PostEvent(
+ WRTInstallerNS::InstallPluginEvent());
+ }
+
+ if (WRT_SUCCESS == status) {
+ This->m_returnStatus = 0;
+ LogDebug("One plugin Installation succesfull: " << path);
+ return;
+ }
+
+ // Failure
+ LogWarning("One of the plugins installation failed!: " << path);
+
+ if (WRT_PLUGIN_INSTALLER_ERROR_WAITING == status) {
+ LogInfo("Plugin installation is waiting for dependencies");
+ }
+
+ switch (status) {
+ case WRT_PLUGIN_INSTALLER_ERROR_WRONG_PATH:
+ LogError("failed: wrong path to plugin directory\n");
+ break;
+
+ case WRT_PLUGIN_INSTALLER_ERROR_METAFILE:
+ LogError("failed: plugin metafile error\n");
+ break;
+
+ case WRT_PLUGIN_INSTALLER_ERROR_ALREADY_INSTALLED:
+ LogError("failed: plugin already installed\n");
+ break;
+
+ case WRT_PLUGIN_INSTALLER_ERROR_LIBRARY_ERROR:
+ LogError("failed: plugin library: missing symbols or structures\n");
+ break;
+
+ case WRT_PLUGIN_INSTALLER_ERROR_UNKNOWN:
+ LogError("failed: unknown error\n");
+ break;
+
+ default:
+ break;
+ }
+}
+
+void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
+ const char* description,
+ void* userdata)
+{
+ PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
+
+ std::string path = std::string(data->pluginPath);
+
+ LogInfo("Plugin Installation: " << path <<
+ " progress: " << percent <<
+ "description " << description);
+}
+
+//void WrtInstaller::staticWrtInstallProgressCallback(float percent,
+// const char* description, void* userdata)
+//{
+// WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
+// std::stringstream percentStr;
+// LogInfo(" progress: " << percent <<
+// " description: " << description);
+//
+// if (!This->m_quiet) {
+// This->m_popup->init();
+// elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
+// evas_object_show(This->m_popup->m_popup);
+// }
+//}
+//void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
+// const char* description, void* userdata)
+//{
+// WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
+// std::stringstream percentStr;
+// LogInfo(" progress: " << percent <<
+// " description: " << description);
+//
+// if (!This->m_quiet) {
+// This->m_popup->init();
+// elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
+// evas_object_show(This->m_popup->m_popup);
+// }
+//}
+
+#if 0
+WrtInstaller::InstallerPopup::InstallerPopup() :
+ m_win(NULL),
+ m_popup(NULL),
+ m_progressbar(NULL)
+{
+}
+
+WrtInstaller::InstallerPopup::~InstallerPopup()
+{
+ LogDebug("App Finished");
+}
+
+void WrtInstaller::InstallerPopup::init()
+{
+ LogDebug("Window Init");
+
+ if (m_win == NULL) {
+ // create window
+ m_win = createWin("wrt-installer");
+
+ // create popup
+ m_popup = elm_popup_add(m_win);
+
+ // create progressbar
+ m_progressbar = elm_progressbar_add(m_popup);
+ elm_object_style_set(m_progressbar, "list_progress");
+ elm_progressbar_horizontal_set(m_progressbar, EINA_TRUE);
+ evas_object_size_hint_align_set(m_progressbar, EVAS_HINT_FILL,
+ EVAS_HINT_FILL);
+ evas_object_size_hint_weight_set(m_progressbar, EVAS_HINT_EXPAND,
+ EVAS_HINT_EXPAND);
+ elm_object_content_set(m_popup, m_progressbar);
+ elm_progressbar_value_set(m_progressbar, 0.0);
+ evas_object_show(m_progressbar);
+
+ evas_object_show(m_popup);
+ evas_object_show(m_win);
+ }
+}
+
+Evas_Object* WrtInstaller::InstallerPopup::createWin(const char *name)
+{
+ Evas_Object *win;
+ win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
+
+ int w, h;
+ if(!win)
+ return NULL;
+
+ elm_win_alpha_set(win, EINA_TRUE);
+ elm_win_title_set(win, name);
+ elm_win_borderless_set(win, EINA_TRUE);
+ elm_win_raise(win);
+
+ ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
+ evas_object_resize(win, w, h);
+ return win;
+}
+
+void WrtInstaller::InstallerPopup::showPopup(void* userdata,
+ const DPL::String& pkgMsg,
+ ShowResultCallback callback)
+{
+ Evas_Object *btn;
+
+
+ LogDebug("Result Popup Created");
+ evas_object_del(m_popup);
+ m_popup = NULL;
+
+ m_popup = elm_popup_add(m_win);
+ if (!m_popup)
+ return;
+
+ btn = elm_button_add(m_popup);
+ if (!btn) {
+ evas_object_del(m_popup);
+ return;
+ }
+ elm_object_text_set(btn, "OK");
+ evas_object_smart_callback_add(btn, "clicked", callback, userdata);
+ elm_object_part_content_set(m_popup, "button1", btn);
+ elm_object_part_text_set(m_popup, "title,text", "RESULT");
+ elm_object_text_set(m_popup, DPL::ToUTF8String(pkgMsg).c_str());
+
+ evas_object_show(m_popup);
+ evas_object_show(m_win);
+
+}
+#endif
+
+//void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
+// void* /*event_info*/)
+//{
+// WrtInstaller *This = static_cast<WrtInstaller*>(data);
+// Assert(This);
+//
+// This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
+// ::PostEvent(WRTInstallerNS::NextStepEvent());
+//}
+//
+//void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
+// void* /*event_info*/)
+//{
+// WrtInstaller *This = static_cast<WrtInstaller*>(data);
+// Assert(This);
+//
+// This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
+// ::PostEvent(WRTInstallerNS::QuitEvent());
+//}
+
+void WrtInstaller::installNewPlugins()
+{
+ LogDebug("Install new plugins");
+
+ if (!PluginUtils::lockPluginInstallation()) {
+ LogInfo("Lock NOT created");
+ return;
+ }
+
+ if (!PluginUtils::checkPluginInstallationRequired()) {
+ LogDebug("Plugin installation not required");
+ PluginUtils::unlockPluginInstallation();
+ return;
+ }
+
+ m_startupPluginInstallation = true;
+ AddStep(&WrtInstaller::installPluginsStep);
+}
+
+int main(int argc, char *argv[])
+{
+ // Output on stdout will be flushed after every newline character,
+ // even if it is redirected to a pipe. This is useful for running
+ // from a script and parsing output.
+ // (Standard behavior of stdlib is to use full buffering when
+ // redirected to a pipe, which means even after an end of line
+ // the output may not be flushed).
+ setlinebuf(stdout);
+
+ // Check and re-set the file open limitation
+ struct rlimit rlim;
+ if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
+ LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")" );
+ LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")" );
+
+ if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
+ rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
+ rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
+ if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
+ LogError("setrlimit is fail!!");
+ }
+ }
+ } else {
+ LogError("getrlimit is fail!!");
+ }
+
+ // set evas backend type for emulator
+ // popup isn't showed in the emulator,
+ // if backend isn't set to SW backend
+// if (GlobalSettings::IsEmulator()) {
+// if (setenv("ELM_ENGINE", "x11", 1)) {
+// LogDebug("Enable backend");
+// }
+// }
+
+ WrtInstaller app(argc, argv);
+ int ret = app.Exec();
+ LogDebug("App returned: " << ret);
+ ret = app.getReturnStatus();
+ LogDebug("WrtInstaller returned: " << ret);
+ return ret;
+}