066300396795e9e92f4370f21c4189766ad58588
[apps/agl-service-windowmanager.git] / src / activity_manager.hpp
1 /*
2  * Copyright (c) 2018 Panasonic Corporation
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 #ifndef ACTIVITY_MANAGER_HPP
17 #define ACTIVITY_MANAGER_HPP
18
19 #include <bitset>
20
21 extern "C"
22 {
23 #include <afb/afb-binding.h>
24 }
25
26 namespace lcm
27 {
28
29 #define LCM_EVENT_STATUS_CHANGED "statusChanged"
30 #define LCM_API_GET_ACTIVITY_STATUS "getActivityStatus"
31 #define LCM_API    "api"
32 #define LCM_TARGET "target"
33 #define LCM_STATE  "state"
34
35 enum activity_status
36 {
37   NOTEXISTS,
38
39   CREATED,  // after ON_CREATE
40   DESTROYED,// after ON_DESTROY
41
42   STARTED,  // after ON_START, ON_RESTART
43   STOPPED,  // after ON_STOP
44
45   FOREGROUND,  // after ON_FOREGROUND
46   BACKGROUND,  // after ON_BACKGROUND
47
48   NUM_STATUS,
49 };
50
51 #define ACTIVITY_FILTER_ALL_SET "111111"  // For demo, always notify all states
52
53 struct _observer_context {
54   afb_event_t event;  // onStatusChanged
55   std::bitset<NUM_STATUS> filter; // not supported yet
56 };
57
58 using observer = struct _observer_context;
59
60 // map of <"id:appid", "context of observer">
61 using observers = std::map<std::string, observer>;
62
63 class ActivityManager
64 {
65  public:
66   explicit ActivityManager();
67   ~ActivityManager() = default;
68
69   void api_register_activity_observer (afb_req_t req);
70   void api_unregister_activity_observer (afb_req_t req);
71   wm::result<json_object *> api_get_activity_status(const char *appid);
72
73  public:
74   void emit_activity_status_changed(const char* appid, const char* state);
75
76   // map of <"id:target", "registered observers">
77   std::map<std::string, observers> map_observers;
78   // map of <"id:target", "current_state">
79   std::map<std::string, int> states;
80
81   const char *states_s[NUM_STATUS];
82 };
83
84 } // namespace lcm
85 #endif /* ACTIVITY_MANAGER_HPP */