• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef TIMER_H
17 #define TIMER_H
18 #include <string>
19 #include <errno.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <cstdio>
24 
25 #include "device_manager_log.h"
26 
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 typedef void (*TimeoutHandle)(void *data);
31 
32 #define MAXEVENTS 255
33 
34 enum DmTimerStatus : int32_t {
35     DM_STATUS_INIT = 0,
36     DM_STATUS_RUNNING = 1,
37     DM_STATUS_BUSY = 2,
38     DM_STATUS_CREATE_ERROR = 3,
39     DM_STATUS_FINISH = 6,
40 };
41 
42 class DmTimer {
43 public:
44     DmTimer(std::string &name);
45     ~DmTimer();
46     DmTimerStatus Start(uint32_t timeOut, TimeoutHandle handle, void *data);
47     void Stop(int32_t code);
48     void WiteforTimeout();
49 
50 private:
51     int32_t CreateTimeFd();
52     void Release();
53 
54 private:
55     DmTimerStatus mStatus_;
56     uint32_t mTimeOutSec_;
57     TimeoutHandle mHandle_;
58     void *mHandleData_;
59     int32_t mTimeFd_[2];
60     int32_t mEpFd_;
61     std::string mTimerName_;
62 };
63 }
64 }
65 #endif
66 
67