/* * Copyright (c) 2018 Panasonic Corporation * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ACTIVITY_MANAGER_HPP #define ACTIVITY_MANAGER_HPP #include extern "C" { #include } namespace lcm { #define LCM_EVENT_STATUS_CHANGED "statusChanged" #define LCM_API_GET_ACTIVITY_STATUS "getActivityStatus" #define LCM_API "api" #define LCM_TARGET "target" #define LCM_STATE "state" enum activity_status { NOTEXISTS, CREATED, // after ON_CREATE DESTROYED,// after ON_DESTROY STARTED, // after ON_START, ON_RESTART STOPPED, // after ON_STOP FOREGROUND, // after ON_FOREGROUND BACKGROUND, // after ON_BACKGROUND NUM_STATUS, }; #define ACTIVITY_FILTER_ALL_SET "111111" // For demo, always notify all states struct _observer_context { afb_event_t event; // onStatusChanged std::bitset filter; // not supported yet }; using observer = struct _observer_context; class ActivityManager { public: explicit ActivityManager(); ~ActivityManager() = default; void api_register_activity_observer (afb_req_t req, void* &obs_ctx); void api_unregister_activity_observer (afb_req_t req, void* &obs_ctx); wm::result api_get_activity_status(const char *appid); void emit_activity_status_changed(const char* appid, const char* state); void lcm_clear_context (void* &lcm_ctx); // map of <"string:target $appid", "vector of registered observers"> std::map> map_observers; // map of <"id:target", "current_state"> std::map states; const char *states_s[NUM_STATUS]; private: void remove_observer (observer* obs, std::vector& obs_v); }; } // namespace lcm #endif /* ACTIVITY_MANAGER_HPP */