summaryrefslogtreecommitdiff
path: root/src/plugins-installer
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins-installer')
-rw-r--r--src/plugins-installer/CMakeLists.txt73
-rw-r--r--src/plugins-installer/DESCRIPTION2
-rw-r--r--src/plugins-installer/plugin_installer.cpp752
-rw-r--r--src/plugins-installer/plugin_installer.h102
-rw-r--r--src/plugins-installer/plugin_installer_errors.h38
-rw-r--r--src/plugins-installer/plugin_installer_types.h37
-rw-r--r--src/plugins-installer/plugin_metafile_reader.cpp82
-rw-r--r--src/plugins-installer/plugin_metafile_reader.h61
-rw-r--r--src/plugins-installer/plugin_objects.cpp125
-rw-r--r--src/plugins-installer/plugin_objects.h58
-rw-r--r--src/plugins-installer/plugin_utils.cpp83
-rw-r--r--src/plugins-installer/plugin_utils.h35
-rw-r--r--src/plugins-installer/wrt_plugins_installer.cpp51
13 files changed, 1499 insertions, 0 deletions
diff --git a/src/plugins-installer/CMakeLists.txt b/src/plugins-installer/CMakeLists.txt
new file mode 100644
index 0000000..b0bf8f0
--- /dev/null
+++ b/src/plugins-installer/CMakeLists.txt
@@ -0,0 +1,73 @@
+# Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+# @file CMakeLists.txt
+# @author Andrzej Surdej (a.surdej@samsung.com)
+# @version 1.0
+#
+
+SET(TARGET_PLUGINS_INSTALLER "wrt-plugins-installer")
+
+SET(WRT_PLUGINS_INSTALLER_SRC_DIR
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+PKG_CHECK_MODULES(PLUGINS_INSTALLER_DEPS
+ libxml-2.0
+ cert-svc-vcore
+ dpl-efl
+ dpl-utils-efl
+ dpl-wrt-dao-rw
+ libpcrecpp
+ REQUIRED
+)
+
+INCLUDE_DIRECTORIES(
+ ${WRT_PLUGINS_INSTALLER_SRC_DIR}
+ ${PLUGINS_INSTALLER_INCLUDES}
+ ${PLUGINS_INSTALLER_DEPS_INCLUDE_DIRS}
+ ${PLUGINS_API_SUPPORT_DIRS}
+)
+
+SET(WRT_PLUGINS_INSTALLER_SOURCES
+ ${WRT_PLUGINS_INSTALLER_SRC_DIR}/wrt_plugins_installer.cpp
+ ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_installer.cpp
+ ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_utils.cpp
+ ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_objects.cpp
+ ${WRT_PLUGINS_INSTALLER_SRC_DIR}/plugin_metafile_reader.cpp
+)
+
+ADD_DEFINITIONS(${PLUGINS_INSTALLER_DEPS_CFLAGS})
+ADD_DEFINITIONS(${PLUGINS_INSTALLER_DEPS_CFLAGS_OTHERS})
+
+ADD_EXECUTABLE(${TARGET_PLUGINS_INSTALLER}
+ ${WRT_PLUGINS_INSTALLER_SOURCES}
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_INSTALLER} PROPERTIES
+ COMPILE_DEFINITIONS LOG_TAG="${LOG_TAG}")
+
+TARGET_LINK_LIBRARIES(${TARGET_PLUGINS_INSTALLER}
+ ${PLUGINS_INSTALLER_DEPS_LIBRARIES}
+ ${TARGET_PLUGINS_API_SUPPORT} "-ldl"
+)
+
+SET_TARGET_PROPERTIES(${TARGET_PLUGINS_INSTALLER} PROPERTIES
+ LINK_FLAGS "-Wl,--as-needed -Wl,--hash-style=both"
+ BUILD_WITH_INSTALL_RPATH ON
+ INSTALL_RPATH_USE_LINK_PATH ON
+)
+
+INSTALL(TARGETS ${TARGET_PLUGINS_INSTALLER} DESTINATION bin)
diff --git a/src/plugins-installer/DESCRIPTION b/src/plugins-installer/DESCRIPTION
new file mode 100644
index 0000000..0e8c571
--- /dev/null
+++ b/src/plugins-installer/DESCRIPTION
@@ -0,0 +1,2 @@
+!!!options!!! stop
+Widget (un)installer, plugin (un)installer
diff --git a/src/plugins-installer/plugin_installer.cpp b/src/plugins-installer/plugin_installer.cpp
new file mode 100644
index 0000000..e570c55
--- /dev/null
+++ b/src/plugins-installer/plugin_installer.cpp
@@ -0,0 +1,752 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_installer.cpp
+ * @author Andrzej Surdej(a.surdej@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#include "plugin_installer.h"
+
+#include <sys/stat.h>
+#include <cstdio>
+#include <dlfcn.h>
+#include <string>
+
+#include <vcore/VCore.h>
+#include <libxml/parser.h>
+
+#include "plugin_objects.h"
+#include "plugin_metafile_reader.h"
+#include "plugin_installer_errors.h"
+
+#include <Plugin.h>
+#include <IObject_cast.h>
+#include <plugin_utils.h>
+#include <ExportedApi.h>
+
+#include <wrt-commons/wrt_plugin_export.h>
+
+#include <dpl/log/wrt_log.h>
+#include <dpl/exception.h>
+#include <dpl/utils/path.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+#include <dpl/wrt-dao-rw/feature_dao.h>
+#include <dpl/foreach.h>
+#include <dpl/wrt-dao-ro/WrtDatabase.h>
+
+#include <dpl/singleton_impl.h>
+
+using namespace WrtDB;
+using namespace WrtPluginsApi;
+
+
+IMPLEMENT_SINGLETON(PluginsInstaller)
+
+namespace {
+const std::string DIRECTORY_SEPARATOR = std::string("/");
+}
+
+const int PluginsInstaller::INSTALLATION_ERROR = -1;
+
+PluginsInstaller::PluginsInstaller() :
+ m_initialized(false)
+{
+ WrtLogD("PluginsInstaller created.");
+}
+PluginsInstaller::~PluginsInstaller()
+{
+ WrtLogD("PluginsInstaller destroyed.");
+}
+
+void PluginsInstaller::checkDatabaseTablesExistance()
+{
+ if (!WrtDB::WrtDatabase::CheckTableExist("FeaturesList") ||
+ !WrtDB::WrtDatabase::CheckTableExist("PluginProperties") ||
+ !WrtDB::WrtDatabase::CheckTableExist("PluginDependencies") ||
+ !WrtDB::WrtDatabase::CheckTableExist("PluginImplementedObjects") ||
+ !WrtDB::WrtDatabase::CheckTableExist("PluginRequiredObjects") ||
+ !WrtDB::WrtDatabase::CheckTableExist("DeviceCapabilities") ||
+ !WrtDB::WrtDatabase::CheckTableExist("FeatureDeviceCapProxy"))
+ {
+ WrtLogE("Wrong database. Required tables not exist.");
+ deinitialize();
+ Assert(false && "Wrong database. Required tables not exist.");
+ }
+}
+
+bool PluginsInstaller::initialize()
+{
+ WrtLogD("Initializing required systems.");
+
+ // Check paths
+ if (!PluginUtils::checkPaths()) {
+ return false;
+ }
+ // Initialize ValidationCore - this must be done before AttachDatabases
+ ValidationCore::VCoreInit(
+ std::string(GlobalConfig::GetFingerprintListFile()),
+ std::string(GlobalConfig::GetFingerprintListSchema()),
+ std::string(GlobalConfig::GetVCoreDatabaseFilePath()));
+
+ xmlInitParser();
+ WrtDB::WrtDatabase::attachToThreadRW();
+ ValidationCore::AttachToThreadRW();
+ checkDatabaseTablesExistance();
+ WrtLogD("Initialized.");
+ m_initialized = true;
+ return true;
+}
+
+void PluginsInstaller::deinitialize()
+{
+ WrtLogD("Shuting systems down.");
+ m_initialized = false;
+ ValidationCore::DetachFromThread();
+ WrtDB::WrtDatabase::detachFromThread();
+ ValidationCore::VCoreDeinit();
+ xmlCleanupParser();
+ WrtLogD("Done");
+}
+
+PluginsInstaller::ReturnStatus PluginsInstaller::installPlugin(
+ const std::string& libPath)
+{
+ if (!m_initialized) {
+ WrtLogE("Plugins installer not initialized.");
+ return ReturnStatus::NotInitialized;
+ }
+ WrtLogD("Plugin installation started. Checking path: %s", libPath.c_str());
+
+ if (!PluginUtils::checkPath(libPath)) {
+ return ReturnStatus::WrongPluginPath;
+ }
+
+ WrtLogD("Plugin path ok. Searching for config file...");
+
+ std::string metaFileName = libPath + DIRECTORY_SEPARATOR +
+ std::string(WrtDB::GlobalConfig::GetPluginMetafileName());
+ if (PluginUtils::checkFileExistance(metaFileName)) {
+ return installPluginFromMetafile(libPath, metaFileName);
+ }
+
+ PluginMetafileData pluginInfo;
+ pluginInfo.m_libraryName = getLibraryName(libPath);
+
+ WrtLogD("Config file done. Lib name: %s. Searching for installed plugin...",
+ pluginInfo.m_libraryName.c_str());
+
+ if (WrtDB::PluginDAO::isPluginInstalled(pluginInfo.m_libraryName)) {
+ WrtLogD("Plugin already installed.");
+ return ReturnStatus::AlreadyInstalled;
+ }
+ WrtLogD("Plugin not installed. Loading library file...");
+
+ PluginObjectsPtr libraryObjects;
+ PluginHandle pluginHandle;
+
+ std::string filename = libPath + DIRECTORY_SEPARATOR +
+ pluginInfo.m_libraryName;
+
+ WrtLogD("Loading plugin: %s", filename.c_str());
+
+ Plugin* plugin;
+ Try
+ {
+ plugin = m_registry.GetPlugin(filename);
+ }
+ Catch(DPL::Exception) {
+ WrtLogE("Loading library failed %s", filename.c_str());
+ return ReturnStatus::LoadingLibraryError;
+ }
+ libraryObjects = PluginObjectsPtr(new PluginObjects());
+
+ WrtLogD("#####");
+ WrtLogD("##### Plugin: %s supports new plugin API", filename.c_str());
+ WrtLogD("#####");
+
+ FOREACH(o, *plugin->GetObjects()) {
+ libraryObjects->addObjects(CAST(*o)->GetParentName(),
+ CAST(*o)->GetName());
+
+ WrtLogD("[Parent << Object] %s << %s",
+ CAST(*o)->GetParentName(),
+ CAST(*o)->GetName());
+
+ registerObjects(libraryObjects, plugin->GetObjects());
+ }
+
+ if (!fillMappingInterfaces(pluginInfo, filename)) {
+ m_registry.RemovePlugin(filename, *plugin);
+ return ReturnStatus::LoadingLibraryError;
+ }
+
+ WrtLogD("Library loaded. Registering plugin...");
+
+ Try
+ {
+ pluginHandle =
+ PluginDAO::registerPlugin(pluginInfo, libPath);
+
+ WrtLogD("Plugin registered. Registering features...");
+
+ FOREACH(it, pluginInfo.m_featureContainer)
+ {
+ WrtLogE("PluginHandle: %d", pluginHandle);
+ FeatureDAO::RegisterFeature(*it, pluginHandle);
+ }
+
+ WrtLogD("Features registered. Registering objects...");
+
+ registerPluginObjects(pluginHandle, libraryObjects);
+
+ WrtLogD("Registration done. Resolving dependencies...");
+
+ //TODO: can it be replaced with resolvePluginDependencies(handle)
+ if (!registerAndUpdateInstallation(pluginHandle, libraryObjects)) {
+ return ReturnStatus::InstallationWaiting;
+ }
+ } Catch(DPL::Exception) {
+ WrtLogE("Failed to make database entry.");
+ return ReturnStatus::DatabaseError;
+ }
+
+ WrtLogD("Plugin installed successfully.");
+ return ReturnStatus::Success;
+}
+
+PluginObjectsPtr PluginsInstaller::loadLibraryFromMetafile(
+ const std::string& libName) const
+{
+ WrtLogD("Loading library: %s", libName.c_str());
+
+ void *dlHandle = dlopen(libName.c_str(), RTLD_NOW);
+ if (dlHandle == NULL) {
+ const char* error = (const char*)dlerror();
+ WrtLogE("Failed to load plugin: %s. Reason: %s",
+ libName.c_str(),
+ (error != NULL ? error : "unknown"));
+ ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+ }
+
+ const js_entity_definition_t *rawEntityList = NULL;
+ get_widget_entity_map_proc *getWidgetEntityMapProcPtr = NULL;
+
+ getWidgetEntityMapProcPtr =
+ reinterpret_cast<get_widget_entity_map_proc *>(dlsym(dlHandle,
+ PLUGIN_GET_CLASS_MAP_PROC_NAME));
+
+ if (getWidgetEntityMapProcPtr) {
+ rawEntityList = (*getWidgetEntityMapProcPtr)();
+ } else {
+ rawEntityList =
+ static_cast<const js_entity_definition_t *>(dlsym(dlHandle,
+ PLUGIN_CLASS_MAP_NAME));
+ }
+
+ if (rawEntityList == NULL) {
+ dlclose(dlHandle);
+ WrtLogE("Failed to read class name %s", libName.c_str());
+ ThrowMsg(PluginInstall::Exceptions::LibraryException, "Library error");
+ }
+
+ PluginObjectsPtr libraryObjects = PluginObjectsPtr(new PluginObjects());
+ const js_entity_definition_t *rawEntityListIterator = rawEntityList;
+
+ WrtLogD("#####");
+ WrtLogD("##### Plugin: %s is using deprecated API", libName.c_str());
+ WrtLogD("#####");
+
+ while (rawEntityListIterator->parent_name != NULL &&
+ rawEntityListIterator->object_name != NULL)
+ {
+ WrtLogD("##### [%s]: ", rawEntityListIterator->object_name);
+ WrtLogD("##### Parent: %s", rawEntityListIterator->parent_name);
+ WrtLogD("#####");
+
+ libraryObjects->addObjects(rawEntityListIterator->parent_name,
+ rawEntityListIterator->object_name);
+
+ ++rawEntityListIterator;
+ }
+
+ // Unload library
+ if (dlclose(dlHandle) != 0) {
+ WrtLogE("Cannot close plugin handle");
+ } else {
+ WrtLogD("Library is unloaded");
+ }
+
+ // Load export table
+ WrtLogD("Library successfuly loaded and parsed");
+
+ return libraryObjects;
+}
+
+PluginsInstaller::ReturnStatus PluginsInstaller::installPluginFromMetafile(
+ const std::string& path, const std::string& metaFilePath)
+{
+ if (!m_initialized) {
+ WrtLogE("Plugins installer not initialized.");
+ return ReturnStatus::NotInitialized;
+ }
+ OptionalPluginMetafileData pluginData;
+ Try
+ {
+ pluginData = parseMetafile(metaFilePath);
+ }
+ Catch(PluginInstall::Exceptions::XMLFileParsingException)
+ {
+ WrtLogE("Parsing metafile failed.");
+ return ReturnStatus::MetafileError;
+ }
+ if (!pluginData) {
+ return ReturnStatus::MetafileError;
+ }
+
+ if (WrtDB::PluginDAO::isPluginInstalled(pluginData->m_libraryName)) {
+ WrtLogD("Plugin already installed.");
+ return ReturnStatus::AlreadyInstalled;
+ }
+ Try {
+ WrtLogE("path is: %s, libraryName: %s",
+ path.c_str(),
+ pluginData->m_libraryName.c_str());
+ PluginObjectsPtr objects = loadLibraryFromMetafile(
+ path + DIRECTORY_SEPARATOR + pluginData->m_libraryName);
+
+ PluginHandle pluginHandle =
+ PluginDAO::registerPlugin(*pluginData, path);
+
+ WrtLogD("Plugin registered. Registering features...");
+
+ FOREACH(it, pluginData->m_featureContainer)
+ {
+ WrtLogE("PluginHandle: %d", pluginHandle);
+ FeatureDAO::RegisterFeature(*it, pluginHandle);
+ }
+
+ WrtLogD("Features registered. Registering objects...");
+
+ registerPluginObjects(pluginHandle, objects);
+
+ WrtLogD("Objects registered. Finishing...");
+
+ if (!registerAndUpdateInstallation(pluginHandle, objects)) {
+ return ReturnStatus::InstallationWaiting;
+ }
+ } Catch(DPL::Exception) {
+ WrtLogE("Failed to make database entry.");
+ return ReturnStatus::DatabaseError;
+ }
+
+ WrtLogD("Plugin installed successfully.");
+ return ReturnStatus::Success;
+}
+
+int PluginsInstaller::installAllPlugins()
+{
+ if (!m_initialized) {
+ WrtLogE("Plugins installer not initialized.");
+ return INSTALLATION_ERROR;
+ }
+ WrtLogD("Installing plugins ...");
+
+ std::string PLUGIN_PATH = std::string(GlobalConfig::GetDevicePluginPath());
+
+ DIR *dir;
+ dir = opendir(PLUGIN_PATH.c_str());
+
+ if (!dir) {
+ return INSTALLATION_ERROR;
+ }
+
+ WrtLogD("Plugin DIRECTORY IS %s", PLUGIN_PATH.c_str());
+ int return_code;
+ struct dirent libdir;
+ struct dirent* result;
+
+ errno = 0;
+
+ std::list<std::string> pluginsPaths;
+
+ for (return_code = readdir_r(dir, &libdir, &result);
+ result != NULL && return_code == 0;
+ return_code = readdir_r(dir, &libdir, &result)) {
+ if (strcmp(libdir.d_name, ".") == 0 ||
+ strcmp(libdir.d_name, "..") == 0)
+ {
+ continue;
+ }
+
+ std::string path = PLUGIN_PATH;
+ path += "/";
+ path += libdir.d_name;
+
+ struct stat tmp;
+
+ if (stat(path.c_str(), &tmp) == -1) {
+ WrtLogE("Failed to open file %s", path.c_str());
+ continue;
+ }
+
+ if (!S_ISDIR(tmp.st_mode)) {
+ WrtLogE("Not a directory %s", path.c_str());
+ continue;
+ }
+
+ WrtLogD("Found plugin at %s", path.c_str());
+ pluginsPaths.push_back(path);
+ }
+
+ if (0 != return_code)
+ WrtLogE("Error while reading directory.");
+
+ if (-1 == closedir(dir)) {
+ WrtLogE("Failed to close dir: %s", PLUGIN_PATH.c_str());
+ }
+
+ WrtLogD("Plugins to install: %d", pluginsPaths.size());
+
+ for (size_t k = 0; k <= pluginsPaths.size(); ++k) {
+ printf(" ");
+ }
+ printf("]\r[");
+ int installedPluginsCount = 0;
+ ReturnStatus ret = ReturnStatus::Unknown;
+ FOREACH(it, pluginsPaths) {
+ WrtLogD("Preparing to plugin installation: %s", (*it).c_str());
+ ret = installPlugin(*it);
+ if (ReturnStatus::Success == ret) {
+ ++installedPluginsCount;
+ WrtLogD("Plugin %s installed.", (*it).c_str());
+ } else if (ReturnStatus::InstallationWaiting == ret) {
+ WrtLogW("Plugin not installed. Waiting for dependency");
+ } else {
+ WrtLogE("Plugin installation failed");
+ }
+ printf("#");
+ fflush(stdout);
+ }
+ printf("\n");
+ installedPluginsCount += installWaitingPlugins();
+ m_registry.UnloadAll();
+ WrtLogD("Installed %d plugins of total: %d",
+ installedPluginsCount,
+ pluginsPaths.size());
+ return installedPluginsCount;
+}
+
+void PluginsInstaller::uninstallPlugin(WrtDB::DbPluginHandle handle, const PluginDAOReadOnly& dao)
+{
+ WrtLogD("Unregister plugin: %s ...", dao.getLibraryName().c_str());
+
+ // mark dependent plugins as waiting when their dependency disappered
+ auto dependentPlugins = *dao.getLibraryDependentPlugins();
+ FOREACH(pl, dependentPlugins) {
+ PluginDAO::setPluginInstallationStatus(*pl, PluginDAO::INSTALLATION_WAITING);
+ PluginDAO::unregisterPluginLibrariesDependencies(*pl);
+ }
+
+ PluginDAO::unregisterPlugin(handle);
+}
+
+int PluginsInstaller::uninstallMissingAndChangedPlugins()
+{
+ int uninstalled = 0;
+ WrtDB::PluginHandleList list = PluginDAO::getPluginHandleList();
+ FOREACH(item, list)
+ {
+ Try {
+ PluginDAOReadOnly dao(*item);
+ DPL::Utils::Path libPath(dao.getLibraryPath());
+ if (!libPath.Exists()) {
+ // plugin deleted
+ uninstallPlugin(*item, dao);
+ ++uninstalled;
+ } else {
+ std::time_t timestamp = libPath.LastWriteTime();
+ if (timestamp != dao.getLibraryTimestamp()) {
+ // plugin updated
+ uninstallPlugin(*item, dao);
+ ++uninstalled;
+ }
+ }
+ } Catch(PluginDAOReadOnly::Exception::PluginNotExist) {
+ // ignore, plugin may be already removed
+ }
+ }
+ return uninstalled;
+}
+
+int PluginsInstaller::installWaitingPlugins()
+{
+ PluginHandleSetPtr waitingPlugins;
+
+ waitingPlugins =
+ PluginDAO::getPluginHandleByStatus(PluginDAO::INSTALLATION_WAITING);
+
+ int pluginsInstalled = 0;
+ FOREACH(it, *waitingPlugins)
+ {
+ if (resolvePluginDependencies(*it)) {
+ ++pluginsInstalled;
+ }
+ }
+ return pluginsInstalled;
+}
+
+bool PluginsInstaller::resolvePluginDependencies(PluginHandle handle)
+{
+ PluginHandleSetPtr dependencies(new PluginHandleSet);
+
+ PluginObjects::ObjectsPtr requiredObjects =
+ PluginDAO::getRequiredObjectsForPluginHandle(handle);
+
+ PluginHandle depHandle = INVALID_PLUGIN_HANDLE;
+
+ FOREACH(requiredObject, *requiredObjects)
+ {
+ depHandle =
+ PluginDAO::getPluginHandleForImplementedObject(*requiredObject);
+
+ if (INVALID_PLUGIN_HANDLE == depHandle) {
+ WrtLogE("Library implementing: %s NOT FOUND", requiredObject->c_str());
+ return false;
+ }
+ dependencies->insert(depHandle);
+ }
+
+ PluginDAO::registerPluginLibrariesDependencies(handle, dependencies);
+ PluginDAO::setPluginInstallationStatus(handle,
+ PluginDAO::INSTALLATION_COMPLETED);
+
+ return true;
+}
+
+void PluginsInstaller::registerObjects(const PluginObjectsPtr& libObj,
+ const IObjectsListPtr& objects) const
+{
+ WrtLogD("registerObjects invoked");
+
+ FOREACH(o, *objects)
+ {
+ auto children = CAST(*o)->GetChildren();
+
+ if (children) {
+ FOREACH(c, *children)
+ {
+ libObj->addObjects(CAST(*o)->GetName(), CAST(*c)->GetName());
+
+ WrtLogD("[Parent << Object] %s << %s",
+ CAST(*c)->GetName(),
+ CAST(*o)->GetName());
+ }
+
+ registerObjects(libObj, children);
+ }
+ }
+}
+
+PluginsInstaller::OptionalPluginMetafileData PluginsInstaller::parseMetafile(
+ const std::string& path) const
+{
+ WrtLogD("Plugin Config file: %s", path.c_str());
+ Try
+ {
+ PluginMetafileData pluginInfo;
+ PluginMetafileReader reader;
+ reader.initialize(path);
+ reader.read(pluginInfo);
+
+ FOREACH(it, pluginInfo.m_featureContainer) {
+ WrtLogD("Parsed feature : %s", it->m_name.c_str());
+
+ FOREACH(devCap, it->m_deviceCapabilities) {
+ WrtLogD(" | DevCap : %s", (*devCap).c_str());
+ }
+ }
+ return OptionalPluginMetafileData(pluginInfo);
+ }
+ Catch(ValidationCore::ParserSchemaException::Base) {
+ WrtLogE("Error during file processing %s", path.c_str());
+ ThrowMsg(PluginInstall::Exceptions::XMLFileParsingException,
+ "Parsing metafile failed");
+ }
+}
+
+std::string PluginsInstaller::getLibraryName(const std::string& dirPath) const
+{
+ std::string pluginPath = dirPath;
+ size_t indexpos = pluginPath.find_last_of('/');
+
+ if (std::string::npos == indexpos) {
+ indexpos = 0;
+ } else {
+ indexpos += 1; // move after '/'
+ }
+
+ std::string libName = pluginPath.substr(indexpos);
+ libName = WrtDB::GlobalConfig::GetPluginPrefix() + libName
+ + WrtDB::GlobalConfig::GetPluginSuffix();
+ WrtLogD("Plugin .so: %s", libName.c_str());
+ return libName;
+}
+
+bool PluginsInstaller::registerAndUpdateInstallation(
+ const WrtDB::DbPluginHandle& pluginHandle,
+ const PluginObjectsPtr& libraries)
+{
+ PluginHandleSetPtr handles = PluginHandleSetPtr(new PluginHandleSet);
+
+ DbPluginHandle handle = INVALID_PLUGIN_HANDLE;
+
+ //register requiredObjects
+ FOREACH(it, *(libraries->getDependentObjects()))
+ {
+ if (libraries->hasObject(*it)) {
+ WrtLogD("Dependency from the same library. ignored");
+ continue;
+ }
+
+ handle = PluginDAO::getPluginHandleForImplementedObject(*it);
+ if (handle == INVALID_PLUGIN_HANDLE) {
+ WrtLogE("Library implementing: %s NOT FOUND", (*it).c_str());
+ PluginDAO::setPluginInstallationStatus(
+ pluginHandle,
+ PluginDAO::INSTALLATION_WAITING);
+ return false;
+ }
+
+ handles->insert(handle);
+ }
+
+ PluginDAO::registerPluginLibrariesDependencies(pluginHandle, handles);
+
+ PluginDAO::setPluginInstallationStatus(pluginHandle,
+ PluginDAO::INSTALLATION_COMPLETED);
+ return true;
+}
+
+bool PluginsInstaller::fillMappingInterfaces(PluginMetafileData& pluginData,
+ const std::string& filename)
+{
+ void *dlHandle = dlopen(filename.c_str(), RTLD_NOW);
+ if (dlHandle == NULL) {
+ const char* error = (const char*)dlerror();
+ WrtLogE("Failed to load plugin: %s. Reason: %s",
+ filename.c_str(),
+ (error != NULL ? error : "unknown"));
+ return false;
+ }
+ Try
+ {
+ ExportedApi* entryPoint =
+ static_cast<ExportedApi*>(dlsym(dlHandle, GetExportedSymbolName()));
+ if (NULL == entryPoint) {
+ const char* error = (const char*)dlerror();
+ WrtLogE("Error: %s", (error != NULL ? error : "unknown"));
+ ThrowMsg(PluginInstall::Exceptions::LibraryException,
+ "Library error");
+ }
+
+ // obtain feature -> dev-cap mapping
+ feature_mapping_interface_t mappingInterface = { NULL, NULL, NULL };
+ entryPoint->GetProvidedFeatures(&mappingInterface);
+
+ if (!mappingInterface.featGetter || !mappingInterface.release ||
+ !mappingInterface.dcGetter)
+ {
+ WrtLogE("Failed to obtain mapping interface from .so");
+ ThrowMsg(PluginInstall::Exceptions::LibraryException,
+ "Library error");
+ }
+
+ feature_mapping_t* devcapMapping = mappingInterface.featGetter();
+
+ WrtLogD("Getting mapping from features to device capabilities");
+
+ for (size_t i = 0; i < devcapMapping->featuresCount; ++i) {
+ PluginMetafileData::Feature feature;
+ feature.m_name = devcapMapping->features[i].feature_name;
+
+ WrtLogD("Feature: %s", feature.m_name.c_str());
+
+ const devcaps_t* dc =
+ mappingInterface.dcGetter(
+ devcapMapping,
+ devcapMapping->features[i].
+ feature_name);
+
+ WrtLogD("device=cap: %p", dc);
+
+ if (dc) {
+ WrtLogD("devcaps count: %d", dc->devCapsCount);
+
+ for (size_t j = 0; j < dc->devCapsCount; ++j) {
+ WrtLogD("devcap: %s", dc->deviceCaps[j]);
+ feature.m_deviceCapabilities.insert(dc->deviceCaps[j]);
+ }
+ }
+
+ pluginData.m_featureContainer.insert(feature);
+ }
+
+ mappingInterface.release(devcapMapping);
+ } Catch(PluginInstall::Exceptions::PluginsInstallerException)
+ {
+ WrtLogE("Exception while feature mapping");
+ dlclose(dlHandle);
+ return false;
+ }
+
+ // Unload library
+ if (dlclose(dlHandle) != 0) {
+ WrtLogE("Cannot close plugin handle");
+ } else {
+ WrtLogD("Library is unloaded");
+ }
+ return true;
+}
+
+void PluginsInstaller::registerPluginObjects(
+ const WrtDB::DbPluginHandle& handle,
+ const PluginObjectsPtr libObjects)
+const
+{
+ //register implemented objects
+ PluginObjects::ObjectsPtr objects =
+ libObjects->getImplementedObject();
+
+ FOREACH(it, *objects)
+ {
+ WrtDB::PluginDAO::registerPluginImplementedObject(*it, handle);
+ }
+
+ //register requiredObjects
+ objects = libObjects->getDependentObjects();
+
+ FOREACH(it, *objects)
+ {
+ if (libObjects->hasObject(*it)) {
+ WrtLogD("Dependency from the same library. ignored");
+ continue;
+ }
+ WrtDB::PluginDAO::registerPluginRequiredObject(*it, handle);
+ }
+}
+
diff --git a/src/plugins-installer/plugin_installer.h b/src/plugins-installer/plugin_installer.h
new file mode 100644
index 0000000..f669e76
--- /dev/null
+++ b/src/plugins-installer/plugin_installer.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_installer.h
+ * @author Andrzej Surdej(a.surdej@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H
+#define WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H
+
+#include <string>
+#include <utility>
+#include <boost/optional.hpp>
+#include <plugin_installer_types.h>
+#include <plugin_objects.h>
+#include <IObject.h>
+#include <PluginRegistry.h>
+
+#include <dpl/wrt-dao-rw/plugin_dao.h>
+#include <dpl/singleton.h>
+
+class PluginsInstaller
+{
+ public:
+ static const int INSTALLATION_ERROR;
+ enum class ReturnStatus
+ {
+ Success, ///< Success
+
+ NotInitialized, ///< Singleton not initialized
+ WrongPluginPath, ///< ?
+ MetafileError, ///< ?
+ AlreadyInstalled, ///< ?
+ LoadingLibraryError, ///< Loading library by dlopen failed.
+ /// It may be caused by missing symbols
+ InstallationWaiting, /// Installation failed due to dependencies
+ DatabaseError, /// Unable to update database
+ Unknown ///< Temporary error. Try to not use this.
+ };
+
+ bool initialize();
+ int installAllPlugins();
+ void deinitialize();
+
+ ReturnStatus installPlugin(const std::string& libPath);
+ ReturnStatus installPluginFromMetafile(const std::string& libPath,
+ const std::string& metaFilePath);
+
+ int installWaitingPlugins();
+ bool resolvePluginDependencies(PluginHandle handle);
+
+ bool isInitialized();
+
+ int uninstallMissingAndChangedPlugins();
+ void uninstallPlugin(WrtDB::DbPluginHandle handle, const WrtDB::PluginDAOReadOnly& dao);
+
+ private:
+ friend class DPL::Singleton<PluginsInstaller>;
+
+ PluginsInstaller();
+ virtual ~PluginsInstaller();
+
+ void registerObjects(const PluginObjectsPtr& libObj,
+ const WrtPluginsApi::IObjectsListPtr& objects) const;
+
+ typedef boost::optional<WrtDB::PluginMetafileData> OptionalPluginMetafileData;
+ OptionalPluginMetafileData parseMetafile(const std::string& path) const;
+
+ std::string getLibraryName(const std::string& dirPath) const;
+ bool registerAndUpdateInstallation(const PluginHandle& pluginHandle,
+ const PluginObjectsPtr& libraries);
+ bool fillMappingInterfaces(WrtDB::PluginMetafileData& pluginData,
+ const std::string& filename);
+ void registerPluginObjects(const PluginHandle& handle,
+ const PluginObjectsPtr libObjects) const;
+ void checkDatabaseTablesExistance();
+ PluginObjectsPtr loadLibraryFromMetafile(const std::string& libName) const;
+
+ WrtPluginsApi::PluginRegistry m_registry;
+ bool m_initialized;
+ bool m_reinstall;
+};
+
+typedef DPL::Singleton<PluginsInstaller> PluginsInstallerSingleton;
+
+#endif /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_H */
+
diff --git a/src/plugins-installer/plugin_installer_errors.h b/src/plugins-installer/plugin_installer_errors.h
new file mode 100644
index 0000000..9a94a79
--- /dev/null
+++ b/src/plugins-installer/plugin_installer_errors.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_installer_errors.h
+ * @author Pawel Sikorski (p.sikorski@samgsung.com)
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_ERRORS_H
+#define WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_ERRORS_H
+
+#include <dpl/exception.h>
+
+namespace PluginInstall {
+namespace Exceptions {
+DECLARE_EXCEPTION_TYPE(DPL::Exception, PluginsInstallerException)
+DECLARE_EXCEPTION_TYPE(PluginsInstallerException, LibraryException)
+DECLARE_EXCEPTION_TYPE(PluginsInstallerException, XMLFileParsingException)
+} //namespace
+} //namespace
+
+#endif /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_ERRORS_H */
+
diff --git a/src/plugins-installer/plugin_installer_types.h b/src/plugins-installer/plugin_installer_types.h
new file mode 100644
index 0000000..ae3a5db
--- /dev/null
+++ b/src/plugins-installer/plugin_installer_types.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_installer_types.h
+ * @author Andrzej Surdej (a.surdej@samgsung.com)
+ * @version
+ * @brief
+ */
+
+#ifndef WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_TYPES_H
+#define WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_TYPES_H
+
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+
+/* Define db type */
+typedef WrtDB::DbWidgetHandle WidgetHandle;
+typedef WrtDB::DbWidgetHandleList WidgetHandleList;
+
+typedef WrtDB::DbWidgetFeature WidgetFeature;
+typedef WrtDB::DbWidgetFeatureSet WidgetFeatureSet;
+
+typedef WrtDB::DbPluginHandle PluginHandle;
+
+#endif /* WRT_PLUGINS_INSTALLER_PLUGIN_INSTALLER_TYPES_H */
diff --git a/src/plugins-installer/plugin_metafile_reader.cpp b/src/plugins-installer/plugin_metafile_reader.cpp
new file mode 100644
index 0000000..b65c2e3
--- /dev/null
+++ b/src/plugins-installer/plugin_metafile_reader.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_metafile_reader.cpp
+ * @author Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#include "plugin_metafile_reader.h"
+
+using namespace WrtDB;
+
+namespace {
+const std::string XML_NAMESPACE = "";
+
+const std::string TOKEN_LIBRARY_NAME = "library-name";
+const std::string TOKEN_API_FEATURE = "api-feature";
+const std::string TOKEN_NAME = "name";
+const std::string TOKEN_DEVICECAPABILITY = "device-capability";
+}
+
+PluginMetafileReader::PluginMetafileReader() : m_parserSchema(this)
+{
+ m_parserSchema.addEndTagCallback(
+ TOKEN_LIBRARY_NAME,
+ XML_NAMESPACE,
+ &PluginMetafileReader::tokenEndLibraryName);
+
+ m_parserSchema.addEndTagCallback(
+ TOKEN_API_FEATURE,
+ XML_NAMESPACE,
+ &PluginMetafileReader::tokenEndApiFeature);
+
+ m_parserSchema.addEndTagCallback(
+ TOKEN_NAME,
+ XML_NAMESPACE,
+ &PluginMetafileReader::tokenEndName);
+
+ m_parserSchema.addEndTagCallback(
+ TOKEN_DEVICECAPABILITY,
+ XML_NAMESPACE,
+ &PluginMetafileReader::tokenEndDeviceCapability);
+}
+
+void PluginMetafileReader::blankFunction(PluginMetafileData & /* data */)
+{}
+
+void PluginMetafileReader::tokenEndLibraryName(PluginMetafileData &data)
+{
+ data.m_libraryName = m_parserSchema.getText();
+}
+
+void PluginMetafileReader::tokenEndApiFeature(PluginMetafileData &data)
+{
+ data.m_featureContainer.insert(m_feature);
+ m_feature.m_deviceCapabilities.clear();
+}
+
+void PluginMetafileReader::tokenEndName(PluginMetafileData & /* data */)
+{
+ m_feature.m_name = m_parserSchema.getText();
+}
+
+void PluginMetafileReader::tokenEndDeviceCapability(PluginMetafileData& /*data*/)
+{
+ m_feature.m_deviceCapabilities.insert(m_parserSchema.getText());
+}
+
diff --git a/src/plugins-installer/plugin_metafile_reader.h b/src/plugins-installer/plugin_metafile_reader.h
new file mode 100644
index 0000000..b0c88f0
--- /dev/null
+++ b/src/plugins-installer/plugin_metafile_reader.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_metafile_reader.h
+ * @author Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_METAFILE_READER_H_
+#define WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_METAFILE_READER_H_
+
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+#include <vcore/ParserSchema.h>
+
+class PluginMetafileReader
+{
+ public:
+ PluginMetafileReader();
+
+ void initialize(const std::string &filename)
+ {
+ m_parserSchema.initialize(filename,
+ true,
+ ValidationCore::SaxReader::VALIDATION_DTD,
+ std::string());
+ }
+
+ void read(WrtDB::PluginMetafileData &data)
+ {
+ m_parserSchema.read(data);
+ }
+
+ private:
+ void blankFunction(WrtDB::PluginMetafileData &data);
+
+ void tokenEndLibraryName(WrtDB::PluginMetafileData &data);
+ void tokenEndApiFeature(WrtDB::PluginMetafileData &data);
+ void tokenEndName(WrtDB::PluginMetafileData &data);
+ void tokenEndDeviceCapability(WrtDB::PluginMetafileData &data);
+
+ WrtDB::PluginMetafileData::Feature m_feature;
+
+ ValidationCore::ParserSchema<PluginMetafileReader,
+ WrtDB::PluginMetafileData> m_parserSchema;
+};
+
+#endif
diff --git a/src/plugins-installer/plugin_objects.cpp b/src/plugins-installer/plugin_objects.cpp
new file mode 100644
index 0000000..5149225
--- /dev/null
+++ b/src/plugins-installer/plugin_objects.cpp
@@ -0,0 +1,125 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_objects.h
+ * @author Grzegorz Krawczyk (g.krawczyk@samgsung.com)
+ * @version
+ * @brief
+ */
+#include <string>
+#include <dpl/log/wrt_log.h>
+#include "plugin_objects.h"
+#include <IObject.h>
+
+namespace {
+const char* SEPARATOR = ".";
+const std::string GLOBAL_OBJECT_NAME = WrtPluginsApi::IObject::WINDOW_OBJECT();
+const std::string OLD_GLOBAL_OBJECT_NAME = "GLOBAL_OBJECT";
+
+std::string normalizeName(const std::string& objectName)
+{
+ if (objectName.empty()) {
+ WrtLogE("Normalize name, name size is 0");
+ return objectName;
+ }
+
+ if (!objectName.compare(0, GLOBAL_OBJECT_NAME.size(),
+ GLOBAL_OBJECT_NAME))
+ {
+ return objectName;
+ }
+
+ //normalizing name of objects registered in old way
+ if (!objectName.compare(0, OLD_GLOBAL_OBJECT_NAME.size(),
+ OLD_GLOBAL_OBJECT_NAME))
+ {
+ if (objectName.size() > OLD_GLOBAL_OBJECT_NAME.size() + 1)
+ {
+ return GLOBAL_OBJECT_NAME + std::string(SEPARATOR) + objectName.substr(OLD_GLOBAL_OBJECT_NAME.size() + 1);
+ }
+ else
+ {
+ return GLOBAL_OBJECT_NAME;
+ }
+ }
+
+ //each object in storage has name started from $GLOBAL_OBJECT_NAME$
+ return GLOBAL_OBJECT_NAME + std::string(SEPARATOR) + objectName;
+}
+
+std::string normalizeName(const std::string& objectName,
+ const std::string& parentName)
+{
+ if (objectName.empty() || parentName.empty()) {
+ WrtLogE("Normalize name, name size or parent name size is 0");
+ return std::string();
+ }
+
+ std::string normalizedName;
+ normalizedName = normalizeName(parentName) +
+ std::string(SEPARATOR) + objectName;
+
+ return normalizedName;
+}
+}
+
+PluginObjects::PluginObjects()
+{
+ m_implemented = ObjectsPtr(new Objects());
+ m_dependent = ObjectsPtr(new Objects());
+}
+
+PluginObjects::ObjectsPtr PluginObjects::getImplementedObject() const
+{
+ return m_implemented;
+}
+
+PluginObjects::ObjectsPtr PluginObjects::getDependentObjects() const
+{
+ return m_dependent;
+}
+
+void PluginObjects::addObjects(const std::string& parentName,
+ const std::string& name)
+{
+ WrtLogD("\n Parent: %s\n Name: %s\n After: Implemented: %s\n After Dependent: %s",
+ parentName.c_str(),
+ name.c_str(),
+ normalizeName(name, parentName).c_str(),
+ normalizeName(parentName).c_str());
+
+ addImplementedObject(normalizeName(name, parentName));
+ addDependentObject(normalizeName(parentName));
+}
+
+void PluginObjects::addDependentObject(const std::string& value)
+{
+ if (!value.compare(GLOBAL_OBJECT_NAME)) {
+ //dont add dependency to GLOBAL_OBJECT
+ return;
+ }
+ m_dependent->insert(value);
+}
+
+bool PluginObjects::hasObject(const std::string& name) const
+{
+ return m_implemented->find(name) != m_implemented->end();
+}
+
+void PluginObjects::addImplementedObject(const std::string& value)
+{
+ m_implemented->insert(value);
+}
diff --git a/src/plugins-installer/plugin_objects.h b/src/plugins-installer/plugin_objects.h
new file mode 100644
index 0000000..0b27a14
--- /dev/null
+++ b/src/plugins-installer/plugin_objects.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin_objects.h
+ * @author Grzegorz Krawczyk(g.krawczyk@samsung.com)
+ * @version 1.0
+ * @brief
+ */
+
+#ifndef WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_OBJECTS_H_
+#define WRT_SRC_INSTALLER_CORE_PLUGIN_INSTALLER_TASKS_PLUGIN_OBJECTS_H_
+
+#include <memory>
+#include <string>
+#include <set>
+#include <list>
+
+#include <dpl/wrt-dao-ro/common_dao_types.h>
+//TODO TO BE MOVED SOMEWHERE ELSE
+// AS OTHER MODULES (LIKE DAO) USE IT
+
+class PluginObjects : public WrtDB::PluginObjectsDAO
+{
+ public:
+ explicit PluginObjects();
+
+ //getters for objects from library
+ ObjectsPtr getImplementedObject() const;
+ ObjectsPtr getDependentObjects() const;
+
+ //add object declaration
+ void addObjects(const std::string& parentName,
+ const std::string& name);
+
+ //check if library implemements object given as name
+ bool hasObject(const std::string& name) const;
+
+ private:
+ void addImplementedObject(const std::string& value);
+ void addDependentObject(const std::string& value);
+};
+
+typedef std::shared_ptr<PluginObjects> PluginObjectsPtr;
+
+#endif
diff --git a/src/plugins-installer/plugin_utils.cpp b/src/plugins-installer/plugin_utils.cpp
new file mode 100644
index 0000000..18f49d6
--- /dev/null
+++ b/src/plugins-installer/plugin_utils.cpp
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin-utils.cpp
+ * @author
+ * @version 1.0
+ * @brief Header file for plugin util
+ */
+
+#include "plugin_utils.h"
+#include <dpl/semaphore.h>
+#include <dpl/exception.h>
+#include <dpl/log/wrt_log.h>
+#include <dpl/wrt-dao-ro/global_config.h>
+
+using namespace WrtDB;
+
+namespace PluginUtils {
+//checks if file exists and is regular file
+bool checkFileExistance(const std::string& filename)
+{
+ struct stat tmp;
+
+ if (0 == stat(filename.c_str(), &tmp) && S_ISREG(tmp.st_mode)) {
+ return true;
+ }
+ return false;
+}
+
+std::string cutOffFileName(const std::string& path)
+{
+ size_t found = path.find_last_of("/");
+ if (found == std::string::npos) {
+ return path;
+ } else {
+ return path.substr(0, found);
+ }
+}
+
+bool checkPath(const std::string& path)
+{
+ struct stat st;
+ if (0 == stat(path.c_str(), &st) && S_ISDIR(st.st_mode)) {
+ return true;
+ }
+ WrtLogE("Cannot access directory [%s]", path.c_str());
+ return false;
+}
+
+bool checkPaths()
+{
+ bool if_ok = true;
+ if_ok &= (checkPath(cutOffFileName(
+ GlobalConfig::GetWrtDatabaseFilePath())));
+ if (!if_ok) {
+ WrtLogE("Path <%s> does not exist.", GlobalConfig::GetWrtDatabaseFilePath());
+ }
+
+ if_ok &= (checkPath(GlobalConfig::GetDevicePluginPath()));
+ if (!if_ok) {
+ WrtLogE("Path <%s> does not exist.", GlobalConfig::GetDevicePluginPath());
+ }
+
+ if_ok &= (checkPath(GlobalConfig::GetUserInstalledWidgetPath()));
+ if (!if_ok) {
+ WrtLogE("Path <%s> does not exist.", GlobalConfig::GetUserInstalledWidgetPath());
+ }
+ return if_ok;
+}
+} //namespace PluginUtils
diff --git a/src/plugins-installer/plugin_utils.h b/src/plugins-installer/plugin_utils.h
new file mode 100644
index 0000000..a542e28
--- /dev/null
+++ b/src/plugins-installer/plugin_utils.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file plugin-utils.h
+ * @author
+ * @version 1.0
+ * @brief Header file for plugin util
+ */
+#ifndef PLUGIN_UTILS_H
+#define PLUGIN_UTILS_H
+
+#include <string>
+#include <sys/stat.h>
+
+namespace PluginUtils {
+bool checkFileExistance(const std::string& filename);
+
+std::string cutOffFileName(const std::string& path);
+bool checkPath(const std::string& path);
+bool checkPaths();
+}
+#endif // PLUGIN_UTILS_H
diff --git a/src/plugins-installer/wrt_plugins_installer.cpp b/src/plugins-installer/wrt_plugins_installer.cpp
new file mode 100644
index 0000000..aa7ea53
--- /dev/null
+++ b/src/plugins-installer/wrt_plugins_installer.cpp
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/* @file wrt_plugins_installer.cpp
+ * @author Andrzej Surdej(a.surdej@gmail.com)
+ * @version 1.0
+ * @brief Main file for plugins installer
+ */
+
+#include <plugin_installer.h>
+#include <dpl/log/wrt_log.h>
+#include <string>
+#include <cstdio>
+#include <dpl/exception.h>
+#include <dpl/platform.h>
+
+int main(int /*argc*/, char */*argv*/[])
+{
+ UNHANDLED_EXCEPTION_HANDLER_BEGIN
+ {
+ WrtLogD("Plugins installation started.");
+
+ printf("Installing plugins...\n");
+ PluginsInstallerSingleton::Instance().initialize();
+
+#ifdef ENABLE(DOWNLOADABLE_PLUGIN)
+ int uninstalled = PluginsInstallerSingleton::Instance().uninstallMissingAndChangedPlugins();
+ printf("# %d plugins uninstalled.\n", uninstalled);
+#endif
+
+ int installed = PluginsInstallerSingleton::Instance().installAllPlugins();
+ printf("# %d plugins installed.\n", installed);
+
+ PluginsInstallerSingleton::Instance().deinitialize();
+ WrtLogD("All plugins installed successfuly");
+ return 0;
+ }
+ UNHANDLED_EXCEPTION_HANDLER_END
+}