2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 /* @file wrt_installer.cpp
18 * @brief Implementation file for installer
21 #include "wrt_installer.h"
22 #include "plugin_utils.h"
29 #include <sys/resource.h>
30 #include <dpl/optional.h>
31 #include <dpl/scoped_free.h>
32 #include <dpl/optional_typedefs.h>
33 #include <dpl/exception.h>
34 #include <dpl/sstream.h>
36 #include <dpl/wrt-dao-ro/global_config.h>
37 #include <dpl/wrt-dao-ro/config_parser_data.h>
38 #include <dpl/localization/localization_utils.h>
39 #include <dpl/optional_typedefs.h>
40 #include <dpl/string.h>
41 #include <dpl/abstract_waitable_input_adapter.h>
42 #include <dpl/abstract_waitable_output_adapter.h>
43 #include <dpl/zip_input.h>
44 #include <dpl/binary_queue.h>
46 #include <dpl/errno_string.h>
47 #include <dpl/utils/wrt_global_settings.h>
48 #include "option_parser.h"
49 #include <parser_runner.h>
50 #include <widget_parser.h>
51 #include <root_parser.h>
55 #define NOFILE_CNT_FOR_INSTALLER 9999
57 using namespace WrtDB;
59 namespace { // anonymous
60 const char AUL_ARG_KEY[] = "widget_arg";
61 const char * const PKGMGR_INSTALL_MSG = "Install widget";
62 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
64 const double BASE_LAYOUT_W = 720.0f;
65 const double BASE_LAYOUT_H = 1280.0f;
67 const char * const CONFIG_XML = "config.xml";
71 void operator()(void* x) { free(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),
87 m_numPluginsToInstall(0),
90 m_installByPkgmgr(false),
93 m_startupPluginInstallation(false),
94 m_preloadWidget(false)
97 LogDebug("App Created");
100 WrtInstaller::~WrtInstaller()
102 LogDebug("App Finished");
105 void WrtInstaller::OnStop()
107 LogInfo("Stopping Dummy Client");
110 void WrtInstaller::OnCreate()
112 LogInfo("Creating DummyClient");
114 "===========================================================\n");
115 fprintf(stderr, "# wrt-installer #\n");
116 fprintf(stderr, "# argc [%ld]\n", m_argc);
117 fprintf(stderr, "# argv[0] = [%s]\n", m_argv[0]);
118 fprintf(stderr, "# argv[1] = [%s]\n", m_argv[1]);
119 fprintf(stderr, "# argv[2] = [%s]\n", m_argv[2]);
121 "===========================================================\n");
123 AddStep(&WrtInstaller::initStep);
125 std::string arg = m_argv[0];
127 pkgmgrSignalInterface = std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
128 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
129 new PackageManager::PkgmgrSignalDummy()
134 return showHelpAndQuit();
139 if (arg.find("wrt-installer") != std::string::npos)
142 return showHelpAndQuit();
146 if (arg == "-h" || arg == "--help") {
148 return showHelpAndQuit();
152 return showHelpAndQuit();
153 } else if (arg == "-p" || arg == "--install-plugins") {
155 return showHelpAndQuit();
157 if (!m_startupPluginInstallation) {
158 AddStep(&WrtInstaller::installPluginsStep);
160 LogInfo("Plugin installation alredy started");
162 } else if (arg == "-i" || arg == "--install") {
164 return showHelpAndQuit();
168 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
169 LogInfo("Installing package directly from directory");
170 m_installPolicy = WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL;
174 LogInfo("Installing from regular location");
175 m_installPolicy = WRT_WIM_POLICY_WAC;
177 m_packagePath = m_argv[2];
178 AddStep(&WrtInstaller::installStep);
179 } else if (arg == "-if" || arg == "--install-force") {
181 return showHelpAndQuit();
184 m_packagePath = m_argv[2];
185 m_installPolicy = WRT_WIM_POLICY_FORCE_INSTALL;
186 AddStep(&WrtInstaller::installStep);
187 } else if (arg == "-il" || arg == "--install-preload") {
189 return showHelpAndQuit();
192 m_packagePath = m_argv[2];
193 m_preloadWidget = true;
194 m_installPolicy = WRT_WIM_POLICY_WAC;
195 AddStep(&WrtInstaller::installStep);
196 } else if (arg == "-un" || arg == "--uninstall-name") {
198 return showHelpAndQuit();
201 AddStep(&WrtInstaller::uninstallPkgNameStep);
202 } else if (arg == "-ug" || arg == "--uninstall-guid") {
204 return showHelpAndQuit();
207 AddStep(&WrtInstaller::uninstallGuidStep);
208 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
210 return showHelpAndQuit();
212 m_packagePath = m_argv[2];
213 AddStep(&WrtInstaller::unistallWgtFileStep);
215 return showHelpAndQuit();
218 } else if (arg.find("backend") != std::string::npos) {
219 using namespace PackageManager;
220 m_installByPkgmgr = true;
222 auto pkgmgrSignal = std::shared_ptr<PackageManager::PkgmgrSignal>(
223 new PackageManager::PkgmgrSignal()
226 pkgmgrSignal->initialize(m_argc, m_argv);
227 m_quiet = pkgmgrSignal->isNoPopupRequired();
228 LogDebug("backend m_quiet"<<m_quiet);
230 int reqType = pkgmgrSignal->getRequestedType();
232 pkgmgrSignalInterface =
233 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(pkgmgrSignal);
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_installPolicy = WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL;
244 LogInfo("Installing from regular location");
245 m_installPolicy = WRT_WIM_POLICY_WAC;
247 AddStep(&WrtInstaller::installStep);
249 case PKGMGR_REQ_UNINSTALL:
251 AddStep(&WrtInstaller::uninstallPkgNameStep);
254 LogDebug("Not available type");
259 AddStep(&WrtInstaller::shutdownStep);
260 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::PostEvent(
261 WRTInstallerNS::NextStepEvent());
264 void WrtInstaller::OnReset(bundle *b)
266 const char * bundledVal = bundle_get_val(b, AUL_ARG_KEY);
267 if (bundledVal != NULL) {
268 m_bundleValue = bundledVal;
269 LogInfo("Bundled value for (" << AUL_ARG_KEY << ") key received: " <<
274 int WrtInstaller::getReturnStatus() const
276 if (!m_returnStatus) {
283 void WrtInstaller::OnTerminate()
285 LogDebug("Wrt Shutdown now");
286 PluginUtils::unlockPluginInstallation();
288 wrt_installer_shutdown();
293 void WrtInstaller::showHelpAndQuit()
295 printf("Usage: wrt-installer [OPTION]... [WIDGET: ID/NAME/GUID/PATH]...\n"
296 "Operate with WebRuntime daemon: install, uninstall"
297 " and launch widgets.\n"
298 "Query list of installed widgets and setup up debugging support.\n"
300 "Exactly one option must be selected.\n"
301 "Mandatory arguments to long options are mandatory for short "
303 " -h, --help show this help\n"
304 " -p, --install-plugins install plugins\n"
306 "install or update widget package for given path\n"
307 " -if, --install-force "
308 "install forcibly widget package for given path\n"
309 " -un, --uninstall-name "
310 "uninstall widget for given package name\n"
311 " -ug, --uninstall-guid "
312 "uninstall widget for given Global Unique IDentifier\n"
313 " -up, --uninstall-packagepath "
314 "uninstall widget for given package file path\n"
320 void WrtInstaller::OnEventReceived(const WRTInstallerNS::QuitEvent& /*event*/)
325 LogDebug("Wrt Shutdown now");
326 SwitchToStep(&WrtInstaller::shutdownStep);
327 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::PostEvent(
328 WRTInstallerNS::NextStepEvent());
330 LogDebug("Quiting application");
335 void WrtInstaller::OnEventReceived(
336 const WRTInstallerNS::NextStepEvent& /*event*/)
338 LogDebug("Executing next step");
342 void WrtInstaller::OnEventReceived(
343 const WRTInstallerNS::InstallPluginEvent& /*event*/)
345 PluginInstallerData* privateData = new PluginInstallerData;
346 privateData->wrtInstaller = this;
348 if (!(*m_pluginsPaths).empty()) {
349 privateData->pluginPath = (*m_pluginsPaths).front();
350 (*m_pluginsPaths).pop_front();
352 wrt_install_plugin(privateData->pluginPath.c_str(),
353 static_cast<void*>(privateData),
354 &staticWrtPluginInstallationCallback,
355 &staticWrtPluginInstallProgressCb);
361 void WrtInstaller::initStep()
363 wrt_installer_init(this, staticWrtInitCallback);
366 void WrtInstaller::installStep()
368 LogDebug("Installing widget ...");
369 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
370 m_packagePath.c_str()));
372 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
373 this, &staticWrtStatusCallback,
374 (!m_quiet || m_installByPkgmgr)
375 ? &staticWrtInstallProgressCallback : NULL,
379 pkgmgrSignalInterface);
382 void WrtInstaller::installPluginsStep()
384 LogDebug("Installing plugins ...");
385 fprintf(stderr,"Installing plugins ...\n");
387 if (m_startupPluginInstallation) {
388 LogInfo("Plugin installation started because new plugin package found");
389 } else if (!PluginUtils::lockPluginInstallation()) {
390 LogError("Failed to open plugin installation lock file"
391 " Plugins are currently installed by other process");
392 staticWrtPluginInstallationCallback(WRT_PLUGIN_INSTALLER_ERROR_LOCK,
397 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
400 dir = opendir(PLUGIN_PATH.c_str());
406 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
407 struct dirent* libdir;
411 std::list<std::string> pluginsPaths;
413 while ((libdir = readdir(dir)) != 0) {
414 if (strcmp(libdir->d_name, ".") == 0 ||
415 strcmp(libdir->d_name, "..") == 0)
420 std::string path = PLUGIN_PATH;
422 path += libdir->d_name;
426 if (stat(path.c_str(), &tmp) == -1) {
427 LogError("Failed to open file" << path);
431 if (!S_ISDIR(tmp.st_mode)) {
432 LogError("Not a directory" << path);
436 pluginsPaths.push_back(path);
439 //set nb of plugins to install
440 //this value indicate how many callbacks are expected
441 m_numPluginsToInstall = pluginsPaths.size();
442 LogInfo("Plugins to install: " << m_numPluginsToInstall);
443 m_pluginsPaths = pluginsPaths;
445 m_totalPlugins = m_numPluginsToInstall;
446 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
447 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
449 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
450 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
451 << DPL::GetErrnoString());
455 void WrtInstaller::uninstallPkgNameStep()
457 LogDebug("Uninstalling widget ...");
458 LogDebug("Package name : " << m_name);
459 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
460 (!m_quiet || m_installByPkgmgr)
461 ? &staticWrtUninstallProgressCallback : NULL,
462 pkgmgrSignalInterface);
465 void WrtInstaller::uninstallGuidStep()
467 LogDebug("Uninstalling widget ...");
469 WrtErrStatus status = wrt_get_widget_by_guid(pkgname, m_name);
470 if (status == WRT_SUCCESS) {
471 LogDebug("Guid : " << m_name);
472 wrt_uninstall_widget(pkgname.c_str(), this, &staticWrtStatusCallback,
473 !m_quiet ? &staticWrtUninstallProgressCallback : NULL,
474 pkgmgrSignalInterface);
476 printf("failed: can not uninstall widget\n");
477 LogError("Fail to uninstalling widget... ");
479 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
480 WRTInstallerNS::QuitEvent());
484 void WrtInstaller::unistallWgtFileStep()
486 LogDebug("Uninstalling widget ...");
491 ConfigParserData configInfo;
494 std::unique_ptr<DPL::ZipInput> zipFile(
495 new DPL::ZipInput(m_packagePath));
497 // Open config.xml file
498 std::unique_ptr<DPL::ZipInput::File> configFile(
499 zipFile->OpenFile(CONFIG_XML));
502 DPL::BinaryQueue buffer;
503 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
504 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
505 DPL::Copy(&inputAdapter, &outputAdapter);
506 parser.Parse(&buffer,
508 new RootParser<WidgetParser>(configInfo,
509 DPL::FromUTF32String(
512 DPL::OptionalString widgetGUID = configInfo.widget_id;
514 std::string guid = DPL::ToUTF8String(*widgetGUID);
517 WrtErrStatus status = wrt_get_widget_by_guid(pkgname, guid);
518 if (status == WRT_SUCCESS) {
519 LogDebug("Pkgname from packagePath : " << pkgname);
520 wrt_uninstall_widget(pkgname.c_str(), this, &staticWrtStatusCallback,
521 !m_quiet ? &staticWrtUninstallProgressCallback : NULL,
522 pkgmgrSignalInterface);
524 LogError("Fail to uninstalling widget... ");
526 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
527 WRTInstallerNS::QuitEvent());
530 Catch(DPL::ZipInput::Exception::OpenFailed)
532 LogError("Failed to open widget package");
533 printf("failed: widget package does not exist\n");
535 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
536 WRTInstallerNS::QuitEvent());
538 Catch(DPL::ZipInput::Exception::OpenFileFailed)
540 printf("failed: widget config file does not exist\n");
541 LogError("Failed to open config.xml file");
543 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
544 WRTInstallerNS::QuitEvent());
546 Catch(ElementParser::Exception::ParseError)
548 printf("failed: can not parse config file\n");
549 LogError("Failed to parse config.xml file");
551 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
552 WRTInstallerNS::QuitEvent());
556 void WrtInstaller::shutdownStep()
558 LogDebug("Closing Wrt connection ...");
560 wrt_installer_shutdown();
561 m_initialized = false;
562 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
563 WRTInstallerNS::QuitEvent());
567 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
570 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
573 if (status == WRT_SUCCESS) {
574 LogDebug("Init succesfull");
575 This->m_initialized = true;
576 This->m_returnStatus = 0;
578 if (This->popupsEnabled()) {
579 This->m_popup = new InstallerPopup;
580 This->m_popup->init();
583 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
584 ::PostEvent(WRTInstallerNS::NextStepEvent());
586 LogError("Init unsuccesfull");
587 This->m_returnStatus = -1;
588 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::PostEvent(
589 WRTInstallerNS::QuitEvent());
593 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
597 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
600 Step current = This->GetCurrentStep();
601 DPL::String resultMsg;
602 std::string printMsg;
604 if (current == &WrtInstaller::installStep)
606 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
607 printMsg = "installation";
608 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
609 current == &WrtInstaller::uninstallGuidStep ||
610 current == &WrtInstaller::unistallWgtFileStep)
612 resultMsg = DPL::FromUTF8String(PKGMGR_UNINSTALL_MSG);
613 printMsg = "uninstallation";
616 if (WRT_SUCCESS != status) {
618 LogError("Step failed");
619 This->m_returnStatus = -1;
621 if (This->popupsEnabled()) {
622 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
623 This->m_popup->showPopup(This, resultMsg, failResultCallback);
625 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
626 ::PostEvent(WRTInstallerNS::QuitEvent());
630 case WRT_INSTALLER_ERROR_INVALID_WIDGET_PACKAGE:
631 This->m_returnStatus = 1; //this status is specific
632 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
633 tizenId.c_str(), printMsg.c_str());
636 case WRT_INSTALLER_ERROR_WIDGET_DOES_NOT_EXIST:
637 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
638 tizenId.c_str(), printMsg.c_str());
641 case WRT_INSTALLER_ERROR_ALREADY_UNINSTALLING:
642 fprintf(stderr, "## wrt-installer : %s %s has failed - already uninstalling\n",
643 tizenId.c_str(), printMsg.c_str());
646 case WRT_INSTALLER_ERROR_OUT_OUT_DISK_SPACE:
647 fprintf(stderr,"## wrt-installer : %s %s has failed - out of disk space\n",
648 tizenId.c_str(), printMsg.c_str());
651 case WRT_INSTALLER_ERROR_INVALID_CERTIFICATE:
652 fprintf(stderr,"## wrt-installer : %s %s has failed - invalid certificate\n",
653 tizenId.c_str(), printMsg.c_str());
656 case WRT_INSTALLER_ERROR_ALREADY_INSTALLED:
657 fprintf(stderr,"## wrt-installer : %s %s has failed - already installed\n",
658 tizenId.c_str(), printMsg.c_str());
661 case WRT_INSTALLER_ERROR_INTERNAL:
662 fprintf(stderr,"## wrt-installer : %s %s has failed - internal error\n",
663 tizenId.c_str(), printMsg.c_str());
666 case WRT_INSTALLER_ERROR_NOT_ALLOWED:
667 fprintf(stderr,"## wrt-installer : %s %s has failed - installation or update not allowed; invalid"
668 " mode\n", tizenId.c_str(), printMsg.c_str());
671 case WRT_INSTALLER_ERROR_DEFERRED:
672 fprintf(stderr,"## wrt-installer : deferred: widget update will continue after the widget"
673 " has been stopped\n");
676 case WRT_INSTALLER_ERROR_DATABASE_FAILURE:
677 fprintf(stderr,"## wrt-installer : %s %s has failed - database failure\n",
678 tizenId.c_str(), printMsg.c_str());
681 case WRT_INSTALLER_ERROR_OSPSVC:
682 fprintf(stderr,"## wrt-installer : %s %s has failed - during installation or"
683 " uninstallation osp service\n", tizenId.c_str(),
687 case WRT_INSTALLER_ERROR_UNKNOWN:
688 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
689 tizenId.c_str(), printMsg.c_str());
697 fprintf(stderr, "## wrt-installer : %s %s was successful.\n", tizenId.c_str(), printMsg.c_str());
698 LogDebug("Status succesfull");
699 This->m_returnStatus = 0;
700 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
702 if (This->popupsEnabled()) {
703 This->m_popup->showPopup(This, resultMsg, showResultCallback);
705 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
706 ::PostEvent(WRTInstallerNS::NextStepEvent());
711 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
716 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
718 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
720 std::string path = std::string(data->pluginPath);
723 This->m_numPluginsToInstall--;
724 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
726 if (This->m_numPluginsToInstall < 1) {
727 LogDebug("All plugins installation completed");
728 fprintf(stderr,"All plugins installation completed.\n");
730 //remove installation request
731 if (!PluginUtils::removeInstallationRequiredFlag()) {
732 LogInfo("Failed to remove file initializing plugin installation");
736 if (!PluginUtils::unlockPluginInstallation()) {
737 LogInfo("Failed to remove installation lock");
740 if (This->popupsEnabled()) {
741 This->m_popup->init();
742 elm_progressbar_value_set(This->m_popup->m_progressbar, 100.0);
743 evas_object_show(This->m_popup->m_popup);
746 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
747 ::PostEvent(WRTInstallerNS::NextStepEvent());
749 if (This->popupsEnabled()) {
750 This->m_popup->init();
751 float percent = (This->m_totalPlugins - This->m_numPluginsToInstall)/(float)This->m_totalPlugins;
752 elm_progressbar_value_set(This->m_popup->m_progressbar, percent);
753 evas_object_show(This->m_popup->m_popup);
756 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>::PostEvent(
757 WRTInstallerNS::InstallPluginEvent());
760 if (WRT_SUCCESS == status) {
761 This->m_returnStatus = 0;
762 fprintf(stderr, "## wrt-installer : plugin installation successfull [%s]\n",
764 LogDebug("One plugin Installation succesfull: " << path);
769 LogWarning("One of the plugins installation failed!: " << path);
771 if (WRT_PLUGIN_INSTALLER_ERROR_WAITING == status) {
772 LogInfo("Plugin installation is waiting for dependencies");
773 fprintf(stderr, "## wrt-installer : plugin installation failed [%s]\n",
778 case WRT_PLUGIN_INSTALLER_ERROR_WRONG_PATH:
779 LogError("failed: wrong path to plugin directory\n");
782 case WRT_PLUGIN_INSTALLER_ERROR_METAFILE:
783 LogError("failed: plugin metafile error\n");
786 case WRT_PLUGIN_INSTALLER_ERROR_ALREADY_INSTALLED:
787 LogError("failed: plugin already installed\n");
790 case WRT_PLUGIN_INSTALLER_ERROR_LIBRARY_ERROR:
791 LogError("failed: plugin library: missing symbols or structures\n");
794 case WRT_PLUGIN_INSTALLER_ERROR_UNKNOWN:
795 LogError("failed: unknown error\n");
803 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
804 const char* description,
807 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
809 std::string path = std::string(data->pluginPath);
811 LogInfo("Plugin Installation: " << path <<
812 " progress: " << percent <<
813 "description " << description);
816 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
817 const char* description, void* userdata)
819 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
820 std::stringstream percentStr;
821 LogInfo(" progress: " << percent <<
822 " description: " << description);
824 if (This->popupsEnabled()) {
825 This->m_popup->init();
826 elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
827 evas_object_show(This->m_popup->m_popup);
830 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
831 const char* description, void* userdata)
833 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
834 std::stringstream percentStr;
835 LogInfo(" progress: " << percent <<
836 " description: " << description);
838 if (This->popupsEnabled()) {
839 This->m_popup->init();
840 elm_progressbar_value_set(This->m_popup->m_progressbar, percent/100.0);
841 evas_object_show(This->m_popup->m_popup);
845 WrtInstaller::InstallerPopup::InstallerPopup() :
852 WrtInstaller::InstallerPopup::~InstallerPopup()
854 LogDebug("App Finished");
857 void WrtInstaller::InstallerPopup::init()
859 LogDebug("Window Init");
863 m_win = createWin("wrt-installer");
866 m_popup = elm_popup_add(m_win);
868 // create progressbar
869 m_progressbar = elm_progressbar_add(m_popup);
870 elm_object_style_set(m_progressbar, "list_progress");
871 elm_progressbar_horizontal_set(m_progressbar, EINA_TRUE);
872 evas_object_size_hint_align_set(m_progressbar, EVAS_HINT_FILL,
874 evas_object_size_hint_weight_set(m_progressbar, EVAS_HINT_EXPAND,
876 elm_object_content_set(m_popup, m_progressbar);
877 elm_progressbar_value_set(m_progressbar, 0.0);
878 evas_object_show(m_progressbar);
880 evas_object_show(m_popup);
881 evas_object_show(m_win);
885 Evas_Object* WrtInstaller::InstallerPopup::createWin(const char *name)
888 win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
894 elm_win_alpha_set(win, EINA_TRUE);
895 elm_win_title_set(win, name);
896 elm_win_borderless_set(win, EINA_TRUE);
899 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
900 evas_object_resize(win, w, h);
904 void WrtInstaller::InstallerPopup::showPopup(void* userdata,
905 const DPL::String& pkgMsg,
906 ShowResultCallback callback)
911 LogDebug("Result Popup Created");
912 evas_object_del(m_popup);
915 m_popup = elm_popup_add(m_win);
919 btn = elm_button_add(m_popup);
921 evas_object_del(m_popup);
924 elm_object_text_set(btn, "OK");
925 evas_object_smart_callback_add(btn, "clicked", callback, userdata);
926 elm_object_part_content_set(m_popup, "button1", btn);
927 elm_object_part_text_set(m_popup, "title,text", "RESULT");
928 elm_object_text_set(m_popup, DPL::ToUTF8String(pkgMsg).c_str());
930 evas_object_show(m_popup);
931 evas_object_show(m_win);
935 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
936 void* /*event_info*/)
938 WrtInstaller *This = static_cast<WrtInstaller*>(data);
941 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
942 ::PostEvent(WRTInstallerNS::NextStepEvent());
945 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
946 void* /*event_info*/)
948 WrtInstaller *This = static_cast<WrtInstaller*>(data);
951 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
952 ::PostEvent(WRTInstallerNS::QuitEvent());
955 void WrtInstaller::installNewPlugins()
957 LogDebug("Install new plugins");
959 if (!PluginUtils::lockPluginInstallation()) {
960 LogInfo("Lock NOT created");
964 if (!PluginUtils::checkPluginInstallationRequired()) {
965 LogDebug("Plugin installation not required");
966 PluginUtils::unlockPluginInstallation();
970 m_startupPluginInstallation = true;
971 AddStep(&WrtInstaller::installPluginsStep);
974 bool WrtInstaller::popupsEnabled() const
976 return !m_quiet && !GlobalSettings::PopupsTestModeEnabled();
979 int main(int argc, char *argv[])
981 UNHANDLED_EXCEPTION_HANDLER_BEGIN
983 // Output on stdout will be flushed after every newline character,
984 // even if it is redirected to a pipe. This is useful for running
985 // from a script and parsing output.
986 // (Standard behavior of stdlib is to use full buffering when
987 // redirected to a pipe, which means even after an end of line
988 // the output may not be flushed).
991 // Check and re-set the file open limitation
993 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
994 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")" );
995 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")" );
997 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
998 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
999 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1000 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1001 LogError("setrlimit is fail!!");
1005 LogError("getrlimit is fail!!");
1008 // set evas backend type for emulator
1009 // popup isn't showed in the emulator,
1010 // if backend isn't set to SW backend
1011 if (GlobalSettings::IsEmulator()) {
1012 if (setenv("ELM_ENGINE", "x11", 1)) {
1013 LogDebug("Enable backend");
1017 WrtInstaller app(argc, argv);
1018 int ret = app.Exec();
1019 LogDebug("App returned: " << ret);
1020 ret = app.getReturnStatus();
1021 LogDebug("WrtInstaller returned: " << ret);
1024 UNHANDLED_EXCEPTION_HANDLER_END