MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / BOpen

Method BOpen

Engine/lib/sdl/src/hidapi/android/hid.cpp:487–541  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

485 }
486
487 bool BOpen()
488 {
489 // Make sure thread is attached to JVM/env
490 JNIEnv *env;
491 g_JVM->AttachCurrentThread( &env, NULL );
492 pthread_setspecific( g_ThreadKey, (void*)env );
493
494 if ( !g_HIDDeviceManagerCallbackHandler )
495 {
496 LOGV( "Device open without callback handler" );
497 return false;
498 }
499
500 m_bIsWaitingForOpen = false;
501 m_bOpenResult = env->CallBooleanMethod( g_HIDDeviceManagerCallbackHandler, g_midHIDDeviceManagerOpen, m_nId );
502 ExceptionCheck( env, "BOpen" );
503
504 if ( m_bIsWaitingForOpen )
505 {
506 hid_mutex_guard cvl( &m_cvLock );
507
508 const int OPEN_TIMEOUT_SECONDS = 60;
509 struct timespec ts, endtime;
510 clock_gettime( CLOCK_REALTIME, &ts );
511 endtime = ts;
512 endtime.tv_sec += OPEN_TIMEOUT_SECONDS;
513 do
514 {
515 if ( pthread_cond_timedwait( &m_cv, &m_cvLock, &endtime ) != 0 )
516 {
517 break;
518 }
519 }
520 while ( m_bIsWaitingForOpen && get_timespec_ms( ts ) < get_timespec_ms( endtime ) );
521 }
522
523 if ( !m_bOpenResult )
524 {
525 if ( m_bIsWaitingForOpen )
526 {
527 LOGV( "Device open failed - timed out waiting for device permission" );
528 }
529 else
530 {
531 LOGV( "Device open failed" );
532 }
533 return false;
534 }
535
536 m_pDevice = new hid_device;
537 m_pDevice->m_nId = m_nId;
538 m_pDevice->m_nDeviceRefCount = 1;
539 LOGD("Creating device %d (%p), refCount = 1\n", m_pDevice->m_nId, m_pDevice);
540 return true;
541 }
542
543 void SetOpenPending()
544 {

Callers 1

hid_open_pathFunction · 0.80

Calls 2

ExceptionCheckFunction · 0.85
get_timespec_msFunction · 0.85

Tested by

no test coverage detected