1 /* 2 * Copyright (C) 2024 The Android Open Source Project 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 17 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_NEARBY_TIMER_H_ 18 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_NEARBY_TIMER_H_ 19 20 #include <cstdint> 21 22 #include "chre_api/chre.h" 23 24 namespace nearby { 25 26 class Timer { 27 public: 28 // Constructs timer. Timer(bool is_one_shot)29 explicit Timer(bool is_one_shot) : is_one_shot_(is_one_shot) {} 30 31 // Sets timer duration in milliseconds. SetDurationMs(uint32_t duration_ms)32 void SetDurationMs(uint32_t duration_ms) { 33 duration_ms_ = duration_ms; 34 } 35 36 // Starts timer. 37 bool StartTimer(); 38 39 // Stops timer. 40 bool StopTimer(); 41 42 // Returns timer id. GetTimerId()43 const uint32_t *GetTimerId() { 44 return &timer_id_; 45 } 46 47 private: 48 uint32_t timer_id_ = CHRE_TIMER_INVALID; 49 uint32_t duration_ms_ = 0; 50 bool is_one_shot_; 51 }; 52 53 } // namespace nearby 54 55 #endif // LOCATION_LBS_CONTEXTHUB_NANOAPPS_NEARBY_TIMER_H_ 56