The license change version 1.0 to version 1.1
[platform/framework/web/web-provider.git] / src / Plugin / AppBoxPlugin / AppBoxObserver.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://floralicense.org/license/
9  *
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.
15  */
16 /**
17  * @file    AppBoxObserver.cpp
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  */
20
21 #include <string>
22 #include <map>
23 #include <Core/Util/Log.h>
24 #include "AppBoxRenderView.h"
25 #include "AppBoxRenderBuffer.h"
26 #include "AppBoxObserver.h"
27
28
29 // static variable intialization
30 AppBoxObserver* AppBoxObserver::s_instance = NULL;
31
32 AppBoxObserver::AppBoxObserver()
33     : m_initialized(false)
34     , m_renderViewMap()
35     , m_renderBufferMap()
36 {
37     LogD("enter");
38 }
39
40 AppBoxObserver::~AppBoxObserver()
41 {
42     LogD("enter");
43 }
44
45 AppBoxObserver* AppBoxObserver::Instance()
46 {
47     LogD("enter");
48     if (!s_instance) {
49         s_instance = new AppBoxObserver();
50     }
51
52     return s_instance;
53 }
54
55 void AppBoxObserver::initialize()
56 {
57     LogD("enter");
58     if (m_initialized) {
59         LogD("already initialized");
60         return;
61     }
62
63     m_initialized = true;
64 }
65
66 void AppBoxObserver::shutdown()
67 {
68     LogD("enter");
69     if (!m_initialized) {
70         LogD("not yet initialized");
71         return;
72     }
73
74     m_initialized = false;
75 }
76
77 AppBoxRenderView* AppBoxObserver::getRenderView(std::string instanceId)
78 {
79     LogD("enter");
80
81     auto it = m_renderViewMap.find(instanceId);
82     if (it != m_renderViewMap.end()) {
83         LogD("registered: %s (%p)", it->first.c_str(), it->second);
84         return it->second;
85     }
86
87     return NULL;
88 }
89
90 void AppBoxObserver::registerRenderView(std::string instanceId, AppBoxRenderView* view)
91 {
92     LogD("enter");
93
94     if (getRenderView(instanceId)) {
95         LogD("already registered");
96         return;
97     }
98
99     m_renderViewMap.insert(RenderViewMapPair(instanceId, view));
100 }
101
102 void AppBoxObserver::unregisterRenderView(std::string instanceId)
103 {
104     LogD("enter");
105     m_renderViewMap.erase(instanceId);
106 }
107
108 AppBoxRenderBuffer* AppBoxObserver::getRenderBuffer(std::string instanceId)
109 {
110     LogD("enter");
111
112     auto it = m_renderBufferMap.find(instanceId);
113     if (it != m_renderBufferMap.end()) {
114         LogD("registered: %s (%p)", it->first.c_str(), it->second);
115         return it->second;
116     }
117
118     return NULL;
119 }
120
121 void AppBoxObserver::registerRenderBuffer(std::string instanceId, AppBoxRenderBuffer* buffer)
122 {
123     LogD("enter");
124
125     if (getRenderBuffer(instanceId)) {
126         LogD("already registered");
127         return;
128     }
129
130     m_renderBufferMap.insert(RenderBufferMapPair(instanceId, buffer));
131 }
132
133 void AppBoxObserver::unregisterRenderBuffer(std::string instanceId)
134 {
135     LogD("enter");
136     m_renderBufferMap.erase(instanceId);
137 }