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.
17 * @file wrt_installer_api.cpp
18 * @author Chung Jihoon (jihoon.chung@samsung.com)
20 * @brief This file contains definitions of wrt installer api
25 #include <sys/types.h>
28 #include <dpl/exception.h>
29 #include <dpl/log/log.h>
30 #include <dpl/assert.h>
31 #include <dpl/semaphore.h>
32 #include <dpl/sstream.h>
33 #include <dpl/errno_string.h>
34 #include <libxml/parser.h>
37 #include <wrt_installer_api.h>
38 #include <installer_callbacks_translate.h>
39 #include <installer_controller.h>
40 #include <language_subtag_rst_tree.h>
41 #include <dpl/wrt-dao-ro/global_config.h>
42 #include <dpl/utils/widget_version.h>
44 #include <dpl/localization/w3c_file_localization.h>
45 #include <dpl/wrt-dao-ro/WrtDatabase.h>
46 #include <vcore/VCore.h>
47 #include <installer_main_thread.h>
49 using namespace WrtDB;
53 #define EXPORT_API __attribute__((visibility("default")))
57 inline InstallMode::Type translateInstallMode(
58 WrtInstallMode installMode)
60 if (WRT_INSTALL_MODE_INSTALL_WGT == installMode) {
61 return InstallMode::INSTALL_MODE_WGT;
62 } else if (WRT_INSTALL_MODE_INSTALL_DIRECTORY == installMode) {
63 return InstallMode::INSTALL_MODE_DIRECTORY;
64 } else if (WRT_INSTALL_MODE_INSTALL_PRELOAD == installMode) {
65 return InstallMode::INSTALL_MODE_PRELOAD;
66 } else if (WRT_INSTALL_MODE_REINSTALL == installMode) {
67 return InstallMode::REINSTALL_MODE_DIRECTORY;
69 Assert(true && "wrong argument is inputed");
70 return InstallMode::WRONG_INSTALL_MODE;
73 static std::string cutOffFileName(const std::string& path)
75 size_t found = path.find_last_of("/");
76 if (found == std::string::npos) {
79 return path.substr(0, found);
83 static bool checkPath(const std::string& path)
86 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
89 LogError("Cannot access directory [ " << path << " ]");
93 static bool checkPaths()
97 if_ok &= (checkPath(cutOffFileName(GlobalConfig::GetWrtDatabaseFilePath())));
98 if_ok &= (checkPath(GlobalConfig::GetDevicePluginPath()));
99 if_ok &= (checkPath(GlobalConfig::GetUserInstalledWidgetPath()));
100 if_ok &= (checkPath(GlobalConfig::GetUserPreloadedWidgetPath()));
105 EXPORT_API void wrt_installer_init(void *userdata,
106 WrtInstallerInitCallback callback)
109 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
112 LogInfo("[WRT-API] INITIALIZING WRT INSTALLER...");
113 LogInfo("[WRT-API] BUILD: " << __TIMESTAMP__);
115 // Touch InstallerController Singleton
116 InstallerMainThreadSingleton::Instance().TouchArchitecture();
121 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
126 // Initialize ValidationCore - this must be done before AttachDatabases
127 ValidationCore::VCoreInit(
128 std::string(GlobalConfig::GetFingerprintListFile()),
129 std::string(GlobalConfig::GetFingerprintListSchema()),
130 std::string(GlobalConfig::GetVCoreDatabaseFilePath()));
132 InstallerMainThreadSingleton::Instance().AttachDatabases();
134 LogInfo("Prepare libxml2 to work in multithreaded program.");
137 // Initialize Language Subtag registry
138 LanguageSubtagRstTreeSingleton::Instance().Initialize();
141 CONTROLLER_POST_SYNC_EVENT(
142 Logic::InstallerController,
143 InstallerControllerEvents::
146 // Install deferred widget packages
147 CONTROLLER_POST_EVENT(
148 Logic::InstallerController,
149 InstallerControllerEvents::
150 InstallDeferredWidgetPackagesEvent());
153 LogInfo("[WRT-API] WRT INSTALLER INITIALIZATION CALLBACK");
154 callback(WRT_SUCCESS, userdata);
156 } catch (const DPL::Exception& ex) {
157 LogError("Internal Error during Init:");
158 DPL::Exception::DisplayKnownException(ex);
160 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
167 EXPORT_API void wrt_installer_shutdown()
170 LogInfo("[WRT-API] DEINITIALIZING WRT INSTALLER...");
172 // Installer termination
173 CONTROLLER_POST_SYNC_EVENT(
174 Logic::InstallerController,
175 InstallerControllerEvents::
178 InstallerMainThreadSingleton::Instance().DetachDatabases();
180 // This must be done after DetachDatabase
181 ValidationCore::VCoreDeinit();
183 // Global deinit check
184 LogInfo("Cleanup libxml2 global values.");
186 } catch (const DPL::Exception& ex) {
187 LogError("Internal Error during Shutdown:");
188 DPL::Exception::DisplayKnownException(ex);
192 EXPORT_API void wrt_install_widget(
195 WrtInstallerStatusCallback status_cb,
196 WrtProgressCallback progress_cb,
197 WrtInstallMode installMode,
199 std::shared_ptr<PackageManager::
200 IPkgmgrSignal> pkgmgrInterface
203 UNHANDLED_EXCEPTION_HANDLER_BEGIN
205 LogInfo("[WRT-API] INSTALL WIDGET: " << path);
206 // Post installation event
207 CONTROLLER_POST_EVENT(
208 Logic::InstallerController,
209 InstallerControllerEvents::InstallWidgetEvent(
210 path, WidgetInstallationStruct(
211 InstallerCallbacksTranslate::installFinishedCallback,
212 InstallerCallbacksTranslate::installProgressCallback,
213 new InstallerCallbacksTranslate::StatusCallbackStruct(
214 userdata, status_cb, progress_cb),
215 translateInstallMode(installMode),
219 UNHANDLED_EXCEPTION_HANDLER_END
222 EXPORT_API void wrt_uninstall_widget(
223 const char * const tzAppid,
225 WrtInstallerStatusCallback status_cb,
226 WrtProgressCallback progress_cb,
227 std::shared_ptr<PackageManager::
228 IPkgmgrSignal> pkgmgrSignalInterface)
230 UNHANDLED_EXCEPTION_HANDLER_BEGIN
232 std::string tizenAppid(tzAppid);
233 LogInfo("[WRT-API] UNINSTALL WIDGET: " << tizenAppid);
234 // Post uninstallation event
235 CONTROLLER_POST_EVENT(
236 Logic::InstallerController,
237 InstallerControllerEvents::UninstallWidgetEvent(
239 WidgetUninstallationStruct(
240 InstallerCallbacksTranslate::uninstallFinishedCallback,
241 InstallerCallbacksTranslate::installProgressCallback,
242 new InstallerCallbacksTranslate::StatusCallbackStruct(
243 userdata, status_cb, progress_cb),
244 pkgmgrSignalInterface
249 UNHANDLED_EXCEPTION_HANDLER_END
252 EXPORT_API void wrt_install_plugin(
253 const char *pluginDir,
255 WrtPluginInstallerStatusCallback status_cb,
256 WrtProgressCallback progress_cb)
258 UNHANDLED_EXCEPTION_HANDLER_BEGIN
260 LogInfo("[WRT-API] INSTALL PLUGIN: " << pluginDir);
261 //Private data for status callback
262 //Resource is free in pluginInstallFinishedCallback
263 InstallerCallbacksTranslate::PluginStatusCallbackStruct*
265 new InstallerCallbacksTranslate::PluginStatusCallbackStruct(
266 user_param, status_cb, progress_cb);
268 CONTROLLER_POST_EVENT(
269 Logic::InstallerController,
270 InstallerControllerEvents::InstallPluginEvent(
271 std::string(pluginDir),
272 PluginInstallerStruct(
273 InstallerCallbacksTranslate::
274 pluginInstallFinishedCallback,
275 InstallerCallbacksTranslate::
276 installProgressCallback, callbackStruct)));
278 UNHANDLED_EXCEPTION_HANDLER_END