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 HRilEventMessage event; 31 }; 32 33 class HRilTimerCallback { 34 public: HRilTimerCallback()35 HRilTimerCallback() {}; 36 virtual ~HRilTimerCallback() = default; 37 38 void EventLoop(); 39 std::shared_ptr<HRilTimerCallbackMessage> HRilSetTimerCallbackInfo( 40 HRilCallbackFun func, uint8_t *param, const struct timeval *tv); 41 42 private: 43 void FdTriggerCallback(int32_t fd, int16_t events, std::shared_ptr<void> param); 44 void TimerCallback(int32_t fd, int16_t events, std::shared_ptr<void> param); 45 void OnTriggerEvent(); 46 47 private: 48 HRilEventMessage fdTriggerEvent_; 49 int32_t triggerReadFd_; 50 int32_t triggerWriteFd_; 51 std::unique_ptr<HRilEvent> event_ = nullptr; 52 const int32_t PIPE_SIZE_MAX = 2; 53 const int32_t READ_FD_BUFF_SIZE = 16; 54 std::thread::id eventLoopTid_; 55 }; 56 } // namespace Telephony 57 } // namespace OHOS 58 #endif // OHOS_HRIL_TIMER_CALLBACK_H