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 BoxManager.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
21 #include <ewk_context.h>
22 #include <Plugin/IBoxPluginFactory.h>
23 #include <Plugin/box_plugin_interface.h>
28 #include "BoxManager.h"
30 BoxManager::BoxManager(IBoxPluginFactoryPtr factory)
31 : m_boxFactory(factory)
36 BoxManager::~BoxManager()
41 bool BoxManager::doCommand(const request_cmd_type type, const BoxInfoPtr& boxInfo)
46 case REQUEST_CMD_ADD_BOX:
47 result = requestAddBox(boxInfo, m_defaultContext);
49 case REQUEST_CMD_REMOVE_BOX:
50 result = requestRemoveBox(boxInfo->instanceId);
52 case REQUEST_CMD_RESIZE_BOX:
53 result = requestResizeBox(boxInfo->instanceId, boxInfo->boxWidth, boxInfo->boxHeight);
55 case REQUEST_CMD_RESUME_BOX:
56 result = requestResumeBox(boxInfo->instanceId);
58 case REQUEST_CMD_PAUSE_BOX:
59 result = requestPauseBox(boxInfo->instanceId);
61 case REQUEST_CMD_RESUME_ALL:
62 result = requestResumeAll();
64 case REQUEST_CMD_PAUSE_ALL:
65 result = requestPauseAll();
67 case REQUEST_CMD_OPEN_PD:
68 result = requestOpenPd(boxInfo->instanceId,
69 boxInfo->pdWidth, boxInfo->pdHeight,
70 boxInfo->pdX, boxInfo->pdY);
72 case REQUEST_CMD_CLOSE_PD:
73 result = requestClosePd(boxInfo->instanceId);
75 case REQUEST_CMD_CHANGE_PERIOD:
76 result = requestChangePeriod(boxInfo->instanceId, boxInfo->period);
78 case REQUEST_CMD_UPDATE_BOX:
79 result = requestUpdateBox(boxInfo->instanceId);
82 LogD("not available request type");
89 bool BoxManager::requestAddBox(BoxInfoPtr boxInfo, EwkContextPtr ewkContext)
96 if (!m_defaultContext) {
97 m_defaultContext = EwkContextPtr(ewk_context_new(), EwkContextDeleter());
99 ewkContext = m_defaultContext;
101 box = Box::create(boxInfo, m_boxFactory, ewkContext);
103 LogD("exection occurs during adding box");
109 LogD("problem occurs during rendering box");
113 insertBoxMap(boxInfo->instanceId, box);
117 bool BoxManager::requestRemoveBox(std::string& instanceId)
119 IBoxPtr box = searchBoxMap(instanceId);
128 eraseBoxMap(instanceId);
132 bool BoxManager::requestResizeBox(std::string& instanceId, int width, int height)
135 IBoxPtr box = searchBoxMap(instanceId);
140 return box->resize(width, height);
143 bool BoxManager::requestResumeBox(std::string& instanceId)
146 IBoxPtr box = searchBoxMap(instanceId);
151 return box->resume();
154 bool BoxManager::requestPauseBox(std::string& instanceId)
157 IBoxPtr box = searchBoxMap(instanceId);
162 // paused by switching other page
163 return box->pause(false);
166 bool BoxManager::requestResumeAll()
169 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
170 if (it->second->isCurrentTab()) {
171 it->second->resume();
178 bool BoxManager::requestPauseAll()
181 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
182 if (it->second->isCurrentTab()) {
183 // paused by entering background
184 it->second->pause(true);
191 bool BoxManager::requestOpenPd(
192 std::string& instanceId,
193 int width, int height, double x, double y)
196 IBoxPtr box = searchBoxMap(instanceId);
201 return box->openPd(width, height, x, y);
204 bool BoxManager::requestClosePd(std::string& instanceId)
207 IBoxPtr box = searchBoxMap(instanceId);
212 return box->closePd();
215 bool BoxManager::requestChangePeriod(std::string& instanceId, float period)
218 IBoxPtr box = searchBoxMap(instanceId);
223 return box->changePeriod(period);
226 bool BoxManager::requestUpdateBox(std::string& instanceId)
229 IBoxPtr box = searchBoxMap(instanceId);
234 return box->update();
237 void BoxManager::insertBoxMap(std::string& instanceId, IBoxPtr box)
239 if (!searchBoxMap(instanceId)) {
240 LogD("insert box to map: %s", instanceId.c_str());
241 m_boxMap.insert(BoxMapPair(instanceId, box));
243 LogD("this box was already inserted!");
247 void BoxManager::eraseBoxMap(std::string& instanceId)
249 LogD("erase box to map");
250 if (!searchBoxMap(instanceId)) {
251 LogD("not available box");
255 m_boxMap.erase(instanceId);
258 void BoxManager::updateBoxMap(std::string& instanceId, IBoxPtr box)
260 if (searchBoxMap(instanceId)) {
261 eraseBoxMap(instanceId);
264 insertBoxMap(instanceId, box);
267 IBoxPtr BoxManager::searchBoxMap(std::string& instanceId)
272 auto it = m_boxMap.find(instanceId);
273 if (it != m_boxMap.end()) {
274 LogD("found box: %s (%p)", it->first.c_str(), it->second.get());
281 void BoxManager::clearBoxMap()
286 void BoxManager::EwkContextDeleter::operator()(Ewk_Context* ptr)
288 LogD("ewk context delete");
290 ewk_context_delete(ptr);