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);