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);
79 LogD("not available request type");
86 bool BoxManager::requestAddBox(BoxInfoPtr boxInfo, EwkContextPtr ewkContext)
93 if (!m_defaultContext) {
94 m_defaultContext = EwkContextPtr(ewk_context_new(), EwkContextDeleter());
96 ewkContext = m_defaultContext;
98 box = Box::create(boxInfo, m_boxFactory, ewkContext);
100 LogD("exection occurs during adding box");
106 LogD("problem occurs during rendering box");
110 insertBoxMap(boxInfo->instanceId, box);
114 bool BoxManager::requestRemoveBox(std::string& instanceId)
116 IBoxPtr box = searchBoxMap(instanceId);
125 eraseBoxMap(instanceId);
129 bool BoxManager::requestResizeBox(std::string& instanceId, int width, int height)
132 IBoxPtr box = searchBoxMap(instanceId);
137 return box->resize(width, height);
140 bool BoxManager::requestResumeBox(std::string& instanceId)
143 IBoxPtr box = searchBoxMap(instanceId);
148 return box->resume();
151 bool BoxManager::requestPauseBox(std::string& instanceId)
154 IBoxPtr box = searchBoxMap(instanceId);
162 bool BoxManager::requestResumeAll()
165 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
166 it->second->resume();
172 bool BoxManager::requestPauseAll()
175 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
182 bool BoxManager::requestOpenPd(
183 std::string& instanceId,
184 int width, int height, double x, double y)
187 IBoxPtr box = searchBoxMap(instanceId);
192 return box->openPd(width, height, x, y);
195 bool BoxManager::requestClosePd(std::string& instanceId)
198 IBoxPtr box = searchBoxMap(instanceId);
203 return box->closePd();
206 bool BoxManager::requestChangePeriod(std::string& instanceId, float period)
209 IBoxPtr box = searchBoxMap(instanceId);
214 return box->changePeriod(period);
217 void BoxManager::insertBoxMap(std::string& instanceId, IBoxPtr box)
219 if (!searchBoxMap(instanceId)) {
220 LogD("insert box to map: %s", instanceId.c_str());
221 m_boxMap.insert(BoxMapPair(instanceId, box));
223 LogD("this box was already inserted!");
227 void BoxManager::eraseBoxMap(std::string& instanceId)
229 LogD("erase box to map");
230 if (!searchBoxMap(instanceId)) {
231 LogD("not available box");
235 m_boxMap.erase(instanceId);
238 void BoxManager::updateBoxMap(std::string& instanceId, IBoxPtr box)
240 if (searchBoxMap(instanceId)) {
241 eraseBoxMap(instanceId);
244 insertBoxMap(instanceId, box);
247 IBoxPtr BoxManager::searchBoxMap(std::string& instanceId)
252 auto it = m_boxMap.find(instanceId);
253 if (it != m_boxMap.end()) {
254 LogD("found box: %s (%p)", it->first.c_str(), it->second.get());
261 void BoxManager::clearBoxMap()
266 void BoxManager::EwkContextDeleter::operator()(Ewk_Context* ptr)
268 LogD("ewk context delete");
270 ewk_context_delete(ptr);