2feb9f6ee7796baf13f1aa78c3e69e34e84b1e98
[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         // get the current application id from WRT
72         void setCurrentAppId(std::string appId);
73         std::string getCurrentAppId() const;
74
75 private:
76
77         static bool app_callback(package_info_app_component_type_e comp_type, const char *app_id, void *user_data);
78         void appListChangedCallback(app_manger_event_type_e event_type, const char *pkgId, void *user_data);
79         static int app_list_changed_cb_broker(int id, const char *type, const char *package, const char *key, const char *val, const void *msg, void *data);
80
81         void appListAppInstalled(const char *appId);
82         void appListAppUninstalled(const char *appId);
83         void appListAppUpdated(const char *appId);
84
85         void registerAppListChangedCallbacks();
86         void unregisterAppListChangedCallbacks();
87
88         typedef std::set<IAppManagerAppListChangedCallbacks *> AppListChangedCallbacksSet;
89         AppListChangedCallbacksSet m_callbacks;
90         pkgmgr_client *m_manager_handle;
91         long m_watchIdAcc;
92         std::string m_curr_app_id;
93
94 public:
95         std::vector<std::string> applist;
96
97 public:
98         friend class DPL::Singleton<AppManagerWrapper>;
99 };
100
101 typedef DPL::Singleton<AppManagerWrapper> AppManagerWrapperSingleton;
102
103 } // Application
104 } // DeviceAPI
105
106 #endif // TIZENAPIS_PLATFORM_APPLICATION_APP_MANAGER_WRAPPER_H_