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 AppBoxManager.cpp
18 * @author Yunchan Cho (yunchan.cho@samsung.com)
21 #include <core_module.h>
22 #include <Plugin/IBoxPluginFactory.h>
23 #include <Core/BoxData.h>
24 #include <Core/BoxManager.h>
25 #include <Core/IBox.h>
26 #include <Core/Util/Log.h>
27 #include <API/web_provider_livebox_info.h>
28 #include "AppBoxObserver.h"
29 #include "AppBoxManager.h"
31 static const std::string bundlePath("/usr/lib/libwrt-injected-bundle.so");
33 AppBoxManager::AppBoxManager(IBoxPluginFactoryPtr factory)
36 bool ret = WRT::CoreModuleSingleton::Instance().Init();
38 throw; // throw exeception
40 AppBoxObserver::Instance()->initialize();
43 AppBoxManager::~AppBoxManager()
45 AppBoxObserver::Instance()->shutdown();
48 bool AppBoxManager::requestAddBox(BoxInfoPtr boxInfo, EwkContextPtr ewkContext)
52 web_provider_livebox_get_app_id(boxInfo->boxId.c_str());
55 LogD("no appid of %s", boxInfo->boxId.c_str());
59 std::string appIdStr(appId);
62 auto it = m_ewkContextMap.find(appIdStr);
63 if (it == m_ewkContextMap.end()) {
64 ewkContext = getAvailableEwkContext();
65 insertContextMap(appIdStr, ewkContext);
67 ewkContext = it->second;
70 if (!BoxManager::requestAddBox(boxInfo, ewkContext)) {
77 bool AppBoxManager::requestRemoveBox(std::string& instanceId)
79 if (!BoxManager::requestRemoveBox(instanceId)) {
86 EwkContextPtr AppBoxManager::getAvailableEwkContext()
89 ewk_context_new_with_injected_bundle_path(bundlePath.c_str()),
90 BoxManager::EwkContextDeleter());
93 void AppBoxManager::insertContextMap(std::string& appId, EwkContextPtr ewkContext)
95 m_ewkContextMap.insert(EwkContextMapPair(appId, ewkContext));
98 void AppBoxManager::eraseContextMap(std::string& appId)
100 m_ewkContextMap.erase(appId);