| 430 | } |
| 431 | |
| 432 | bool BOpen() |
| 433 | { |
| 434 | // Make sure thread is attached to JVM/env |
| 435 | JNIEnv *env; |
| 436 | g_JVM->AttachCurrentThread( &env, NULL ); |
| 437 | pthread_setspecific( g_ThreadKey, (void*)env ); |
| 438 | |
| 439 | m_bIsWaitingForOpen = false; |
| 440 | m_bOpenResult = env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerOpen, m_nId ); |
| 441 | ExceptionCheck( env, "BOpen" ); |
| 442 | |
| 443 | if ( m_bIsWaitingForOpen ) |
| 444 | { |
| 445 | hid_mutex_guard cvl( &m_cvLock ); |
| 446 | |
| 447 | const int OPEN_TIMEOUT_SECONDS = 60; |
| 448 | struct timespec ts, endtime; |
| 449 | clock_gettime( CLOCK_REALTIME, &ts ); |
| 450 | endtime = ts; |
| 451 | endtime.tv_sec += OPEN_TIMEOUT_SECONDS; |
| 452 | do |
| 453 | { |
| 454 | if ( pthread_cond_timedwait( &m_cv, &m_cvLock, &endtime ) != 0 ) |
| 455 | { |
| 456 | break; |
| 457 | } |
| 458 | } |
| 459 | while ( m_bIsWaitingForOpen && get_timespec_ms( ts ) < get_timespec_ms( endtime ) ); |
| 460 | } |
| 461 | |
| 462 | if ( !m_bOpenResult ) |
| 463 | { |
| 464 | if ( m_bIsWaitingForOpen ) |
| 465 | { |
| 466 | LOGV( "Device open failed - timed out waiting for device permission" ); |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | LOGV( "Device open failed" ); |
| 471 | } |
| 472 | return false; |
| 473 | } |
| 474 | |
| 475 | m_pDevice = new hid_device; |
| 476 | m_pDevice->m_nId = m_nId; |
| 477 | m_pDevice->m_nDeviceRefCount = 1; |
| 478 | LOGD("Creating device %d (%p), refCount = 1\n", m_pDevice->m_nId, m_pDevice); |
| 479 | return true; |
| 480 | } |
| 481 | |
| 482 | void SetOpenPending() |
| 483 | { |
no test coverage detected