From 2b38a768c71ae0b7002e75d1a1824c06ef94b7a1 Mon Sep 17 00:00:00 2001 From: Matthew Date: Tue, 11 Jun 2024 23:58:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=89=E5=BE=85=E6=8B=8D=E7=85=A7=E7=BA=BF?= =?UTF-8?q?=E7=A8=8B=E7=BB=93=E6=9D=9F=E7=9A=84=E4=BF=9D=E6=8A=A4=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E6=AD=BB=E7=AD=89=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 33 +++++++++++++++++++++++++++++++- app/src/main/cpp/PhoneDevice.h | 2 ++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 51c13b02..6046af09 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -913,6 +913,18 @@ void CPhoneDevice::handleTimerImpl(CPhoneDevice::TIMER_CONTEXT* context) } } +void CPhoneDevice::handleRebootTimer(union sigval v) +{ + CPhoneDevice* pDevice = (CPhoneDevice*)(v.sival_ptr); + // Reboot APP + XYLOG(XYLOG_SEVERITY_ERROR, "Camera Close Thread is DEAD, will RESTART app"); + pDevice->Reboot(0); +} + +// void CPhoneDevice::handleRebootTimerImpl() +// { +// } + IDevice::timer_uid_t CPhoneDevice::RegisterTimer(unsigned int timerType, unsigned int timeout, void* data, unsigned long times/* = 0*/) { struct sigevent evp = { 0 }; @@ -953,7 +965,6 @@ IDevice::timer_uid_t CPhoneDevice::RegisterTimer(unsigned int timerType, unsigne } ret = timer_settime(timer, 0, &ts, NULL); - if(ret) { timer_delete(timer); @@ -1085,7 +1096,27 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector< if (m_threadClose.joinable()) { XYLOG(XYLOG_SEVERITY_INFO, "TP: Wait Prev Thread CH=%u PR=%X PHOTOID=%u", (unsigned int)photoInfo.channel, (unsigned int)photoInfo.preset, photoInfo.photoId); + struct sigevent evp = { 0 }; + struct itimerspec ts = { 0 }; + timer_t timer; + int ret; + + evp.sigev_value.sival_ptr = this; + evp.sigev_notify = SIGEV_THREAD; //SIGEV_THREAD_ID; + evp.sigev_notify_function = CPhoneDevice::handleRebootTimer; + // evp.sigev_notify_thread_id = gettid(); + // evp.sigev_notify = SIGEV_SIGNAL; + // evp.sigev_signo = SIGUSR2; + + ret = timer_create(CLOCK_REALTIME, &evp, &timer); + if( ret == 0) + { + ts.it_value.tv_sec = 8; // 8 seconds + ts.it_value.tv_nsec = 0; + ret = timer_settime(timer, 0, &ts, NULL); + } m_threadClose.join(); + timer_delete(timer); XYLOG(XYLOG_SEVERITY_INFO, "TP: Wait Prev Thread End CH=%u PR=%X PHOTOID=%u", (unsigned int)photoInfo.channel, (unsigned int)photoInfo.preset, photoInfo.photoId); } diff --git a/app/src/main/cpp/PhoneDevice.h b/app/src/main/cpp/PhoneDevice.h index 7408fa09..bf8114a7 100644 --- a/app/src/main/cpp/PhoneDevice.h +++ b/app/src/main/cpp/PhoneDevice.h @@ -261,6 +261,8 @@ protected: bool RegisterHandlerForSignal(int sig); void static handleTimer(union sigval v); void handleTimerImpl(TIMER_CONTEXT* context); + void static handleRebootTimer(union sigval v); + // void handleRebootTimerImpl(); int QueryBatteryVoltage(int retries);