2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
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 web_app_core_data.cpp
18 * @author Leerang Song (leerang.song@samsung.com)
21 #include "web_app_core_data.h"
26 #include <dpl/assert.h>
27 #include <dpl/availability.h>
28 #include <dpl/log/wrt_log.h>
32 } // anonymous namespace
34 WebAppCoreDataManager::WebAppCoreDataManager()
38 WebAppCoreDataManager::~WebAppCoreDataManager()
42 bool WebAppCoreDataManager::add(const std::string& appId)
45 WrtLogE("appid is empty");
49 auto it = m_webAppCoreDataMap.find(appId);
50 if (it != m_webAppCoreDataMap.end()) {
51 WrtLogE("already exist");
55 WebAppCoreData* data = new WebAppCoreData();
56 data->status = WebAppCoreDataManager::Status::CREATED;
58 m_webAppCoreDataMap.insert(WebAppCoreDataPair(appId, data));
63 bool WebAppCoreDataManager::remove(const std::string& appId)
66 WrtLogE("appid is empty");
70 auto it = m_webAppCoreDataMap.find(appId);
71 if (it == m_webAppCoreDataMap.end()) {
76 m_webAppCoreDataMap.erase(it);
81 void WebAppCoreDataManager::show(const std::string& appId)
83 setStatus(appId, WebAppCoreDataManager::Status::RUNNING);
86 void WebAppCoreDataManager::hide(const std::string& appId)
88 DPL_UNUSED_PARAM(appId);
92 void WebAppCoreDataManager::resume(const std::string& appId)
94 setStatus(appId, WebAppCoreDataManager::Status::RUNNING);
97 void WebAppCoreDataManager::suspend(const std::string& appId)
99 setStatus(appId, WebAppCoreDataManager::Status::SUSPENDED);
102 bool WebAppCoreDataManager::isResumed(const std::string& appId)
104 return compareStatus(appId, WebAppCoreDataManager::Status::RUNNING);
107 bool WebAppCoreDataManager::isSuspended(const std::string& appId)
109 return compareStatus(appId, WebAppCoreDataManager::Status::SUSPENDED);
112 bool WebAppCoreDataManager::isAppIdFound(const std::string& appId)
116 auto it = m_webAppCoreDataMap.find(appId);
117 if (it == m_webAppCoreDataMap.end()) {
118 WrtLogE("appid not found in map");
124 WebAppCoreDataManager::Status WebAppCoreDataManager::getStatus(const std::string& appId)
127 WrtLogE("appid is empty");
131 auto it = m_webAppCoreDataMap.find(appId);
132 if (it == m_webAppCoreDataMap.end()) {
133 WrtLogE("No data found for given pid");
137 return it->second->status;
140 void WebAppCoreDataManager::setStatus(const std::string& appId, Status status)
143 WrtLogE("appid is empty");
147 auto it = m_webAppCoreDataMap.find(appId);
148 if (it == m_webAppCoreDataMap.end()) {
153 it->second->status = status;
157 bool WebAppCoreDataManager::compareStatus(const std::string& appId, Status status)
159 return getStatus(appId) == status ? true : false;
162 void WebAppCoreDataManager::setPid(const std::string& appId, pid_t pid)
165 WrtLogE("appid is empty");
169 auto it = m_webAppCoreDataMap.find(appId);
170 if (it == m_webAppCoreDataMap.end()) {
175 it->second->pid = pid;
178 pid_t WebAppCoreDataManager::getPid(const std::string& appId)
181 WrtLogE("appid is empty");
185 auto it = m_webAppCoreDataMap.find(appId);
186 if (it == m_webAppCoreDataMap.end()) {
191 return it->second->pid;
194 void WebAppCoreDataManager::setFd(const std::string& appId, Ecore_Fd_Handler* fd)
197 WrtLogE("appid is empty");
201 auto it = m_webAppCoreDataMap.find(appId);
202 if (it == m_webAppCoreDataMap.end()) {
210 Ecore_Fd_Handler* WebAppCoreDataManager::getFd(const std::string& appId)
213 WrtLogE("appid is empty");
217 auto it = m_webAppCoreDataMap.find(appId);
218 if (it == m_webAppCoreDataMap.end()) {
223 return it->second->fd;
226 std::string WebAppCoreDataManager::getAppIdFromFd(int fd)
229 WrtLogE("fail to get fd");
234 for (auto it = m_webAppCoreDataMap.begin(); it != m_webAppCoreDataMap.end(); ++it) {
235 if (ecore_main_fd_handler_fd_get(it->second->fd) == fd) {