2 * Copyright (c) 2011 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.
18 #ifndef TIZENAPIS_PLATFORM_APPLICATION_H_
19 #define TIZENAPIS_PLATFORM_APPLICATION_H_
24 #include <Commons/Emitters.h>
25 #include <API/Application/IApplication.h>
26 #include <API/Application/ApplicationFactory.h>
27 #include <API/Application/EventListInstalledApplications.h>
28 #include <API/Application/EventGetApplication.h>
29 #include <API/Application/EventManageApplication.h>
30 #include <API/Application/EventInstalledApplicationChanged.h>
31 #include <API/Application/EventLaunchService.h>
33 //#include <app_manager.h>
34 #include <app_service.h>
36 #include "AppManagerWrapper.h"
38 using namespace TizenApis::Api::Application;
42 namespace Application {
44 class Application: public IApplication, public IAppManagerAppListChangedCallbacks {
45 friend class ApplicationFactory;
49 virtual ~Application();
50 virtual void launch(const EventManageApplicationPtr& event);
51 virtual void kill(const EventManageApplicationPtr& event);
52 virtual void listApplications(const EventListInstalledApplicationsPtr& event);
53 virtual void getApplication(const EventGetApplicationPtr& event);
54 virtual long addApplicationInformationEventListener(const EventInstalledApplicationChangedEmitterPtr& emitter);
55 virtual void removeApplicationInformationEventListener(const long watchId);
56 virtual void launchService(const EventLaunchServicePtr& event);
57 virtual void getApplicationService(const EventLaunchServicePtr& event);
58 virtual void install(const EventApplicationInstallPtr& event);
59 virtual void uninstall(const EventApplicationInstallPtr& event);
60 virtual void update(const EventApplicationInstallPtr& event);
62 void launchServiceManualAnswer(service_h request, service_h reply, service_result_e result,
63 Api::Application::EventLaunchServicePtr &event);
64 //void InstalledApplicationChanged(app_manger_event_type_e event_type,const char *package);
65 void callKillEventCallback(int pid);
66 void installAppAnswer(int req_id,
73 Api::Application::EventApplicationInstallPtr &event);
76 virtual void OnRequestReceived(const EventListInstalledApplicationsPtr& event);
77 virtual void OnRequestReceived(const EventManageApplicationPtr& event);
78 virtual void OnRequestReceived(const EventGetApplicationPtr& event);
79 virtual void OnRequestReceived(const EventLaunchServicePtr& event);
80 virtual void OnRequestReceived(const EventApplicationInstallPtr& event);
82 // inherited from IAppManagerAppListChangedCallbacks
83 virtual void onAppManagerEventInstalled(AppManagerPackageInfoPtr &pkgInfo);
84 virtual void onAppManagerEventUninstalled(AppManagerPackageInfoPtr &pkgInfo);
85 virtual void onAppManagerEventUpdated(AppManagerPackageInfoPtr &pkgInfo);
89 EventManageApplicationPtr getKillEvent(int pid);
91 DPL::Mutex m_initializationMutex;
94 std::map<int, EventManageApplicationPtr> m_killEventMap;
95 mutable DPL::Mutex m_killMapLock;
97 typedef WrtDeviceApis::Commons::Emitters<TizenApis::Api::Application::EventInstalledApplicationChangedEmitter> EventInstalledApplicationChangedEmitters;
98 typedef std::map<long, TizenApis::Api::Application::EventInstalledApplicationChangedEmitter::IdType> WatchIdMap;
100 EventInstalledApplicationChangedEmitters m_installedApplicationsEmitters;
101 WatchIdMap m_watchIdMap;
104 class LaunchServicePendingEvent
107 LaunchServicePendingEvent(void *thisObject, const Api::Application::EventLaunchServicePtr &event) :
108 m_thisObject(thisObject),
113 virtual ~LaunchServicePendingEvent()
117 void* getThisObject() const { return m_thisObject; }
118 Api::Application::EventLaunchServicePtr getEvent() const { return m_event; }
122 Api::Application::EventLaunchServicePtr m_event;
125 class ApplicationInstallPendingEvent
128 ApplicationInstallPendingEvent(void *thisObject, const Api::Application::EventApplicationInstallPtr &event) :
129 m_thisObject(thisObject),
134 virtual ~ApplicationInstallPendingEvent()
138 void* getThisObject() const { return m_thisObject; }
139 Api::Application::EventApplicationInstallPtr getEvent() const { return m_event; }
143 Api::Application::EventApplicationInstallPtr m_event;
146 template <class KeyType, class DataType>
150 typedef unsigned int DataKeyType;
151 typedef DataType * DataPtrType;
152 typedef std::pair<KeyType, DataPtrType> KeyDataPairType;
153 typedef std::map<DataKeyType, KeyDataPairType> DataMapType;
154 typedef std::set<DataKeyType> DataKeySetType;
155 typedef std::map<KeyType, DataKeySetType> KeyMapType;
156 typedef std::list<DataPtrType> DataPtrListType;
163 DataKeyType insert(const KeyType &key, const DataPtrType &dataPtr)
165 DataKeyType dataKey = ++m_keyAcc;
167 KeyDataPairType pair(key, dataPtr);
168 m_dataMap.insert(std::pair<DataKeyType, KeyDataPairType>(dataKey, pair));
170 typename KeyMapType::iterator keyMapIter = m_keyMap.find(key);
171 if(keyMapIter == m_keyMap.end())
173 DataKeySetType newKeySet;
174 m_keyMap.insert(std::pair<KeyType, DataKeySetType>(key, newKeySet));
175 keyMapIter = m_keyMap.find(key);
178 DataKeySetType &dataKeySet = keyMapIter->second;
180 dataKeySet.insert(dataKey);
185 DataPtrType getData(const DataKeyType &dataKey) const
187 typename DataMapType::const_iterator dataMapIter = m_dataMap.find(dataKey);
189 if(dataMapIter == m_dataMap.end())
190 return static_cast<DataPtrType>(NULL);
192 return dataMapIter->second.second;
195 DataPtrListType getDataPtrList(const KeyType &key)
197 DataPtrListType dataPtrList;
199 typename KeyMapType::const_iterator keyMapIter = m_keyMap.find(key);
200 if(keyMapIter == m_keyMap.end())
203 DataKeySetType keySet = keyMapIter->second;
204 DataKeySetType::iterator keySetIter = keySet.begin();
205 for(; keySetIter != keySet.end(); keySetIter++)
207 DataPtrType dataPtr = getData(*keySetIter);
210 LogWarning("No data for " << *keySetIter);
214 dataPtrList.push_back(dataPtr);
220 void eraseData(const DataKeyType &dataKey)
222 typename DataMapType::iterator dataKeyIter = m_dataMap.find(dataKey);
224 if(dataKeyIter == m_dataMap.end())
226 LogDebug("No data for " << dataKey);
230 KeyType key = dataKeyIter->second.first;
232 m_dataMap.erase(dataKeyIter);
234 typename KeyMapType::iterator keyMapIter = m_keyMap.find(key);
235 if(keyMapIter == m_keyMap.end())
237 LogWarning("No data for Key");
241 DataKeySetType &keySet = keyMapIter->second;
242 DataKeySetType::iterator keySetIter = keySet.find(dataKey);
243 if(keySetIter == keySet.end())
245 LogWarning("No data for " << dataKey);
249 keySet.erase(keySetIter);
252 void eraseKey(const KeyType &key)
254 typename KeyMapType::iterator keyMapIter = m_keyMap.find(key);
255 if(keyMapIter == m_keyMap.end())
257 LogDebug("No data to erase.");
261 DataKeySetType &keySet = keyMapIter->second;
262 DataKeySetType::iterator keySetIter = keySet.begin();
263 for(; keySetIter != keySet.end(); keySetIter++)
265 typename DataMapType::iterator dataKeyIter = m_dataMap.find(*keySetIter);
266 if(dataKeyIter == m_dataMap.end())
268 LogWarning("No data to erase.");
272 m_dataMap.erase(dataKeyIter);
275 m_keyMap.erase(keyMapIter);
279 DataKeyType m_keyAcc;
281 DataMapType m_dataMap;