From f9fd8a10a3ed2a8904c65fc265c503dfe6c25098 Mon Sep 17 00:00:00 2001 From: Marcus Winter Date: Mon, 17 Nov 2014 20:39:37 +0100 Subject: [PATCH] mtapi_c: extended action plugin api, some cleanup --- mtapi_c/include/embb/mtapi/c/mtapi_ext.h | 15 +++++++++++---- mtapi_c/src/embb_mtapi_action_plugin_t.c | 12 ++++++++---- mtapi_c/src/embb_mtapi_action_t.c | 7 ++++++- mtapi_c/src/embb_mtapi_action_t.h | 6 ++++-- mtapi_c/src/embb_mtapi_task_t.c | 4 ++-- mtapi_c/test/embb_mtapi_test_plugin.cc | 24 ++++++++++++++++++++---- 6 files changed, 51 insertions(+), 17 deletions(-) diff --git a/mtapi_c/include/embb/mtapi/c/mtapi_ext.h b/mtapi_c/include/embb/mtapi/c/mtapi_ext.h index 5934364..84ff46e 100644 --- a/mtapi_c/include/embb/mtapi/c/mtapi_ext.h +++ b/mtapi_c/include/embb/mtapi/c/mtapi_ext.h @@ -36,20 +36,27 @@ extern "C" { #endif -typedef void(*mtapi_ext_plugin_action_start_function_t)( +typedef void(*mtapi_ext_plugin_task_start_function_t)( MTAPI_IN mtapi_task_hndl_t task, MTAPI_OUT mtapi_status_t* status ); -typedef void(*mtapi_ext_plugin_action_cancel_function_t)( +typedef void(*mtapi_ext_plugin_task_cancel_function_t)( MTAPI_IN mtapi_task_hndl_t task, MTAPI_OUT mtapi_status_t* status ); +typedef void(*mtapi_ext_plugin_action_finalize_function_t)( + MTAPI_IN mtapi_action_hndl_t action, + MTAPI_OUT mtapi_status_t* status +); + mtapi_action_hndl_t mtapi_ext_plugin_action_create( MTAPI_IN mtapi_job_id_t job_id, - MTAPI_IN mtapi_ext_plugin_action_start_function_t start_function, - MTAPI_IN mtapi_ext_plugin_action_cancel_function_t cancel_function, + MTAPI_IN mtapi_ext_plugin_task_start_function_t task_start_function, + MTAPI_IN mtapi_ext_plugin_task_cancel_function_t task_cancel_function, + MTAPI_IN mtapi_ext_plugin_action_finalize_function_t action_finalize_function, + MTAPI_IN void* plugin_data, MTAPI_IN void* node_local_data, MTAPI_IN mtapi_size_t node_local_data_size, MTAPI_IN mtapi_action_attributes_t* attributes, diff --git a/mtapi_c/src/embb_mtapi_action_plugin_t.c b/mtapi_c/src/embb_mtapi_action_plugin_t.c index a8e91dc..11462ec 100644 --- a/mtapi_c/src/embb_mtapi_action_plugin_t.c +++ b/mtapi_c/src/embb_mtapi_action_plugin_t.c @@ -33,8 +33,10 @@ mtapi_action_hndl_t mtapi_ext_plugin_action_create( MTAPI_IN mtapi_job_id_t job_id, - MTAPI_IN mtapi_ext_plugin_action_start_function_t start_function, - MTAPI_IN mtapi_ext_plugin_action_cancel_function_t cancel_function, + MTAPI_IN mtapi_ext_plugin_task_start_function_t task_start_function, + MTAPI_IN mtapi_ext_plugin_task_cancel_function_t task_cancel_function, + MTAPI_IN mtapi_ext_plugin_action_finalize_function_t action_finalize_function, + MTAPI_IN void* plugin_data, MTAPI_IN void* node_local_data, MTAPI_IN mtapi_size_t node_local_data_size, MTAPI_IN mtapi_action_attributes_t* attributes, @@ -61,8 +63,10 @@ mtapi_action_hndl_t mtapi_ext_plugin_action_create( new_action->is_plugin_action = MTAPI_TRUE; embb_atomic_store_int(&new_action->num_tasks, 0); - new_action->plugin_start_function = start_function; - new_action->plugin_cancel_function = cancel_function; + new_action->plugin_task_start_function = task_start_function; + new_action->plugin_task_cancel_function = task_cancel_function; + new_action->plugin_action_finalize_function = action_finalize_function; + new_action->plugin_data = (void*)plugin_data; /* set defaults if no attributes were given */ if (MTAPI_NULL != attributes) { diff --git a/mtapi_c/src/embb_mtapi_action_t.c b/mtapi_c/src/embb_mtapi_action_t.c index 0adae91..b21ba35 100644 --- a/mtapi_c/src/embb_mtapi_action_t.c +++ b/mtapi_c/src/embb_mtapi_action_t.c @@ -60,6 +60,10 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) { } void embb_mtapi_action_finalize(embb_mtapi_action_t* that) { + if (that->is_plugin_action) { + // TODO: check status + that->plugin_action_finalize_function(that->handle, NULL); + } embb_mtapi_action_initialize(that); } @@ -324,7 +328,8 @@ void mtapi_action_delete( node, local_action->job_id); embb_mtapi_job_remove_action(local_job, local_action); } - embb_mtapi_action_finalize(local_action); + /* this is done by pool deallocate: + embb_mtapi_action_finalize(local_action); */ embb_mtapi_action_pool_deallocate(node->action_pool, local_action); } else { local_status = MTAPI_ERR_ACTION_INVALID; diff --git a/mtapi_c/src/embb_mtapi_action_t.h b/mtapi_c/src/embb_mtapi_action_t.h index bf0bfe1..7cbb45b 100644 --- a/mtapi_c/src/embb_mtapi_action_t.h +++ b/mtapi_c/src/embb_mtapi_action_t.h @@ -58,8 +58,10 @@ struct embb_mtapi_action_struct { mtapi_boolean_t enabled; mtapi_boolean_t is_plugin_action; - mtapi_ext_plugin_action_start_function_t plugin_start_function; - mtapi_ext_plugin_action_cancel_function_t plugin_cancel_function; + void* plugin_data; + mtapi_ext_plugin_task_start_function_t plugin_task_start_function; + mtapi_ext_plugin_task_cancel_function_t plugin_task_cancel_function; + mtapi_ext_plugin_action_finalize_function_t plugin_action_finalize_function; embb_atomic_int num_tasks; }; diff --git a/mtapi_c/src/embb_mtapi_task_t.c b/mtapi_c/src/embb_mtapi_task_t.c index 89e2dca..45810e5 100644 --- a/mtapi_c/src/embb_mtapi_task_t.c +++ b/mtapi_c/src/embb_mtapi_task_t.c @@ -239,7 +239,7 @@ static mtapi_task_hndl_t embb_mtapi_task_start( if (local_action->is_plugin_action) { /* schedule plugin task */ mtapi_status_t plugin_status = MTAPI_ERR_UNKNOWN; - local_action->plugin_start_function(task_hndl, &plugin_status); + local_action->plugin_task_start_function(task_hndl, &plugin_status); was_scheduled = (MTAPI_SUCCESS == plugin_status) ? MTAPI_TRUE : MTAPI_FALSE; } else { /* schedule local task */ @@ -469,7 +469,7 @@ void mtapi_task_cancel( embb_mtapi_action_t* local_action = embb_mtapi_action_pool_get_storage_for_handle(node->action_pool, local_task->action); if (local_action->is_plugin_action) { - local_action->plugin_cancel_function(task, &local_status); + local_action->plugin_task_cancel_function(task, &local_status); } } else { local_status = MTAPI_SUCCESS; diff --git a/mtapi_c/test/embb_mtapi_test_plugin.cc b/mtapi_c/test/embb_mtapi_test_plugin.cc index e592410..d20f37f 100644 --- a/mtapi_c/test/embb_mtapi_test_plugin.cc +++ b/mtapi_c/test/embb_mtapi_test_plugin.cc @@ -34,6 +34,7 @@ #include #include +#include #define PLUGIN_JOB_ID 2 @@ -43,6 +44,7 @@ mtapi_task_hndl_t plugin_task; embb_atomic_int plugin_task_available; int plugin_thread_function(void * args) { + EMBB_UNUSED(args); while (embb_atomic_load_int(&plugin_running)) { /* wait for incoming task */ while (embb_atomic_load_int(&plugin_running) && !embb_atomic_load_int(&plugin_task_available)) @@ -70,6 +72,9 @@ void plugin_initialize( MTAPI_IN mtapi_node_t node_id, MTAPI_OUT mtapi_status_t* status ) { + EMBB_UNUSED(domain_id); + EMBB_UNUSED(node_id); + mtapi_status_t local_status = MTAPI_ERR_UNKNOWN; int err; @@ -102,7 +107,7 @@ void plugin_finalize( mtapi_status_set(status, local_status); } -void plugin_action_start( +void plugin_task_start( MTAPI_IN mtapi_task_hndl_t task, MTAPI_OUT mtapi_status_t* status) { mtapi_status_t local_status = MTAPI_ERR_UNKNOWN; @@ -125,15 +130,24 @@ void plugin_action_start( mtapi_status_set(status, local_status); } -void plugin_action_cancel( +void plugin_task_cancel( MTAPI_IN mtapi_task_hndl_t task, MTAPI_OUT mtapi_status_t* status ) { + EMBB_UNUSED(task); mtapi_status_t local_status = MTAPI_ERR_UNKNOWN; mtapi_status_set(status, local_status); } +void plugin_action_finalize( + MTAPI_IN mtapi_action_hndl_t action, + MTAPI_OUT mtapi_status_t* status + ) { + EMBB_UNUSED(action); + mtapi_status_set(status, MTAPI_SUCCESS); +} + PluginTest::PluginTest() { CreateUnit("mtapi plugin test"). Add(&PluginTest::TestBasic, this); @@ -180,8 +194,10 @@ void PluginTest::TestBasic() { status = MTAPI_ERR_UNKNOWN; action = mtapi_ext_plugin_action_create( PLUGIN_JOB_ID, - plugin_action_start, - plugin_action_cancel, + plugin_task_start, + plugin_task_cancel, + plugin_action_finalize, + MTAPI_NULL, MTAPI_NULL, 0, MTAPI_DEFAULT_ACTION_ATTRIBUTES, -- libgit2 0.26.0