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>
31 #include <dpl/log/log.h>
32 #include <dpl/optional.h>
33 #include <dpl/optional_typedefs.h>
34 #include <dpl/exception.h>
35 #include <dpl/wrt-dao-ro/global_config.h>
36 #include <dpl/wrt-dao-ro/config_parser_data.h>
37 #include <dpl/string.h>
38 #include <dpl/abstract_waitable_input_adapter.h>
39 #include <dpl/abstract_waitable_output_adapter.h>
40 #include <dpl/zip_input.h>
41 #include <dpl/binary_queue.h>
43 #include <dpl/errno_string.h>
44 #include <dpl/utils/wrt_global_settings.h>
45 #include <dpl/utils/wrt_utility.h>
46 #include <parser_runner.h>
47 #include <widget_parser.h>
48 #include <root_parser.h>
50 #include <Elementary.h>
52 #include <pkg-manager/pkgmgr_signal_interface.h>
53 #include <pkg-manager/pkgmgr_signal_dummy.h>
54 #include <pkg-manager/pkgmgr_signal.h>
56 using namespace WrtDB;
58 namespace { // anonymous
59 const char * const PKGMGR_INSTALL_MSG = "Install widget";
60 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
62 const char * const CONFIG_XML = "config.xml";
63 const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
65 const unsigned int NOFILE_CNT_FOR_INSTALLER = 9999;
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),
85 m_installMode(WRT_INSTALL_MODE_UNKNOWN),
88 m_numPluginsToInstall(0),
91 m_installByPkgmgr(false),
93 m_startupPluginInstallation(false)
96 LogDebug("App Created");
99 WrtInstaller::~WrtInstaller()
101 LogDebug("App Finished");
104 int WrtInstaller::getReturnStatus() const
106 if (!m_returnStatus) {
113 void WrtInstaller::OnStop()
115 LogInfo("Stopping Dummy Client");
118 void WrtInstaller::OnCreate()
120 LogInfo("Creating DummyClient");
122 "===========================================================\n");
123 fprintf(stderr, "# wrt-installer #\n");
124 fprintf(stderr, "# argc [%d]\n", m_argc);
125 fprintf(stderr, "# argv[0] = [%s]\n", m_argv[0]);
126 fprintf(stderr, "# argv[1] = [%s]\n", m_argv[1]);
127 fprintf(stderr, "# argv[2] = [%s]\n", m_argv[2]);
129 "===========================================================\n");
131 AddStep(&WrtInstaller::initStep);
133 std::string arg = m_argv[0];
135 pkgmgrSignalInterface =
136 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
137 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
138 new PackageManager::PkgmgrSignalDummy()
143 return showHelpAndQuit();
148 if (arg.find("wrt-installer") != std::string::npos) {
150 return showHelpAndQuit();
154 if (arg == "-h" || arg == "--help") {
156 return showHelpAndQuit();
160 return showHelpAndQuit();
161 } else if (arg == "-p" || arg == "--install-plugins") {
163 return showHelpAndQuit();
166 if (!m_startupPluginInstallation) {
167 AddStep(&WrtInstaller::installPluginsStep);
169 LogInfo("Plugin installation alredy started");
171 } else if (arg == "-i" || arg == "--install") {
173 return showHelpAndQuit();
177 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
178 LogInfo("Installing package directly from directory");
179 m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
181 LogInfo("Installing from regular location");
182 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
184 m_packagePath = m_argv[2];
186 AddStep(&WrtInstaller::installStep);
187 } else if (arg == "-ip" || arg == "--install-preload") {
188 LogDebug("Install preload web app");
190 return showHelpAndQuit();
192 m_packagePath = m_argv[2];
193 m_installMode = WRT_INSTALL_MODE_INSTALL_PRELOAD;
194 AddStep(&WrtInstaller::installStep);
195 } else if (arg == "-c" || arg == "--csc-update") {
196 // "path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true"
197 LogDebug("Install & uninstall by csc configuration");
199 return showHelpAndQuit();
201 std::string configuration = m_argv[2];
202 m_CSCconfigurationMap = parseCSCConfiguration(configuration);
204 CSCConfiguration::dataMap::iterator it;
205 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_OP);
206 if (it == m_CSCconfigurationMap.end()) {
207 return showHelpAndQuit();
210 if (it->second == CSCConfiguration::VALUE_INSTALL) {
211 LogDebug("operation = " << it->second);
212 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
213 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
214 if (it == m_CSCconfigurationMap.end()) {
215 return showHelpAndQuit();
217 m_packagePath = it->second;
218 AddStep(&WrtInstaller::installStep);
219 LogDebug("path = " << m_packagePath);
220 } else if (it->second == CSCConfiguration::VALUE_UNINSTALL) {
221 LogDebug("operation = " << it->second);
222 // uninstall command isn't confirmed yet
223 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
224 if (it == m_CSCconfigurationMap.end()) {
225 return showHelpAndQuit();
227 m_packagePath = it->second;
228 AddStep(&WrtInstaller::unistallWgtFileStep);
229 LogDebug("operation = uninstall");
230 LogDebug("path = " << m_packagePath);
232 LogError("Unknown operation : " << it->second);
233 LogDebug("operation = " << it->second);
234 return showHelpAndQuit();
236 } else if (arg == "-un" || arg == "--uninstall-name") {
238 return showHelpAndQuit();
241 AddStep(&WrtInstaller::uninstallPkgNameStep);
242 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
244 return showHelpAndQuit();
246 m_packagePath = m_argv[2];
247 AddStep(&WrtInstaller::unistallWgtFileStep);
248 } else if (arg == "-r" || arg == "--reinstall") {
250 return showHelpAndQuit();
252 LogInfo("Installing package directly from directory");
253 m_installMode = WRT_INSTALL_MODE_REINSTALL;
254 m_packagePath = m_argv[2];
255 AddStep(&WrtInstaller::installStep);
257 return showHelpAndQuit();
259 } else if (arg.find("backend") != std::string::npos) {
260 using namespace PackageManager;
261 m_installByPkgmgr = true;
263 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
264 new PackageManager::PkgmgrSignal()
267 pkgmgrSignal->initialize(m_argc, m_argv);
268 m_quiet = pkgmgrSignal->isNoPopupRequired();
269 LogDebug("backend m_quiet" << m_quiet);
271 int reqType = pkgmgrSignal->getRequestedType();
273 pkgmgrSignalInterface =
274 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
277 case PKGMGR_REQ_INSTALL:
278 m_packagePath = m_argv[4];
280 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
281 LogInfo("Installing package directly from directory");
282 m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
284 LogInfo("Installing from regular location");
285 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
287 AddStep(&WrtInstaller::installStep);
289 case PKGMGR_REQ_UNINSTALL:
291 AddStep(&WrtInstaller::uninstallPkgNameStep);
293 case PKGMGR_REQ_REINSTALL:
294 m_packagePath = m_argv[4];
295 m_installMode = WRT_INSTALL_MODE_REINSTALL;
296 AddStep(&WrtInstaller::installStep);
299 LogDebug("Not available type");
304 AddStep(&WrtInstaller::shutdownStep);
305 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
307 WRTInstallerNS::NextStepEvent());
310 void WrtInstaller::OnReset(bundle* /*b*/)
315 void WrtInstaller::OnTerminate()
317 LogDebug("Wrt Shutdown now");
318 PluginUtils::unlockPluginInstallation(m_installMode ==
319 WRT_INSTALL_MODE_INSTALL_PRELOAD);
321 wrt_installer_shutdown();
325 void WrtInstaller::showHelpAndQuit()
327 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
328 "Operate with WebRuntime daemon: install, uninstall"
329 " and launch widgets.\n"
330 "Query list of installed widgets and setup up debugging support.\n"
332 "Exactly one option must be selected.\n"
333 "Mandatory arguments to long options are mandatory for short "
335 " -h, --help show this help\n"
336 " -p, --install-plugins install plugins\n"
338 "install or update widget package for given path\n"
340 "install or uninstall by CSC configuration \n"
341 " -un, --uninstall-name "
342 "uninstall widget for given package name\n"
343 " -up, --uninstall-packagepath "
344 "uninstall widget for given package file path\n"
346 "reinstall web application\n"
352 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
357 LogDebug("Wrt Shutdown now");
358 SwitchToStep(&WrtInstaller::shutdownStep);
359 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
361 WRTInstallerNS::NextStepEvent());
363 LogDebug("Quiting application");
368 void WrtInstaller::OnEventReceived(
369 const WRTInstallerNS::NextStepEvent& /*event*/)
371 LogDebug("Executing next step");
375 void WrtInstaller::OnEventReceived(
376 const WRTInstallerNS::InstallPluginEvent& /*event*/)
378 PluginInstallerData* privateData = new PluginInstallerData;
379 privateData->wrtInstaller = this;
381 if (!(*m_pluginsPaths).empty()) {
382 privateData->pluginPath = (*m_pluginsPaths).front();
383 (*m_pluginsPaths).pop_front();
385 wrt_install_plugin(privateData->pluginPath.c_str(),
386 static_cast<void*>(privateData),
387 &staticWrtPluginInstallationCallback,
388 &staticWrtPluginInstallProgressCb);
394 void WrtInstaller::initStep()
396 wrt_installer_init(this, staticWrtInitCallback);
399 void WrtInstaller::installStep()
401 LogDebug("Installing widget ...");
402 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
403 m_packagePath.c_str()));
405 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
406 this, &staticWrtStatusCallback,
407 (!m_quiet || m_installByPkgmgr)
408 ? &staticWrtInstallProgressCallback : NULL,
411 pkgmgrSignalInterface);
414 void WrtInstaller::installPluginsStep()
416 LogDebug("Installing plugins ...");
417 fprintf(stderr, "Installing plugins ...\n");
419 if (m_startupPluginInstallation) {
420 LogInfo("Plugin installation started because new plugin package found");
421 } else if (!PluginUtils::lockPluginInstallation(m_installMode ==
422 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
423 LogError("Failed to open plugin installation lock file"
424 " Plugins are currently installed by other process");
425 staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
430 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
433 dir = opendir(PLUGIN_PATH.c_str());
439 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
441 std::list<std::string> pluginsPaths;
442 struct dirent libdir;
443 struct dirent *result;
446 for (return_code = readdir_r(dir, &libdir, &result);
447 result != NULL && return_code == 0;
448 return_code = readdir_r(dir, &libdir, &result))
450 if (strcmp(libdir.d_name, ".") == 0 ||
451 strcmp(libdir.d_name, "..") == 0)
456 std::string path = PLUGIN_PATH;
458 path += libdir.d_name;
462 if (stat(path.c_str(), &tmp) == -1) {
463 LogError("Failed to open file" << path);
467 if (!S_ISDIR(tmp.st_mode)) {
468 LogError("Not a directory" << path);
472 pluginsPaths.push_back(path);
475 if (return_code != 0 || errno != 0) {
476 LogError("readdir_r() failed with " << DPL::GetErrnoString());
479 //set nb of plugins to install
480 //this value indicate how many callbacks are expected
481 m_numPluginsToInstall = pluginsPaths.size();
482 LogInfo("Plugins to install: " << m_numPluginsToInstall);
483 m_pluginsPaths = pluginsPaths;
485 m_totalPlugins = m_numPluginsToInstall;
486 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
487 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
489 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
490 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
491 << DPL::GetErrnoString());
495 void WrtInstaller::uninstallPkgNameStep()
497 LogDebug("Uninstalling widget ...");
498 LogDebug("Package name : " << m_name);
499 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
500 (!m_quiet || m_installByPkgmgr)
501 ? &staticWrtUninstallProgressCallback : NULL,
502 pkgmgrSignalInterface);
505 void WrtInstaller::unistallWgtFileStep()
507 LogDebug("Uninstalling widget ...");
512 ConfigParserData configInfo;
515 std::unique_ptr<DPL::ZipInput> zipFile(
516 new DPL::ZipInput(m_packagePath));
517 std::unique_ptr<DPL::ZipInput::File> configFile;
520 // Open config.xml file
521 configFile.reset(zipFile->OpenFile(CONFIG_XML));
523 Catch(DPL::ZipInput::Exception::OpenFileFailed)
525 // Open config.xml file for hybrid
526 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
530 DPL::BinaryQueue buffer;
531 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
532 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
533 DPL::Copy(&inputAdapter, &outputAdapter);
534 parser.Parse(&buffer,
536 new RootParser<WidgetParser>(configInfo,
537 DPL::FromUTF32String(
540 DPL::OptionalString pkgId = configInfo.tizenPkgId;
541 if (!pkgId.IsNull()) {
542 LogDebug("Pkgid from packagePath : " << pkgId);
543 wrt_uninstall_widget(
544 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
545 !m_quiet ? &staticWrtUninstallProgressCallback
547 pkgmgrSignalInterface);
549 LogError("Fail to uninstalling widget... ");
551 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
553 WRTInstallerNS::QuitEvent());
556 Catch(DPL::ZipInput::Exception::OpenFailed)
558 LogError("Failed to open widget package");
559 printf("failed: widget package does not exist\n");
561 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
563 WRTInstallerNS::QuitEvent());
565 Catch(DPL::ZipInput::Exception::OpenFileFailed)
567 printf("failed: widget config file does not exist\n");
568 LogError("Failed to open config.xml file");
570 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
572 WRTInstallerNS::QuitEvent());
574 Catch(ElementParser::Exception::ParseError)
576 printf("failed: can not parse config file\n");
577 LogError("Failed to parse config.xml file");
579 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
581 WRTInstallerNS::QuitEvent());
585 void WrtInstaller::shutdownStep()
587 LogDebug("Closing Wrt connection ...");
589 wrt_installer_shutdown();
590 m_initialized = false;
591 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
593 WRTInstallerNS::QuitEvent());
597 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
600 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
603 if (status == WRT_SUCCESS) {
604 LogDebug("Init succesfull");
605 This->m_initialized = true;
606 This->m_returnStatus = 0;
608 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
609 ::PostEvent(WRTInstallerNS::NextStepEvent());
611 LogError("Init unsuccesfull");
612 This->m_returnStatus = -1;
613 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
615 WRTInstallerNS::QuitEvent());
619 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
623 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
626 Step current = This->GetCurrentStep();
627 DPL::String resultMsg;
628 std::string printMsg;
630 if (current == &WrtInstaller::installStep) {
631 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
632 printMsg = "installation";
633 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
634 current == &WrtInstaller::unistallWgtFileStep)
636 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
637 printMsg = "uninstallation";
640 if (WRT_SUCCESS != status) {
642 LogError("Step failed");
643 This->m_returnStatus = -1;
645 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
646 ::PostEvent(WRTInstallerNS::QuitEvent());
649 case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
650 This->m_returnStatus = 1; //this status is specific
651 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
652 tizenId.c_str(), printMsg.c_str());
655 case WRT_INSTALLER_ERROR_PACKAGE_INVALID:
656 This->m_returnStatus = 1; //this status is specific
657 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
658 tizenId.c_str(), printMsg.c_str());
661 case WRT_INSTALLER_ERROR_PACKAGE_LOWER_VERSION:
662 This->m_returnStatus = 1; //this status is specific
663 fprintf(stderr, "## wrt-installer : %s %s has failed - given"
664 " version is lower than existing version\n",
665 tizenId.c_str(), printMsg.c_str());
668 case WRT_INSTALLER_ERROR_MANIFEST_NOT_FOUND:
669 This->m_returnStatus = 1; //this status is specific
670 fprintf(stderr, "## wrt-installer : %s %s has failed - manifest"
671 " file doesn't find in package.\n",
672 tizenId.c_str(), printMsg.c_str());
675 case WRT_INSTALLER_ERROR_MANIFEST_INVALID:
676 This->m_returnStatus = 1; //this status is specific
677 fprintf(stderr, "## wrt-installer : %s %s has failed - "
678 "invalid manifestx.xml\n",
679 tizenId.c_str(), printMsg.c_str());
682 case WRT_INSTALLER_CONFIG_NOT_FOUND:
683 This->m_returnStatus = 1; //this status is specific
684 fprintf(stderr, "## wrt-installer : %s %s has failed - "
685 "config.xml does not exist\n",
686 tizenId.c_str(), printMsg.c_str());
689 case WRT_INSTALLER_ERROR_CONFIG_INVALID:
690 This->m_returnStatus = 1; //this status is specific
691 fprintf(stderr, "## wrt-installer : %s %s has failed - "
692 "invalid config.xml\n",
693 tizenId.c_str(), printMsg.c_str());
696 case WRT_INSTALLER_ERROR_SIGNATURE_NOT_FOUND:
697 This->m_returnStatus = 1; //this status is specific
698 fprintf(stderr, "## wrt-installer : %s %s has failed - "
699 "signature doesn't exist in package.\n",
700 tizenId.c_str(), printMsg.c_str());
703 case WRT_INSTALLER_ERROR_SIGNATURE_INVALID:
704 This->m_returnStatus = 1; //this status is specific
705 fprintf(stderr, "## wrt-installer : %s %s has failed - "
706 "invalid signature.\n",
707 tizenId.c_str(), printMsg.c_str());
710 case WRT_INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED:
711 This->m_returnStatus = 1; //this status is specific
712 fprintf(stderr, "## wrt-installer : %s %s has failed - "
713 "signature verification failed.\n",
714 tizenId.c_str(), printMsg.c_str());
717 case WRT_INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND:
718 This->m_returnStatus = 1; //this status is specific
719 fprintf(stderr, "## wrt-installer : %s %s has failed - "
720 "root certificate could not find.\n",
721 tizenId.c_str(), printMsg.c_str());
724 case WRT_INSTALLER_ERROR_CERTIFICATION_INVAID:
725 This->m_returnStatus = 1; //this status is specific
726 fprintf(stderr, "## wrt-installer : %s %s has failed - "
727 "invalid certification.\n",
728 tizenId.c_str(), printMsg.c_str());
731 case WRT_INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
732 This->m_returnStatus = 1; //this status is specific
733 fprintf(stderr, "## wrt-installer : %s %s has failed - "
734 "certificate chain verification failed.\n",
735 tizenId.c_str(), printMsg.c_str());
738 case WRT_INSTALLER_ERROR_CERTIFICATE_EXPIRED:
739 This->m_returnStatus = 1; //this status is specific
740 fprintf(stderr, "## wrt-installer : %s %s has failed - "
741 "certificate expired.\n",
742 tizenId.c_str(), printMsg.c_str());
745 case WRT_INSTALLER_ERROR_INVALID_PRIVILEGE:
746 This->m_returnStatus = 1; //this status is specific
747 fprintf(stderr, "## wrt-installer : %s %s has failed - "
748 "invalid privilege\n",
749 tizenId.c_str(), printMsg.c_str());
752 case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
753 This->m_returnStatus = 1; //this status is specific
754 fprintf(stderr, "## wrt-installer : %s %s has failed - "
755 "menu icon could not find\n",
756 tizenId.c_str(), printMsg.c_str());
759 case WRT_INSTALLER_ERROR_FATAL_ERROR:
760 This->m_returnStatus = 1; //this status is specific
761 fprintf(stderr, "## wrt-installer : %s %s has failed - "
763 tizenId.c_str(), printMsg.c_str());
766 case WRT_INSTALLER_ERROR_OUT_OF_STORAGE:
767 This->m_returnStatus = 1; //this status is specific
768 fprintf(stderr, "## wrt-installer : %s %s has failed - "
770 tizenId.c_str(), printMsg.c_str());
773 case WRT_INSTALLER_ERROR_OUT_OF_MEMORY:
774 This->m_returnStatus = 1; //this status is specific
775 fprintf(stderr, "## wrt-installer : %s %s has failed - "
777 tizenId.c_str(), printMsg.c_str());
780 case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
781 This->m_returnStatus = 1; //this status is specific
782 fprintf(stderr, "## wrt-installer : %s %s has failed - "
783 "package already installed\n",
784 tizenId.c_str(), printMsg.c_str());
787 case WRT_INSTALLER_ERROR_ACE_CHECK_FAILED:
788 This->m_returnStatus = 1; //this status is specific
789 fprintf(stderr, "## wrt-installer : %s %s has failed - "
790 "ace check failure\n",
791 tizenId.c_str(), printMsg.c_str());
794 case WRT_INSTALLER_ERROR_MANIFEST_CREATE_FAILED:
795 This->m_returnStatus = 1; //this status is specific
796 fprintf(stderr, "## wrt-installer : %s %s has failed - "
797 "to create manifest failed\n",
798 tizenId.c_str(), printMsg.c_str());
801 case WRT_INSTALLER_ERROR_ENCRYPTION_FAILED:
802 This->m_returnStatus = 1; //this status is specific
803 fprintf(stderr, "## wrt-installer : %s %s has failed - "
804 "encryption of resource failed\n",
805 tizenId.c_str(), printMsg.c_str());
808 case WRT_INSTALLER_ERROR_INSTALL_OSP_SERVCIE:
809 This->m_returnStatus = 1; //this status is specific
810 fprintf(stderr, "## wrt-installer : %s %s has failed - "
811 "installation of osp service failed\n",
812 tizenId.c_str(), printMsg.c_str());
815 case WRT_INSTALLER_ERROR_UNINSTALLATION_FAILED:
816 This->m_returnStatus = 1; //this status is specific
817 fprintf(stderr, "## wrt-installer : %s %s has failed - "
818 "widget uninstallation failed\n",
819 tizenId.c_str(), printMsg.c_str());
823 case WRT_INSTALLER_ERROR_UNKNOWN:
824 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
825 tizenId.c_str(), printMsg.c_str());
833 "## wrt-installer : %s %s was successful.\n",
836 LogDebug("Status succesfull");
837 This->m_returnStatus = 0;
838 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
840 if (This->m_installMode == WRT_INSTALL_MODE_INSTALL_PRELOAD &&
841 !This->m_packagePath.empty()) {
842 LogDebug("This widget is preloaded so it will be removed : "
843 << This->m_packagePath);
844 if (!WrtUtilRemove(This->m_packagePath)) {
845 LogError("Failed to remove " << This->m_packagePath);
849 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
851 ::PostEvent(WRTInstallerNS::NextStepEvent());
855 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
860 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
862 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
864 std::string path = std::string(data->pluginPath);
867 This->m_numPluginsToInstall--;
868 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
870 if (This->m_numPluginsToInstall < 1) {
871 LogDebug("All plugins installation completed");
872 fprintf(stderr, "All plugins installation completed.\n");
874 //remove installation request
875 if (!PluginUtils::removeInstallationRequiredFlag()) {
876 LogInfo("Failed to remove file initializing plugin installation");
880 if (!PluginUtils::unlockPluginInstallation(This->m_installMode ==
881 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
882 LogInfo("Failed to remove installation lock");
885 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
886 ::PostEvent(WRTInstallerNS::NextStepEvent());
888 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
889 InstallPluginEvent>::
891 WRTInstallerNS::InstallPluginEvent());
894 if (WRT_SUCCESS == status) {
895 This->m_returnStatus = 0;
897 "## wrt-installer : plugin installation successfull [%s]\n",
899 LogDebug("One plugin Installation succesfull: " << path);
904 LogWarning("One of the plugins installation failed!: " << path);
907 case WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED:
908 LogError("failed: plugin installation failed\n");
911 case WRT_INSTALLER_ERROR_UNKNOWN:
912 LogError("failed: unknown error\n");
920 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
921 const char* description,
924 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
926 std::string path = std::string(data->pluginPath);
928 LogInfo("Plugin Installation: " << path <<
929 " progress: " << percent <<
930 "description " << description);
933 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
934 const char* description,
937 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
938 LogInfo(" progress: " << percent <<
939 " description: " << description);
941 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
942 const char* description,
945 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
946 LogInfo(" progress: " << percent <<
947 " description: " << description);
950 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
951 void* /*event_info*/)
953 WrtInstaller *This = static_cast<WrtInstaller*>(data);
956 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
957 ::PostEvent(WRTInstallerNS::NextStepEvent());
960 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
961 void* /*event_info*/)
963 WrtInstaller *This = static_cast<WrtInstaller*>(data);
966 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
967 ::PostEvent(WRTInstallerNS::QuitEvent());
970 void WrtInstaller::installNewPlugins()
972 LogDebug("Install new plugins");
974 if (!PluginUtils::lockPluginInstallation(m_installMode ==
975 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
976 LogInfo("Lock NOT created");
980 if (!PluginUtils::checkPluginInstallationRequired()) {
981 LogDebug("Plugin installation not required");
982 PluginUtils::unlockPluginInstallation(m_installMode ==
983 WRT_INSTALL_MODE_INSTALL_PRELOAD);
987 m_startupPluginInstallation = true;
988 AddStep(&WrtInstaller::installPluginsStep);
991 CSCConfiguration::dataMap WrtInstaller::parseCSCConfiguration(
994 // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
995 // parsing CSC configuration string
996 LogDebug("parseConfiguration");
997 CSCConfiguration::dataMap result;
1000 LogDebug("Input argument is empty");
1004 char* buf = strdup(str.c_str());
1005 const char* ptr = strtok(buf,":");
1006 while (ptr != NULL) {
1007 std::string string = ptr;
1008 size_t pos = string.find('=');
1009 if (pos == std::string::npos) {
1013 CSCConfiguration::dataPair(string.substr(0, pos),
1014 string.substr(pos+1)));
1015 ptr = strtok (NULL, ":");
1020 int main(int argc, char *argv[])
1022 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1024 // Output on stdout will be flushed after every newline character,
1025 // even if it is redirected to a pipe. This is useful for running
1026 // from a script and parsing output.
1027 // (Standard behavior of stdlib is to use full buffering when
1028 // redirected to a pipe, which means even after an end of line
1029 // the output may not be flushed).
1032 // Check and re-set the file open limitation
1034 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1035 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
1036 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
1038 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1039 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1040 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1041 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1042 LogError("setrlimit is fail!!");
1046 LogError("getrlimit is fail!!");
1049 // set evas backend type for emulator
1050 // popup isn't showed in the emulator,
1051 // if backend isn't set to SW backend
1052 if (GlobalSettings::IsEmulator()) {
1053 if (setenv("ELM_ENGINE", "x11", 1)) {
1054 LogDebug("Enable backend");
1058 WrtInstaller app(argc, argv);
1059 int ret = app.Exec();
1060 LogDebug("App returned: " << ret);
1061 ret = app.getReturnStatus();
1062 LogDebug("WrtInstaller returned: " << ret);
1065 UNHANDLED_EXCEPTION_HANDLER_END