Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / FUi_UiBuilderControlTable.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://floralicense.org/license/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19 * @file         FUi_UiBuilderControlTable.cpp
20 * @brief                This is the implementation file for _UiBuilderControlTable class.
21 */
22
23 #include <string.h>
24 #include <stdlib.h>
25 #include <FIo.h>
26 #include <FUiIOrientationEventListener.h>
27 #include <FBaseSysLog.h>
28 #include "FUi_UiBuilderControlTable.h"
29 #include "FUi_UiBuilder.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Ui;
34
35 namespace Tizen { namespace Ui
36 {
37 _UiBuilderControlTable::_UiBuilderControlTable(void)
38         : __pUiBuilderControlTableInFomationList(null)
39 {
40         if (__pUiBuilderControlTableInFomationList == null)
41         {
42                 __pUiBuilderControlTableInFomationList = new (std::nothrow) ArrayListT<_UiBuilderControlTableInFomation*>;
43         }
44 }
45
46 _UiBuilderControlTable::~_UiBuilderControlTable(void)
47 {
48         if (__pUiBuilderControlTableInFomationList)
49         {
50                 _UiBuilderControlTableInFomation* pUiBuilderControlTableInFomation = null;
51                 int controlCount = __pUiBuilderControlTableInFomationList->GetCount();
52                 for (int i = 0; i < controlCount; i++)
53                 {
54                         __pUiBuilderControlTableInFomationList->GetAt(i, pUiBuilderControlTableInFomation);
55                         delete pUiBuilderControlTableInFomation;
56                 }
57                 __pUiBuilderControlTableInFomationList->RemoveAll();
58                 delete __pUiBuilderControlTableInFomationList;
59                 __pUiBuilderControlTableInFomationList = null;
60         }
61 }
62
63 _UiBuilderControlTableManager::_UiBuilderControlTableManager(void)
64 : __pControlTable(null)
65 {
66
67 }
68
69 _UiBuilderControlTableManager::~_UiBuilderControlTableManager(void)
70 {
71
72 }
73
74 result
75 _UiBuilderControlTableManager::Construct(void)
76 {
77         if (__pControlTable == null)
78         {
79                 __pControlTable = new (std::nothrow)  _UiBuilderControlTable;
80                 SysTryReturn(NID_UI, __pControlTable != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _UiBuilderControlTable.");
81         }
82
83         return E_SUCCESS;
84 }
85
86 _UiBuilderControlTableManager*
87 _UiBuilderControlTableManager::GetInstance()
88 {
89         result r = E_SUCCESS;
90         static _UiBuilderControlTableManager* pUiBuilderControlTable = null;
91
92         if (pUiBuilderControlTable == null)
93         {
94                 pUiBuilderControlTable = new (std::nothrow) _UiBuilderControlTableManager;
95                 SysTryReturn(NID_UI, pUiBuilderControlTable != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to create _pUiBuilder.");
96
97                 r = pUiBuilderControlTable->Construct();
98                 SysTryReturn(NID_UI, r == E_SUCCESS, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Unable to construct _pUiBuilder.");
99         }
100
101         return pUiBuilderControlTable;
102 }
103 _UiBuilderControlTable*
104 _UiBuilderControlTableManager::GetControlTable() const
105 {
106         return __pControlTable;
107 }
108
109 void
110 _UiBuilderControlTableManager::RegisterControl(const Tizen::Base::String& controlMakerName, _UiBuilderControlMakerFunctionPointer pControlMakerFunctionPointer)
111 {
112         _UiBuilderControlTableManager* pUiBuilderControlTableManager = GetInstance();
113         _UiBuilderControlTable* pUiBuilderControlTable = null;
114         if(pUiBuilderControlTableManager != null && pControlMakerFunctionPointer != null)
115         {
116                 pUiBuilderControlTable = pUiBuilderControlTableManager->GetControlTable();
117         }
118         else
119         {
120                 return;
121         }
122
123         _UiBuilderControlTableInFomation* pUiBuilderControlTableInFomation = null;
124         pUiBuilderControlTableInFomation = new (std::nothrow) _UiBuilderControlTableInFomation;
125         if (pUiBuilderControlTableInFomation != null)
126         {
127                 pUiBuilderControlTableInFomation->__controlMakerName =  controlMakerName;
128                 pUiBuilderControlTableInFomation->__pContolMakerFunctionPointer = pControlMakerFunctionPointer;
129                 pUiBuilderControlTable->__pUiBuilderControlTableInFomationList->Add(pUiBuilderControlTableInFomation);
130         }
131         else
132         {
133                 SysLogException(NID_UI, E_OUT_OF_MEMORY, "[kongp]Failed to CreateControl()");
134         }
135
136         SysLog(NID_UI, "[UiBuilder]Register success [%ls]", pUiBuilderControlTableInFomation->__controlMakerName.GetPointer());
137 }
138
139 void
140 _UiBuilderControlTableManager::UnregisterControl(const Tizen::Base::String& controlMakerName)
141 {
142         _UiBuilderControlTableManager* pUiBuilderControlTableManager = GetInstance();
143         _UiBuilderControlTable* pUiBuilderControlTable = null;
144         if(controlMakerName.IsEmpty() == false)
145         {
146                 pUiBuilderControlTable = pUiBuilderControlTableManager->GetControlTable();
147         }
148         else
149         {
150                 return;
151         }
152
153         IEnumeratorT<_UiBuilderControlTableInFomation*>* pEnum = pUiBuilderControlTable->__pUiBuilderControlTableInFomationList->GetEnumeratorN();
154         _UiBuilderControlTableInFomation* pUiBuilderControlTableInFomation = null;
155
156         while (pEnum->MoveNext() == E_SUCCESS)
157         {
158                 pEnum->GetCurrent(pUiBuilderControlTableInFomation);
159                 if (pUiBuilderControlTableInFomation->__controlMakerName.Equals(controlMakerName, false))
160                 {
161                         pUiBuilderControlTableInFomation->__pContolMakerFunctionPointer = null;
162                         break;
163                 }
164         }
165         delete pEnum;
166
167 }
168
169 String
170 _UiBuilderControlTableManager::GetName(int index) const
171 {
172         _UiBuilderControlTableManager* pUiBuilderControlTableManager = GetInstance();
173         SysTryReturn(NID_UI, pUiBuilderControlTableManager != null, null, E_SYSTEM,
174                                         "[E_SYSTEM] IUnable to get the UiBuilderControlTableManager");
175
176         _UiBuilderControlTable* pUiBuilderControlTable = pUiBuilderControlTableManager->GetControlTable();
177
178         _UiBuilderControlTableInFomation* pUiBuilderControlTableInFomation = null;
179         pUiBuilderControlTable->__pUiBuilderControlTableInFomationList->GetAt(index, pUiBuilderControlTableInFomation);
180         SysTryReturn(NID_UI, pUiBuilderControlTableInFomation != null, L"", GetLastResult(), "Failed to GetControl()");
181
182         return (const Tizen::Base::String) pUiBuilderControlTableInFomation->__controlMakerName;
183 }
184
185 _UiBuilderControlMakerFunctionPointer
186 _UiBuilderControlTableManager::GetControlMaker(int index) const
187 {
188
189         _UiBuilderControlTableManager* pUiBuilderControlTableManager = GetInstance();
190         SysTryReturn(NID_UI, pUiBuilderControlTableManager != null, null, E_SYSTEM,
191                                         "[E_SYSTEM] IUnable to get the UiBuilderControlTableManager");
192
193         _UiBuilderControlTable* pUiBuilderControlTable = pUiBuilderControlTableManager->GetControlTable();
194         _UiBuilderControlTableInFomation* pUiBuilderControlTableInFomation = null;
195         pUiBuilderControlTable->__pUiBuilderControlTableInFomationList->GetAt(index, pUiBuilderControlTableInFomation);
196         SysTryReturn(NID_UI, pUiBuilderControlTableInFomation != null, null, GetLastResult(), "Failed to GetControl()");
197
198         return pUiBuilderControlTableInFomation->__pContolMakerFunctionPointer;
199 }
200
201 } }  // Tizen::Ui