Merge "[Systeminfo] Implementation for remaining time to charge/discharge battery...
[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 <functional>
24 #include <memory>
25 #include <package-manager.h>
26 #include <string>
27 #include <pkgmgr-info.h>
28
29 #include "common/picojson.h"
30 #include "common/platform_result.h"
31
32 typedef std::function<void(picojson::value*)> JsonCallback;
33
34 namespace extension {
35 namespace application {
36
37 class ApplicationInstance;
38
39 class ApplicationManager {
40  public:
41   explicit ApplicationManager(ApplicationInstance& instance);
42   ~ApplicationManager();
43
44   void GetCurrentApplication(const std::string& app_id, picojson::object* out);
45   void Kill(const picojson::value& args);
46   void Launch(const picojson::value& args);
47   void LaunchAppControl(const picojson::value& args);
48   void FindAppControl(const picojson::value& args);
49   void GetAppsContext(const picojson::value& args);
50   void GetAppContext(const picojson::value& args, picojson::object* out);
51   void GetAppsInfo(const picojson::value& args);
52   void GetAppInfo(const std::string& app_id, picojson::object* out);
53   void GetAppCerts(const std::string& app_id, picojson::object* out);
54   void GetAppSharedUri(const std::string& app_id, picojson::object* out);
55   void GetAppMetaData(const std::string& app_id, picojson::object* out);
56   void GetBatteryUsageInfo(const picojson::value& args, picojson::object* out);
57   void StartAppInfoEventListener(picojson::object* out);
58   void StopAppInfoEventListener();
59   void GetApplicationInformationSize(const picojson::value& args, picojson::object* out);
60   void AsyncResponse(common::PlatformResult& result, std::shared_ptr<picojson::value>* response);
61
62   void BroadcastEventHelper(const picojson::value& args, picojson::object& out, bool trusted);
63   common::PlatformResult StartEventListener(const std::string& event_name,
64                                             const JsonCallback& callback);
65   void StopEventListener(const std::string& event_name);
66   common::PlatformResult StartStatusListener(const JsonCallback& callback);
67   common::PlatformResult StopStatusChangeListener();
68
69  private:
70   char* GetPackageId(const std::string& app_id);
71
72   pkgmgr_client* pkgmgr_client_handle_;
73   pkgmgr_client* pkgmgr_client_uninstall_handle_;
74   ApplicationInstance& instance_;
75   app_manager_event_h app_status_handle_;
76
77   JsonCallback event_callback_;
78   JsonCallback status_callback_;
79   std::map<std::string, event_handler_h> event_handler_map_;
80   static void OnEvent(const char* event_name,
81                       bundle* event_data,
82                       void* user_data);
83   static void OnStatusEvent(const char *type, const char *app_id,
84                             app_manager_event_type_e event_type,
85                             app_manager_event_state_e event_state,
86                             app_manager_event_h handle,
87                             void *user_data);
88 };
89
90 } // namespace application
91 } // namespace extension
92
93 #endif // SRC_APPLICATION_APPLICATION_MANAGER_H__