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/assert.h>
30 #include <dpl/semaphore.h>
31 #include <dpl/sstream.h>
32 #include <dpl/errno_string.h>
33 #include <libxml/parser.h>
35 #include <wrt_installer_api.h>
36 #include <installer_callbacks_translate.h>
37 #include <installer_controller.h>
38 #include <language_subtag_rst_tree.h>
39 #include <dpl/wrt-dao-ro/global_config.h>
40 #include <dpl/utils/widget_version.h>
42 #include <dpl/localization/w3c_file_localization.h>
43 #include <dpl/wrt-dao-ro/WrtDatabase.h>
44 #include <vcore/VCore.h>
45 #include <installer_main_thread.h>
46 #include <wrt_install_mode.h>
47 #include <installer_log.h>
49 using namespace WrtDB;
51 static std::string cutOffFileName(const std::string& path)
53 size_t found = path.find_last_of("/");
54 if (found == std::string::npos) {
57 return path.substr(0, found);
61 static bool checkPath(const std::string& path)
64 if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
67 _E("Cannot access directory [ %s ]", path.c_str());
71 static bool checkPaths()
75 if_ok &= (checkPath(cutOffFileName(GlobalConfig::GetWrtDatabaseFilePath())));
76 if_ok &= (checkPath(GlobalConfig::GetDevicePluginPath()));
77 if_ok &= (checkPath(GlobalConfig::GetUserInstalledWidgetPath()));
78 if_ok &= (checkPath(GlobalConfig::GetUserPreloadedWidgetPath()));
83 void wrt_installer_init(void *userdata,
84 WrtInstallerInitCallback callback)
87 _D("[WRT-API] INITIALIZING WRT INSTALLER...");
88 _D("[WRT-API] BUILD: %s", __TIMESTAMP__);
90 // Touch InstallerController Singleton
91 InstallerMainThreadSingleton::Instance().TouchArchitecture();
96 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
101 // Initialize ValidationCore - this must be done before AttachDatabases
102 ValidationCore::VCoreInit(
103 std::string(GlobalConfig::GetFingerprintListFile()),
104 std::string(GlobalConfig::GetFingerprintListSchema()),
105 std::string(GlobalConfig::GetVCoreDatabaseFilePath()));
107 InstallerMainThreadSingleton::Instance().AttachDatabases();
109 _D("Prepare libxml2 to work in multithreaded program.");
112 // Initialize Language Subtag registry
113 LanguageSubtagRstTreeSingleton::Instance().Initialize();
116 CONTROLLER_POST_SYNC_EVENT(
117 Logic::InstallerController,
118 InstallerControllerEvents::
122 _D("[WRT-API] WRT INSTALLER INITIALIZATION CALLBACK");
123 callback(WRT_SUCCESS, userdata);
125 } catch (const DPL::Exception& ex) {
126 _E("Internal Error during Init:");
127 DPL::Exception::DisplayKnownException(ex);
129 callback(WRT_INSTALLER_ERROR_FATAL_ERROR, userdata);
136 void wrt_installer_shutdown()
139 _D("[WRT-API] DEINITIALIZING WRT INSTALLER...");
141 // Installer termination
142 CONTROLLER_POST_SYNC_EVENT(
143 Logic::InstallerController,
144 InstallerControllerEvents::
147 InstallerMainThreadSingleton::Instance().DetachDatabases();
149 // This must be done after DetachDatabase
150 ValidationCore::VCoreDeinit();
152 // Global deinit check
153 _D("Cleanup libxml2 global values.");
155 } catch (const DPL::Exception& ex) {
156 _E("Internal Error during Shutdown:");
157 DPL::Exception::DisplayKnownException(ex);
161 void wrt_install_widget(
165 WrtInstallerStatusCallback status_cb,
166 WrtProgressCallback progress_cb,
167 InstallMode installMode,
168 std::shared_ptr<PackageManager::
169 IPkgmgrSignal> pkgmgrInterface
172 UNHANDLED_EXCEPTION_HANDLER_BEGIN
174 if (InstallMode::InstallTime::PRELOAD == installMode.installTime) {
175 DPL::Log::OldStyleLogProvider *oldStyleProvider =
176 new DPL::Log::OldStyleLogProvider(false, false, false, true,
178 DPL::Log::LogSystemSingleton::Instance().AddProvider(oldStyleProvider);
181 _D("[WRT-API] INSTALL WIDGET: %s", path);
182 // Post installation event
183 CONTROLLER_POST_EVENT(
184 Logic::InstallerController,
185 InstallerControllerEvents::InstallWidgetEvent(
186 path, tzPkgId, Jobs::WidgetInstall::WidgetInstallationStruct(
187 InstallerCallbacksTranslate::installFinishedCallback,
188 InstallerCallbacksTranslate::installProgressCallback,
189 new InstallerCallbacksTranslate::StatusCallbackStruct(
190 userdata, status_cb, progress_cb),
194 UNHANDLED_EXCEPTION_HANDLER_END
197 void wrt_uninstall_widget(
198 const char * const tzAppid,
200 WrtInstallerStatusCallback status_cb,
201 WrtProgressCallback progress_cb,
202 std::shared_ptr<PackageManager::
203 IPkgmgrSignal> pkgmgrSignalInterface)
205 UNHANDLED_EXCEPTION_HANDLER_BEGIN
207 std::string tizenAppid(tzAppid);
208 _D("[WRT-API] UNINSTALL WIDGET: %s", tizenAppid.c_str());
209 // Post uninstallation event
210 CONTROLLER_POST_EVENT(
211 Logic::InstallerController,
212 InstallerControllerEvents::UninstallWidgetEvent(
214 WidgetUninstallationStruct(
215 InstallerCallbacksTranslate::uninstallFinishedCallback,
216 InstallerCallbacksTranslate::installProgressCallback,
217 new InstallerCallbacksTranslate::StatusCallbackStruct(
218 userdata, status_cb, progress_cb),
219 pkgmgrSignalInterface
224 UNHANDLED_EXCEPTION_HANDLER_END
227 void wrt_install_plugin(
228 const char *pluginDir,
230 WrtPluginInstallerStatusCallback status_cb,
231 WrtProgressCallback progress_cb)
233 UNHANDLED_EXCEPTION_HANDLER_BEGIN
235 _D("[WRT-API] INSTALL PLUGIN: %s", pluginDir);
236 //Private data for status callback
237 //Resource is free in pluginInstallFinishedCallback
238 InstallerCallbacksTranslate::PluginStatusCallbackStruct*
240 new InstallerCallbacksTranslate::PluginStatusCallbackStruct(
241 user_param, status_cb, progress_cb);
243 CONTROLLER_POST_EVENT(
244 Logic::InstallerController,
245 InstallerControllerEvents::InstallPluginEvent(
246 std::string(pluginDir),
247 PluginInstallerStruct(
248 InstallerCallbacksTranslate::
249 pluginInstallFinishedCallback,
250 InstallerCallbacksTranslate::
251 installProgressCallback, callbackStruct)));
253 UNHANDLED_EXCEPTION_HANDLER_END