2 * Copyright (c) 2018 Panasonic Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef ACTIVITY_MANAGER_HPP
17 #define ACTIVITY_MANAGER_HPP
23 #include <afb/afb-binding.h>
29 #define LCM_EVENT_STATUS_CHANGED "statusChanged"
30 #define LCM_API_GET_ACTIVITY_STATUS "getActivityStatus"
32 #define LCM_TARGET "target"
33 #define LCM_STATE "state"
39 CREATED, // after ON_CREATE
40 DESTROYED,// after ON_DESTROY
42 STARTED, // after ON_START, ON_RESTART
43 STOPPED, // after ON_STOP
45 FOREGROUND, // after ON_FOREGROUND
46 BACKGROUND, // after ON_BACKGROUND
51 #define ACTIVITY_FILTER_ALL_SET "111111" // For demo, always notify all states
53 struct _observer_context {
54 afb_event_t event; // onStatusChanged
55 std::bitset<NUM_STATUS> filter; // not supported yet
58 using observer = struct _observer_context;
63 explicit ActivityManager();
64 ~ActivityManager() = default;
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);
70 void emit_activity_status_changed(const char* appid, const char* state);
71 void lcm_clear_context (void* &lcm_ctx);
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;
78 const char *states_s[NUM_STATUS];
81 void remove_observer (observer* obs, std::vector<observer*>& obs_v);
85 #endif /* ACTIVITY_MANAGER_HPP */