int main( int argc, char *argv[] ) { DirectResult ret; if (parse_cmdline( argc, argv )) return -1; direct_mutex_init( &lock ); direct_waitqueue_init( &queue ); ret = One_Initialize(); if (ret) return ret; ret = OneThread_Create( "OneTest", &thread ); if (ret) return ret; ret = OneQueue_New( ONE_QUEUE_NO_FLAGS, queue_id, &queue_id ); if (ret) return ret; D_INFO( "Queue ID %u\n", queue_id ); TestWakeUp(); direct_mutex_deinit( &lock ); direct_waitqueue_deinit( &queue ); return 0; }
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; }
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; }