2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /* @file wrt_installer.cpp
18 * @brief Implementation file for installer
21 #include "wrt_installer.h"
22 #include "plugin_utils.h"
28 #include <sys/resource.h>
29 #include <dpl/optional.h>
30 #include <dpl/scoped_free.h>
31 #include <dpl/optional_typedefs.h>
32 #include <dpl/exception.h>
33 #include <dpl/sstream.h>
35 #include <dpl/wrt-dao-ro/global_config.h>
36 #include <dpl/wrt-dao-ro/config_parser_data.h>
37 #include <dpl/localization/localization_utils.h>
38 #include <dpl/popup/popup_controller.h>
39 #include <dpl/optional_typedefs.h>
40 #include <dpl/string.h>
41 #include <dpl/abstract_waitable_input_adapter.h>
42 #include <dpl/abstract_waitable_output_adapter.h>
43 #include <dpl/zip_input.h>
44 #include <dpl/scoped_ptr.h>
45 #include <dpl/binary_queue.h>
47 #include <dpl/utils/wrt_global_settings.h>
48 #include "option_parser.h"
49 #include <parser_runner.h>
50 #include <widget_parser.h>
51 #include <root_parser.h>
52 #include <pkg-manager/pkgmgr_signal.h>
54 #define NOFILE_CNT_FOR_INSTALLER 9999
56 using namespace WrtDB;
58 namespace { // anonymous
59 const char AUL_ARG_KEY[] = "widget_arg";
60 const char * const PKGMGR_INSTALL_MSG = "Install widget";
61 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
63 const double BASE_LAYOUT_W = 720.0f;
64 const double BASE_LAYOUT_H = 1280.0f;
66 const char * const CONFIG_XML = "config.xml";
68 struct PluginInstallerData
71 std::string pluginPath;
73 } // namespace anonymous
75 WrtInstaller::WrtInstaller(int argc, char **argv) :
76 Application(argc, argv, "backend", false),
77 DPL::TaskDecl<WrtInstaller>(this),
81 m_numPluginsToInstall(0),
84 m_installByPkgmgr(false),
87 m_startupPluginInstallation(false)
90 LogDebug("App Created");
93 WrtInstaller::~WrtInstaller()
95 LogDebug("App Finished");
98 void WrtInstaller::OnStop()
100 LogInfo("Stopping Dummy Client");
103 void WrtInstaller::OnCreate()
105 LogInfo("Creating DummyClient");
107 AddStep(&WrtInstaller::initStep);
109 std::string arg = m_argv[0];
112 return showHelpAndQuit();
117 if (arg.find("wrt-installer") != std::string::npos)
120 return showHelpAndQuit();
124 if (arg == "-h" || arg == "--help") {
126 return showHelpAndQuit();
130 return showHelpAndQuit();
131 } else if (arg == "-p" || arg == "--install-plugins") {
133 return showHelpAndQuit();
135 if (!m_startupPluginInstallation) {
136 AddStep(&WrtInstaller::installPluginsStep);
138 LogInfo("Plugin installation alredy started");
140 } else if (arg == "-i" || arg == "--install") {
142 return showHelpAndQuit();
145 m_packagePath = m_argv[2];
146 m_installPolicy = WRT_WIM_POLICY_WAC;
147 AddStep(&WrtInstaller::installStep);
148 } else if (arg == "-iu" || arg == "--install-or-update") {
150 return showHelpAndQuit();
153 m_packagePath = m_argv[2];
154 m_installPolicy = WRT_WIM_POLICY_WAC;
155 AddStep(&WrtInstaller::installStep);
156 } else if (arg == "-if" || arg == "--install-force") {
158 return showHelpAndQuit();
161 m_packagePath = m_argv[2];
162 m_installPolicy = WRT_WIM_POLICY_FORCE_INSTALL;
163 AddStep(&WrtInstaller::installStep);
164 } else if (arg == "-inq" || arg == "--install-not-quiet") {
166 return showHelpAndQuit();
169 m_packagePath = m_argv[2];
170 m_installPolicy = WRT_WIM_POLICY_NEVER_UPDATE;
171 AddStep(&WrtInstaller::installStep);
172 } else if (arg == "-u" || arg == "--uninstall") {
174 return showHelpAndQuit();
177 m_handle = atoi(m_argv[2]);
178 AddStep(&WrtInstaller::uninstallStep);
179 } else if (arg == "-un" || arg == "--uninstall-name") {
181 return showHelpAndQuit();
184 AddStep(&WrtInstaller::uninstallPkgNameStep);
185 } else if (arg == "-ug" || arg == "--uninstall-guid") {
187 return showHelpAndQuit();
190 AddStep(&WrtInstaller::uninstallGuidStep);
191 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
193 return showHelpAndQuit();
195 m_packagePath = m_argv[2];
196 AddStep(&WrtInstaller::unistallWgtFileStep);
197 } else if (arg == "-unq" || arg == "--uninstall-not-quiet") {
199 return showHelpAndQuit();
202 m_handle = atoi(m_argv[2]);
203 AddStep(&WrtInstaller::uninstallStep);
205 } else if (arg.find("backend") != std::string::npos) {
206 using namespace PackageManager;
207 m_installByPkgmgr = true;
209 PkgmgrSignalSingleton::Instance().initialize(m_argc, m_argv);
210 m_quiet = PkgmgrSignalSingleton::Instance().isNoPopupRequired();
211 LogDebug("backend m_quiet"<<m_quiet);
213 int reqType = PkgmgrSignalSingleton::Instance().getRequestedType();
216 case PKGMGR_REQ_INSTALL:
217 m_packagePath = m_argv[4];
218 m_installPolicy = WRT_WIM_POLICY_WAC;
219 AddStep(&WrtInstaller::installStep);
221 case PKGMGR_REQ_UNINSTALL:
223 AddStep(&WrtInstaller::uninstallPkgNameStep);
226 LogDebug("Not available type");
230 // Launch widget based on application basename
231 size_t pos = arg.find_last_of('/');
233 if (pos != std::string::npos) {
234 arg = arg.erase(0, pos + 1);
237 if (sscanf(arg.c_str(), "%i", &m_handle) != 1) {
238 printf("failed: invalid widget handle\n");
239 return showHelpAndQuit();
242 LogDebug("Widget Id: " << m_handle << " (" << arg << ")");
245 AddStep(&WrtInstaller::shutdownStep);
246 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::PostEvent(
247 WRTInstallerNS::NextStepEvent());
250 void WrtInstaller::OnReset(bundle *b)
252 const char * bundledVal = bundle_get_val(b, AUL_ARG_KEY);
253 if (bundledVal != NULL) {
254 m_bundleValue = bundledVal;
255 LogInfo("Bundled value for (" << AUL_ARG_KEY << ") key received: " <<
260 int WrtInstaller::getReturnStatus() const
262 if (!m_returnStatus) {
269 void WrtInstaller::OnTerminate()
271 LogDebug("Wrt Shutdown now");
272 PluginUtils::unlockPluginInstallation();
274 wrt_installer_shutdown();
279 void WrtInstaller::showHelpAndQuit()
281 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/GUID/PATH]...\n"
282 "Operate with WebRuntime daemon: install, uninstall"
283 " and launch widgets.\n"
284 "Query list of installed widgets and setup up debugging support.\n"
286 "Exactly one option must be selected.\n"
287 "Mandatory arguments to long options are mandatory for short "
289 " -h, --help show this help\n"
290 " -p, --install-plugins install plugins\n"
292 "install widget package for given path\n"
293 " -iu, --install-or-update "
294 "install or update widget package for given path\n"
295 " -if, --install-force "
296 "install forcibly widget package for given path\n"
297 " -inq, --install-not-quiet "
298 "install with popup \n"
300 "uninstall widget for given ID\n"
301 " -un, --uninstall for given package name "
302 "uninstall widget for given package name\n"
303 " -ug, --uninstall-guid "
304 "uninstall widget for given package path\n"
305 " -up, --uninstall-packagepath "
306 "uninstall widget for given Global Unique IDentifier\n"
307 " -unq, --uninstall-not-quiet "
308 "uninstall with popup \n"
314 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
319 LogDebug("Wrt Shutdown now");
320 SwitchToStep(&WrtInstaller::shutdownStep);
321 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::PostEvent(
322 WRTInstallerNS::NextStepEvent());
324 LogDebug("Quiting application");
329 void WrtInstaller::OnEventReceived(
330 const WRTInstallerNS::NextStepEvent& /*event*/)
332 LogDebug("Executing next step");
336 void WrtInstaller::OnEventReceived(
337 const WRTInstallerNS::InstallPluginEvent& /*event*/)
339 PluginInstallerData* privateData = new PluginInstallerData;
340 privateData->wrtInstaller = this;
342 if (!(*m_pluginsPaths).empty()) {
343 privateData->pluginPath = (*m_pluginsPaths).front();
344 (*m_pluginsPaths).pop_front();
346 wrt_install_plugin(privateData->pluginPath.c_str(),
347 static_cast<void*>(privateData),
348 &staticWrtPluginInstallationCallback,
349 &staticWrtPluginInstallProgressCb);
355 void WrtInstaller::initStep()
357 wrt_installer_init(this, staticWrtInitCallback);
360 void WrtInstaller::installStep()
362 LogDebug("Installing widget ...");
363 DPL::ScopedFree<char> packagePath(canonicalize_file_name(
364 m_packagePath.c_str()));
366 wrt_install_widget(packagePath ? packagePath.Get() : m_packagePath.c_str(),
367 this, &staticWrtStatusCallback,
368 (!m_quiet || m_installByPkgmgr)
369 ? &staticWrtInstallProgressCallback : NULL,
374 void WrtInstaller::installPluginsStep()
376 LogDebug("Installing plugins ...");
378 if (m_startupPluginInstallation) {
379 LogInfo("Plugin installation started because new plugin package found");
380 } else if (!PluginUtils::lockPluginInstallation()) {
381 LogError("Failed to open plugin installation lock file"
382 " Plugins are currently installed by other process");
383 staticWrtPluginInstallationCallback(WRT_PLUGIN_INSTALLER_ERROR_LOCK,
388 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
391 dir = opendir(PLUGIN_PATH.c_str());
397 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
398 struct dirent* libdir;
402 std::list<std::string> pluginsPaths;
404 while ((libdir = readdir(dir)) != 0) {
405 if (strcmp(libdir->d_name, ".") == 0 ||
406 strcmp(libdir->d_name, "..") == 0)
411 std::string path = PLUGIN_PATH;
413 path += libdir->d_name;
417 if (stat(path.c_str(), &tmp) == -1) {
418 LogError("Failed to open file" << path);
422 if (!S_ISDIR(tmp.st_mode)) {
423 LogError("Not a directory" << path);
427 pluginsPaths.push_back(path);
430 //set nb of plugins to install
431 //this value indicate how many callbacks are expected
432 m_numPluginsToInstall = pluginsPaths.size();
433 LogInfo("Plugins to install: " << m_numPluginsToInstall);
434 m_pluginsPaths = pluginsPaths;
436 m_totalPlugins = m_numPluginsToInstall;
437 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
438 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
440 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
441 LogError("Failed to close dir: " << dir);
445 void WrtInstaller::uninstallStep()
447 LogDebug("Uninstalling widget ...");
448 wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
449 (!m_quiet || m_installByPkgmgr)
450 ? &staticWrtUninstallProgressCallback : NULL);
453 void WrtInstaller::uninstallPkgNameStep()
455 LogDebug("Uninstalling widget ...");
456 WrtErrStatus status = wrt_get_widget_by_pkgname(m_name, &m_handle);
457 if (status == WRT_SUCCESS) {
458 LogDebug("Get Widget Handle by package name : " << m_handle);
459 wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
460 (!m_quiet || m_installByPkgmgr)
461 ? &staticWrtUninstallProgressCallback : NULL);
463 printf("failed: can not uninstall widget\n");
464 LogError("Fail to uninstalling widget... ");
466 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
467 WRTInstallerNS::QuitEvent());
471 void WrtInstaller::uninstallGuidStep()
473 LogDebug("Uninstalling widget ...");
474 WrtErrStatus status = wrt_get_widget_by_guid(m_name, &m_handle);
475 if (status == WRT_SUCCESS) {
476 LogDebug("Get Widget Handle by guid : " << m_handle);
477 wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
478 !m_quiet ? &staticWrtUninstallProgressCallback : NULL);
480 printf("failed: can not uninstall widget\n");
481 LogError("Fail to uninstalling widget... ");
483 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
484 WRTInstallerNS::QuitEvent());
488 void WrtInstaller::unistallWgtFileStep()
490 LogDebug("Uninstalling widget ...");
495 ConfigParserData configInfo;
498 DPL::ScopedPtr<DPL::ZipInput> zipFile(
499 new DPL::ZipInput(m_packagePath));
501 // Open config.xml file
502 DPL::ScopedPtr<DPL::ZipInput::File> configFile(
503 zipFile->OpenFile(CONFIG_XML));
506 DPL::BinaryQueue buffer;
507 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.Get());
508 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
509 DPL::Copy(&inputAdapter, &outputAdapter);
510 parser.Parse(&buffer,
512 new RootParser<WidgetParser>(configInfo,
513 DPL::FromUTF32String(
516 DPL::OptionalString widgetGUID = configInfo.widget_id;
518 std::string guid = DPL::ToUTF8String(*widgetGUID);
520 WrtErrStatus status = wrt_get_widget_by_guid(guid, &m_handle);
521 if (status == WRT_SUCCESS) {
522 LogDebug("Get Widget Handle by guid : " << m_handle);
523 wrt_uninstall_widget(m_handle, this, &staticWrtStatusCallback,
524 !m_quiet ? &staticWrtUninstallProgressCallback : NULL);
526 LogError("Fail to uninstalling widget... ");
528 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
529 WRTInstallerNS::QuitEvent());
532 Catch(DPL::ZipInput::Exception::OpenFailed)
534 LogError("Failed to open widget package");
535 printf("failed: widget package does not exist\n");
537 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
538 WRTInstallerNS::QuitEvent());
540 Catch(DPL::ZipInput::Exception::OpenFileFailed)
542 printf("failed: widget config file does not exist\n");
543 LogError("Failed to open config.xml file");
545 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
546 WRTInstallerNS::QuitEvent());
548 Catch(ElementParser::Exception::ParseError)
550 printf("failed: can not parse config file\n");
551 LogError("Failed to parse config.xml file");
553 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
554 WRTInstallerNS::QuitEvent());
558 void WrtInstaller::shutdownStep()
560 LogDebug("Closing Wrt connection ...");
562 wrt_installer_shutdown();
563 m_initialized = false;
564 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
565 WRTInstallerNS::QuitEvent());
569 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
572 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
575 if (status == WRT_SUCCESS) {
576 LogDebug("Init succesfull");
577 This->m_initialized = true;
578 This->m_returnStatus = 0;
580 if (!This->m_quiet) {
581 This->m_popup = new InstallerPopup;
582 This->m_popup->init();
585 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
586 ::PostEvent(WRTInstallerNS::NextStepEvent());
588 LogError("Init unsuccesfull");
589 This->m_returnStatus = -1;
590 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
591 WRTInstallerNS::QuitEvent());
595 void WrtInstaller::staticWrtStatusCallback(int handle,
599 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
602 Step current = This->GetCurrentStep();
603 DPL::String resultMsg;
604 std::string printMsg;
606 if (current == &WrtInstaller::installStep)
608 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
609 printMsg = "installed";
610 } else if (current == &WrtInstaller::uninstallStep ||
611 current == &WrtInstaller::uninstallPkgNameStep ||
612 current == &WrtInstaller::uninstallGuidStep ||
613 current == &WrtInstaller::unistallWgtFileStep)
615 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
616 printMsg = "uninstalled";
619 if (WRT_SUCCESS != status) {
621 LogDebug("Step failed");
622 This->m_returnStatus = -1;
624 if (!This->m_quiet) {
625 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
626 This->m_popup->showPopup(This, resultMsg, failResultCallback);
628 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
629 ::PostEvent(WRTInstallerNS::QuitEvent());
633 case WRT_INSTALLER_ERROR_INVALID_WIDGET_PACKAGE:
634 This->m_returnStatus = 1; //this status is specific
635 printf("failed: invalid widget package\n");
638 case WRT_INSTALLER_ERROR_WIDGET_DOES_NOT_EXIST:
639 printf("failed: widget package does not exist\n");
642 case WRT_INSTALLER_ERROR_FACTORY_WIDGET:
643 printf("failed: factory widget\n");
646 case WRT_INSTALLER_ERROR_ALREADY_UNINSTALLING:
647 printf("failed: already uninstalling\n");
650 case WRT_INSTALLER_ERROR_OUT_OUT_DISK_SPACE:
651 printf("failed: out of disk space\n");
654 case WRT_INSTALLER_ERROR_INVALID_CERTIFICATE:
655 printf("failed: invalid certificate\n");
658 case WRT_INSTALLER_ERROR_ALREADY_INSTALLED:
659 printf("failed: already installed\n");
662 case WRT_INSTALLER_ERROR_INTERNAL:
663 printf("failed: internal error\n");
666 case WRT_INSTALLER_ERROR_NOT_ALLOWED:
667 printf("failed: installation or update not allowed; invalid"
671 case WRT_INSTALLER_ERROR_DEFERRED:
672 printf("deferred: widget update will continue after the widget"
673 " has been stopped\n");
676 case WRT_INSTALLER_ERROR_DATABASE_FAILURE:
677 printf("failed: database failure\n");
680 case WRT_INSTALLER_ERROR_OSPSVC:
681 printf("failed: during installation or uninstallation osp service\n");
684 case WRT_INSTALLER_ERROR_UNKNOWN:
685 printf("failed: unknown error\n");
693 printf("%s : %d\n", printMsg.c_str(), handle);
694 LogDebug("Status succesfull");
695 This->m_handle = handle;
696 This->m_returnStatus = 0;
697 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
699 if (!This->m_quiet) {
700 This->m_popup->showPopup(This, resultMsg, showResultCallback);
702 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
703 ::PostEvent(WRTInstallerNS::NextStepEvent());
708 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
713 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
715 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
717 std::string path = std::string(data->pluginPath);
720 This->m_numPluginsToInstall--;
721 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
723 if (This->m_numPluginsToInstall < 1) {
724 LogDebug("All plugins installation completed");
726 //remove installation request
727 if (!PluginUtils::removeInstallationRequiredFlag()) {
728 LogInfo("Failed to remove file initializing plugin installation");
732 if (!PluginUtils::unlockPluginInstallation()) {
733 LogInfo("Failed to remove installation lock");
736 if (!This->m_quiet) {
737 This->m_popup->init();
738 elm_progressbar_value_set(This->m_popup->m_progressbar, 100.0);
739 evas_object_show(This->m_popup->m_popup);
742 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
743 ::PostEvent(WRTInstallerNS::NextStepEvent());
745 if (!This->m_quiet) {
746 This->m_popup->init();
747 float percent = (This->m_totalPlugins - This->m_numPluginsToInstall)/(float)This->m_totalPlugins;
748 elm_progressbar_value_set(This->m_popup->m_progressbar, percent);
749 evas_object_show(This->m_popup->m_popup);
752 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>::PostEvent(
753 WRTInstallerNS::InstallPluginEvent());
756 if (WRT_SUCCESS == status) {
757 This->m_returnStatus = 0;
758 LogDebug("One plugin Installation succesfull: " << path);
763 LogWarning("One of the plugins installation failed!: " << path);
765 if (WRT_PLUGIN_INSTALLER_ERROR_WAITING == status) {
766 LogInfo("Plugin installation is waiting for dependencies");
770 case WRT_PLUGIN_INSTALLER_ERROR_WRONG_PATH:
771 LogError("failed: wrong path to plugin directory\n");
774 case WRT_PLUGIN_INSTALLER_ERROR_METAFILE:
775 LogError("failed: plugin metafile error\n");
778 case WRT_PLUGIN_INSTALLER_ERROR_ALREADY_INSTALLED:
779 LogError("failed: plugin already installed\n");
782 case WRT_PLUGIN_INSTALLER_ERROR_LIBRARY_ERROR:
783 LogError("failed: plugin library: missing symbols or structures\n");
786 case WRT_PLUGIN_INSTALLER_ERROR_UNKNOWN:
787 LogError("failed: unknown error\n");
795 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
796 const char* description,
799 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
801 std::string path = std::string(data->pluginPath);
803 LogInfo("Plugin Installation: " << path <<
804 " progress: " << percent <<
805 "description " << description);
808 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
809 const char* description, void* userdata)
811 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
812 std::stringstream percentStr;
813 LogInfo(" progress: " << percent <<
814 " description: " << description);
816 if (!This->m_quiet) {
817 This->m_popup->init();
818 elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
819 evas_object_show(This->m_popup->m_popup);
822 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
823 const char* description, void* userdata)
825 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
826 std::stringstream percentStr;
827 LogInfo(" progress: " << percent <<
828 " description: " << description);
830 if (!This->m_quiet) {
831 This->m_popup->init();
832 elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
833 evas_object_show(This->m_popup->m_popup);
837 WrtInstaller::InstallerPopup::InstallerPopup() :
844 WrtInstaller::InstallerPopup::~InstallerPopup()
846 LogDebug("App Finished");
849 void WrtInstaller::InstallerPopup::init()
851 LogDebug("Window Init");
855 m_win = createWin("wrt-installer");
858 m_popup = elm_popup_add(m_win);
860 // create progressbar
861 m_progressbar = elm_progressbar_add(m_popup);
862 elm_object_style_set(m_progressbar, "list_progress");
863 elm_progressbar_horizontal_set(m_progressbar, EINA_TRUE);
864 evas_object_size_hint_align_set(m_progressbar, EVAS_HINT_FILL,
866 evas_object_size_hint_weight_set(m_progressbar, EVAS_HINT_EXPAND,
868 elm_object_content_set(m_popup, m_progressbar);
869 elm_progressbar_value_set(m_progressbar, 0.0);
870 evas_object_show(m_progressbar);
872 evas_object_show(m_popup);
873 evas_object_show(m_win);
877 Evas_Object* WrtInstaller::InstallerPopup::createWin(const char *name)
880 win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
886 elm_win_alpha_set(win, EINA_TRUE);
887 elm_win_title_set(win, name);
888 elm_win_borderless_set(win, EINA_TRUE);
891 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
892 evas_object_resize(win, w, h);
896 void WrtInstaller::InstallerPopup::showPopup(void* userdata,
897 const DPL::String& pkgMsg,
898 ShowResultCallback callback)
903 LogDebug("Result Popup Created");
904 evas_object_del(m_popup);
907 m_popup = elm_popup_add(m_win);
911 btn = elm_button_add(m_popup);
913 evas_object_del(m_popup);
916 elm_object_text_set(btn, "OK");
917 evas_object_smart_callback_add(btn, "clicked", callback, userdata);
918 elm_object_part_content_set(m_popup, "button1", btn);
919 elm_object_part_text_set(m_popup, "title,text", "RESULT");
920 elm_object_text_set(m_popup, DPL::ToUTF8String(pkgMsg).c_str());
922 evas_object_show(m_popup);
923 evas_object_show(m_win);
927 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
928 void* /*event_info*/)
930 WrtInstaller *This = static_cast<WrtInstaller*>(data);
933 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
934 ::PostEvent(WRTInstallerNS::NextStepEvent());
937 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
938 void* /*event_info*/)
940 WrtInstaller *This = static_cast<WrtInstaller*>(data);
943 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
944 ::PostEvent(WRTInstallerNS::QuitEvent());
947 void WrtInstaller::installNewPlugins()
949 LogDebug("Install new plugins");
951 if (!PluginUtils::lockPluginInstallation()) {
952 LogInfo("Lock NOT created");
956 if (!PluginUtils::checkPluginInstallationRequired()) {
957 LogDebug("Plugin installation not required");
958 PluginUtils::unlockPluginInstallation();
962 m_startupPluginInstallation = true;
963 AddStep(&WrtInstaller::installPluginsStep);
966 int main(int argc, char *argv[])
968 // Output on stdout will be flushed after every newline character,
969 // even if it is redirected to a pipe. This is useful for running
970 // from a script and parsing output.
971 // (Standard behavior of stdlib is to use full buffering when
972 // redirected to a pipe, which means even after an end of line
973 // the output may not be flushed).
976 // Check and re-set the file open limitation
978 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
979 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")" );
980 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")" );
982 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
983 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
984 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
985 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
986 LogError("setrlimit is fail!!");
990 LogError("getrlimit is fail!!");
993 // set evas backend type for emulator
994 // popup isn't showed in the emulator,
995 // if backend isn't set to SW backend
996 if (GlobalSettings::IsEmulator()) {
997 if (setenv("ELM_ENGINE", "x11", 1)) {
998 LogDebug("Enable backend");
1002 WrtInstaller app(argc, argv);
1003 int ret = app.Exec();
1004 LogDebug("App returned: " << ret);
1005 ret = app.getReturnStatus();
1006 LogDebug("WrtInstaller returned: " << ret);