diff options
Diffstat (limited to 'src/activity_manager.hpp')
-rw-r--r-- | src/activity_manager.hpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/activity_manager.hpp b/src/activity_manager.hpp new file mode 100644 index 0000000..0663003 --- /dev/null +++ b/src/activity_manager.hpp @@ -0,0 +1,85 @@ +/* + * 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 <bitset> + +extern "C" +{ +#include <afb/afb-binding.h> +} + +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<NUM_STATUS> filter; // not supported yet +}; + +using observer = struct _observer_context; + +// map of <"id:appid", "context of observer"> +using observers = std::map<std::string, observer>; + +class ActivityManager +{ + public: + explicit ActivityManager(); + ~ActivityManager() = default; + + void api_register_activity_observer (afb_req_t req); + void api_unregister_activity_observer (afb_req_t req); + wm::result<json_object *> api_get_activity_status(const char *appid); + + public: + void emit_activity_status_changed(const char* appid, const char* state); + + // map of <"id:target", "registered observers"> + std::map<std::string, observers> map_observers; + // map of <"id:target", "current_state"> + std::map<std::string, int> states; + + const char *states_s[NUM_STATUS]; +}; + +} // namespace lcm +#endif /* ACTIVITY_MANAGER_HPP */ |