2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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 BoxPluginConnector.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
22 #include <Core/Util/Log.h>
23 #include <Core/BoxData.h>
24 #include <API/web_provider_plugin_info.h>
25 #include "box_plugin_interface.h"
26 #include "BoxPluginConnector.h"
28 BoxPluginConnector::BoxPluginConnector()
32 BoxPluginConnector::~BoxPluginConnector()
36 bool BoxPluginConnector::initialize()
41 web_provider_plugin_info** pluginList = NULL;
42 pluginList = web_provider_plugin_get_installed_list(&count);
45 LogD("failed to get installed plugin's information");
50 LogD("There is no available livebox plugins");
56 // get information of installed plugin
57 LogD("get information of installed plugin");
58 for (int i = 0; i < count; i++) {
63 LogD("plugin path: %s", pluginList[i]->path);
64 void* handle = dlopen(pluginList[i]->path, RTLD_LAZY);
66 LogD("failed to load plugin so: %s", dlerror());
70 std::shared_ptr<plugin_interfaces> pluginInfo(new plugin_interfaces);
72 pluginInfo->handle = handle;
73 pluginInfo->service_boxid = NULL;
74 if (pluginList[i]->service_boxid) {
75 pluginInfo->service_boxid = strdup(pluginList[i]->service_boxid);
78 pluginInfo->initialize =
79 reinterpret_cast<plugin_interface_func_initialize>(
80 dlsym(handle, WEB_PROVIDER_PLUGIN_INTERFACE_SYM_INITIALIZE));
82 reinterpret_cast<plugin_interface_func_command>(
83 dlsym(handle, WEB_PROVIDER_PLUGIN_INTERFACE_SYM_COMMAND));
84 pluginInfo->shutdown =
85 reinterpret_cast<plugin_interface_func_shutdown>(
86 dlsym(handle, WEB_PROVIDER_PLUGIN_INTERFACE_SYM_SHUTDOWN));
88 if (!pluginInfo->initialize || !pluginInfo->command ||
89 !pluginInfo->shutdown)
91 LogD("symbol for plugin interface is not found");
95 m_pluginMap[std::string(pluginList[i]->type)] = pluginInfo;
99 for (auto it = m_pluginMap.begin();
100 it != m_pluginMap.end(); ++it)
103 // TODO add exception or abnormal action on loading plugin
104 if (it->second->initialize() < 0) {
105 LogD("fail to intialize plugin");
111 // release information
112 LogD("release json data of plugins");
113 web_provider_plugin_release_installed_list(pluginList, count);
118 bool BoxPluginConnector::shutdown()
121 // if needed, unload each plugin's DSO.
122 for (auto it = m_pluginMap.begin();
123 it != m_pluginMap.end(); ++it)
126 it->second->shutdown();
127 dlclose(it->second->handle);
134 bool BoxPluginConnector::requestCommand(
135 const request_cmd_type type, const BoxInfoPtr& boxInfo)
139 // in case of request of resume all or pause all, all plugins should handle that.
140 if (type == REQUEST_CMD_RESUME_ALL || type == REQUEST_CMD_PAUSE_ALL) {
141 for (auto it = m_pluginMap.begin();
142 it != m_pluginMap.end(); ++it)
145 // In this case, boxInfo doesn't have any meaning
146 it->second->command(type, boxInfo);
152 const std::shared_ptr<plugin_interfaces> plugin = m_pluginMap[boxInfo->boxType];
154 LogD("not available livebox type");
158 int ret = plugin->command(type, boxInfo);
160 LogD("failed to request command");
167 std::string BoxPluginConnector::getBoxType(const std::string& serviceBoxId)
172 for (auto it = m_pluginMap.begin();
173 it != m_pluginMap.end(); ++it)
175 if (it->second && it->second->service_boxid) {
176 if (serviceBoxId == it->second->service_boxid) {
177 LogD("service box id is matched!: %s", it->first.c_str());