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"
29 #include <sys/resource.h>
30 #include <dpl/optional.h>
31 #include <dpl/scoped_free.h>
32 #include <dpl/optional_typedefs.h>
33 #include <dpl/exception.h>
34 #include <dpl/sstream.h>
36 #include <dpl/wrt-dao-ro/global_config.h>
37 #include <dpl/wrt-dao-ro/config_parser_data.h>
38 #include <dpl/localization/localization_utils.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/binary_queue.h>
46 #include <dpl/errno_string.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>
53 #define NOFILE_CNT_FOR_INSTALLER 9999
55 using namespace WrtDB;
57 namespace { // anonymous
58 const char AUL_ARG_KEY[] = "widget_arg";
59 const char * const PKGMGR_INSTALL_MSG = "Install widget";
60 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
62 const double BASE_LAYOUT_W = 720.0f;
63 const double BASE_LAYOUT_H = 1280.0f;
65 const char * const CONFIG_XML = "config.xml";
69 void operator()(void* x)
75 struct PluginInstallerData
78 std::string pluginPath;
80 } // namespace anonymous
82 WrtInstaller::WrtInstaller(int argc, char **argv) :
83 Application(argc, argv, "backend", false),
84 DPL::TaskDecl<WrtInstaller>(this),
88 m_numPluginsToInstall(0),
91 m_installByPkgmgr(false),
94 m_startupPluginInstallation(false),
95 m_preloadWidget(false)
98 LogDebug("App Created");
101 WrtInstaller::~WrtInstaller()
103 LogDebug("App Finished");
106 void WrtInstaller::OnStop()
108 LogInfo("Stopping Dummy Client");
111 void WrtInstaller::OnCreate()
113 LogInfo("Creating DummyClient");
115 "===========================================================\n");
116 fprintf(stderr, "# wrt-installer #\n");
117 fprintf(stderr, "# argc [%ld]\n", m_argc);
118 fprintf(stderr, "# argv[0] = [%s]\n", m_argv[0]);
119 fprintf(stderr, "# argv[1] = [%s]\n", m_argv[1]);
120 fprintf(stderr, "# argv[2] = [%s]\n", m_argv[2]);
122 "===========================================================\n");
124 AddStep(&WrtInstaller::initStep);
126 std::string arg = m_argv[0];
128 pkgmgrSignalInterface =
129 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
130 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
131 new PackageManager::PkgmgrSignalDummy()
136 return showHelpAndQuit();
141 if (arg.find("wrt-installer") != std::string::npos) {
143 return showHelpAndQuit();
147 if (arg == "-h" || arg == "--help") {
149 return showHelpAndQuit();
153 return showHelpAndQuit();
154 } else if (arg == "-p" || arg == "--install-plugins") {
156 return showHelpAndQuit();
158 if (!m_startupPluginInstallation) {
159 AddStep(&WrtInstaller::installPluginsStep);
161 LogInfo("Plugin installation alredy started");
163 } else if (arg == "-i" || arg == "--install") {
165 return showHelpAndQuit();
169 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
170 LogInfo("Installing package directly from directory");
171 m_installPolicy = WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL;
173 LogInfo("Installing from regular location");
174 m_installPolicy = WRT_WIM_POLICY_WAC;
176 m_packagePath = m_argv[2];
177 AddStep(&WrtInstaller::installStep);
178 } else if (arg == "-if" || arg == "--install-force") {
180 return showHelpAndQuit();
183 m_packagePath = m_argv[2];
184 m_installPolicy = WRT_WIM_POLICY_FORCE_INSTALL;
185 AddStep(&WrtInstaller::installStep);
186 } else if (arg == "-il" || arg == "--install-preload") {
188 return showHelpAndQuit();
191 m_packagePath = m_argv[2];
192 m_preloadWidget = true;
193 m_installPolicy = WRT_WIM_POLICY_WAC;
194 AddStep(&WrtInstaller::installStep);
195 } else if (arg == "-un" || arg == "--uninstall-name") {
197 return showHelpAndQuit();
200 AddStep(&WrtInstaller::uninstallPkgNameStep);
201 } else if (arg == "-ug" || arg == "--uninstall-guid") {
203 return showHelpAndQuit();
206 AddStep(&WrtInstaller::uninstallGuidStep);
207 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
209 return showHelpAndQuit();
211 m_packagePath = m_argv[2];
212 AddStep(&WrtInstaller::unistallWgtFileStep);
214 return showHelpAndQuit();
216 } else if (arg.find("backend") != std::string::npos) {
217 using namespace PackageManager;
218 m_installByPkgmgr = true;
220 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
221 new PackageManager::PkgmgrSignal()
224 pkgmgrSignal->initialize(m_argc, m_argv);
225 m_quiet = pkgmgrSignal->isNoPopupRequired();
226 LogDebug("backend m_quiet" << m_quiet);
228 int reqType = pkgmgrSignal->getRequestedType();
230 pkgmgrSignalInterface =
231 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
234 case PKGMGR_REQ_INSTALL:
235 m_packagePath = m_argv[4];
237 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
238 LogInfo("Installing package directly from directory");
239 m_installPolicy = WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL;
241 LogInfo("Installing from regular location");
242 m_installPolicy = WRT_WIM_POLICY_WAC;
244 AddStep(&WrtInstaller::installStep);
246 case PKGMGR_REQ_UNINSTALL:
248 AddStep(&WrtInstaller::uninstallPkgNameStep);
251 LogDebug("Not available type");
256 AddStep(&WrtInstaller::shutdownStep);
257 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
259 WRTInstallerNS::NextStepEvent());
262 void WrtInstaller::OnReset(bundle *b)
264 const char * bundledVal = bundle_get_val(b, AUL_ARG_KEY);
265 if (bundledVal != NULL) {
266 m_bundleValue = bundledVal;
267 LogInfo("Bundled value for (" << AUL_ARG_KEY << ") key received: " <<
272 int WrtInstaller::getReturnStatus() const
274 if (!m_returnStatus) {
281 void WrtInstaller::OnTerminate()
283 LogDebug("Wrt Shutdown now");
284 PluginUtils::unlockPluginInstallation();
286 wrt_installer_shutdown();
291 void WrtInstaller::showHelpAndQuit()
293 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/GUID/PATH]...\n"
294 "Operate with WebRuntime daemon: install, uninstall"
295 " and launch widgets.\n"
296 "Query list of installed widgets and setup up debugging support.\n"
298 "Exactly one option must be selected.\n"
299 "Mandatory arguments to long options are mandatory for short "
301 " -h, --help show this help\n"
302 " -p, --install-plugins install plugins\n"
304 "install or update widget package for given path\n"
305 " -if, --install-force "
306 "install forcibly widget package for given path\n"
307 " -un, --uninstall-name "
308 "uninstall widget for given package name\n"
309 " -ug, --uninstall-guid "
310 "uninstall widget for given Global Unique IDentifier\n"
311 " -up, --uninstall-packagepath "
312 "uninstall widget for given package file path\n"
318 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
323 LogDebug("Wrt Shutdown now");
324 SwitchToStep(&WrtInstaller::shutdownStep);
325 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
327 WRTInstallerNS::NextStepEvent());
329 LogDebug("Quiting application");
334 void WrtInstaller::OnEventReceived(
335 const WRTInstallerNS::NextStepEvent& /*event*/)
337 LogDebug("Executing next step");
341 void WrtInstaller::OnEventReceived(
342 const WRTInstallerNS::InstallPluginEvent& /*event*/)
344 PluginInstallerData* privateData = new PluginInstallerData;
345 privateData->wrtInstaller = this;
347 if (!(*m_pluginsPaths).empty()) {
348 privateData->pluginPath = (*m_pluginsPaths).front();
349 (*m_pluginsPaths).pop_front();
351 wrt_install_plugin(privateData->pluginPath.c_str(),
352 static_cast<void*>(privateData),
353 &staticWrtPluginInstallationCallback,
354 &staticWrtPluginInstallProgressCb);
360 void WrtInstaller::initStep()
362 wrt_installer_init(this, staticWrtInitCallback);
365 void WrtInstaller::installStep()
367 LogDebug("Installing widget ...");
368 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
369 m_packagePath.c_str()));
371 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
372 this, &staticWrtStatusCallback,
373 (!m_quiet || m_installByPkgmgr)
374 ? &staticWrtInstallProgressCallback : NULL,
378 pkgmgrSignalInterface);
381 void WrtInstaller::installPluginsStep()
383 LogDebug("Installing plugins ...");
384 fprintf(stderr, "Installing plugins ...\n");
386 if (m_startupPluginInstallation) {
387 LogInfo("Plugin installation started because new plugin package found");
388 } else if (!PluginUtils::lockPluginInstallation()) {
389 LogError("Failed to open plugin installation lock file"
390 " Plugins are currently installed by other process");
391 staticWrtPluginInstallationCallback(WRT_PLUGIN_INSTALLER_ERROR_LOCK,
396 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
399 dir = opendir(PLUGIN_PATH.c_str());
405 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
406 struct dirent* libdir;
410 std::list<std::string> pluginsPaths;
412 while ((libdir = readdir(dir)) != 0) {
413 if (strcmp(libdir->d_name, ".") == 0 ||
414 strcmp(libdir->d_name, "..") == 0)
419 std::string path = PLUGIN_PATH;
421 path += libdir->d_name;
425 if (stat(path.c_str(), &tmp) == -1) {
426 LogError("Failed to open file" << path);
430 if (!S_ISDIR(tmp.st_mode)) {
431 LogError("Not a directory" << path);
435 pluginsPaths.push_back(path);
438 //set nb of plugins to install
439 //this value indicate how many callbacks are expected
440 m_numPluginsToInstall = pluginsPaths.size();
441 LogInfo("Plugins to install: " << m_numPluginsToInstall);
442 m_pluginsPaths = pluginsPaths;
444 m_totalPlugins = m_numPluginsToInstall;
445 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
446 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
448 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
449 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
450 << DPL::GetErrnoString());
454 void WrtInstaller::uninstallPkgNameStep()
456 LogDebug("Uninstalling widget ...");
457 LogDebug("Package name : " << m_name);
458 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
459 (!m_quiet || m_installByPkgmgr)
460 ? &staticWrtUninstallProgressCallback : NULL,
461 pkgmgrSignalInterface);
464 void WrtInstaller::uninstallGuidStep()
466 LogDebug("Uninstalling widget ...");
468 WrtErrStatus status = wrt_get_widget_by_guid(appid, m_name);
469 if (status == WRT_SUCCESS) {
470 LogDebug("Guid : " << m_name);
471 wrt_uninstall_widget(
472 appid.c_str(), this, &staticWrtStatusCallback,
473 !m_quiet ? &staticWrtUninstallProgressCallback :
475 pkgmgrSignalInterface);
477 printf("failed: can not uninstall widget\n");
478 LogError("Fail to uninstalling widget... ");
480 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
482 WRTInstallerNS::QuitEvent());
486 void WrtInstaller::unistallWgtFileStep()
488 LogDebug("Uninstalling widget ...");
493 ConfigParserData configInfo;
496 std::unique_ptr<DPL::ZipInput> zipFile(
497 new DPL::ZipInput(m_packagePath));
499 // Open config.xml file
500 std::unique_ptr<DPL::ZipInput::File> configFile(
501 zipFile->OpenFile(CONFIG_XML));
504 DPL::BinaryQueue buffer;
505 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
506 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
507 DPL::Copy(&inputAdapter, &outputAdapter);
508 parser.Parse(&buffer,
510 new RootParser<WidgetParser>(configInfo,
511 DPL::FromUTF32String(
514 DPL::OptionalString widgetGUID = configInfo.widget_id;
516 std::string guid = DPL::ToUTF8String(*widgetGUID);
519 WrtErrStatus status = wrt_get_widget_by_guid(appid, guid);
520 if (status == WRT_SUCCESS) {
521 LogDebug("Appid from packagePath : " << appid);
522 wrt_uninstall_widget(
523 appid.c_str(), this, &staticWrtStatusCallback,
524 !m_quiet ? &staticWrtUninstallProgressCallback
526 pkgmgrSignalInterface);
528 LogError("Fail to uninstalling widget... ");
530 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
532 WRTInstallerNS::QuitEvent());
535 Catch(DPL::ZipInput::Exception::OpenFailed)
537 LogError("Failed to open widget package");
538 printf("failed: widget package does not exist\n");
540 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
542 WRTInstallerNS::QuitEvent());
544 Catch(DPL::ZipInput::Exception::OpenFileFailed)
546 printf("failed: widget config file does not exist\n");
547 LogError("Failed to open config.xml file");
549 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
551 WRTInstallerNS::QuitEvent());
553 Catch(ElementParser::Exception::ParseError)
555 printf("failed: can not parse config file\n");
556 LogError("Failed to parse config.xml file");
558 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
560 WRTInstallerNS::QuitEvent());
564 void WrtInstaller::shutdownStep()
566 LogDebug("Closing Wrt connection ...");
568 wrt_installer_shutdown();
569 m_initialized = false;
570 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
572 WRTInstallerNS::QuitEvent());
576 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
579 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
582 if (status == WRT_SUCCESS) {
583 LogDebug("Init succesfull");
584 This->m_initialized = true;
585 This->m_returnStatus = 0;
587 if (This->popupsEnabled()) {
588 This->m_popup = new InstallerPopup;
589 This->m_popup->init();
592 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
593 ::PostEvent(WRTInstallerNS::NextStepEvent());
595 LogError("Init unsuccesfull");
596 This->m_returnStatus = -1;
597 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
599 WRTInstallerNS::QuitEvent());
603 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
607 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
610 Step current = This->GetCurrentStep();
611 DPL::String resultMsg;
612 std::string printMsg;
614 if (current == &WrtInstaller::installStep) {
615 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
616 printMsg = "installation";
617 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
618 current == &WrtInstaller::uninstallGuidStep ||
619 current == &WrtInstaller::unistallWgtFileStep)
621 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
622 printMsg = "uninstallation";
625 if (WRT_SUCCESS != status) {
627 LogError("Step failed");
628 This->m_returnStatus = -1;
630 if (This->popupsEnabled()) {
631 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
632 This->m_popup->showPopup(This, resultMsg, failResultCallback);
634 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
635 ::PostEvent(WRTInstallerNS::QuitEvent());
639 case WRT_INSTALLER_ERROR_INVALID_WIDGET_PACKAGE:
640 This->m_returnStatus = 1; //this status is specific
643 "## wrt-installer : %s %s has failed - invalid widget package\n",
648 case WRT_INSTALLER_ERROR_WIDGET_DOES_NOT_EXIST:
651 "## wrt-installer : %s %s has failed - widget package does not exist\n",
656 case WRT_INSTALLER_ERROR_ALREADY_UNINSTALLING:
659 "## wrt-installer : %s %s has failed - already uninstalling\n",
664 case WRT_INSTALLER_ERROR_OUT_OUT_DISK_SPACE:
666 "## wrt-installer : %s %s has failed - out of disk space\n",
671 case WRT_INSTALLER_ERROR_INVALID_CERTIFICATE:
674 "## wrt-installer : %s %s has failed - invalid certificate\n",
679 case WRT_INSTALLER_ERROR_ALREADY_INSTALLED:
681 "## wrt-installer : %s %s has failed - already installed\n",
686 case WRT_INSTALLER_ERROR_INTERNAL:
688 "## wrt-installer : %s %s has failed - internal error\n",
693 case WRT_INSTALLER_ERROR_NOT_ALLOWED:
696 "## wrt-installer : %s %s has failed - installation or update not allowed; invalid"
702 case WRT_INSTALLER_ERROR_DEFERRED:
705 "## wrt-installer : deferred: widget update will continue after the widget"
706 " has been stopped\n");
709 case WRT_INSTALLER_ERROR_DATABASE_FAILURE:
711 "## wrt-installer : %s %s has failed - database failure\n",
716 case WRT_INSTALLER_ERROR_OSPSVC:
719 "## wrt-installer : %s %s has failed - during installation or"
720 " uninstallation osp service\n",
725 case WRT_INSTALLER_ERROR_UNKNOWN:
727 "## wrt-installer : %s %s has failed - unknown error\n",
737 "## wrt-installer : %s %s was successful.\n",
740 LogDebug("Status succesfull");
741 This->m_returnStatus = 0;
742 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
744 if (This->popupsEnabled()) {
745 This->m_popup->showPopup(This, resultMsg, showResultCallback);
747 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
749 ::PostEvent(WRTInstallerNS::NextStepEvent());
754 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
759 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
761 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
763 std::string path = std::string(data->pluginPath);
766 This->m_numPluginsToInstall--;
767 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
769 if (This->m_numPluginsToInstall < 1) {
770 LogDebug("All plugins installation completed");
771 fprintf(stderr, "All plugins installation completed.\n");
773 //remove installation request
774 if (!PluginUtils::removeInstallationRequiredFlag()) {
775 LogInfo("Failed to remove file initializing plugin installation");
779 if (!PluginUtils::unlockPluginInstallation()) {
780 LogInfo("Failed to remove installation lock");
783 if (This->popupsEnabled()) {
784 This->m_popup->init();
785 elm_progressbar_value_set(This->m_popup->m_progressbar, 100.0);
786 evas_object_show(This->m_popup->m_popup);
789 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
790 ::PostEvent(WRTInstallerNS::NextStepEvent());
792 if (This->popupsEnabled()) {
793 This->m_popup->init();
795 (This->m_totalPlugins -
796 This->m_numPluginsToInstall) / (float)This->m_totalPlugins;
797 elm_progressbar_value_set(This->m_popup->m_progressbar, percent);
798 evas_object_show(This->m_popup->m_popup);
801 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
802 InstallPluginEvent>::
804 WRTInstallerNS::InstallPluginEvent());
807 if (WRT_SUCCESS == status) {
808 This->m_returnStatus = 0;
810 "## wrt-installer : plugin installation successfull [%s]\n",
812 LogDebug("One plugin Installation succesfull: " << path);
817 LogWarning("One of the plugins installation failed!: " << path);
819 if (WRT_PLUGIN_INSTALLER_ERROR_WAITING == status) {
820 LogInfo("Plugin installation is waiting for dependencies");
821 fprintf(stderr, "## wrt-installer : plugin installation failed [%s]\n",
826 case WRT_PLUGIN_INSTALLER_ERROR_WRONG_PATH:
827 LogError("failed: wrong path to plugin directory\n");
830 case WRT_PLUGIN_INSTALLER_ERROR_METAFILE:
831 LogError("failed: plugin metafile error\n");
834 case WRT_PLUGIN_INSTALLER_ERROR_ALREADY_INSTALLED:
835 LogError("failed: plugin already installed\n");
838 case WRT_PLUGIN_INSTALLER_ERROR_LIBRARY_ERROR:
839 LogError("failed: plugin library: missing symbols or structures\n");
842 case WRT_PLUGIN_INSTALLER_ERROR_UNKNOWN:
843 LogError("failed: unknown error\n");
851 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
852 const char* description,
855 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
857 std::string path = std::string(data->pluginPath);
859 LogInfo("Plugin Installation: " << path <<
860 " progress: " << percent <<
861 "description " << description);
864 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
865 const char* description,
868 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
869 std::stringstream percentStr;
870 LogInfo(" progress: " << percent <<
871 " description: " << description);
873 if (This->popupsEnabled()) {
874 This->m_popup->init();
875 elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
876 evas_object_show(This->m_popup->m_popup);
879 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
880 const char* description,
883 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
884 std::stringstream percentStr;
885 LogInfo(" progress: " << percent <<
886 " description: " << description);
888 if (This->popupsEnabled()) {
889 This->m_popup->init();
890 elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
891 evas_object_show(This->m_popup->m_popup);
895 WrtInstaller::InstallerPopup::InstallerPopup() :
901 WrtInstaller::InstallerPopup::~InstallerPopup()
903 LogDebug("App Finished");
906 void WrtInstaller::InstallerPopup::init()
908 LogDebug("Window Init");
912 m_win = createWin("wrt-installer");
915 m_popup = elm_popup_add(m_win);
917 // create progressbar
918 m_progressbar = elm_progressbar_add(m_popup);
919 elm_object_style_set(m_progressbar, "list_progress");
920 elm_progressbar_horizontal_set(m_progressbar, EINA_TRUE);
921 evas_object_size_hint_align_set(m_progressbar, EVAS_HINT_FILL,
923 evas_object_size_hint_weight_set(m_progressbar, EVAS_HINT_EXPAND,
925 elm_object_content_set(m_popup, m_progressbar);
926 elm_progressbar_value_set(m_progressbar, 0.0);
927 evas_object_show(m_progressbar);
929 evas_object_show(m_popup);
930 evas_object_show(m_win);
934 Evas_Object* WrtInstaller::InstallerPopup::createWin(const char *name)
937 win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
944 elm_win_alpha_set(win, EINA_TRUE);
945 elm_win_title_set(win, name);
946 elm_win_borderless_set(win, EINA_TRUE);
949 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
950 evas_object_resize(win, w, h);
954 void WrtInstaller::InstallerPopup::showPopup(void* userdata,
955 const DPL::String& pkgMsg,
956 ShowResultCallback callback)
960 LogDebug("Result Popup Created");
961 evas_object_del(m_popup);
964 m_popup = elm_popup_add(m_win);
969 btn = elm_button_add(m_popup);
971 evas_object_del(m_popup);
974 elm_object_text_set(btn, "OK");
975 evas_object_smart_callback_add(btn, "clicked", callback, userdata);
976 elm_object_part_content_set(m_popup, "button1", btn);
977 elm_object_part_text_set(m_popup, "title,text", "RESULT");
978 elm_object_text_set(m_popup, DPL::ToUTF8String(pkgMsg).c_str());
980 evas_object_show(m_popup);
981 evas_object_show(m_win);
984 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
985 void* /*event_info*/)
987 WrtInstaller *This = static_cast<WrtInstaller*>(data);
990 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
991 ::PostEvent(WRTInstallerNS::NextStepEvent());
994 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
995 void* /*event_info*/)
997 WrtInstaller *This = static_cast<WrtInstaller*>(data);
1000 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
1001 ::PostEvent(WRTInstallerNS::QuitEvent());
1004 void WrtInstaller::installNewPlugins()
1006 LogDebug("Install new plugins");
1008 if (!PluginUtils::lockPluginInstallation()) {
1009 LogInfo("Lock NOT created");
1013 if (!PluginUtils::checkPluginInstallationRequired()) {
1014 LogDebug("Plugin installation not required");
1015 PluginUtils::unlockPluginInstallation();
1019 m_startupPluginInstallation = true;
1020 AddStep(&WrtInstaller::installPluginsStep);
1023 bool WrtInstaller::popupsEnabled() const
1025 return !m_quiet && !GlobalSettings::PopupsTestModeEnabled();
1028 int main(int argc, char *argv[])
1030 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1032 // Output on stdout will be flushed after every newline character,
1033 // even if it is redirected to a pipe. This is useful for running
1034 // from a script and parsing output.
1035 // (Standard behavior of stdlib is to use full buffering when
1036 // redirected to a pipe, which means even after an end of line
1037 // the output may not be flushed).
1040 // Check and re-set the file open limitation
1042 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1043 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
1044 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
1046 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1047 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1048 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1049 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1050 LogError("setrlimit is fail!!");
1054 LogError("getrlimit is fail!!");
1057 // set evas backend type for emulator
1058 // popup isn't showed in the emulator,
1059 // if backend isn't set to SW backend
1060 if (GlobalSettings::IsEmulator()) {
1061 if (setenv("ELM_ENGINE", "x11", 1)) {
1062 LogDebug("Enable backend");
1066 WrtInstaller app(argc, argv);
1067 int ret = app.Exec();
1068 LogDebug("App returned: " << ret);
1069 ret = app.getReturnStatus();
1070 LogDebug("WrtInstaller returned: " << ret);
1073 UNHANDLED_EXCEPTION_HANDLER_END