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>
53 #define NOFILE_CNT_FOR_INSTALLER 9999
55 using namespace WrtDB;
57 namespace { // anonymous
58 const char AUL_ARG_KEY[] = "widget_arg";
59 const char * const PKGMGR_INSTALL_MSG = "Install widget";
60 const char * const PKGMGR_UNINSTALL_MSG = "Uninstall widget";
62 const double BASE_LAYOUT_W = 720.0f;
63 const double BASE_LAYOUT_H = 1280.0f;
65 const char * const CONFIG_XML = "config.xml";
66 const char * const HYBRID_CONFIG_XML = "res/wgt/config.xml";
70 void operator()(void* x)
76 struct PluginInstallerData
79 std::string pluginPath;
81 } // namespace anonymous
83 WrtInstaller::WrtInstaller(int argc, char **argv) :
84 Application(argc, argv, "backend", false),
85 DPL::TaskDecl<WrtInstaller>(this),
86 m_installPolicy(WRT_WIM_NOT_INSTALLED),
90 m_numPluginsToInstall(0),
93 m_installByPkgmgr(false),
96 m_startupPluginInstallation(false),
97 m_preloadWidget(false)
100 LogDebug("App Created");
103 WrtInstaller::~WrtInstaller()
105 LogDebug("App Finished");
108 void WrtInstaller::OnStop()
110 LogInfo("Stopping Dummy Client");
113 void WrtInstaller::OnCreate()
115 LogInfo("Creating DummyClient");
117 "===========================================================\n");
118 fprintf(stderr, "# wrt-installer #\n");
119 fprintf(stderr, "# argc [%d]\n", m_argc);
120 fprintf(stderr, "# argv[0] = [%s]\n", m_argv[0]);
121 fprintf(stderr, "# argv[1] = [%s]\n", m_argv[1]);
122 fprintf(stderr, "# argv[2] = [%s]\n", m_argv[2]);
124 "===========================================================\n");
126 AddStep(&WrtInstaller::initStep);
128 std::string arg = m_argv[0];
130 pkgmgrSignalInterface =
131 std::static_pointer_cast<PackageManager::IPkgmgrSignal>(
132 std::shared_ptr<PackageManager::PkgmgrSignalDummy>(
133 new PackageManager::PkgmgrSignalDummy()
138 return showHelpAndQuit();
143 if (arg.find("wrt-installer") != std::string::npos) {
145 return showHelpAndQuit();
149 if (arg == "-h" || arg == "--help") {
151 return showHelpAndQuit();
155 return showHelpAndQuit();
156 } else if (arg == "-p" || arg == "--install-plugins") {
158 return showHelpAndQuit();
160 if (!m_startupPluginInstallation) {
161 AddStep(&WrtInstaller::installPluginsStep);
163 LogInfo("Plugin installation alredy started");
165 } else if (arg == "-i" || arg == "--install") {
167 return showHelpAndQuit();
171 if (-1 != stat(m_argv[2], &info) && S_ISDIR(info.st_mode)) {
172 LogInfo("Installing package directly from directory");
173 m_installPolicy = WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL;
175 LogInfo("Installing from regular location");
176 m_installPolicy = WRT_WIM_POLICY_WAC;
178 m_packagePath = m_argv[2];
179 AddStep(&WrtInstaller::installStep);
180 } else if (arg == "-if" || arg == "--install-force") {
182 return showHelpAndQuit();
185 m_packagePath = m_argv[2];
186 m_installPolicy = WRT_WIM_POLICY_FORCE_INSTALL;
187 AddStep(&WrtInstaller::installStep);
188 } else if (arg == "-il" || arg == "--install-preload") {
190 return showHelpAndQuit();
193 m_packagePath = m_argv[2];
194 m_preloadWidget = true;
195 m_installPolicy = WRT_WIM_POLICY_WAC;
196 AddStep(&WrtInstaller::installStep);
197 } else if (arg == "-un" || arg == "--uninstall-name") {
199 return showHelpAndQuit();
202 AddStep(&WrtInstaller::uninstallPkgNameStep);
203 } else if (arg == "-ug" || arg == "--uninstall-guid") {
205 return showHelpAndQuit();
208 AddStep(&WrtInstaller::uninstallGuidStep);
209 } else if (arg == "-up" || arg == "--uninstall-packagepath") {
211 return showHelpAndQuit();
213 m_packagePath = m_argv[2];
214 AddStep(&WrtInstaller::unistallWgtFileStep);
216 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>(
236 case PKGMGR_REQ_INSTALL:
237 m_packagePath = m_argv[4];
239 if (-1 != stat(m_argv[4], &info) && S_ISDIR(info.st_mode)) {
240 LogInfo("Installing package directly from directory");
241 m_installPolicy = WRT_WIM_POLICY_DIRECTORY_FORCE_INSTALL;
243 LogInfo("Installing from regular location");
244 m_installPolicy = WRT_WIM_POLICY_WAC;
246 AddStep(&WrtInstaller::installStep);
248 case PKGMGR_REQ_UNINSTALL:
250 AddStep(&WrtInstaller::uninstallPkgNameStep);
253 LogDebug("Not available type");
258 AddStep(&WrtInstaller::shutdownStep);
259 DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>::
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>::
329 WRTInstallerNS::NextStepEvent());
331 LogDebug("Quiting application");
336 void WrtInstaller::OnEventReceived(
337 const WRTInstallerNS::NextStepEvent& /*event*/)
339 LogDebug("Executing next step");
343 void WrtInstaller::OnEventReceived(
344 const WRTInstallerNS::InstallPluginEvent& /*event*/)
346 PluginInstallerData* privateData = new PluginInstallerData;
347 privateData->wrtInstaller = this;
349 if (!(*m_pluginsPaths).empty()) {
350 privateData->pluginPath = (*m_pluginsPaths).front();
351 (*m_pluginsPaths).pop_front();
353 wrt_install_plugin(privateData->pluginPath.c_str(),
354 static_cast<void*>(privateData),
355 &staticWrtPluginInstallationCallback,
356 &staticWrtPluginInstallProgressCb);
362 void WrtInstaller::initStep()
364 wrt_installer_init(this, staticWrtInitCallback);
367 void WrtInstaller::installStep()
369 LogDebug("Installing widget ...");
370 std::unique_ptr<char, free_deleter> packagePath(canonicalize_file_name(
371 m_packagePath.c_str()));
373 wrt_install_widget(packagePath ? packagePath.get() : m_packagePath.c_str(),
374 this, &staticWrtStatusCallback,
375 (!m_quiet || m_installByPkgmgr)
376 ? &staticWrtInstallProgressCallback : NULL,
380 pkgmgrSignalInterface);
383 void WrtInstaller::installPluginsStep()
385 LogDebug("Installing plugins ...");
386 fprintf(stderr, "Installing plugins ...\n");
388 if (m_startupPluginInstallation) {
389 LogInfo("Plugin installation started because new plugin package found");
390 } else if (!PluginUtils::lockPluginInstallation()) {
391 LogError("Failed to open plugin installation lock file"
392 " Plugins are currently installed by other process");
393 staticWrtPluginInstallationCallback(WRT_PLUGIN_INSTALLER_ERROR_LOCK,
398 std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
401 dir = opendir(PLUGIN_PATH.c_str());
407 LogInfo("Plugin DIRECTORY IS" << PLUGIN_PATH);
409 std::list<std::string> pluginsPaths;
410 struct dirent libdir;
411 struct dirent *result;
414 for (return_code = readdir_r(dir, &libdir, &result);
415 result != NULL && return_code == 0;
416 return_code = readdir_r(dir, &libdir, &result))
418 if (strcmp(libdir.d_name, ".") == 0 ||
419 strcmp(libdir.d_name, "..") == 0)
424 std::string path = PLUGIN_PATH;
426 path += libdir.d_name;
430 if (stat(path.c_str(), &tmp) == -1) {
431 LogError("Failed to open file" << path);
435 if (!S_ISDIR(tmp.st_mode)) {
436 LogError("Not a directory" << path);
440 pluginsPaths.push_back(path);
443 if (return_code != 0 || errno != 0) {
444 LogError("readdir_r() failed with " << DPL::GetErrnoString());
447 //set nb of plugins to install
448 //this value indicate how many callbacks are expected
449 m_numPluginsToInstall = pluginsPaths.size();
450 LogInfo("Plugins to install: " << m_numPluginsToInstall);
451 m_pluginsPaths = pluginsPaths;
453 m_totalPlugins = m_numPluginsToInstall;
454 DPL::Event::ControllerEventHandler<WRTInstallerNS::InstallPluginEvent>
455 ::PostEvent(WRTInstallerNS::InstallPluginEvent());
457 if (-1 == TEMP_FAILURE_RETRY(closedir(dir))) {
458 LogError("Failed to close dir: " << PLUGIN_PATH << " with error: "
459 << DPL::GetErrnoString());
463 void WrtInstaller::uninstallPkgNameStep()
465 LogDebug("Uninstalling widget ...");
466 LogDebug("Package name : " << m_name);
467 wrt_uninstall_widget(m_name.c_str(), this, &staticWrtStatusCallback,
468 (!m_quiet || m_installByPkgmgr)
469 ? &staticWrtUninstallProgressCallback : NULL,
470 pkgmgrSignalInterface);
473 void WrtInstaller::uninstallGuidStep()
475 LogDebug("Uninstalling widget ...");
477 WrtErrStatus status = wrt_get_widget_by_guid(appid, m_name);
478 if (status == WRT_SUCCESS) {
479 LogDebug("Guid : " << m_name);
480 wrt_uninstall_widget(
481 appid.c_str(), this, &staticWrtStatusCallback,
482 !m_quiet ? &staticWrtUninstallProgressCallback :
484 pkgmgrSignalInterface);
486 printf("failed: can not uninstall widget\n");
487 LogError("Fail to uninstalling widget... ");
489 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
491 WRTInstallerNS::QuitEvent());
495 void WrtInstaller::unistallWgtFileStep()
497 LogDebug("Uninstalling widget ...");
502 ConfigParserData configInfo;
505 std::unique_ptr<DPL::ZipInput> zipFile(
506 new DPL::ZipInput(m_packagePath));
507 std::unique_ptr<DPL::ZipInput::File> configFile;
510 // Open config.xml file
511 configFile.reset(zipFile->OpenFile(CONFIG_XML));
513 Catch(DPL::ZipInput::Exception::OpenFileFailed)
515 // Open config.xml file for hybrid
516 configFile.reset(zipFile->OpenFile(HYBRID_CONFIG_XML));
520 DPL::BinaryQueue buffer;
521 DPL::AbstractWaitableInputAdapter inputAdapter(configFile.get());
522 DPL::AbstractWaitableOutputAdapter outputAdapter(&buffer);
523 DPL::Copy(&inputAdapter, &outputAdapter);
524 parser.Parse(&buffer,
526 new RootParser<WidgetParser>(configInfo,
527 DPL::FromUTF32String(
530 DPL::OptionalString pkgId = configInfo.tizenPkgId;
531 if (!pkgId.IsNull()) {
532 LogDebug("Pkgid from packagePath : " << pkgId);
533 wrt_uninstall_widget(
534 DPL::ToUTF8String(*pkgId).c_str(), this, &staticWrtStatusCallback,
535 !m_quiet ? &staticWrtUninstallProgressCallback
537 pkgmgrSignalInterface);
539 LogError("Fail to uninstalling widget... ");
541 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
543 WRTInstallerNS::QuitEvent());
546 Catch(DPL::ZipInput::Exception::OpenFailed)
548 LogError("Failed to open widget package");
549 printf("failed: widget package does not exist\n");
551 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
553 WRTInstallerNS::QuitEvent());
555 Catch(DPL::ZipInput::Exception::OpenFileFailed)
557 printf("failed: widget config file does not exist\n");
558 LogError("Failed to open config.xml file");
560 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
562 WRTInstallerNS::QuitEvent());
564 Catch(ElementParser::Exception::ParseError)
566 printf("failed: can not parse config file\n");
567 LogError("Failed to parse config.xml file");
569 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
571 WRTInstallerNS::QuitEvent());
575 void WrtInstaller::shutdownStep()
577 LogDebug("Closing Wrt connection ...");
579 wrt_installer_shutdown();
580 m_initialized = false;
581 DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
583 WRTInstallerNS::QuitEvent());
587 void WrtInstaller::staticWrtInitCallback(WrtErrStatus status,
590 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
593 if (status == WRT_SUCCESS) {
594 LogDebug("Init succesfull");
595 This->m_initialized = true;
596 This->m_returnStatus = 0;
598 if (This->popupsEnabled()) {
599 This->m_popup = new InstallerPopup;
600 This->m_popup->init();
603 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
604 ::PostEvent(WRTInstallerNS::NextStepEvent());
606 LogError("Init unsuccesfull");
607 This->m_returnStatus = -1;
608 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>::
610 WRTInstallerNS::QuitEvent());
614 void WrtInstaller::staticWrtStatusCallback(std::string tizenId,
618 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
621 Step current = This->GetCurrentStep();
622 DPL::String resultMsg;
623 std::string printMsg;
625 if (current == &WrtInstaller::installStep) {
626 resultMsg = DPL::FromUTF8String(PKGMGR_INSTALL_MSG);
627 printMsg = "installation";
628 } else if (current == &WrtInstaller::uninstallPkgNameStep ||
629 current == &WrtInstaller::uninstallGuidStep ||
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 if (This->popupsEnabled()) {
642 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_FAILURE);
643 This->m_popup->showPopup(This, resultMsg, failResultCallback);
645 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
646 ::PostEvent(WRTInstallerNS::QuitEvent());
650 case WRT_INSTALLER_ERROR_INVALID_WIDGET_PACKAGE:
651 This->m_returnStatus = 1; //this status is specific
652 fprintf(stderr, "## wrt-installer : %s %s has failed - invalid widget package\n",
653 tizenId.c_str(), printMsg.c_str());
656 case WRT_INSTALLER_ERROR_WIDGET_DOES_NOT_EXIST:
657 fprintf(stderr, "## wrt-installer : %s %s has failed - widget package does not exist\n",
658 tizenId.c_str(), printMsg.c_str());
661 case WRT_INSTALLER_ERROR_ALREADY_UNINSTALLING:
662 fprintf(stderr, "## wrt-installer : %s %s has failed - already uninstalling\n",
663 tizenId.c_str(), printMsg.c_str());
666 case WRT_INSTALLER_ERROR_INVALID_CERTIFICATE:
667 fprintf(stderr,"## wrt-installer : %s %s has failed - invalid certificate - invalid signature\n",
668 tizenId.c_str(), printMsg.c_str());
671 case WRT_INSTALLER_ERROR_ALREADY_INSTALLED:
672 fprintf(stderr,"## wrt-installer : %s %s has failed - already installed\n",
673 tizenId.c_str(), printMsg.c_str());
676 case WRT_INSTALLER_ERROR_INTERNAL:
677 fprintf(stderr,"## wrt-installer : %s %s has failed - internal error\n",
678 tizenId.c_str(), printMsg.c_str());
681 case WRT_INSTALLER_ERROR_NOT_ALLOWED:
682 fprintf(stderr,"## wrt-installer : %s %s has failed - installation or update not allowed; invalid"
683 " mode\n", tizenId.c_str(), printMsg.c_str());
686 case WRT_INSTALLER_ERROR_DEFERRED:
687 fprintf(stderr,"## wrt-installer : deferred: widget update will continue after the widget"
688 " has been stopped\n");
691 case WRT_INSTALLER_ERROR_DATABASE_FAILURE:
692 fprintf(stderr,"## wrt-installer : %s %s has failed - database failure\n",
693 tizenId.c_str(), printMsg.c_str());
696 case WRT_INSTALLER_ERROR_OSPSVC:
697 fprintf(stderr,"## wrt-installer : %s %s has failed - during installation or"
698 " uninstallation osp service\n", tizenId.c_str(),
702 case WRT_INSTALLER_ERROR_UNKNOWN:
703 fprintf(stderr,"## wrt-installer : %s %s has failed - unknown error\n",
704 tizenId.c_str(), printMsg.c_str());
712 "## wrt-installer : %s %s was successful.\n",
715 LogDebug("Status succesfull");
716 This->m_returnStatus = 0;
717 resultMsg += L" : " + DPL::FromUTF8String(PKGMGR_END_SUCCESS);
719 if (This->popupsEnabled()) {
720 This->m_popup->showPopup(This, resultMsg, showResultCallback);
722 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
724 ::PostEvent(WRTInstallerNS::NextStepEvent());
729 void WrtInstaller::staticWrtPluginInstallationCallback(WrtErrStatus status,
734 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
736 WrtInstaller *This = static_cast<WrtInstaller*>(data->wrtInstaller);
738 std::string path = std::string(data->pluginPath);
741 This->m_numPluginsToInstall--;
742 LogDebug("Plugins to install: " << This->m_numPluginsToInstall);
744 if (This->m_numPluginsToInstall < 1) {
745 LogDebug("All plugins installation completed");
746 fprintf(stderr, "All plugins installation completed.\n");
748 //remove installation request
749 if (!PluginUtils::removeInstallationRequiredFlag()) {
750 LogInfo("Failed to remove file initializing plugin installation");
754 if (!PluginUtils::unlockPluginInstallation()) {
755 LogInfo("Failed to remove installation lock");
758 if (This->popupsEnabled()) {
759 This->m_popup->init();
760 elm_progressbar_value_set(This->m_popup->m_progressbar, 100.0);
761 evas_object_show(This->m_popup->m_popup);
764 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
765 ::PostEvent(WRTInstallerNS::NextStepEvent());
767 if (This->popupsEnabled()) {
768 This->m_popup->init();
770 (This->m_totalPlugins -
771 This->m_numPluginsToInstall) / (float)This->m_totalPlugins;
772 elm_progressbar_value_set(This->m_popup->m_progressbar, percent);
773 evas_object_show(This->m_popup->m_popup);
776 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::
777 InstallPluginEvent>::
779 WRTInstallerNS::InstallPluginEvent());
782 if (WRT_SUCCESS == status) {
783 This->m_returnStatus = 0;
785 "## wrt-installer : plugin installation successfull [%s]\n",
787 LogDebug("One plugin Installation succesfull: " << path);
792 LogWarning("One of the plugins installation failed!: " << path);
794 if (WRT_PLUGIN_INSTALLER_ERROR_WAITING == status) {
795 LogInfo("Plugin installation is waiting for dependencies");
796 fprintf(stderr, "## wrt-installer : plugin installation failed [%s]\n",
801 case WRT_PLUGIN_INSTALLER_ERROR_WRONG_PATH:
802 LogError("failed: wrong path to plugin directory\n");
805 case WRT_PLUGIN_INSTALLER_ERROR_METAFILE:
806 LogError("failed: plugin metafile error\n");
809 case WRT_PLUGIN_INSTALLER_ERROR_ALREADY_INSTALLED:
810 LogError("failed: plugin already installed\n");
813 case WRT_PLUGIN_INSTALLER_ERROR_LIBRARY_ERROR:
814 LogError("failed: plugin library: missing symbols or structures\n");
817 case WRT_PLUGIN_INSTALLER_ERROR_UNKNOWN:
818 LogError("failed: unknown error\n");
826 void WrtInstaller::staticWrtPluginInstallProgressCb(float percent,
827 const char* description,
830 PluginInstallerData* data = static_cast<PluginInstallerData*>(userdata);
832 std::string path = std::string(data->pluginPath);
834 LogInfo("Plugin Installation: " << path <<
835 " progress: " << percent <<
836 "description " << description);
839 void WrtInstaller::staticWrtInstallProgressCallback(float percent,
840 const char* description,
843 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
844 LogInfo(" progress: " << percent <<
845 " description: " << description);
847 if (This->popupsEnabled()) {
848 This->m_popup->init();
849 elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
850 evas_object_show(This->m_popup->m_popup);
853 void WrtInstaller::staticWrtUninstallProgressCallback(float percent,
854 const char* description,
857 WrtInstaller *This = static_cast<WrtInstaller*>(userdata);
858 LogInfo(" progress: " << percent <<
859 " description: " << description);
861 if (This->popupsEnabled()) {
862 This->m_popup->init();
863 elm_progressbar_value_set(This->m_popup->m_progressbar, percent / 100.0);
864 evas_object_show(This->m_popup->m_popup);
868 WrtInstaller::InstallerPopup::InstallerPopup() :
874 WrtInstaller::InstallerPopup::~InstallerPopup()
876 LogDebug("App Finished");
879 void WrtInstaller::InstallerPopup::init()
881 LogDebug("Window Init");
885 m_win = createWin("wrt-installer");
888 m_popup = elm_popup_add(m_win);
890 // create progressbar
891 m_progressbar = elm_progressbar_add(m_popup);
892 elm_object_style_set(m_progressbar, "list_progress");
893 elm_progressbar_horizontal_set(m_progressbar, EINA_TRUE);
894 evas_object_size_hint_align_set(m_progressbar, EVAS_HINT_FILL,
896 evas_object_size_hint_weight_set(m_progressbar, EVAS_HINT_EXPAND,
898 elm_object_content_set(m_popup, m_progressbar);
899 elm_progressbar_value_set(m_progressbar, 0.0);
900 evas_object_show(m_progressbar);
902 evas_object_show(m_popup);
903 evas_object_show(m_win);
907 Evas_Object* WrtInstaller::InstallerPopup::createWin(const char *name)
910 win = elm_win_add(NULL, name, ELM_WIN_DIALOG_BASIC);
917 elm_win_alpha_set(win, EINA_TRUE);
918 elm_win_title_set(win, name);
919 elm_win_borderless_set(win, EINA_TRUE);
922 ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
923 evas_object_resize(win, w, h);
927 void WrtInstaller::InstallerPopup::showPopup(void* userdata,
928 const DPL::String& pkgMsg,
929 ShowResultCallback callback)
933 LogDebug("Result Popup Created");
934 evas_object_del(m_popup);
937 m_popup = elm_popup_add(m_win);
942 btn = elm_button_add(m_popup);
944 evas_object_del(m_popup);
947 elm_object_text_set(btn, "OK");
948 evas_object_smart_callback_add(btn, "clicked", callback, userdata);
949 elm_object_part_content_set(m_popup, "button1", btn);
950 elm_object_part_text_set(m_popup, "title,text", "RESULT");
951 elm_object_text_set(m_popup, DPL::ToUTF8String(pkgMsg).c_str());
953 evas_object_show(m_popup);
954 evas_object_show(m_win);
957 void WrtInstaller::showResultCallback(void *data, Evas_Object* /*obj*/,
958 void* /*event_info*/)
960 WrtInstaller *This = static_cast<WrtInstaller*>(data);
963 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::NextStepEvent>
964 ::PostEvent(WRTInstallerNS::NextStepEvent());
967 void WrtInstaller::failResultCallback(void *data, Evas_Object* /*obj*/,
968 void* /*event_info*/)
970 WrtInstaller *This = static_cast<WrtInstaller*>(data);
973 This->DPL::Event::ControllerEventHandler<WRTInstallerNS::QuitEvent>
974 ::PostEvent(WRTInstallerNS::QuitEvent());
977 void WrtInstaller::installNewPlugins()
979 LogDebug("Install new plugins");
981 if (!PluginUtils::lockPluginInstallation()) {
982 LogInfo("Lock NOT created");
986 if (!PluginUtils::checkPluginInstallationRequired()) {
987 LogDebug("Plugin installation not required");
988 PluginUtils::unlockPluginInstallation();
992 m_startupPluginInstallation = true;
993 AddStep(&WrtInstaller::installPluginsStep);
996 bool WrtInstaller::popupsEnabled() const
998 return !m_quiet && !GlobalSettings::PopupsTestModeEnabled();
1001 int main(int argc, char *argv[])
1003 UNHANDLED_EXCEPTION_HANDLER_BEGIN
1005 // Output on stdout will be flushed after every newline character,
1006 // even if it is redirected to a pipe. This is useful for running
1007 // from a script and parsing output.
1008 // (Standard behavior of stdlib is to use full buffering when
1009 // redirected to a pipe, which means even after an end of line
1010 // the output may not be flushed).
1013 // Check and re-set the file open limitation
1015 if (getrlimit(RLIMIT_NOFILE, &rlim) != -1) {
1016 LogDebug("RLIMIT_NOFILE sft(" << rlim.rlim_cur << ")");
1017 LogDebug("RLIMIT_NOFILE hrd(" << rlim.rlim_max << ")");
1019 if (rlim.rlim_cur < NOFILE_CNT_FOR_INSTALLER) {
1020 rlim.rlim_cur = NOFILE_CNT_FOR_INSTALLER;
1021 rlim.rlim_max = NOFILE_CNT_FOR_INSTALLER;
1022 if (setrlimit(RLIMIT_NOFILE, &rlim) == -1) {
1023 LogError("setrlimit is fail!!");
1027 LogError("getrlimit is fail!!");
1030 // set evas backend type for emulator
1031 // popup isn't showed in the emulator,
1032 // if backend isn't set to SW backend
1033 if (GlobalSettings::IsEmulator()) {
1034 if (setenv("ELM_ENGINE", "x11", 1)) {
1035 LogDebug("Enable backend");
1039 WrtInstaller app(argc, argv);
1040 int ret = app.Exec();
1041 LogDebug("App returned: " << ret);
1042 ret = app.getReturnStatus();
1043 LogDebug("WrtInstaller returned: " << ret);
1046 UNHANDLED_EXCEPTION_HANDLER_END