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),
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 void WrtInstaller::OnStop()
114 LogInfo("Stopping Dummy Client");
117 void WrtInstaller::OnCreate()
119 LogInfo("Creating DummyClient");
121 "===========================================================\n");
122 fprintf(stderr, "# wrt-installer #\n");
123 fprintf(stderr, "# argc [%d]\n", m_argc);
124 fprintf(stderr, "# argv[0] = [%s]\n", m_argv[0]);
125 fprintf(stderr, "# argv[1] = [%s]\n", m_argv[1]);
126 fprintf(stderr, "# argv[2] = [%s]\n", m_argv[2]);
128 "===========================================================\n");
130 AddStep(&WrtInstaller::initStep);
132 std::string arg = m_argv[0];
134 pkgmgrSignalInterface =
135 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
136 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
137 new PackageManager::PkgmgrSignalDummy()
142 return showHelpAndQuit();
147 if (arg.find("wrt-installer") != std::string::npos) {
149 return showHelpAndQuit();
153 if (arg == "-h" || arg == "--help") {
155 return showHelpAndQuit();
159 return showHelpAndQuit();
160 } else if (arg == "-p" || arg == "--install-plugins") {
162 return showHelpAndQuit();
165 if (!m_startupPluginInstallation) {
166 AddStep(&WrtInstaller::installPluginsStep);
168 LogInfo("Plugin installation alredy started");
170 } else if (arg == "-i" || arg == "--install") {
172 return showHelpAndQuit();
176 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
177 LogInfo("Installing package directly from directory");
178 m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
180 LogInfo("Installing from regular location");
181 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
183 m_packagePath = m_argv[2];
185 AddStep(&WrtInstaller::installStep);
186 } else if (arg == "-ip" || arg == "--install-preload") {
187 LogDebug("Install preload web app");
189 return showHelpAndQuit();
191 m_packagePath = m_argv[2];
192 m_installMode = WRT_INSTALL_MODE_INSTALL_PRELOAD;
193 AddStep(&WrtInstaller::installStep);
194 } else if (arg == "-c" || arg == "--csc-update") {
195 // "path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true"
196 LogDebug("Install & uninstall by csc configuration");
198 return showHelpAndQuit();
200 std::string configuration = m_argv[2];
201 m_CSCconfigurationMap = parseCSCConfiguration(configuration);
203 CSCConfiguration::dataMap::iterator it;
204 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_OP);
205 if (it == m_CSCconfigurationMap.end()) {
206 return showHelpAndQuit();
209 if (it->second == CSCConfiguration::VALUE_INSTALL) {
210 LogDebug("operation = " << it->second);
211 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
212 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
213 if (it == m_CSCconfigurationMap.end()) {
214 return showHelpAndQuit();
216 m_packagePath = it->second;
217 AddStep(&WrtInstaller::installStep);
218 LogDebug("path = " << m_packagePath);
219 } else if (it->second == CSCConfiguration::VALUE_UNINSTALL) {
220 LogDebug("operation = " << it->second);
221 // uninstall command isn't confirmed yet
222 it = m_CSCconfigurationMap.find(CSCConfiguration::KEY_PATH);
223 if (it == m_CSCconfigurationMap.end()) {
224 return showHelpAndQuit();
226 m_packagePath = it->second;
227 AddStep(&WrtInstaller::unistallWgtFileStep);
228 LogDebug("operation = uninstall");
229 LogDebug("path = " << m_packagePath);
231 LogError("Unknown operation : " << it->second);
232 LogDebug("operation = " << it->second);
233 return showHelpAndQuit();
235 } else if (arg == "-un" || arg == "--uninstall-name") {
237 return showHelpAndQuit();
240 AddStep(&WrtInstaller::uninstallPkgNameStep);
241 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
243 return showHelpAndQuit();
245 m_packagePath = m_argv[2];
246 AddStep(&WrtInstaller::unistallWgtFileStep);
247 } else if (arg == "-r" || arg == "--reinstall") {
249 return showHelpAndQuit();
251 LogInfo("Installing package directly from directory");
252 m_installMode = WRT_INSTALL_MODE_REINSTALL;
253 m_packagePath = m_argv[2];
254 AddStep(&WrtInstaller::installStep);
256 return showHelpAndQuit();
258 } else if (arg.find("backend") != std::string::npos) {
259 using namespace PackageManager;
260 m_installByPkgmgr = true;
262 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
263 new PackageManager::PkgmgrSignal()
266 pkgmgrSignal->initialize(m_argc, m_argv);
268 int reqType = pkgmgrSignal->getRequestedType();
270 pkgmgrSignalInterface =
271 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
274 case PKGMGR_REQ_INSTALL:
275 m_packagePath = m_argv[4];
277 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
278 LogInfo("Installing package directly from directory");
279 m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
281 LogInfo("Installing from regular location");
282 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
284 AddStep(&WrtInstaller::installStep);
286 case PKGMGR_REQ_UNINSTALL:
288 AddStep(&WrtInstaller::uninstallPkgNameStep);
290 case PKGMGR_REQ_REINSTALL:
291 m_packagePath = m_argv[4];
292 m_installMode = WRT_INSTALL_MODE_REINSTALL;
293 AddStep(&WrtInstaller::installStep);
296 LogDebug("Not available type");
301 AddStep(&WrtInstaller::shutdownStep);
302 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
304 WRTInstallerNS::NextStepEvent());
307 void WrtInstaller::OnReset(bundle* /*b*/)
312 void WrtInstaller::OnTerminate()
314 LogDebug("Wrt Shutdown now");
315 PluginUtils::unlockPluginInstallation(m_installMode ==
316 WRT_INSTALL_MODE_INSTALL_PRELOAD);
318 wrt_installer_shutdown();
322 void WrtInstaller::showHelpAndQuit()
324 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
325 "Operate with WebRuntime daemon: install, uninstall"
326 " and launch widgets.\n"
327 "Query list of installed widgets and setup up debugging support.\n"
329 "Exactly one option must be selected.\n"
330 "Mandatory arguments to long options are mandatory for short "
332 " -h, --help show this help\n"
333 " -p, --install-plugins install plugins\n"
335 "install or update widget package for given path\n"
337 "install or uninstall by CSC configuration \n"
338 " -un, --uninstall-name "
339 "uninstall widget for given package name\n"
340 " -up, --uninstall-packagepath "
341 "uninstall widget for given package file path\n"
343 "reinstall web application\n"
349 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
354 LogDebug("Wrt Shutdown now");
355 SwitchToStep(&WrtInstaller::shutdownStep);
356 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
358 WRTInstallerNS::NextStepEvent());
360 LogDebug("Quiting application");
365 void WrtInstaller::OnEventReceived(
366 const WRTInstallerNS::NextStepEvent& /*event*/)
368 LogDebug("Executing next step");
372 void WrtInstaller::OnEventReceived(
373 const WRTInstallerNS::InstallPluginEvent& /*event*/)
375 PluginInstallerData* privateData = new PluginInstallerData;
376 privateData->wrtInstaller = this;
378 if (!(*m_pluginsPaths).empty()) {
379 privateData->pluginPath = (*m_pluginsPaths).front();
380 (*m_pluginsPaths).pop_front();
382 wrt_install_plugin(privateData->pluginPath.c_str(),
383 static_cast<void*>(privateData),
384 &staticWrtPluginInstallationCallback,
385 &staticWrtPluginInstallProgressCb);
391 void WrtInstaller::initStep()
393 wrt_installer_init(this, staticWrtInitCallback);
396 void WrtInstaller::installStep()
398 LogDebug("Installing widget ...");
399 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
400 m_packagePath.c_str()));
402 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
403 this, &staticWrtStatusCallback,
405 ? &staticWrtInstallProgressCallback : NULL,
407 pkgmgrSignalInterface);
410 void WrtInstaller::installPluginsStep()
412 LogDebug("Installing plugins ...");
413 fprintf(stderr, "Installing plugins ...\n");
415 if (m_startupPluginInstallation) {
416 LogInfo("Plugin installation started because new plugin package found");
417 } else if (!PluginUtils::lockPluginInstallation(m_installMode ==
418 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
419 LogError("Failed to open plugin installation lock file"
420 " Plugins are currently installed by other process");
421 staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
426 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
429 dir = opendir(PLUGIN_PATH.c_str());
435 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
437 std::list<std::string> pluginsPaths;
438 struct dirent libdir;
439 struct dirent *result;
442 for (return_code = readdir_r(dir, &libdir, &result);
443 result != NULL && return_code == 0;
444 return_code = readdir_r(dir, &libdir, &result))
446 if (strcmp(libdir.d_name, ".") == 0 ||
447 strcmp(libdir.d_name, "..") == 0)
452 std::string path = PLUGIN_PATH;
454 path += libdir.d_name;
458 if (stat(path.c_str(), &tmp) == -1) {
459 LogError("Failed to open file" << path);
463 if (!S_ISDIR(tmp.st_mode)) {
464 LogError("Not a directory" << path);
468 pluginsPaths.push_back(path);
471 if (return_code != 0 || errno != 0) {
472 LogError("readdir_r() failed with " << DPL::GetErrnoString());
475 //set nb of plugins to install
476 //this value indicate how many callbacks are expected
477 m_numPluginsToInstall = pluginsPaths.size();
478 LogInfo("Plugins to install: " << m_numPluginsToInstall);
479 m_pluginsPaths = pluginsPaths;
481 m_totalPlugins = m_numPluginsToInstall;
482 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
483 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
485 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
486 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
487 << DPL::GetErrnoString());
491 void WrtInstaller::uninstallPkgNameStep()
493 LogDebug("Uninstalling widget ...");
494 LogDebug("Package name : " << m_name);
495 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
497 ? &staticWrtUninstallProgressCallback : NULL,
498 pkgmgrSignalInterface);
501 void WrtInstaller::unistallWgtFileStep()
503 LogDebug("Uninstalling widget ...");
508 ConfigParserData configInfo;
511 std::unique_ptr<DPL::ZipInput> zipFile(
512 new DPL::ZipInput(m_packagePath));
513 std::unique_ptr<DPL::ZipInput::File> configFile;
516 // Open config.xml file
517 configFile.reset(zipFile->OpenFile(CONFIG_XML));
519 Catch(DPL::ZipInput::Exception::OpenFileFailed)
521 // Open config.xml file for hybrid
522 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
526 DPL::BinaryQueue buffer;
527 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
528 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
529 DPL::Copy(&inputAdapter, &outputAdapter);
530 parser.Parse(&buffer,
532 new RootParser<WidgetParser>(configInfo,
533 DPL::FromUTF32String(
536 DPL::OptionalString pkgId = configInfo.tizenPkgId;
537 if (!pkgId.IsNull()) {
538 LogDebug("Pkgid from packagePath : " << pkgId);
539 wrt_uninstall_widget(
540 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
541 !m_installByPkgmgr ? &staticWrtUninstallProgressCallback
543 pkgmgrSignalInterface);
545 LogError("Fail to uninstalling widget... ");
547 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
549 WRTInstallerNS::QuitEvent());
552 Catch(DPL::ZipInput::Exception::OpenFailed)
554 LogError("Failed to open widget package");
555 printf("failed: widget package does not exist\n");
557 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
559 WRTInstallerNS::QuitEvent());
561 Catch(DPL::ZipInput::Exception::OpenFileFailed)
563 printf("failed: widget config file does not exist\n");
564 LogError("Failed to open config.xml file");
566 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
568 WRTInstallerNS::QuitEvent());
570 Catch(ElementParser::Exception::ParseError)
572 printf("failed: can not parse config file\n");
573 LogError("Failed to parse config.xml file");
575 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
577 WRTInstallerNS::QuitEvent());
581 void WrtInstaller::shutdownStep()
583 LogDebug("Closing Wrt connection ...");
585 wrt_installer_shutdown();
586 m_initialized = false;
587 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
589 WRTInstallerNS::QuitEvent());
593 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
596 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
599 if (status == WRT_SUCCESS) {
600 LogDebug("Init succesfull");
601 This->m_initialized = true;
602 This->m_returnStatus = 0;
604 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
605 ::PostEvent(WRTInstallerNS::NextStepEvent());
607 LogError("Init unsuccesfull");
608 This->m_returnStatus = -1;
609 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
611 WRTInstallerNS::QuitEvent());
615 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
619 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
622 Step current = This->GetCurrentStep();
623 DPL::String resultMsg;
624 std::string printMsg;
626 if (current == &WrtInstaller::installStep) {
627 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
628 printMsg = "installation";
629 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
630 current == &WrtInstaller::unistallWgtFileStep)
632 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
633 printMsg = "uninstallation";
636 if (WRT_SUCCESS != status) {
638 LogError("Step failed");
639 This->m_returnStatus = -1;
641 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
642 ::PostEvent(WRTInstallerNS::QuitEvent());
645 case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
646 This->m_returnStatus = 1; //this status is specific
647 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
648 tizenId.c_str(), printMsg.c_str());
651 case WRT_INSTALLER_ERROR_PACKAGE_INVALID:
652 This->m_returnStatus = 1; //this status is specific
653 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
654 tizenId.c_str(), printMsg.c_str());
657 case WRT_INSTALLER_ERROR_PACKAGE_LOWER_VERSION:
658 This->m_returnStatus = 1; //this status is specific
659 fprintf(stderr, "## wrt-installer : %s %s has failed - given"
660 " version is lower than existing version\n",
661 tizenId.c_str(), printMsg.c_str());
664 case WRT_INSTALLER_ERROR_MANIFEST_NOT_FOUND:
665 This->m_returnStatus = 1; //this status is specific
666 fprintf(stderr, "## wrt-installer : %s %s has failed - manifest"
667 " file doesn't find in package.\n",
668 tizenId.c_str(), printMsg.c_str());
671 case WRT_INSTALLER_ERROR_MANIFEST_INVALID:
672 This->m_returnStatus = 1; //this status is specific
673 fprintf(stderr, "## wrt-installer : %s %s has failed - "
674 "invalid manifestx.xml\n",
675 tizenId.c_str(), printMsg.c_str());
678 case WRT_INSTALLER_CONFIG_NOT_FOUND:
679 This->m_returnStatus = 1; //this status is specific
680 fprintf(stderr, "## wrt-installer : %s %s has failed - "
681 "config.xml does not exist\n",
682 tizenId.c_str(), printMsg.c_str());
685 case WRT_INSTALLER_ERROR_CONFIG_INVALID:
686 This->m_returnStatus = 1; //this status is specific
687 fprintf(stderr, "## wrt-installer : %s %s has failed - "
688 "invalid config.xml\n",
689 tizenId.c_str(), printMsg.c_str());
692 case WRT_INSTALLER_ERROR_SIGNATURE_NOT_FOUND:
693 This->m_returnStatus = 1; //this status is specific
694 fprintf(stderr, "## wrt-installer : %s %s has failed - "
695 "signature doesn't exist in package.\n",
696 tizenId.c_str(), printMsg.c_str());
699 case WRT_INSTALLER_ERROR_SIGNATURE_INVALID:
700 This->m_returnStatus = 1; //this status is specific
701 fprintf(stderr, "## wrt-installer : %s %s has failed - "
702 "invalid signature.\n",
703 tizenId.c_str(), printMsg.c_str());
706 case WRT_INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED:
707 This->m_returnStatus = 1; //this status is specific
708 fprintf(stderr, "## wrt-installer : %s %s has failed - "
709 "signature verification failed.\n",
710 tizenId.c_str(), printMsg.c_str());
713 case WRT_INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND:
714 This->m_returnStatus = 1; //this status is specific
715 fprintf(stderr, "## wrt-installer : %s %s has failed - "
716 "root certificate could not find.\n",
717 tizenId.c_str(), printMsg.c_str());
720 case WRT_INSTALLER_ERROR_CERTIFICATION_INVAID:
721 This->m_returnStatus = 1; //this status is specific
722 fprintf(stderr, "## wrt-installer : %s %s has failed - "
723 "invalid certification.\n",
724 tizenId.c_str(), printMsg.c_str());
727 case WRT_INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
728 This->m_returnStatus = 1; //this status is specific
729 fprintf(stderr, "## wrt-installer : %s %s has failed - "
730 "certificate chain verification failed.\n",
731 tizenId.c_str(), printMsg.c_str());
734 case WRT_INSTALLER_ERROR_CERTIFICATE_EXPIRED:
735 This->m_returnStatus = 1; //this status is specific
736 fprintf(stderr, "## wrt-installer : %s %s has failed - "
737 "certificate expired.\n",
738 tizenId.c_str(), printMsg.c_str());
741 case WRT_INSTALLER_ERROR_INVALID_PRIVILEGE:
742 This->m_returnStatus = 1; //this status is specific
743 fprintf(stderr, "## wrt-installer : %s %s has failed - "
744 "invalid privilege\n",
745 tizenId.c_str(), printMsg.c_str());
748 case WRT_INSTALLER_ERROR_PRIVILEGE_LEVEL_VIOLATION:
749 This->m_returnStatus = 1; //this status is specific
750 fprintf(stderr, "## wrt-installer : %s %s has failed - "
751 "privilege level violation\n",
752 tizenId.c_str(), printMsg.c_str());
755 case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
756 This->m_returnStatus = 1; //this status is specific
757 fprintf(stderr, "## wrt-installer : %s %s has failed - "
758 "menu icon could not find\n",
759 tizenId.c_str(), printMsg.c_str());
762 case WRT_INSTALLER_ERROR_FATAL_ERROR:
763 This->m_returnStatus = 1; //this status is specific
764 fprintf(stderr, "## wrt-installer : %s %s has failed - "
766 tizenId.c_str(), printMsg.c_str());
769 case WRT_INSTALLER_ERROR_OUT_OF_STORAGE:
770 This->m_returnStatus = 1; //this status is specific
771 fprintf(stderr, "## wrt-installer : %s %s has failed - "
773 tizenId.c_str(), printMsg.c_str());
776 case WRT_INSTALLER_ERROR_OUT_OF_MEMORY:
777 This->m_returnStatus = 1; //this status is specific
778 fprintf(stderr, "## wrt-installer : %s %s has failed - "
780 tizenId.c_str(), printMsg.c_str());
783 case WRT_INSTALLER_ERROR_ARGUMENT_INVALID:
784 This->m_returnStatus = 1; //this status is specific
785 fprintf(stderr, "## wrt-installer : %s %s has failed - "
786 "invalid argument\n",
787 tizenId.c_str(), printMsg.c_str());
790 case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
791 This->m_returnStatus = 1; //this status is specific
792 fprintf(stderr, "## wrt-installer : %s %s has failed - "
793 "package already installed\n",
794 tizenId.c_str(), printMsg.c_str());
797 case WRT_INSTALLER_ERROR_ACE_CHECK_FAILED:
798 This->m_returnStatus = 1; //this status is specific
799 fprintf(stderr, "## wrt-installer : %s %s has failed - "
800 "ace check failure\n",
801 tizenId.c_str(), printMsg.c_str());
804 case WRT_INSTALLER_ERROR_MANIFEST_CREATE_FAILED:
805 This->m_returnStatus = 1; //this status is specific
806 fprintf(stderr, "## wrt-installer : %s %s has failed - "
807 "to create manifest failed\n",
808 tizenId.c_str(), printMsg.c_str());
811 case WRT_INSTALLER_ERROR_ENCRYPTION_FAILED:
812 This->m_returnStatus = 1; //this status is specific
813 fprintf(stderr, "## wrt-installer : %s %s has failed - "
814 "encryption of resource failed\n",
815 tizenId.c_str(), printMsg.c_str());
818 case WRT_INSTALLER_ERROR_INSTALL_OSP_SERVCIE:
819 This->m_returnStatus = 1; //this status is specific
820 fprintf(stderr, "## wrt-installer : %s %s has failed - "
821 "installation of osp service failed\n",
822 tizenId.c_str(), printMsg.c_str());
825 case WRT_INSTALLER_ERROR_UNINSTALLATION_FAILED:
826 This->m_returnStatus = 1; //this status is specific
827 fprintf(stderr, "## wrt-installer : %s %s has failed - "
828 "widget uninstallation failed\n",
829 tizenId.c_str(), printMsg.c_str());
833 case WRT_INSTALLER_ERROR_UNKNOWN:
834 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
835 tizenId.c_str(), printMsg.c_str());
843 "## wrt-installer : %s %s was successful.\n",
846 LogDebug("Status succesfull");
847 This->m_returnStatus = 0;
848 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
850 if (This->m_installMode == WRT_INSTALL_MODE_INSTALL_PRELOAD &&
851 !This->m_packagePath.empty()) {
852 LogDebug("This widget is preloaded so it will be removed : "
853 << This->m_packagePath);
854 if (!WrtUtilRemove(This->m_packagePath)) {
855 LogError("Failed to remove " << This->m_packagePath);
859 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
861 ::PostEvent(WRTInstallerNS::NextStepEvent());
865 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
870 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
872 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
874 std::string path = std::string(data->pluginPath);
877 This->m_numPluginsToInstall--;
878 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
880 if (This->m_numPluginsToInstall < 1) {
881 LogDebug("All plugins installation completed");
882 fprintf(stderr, "All plugins installation completed.\n");
884 //remove installation request
885 if (!PluginUtils::removeInstallationRequiredFlag()) {
886 LogInfo("Failed to remove file initializing plugin installation");
890 if (!PluginUtils::unlockPluginInstallation(This->m_installMode ==
891 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
892 LogInfo("Failed to remove installation lock");
895 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
896 ::PostEvent(WRTInstallerNS::NextStepEvent());
898 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
899 InstallPluginEvent>::
901 WRTInstallerNS::InstallPluginEvent());
904 if (WRT_SUCCESS == status) {
905 This->m_returnStatus = 0;
907 "## wrt-installer : plugin installation successfull [%s]\n",
909 LogDebug("One plugin Installation succesfull: " << path);
914 LogWarning("One of the plugins installation failed!: " << path);
917 case WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED:
918 LogError("failed: plugin installation failed\n");
921 case WRT_INSTALLER_ERROR_UNKNOWN:
922 LogError("failed: unknown error\n");
930 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
931 const char* description,
934 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
936 std::string path = std::string(data->pluginPath);
938 LogInfo("Plugin Installation: " << path <<
939 " progress: " << percent <<
940 "description " << description);
943 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
944 const char* description,
947 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
948 LogInfo(" progress: " << percent <<
949 " description: " << description);
951 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
952 const char* description,
955 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
956 LogInfo(" progress: " << percent <<
957 " description: " << description);
960 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
961 void* /*event_info*/)
963 WrtInstaller *This = static_cast<WrtInstaller*>(data);
966 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
967 ::PostEvent(WRTInstallerNS::NextStepEvent());
970 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
971 void* /*event_info*/)
973 WrtInstaller *This = static_cast<WrtInstaller*>(data);
976 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
977 ::PostEvent(WRTInstallerNS::QuitEvent());
980 void WrtInstaller::installNewPlugins()
982 LogDebug("Install new plugins");
984 if (!PluginUtils::lockPluginInstallation(m_installMode ==
985 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
986 LogInfo("Lock NOT created");
990 if (!PluginUtils::checkPluginInstallationRequired()) {
991 LogDebug("Plugin installation not required");
992 PluginUtils::unlockPluginInstallation(m_installMode ==
993 WRT_INSTALL_MODE_INSTALL_PRELOAD);
997 m_startupPluginInstallation = true;
998 AddStep(&WrtInstaller::installPluginsStep);
1001 CSCConfiguration::dataMap WrtInstaller::parseCSCConfiguration(
1004 // path=/opt/system/csc/Ozq2iEG15R-2.0.0-arm.wgt:op=install:removable=true
1005 // parsing CSC configuration string
1006 LogDebug("parseConfiguration");
1007 CSCConfiguration::dataMap result;
1010 LogDebug("Input argument is empty");
1014 char* buf = strdup(str.c_str());
1015 const char* ptr = strtok(buf,":");
1016 while (ptr != NULL) {
1017 std::string string = ptr;
1018 ptr = strtok (NULL, ":");
1019 size_t pos = string.find('=');
1020 if (pos == std::string::npos) {
1024 CSCConfiguration::dataPair(string.substr(0, pos),
1025 string.substr(pos+1)));
1031 int main(int argc, char *argv[])
1033 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1035 // Output on stdout will be flushed after every newline character,
1036 // even if it is redirected to a pipe. This is useful for running
1037 // from a script and parsing output.
1038 // (Standard behavior of stdlib is to use full buffering when
1039 // redirected to a pipe, which means even after an end of line
1040 // the output may not be flushed).
1043 // Check and re-set the file open limitation
1045 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1046 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
1047 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
1049 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1050 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1051 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1052 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1053 LogError("setrlimit is fail!!");
1057 LogError("getrlimit is fail!!");
1060 // set evas backend type for emulator
1061 // popup isn't showed in the emulator,
1062 // if backend isn't set to SW backend
1063 if (GlobalSettings::IsEmulator()) {
1064 if (setenv("ELM_ENGINE", "x11", 1)) {
1065 LogDebug("Enable backend");
1069 WrtInstaller app(argc, argv);
1070 int ret = app.Exec();
1071 LogDebug("App returned: " << ret);
1072 ret = app.getReturnStatus();
1073 LogDebug("WrtInstaller returned: " << ret);
1076 UNHANDLED_EXCEPTION_HANDLER_END