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 <dpl/utils/wrt_utility.h>
45 #include <parser_runner.h>
46 #include <widget_parser.h>
47 #include <root_parser.h>
49 #include <Elementary.h>
51 #include <pkg-manager/pkgmgr_signal_interface.h>
52 #include <pkg-manager/pkgmgr_signal_dummy.h>
53 #include <pkg-manager/pkgmgr_signal.h>
55 using namespace WrtDB;
57 namespace { // anonymous
58 const char * const PKGMGR_INSTALL_MSG = "Install widget";
59 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
61 const char * const CONFIG_XML = "config.xml";
62 const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
64 const unsigned int NOFILE_CNT_FOR_INSTALLER = 9999;
68 void operator()(void* x)
74 struct PluginInstallerData
77 std::string pluginPath;
79 } // namespace anonymous
81 WrtInstaller::WrtInstaller(int argc, char **argv) :
82 Application(argc, argv, "backend", false),
83 DPL::TaskDecl<WrtInstaller>(this),
84 m_installMode(WRT_INSTALL_MODE_UNKNOWN),
87 m_numPluginsToInstall(0),
90 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 == "-un" || arg == "--uninstall-name") {
196 return showHelpAndQuit();
199 AddStep(&WrtInstaller::uninstallPkgNameStep);
200 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
202 return showHelpAndQuit();
204 m_packagePath = m_argv[2];
205 AddStep(&WrtInstaller::unistallWgtFileStep);
206 } else if (arg == "-r" || arg == "--reinstall") {
208 return showHelpAndQuit();
210 LogInfo("Installing package directly from directory");
211 m_installMode = WRT_INSTALL_MODE_REINSTALL;
212 m_packagePath = m_argv[2];
213 AddStep(&WrtInstaller::installStep);
215 return showHelpAndQuit();
217 } else if (arg.find("backend") != std::string::npos) {
218 using namespace PackageManager;
219 m_installByPkgmgr = true;
221 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
222 new PackageManager::PkgmgrSignal()
225 pkgmgrSignal->initialize(m_argc, m_argv);
226 m_quiet = pkgmgrSignal->isNoPopupRequired();
227 LogDebug("backend m_quiet" << m_quiet);
229 int reqType = pkgmgrSignal->getRequestedType();
231 pkgmgrSignalInterface =
232 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
235 case PKGMGR_REQ_INSTALL:
236 m_packagePath = m_argv[4];
238 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
239 LogInfo("Installing package directly from directory");
240 m_installMode = WRT_INSTALL_MODE_INSTALL_DIRECTORY;
242 LogInfo("Installing from regular location");
243 m_installMode = WRT_INSTALL_MODE_INSTALL_WGT;
245 AddStep(&WrtInstaller::installStep);
247 case PKGMGR_REQ_UNINSTALL:
249 AddStep(&WrtInstaller::uninstallPkgNameStep);
251 case PKGMGR_REQ_REINSTALL:
252 m_packagePath = m_argv[4];
253 m_installMode = WRT_INSTALL_MODE_REINSTALL;
254 AddStep(&WrtInstaller::installStep);
257 LogDebug("Not available type");
262 AddStep(&WrtInstaller::shutdownStep);
263 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
265 WRTInstallerNS::NextStepEvent());
268 void WrtInstaller::OnReset(bundle* /*b*/)
273 void WrtInstaller::OnTerminate()
275 LogDebug("Wrt Shutdown now");
276 PluginUtils::unlockPluginInstallation(m_installMode ==
277 WRT_INSTALL_MODE_INSTALL_PRELOAD);
279 wrt_installer_shutdown();
283 void WrtInstaller::showHelpAndQuit()
285 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/PATH]...\n"
286 "Operate with WebRuntime daemon: install, uninstall"
287 " and launch widgets.\n"
288 "Query list of installed widgets and setup up debugging support.\n"
290 "Exactly one option must be selected.\n"
291 "Mandatory arguments to long options are mandatory for short "
293 " -h, --help show this help\n"
294 " -p, --install-plugins install plugins\n"
296 "install or update widget package for given path\n"
297 " -un, --uninstall-name "
298 "uninstall widget for given package name\n"
299 " -up, --uninstall-packagepath "
300 "uninstall widget for given package file path\n"
302 "reinstall web application\n"
308 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
313 LogDebug("Wrt Shutdown now");
314 SwitchToStep(&WrtInstaller::shutdownStep);
315 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
317 WRTInstallerNS::NextStepEvent());
319 LogDebug("Quiting application");
324 void WrtInstaller::OnEventReceived(
325 const WRTInstallerNS::NextStepEvent& /*event*/)
327 LogDebug("Executing next step");
331 void WrtInstaller::OnEventReceived(
332 const WRTInstallerNS::InstallPluginEvent& /*event*/)
334 PluginInstallerData* privateData = new PluginInstallerData;
335 privateData->wrtInstaller = this;
337 if (!(*m_pluginsPaths).empty()) {
338 privateData->pluginPath = (*m_pluginsPaths).front();
339 (*m_pluginsPaths).pop_front();
341 wrt_install_plugin(privateData->pluginPath.c_str(),
342 static_cast<void*>(privateData),
343 &staticWrtPluginInstallationCallback,
344 &staticWrtPluginInstallProgressCb);
350 void WrtInstaller::initStep()
352 wrt_installer_init(this, staticWrtInitCallback);
355 void WrtInstaller::installStep()
357 LogDebug("Installing widget ...");
358 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
359 m_packagePath.c_str()));
361 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
362 this, &staticWrtStatusCallback,
363 (!m_quiet || m_installByPkgmgr)
364 ? &staticWrtInstallProgressCallback : NULL,
367 pkgmgrSignalInterface);
370 void WrtInstaller::installPluginsStep()
372 LogDebug("Installing plugins ...");
373 fprintf(stderr, "Installing plugins ...\n");
375 if (m_startupPluginInstallation) {
376 LogInfo("Plugin installation started because new plugin package found");
377 } else if (!PluginUtils::lockPluginInstallation(m_installMode ==
378 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
379 LogError("Failed to open plugin installation lock file"
380 " Plugins are currently installed by other process");
381 staticWrtPluginInstallationCallback(WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED,
386 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
389 dir = opendir(PLUGIN_PATH.c_str());
395 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
397 std::list<std::string> pluginsPaths;
398 struct dirent libdir;
399 struct dirent *result;
402 for (return_code = readdir_r(dir, &libdir, &result);
403 result != NULL && return_code == 0;
404 return_code = readdir_r(dir, &libdir, &result))
406 if (strcmp(libdir.d_name, ".") == 0 ||
407 strcmp(libdir.d_name, "..") == 0)
412 std::string path = PLUGIN_PATH;
414 path += libdir.d_name;
418 if (stat(path.c_str(), &tmp) == -1) {
419 LogError("Failed to open file" << path);
423 if (!S_ISDIR(tmp.st_mode)) {
424 LogError("Not a directory" << path);
428 pluginsPaths.push_back(path);
431 if (return_code != 0 || errno != 0) {
432 LogError("readdir_r() failed with " << DPL::GetErrnoString());
435 //set nb of plugins to install
436 //this value indicate how many callbacks are expected
437 m_numPluginsToInstall = pluginsPaths.size();
438 LogInfo("Plugins to install: " << m_numPluginsToInstall);
439 m_pluginsPaths = pluginsPaths;
441 m_totalPlugins = m_numPluginsToInstall;
442 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
443 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
445 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
446 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
447 << DPL::GetErrnoString());
451 void WrtInstaller::uninstallPkgNameStep()
453 LogDebug("Uninstalling widget ...");
454 LogDebug("Package name : " << m_name);
455 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
456 (!m_quiet || m_installByPkgmgr)
457 ? &staticWrtUninstallProgressCallback : NULL,
458 pkgmgrSignalInterface);
461 void WrtInstaller::unistallWgtFileStep()
463 LogDebug("Uninstalling widget ...");
468 ConfigParserData configInfo;
471 std::unique_ptr<DPL::ZipInput> zipFile(
472 new DPL::ZipInput(m_packagePath));
473 std::unique_ptr<DPL::ZipInput::File> configFile;
476 // Open config.xml file
477 configFile.reset(zipFile->OpenFile(CONFIG_XML));
479 Catch(DPL::ZipInput::Exception::OpenFileFailed)
481 // Open config.xml file for hybrid
482 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
486 DPL::BinaryQueue buffer;
487 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
488 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
489 DPL::Copy(&inputAdapter, &outputAdapter);
490 parser.Parse(&buffer,
492 new RootParser<WidgetParser>(configInfo,
493 DPL::FromUTF32String(
496 DPL::OptionalString pkgId = configInfo.tizenPkgId;
497 if (!pkgId.IsNull()) {
498 LogDebug("Pkgid from packagePath : " << pkgId);
499 wrt_uninstall_widget(
500 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
501 !m_quiet ? &staticWrtUninstallProgressCallback
503 pkgmgrSignalInterface);
505 LogError("Fail to uninstalling widget... ");
507 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
509 WRTInstallerNS::QuitEvent());
512 Catch(DPL::ZipInput::Exception::OpenFailed)
514 LogError("Failed to open widget package");
515 printf("failed: widget package does not exist\n");
517 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
519 WRTInstallerNS::QuitEvent());
521 Catch(DPL::ZipInput::Exception::OpenFileFailed)
523 printf("failed: widget config file does not exist\n");
524 LogError("Failed to open config.xml file");
526 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
528 WRTInstallerNS::QuitEvent());
530 Catch(ElementParser::Exception::ParseError)
532 printf("failed: can not parse config file\n");
533 LogError("Failed to parse config.xml file");
535 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
537 WRTInstallerNS::QuitEvent());
541 void WrtInstaller::shutdownStep()
543 LogDebug("Closing Wrt connection ...");
545 wrt_installer_shutdown();
546 m_initialized = false;
547 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
549 WRTInstallerNS::QuitEvent());
553 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
556 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
559 if (status == WRT_SUCCESS) {
560 LogDebug("Init succesfull");
561 This->m_initialized = true;
562 This->m_returnStatus = 0;
564 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
565 ::PostEvent(WRTInstallerNS::NextStepEvent());
567 LogError("Init unsuccesfull");
568 This->m_returnStatus = -1;
569 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
571 WRTInstallerNS::QuitEvent());
575 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
579 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
582 Step current = This->GetCurrentStep();
583 DPL::String resultMsg;
584 std::string printMsg;
586 if (current == &WrtInstaller::installStep) {
587 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
588 printMsg = "installation";
589 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
590 current == &WrtInstaller::unistallWgtFileStep)
592 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
593 printMsg = "uninstallation";
596 if (WRT_SUCCESS != status) {
598 LogError("Step failed");
599 This->m_returnStatus = -1;
601 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
602 ::PostEvent(WRTInstallerNS::QuitEvent());
605 case WRT_INSTALLER_ERROR_PACKAGE_NOT_FOUND:
606 This->m_returnStatus = 1; //this status is specific
607 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
608 tizenId.c_str(), printMsg.c_str());
611 case WRT_INSTALLER_ERROR_PACKAGE_INVALID:
612 This->m_returnStatus = 1; //this status is specific
613 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
614 tizenId.c_str(), printMsg.c_str());
617 case WRT_INSTALLER_ERROR_PACKAGE_LOWER_VERSION:
618 This->m_returnStatus = 1; //this status is specific
619 fprintf(stderr, "## wrt-installer : %s %s has failed - given"
620 " version is lower than existing version\n",
621 tizenId.c_str(), printMsg.c_str());
624 case WRT_INSTALLER_ERROR_MANIFEST_NOT_FOUND:
625 This->m_returnStatus = 1; //this status is specific
626 fprintf(stderr, "## wrt-installer : %s %s has failed - manifest"
627 " file doesn't find in package.\n",
628 tizenId.c_str(), printMsg.c_str());
631 case WRT_INSTALLER_ERROR_MANIFEST_INVALID:
632 This->m_returnStatus = 1; //this status is specific
633 fprintf(stderr, "## wrt-installer : %s %s has failed - "
634 "invalid manifestx.xml\n",
635 tizenId.c_str(), printMsg.c_str());
638 case WRT_INSTALLER_CONFIG_NOT_FOUND:
639 This->m_returnStatus = 1; //this status is specific
640 fprintf(stderr, "## wrt-installer : %s %s has failed - "
641 "config.xml does not exist\n",
642 tizenId.c_str(), printMsg.c_str());
645 case WRT_INSTALLER_ERROR_CONFIG_INVALID:
646 This->m_returnStatus = 1; //this status is specific
647 fprintf(stderr, "## wrt-installer : %s %s has failed - "
648 "invalid config.xml\n",
649 tizenId.c_str(), printMsg.c_str());
652 case WRT_INSTALLER_ERROR_SIGNATURE_NOT_FOUND:
653 This->m_returnStatus = 1; //this status is specific
654 fprintf(stderr, "## wrt-installer : %s %s has failed - "
655 "signature doesn't exist in package.\n",
656 tizenId.c_str(), printMsg.c_str());
659 case WRT_INSTALLER_ERROR_SIGNATURE_INVALID:
660 This->m_returnStatus = 1; //this status is specific
661 fprintf(stderr, "## wrt-installer : %s %s has failed - "
662 "invalid signature.\n",
663 tizenId.c_str(), printMsg.c_str());
666 case WRT_INSTALLER_ERROR_SIGNATURE_VERIFICATION_FAILED:
667 This->m_returnStatus = 1; //this status is specific
668 fprintf(stderr, "## wrt-installer : %s %s has failed - "
669 "signature verification failed.\n",
670 tizenId.c_str(), printMsg.c_str());
673 case WRT_INSTALLER_ERROR_ROOT_CERTIFICATE_NOT_FOUND:
674 This->m_returnStatus = 1; //this status is specific
675 fprintf(stderr, "## wrt-installer : %s %s has failed - "
676 "root certificate could not find.\n",
677 tizenId.c_str(), printMsg.c_str());
680 case WRT_INSTALLER_ERROR_CERTIFICATION_INVAID:
681 This->m_returnStatus = 1; //this status is specific
682 fprintf(stderr, "## wrt-installer : %s %s has failed - "
683 "invalid certification.\n",
684 tizenId.c_str(), printMsg.c_str());
687 case WRT_INSTALLER_ERROR_CERTIFICATE_CHAIN_VERIFICATION_FAILED:
688 This->m_returnStatus = 1; //this status is specific
689 fprintf(stderr, "## wrt-installer : %s %s has failed - "
690 "certificate chain verification failed.\n",
691 tizenId.c_str(), printMsg.c_str());
694 case WRT_INSTALLER_ERROR_CERTIFICATE_EXPIRED:
695 This->m_returnStatus = 1; //this status is specific
696 fprintf(stderr, "## wrt-installer : %s %s has failed - "
697 "certificate expired.\n",
698 tizenId.c_str(), printMsg.c_str());
701 case WRT_INSTALLER_ERROR_INVALID_PRIVILEGE:
702 This->m_returnStatus = 1; //this status is specific
703 fprintf(stderr, "## wrt-installer : %s %s has failed - "
704 "invalid privilege\n",
705 tizenId.c_str(), printMsg.c_str());
708 case WRT_INSTALLER_ERROR_MENU_ICON_NOT_FOUND:
709 This->m_returnStatus = 1; //this status is specific
710 fprintf(stderr, "## wrt-installer : %s %s has failed - "
711 "menu icon could not find\n",
712 tizenId.c_str(), printMsg.c_str());
715 case WRT_INSTALLER_ERROR_FATAL_ERROR:
716 This->m_returnStatus = 1; //this status is specific
717 fprintf(stderr, "## wrt-installer : %s %s has failed - "
719 tizenId.c_str(), printMsg.c_str());
722 case WRT_INSTALLER_ERROR_OUT_OF_STORAGE:
723 This->m_returnStatus = 1; //this status is specific
724 fprintf(stderr, "## wrt-installer : %s %s has failed - "
726 tizenId.c_str(), printMsg.c_str());
729 case WRT_INSTALLER_ERROR_OUT_OF_MEMORY:
730 This->m_returnStatus = 1; //this status is specific
731 fprintf(stderr, "## wrt-installer : %s %s has failed - "
733 tizenId.c_str(), printMsg.c_str());
736 case WRT_INSTALLER_ERROR_PACKAGE_ALREADY_INSTALLED:
737 This->m_returnStatus = 1; //this status is specific
738 fprintf(stderr, "## wrt-installer : %s %s has failed - "
739 "package already installed\n",
740 tizenId.c_str(), printMsg.c_str());
743 case WRT_INSTALLER_ERROR_ACE_CHECK_FAILED:
744 This->m_returnStatus = 1; //this status is specific
745 fprintf(stderr, "## wrt-installer : %s %s has failed - "
746 "ace check failure\n",
747 tizenId.c_str(), printMsg.c_str());
750 case WRT_INSTALLER_ERROR_MANIFEST_CREATE_FAILED:
751 This->m_returnStatus = 1; //this status is specific
752 fprintf(stderr, "## wrt-installer : %s %s has failed - "
753 "to create manifest failed\n",
754 tizenId.c_str(), printMsg.c_str());
757 case WRT_INSTALLER_ERROR_ENCRYPTION_FAILED:
758 This->m_returnStatus = 1; //this status is specific
759 fprintf(stderr, "## wrt-installer : %s %s has failed - "
760 "encryption of resource failed\n",
761 tizenId.c_str(), printMsg.c_str());
764 case WRT_INSTALLER_ERROR_INSTALL_OSP_SERVCIE:
765 This->m_returnStatus = 1; //this status is specific
766 fprintf(stderr, "## wrt-installer : %s %s has failed - "
767 "installation of osp service failed\n",
768 tizenId.c_str(), printMsg.c_str());
771 case WRT_INSTALLER_ERROR_UNINSTALLATION_FAILED:
772 This->m_returnStatus = 1; //this status is specific
773 fprintf(stderr, "## wrt-installer : %s %s has failed - "
774 "widget uninstallation failed\n",
775 tizenId.c_str(), printMsg.c_str());
779 case WRT_INSTALLER_ERROR_UNKNOWN:
780 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
781 tizenId.c_str(), printMsg.c_str());
789 "## wrt-installer : %s %s was successful.\n",
792 LogDebug("Status succesfull");
793 This->m_returnStatus = 0;
794 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
796 if (This->m_installMode == WRT_INSTALL_MODE_INSTALL_PRELOAD &&
797 !This->m_packagePath.empty()) {
798 LogDebug("This widget is preloaded so it will be removed : "
799 << This->m_packagePath);
800 if (!WrtUtilRemove(This->m_packagePath)) {
801 LogError("Failed to remove " << This->m_packagePath);
805 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
807 ::PostEvent(WRTInstallerNS::NextStepEvent());
811 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
816 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
818 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
820 std::string path = std::string(data->pluginPath);
823 This->m_numPluginsToInstall--;
824 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
826 if (This->m_numPluginsToInstall < 1) {
827 LogDebug("All plugins installation completed");
828 fprintf(stderr, "All plugins installation completed.\n");
830 //remove installation request
831 if (!PluginUtils::removeInstallationRequiredFlag()) {
832 LogInfo("Failed to remove file initializing plugin installation");
836 if (!PluginUtils::unlockPluginInstallation(This->m_installMode ==
837 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
838 LogInfo("Failed to remove installation lock");
841 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
842 ::PostEvent(WRTInstallerNS::NextStepEvent());
844 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
845 InstallPluginEvent>::
847 WRTInstallerNS::InstallPluginEvent());
850 if (WRT_SUCCESS == status) {
851 This->m_returnStatus = 0;
853 "## wrt-installer : plugin installation successfull [%s]\n",
855 LogDebug("One plugin Installation succesfull: " << path);
860 LogWarning("One of the plugins installation failed!: " << path);
863 case WRT_INSTALLER_ERROR_PLUGIN_INSTALLATION_FAILED:
864 LogError("failed: plugin installation failed\n");
867 case WRT_INSTALLER_ERROR_UNKNOWN:
868 LogError("failed: unknown error\n");
876 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
877 const char* description,
880 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
882 std::string path = std::string(data->pluginPath);
884 LogInfo("Plugin Installation: " << path <<
885 " progress: " << percent <<
886 "description " << description);
889 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
890 const char* description,
893 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
894 LogInfo(" progress: " << percent <<
895 " description: " << description);
897 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
898 const char* description,
901 //WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
902 LogInfo(" progress: " << percent <<
903 " description: " << description);
906 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
907 void* /*event_info*/)
909 WrtInstaller *This = static_cast<WrtInstaller*>(data);
912 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
913 ::PostEvent(WRTInstallerNS::NextStepEvent());
916 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
917 void* /*event_info*/)
919 WrtInstaller *This = static_cast<WrtInstaller*>(data);
922 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
923 ::PostEvent(WRTInstallerNS::QuitEvent());
926 void WrtInstaller::installNewPlugins()
928 LogDebug("Install new plugins");
930 if (!PluginUtils::lockPluginInstallation(m_installMode ==
931 WRT_INSTALL_MODE_INSTALL_PRELOAD)) {
932 LogInfo("Lock NOT created");
936 if (!PluginUtils::checkPluginInstallationRequired()) {
937 LogDebug("Plugin installation not required");
938 PluginUtils::unlockPluginInstallation(m_installMode ==
939 WRT_INSTALL_MODE_INSTALL_PRELOAD);
943 m_startupPluginInstallation = true;
944 AddStep(&WrtInstaller::installPluginsStep);
947 int main(int argc, char *argv[])
949 UNHANDLED_EXCEPTION_HANDLER_BEGIN
951 // Output on stdout will be flushed after every newline character,
952 // even if it is redirected to a pipe. This is useful for running
953 // from a script and parsing output.
954 // (Standard behavior of stdlib is to use full buffering when
955 // redirected to a pipe, which means even after an end of line
956 // the output may not be flushed).
959 // Check and re-set the file open limitation
961 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
962 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
963 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
965 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
966 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
967 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
968 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
969 LogError("setrlimit is fail!!");
973 LogError("getrlimit is fail!!");
976 // set evas backend type for emulator
977 // popup isn't showed in the emulator,
978 // if backend isn't set to SW backend
979 if (GlobalSettings::IsEmulator()) {
980 if (setenv("ELM_ENGINE", "x11", 1)) {
981 LogDebug("Enable backend");
985 WrtInstaller app(argc, argv);
986 int ret = app.Exec();
987 LogDebug("App returned: " << ret);
988 ret = app.getReturnStatus();
989 LogDebug("WrtInstaller returned: " << ret);
992 UNHANDLED_EXCEPTION_HANDLER_END