POI: AGL LifeCycle Management
[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 class ActivityManager
61 {
62  public:
63   explicit ActivityManager();
64   ~ActivityManager() = default;
65
66   void api_register_activity_observer (afb_req_t req, void* &obs_ctx);
67   void api_unregister_activity_observer (afb_req_t req, void* &obs_ctx);
68   wm::result<json_object *> api_get_activity_status(const char *appid);
69
70   void emit_activity_status_changed(const char* appid, const char* state);
71   void lcm_clear_context (void* &lcm_ctx);
72
73   // map of <"string:target $appid", "vector of registered observers">
74   std::map<std::string, std::vector<observer*>> map_observers;
75   // map of <"id:target", "current_state">
76   std::map<std::string, int> states;
77
78   const char *states_s[NUM_STATUS];
79
80  private:
81   void remove_observer (observer* obs, std::vector<observer*>& obs_v);
82 };
83
84 } // namespace lcm
85 #endif /* ACTIVITY_MANAGER_HPP */