DFBResult CoreInputHub_AddDevice( CoreInputHub *hub, DFBInputDeviceID device_id, const DFBInputDeviceDescription *desc ) { InputHubNotification notification; D_ASSERT( hub != NULL ); D_ASSERT( desc != NULL ); D_DEBUG_AT( Core_InputHub, "%s( ID %u, '%s' )\n", __FUNCTION__, device_id, desc->name ); memset( ¬ification, 0, sizeof(notification) ); notification.type = IHNT_DEVICE_ADD; notification.data.device_add.device_id = device_id; notification.data.device_add.description = *desc; direct_mutex_lock( &hub->lock ); OneQueue_Dispatch( hub->notify_qid, ¬ification, sizeof(notification) ); direct_mutex_unlock( &hub->lock ); return DFB_OK; }
DFBResult CoreInputHub_DispatchEvent( CoreInputHub *hub, DFBInputDeviceID device_id, const DFBInputEvent *event ) { InputHubNotification notification; D_DEBUG_AT( Core_InputHub, "%s( ID %u, %s )\n", __FUNCTION__, device_id, dfb_input_event_type_name(event->type) ); D_ASSERT( hub != NULL ); D_ASSERT( event != NULL ); memset( ¬ification, 0, sizeof(notification) ); notification.type = IHNT_EVENT_DISPATCH; notification.data.event_dispatch.device_id = device_id; notification.data.event_dispatch.event = *event; direct_mutex_lock( &hub->lock ); OneQueue_Dispatch( hub->notify_qid, ¬ification, sizeof(notification) ); direct_mutex_unlock( &hub->lock ); return DFB_OK; }
static void CoreInputHub_Dispatch( void *context, const OnePacketHeader *header, void *data, OneThread *thread ) { InputHubAttachRequest *request = data; CoreInputHub *hub = context; D_DEBUG_AT( Core_InputHub, "%s()\n", __FUNCTION__ ); direct_mutex_lock( &hub->lock ); // FIXME: replace by own list of devices recorded in CoreInputHub_AddDevice/RemoveDevice calls dfb_input_enumerate_devices( CoreInputHub_EnumDevice_Callback, request, DICAPS_ALL ); InputHubNotification notification; memset( ¬ification, 0, sizeof(notification) ); notification.type = IHNT_ATTACHED; OneQueue_Dispatch( request->listen_qid, ¬ification, sizeof(notification) ); OneQueue_Attach( hub->notify_qid, request->listen_qid ); direct_mutex_unlock( &hub->lock ); }
DFBResult CoreInputHubClient_Activate( CoreInputHubClient *client ) { InputHubAttachRequest request; D_DEBUG_AT( Core_InputHub, "%s()\n", __FUNCTION__ ); request.listen_qid = client->listen_qid; OneQueue_Dispatch( client->remote_qid, &request, sizeof(request) ); return DFB_OK; }
static DFBEnumerationResult CoreInputHub_EnumDevice_Callback( CoreInputDevice *device, void *ctx ) { InputHubNotification notification; InputHubAttachRequest *request = ctx; memset( ¬ification, 0, sizeof(notification) ); notification.type = IHNT_DEVICE_ADD; notification.data.device_add.device_id = dfb_input_device_id( device ); dfb_input_device_description( device, ¬ification.data.device_add.description ); OneQueue_Dispatch( request->listen_qid, ¬ification, sizeof(notification) ); return DFENUM_OK; }
static void * CoreInputHubClient_ActivateThread( DirectThread *thread, void *arg ) { CoreInputHubClient *client = arg; InputHubAttachRequest request; D_DEBUG_AT( Core_InputHub, "%s()\n", __FUNCTION__ ); direct_mutex_lock( &client->lock ); while (!client->activate_stop) { request.listen_qid = client->listen_qid; OneQueue_Dispatch( client->remote_qid, &request, sizeof(request) ); direct_waitqueue_wait_timeout( &client->wq, &client->lock, 1000000 ); } direct_mutex_unlock( &client->lock ); return DFB_OK; }
DFBResult CoreInputHub_RemoveDevice( CoreInputHub *hub, DFBInputDeviceID device_id ) { InputHubNotification notification; D_DEBUG_AT( Core_InputHub, "%s( ID %u )\n", __FUNCTION__, device_id ); D_ASSERT( hub != NULL ); memset( ¬ification, 0, sizeof(notification) ); notification.type = IHNT_DEVICE_REMOVE; notification.data.device_remove.device_id = device_id; direct_mutex_lock( &hub->lock ); OneQueue_Dispatch( hub->notify_qid, ¬ification, sizeof(notification) ); direct_mutex_unlock( &hub->lock ); return DFB_OK; }
static DirectResult TestWakeUp(void) { DirectResult ret; char buf[512]; int loops = 1000000; while (loops--) { ret = OneThread_AddQueue( thread, queue_id, TestDispatch, NULL ); if (ret) { D_DERROR( ret, "OneTest: AddQueue error!\n" ); return ret; } direct_mutex_lock( &lock ); ret = OneQueue_Dispatch( queue_id, buf, 12 ); if (ret) { D_DERROR( ret, "OneTest: Dispatch error!\n" ); direct_mutex_unlock( &lock ); return ret; } direct_waitqueue_wait( &queue, &lock ); direct_mutex_unlock( &lock ); ret = OneThread_RemoveQueue( thread, queue_id ); if (ret) { D_DERROR( ret, "OneTest: RemoveQueue error!\n" ); return ret; } } return DR_OK; }