Update change log and spec for wrt-plugins-tizen_0.4.20
[platform/framework/web/wrt-plugins-tizen.git] / src / Application / AppManagerWrapper.h
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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 #ifndef TIZENAPIS_PLATFORM_APPLICATION_APP_MANAGER_WRAPPER_H_
19 #define TIZENAPIS_PLATFORM_APPLICATION_APP_MANAGER_WRAPPER_H_
20
21 #include <string>
22 #include <map>
23 #include <set>
24 #include <dpl/shared_ptr.h>
25 #include <dpl/singleton.h>
26
27 #include <app_manager.h>
28 #include <package-manager.h>
29 #include <package_manager.h>
30 #include <package_info.h>
31
32 #include "ApplicationInformation.h"
33
34 // To get app size and installed time
35 #include <pkgmgr-info.h>
36
37 namespace DeviceAPI {
38 namespace Application {
39
40
41 class IAppManagerAppListChangedCallbacks
42 {
43 public:
44     friend class AppManagerWrapper;
45
46         IAppManagerAppListChangedCallbacks() {}
47         ~IAppManagerAppListChangedCallbacks() {}
48
49 protected:
50         virtual void onAppManagerEventInstalled(const char *appId) = 0;
51         virtual void onAppManagerEventUninstalled(const char *appId) = 0;
52         virtual void onAppManagerEventUpdated(const char *appId) = 0;
53 };
54
55 class AppManagerWrapper
56 {
57 public:
58         AppManagerWrapper();
59         virtual ~AppManagerWrapper();
60
61         // Can throw InvalidArgumentException or PlatformException
62         void registerAppListChangedCallbacks(IAppManagerAppListChangedCallbacks *callbacks);
63
64         // No throws
65         void unregisterAppListChangedCallbacks(IAppManagerAppListChangedCallbacks *callbacks);
66
67         long getWatchIdAndInc();
68
69         bool initializeAppInfo(ApplicationInformationPtr &appInfo);
70
71 private:
72
73         static bool app_callback(package_info_app_component_type_e comp_type, const char *app_id, void *user_data);
74
75         // callback for app_manager_set_app_list_changed_cb
76         static void appListChangedCallback(app_manger_event_type_e event_type,
77                                            const char *package,
78                                            void *user_data);
79
80         void appListChangedCallback(app_manger_event_type_e event_type,
81                                     const char *package);
82
83         void appListAppInstalled(const char *appId);
84         void appListAppUninstalled(const char *appId);
85         void appListAppUpdated(const char *appId);
86
87         void registerAppListChangedCallbacks();
88         void unregisterAppListChangedCallbacks();
89
90         typedef std::set<IAppManagerAppListChangedCallbacks *> AppListChangedCallbacksSet;
91         AppListChangedCallbacksSet m_callbacks;
92         bool m_registeredCallback;
93
94         long m_watchIdAcc;
95
96 public:
97         friend class DPL::Singleton<AppManagerWrapper>;
98 };
99
100 typedef DPL::Singleton<AppManagerWrapper> AppManagerWrapperSingleton;
101
102 } // Application
103 } // DeviceAPI
104
105 #endif // TIZENAPIS_PLATFORM_APPLICATION_APP_MANAGER_WRAPPER_H_