2 * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Flora License, Version 1.0 (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://www.tizenopensource.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, boxInfo->pdWidth, boxInfo->pdHeight);
70 case REQUEST_CMD_CLOSE_PD:
71 result = requestClosePd(boxInfo->instanceId);
73 case REQUEST_CMD_CHANGE_PERIOD:
74 result = requestChangePeriod(boxInfo->instanceId, boxInfo->period);
77 LogD("not available request type");
84 bool BoxManager::requestAddBox(BoxInfoPtr boxInfo, EwkContextPtr ewkContext)
91 if (!m_defaultContext) {
92 m_defaultContext = EwkContextPtr(ewk_context_new(), EwkContextDeleter());
94 ewkContext = m_defaultContext;
96 box = Box::create(boxInfo, m_boxFactory, ewkContext);
98 LogD("exection occurs during adding box");
104 LogD("problem occurs during rendering box");
108 insertBoxMap(boxInfo->instanceId, box);
112 bool BoxManager::requestRemoveBox(std::string& instanceId)
114 IBoxPtr box = searchBoxMap(instanceId);
123 eraseBoxMap(instanceId);
127 bool BoxManager::requestResizeBox(std::string& instanceId, int width, int height)
130 IBoxPtr box = searchBoxMap(instanceId);
135 return box->resize(width, height);
138 bool BoxManager::requestResumeBox(std::string& instanceId)
141 IBoxPtr box = searchBoxMap(instanceId);
146 return box->resume();
149 bool BoxManager::requestPauseBox(std::string& instanceId)
152 IBoxPtr box = searchBoxMap(instanceId);
160 bool BoxManager::requestResumeAll()
163 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
164 it->second->resume();
170 bool BoxManager::requestPauseAll()
173 for (auto it = m_boxMap.begin(); it != m_boxMap.end(); it++) {
180 bool BoxManager::requestOpenPd(std::string& instanceId, int width, int height)
183 IBoxPtr box = searchBoxMap(instanceId);
188 return box->openPd(width, height);
191 bool BoxManager::requestClosePd(std::string& instanceId)
194 IBoxPtr box = searchBoxMap(instanceId);
199 return box->closePd();
202 bool BoxManager::requestChangePeriod(std::string& instanceId, float period)
205 IBoxPtr box = searchBoxMap(instanceId);
210 return box->changePeriod(period);
213 void BoxManager::insertBoxMap(std::string& instanceId, IBoxPtr box)
215 if (!searchBoxMap(instanceId)) {
216 LogD("insert box to map: %s", instanceId.c_str());
217 m_boxMap.insert(BoxMapPair(instanceId, box));
219 LogD("this box was already inserted!");
223 void BoxManager::eraseBoxMap(std::string& instanceId)
225 LogD("erase box to map");
226 if (!searchBoxMap(instanceId)) {
227 LogD("not available box");
231 m_boxMap.erase(instanceId);
234 void BoxManager::updateBoxMap(std::string& instanceId, IBoxPtr box)
236 if (searchBoxMap(instanceId)) {
237 eraseBoxMap(instanceId);
240 insertBoxMap(instanceId, box);
243 IBoxPtr BoxManager::searchBoxMap(std::string& instanceId)
248 auto it = m_boxMap.find(instanceId);
249 if (it != m_boxMap.end()) {
250 LogD("found box: %s (%p)", it->first.c_str(), it->second.get());
257 void BoxManager::clearBoxMap()
262 void BoxManager::EwkContextDeleter::operator()(Ewk_Context* ptr)
264 LogD("ewk context delete");
266 ewk_context_delete(ptr);