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)
22 #include <ewk_context.h>
23 #include <Plugin/IBoxPluginFactory.h>
24 #include <Plugin/box_plugin_interface.h>
29 #include "BoxManager.h"
31 BoxManager::BoxManager(IBoxPluginFactoryPtr factory)
32 : m_boxFactory(factory)
37 BoxManager::~BoxManager()
42 bool BoxManager::doCommand(const request_cmd_type type, const BoxInfoPtr& boxInfo)
47 case REQUEST_CMD_ADD_BOX:
48 result = requestAddBox(boxInfo, m_defaultContext);
50 case REQUEST_CMD_REMOVE_BOX:
51 result = requestRemoveBox(boxInfo->instanceId);
53 case REQUEST_CMD_RESIZE_BOX:
54 result = requestResizeBox(boxInfo->instanceId, boxInfo->boxWidth, boxInfo->boxHeight);
56 case REQUEST_CMD_RESUME_BOX:
57 result = requestResumeBox(boxInfo->instanceId);
59 case REQUEST_CMD_PAUSE_BOX:
60 result = requestPauseBox(boxInfo->instanceId);
62 case REQUEST_CMD_RESUME_ALL:
63 result = requestResumeAll();
65 case REQUEST_CMD_PAUSE_ALL:
66 result = requestPauseAll();
68 case REQUEST_CMD_OPEN_PD:
69 result = requestOpenPd(boxInfo->instanceId,
70 boxInfo->pdWidth, boxInfo->pdHeight,
71 boxInfo->pdX, boxInfo->pdY);
73 case REQUEST_CMD_CLOSE_PD:
74 result = requestClosePd(boxInfo->instanceId);
76 case REQUEST_CMD_CHANGE_PERIOD:
77 result = requestChangePeriod(boxInfo->instanceId, boxInfo->period);
79 case REQUEST_CMD_UPDATE_BOX:
80 result = requestUpdateBox(boxInfo->boxId);
83 LogD("not available request type");
90 bool BoxManager::requestAddBox(BoxInfoPtr boxInfo, EwkContextPtr ewkContext)
97 if (!m_defaultContext) {
98 m_defaultContext = EwkContextPtr(ewk_context_new(), EwkContextDeleter());
100 ewkContext = m_defaultContext;
102 box = Box::create(boxInfo, m_boxFactory, ewkContext);
104 LogD("exection occurs during adding box");
110 LogD("problem occurs during rendering box");
114 insertBoxMap(boxInfo->instanceId, box);
118 bool BoxManager::requestRemoveBox(std::string& instanceId)
120 IBoxPtr box = searchBoxMap(instanceId);
129 eraseBoxMap(instanceId);
133 bool BoxManager::requestResizeBox(std::string& instanceId, int width, int height)
136 IBoxPtr box = searchBoxMap(instanceId);
141 return box->resize(width, height);
144 bool BoxManager::requestResumeBox(std::string& instanceId)
147 IBoxPtr box = searchBoxMap(instanceId);
152 return box->resume();
155 bool BoxManager::requestPauseBox(std::string& instanceId)
158 IBoxPtr box = searchBoxMap(instanceId);
163 // paused by switching other page
164 return box->pause(false);
167 bool BoxManager::requestResumeAll()
170 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
171 if (it->second->isCurrentTab()) {
172 it->second->resume();
179 bool BoxManager::requestPauseAll()
182 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
183 if (it->second->isCurrentTab()) {
184 // paused by entering background
185 it->second->pause(true);
192 bool BoxManager::requestOpenPd(
193 std::string& instanceId,
194 int width, int height, double x, double y)
197 IBoxPtr box = searchBoxMap(instanceId);
202 return box->openPd(width, height, x, y);
205 bool BoxManager::requestClosePd(std::string& instanceId)
208 IBoxPtr box = searchBoxMap(instanceId);
213 return box->closePd();
216 bool BoxManager::requestChangePeriod(std::string& instanceId, float period)
219 IBoxPtr box = searchBoxMap(instanceId);
224 return box->changePeriod(period);
227 bool BoxManager::requestUpdateBox(std::string& boxId)
233 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); ++it) {
234 if (it->first.find(boxId) == std::string::npos) {
244 void BoxManager::insertBoxMap(std::string& instanceId, IBoxPtr box)
246 if (!searchBoxMap(instanceId)) {
247 LogD("insert box to map: %s", instanceId.c_str());
248 m_boxMap.insert(BoxMapPair(instanceId, box));
250 LogD("this box was already inserted!");
254 void BoxManager::eraseBoxMap(std::string& instanceId)
256 LogD("erase box to map");
257 if (!searchBoxMap(instanceId)) {
258 LogD("not available box");
262 m_boxMap.erase(instanceId);
265 void BoxManager::updateBoxMap(std::string& instanceId, IBoxPtr box)
267 if (searchBoxMap(instanceId)) {
268 eraseBoxMap(instanceId);
271 insertBoxMap(instanceId, box);
274 IBoxPtr BoxManager::searchBoxMap(std::string& instanceId)
279 auto it = m_boxMap.find(instanceId);
280 if (it != m_boxMap.end()) {
281 LogD("found box: %s (%p)", it->first.c_str(), it->second.get());
288 void BoxManager::clearBoxMap()
293 void BoxManager::EwkContextDeleter::operator()(Ewk_Context* ptr)
295 LogD("ewk context delete");
297 ewk_context_delete(ptr);