in inc/sf_c_util/fabric_async_op_sync_wrapper.h [131:215]
HRESULT MU_C4(interface_name, _, operation_name, _execute)(interface_name* com_object BS2SF_ASYNC_OP_SYNC_EXTRACT_BEGIN_ARGS(__VA_ARGS__) BS2SF_ASYNC_OP_SYNC_EXTRACT_END_ARGS_POINTERS(__VA_ARGS__)) \
{ \
HRESULT result; \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_003: [ If com_object is NULL, _execute shall fail and return E_INVALIDARG. ]*/ \
if ( \
(com_object == NULL) \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_020: [ If any of the end arg pointers is NULL, _execute shall fail and return E_INVALIDARG. ]*/ \
BS2SF_ASYNC_OP_SYNC_EXTRACT_END_ARGS_NULL_COMPARE(__VA_ARGS__) \
) \
{ \
LogError("Invalid arguments: interface_name* com_object=%p, ...", com_object); \
result = E_INVALIDARG; \
} \
else \
{ \
volatile_atomic int32_t is_completed; \
(void)interlocked_exchange(&is_completed, 0); \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_004: [ _execute shall create a async operation callback object by calling fabric_async_op_cb_create, passing as arguments the wrapper complete callback. ]*/ \
FABRIC_ASYNC_OP_CB_HANDLE fabric_async_op_cb = fabric_async_op_cb_create(MU_C4(interface_name, _, operation_name, sync_wrapper_cb), (void*)&is_completed); \
if (fabric_async_op_cb == NULL) \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_013: [ If any other error occurs, _execute shall fail and return E_FAIL. ]*/ \
LogError("fabric_async_op_cb_create failed"); \
result = E_FAIL; \
} \
else \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_005: [ A COM wrapper shall be created for the async operation callback object. ]*/ \
IFabricAsyncOperationCallback* callback = COM_WRAPPER_CREATE(FABRIC_ASYNC_OP_CB_HANDLE, IFabricAsyncOperationCallback, fabric_async_op_cb, fabric_async_op_cb_destroy); \
if (callback == NULL) \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_013: [ If any other error occurs, _execute shall fail and return E_FAIL. ]*/ \
LogError("COM wrapper object creation failed"); \
fabric_async_op_cb_destroy(fabric_async_op_cb); \
result = E_FAIL; \
} \
else \
{ \
IFabricAsyncOperationContext* fabric_operation_context; \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_006: [ _execute shall call Begin{operation_name} on com_object, passing as arguments the begin arguments and the async operation callback COM object. ]*/ \
result = com_object->lpVtbl->MU_C2(Begin, operation_name)(com_object BS2SF_ASYNC_OP_SYNC_EXTRACT_BEGIN_ARG_VALUES(__VA_ARGS__), callback, &fabric_operation_context); \
if (FAILED(result)) \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_011: [ If Begin{operation_name} fails, _execute shall return the error returned by Begin{operation_name}. ]*/ \
LogHRESULTError(result, "com_object->lpVtbl->Begin" MU_TOSTRING(operation_name) " failed."); \
/* return result as is */ \
} \
else \
{ \
result = S_OK; \
if (!fabric_operation_context->lpVtbl->CompletedSynchronously(fabric_operation_context)) \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_007: [ If fabric_operation_context has not completed synchronously, _execute shall wait to be signalled by the _sync_wrapper_cb function. ]*/ \
if (InterlockedHL_WaitForValue(&is_completed, 1, UINT32_MAX) != INTERLOCKED_HL_OK) \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_013: [ If any other error occurs, _execute shall fail and return E_FAIL. ]*/ \
LogError("InterlockedHL_WaitForValue failed"); \
result = E_FAIL; \
} \
} \
if (!FAILED(result)) \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_008: [ _execute shall call End{operation_name} on com_object. ]*/ \
result = com_object->lpVtbl->MU_C2(End, operation_name)(com_object, fabric_operation_context BS2SF_ASYNC_OP_SYNC_EXTRACT_END_ARG_VALUES(__VA_ARGS__)); \
if (FAILED(result)) \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_012: [ If End{operation_name} fails, _execute shall return the error returned by End{operation_name}. ]*/ \
LogHRESULTError(result, MU_TOSTRING(MU_C2(End, operation_name)) " failed"); \
/* return result as is */ \
} \
else \
{ \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_010: [ On success, _execute shall return S_OK. ]*/ \
result = S_OK; \
} \
} \
/* Codes_SRS_FABRIC_ASYNC_OP_SYNC_WRAPPER_01_009: [ _execute shall release the asynchronous operation context obtained from Begin{operation_name}. ]*/ \
(void)fabric_operation_context->lpVtbl->Release(fabric_operation_context); \
} \
(void)callback->lpVtbl->Release(callback); \
} \
} \
} \
return result; \
}