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_internal_eventloop.cpp
18 * @author Prathmesh (prathmesh.m@samsung.com)
21 #include "web_internal_eventloop.h"
22 #include <dpl/singleton_safe_impl.h>
24 IMPLEMENT_SAFE_SINGLETON(WebInternalEvent)
26 WebInternalEvent::WebInternalEvent()
30 #ifdef SUPPORT_MULTIPLE_REQUEST
31 WebInternalEvent::~WebInternalEvent()
33 for (auto it = m_webInternalEventMap.begin(); it != m_webInternalEventMap.end(); ++it) {
36 m_webInternalEventMap.clear();
39 void WebInternalEvent::addListner(webInternalEventType type, Ecore_Event_Handler_Cb cbFunc, void *data)
41 auto it = m_webInternalEventMap.find(type);
42 if (it != m_webInternalEventMap.end())
45 WebInternalUserCBData* cbData = new WebInternalUserCBData();
46 cbData->m_event = ecore_event_type_new();
47 cbData->m_callerCallback = cbFunc;
48 cbData->m_data = data;
49 m_customEventHandler = ecore_event_handler_add(cbData->m_event, eventTriggeredCallback, this);
50 m_webInternalEventMap.insert(WebInternalEventPair(type, cbData));
53 void WebInternalEvent::deleteListner(webInternalEventType type)
55 auto it = m_webInternalEventMap.find(type);
56 if (it != m_webInternalEventMap.end()) {
58 m_webInternalEventMap.erase(it);
62 void WebInternalEvent::sendEvent(webInternalEventType type, void *eventInfo)
64 auto it = m_webInternalEventMap.find(type);
65 if (it != m_webInternalEventMap.end()) {
66 WebInternalUserCBData* cbData = it->second;
67 ecore_event_add(cbData->m_event, eventInfo, freeEventInfo, NULL);
71 void WebInternalEvent::freeEventInfo(void *user_data, void *func_data)
73 // Do nothing. Added here else the default free is called.
74 // Need to override the default free and insteed free after
78 Eina_Bool WebInternalEvent::eventTriggeredCallback(void *data, int type, void *eventInfo)
80 WebInternalEvent* This = (WebInternalEvent*)data;
82 for (auto it = This->m_webInternalEventMap.begin(); it != This->m_webInternalEventMap.end(); ++it) {
83 WebInternalUserCBData* cbData = it->second;
84 if (cbData->m_event == type) {
85 cbData->m_callerCallback(cbData->m_data, it->first, eventInfo);
89 return ECORE_CALLBACK_PASS_ON;
92 #else // SUPPORT_MULTIPLE_REQUEST
94 WebInternalEvent::~WebInternalEvent()
98 void WebInternalEvent::addListner(webInternalEventType type, Ecore_Event_Handler_Cb cbFunc, void *data)
100 if (WEB_APP_TERMINATE == type) {
101 m_backEvent = ecore_event_type_new();
102 m_customEventHandler = ecore_event_handler_add(m_backEvent, eventTriggeredCallback, this);
104 m_callerCallback = cbFunc;
108 void WebInternalEvent::deleteListner(webInternalEventType type)
113 void WebInternalEvent::sendEvent(webInternalEventType type, void *eventInfo)
115 if (WEB_APP_TERMINATE == type) {
116 ecore_event_add(m_backEvent, eventInfo, NULL, NULL);
120 Eina_Bool WebInternalEvent::eventTriggeredCallback(void *data, int type, void *eventInfo)
122 WebInternalEvent* This = (WebInternalEvent*)data;
123 if (This->m_backEvent == type) {
124 Ecore_Event_Handler_Cb cb = This->m_callerCallback;
125 cb(This->m_callerData, WEB_APP_TERMINATE, eventInfo);
127 return ECORE_CALLBACK_PASS_ON;
129 #endif // SUPPORT_MULTIPLE_REQUEST