[PROJECT][C++] Reformatting the whole project
[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 <bundle.h>
22 #include <package-manager.h>
23 #include <pkgmgr-info.h>
24 #include <functional>
25 #include <memory>
26 #include <string>
27
28 #include "common/picojson.h"
29 #include "common/platform_result.h"
30
31 typedef std::function<void(picojson::value*)> JsonCallback;
32
33 namespace extension {
34 namespace application {
35
36 class ApplicationInstance;
37
38 class ApplicationManager {
39  public:
40   explicit ApplicationManager(ApplicationInstance& instance);
41   ~ApplicationManager();
42
43   void GetCurrentApplication(const std::string& app_id, picojson::object* out);
44   void Kill(const picojson::value& args);
45   void Launch(const picojson::value& args);
46   void LaunchAppControl(const picojson::value& args);
47   void FindAppControl(const picojson::value& args);
48   void GetAppsContext(const picojson::value& args);
49   void GetAppContext(const picojson::value& args, picojson::object* out);
50   void GetAppsInfo(const picojson::value& args);
51   void GetAppInfo(const std::string& app_id, picojson::object* out);
52   void GetAppCerts(const std::string& app_id, picojson::object* out);
53   void GetAppSharedUri(const std::string& app_id, picojson::object* out);
54   void GetAppMetaData(const std::string& app_id, picojson::object* out);
55   void StartAppInfoEventListener(picojson::object* out);
56   void StopAppInfoEventListener();
57   void GetApplicationInformationSize(const picojson::value& args, picojson::object* out);
58   void AsyncResponse(common::PlatformResult& result, std::shared_ptr<picojson::value>* response);
59
60   void BroadcastEventHelper(const picojson::value& args, picojson::object& out, bool trusted);
61   common::PlatformResult StartEventListener(const std::string& event_name,
62                                             const JsonCallback& callback);
63   void StopEventListener(const std::string& event_name);
64
65  private:
66   char* GetPackageId(const std::string& app_id);
67
68   pkgmgr_client* pkgmgr_client_handle_;
69   pkgmgr_client* pkgmgr_client_uninstall_handle_;
70   ApplicationInstance& instance_;
71
72   JsonCallback event_callback_;
73   std::map<std::string, event_handler_h> event_handler_map_;
74   static void OnEvent(const char* event_name, bundle* event_data, void* user_data);
75 };
76
77 }  // namespace application
78 }  // namespace extension
79
80 #endif  // SRC_APPLICATION_APPLICATION_MANAGER_H__