• 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 OHOS_HRIL_TIMER_CALLBACK_H
17 #define OHOS_HRIL_TIMER_CALLBACK_H
18 
19 #include <thread>
20 
21 #include "hril_event.h"
22 
23 namespace OHOS {
24 namespace Telephony {
25 typedef void (*HRilCallbackFun)(uint8_t *param);
26 
27 struct HRilTimerCallbackMessage {
28     uint8_t *param;
29     HRilCallbackFun func;
30 };
31 
32 class HRilTimerCallback {
33 public:
HRilTimerCallback()34     HRilTimerCallback() {};
35     virtual ~HRilTimerCallback() = default;
36     std::unique_ptr<HRilEvent> event_ = nullptr;
37 
38     void EventLoop();
39     std::shared_ptr<HRilTimerCallbackMessage> HRilSetTimerCallbackInfo(
40         HRilCallbackFun func, uint8_t *param, const struct timeval *tv);
41     void OnTriggerEvent();
42 
43 private:
44     void FdTriggerCallback(int32_t fd, int16_t events, std::shared_ptr<void> param);
45     void TimerCallback(int32_t fd, int16_t events, std::shared_ptr<void> param);
46 
47 private:
48     HRilEventMessage fdTriggerEvent_;
49     int32_t triggerReadFd_;
50     int32_t triggerWriteFd_;
51     const int32_t PIPE_SIZE_MAX = 2;
52     const int32_t READ_FD_BUFF_SIZE = 16;
53     std::thread::id eventLoopTid_;
54 };
55 } // namespace Telephony
56 } // namespace OHOS
57 #endif // OHOS_HRIL_TIMER_CALLBACK_H