DFBResult CoreInputHub_Create( u32 queue_id, CoreInputHub **ret_hub ) { DFBResult ret; CoreInputHub *hub; D_DEBUG_AT( Core_InputHub, "%s()\n", __FUNCTION__ ); D_ASSERT( ret_hub != NULL ); ret = One_Initialize(); if (ret) return ret; hub = D_CALLOC( 1, sizeof(CoreInputHub) ); if (!hub) return D_OOM(); direct_mutex_init( &hub->lock ); ret = OneQueue_New( ONE_QUEUE_NO_FLAGS, queue_id, &hub->method_qid ); if (ret) goto error; ret = OneQueue_New( ONE_QUEUE_VIRTUAL, ONE_QID_NONE, &hub->notify_qid ); if (ret) goto error; ret = OneThread_Create( "Input Hub", &hub->thread ); if (ret) goto error; ret = OneThread_AddQueue( hub->thread, hub->method_qid, CoreInputHub_Dispatch, hub ); if (ret) goto error; D_INFO( "Core/Input/Hub: Running at QID %u\n", hub->method_qid ); *ret_hub = hub; return DFB_OK; error: if (hub->thread) OneThread_Destroy( hub->thread ); if (hub->notify_qid) OneQueue_Destroy( hub->notify_qid ); if (hub->method_qid) OneQueue_Destroy( hub->method_qid ); direct_mutex_deinit( &hub->lock ); D_FREE( hub ); return ret; }
static void IComaComponent_One_Destruct( IComaComponent *thiz ) { int i; IComaComponent_One_data *data = thiz->priv; D_DEBUG( "%s (%p)\n", __FUNCTION__, thiz ); /* If method_func is non-NULL, we're the creator */ if (data->method_func) { if (data->dispatch_thread) { data->dispatch_stop = true; OneQueue_WakeUp( &data->method_qid, 1 ); direct_thread_join( data->dispatch_thread ); direct_thread_destroy( data->dispatch_thread ); } OneQueue_Destroy( data->method_qid ); for (i=0; i<data->num_notifications; i--) OneQueue_Destroy( data->notifications[i].qid ); } data->notify_stop = true; OneQueue_WakeUp( &data->notify_qid, 1 ); if (data->notify_thread) { direct_thread_join( data->notify_thread ); direct_thread_destroy( data->notify_thread ); } OneQueue_Destroy( data->notify_qid ); direct_hash_iterate( data->calls, call_iterator, data ); direct_hash_destroy( data->calls ); direct_mutex_deinit( &data->calls_lock ); if (data->notifications) D_FREE( data->notifications ); if (data->listeners) D_FREE( data->listeners ); One_Shutdown(); DIRECT_DEALLOCATE_INTERFACE( thiz ); }
DFBResult CoreInputHubClient_Destroy( CoreInputHubClient *client ) { D_DEBUG_AT( Core_InputHub, "%s()\n", __FUNCTION__ ); OneThread_Destroy( client->thread ); OneQueue_Destroy( client->listen_qid ); if (client->activate_thread) { direct_mutex_lock( &client->lock ); client->activate_stop = true; direct_waitqueue_broadcast( &client->wq ); direct_mutex_unlock( &client->lock ); direct_thread_join( client->activate_thread ); direct_thread_destroy( client->activate_thread ); } direct_mutex_deinit( &client->lock ); direct_waitqueue_deinit( &client->wq ); D_FREE( client ); return DFB_OK; }
DFBResult CoreInputHubClient_Create( u32 remote_qid, const CoreInputHubClientCallbacks *callbacks, void *ctx, CoreInputHubClient **ret_client ) { DFBResult ret; CoreInputHubClient *client; D_DEBUG_AT( Core_InputHub, "%s( QID 0x%08x )\n", __FUNCTION__, remote_qid ); D_ASSERT( callbacks != NULL ); D_ASSERT( ret_client != NULL ); One_Initialize(); client = D_CALLOC( 1, sizeof(CoreInputHubClient) ); if (!client) return D_OOM(); client->remote_qid = remote_qid; client->callbacks = *callbacks; client->ctx = ctx; ret = OneQueue_New( ONE_QUEUE_NO_FLAGS, ONE_QID_NONE, &client->listen_qid ); if (ret) goto error; OneQueue_SetName( client->listen_qid, "InputHub/Listener" ); ret = OneThread_Create( "Input Hub Client", &client->thread ); if (ret) goto error; ret = OneThread_AddQueue( client->thread, client->listen_qid, CoreInputHubClient_Dispatch, client ); if (ret) goto error; direct_mutex_init( &client->lock ); direct_waitqueue_init( &client->wq ); *ret_client = client; return DFB_OK; error: if (client->thread) OneThread_Destroy( client->thread ); if (client->listen_qid) OneQueue_Destroy( client->listen_qid ); D_FREE( client ); return ret; }
DFBResult CoreInputHub_Destroy( CoreInputHub *hub ) { D_DEBUG_AT( Core_InputHub, "%s()\n", __FUNCTION__ ); D_ASSERT( hub != NULL ); OneThread_Destroy( hub->thread ); OneQueue_Destroy( hub->notify_qid ); OneQueue_Destroy( hub->method_qid ); direct_mutex_deinit( &hub->lock ); D_FREE( hub ); return DFB_OK; }
DFBResult CoreInputHubClient_Destroy( CoreInputHubClient *client ) { D_DEBUG_AT( Core_InputHub, "%s()\n", __FUNCTION__ ); OneThread_Destroy( client->thread ); OneQueue_Destroy( client->listen_qid ); D_FREE( client ); return DFB_OK; }