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");
72 static std::string cutOffFileName(const std::string& path)
74 size_t found = path.find_last_of("/");
75 if (found == std::string::npos) {
78 return path.substr(0, found);
82 static bool checkPath(const std::string& path)
85 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
88 LogError("Cannot access directory [ " << path << " ]");
92 static bool checkPaths()
96 if_ok &= (checkPath(cutOffFileName(GlobalConfig::GetWrtDatabaseFilePath())));
97 if_ok &= (checkPath(GlobalConfig::GetDevicePluginPath()));
98 if_ok &= (checkPath(GlobalConfig::GetUserInstalledWidgetPath()));
99 if_ok &= (checkPath(GlobalConfig::GetUserPreloadedWidgetPath()));
104 EXPORT_API void wrt_installer_init(void *userdata,
105 WrtInstallerInitCallback callback)
108 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
111 LogInfo("[WRT-API] INITIALIZING WRT INSTALLER...");
112 LogInfo("[WRT-API] BUILD: " << __TIMESTAMP__);
114 // Touch InstallerController Singleton
115 InstallerMainThreadSingleton::Instance().TouchArchitecture();
120 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
125 // Initialize ValidationCore - this must be done before AttachDatabases
126 ValidationCore::VCoreInit(
127 std::string(GlobalConfig::GetFingerprintListFile()),
128 std::string(GlobalConfig::GetFingerprintListSchema()),
129 std::string(GlobalConfig::GetVCoreDatabaseFilePath()));
131 InstallerMainThreadSingleton::Instance().AttachDatabases();
133 LogInfo("Prepare libxml2 to work in multithreaded program.");
136 // Initialize Language Subtag registry
137 LanguageSubtagRstTreeSingleton::Instance().Initialize();
140 CONTROLLER_POST_SYNC_EVENT(
141 Logic::InstallerController,
142 InstallerControllerEvents::
145 // Install deferred widget packages
146 CONTROLLER_POST_EVENT(
147 Logic::InstallerController,
148 InstallerControllerEvents::
149 InstallDeferredWidgetPackagesEvent());
152 LogInfo("[WRT-API] WRT INSTALLER INITIALIZATION CALLBACK");
153 callback(WRT_SUCCESS, userdata);
155 } catch (const DPL::Exception& ex) {
156 LogError("Internal Error during Init:");
157 DPL::Exception::DisplayKnownException(ex);
159 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
166 EXPORT_API void wrt_installer_shutdown()
169 LogInfo("[WRT-API] DEINITIALIZING WRT INSTALLER...");
171 // Installer termination
172 CONTROLLER_POST_SYNC_EVENT(
173 Logic::InstallerController,
174 InstallerControllerEvents::
177 InstallerMainThreadSingleton::Instance().DetachDatabases();
179 // This must be done after DetachDatabase
180 ValidationCore::VCoreDeinit();
182 // Global deinit check
183 LogInfo("Cleanup libxml2 global values.");
185 } catch (const DPL::Exception& ex) {
186 LogError("Internal Error during Shutdown:");
187 DPL::Exception::DisplayKnownException(ex);
191 EXPORT_API void wrt_install_widget(
194 WrtInstallerStatusCallback status_cb,
195 WrtProgressCallback progress_cb,
196 WrtInstallMode installMode,
198 std::shared_ptr<PackageManager::
199 IPkgmgrSignal> pkgmgrInterface
202 UNHANDLED_EXCEPTION_HANDLER_BEGIN
204 LogInfo("[WRT-API] INSTALL WIDGET: " << path);
205 // Post installation event
206 CONTROLLER_POST_EVENT(
207 Logic::InstallerController,
208 InstallerControllerEvents::InstallWidgetEvent(
209 path, WidgetInstallationStruct(
210 InstallerCallbacksTranslate::installFinishedCallback,
211 InstallerCallbacksTranslate::installProgressCallback,
212 new InstallerCallbacksTranslate::StatusCallbackStruct(
213 userdata, status_cb, progress_cb),
214 translateInstallMode(installMode),
218 UNHANDLED_EXCEPTION_HANDLER_END
221 EXPORT_API void wrt_uninstall_widget(
222 const char * const tzAppid,
224 WrtInstallerStatusCallback status_cb,
225 WrtProgressCallback progress_cb,
226 std::shared_ptr<PackageManager::
227 IPkgmgrSignal> pkgmgrSignalInterface)
229 UNHANDLED_EXCEPTION_HANDLER_BEGIN
231 std::string tizenAppid(tzAppid);
232 LogInfo("[WRT-API] UNINSTALL WIDGET: " << tizenAppid);
233 // Post uninstallation event
234 CONTROLLER_POST_EVENT(
235 Logic::InstallerController,
236 InstallerControllerEvents::UninstallWidgetEvent(
238 WidgetUninstallationStruct(
239 InstallerCallbacksTranslate::uninstallFinishedCallback,
240 InstallerCallbacksTranslate::installProgressCallback,
241 new InstallerCallbacksTranslate::StatusCallbackStruct(
242 userdata, status_cb, progress_cb),
243 pkgmgrSignalInterface
248 UNHANDLED_EXCEPTION_HANDLER_END
251 EXPORT_API void wrt_install_plugin(
252 const char *pluginDir,
254 WrtPluginInstallerStatusCallback status_cb,
255 WrtProgressCallback progress_cb)
257 UNHANDLED_EXCEPTION_HANDLER_BEGIN
259 LogInfo("[WRT-API] INSTALL PLUGIN: " << pluginDir);
260 //Private data for status callback
261 //Resource is free in pluginInstallFinishedCallback
262 InstallerCallbacksTranslate::PluginStatusCallbackStruct*
264 new InstallerCallbacksTranslate::PluginStatusCallbackStruct(
265 user_param, status_cb, progress_cb);
267 CONTROLLER_POST_EVENT(
268 Logic::InstallerController,
269 InstallerControllerEvents::InstallPluginEvent(
270 std::string(pluginDir),
271 PluginInstallerStruct(
272 InstallerCallbacksTranslate::
273 pluginInstallFinishedCallback,
274 InstallerCallbacksTranslate::
275 installProgressCallback, callbackStruct)));
277 UNHANDLED_EXCEPTION_HANDLER_END