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>
30 #include <dpl/log/log.h>
31 #include <dpl/optional.h>
32 #include <dpl/optional_typedefs.h>
33 #include <dpl/exception.h>
34 #include <dpl/wrt-dao-ro/global_config.h>
35 #include <dpl/wrt-dao-ro/config_parser_data.h>
36 #include <dpl/string.h>
37 #include <dpl/abstract_waitable_input_adapter.h>
38 #include <dpl/abstract_waitable_output_adapter.h>
39 #include <dpl/zip_input.h>
40 #include <dpl/binary_queue.h>
42 #include <dpl/errno_string.h>
43 #include <dpl/utils/wrt_global_settings.h>
44 #include <parser_runner.h>
45 #include <widget_parser.h>
46 #include <root_parser.h>
48 #include <Elementary.h>
50 #include <pkg-manager/pkgmgr_signal_interface.h>
51 #include <pkg-manager/pkgmgr_signal_dummy.h>
52 #include <pkg-manager/pkgmgr_signal.h>
54 using namespace WrtDB;
56 namespace { // anonymous
57 const char * const PKGMGR_INSTALL_MSG = "Install widget";
58 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
60 const char * const CONFIG_XML = "config.xml";
61 const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
63 const unsigned int NOFILE_CNT_FOR_INSTALLER = 9999;
67 void operator()(void* x)
73 struct PluginInstallerData
76 std::string pluginPath;
78 } // namespace anonymous
80 WrtInstaller::WrtInstaller(int argc, char **argv) :
81 Application(argc, argv, "backend", false),
82 DPL::TaskDecl<WrtInstaller>(this),
83 m_installMode(WRT_INSTALL_MODE_UNKNOWN),
86 m_numPluginsToInstall(0),
89 m_installByPkgmgr(false),
92 m_startupPluginInstallation(false)
95 LogDebug("App Created");
98 WrtInstaller::~WrtInstaller()
100 LogDebug("App Finished");
103 int WrtInstaller::getReturnStatus() const
105 if (!m_returnStatus) {
112 WrtInstaller::InstallerPopup::InstallerPopup() :
118 WrtInstaller::InstallerPopup::~InstallerPopup()
120 LogDebug("App Finished");
123 void WrtInstaller::InstallerPopup::init()
125 LogDebug("Window Init");
129 m_win = createWin("wrt-installer");
132 m_popup = elm_popup_add(m_win);
134 // create progressbar
135 m_progressbar = elm_progressbar_add(m_popup);
136 elm_object_style_set(m_progressbar, "list_progress");
137 elm_progressbar_horizontal_set(m_progressbar, EINA_TRUE);
138 evas_object_size_hint_align_set(m_progressbar, EVAS_HINT_FILL,
140 evas_object_size_hint_weight_set(m_progressbar, EVAS_HINT_EXPAND,
142 elm_object_content_set(m_popup, m_progressbar);
143 elm_progressbar_value_set(m_progressbar, 0.0);
144 evas_object_show(m_progressbar);
146 evas_object_show(m_popup);
147 evas_object_show(m_win);
151 Evas_Object* WrtInstaller::InstallerPopup::createWin(const char *name)
154 win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
161 elm_win_alpha_set(win, EINA_TRUE);
162 elm_win_title_set(win, name);
163 elm_win_borderless_set(win, EINA_TRUE);
166 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
167 evas_object_resize(win, w, h);
171 void WrtInstaller::InstallerPopup::showPopup(void* userdata,
172 const DPL::String& pkgMsg,
173 ShowResultCallback callback)
177 LogDebug("Result Popup Created");
178 evas_object_del(m_popup);
181 m_popup = elm_popup_add(m_win);
186 btn = elm_button_add(m_popup);
188 evas_object_del(m_popup);
191 elm_object_text_set(btn, "OK");
192 evas_object_smart_callback_add(btn, "clicked", callback, userdata);
193 elm_object_part_content_set(m_popup, "button1", btn);
194 elm_object_part_text_set(m_popup, "title,text", "RESULT");
195 elm_object_text_set(m_popup, DPL::ToUTF8String(pkgMsg).c_str());
197 evas_object_show(m_popup);
198 evas_object_show(m_win);
201 void WrtInstaller::OnStop()
203 LogInfo("Stopping Dummy Client");
206 void WrtInstaller::OnCreate()
208 LogInfo("Creating DummyClient");
210 "===========================================================\n");
211 fprintf(stderr, "# wrt-installer #\n");
212 fprintf(stderr, "# argc [%d]\n", m_argc);
213 fprintf(stderr, "# argv[0] = [%s]\n", m_argv[0]);
214 fprintf(stderr, "# argv[1] = [%s]\n", m_argv[1]);
215 fprintf(stderr, "# argv[2] = [%s]\n", m_argv[2]);
217 "===========================================================\n");
219 AddStep(&WrtInstaller::initStep);
221 std::string arg = m_argv[0];
223 pkgmgrSignalInterface =
224 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
225 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
226 new PackageManager::PkgmgrSignalDummy()
231 return showHelpAndQuit();
236 if (arg.find("wrt-installer") != std::string::npos) {
238 return showHelpAndQuit();
242 if (arg == "-h" || arg == "--help") {
244 return showHelpAndQuit();
248 return showHelpAndQuit();
249 } else if (arg == "-p" || arg == "--install-plugins") {
251 return showHelpAndQuit();
253 if (!m_startupPluginInstallation) {
254 AddStep(&WrtInstaller::installPluginsStep);
256 LogInfo("Plugin installation alredy started");
258 } else if (arg == "-i" || arg == "--install") {
260 return showHelpAndQuit();
264 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
265 LogInfo("Installing package directly from directory");
266 m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
268 LogInfo("Installing from regular location");
269 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
271 m_packagePath = m_argv[2];
272 AddStep(&WrtInstaller::installStep);
273 } else if (arg == "-il" || arg == "--install-preload") {
275 return showHelpAndQuit();
277 m_packagePath = m_argv[2];
278 m_installMode = WRT_INSTALL_MODE_INSTALL_PRELOAD;
279 AddStep(&WrtInstaller::installStep);
280 } else if (arg == "-un" || arg == "--uninstall-name") {
282 return showHelpAndQuit();
285 AddStep(&WrtInstaller::uninstallPkgNameStep);
286 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
288 return showHelpAndQuit();
290 m_packagePath = m_argv[2];
291 AddStep(&WrtInstaller::unistallWgtFileStep);
292 } else if (arg == "-r" || arg == "--reinstall") {
294 return showHelpAndQuit();
296 LogInfo("Installing package directly from directory");
297 m_installMode = WRT_INSTALL_MODE_REINSTALL;
298 m_packagePath = m_argv[2];
299 AddStep(&WrtInstaller::installStep);
301 return showHelpAndQuit();
303 } else if (arg.find("backend") != std::string::npos) {
304 using namespace PackageManager;
305 m_installByPkgmgr = true;
307 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
308 new PackageManager::PkgmgrSignal()
311 pkgmgrSignal->initialize(m_argc, m_argv);
312 m_quiet = pkgmgrSignal->isNoPopupRequired();
313 LogDebug("backend m_quiet" << m_quiet);
315 int reqType = pkgmgrSignal->getRequestedType();
317 pkgmgrSignalInterface =
318 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
321 case PKGMGR_REQ_INSTALL:
322 m_packagePath = m_argv[4];
324 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
325 LogInfo("Installing package directly from directory");
326 m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
328 LogInfo("Installing from regular location");
329 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
331 AddStep(&WrtInstaller::installStep);
333 case PKGMGR_REQ_UNINSTALL:
335 AddStep(&WrtInstaller::uninstallPkgNameStep);
337 case PKGMGR_REQ_REINSTALL:
338 m_packagePath = m_argv[4];
339 m_installMode = WRT_INSTALL_MODE_REINSTALL;
340 AddStep(&WrtInstaller::installStep);
343 LogDebug("Not available type");
348 AddStep(&WrtInstaller::shutdownStep);
349 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
351 WRTInstallerNS::NextStepEvent());
354 void WrtInstaller::OnReset(bundle* /*b*/)
359 void WrtInstaller::OnTerminate()
361 LogDebug("Wrt Shutdown now");
362 PluginUtils::unlockPluginInstallation();
364 wrt_installer_shutdown();
369 void WrtInstaller::showHelpAndQuit()
371 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
372 "Operate with WebRuntime daemon: install, uninstall"
373 " and launch widgets.\n"
374 "Query list of installed widgets and setup up debugging support.\n"
376 "Exactly one option must be selected.\n"
377 "Mandatory arguments to long options are mandatory for short "
379 " -h, --help show this help\n"
380 " -p, --install-plugins install plugins\n"
382 "install or update widget package for given path\n"
383 " -un, --uninstall-name "
384 "uninstall widget for given package name\n"
385 " -up, --uninstall-packagepath "
386 "uninstall widget for given package file path\n"
388 "reinstall web application\n"
394 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
399 LogDebug("Wrt Shutdown now");
400 SwitchToStep(&WrtInstaller::shutdownStep);
401 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
403 WRTInstallerNS::NextStepEvent());
405 LogDebug("Quiting application");
410 void WrtInstaller::OnEventReceived(
411 const WRTInstallerNS::NextStepEvent& /*event*/)
413 LogDebug("Executing next step");
417 void WrtInstaller::OnEventReceived(
418 const WRTInstallerNS::InstallPluginEvent& /*event*/)
420 PluginInstallerData* privateData = new PluginInstallerData;
421 privateData->wrtInstaller = this;
423 if (!(*m_pluginsPaths).empty()) {
424 privateData->pluginPath = (*m_pluginsPaths).front();
425 (*m_pluginsPaths).pop_front();
427 wrt_install_plugin(privateData->pluginPath.c_str(),
428 static_cast<void*>(privateData),
429 &staticWrtPluginInstallationCallback,
430 &staticWrtPluginInstallProgressCb);
436 void WrtInstaller::initStep()
438 wrt_installer_init(this, staticWrtInitCallback);
441 void WrtInstaller::installStep()
443 LogDebug("Installing widget ...");
444 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
445 m_packagePath.c_str()));
447 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
448 this, &staticWrtStatusCallback,
449 (!m_quiet || m_installByPkgmgr)
450 ? &staticWrtInstallProgressCallback : NULL,
453 pkgmgrSignalInterface);
456 void WrtInstaller::installPluginsStep()
458 LogDebug("Installing plugins ...");
459 fprintf(stderr, "Installing plugins ...\n");
461 if (m_startupPluginInstallation) {
462 LogInfo("Plugin installation started because new plugin package found");
463 } else if (!PluginUtils::lockPluginInstallation()) {
464 LogError("Failed to open plugin installation lock file"
465 " Plugins are currently installed by other process");
466 staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
471 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
474 dir = opendir(PLUGIN_PATH.c_str());
480 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
482 std::list<std::string> pluginsPaths;
483 struct dirent libdir;
484 struct dirent *result;
487 for (return_code = readdir_r(dir, &libdir, &result);
488 result != NULL && return_code == 0;
489 return_code = readdir_r(dir, &libdir, &result))
491 if (strcmp(libdir.d_name, ".") == 0 ||
492 strcmp(libdir.d_name, "..") == 0)
497 std::string path = PLUGIN_PATH;
499 path += libdir.d_name;
503 if (stat(path.c_str(), &tmp) == -1) {
504 LogError("Failed to open file" << path);
508 if (!S_ISDIR(tmp.st_mode)) {
509 LogError("Not a directory" << path);
513 pluginsPaths.push_back(path);
516 if (return_code != 0 || errno != 0) {
517 LogError("readdir_r() failed with " << DPL::GetErrnoString());
520 //set nb of plugins to install
521 //this value indicate how many callbacks are expected
522 m_numPluginsToInstall = pluginsPaths.size();
523 LogInfo("Plugins to install: " << m_numPluginsToInstall);
524 m_pluginsPaths = pluginsPaths;
526 m_totalPlugins = m_numPluginsToInstall;
527 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
528 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
530 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
531 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
532 << DPL::GetErrnoString());
536 void WrtInstaller::uninstallPkgNameStep()
538 LogDebug("Uninstalling widget ...");
539 LogDebug("Package name : " << m_name);
540 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
541 (!m_quiet || m_installByPkgmgr)
542 ? &staticWrtUninstallProgressCallback : NULL,
543 pkgmgrSignalInterface);
546 void WrtInstaller::unistallWgtFileStep()
548 LogDebug("Uninstalling widget ...");
553 ConfigParserData configInfo;
556 std::unique_ptr<DPL::ZipInput> zipFile(
557 new DPL::ZipInput(m_packagePath));
558 std::unique_ptr<DPL::ZipInput::File> configFile;
561 // Open config.xml file
562 configFile.reset(zipFile->OpenFile(CONFIG_XML));
564 Catch(DPL::ZipInput::Exception::OpenFileFailed)
566 // Open config.xml file for hybrid
567 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
571 DPL::BinaryQueue buffer;
572 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
573 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
574 DPL::Copy(&inputAdapter, &outputAdapter);
575 parser.Parse(&buffer,
577 new RootParser<WidgetParser>(configInfo,
578 DPL::FromUTF32String(
581 DPL::OptionalString pkgId = configInfo.tizenPkgId;
582 if (!pkgId.IsNull()) {
583 LogDebug("Pkgid from packagePath : " << pkgId);
584 wrt_uninstall_widget(
585 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
586 !m_quiet ? &staticWrtUninstallProgressCallback
588 pkgmgrSignalInterface);
590 LogError("Fail to uninstalling widget... ");
592 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
594 WRTInstallerNS::QuitEvent());
597 Catch(DPL::ZipInput::Exception::OpenFailed)
599 LogError("Failed to open widget package");
600 printf("failed: widget package does not exist\n");
602 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
604 WRTInstallerNS::QuitEvent());
606 Catch(DPL::ZipInput::Exception::OpenFileFailed)
608 printf("failed: widget config file does not exist\n");
609 LogError("Failed to open config.xml file");
611 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
613 WRTInstallerNS::QuitEvent());
615 Catch(ElementParser::Exception::ParseError)
617 printf("failed: can not parse config file\n");
618 LogError("Failed to parse config.xml file");
620 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
622 WRTInstallerNS::QuitEvent());
626 void WrtInstaller::shutdownStep()
628 LogDebug("Closing Wrt connection ...");
630 wrt_installer_shutdown();
631 m_initialized = false;
632 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
634 WRTInstallerNS::QuitEvent());
638 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
641 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
644 if (status == WRT_SUCCESS) {
645 LogDebug("Init succesfull");
646 This->m_initialized = true;
647 This->m_returnStatus = 0;
649 if (This->popupsEnabled()) {
650 This->m_popup = new InstallerPopup;
651 This->m_popup->init();
654 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
655 ::PostEvent(WRTInstallerNS::NextStepEvent());
657 LogError("Init unsuccesfull");
658 This->m_returnStatus = -1;
659 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
661 WRTInstallerNS::QuitEvent());
665 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
669 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
672 Step current = This->GetCurrentStep();
673 DPL::String resultMsg;
674 std::string printMsg;
676 if (current == &WrtInstaller::installStep) {
677 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
678 printMsg = "installation";
679 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
680 current == &WrtInstaller::unistallWgtFileStep)
682 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
683 printMsg = "uninstallation";
686 if (WRT_SUCCESS != status) {
688 LogError("Step failed");
689 This->m_returnStatus = -1;
691 if (This->popupsEnabled()) {
692 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
693 This->m_popup->showPopup(This, resultMsg, failResultCallback);
695 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
696 ::PostEvent(WRTInstallerNS::QuitEvent());
700 case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
701 This->m_returnStatus = 1; //this status is specific
702 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
703 tizenId.c_str(), printMsg.c_str());
706 case WRT_INSTALLER_ERROR_PACKAGE_INVALID:
707 This->m_returnStatus = 1; //this status is specific
708 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
709 tizenId.c_str(), printMsg.c_str());
712 case WRT_INSTALLER_ERROR_PACKAGE_LOWER_VERSION:
713 This->m_returnStatus = 1; //this status is specific
714 fprintf(stderr, "## wrt-installer : %s %s has failed - given"
715 " version is lower than existing version\n",
716 tizenId.c_str(), printMsg.c_str());
719 case WRT_INSTALLER_ERROR_MANIFEST_NOT_FOUND:
720 This->m_returnStatus = 1; //this status is specific
721 fprintf(stderr, "## wrt-installer : %s %s has failed - manifest"
722 " file doesn't find in package.\n",
723 tizenId.c_str(), printMsg.c_str());
726 case WRT_INSTALLER_ERROR_MANIFEST_INVALID:
727 This->m_returnStatus = 1; //this status is specific
728 fprintf(stderr, "## wrt-installer : %s %s has failed - "
729 "invalid manifestx.xml\n",
730 tizenId.c_str(), printMsg.c_str());
733 case WRT_INSTALLER_CONFIG_NOT_FOUND:
734 This->m_returnStatus = 1; //this status is specific
735 fprintf(stderr, "## wrt-installer : %s %s has failed - "
736 "config.xml does not exist\n",
737 tizenId.c_str(), printMsg.c_str());
740 case WRT_INSTALLER_ERROR_CONFIG_INVALID:
741 This->m_returnStatus = 1; //this status is specific
742 fprintf(stderr, "## wrt-installer : %s %s has failed - "
743 "invalid config.xml\n",
744 tizenId.c_str(), printMsg.c_str());
747 case WRT_INSTALLER_ERROR_SIGNATURE_NOT_FOUND:
748 This->m_returnStatus = 1; //this status is specific
749 fprintf(stderr, "## wrt-installer : %s %s has failed - "
750 "signature doesn't exist in package.\n",
751 tizenId.c_str(), printMsg.c_str());
754 case WRT_INSTALLER_ERROR_SIGNATURE_INVALID:
755 This->m_returnStatus = 1; //this status is specific
756 fprintf(stderr, "## wrt-installer : %s %s has failed - "
757 "invalid signature.\n",
758 tizenId.c_str(), printMsg.c_str());
761 case WRT_INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED:
762 This->m_returnStatus = 1; //this status is specific
763 fprintf(stderr, "## wrt-installer : %s %s has failed - "
764 "signature verification failed.\n",
765 tizenId.c_str(), printMsg.c_str());
768 case WRT_INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND:
769 This->m_returnStatus = 1; //this status is specific
770 fprintf(stderr, "## wrt-installer : %s %s has failed - "
771 "root certificate could not find.\n",
772 tizenId.c_str(), printMsg.c_str());
775 case WRT_INSTALLER_ERROR_CERTIFICATION_INVAID:
776 This->m_returnStatus = 1; //this status is specific
777 fprintf(stderr, "## wrt-installer : %s %s has failed - "
778 "invalid certification.\n",
779 tizenId.c_str(), printMsg.c_str());
782 case WRT_INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
783 This->m_returnStatus = 1; //this status is specific
784 fprintf(stderr, "## wrt-installer : %s %s has failed - "
785 "certificate chain verification failed.\n",
786 tizenId.c_str(), printMsg.c_str());
789 case WRT_INSTALLER_ERROR_CERTIFICATE_EXPIRED:
790 This->m_returnStatus = 1; //this status is specific
791 fprintf(stderr, "## wrt-installer : %s %s has failed - "
792 "certificate expired.\n",
793 tizenId.c_str(), printMsg.c_str());
796 case WRT_INSTALLER_ERROR_INVALID_PRIVILEGE:
797 This->m_returnStatus = 1; //this status is specific
798 fprintf(stderr, "## wrt-installer : %s %s has failed - "
799 "invalid privilege\n",
800 tizenId.c_str(), printMsg.c_str());
803 case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
804 This->m_returnStatus = 1; //this status is specific
805 fprintf(stderr, "## wrt-installer : %s %s has failed - "
806 "menu icon could not find\n",
807 tizenId.c_str(), printMsg.c_str());
810 case WRT_INSTALLER_ERROR_FATAL_ERROR:
811 This->m_returnStatus = 1; //this status is specific
812 fprintf(stderr, "## wrt-installer : %s %s has failed - "
814 tizenId.c_str(), printMsg.c_str());
817 case WRT_INSTALLER_ERROR_OUT_OF_STORAGE:
818 This->m_returnStatus = 1; //this status is specific
819 fprintf(stderr, "## wrt-installer : %s %s has failed - "
821 tizenId.c_str(), printMsg.c_str());
824 case WRT_INSTALLER_ERROR_OUT_OF_MEMORY:
825 This->m_returnStatus = 1; //this status is specific
826 fprintf(stderr, "## wrt-installer : %s %s has failed - "
828 tizenId.c_str(), printMsg.c_str());
831 case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
832 This->m_returnStatus = 1; //this status is specific
833 fprintf(stderr, "## wrt-installer : %s %s has failed - "
834 "package already installed\n",
835 tizenId.c_str(), printMsg.c_str());
838 case WRT_INSTALLER_ERROR_ACE_CHECK_FAILED:
839 This->m_returnStatus = 1; //this status is specific
840 fprintf(stderr, "## wrt-installer : %s %s has failed - "
841 "ace check failure\n",
842 tizenId.c_str(), printMsg.c_str());
845 case WRT_INSTALLER_ERROR_MANIFEST_CREATE_FAILED:
846 This->m_returnStatus = 1; //this status is specific
847 fprintf(stderr, "## wrt-installer : %s %s has failed - "
848 "to create manifest failed\n",
849 tizenId.c_str(), printMsg.c_str());
852 case WRT_INSTALLER_ERROR_ENCRYPTION_FAILED:
853 This->m_returnStatus = 1; //this status is specific
854 fprintf(stderr, "## wrt-installer : %s %s has failed - "
855 "encryption of resource failed\n",
856 tizenId.c_str(), printMsg.c_str());
859 case WRT_INSTALLER_ERROR_INSTALL_OSP_SERVCIE:
860 This->m_returnStatus = 1; //this status is specific
861 fprintf(stderr, "## wrt-installer : %s %s has failed - "
862 "installation of osp service failed\n",
863 tizenId.c_str(), printMsg.c_str());
866 case WRT_INSTALLER_ERROR_UNINSTALLATION_FAILED:
867 This->m_returnStatus = 1; //this status is specific
868 fprintf(stderr, "## wrt-installer : %s %s has failed - "
869 "widget uninstallation failed\n",
870 tizenId.c_str(), printMsg.c_str());
874 case WRT_INSTALLER_ERROR_UNKNOWN:
875 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
876 tizenId.c_str(), printMsg.c_str());
884 "## wrt-installer : %s %s was successful.\n",
887 LogDebug("Status succesfull");
888 This->m_returnStatus = 0;
889 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
891 if (This->popupsEnabled()) {
892 This->m_popup->showPopup(This, resultMsg, showResultCallback);
894 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
896 ::PostEvent(WRTInstallerNS::NextStepEvent());
901 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
906 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
908 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
910 std::string path = std::string(data->pluginPath);
913 This->m_numPluginsToInstall--;
914 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
916 if (This->m_numPluginsToInstall < 1) {
917 LogDebug("All plugins installation completed");
918 fprintf(stderr, "All plugins installation completed.\n");
920 //remove installation request
921 if (!PluginUtils::removeInstallationRequiredFlag()) {
922 LogInfo("Failed to remove file initializing plugin installation");
926 if (!PluginUtils::unlockPluginInstallation()) {
927 LogInfo("Failed to remove installation lock");
930 if (This->popupsEnabled()) {
931 This->m_popup->init();
932 elm_progressbar_value_set(This->m_popup->m_progressbar, 100.0);
933 evas_object_show(This->m_popup->m_popup);
936 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
937 ::PostEvent(WRTInstallerNS::NextStepEvent());
939 if (This->popupsEnabled()) {
940 This->m_popup->init();
942 (This->m_totalPlugins -
943 This->m_numPluginsToInstall) / (float)This->m_totalPlugins;
944 elm_progressbar_value_set(This->m_popup->m_progressbar, percent);
945 evas_object_show(This->m_popup->m_popup);
948 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
949 InstallPluginEvent>::
951 WRTInstallerNS::InstallPluginEvent());
954 if (WRT_SUCCESS == status) {
955 This->m_returnStatus = 0;
957 "## wrt-installer : plugin installation successfull [%s]\n",
959 LogDebug("One plugin Installation succesfull: " << path);
964 LogWarning("One of the plugins installation failed!: " << path);
967 case WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED:
968 LogError("failed: plugin installation failed\n");
971 case WRT_INSTALLER_ERROR_UNKNOWN:
972 LogError("failed: unknown error\n");
980 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
981 const char* description,
984 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
986 std::string path = std::string(data->pluginPath);
988 LogInfo("Plugin Installation: " << path <<
989 " progress: " << percent <<
990 "description " << description);
993 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
994 const char* description,
997 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
998 LogInfo(" progress: " << percent <<
999 " description: " << description);
1001 if (This->popupsEnabled()) {
1002 This->m_popup->init();
1003 elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
1004 evas_object_show(This->m_popup->m_popup);
1007 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
1008 const char* description,
1011 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
1012 LogInfo(" progress: " << percent <<
1013 " description: " << description);
1015 if (This->popupsEnabled()) {
1016 This->m_popup->init();
1017 elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
1018 evas_object_show(This->m_popup->m_popup);
1022 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
1023 void* /*event_info*/)
1025 WrtInstaller *This = static_cast<WrtInstaller*>(data);
1028 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
1029 ::PostEvent(WRTInstallerNS::NextStepEvent());
1032 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
1033 void* /*event_info*/)
1035 WrtInstaller *This = static_cast<WrtInstaller*>(data);
1038 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
1039 ::PostEvent(WRTInstallerNS::QuitEvent());
1042 void WrtInstaller::installNewPlugins()
1044 LogDebug("Install new plugins");
1046 if (!PluginUtils::lockPluginInstallation()) {
1047 LogInfo("Lock NOT created");
1051 if (!PluginUtils::checkPluginInstallationRequired()) {
1052 LogDebug("Plugin installation not required");
1053 PluginUtils::unlockPluginInstallation();
1057 m_startupPluginInstallation = true;
1058 AddStep(&WrtInstaller::installPluginsStep);
1061 bool WrtInstaller::popupsEnabled() const
1063 return !m_quiet && !GlobalSettings::PopupsTestModeEnabled();
1066 int main(int argc, char *argv[])
1068 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1070 // Output on stdout will be flushed after every newline character,
1071 // even if it is redirected to a pipe. This is useful for running
1072 // from a script and parsing output.
1073 // (Standard behavior of stdlib is to use full buffering when
1074 // redirected to a pipe, which means even after an end of line
1075 // the output may not be flushed).
1078 // Check and re-set the file open limitation
1080 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1081 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
1082 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
1084 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1085 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1086 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1087 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1088 LogError("setrlimit is fail!!");
1092 LogError("getrlimit is fail!!");
1095 // set evas backend type for emulator
1096 // popup isn't showed in the emulator,
1097 // if backend isn't set to SW backend
1098 if (GlobalSettings::IsEmulator()) {
1099 if (setenv("ELM_ENGINE", "x11", 1)) {
1100 LogDebug("Enable backend");
1104 WrtInstaller app(argc, argv);
1105 int ret = app.Exec();
1106 LogDebug("App returned: " << ret);
1107 ret = app.getReturnStatus();
1108 LogDebug("WrtInstaller returned: " << ret);
1111 UNHANDLED_EXCEPTION_HANDLER_END