in sfwrapper/inc/h_fabric_macro_generator.h [307:385]
HRESULT H_FABRIC_API(IFABRIC_METHOD_NAME)(H_FABRIC_HANDLE(IFABRIC_INTERFACE_NAME) handle \
ARGS_C_DECLARATION(in_args) \
) \
{ \
HRESULT hr; /*also used a result*/ \
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_001: [ If handle is NULL then H_FABRIC_API(IFABRIC_METHOD_NAME) shall fail and return NULL. ]*/ \
if (handle == NULL) \
{ \
LogError("invalid " MU_TOSTRING(HANDLE_TYPE) " handle=%p", handle); \
hr = E_POINTER; \
} \
else \
{ \
uint32_t retries = 0; /*incremented at every API call - 0 means "it will call once", "1" means it will call 2 times". It is in the name: **re**tries.*/ \
\
do \
{ \
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_002: [ H_FABRIC_API(IFABRIC_METHOD_NAME) shall call IFABRIC_METHOD_NAME on the instance of IFABRIC_INTERFACE_NAME. ]*/ \
hr = IFABRIC_METHOD_NAME(handle->This ARGS_C_CALL(in_args)); \
if (FAILED(hr)) \
{ \
LogHRESULTError(hr, "failure in " MU_TOSTRING(IFABRIC_METHOD_NAME) "(handle->This=%p, ...)", \
handle->This); \
\
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_004: [ If the result is FABRIC_E_OBJECT_CLOSED, FABRIC_E_GATEWAY_NOT_REACHABLE or E_ABORT then H_FABRIC_API(IFABRIC_METHOD_NAME) shall create a new instance of IFABRIC_INTERFACE_NAME. ]*/ \
if ((hr == E_ABORT) || (hr == FABRIC_E_OBJECT_CLOSED) || (hr == FABRIC_E_GATEWAY_NOT_REACHABLE)) \
{ \
IFABRIC_INTERFACE_NAME* newInstance = NULL; \
\
HRESULT hr_create; \
hr_create = CREATE_IFABRICINSTANCE_NAME(IFABRIC_INTERFACE_NAME)(&newInstance); \
if (FAILED(hr_create)) \
{ \
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_005: [ If creating the new instance of IFABRIC_INTERFACE_NAME fails then H_FABRIC_API(IFABRIC_METHOD_NAME) shall retry using the existing IFABRIC_INTERFACE_NAME. ]*/ \
LogHRESULTError(hr_create, "failure in CREATE_IFABRICINSTANCE_NAME(" MU_TOSTRING(IFABRIC_INTERFACE_NAME) ")(&newInstance=%p)", &newInstance); \
/*keep retrying until retry count is exceeded*/ \
} \
else \
{ \
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_006: [ Otherwise H_FABRIC_API(IFABRIC_METHOD_NAME) shall release the existing instance and shall retry using new newly created IFABRIC_INTERFACE_NAME. ]*/ \
/*let go of the old instance*/ \
(void)handle->This->lpVtbl->Release(handle->This); \
\
/*replace it with the new instance*/ \
handle->This = newInstance; \
} \
} \
else if (0 RESULTS_CHECK(permanent_failures)) \
{ \
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_42_002: [ If the result is any value from permanent_failures then H_FABRIC_API(IFABRIC_METHOD_NAME) shall return. ]*/ \
break; \
} \
else \
{ \
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_007: [ If the result is any other value except FABRIC_E_OBJECT_CLOSED, FABRIC_E_GATEWAY_NOT_REACHABLE or E_ABORT then H_FABRIC_API(IFABRIC_METHOD_NAME) shall retry. ]*/ \
/*some other HRESULT, so retry without re-creating the object*/ \
} \
} \
else \
{ \
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_003: [ If the call succeeds then H_FABRIC_API(IFABRIC_METHOD_NAME) shall succeed and return. ]*/ \
break; \
} \
\
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_008: [ H_FABRIC_API(IFABRIC_METHOD_NAME) shall sleep msBetweenRetries. ]*/ \
ThreadAPI_Sleep(handle->msBetweenRetries); \
retries++; \
\
/*Codes_SRS_H_FABRIC_MACRO_GENERATOR_01_009: [ If the total number of retries exceeds nMaxRetries then H_FABRIC_API(IFABRIC_METHOD_NAME) shall return the last error code. ]*/ \
} while (retries < handle->nMaxRetries); \
\
if(FAILED(hr)) \
{ \
LogHRESULTError(hr, "tried for %" PRIu32 " times and it failed", retries); \
} \
} \
\
return hr; \
}