2 * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
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.
17 #include "include/aul_watch_control.h"
25 #include "aul_watch_control_internal.h"
26 #include "include/aul.h"
32 WatchControl(aul_watch_control_cb cb, void* user_data)
33 : cb_(cb), user_data_(user_data) {
36 void Invoke(bundle* b) {
42 aul_watch_control_cb cb_;
46 std::list<WatchControl*> controls;
50 extern "C" API int aul_watch_control_add_handler(aul_watch_control_cb callback,
51 void* user_data, aul_watch_control_h* handle) {
52 if (callback == nullptr || handle == nullptr) {
53 _E("Invalid parameter");
57 auto* control = new (std::nothrow) WatchControl(callback, user_data);
58 if (control == nullptr) {
63 controls.push_back(control);
64 *handle = static_cast<aul_watch_control_h>(control);
68 extern "C" API int aul_watch_control_remove_handler(
69 aul_watch_control_h handle) {
70 if (handle == nullptr) {
71 _E("Invalid parameter");
75 auto* control = static_cast<WatchControl*>(handle);
76 auto found = std::find(controls.begin(), controls.end(), control);
77 if (found == controls.end()) {
78 _E("Invalid parameter");
82 controls.erase(found);
87 void aul_watch_control_invoke(bundle* b) {
91 for (auto control : controls)