1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef POWERMGR_POWER_MGR_TIMER_UTIL_H 16 #define POWERMGR_POWER_MGR_TIMER_UTIL_H 17 18 #include <stdint.h> 19 20 #include <ohos_types.h> 21 #include <time.h> 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif // __cplusplus 26 27 typedef timer_t PowerTimer; 28 typedef void (*PowerTimerCallback)(void *privateData); 29 30 /* 31 * Create timer. Must call PowerMgrDestroyTimer to release memory after timer is not needed 32 */ 33 PowerTimer *PowerMgrCreateTimer(int64_t whenMsec, int64_t intervalMsec, PowerTimerCallback cb); 34 35 /* 36 * Reset timer attributes and stop timer 37 */ 38 BOOL PowerMgrResetTimer(PowerTimer *timer, int64_t whenMsec, int64_t intervalMsec); 39 40 /* 41 * Start timer. The privateData will set to PowerTimerCallback function when timer timeout 42 */ 43 BOOL PowerMgrStartTimer(PowerTimer *timer, void *privateData); 44 45 /* 46 * Restart timer. The privateData will set to PowerTimerCallback function when timer timeout 47 */ 48 BOOL PowerMgrRestartTimer(PowerTimer *timer, void *privateData); 49 50 /* 51 * Stop timer 52 */ 53 BOOL PowerMgrStopTimer(PowerTimer *timer); 54 55 /* 56 * Destory timer 57 */ 58 void PowerMgrDestroyTimer(PowerTimer *timer); 59 60 #ifdef __cplusplus 61 } 62 #endif // __cplusplus 63 #endif // POWERMGR_POWER_MGR_TIMER_UTIL_H 64