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;
67 Assert(true && "wrong argument is inputed");
70 static std::string cutOffFileName(const std::string& path)
72 size_t found = path.find_last_of("/");
73 if (found == std::string::npos) {
76 return path.substr(0, found);
80 static bool checkPath(const std::string& path)
83 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
86 LogError("Cannot access directory [ " << path << " ]");
90 static bool checkPaths()
94 if_ok &= (checkPath(cutOffFileName(GlobalConfig::GetWrtDatabaseFilePath())));
95 if_ok &= (checkPath(GlobalConfig::GetDevicePluginPath()));
96 if_ok &= (checkPath(GlobalConfig::GetUserInstalledWidgetPath()));
97 if_ok &= (checkPath(GlobalConfig::GetUserPreloadedWidgetPath()));
102 EXPORT_API void wrt_installer_init(void *userdata,
103 WrtInstallerInitCallback callback)
106 DPL::Log::LogSystemSingleton::Instance().SetTag("WRT");
109 LogInfo("[WRT-API] INITIALIZING WRT INSTALLER...");
110 LogInfo("[WRT-API] BUILD: " << __TIMESTAMP__);
112 // Touch InstallerController Singleton
113 InstallerMainThreadSingleton::Instance().TouchArchitecture();
118 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
123 // Initialize ValidationCore - this must be done before AttachDatabases
124 ValidationCore::VCoreInit(
125 std::string(GlobalConfig::GetFingerprintListFile()),
126 std::string(GlobalConfig::GetFingerprintListSchema()),
127 std::string(GlobalConfig::GetVCoreDatabaseFilePath()));
129 InstallerMainThreadSingleton::Instance().AttachDatabases();
131 LogInfo("Prepare libxml2 to work in multithreaded program.");
134 // Initialize Language Subtag registry
135 LanguageSubtagRstTreeSingleton::Instance().Initialize();
138 CONTROLLER_POST_SYNC_EVENT(
139 Logic::InstallerController,
140 InstallerControllerEvents::
143 // Install deferred widget packages
144 CONTROLLER_POST_EVENT(
145 Logic::InstallerController,
146 InstallerControllerEvents::
147 InstallDeferredWidgetPackagesEvent());
150 LogInfo("[WRT-API] WRT INSTALLER INITIALIZATION CALLBACK");
151 callback(WRT_SUCCESS, userdata);
153 } catch (const DPL::Exception& ex) {
154 LogError("Internal Error during Init:");
155 DPL::Exception::DisplayKnownException(ex);
157 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
164 EXPORT_API void wrt_installer_shutdown()
167 LogInfo("[WRT-API] DEINITIALIZING WRT INSTALLER...");
169 // Installer termination
170 CONTROLLER_POST_SYNC_EVENT(
171 Logic::InstallerController,
172 InstallerControllerEvents::
175 InstallerMainThreadSingleton::Instance().DetachDatabases();
177 // This must be done after DetachDatabase
178 ValidationCore::VCoreDeinit();
180 // Global deinit check
181 LogInfo("Cleanup libxml2 global values.");
183 } catch (const DPL::Exception& ex) {
184 LogError("Internal Error during Shutdown:");
185 DPL::Exception::DisplayKnownException(ex);
189 EXPORT_API void wrt_install_widget(
192 WrtInstallerStatusCallback status_cb,
193 WrtProgressCallback progress_cb,
194 WrtInstallMode installMode,
196 std::shared_ptr<PackageManager::
197 IPkgmgrSignal> pkgmgrInterface
200 UNHANDLED_EXCEPTION_HANDLER_BEGIN
202 LogInfo("[WRT-API] INSTALL WIDGET: " << path);
203 // Post installation event
204 CONTROLLER_POST_EVENT(
205 Logic::InstallerController,
206 InstallerControllerEvents::InstallWidgetEvent(
207 path, WidgetInstallationStruct(
208 InstallerCallbacksTranslate::installFinishedCallback,
209 InstallerCallbacksTranslate::installProgressCallback,
210 new InstallerCallbacksTranslate::StatusCallbackStruct(
211 userdata, status_cb, progress_cb),
212 translateInstallMode(installMode),
216 UNHANDLED_EXCEPTION_HANDLER_END
219 EXPORT_API void wrt_uninstall_widget(
220 const char * const tzAppid,
222 WrtInstallerStatusCallback status_cb,
223 WrtProgressCallback progress_cb,
224 std::shared_ptr<PackageManager::
225 IPkgmgrSignal> pkgmgrSignalInterface)
227 UNHANDLED_EXCEPTION_HANDLER_BEGIN
229 std::string tizenAppid(tzAppid);
230 LogInfo("[WRT-API] UNINSTALL WIDGET: " << tizenAppid);
231 // Post uninstallation event
232 CONTROLLER_POST_EVENT(
233 Logic::InstallerController,
234 InstallerControllerEvents::UninstallWidgetEvent(
236 WidgetUninstallationStruct(
237 InstallerCallbacksTranslate::uninstallFinishedCallback,
238 InstallerCallbacksTranslate::installProgressCallback,
239 new InstallerCallbacksTranslate::StatusCallbackStruct(
240 userdata, status_cb, progress_cb),
241 pkgmgrSignalInterface
246 UNHANDLED_EXCEPTION_HANDLER_END
249 EXPORT_API void wrt_install_plugin(
250 const char *pluginDir,
252 WrtPluginInstallerStatusCallback status_cb,
253 WrtProgressCallback progress_cb)
255 UNHANDLED_EXCEPTION_HANDLER_BEGIN
257 LogInfo("[WRT-API] INSTALL PLUGIN: " << pluginDir);
258 //Private data for status callback
259 //Resource is free in pluginInstallFinishedCallback
260 InstallerCallbacksTranslate::PluginStatusCallbackStruct*
262 new InstallerCallbacksTranslate::PluginStatusCallbackStruct(
263 user_param, status_cb, progress_cb);
265 CONTROLLER_POST_EVENT(
266 Logic::InstallerController,
267 InstallerControllerEvents::InstallPluginEvent(
268 std::string(pluginDir),
269 PluginInstallerStruct(
270 InstallerCallbacksTranslate::
271 pluginInstallFinishedCallback,
272 InstallerCallbacksTranslate::
273 installProgressCallback, callbackStruct)));
275 UNHANDLED_EXCEPTION_HANDLER_END