Merge branch 'tizen_4.0' into tizen_5.0
[platform/core/api/webapi-plugins.git] / src / application / application_manager.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
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 #ifndef SRC_APPLICATION_APPLICATION_MANAGER_H__
18 #define SRC_APPLICATION_APPLICATION_MANAGER_H__
19
20 #include <app_event.h>
21 #include <app_manager.h>
22 #include <bundle.h>
23 #include <package-manager.h>
24 #include <pkgmgr-info.h>
25 #include <functional>
26 #include <functional>
27 #include <memory>
28 #include <string>
29 #if defined(TIZEN_MOBILE)
30 #include <context-service/context_history.h>
31 #elif defined(TIZEN_WEARABLE)
32 #include <context-service/wearable/context_history.h>
33 #endif
34
35 #include "common/picojson.h"
36 #include "common/platform_result.h"
37
38 typedef std::function<void(picojson::value*)> JsonCallback;
39
40 namespace extension {
41 namespace application {
42
43 class ApplicationInstance;
44
45 class ApplicationManager {
46  public:
47   explicit ApplicationManager(ApplicationInstance& instance);
48   ~ApplicationManager();
49
50   void GetCurrentApplication(const std::string& app_id, picojson::object* out);
51   void Kill(const picojson::value& args);
52   void Launch(const picojson::value& args);
53   void LaunchAppControl(const picojson::value& args);
54   void FindAppControl(const picojson::value& args);
55   void GetAppsContext(const picojson::value& args);
56   void GetAppContext(const picojson::value& args, picojson::object* out);
57   void GetAppsInfo(const picojson::value& args);
58   void GetAppInfo(const std::string& app_id, picojson::object* out);
59   void GetAppCerts(const std::string& app_id, picojson::object* out);
60   void GetAppSharedUri(const std::string& app_id, picojson::object* out);
61   void GetAppMetaData(const std::string& app_id, picojson::object* out);
62   void GetBatteryUsageInfo(const picojson::value& args, picojson::object* out);
63   void GetAppsUsageInfo(const picojson::value& args, picojson::object* out);
64   void StartAppInfoEventListener(picojson::object* out);
65   void StopAppInfoEventListener();
66   void GetApplicationInformationSize(const picojson::value& args, picojson::object* out);
67   void AsyncResponse(const common::PlatformResult& result,
68                      std::shared_ptr<picojson::value>* response);
69
70   void BroadcastEventHelper(const picojson::value& args, picojson::object& out, bool trusted);
71   common::PlatformResult StartEventListener(const std::string& event_name,
72                                             const JsonCallback& callback);
73   void StopEventListener(const std::string& event_name);
74   common::PlatformResult StartStatusListener(const JsonCallback& callback);
75   common::PlatformResult StopStatusChangeListener();
76
77  private:
78   char* GetPackageId(const std::string& app_id);
79
80   pkgmgr_client* pkgmgr_client_handle_;
81   pkgmgr_client* pkgmgr_client_uninstall_handle_;
82   ApplicationInstance& instance_;
83   app_manager_event_h app_status_handle_;
84
85   JsonCallback event_callback_;
86   JsonCallback status_callback_;
87   std::map<std::string, event_handler_h> event_handler_map_;
88   static void OnEvent(const char* event_name, bundle* event_data, void* user_data);
89   static void OnStatusEvent(const char* type, const char* app_id,
90                             app_manager_event_type_e event_type,
91                             app_manager_event_state_e event_state, app_manager_event_h handle,
92                             void* user_data);
93
94 #if defined(TIZEN_MOBILE) || defined(TIZEN_WEARABLE)
95   static common::PlatformResult GetContextHistory(
96       const picojson::value& args, picojson::object* out,
97       common::PlatformResult (*)(const picojson::value&, const context_history_filter_h,
98                                  context_history_data_e* data_type),
99       common::PlatformResult (*)(const context_history_record_h, picojson::object*));
100
101   static common::PlatformResult BatteryUsageFilter(const picojson::value&,
102                                                    const context_history_filter_h,
103                                                    context_history_data_e* data_type);
104   static common::PlatformResult BatteryUsageAttributes(const context_history_record_h,
105                                                        picojson::object*);
106
107   static common::PlatformResult AppsUsageFilter(const picojson::value&,
108                                                 const context_history_filter_h,
109                                                 context_history_data_e* data_type);
110   static common::PlatformResult AppsUsageAttributes(const context_history_record_h,
111                                                     picojson::object*);
112 #endif
113 };
114
115 }  // namespace application
116 }  // namespace extension
117
118 #endif  // SRC_APPLICATION_APPLICATION_MANAGER_H__