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);
165 bool BoxManager::requestResumeAll()
168 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
169 it->second->resume();
175 bool BoxManager::requestPauseAll()
178 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
185 bool BoxManager::requestOpenPd(
186 std::string& instanceId,
187 int width, int height, double x, double y)
190 IBoxPtr box = searchBoxMap(instanceId);
195 return box->openPd(width, height, x, y);
198 bool BoxManager::requestClosePd(std::string& instanceId)
201 IBoxPtr box = searchBoxMap(instanceId);
206 return box->closePd();
209 bool BoxManager::requestChangePeriod(std::string& instanceId, float period)
212 IBoxPtr box = searchBoxMap(instanceId);
217 return box->changePeriod(period);
220 bool BoxManager::requestUpdateBox(std::string& instanceId)
223 IBoxPtr box = searchBoxMap(instanceId);
228 return box->update();
231 void BoxManager::insertBoxMap(std::string& instanceId, IBoxPtr box)
233 if (!searchBoxMap(instanceId)) {
234 LogD("insert box to map: %s", instanceId.c_str());
235 m_boxMap.insert(BoxMapPair(instanceId, box));
237 LogD("this box was already inserted!");
241 void BoxManager::eraseBoxMap(std::string& instanceId)
243 LogD("erase box to map");
244 if (!searchBoxMap(instanceId)) {
245 LogD("not available box");
249 m_boxMap.erase(instanceId);
252 void BoxManager::updateBoxMap(std::string& instanceId, IBoxPtr box)
254 if (searchBoxMap(instanceId)) {
255 eraseBoxMap(instanceId);
258 insertBoxMap(instanceId, box);
261 IBoxPtr BoxManager::searchBoxMap(std::string& instanceId)
266 auto it = m_boxMap.find(instanceId);
267 if (it != m_boxMap.end()) {
268 LogD("found box: %s (%p)", it->first.c_str(), it->second.get());
275 void BoxManager::clearBoxMap()
280 void BoxManager::EwkContextDeleter::operator()(Ewk_Context* ptr)
282 LogD("ewk context delete");
284 ewk_context_delete(ptr);