JSON_ENCODER_TOSTRING_RESULT JSONEncoder_CharPtr_ToString(STRING_HANDLE destination, const void* value) { JSON_ENCODER_TOSTRING_RESULT result; /*Coes_SRS_JSON_ENCODER_99_047:[ JSONEncoder_CharPtr_ToString shall return JSON_ENCODER_TOSTRING_INVALID_ARG if destination or value parameters passed to it are NULL.]*/ if ((destination == NULL) || (value == NULL)) { result = JSON_ENCODER_TOSTRING_INVALID_ARG; LogError("(result = %s)\r\n", ENUM_TO_STRING(JSON_ENCODER_TOSTRING_RESULT, result)); } /*Codes_SRS_JSON_ENCODER_99_048:[ JSONEncoder_CharPtr_ToString shall use strcpy_s to copy from value to destination.]*/ else if (STRING_concat(destination, (const char*)value) != 0) { /*Codes_SRS_JSON_ENCODER_99_049:[ If strcpy_s fails then JSONEncoder_CharPtr_ToString shall return JSON_ENCODER_TOSTRING_ERROR.]*/ result = JSON_ENCODER_TOSTRING_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(JSON_ENCODER_TOSTRING_RESULT, result)); } else { /*Codes_SRS_JSON_ENCODER_99_050:[ If strcpy_s doesn't fail, then JSONEncoder_CharPtr_ToString shall return JSON_ENCODER_TOSTRING_OK]*/ result = JSON_ENCODER_TOSTRING_OK; } return result; }
MULTITREE_RESULT MultiTree_GetValue(MULTITREE_HANDLE treeHandle, const void** destination) { MULTITREE_RESULT result; /*Codes_SRS_MULTITREE_99_042:[If treeHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ if (treeHandle == NULL) { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } /*Codes_SRS_MULTITREE_99_043:[ If destination is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ else if (destination == NULL) { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } else { MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA*)treeHandle; /*Codes_SRS_MULTITREE_99_044:[ If there is no value in the node then MULTITREE_EMPTY_VALUE shall be returned.]*/ if (node->value == NULL) { result = MULTITREE_EMPTY_VALUE; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } else { /*Codes_SRS_MULTITREE_99_041:[This function updates the *destination parameter to the internally stored value.]*/ *destination = node->value; result = MULTITREE_OK; } } return result; }
LOCK_RESULT Lock(LOCK_HANDLE handle) { LOCK_RESULT result; if (handle == NULL) { /*SRS_LOCK_99_007:[ This API on NULL handle passed returns LOCK_ERROR]*/ result = LOCK_ERROR; LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result)); } else { if (mtx_lock((mtx_t*)handle) == thrd_success) { /*SRS_LOCK_99_005:[ This API on success should return LOCK_OK]*/ result = LOCK_OK; } else { /*SRS_LOCK_99_006:[ This API on error should return LOCK_ERROR]*/ result = LOCK_ERROR; LogError("(result = %s)", ENUM_TO_STRING(LOCK_RESULT, result)); } } return result; }
THREADAPI_RESULT ThreadAPI_Join(THREAD_HANDLE threadHandle, int* res) { THREADAPI_RESULT result; THREAD_INSTANCE* threadInstance = (THREAD_INSTANCE*)threadHandle; if (threadInstance == NULL) { result = THREADAPI_INVALID_ARG; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { void* threadResult; if (pthread_join(threadInstance->Pthread_handle, &threadResult) != 0) { result = THREADAPI_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { if (res != NULL) { *res = (int)(intptr_t)threadResult; } result = THREADAPI_OK; } free(threadInstance); } return result; }
THREADAPI_RESULT ThreadAPI_Create(THREAD_HANDLE* threadHandle, THREAD_START_FUNC func, void* arg) { THREADAPI_RESULT result; if ((threadHandle == NULL) || (func == NULL)) { result = THREADAPI_INVALID_ARG; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { *threadHandle = CreateThread(NULL, 0, func, arg, 0, NULL); if(threadHandle == NULL) { result = THREADAPI_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { result = THREADAPI_OK; } } return result; }
TRANSACTION_HANDLE DataPublisher_StartTransaction(DATA_PUBLISHER_HANDLE dataPublisherHandle) { TRANSACTION* transaction; /* Codes_SRS_DATA_PUBLISHER_99_038:[ If DataPublisher_StartTransaction is called with a NULL argument it shall return NULL.] */ if (dataPublisherHandle == NULL) { transaction = NULL; LogError("(Error code: %s)\r\n", ENUM_TO_STRING(DATA_PUBLISHER_RESULT, DATA_PUBLISHER_INVALID_ARG)); } else { /* Codes_SRS_DATA_PUBLISHER_99_007:[ A call to DataPublisher_StartTransaction shall start a new transaction.] */ transaction = (TRANSACTION*)malloc(sizeof(TRANSACTION)); if (transaction == NULL) { LogError("Allocating transaction failed (Error code: %s)\r\n", ENUM_TO_STRING(DATA_PUBLISHER_RESULT, DATA_PUBLISHER_ERROR)); } else { transaction->ValueCount = 0; transaction->Values = NULL; transaction->DataPublisherInstance = (DATA_PUBLISHER_INSTANCE*)dataPublisherHandle; } } /* Codes_SRS_DATA_PUBLISHER_99_008:[ DataPublisher_StartTransaction shall return a non-NULL handle upon success.] */ /* Codes_SRS_DATA_PUBLISHER_99_009:[ DataPublisher_StartTransaction shall return NULL upon failure.] */ return transaction; }
SERIALIZER_RESULT serializer_init(const char* overrideSchemaNamespace) { SERIALIZER_RESULT result; /* Codes_SRS_SCHEMALIB_99_074:[serializer_init when already initialized shall return SERIALIZER_ALREADY_INIT.] */ if (g_AgentState != AGENT_NOT_INITIALIZED) { result = SERIALIZER_ALREADY_INIT; LogError("(result = %s)\r\n", ENUM_TO_STRING(SERIALIZER_RESULT, result)); } else { /* Codes_SRS_SCHEMALIB_99_006:[ Initialize CodeFirst by a call to CodeFirst_Init.] */ /* Codes_SRS_SCHEMALIB_99_076:[serializer_init shall pass the value of overrideSchemaNamespace argument to CodeFirst_Init.] */ if (CodeFirst_Init(overrideSchemaNamespace) != CODEFIRST_OK) { /* Codes_SRS_SCHEMALIB_99_007:[ On error SERIALIZER_CODEFIRST_INIT_FAILED shall be returned.] */ result = SERIALIZER_CODEFIRST_INIT_FAILED; LogError("(result = %s)\r\n", ENUM_TO_STRING(SERIALIZER_RESULT, result)); } else { /* Codes_SRS_SCHEMALIB_99_075:[When an serializer_init call fails for any reason the previous initialization state shall be preserved. The initialized state shall only be changed on a succesfull Init.] */ g_AgentState = AGENT_INITIALIZED; /* Codes_SRS_SCHEMALIB_99_073:[On success serializer_init shall return SERIALIZER_OK.] */ result = SERIALIZER_OK; } } return result; }
/*produces a string in *destination that is equal to name: value*/ HTTP_HEADERS_RESULT HTTPHeaders_GetHeader(HTTP_HEADERS_HANDLE handle, size_t index, char** destination) { HTTP_HEADERS_RESULT result = HTTP_HEADERS_OK; /*Codes_SRS_HTTP_HEADERS_99_028:[ The function shall return NULL if the handle is invalid.]*/ /*Codes_SRS_HTTP_HEADERS_99_032:[ The function shall return HTTP_HEADERS_INVALID_ARG if the destination is NULL]*/ if ( (handle == NULL) || (destination == NULL) ) { result = HTTP_HEADERS_INVALID_ARG; LogError("invalid arg (NULL), result= %s", ENUM_TO_STRING(HTTP_HEADERS_RESULT, result)); } /*Codes_SRS_HTTP_HEADERS_99_029:[ The function shall return HTTP_HEADERS_INVALID_ARG if index is not valid (for example, out of range) for the currently stored headers.]*/ else { HTTP_HEADERS_HANDLE_DATA* handleData = (HTTP_HEADERS_HANDLE_DATA*)handle; const char*const* keys; const char*const* values; size_t headerCount; if (Map_GetInternals(handleData->headers, &keys, &values, &headerCount) != MAP_OK) { /*Codes_SRS_HTTP_HEADERS_99_034:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs]*/ result = HTTP_HEADERS_ERROR; LogError("Map_GetInternals failed, result= %s", ENUM_TO_STRING(HTTP_HEADERS_RESULT, result)); } else { /*Codes_SRS_HTTP_HEADERS_99_029:[ The function shall return HTTP_HEADERS_INVALID_ARG if index is not valid (for example, out of range) for the currently stored headers.]*/ if (index >= headerCount) { result = HTTP_HEADERS_INVALID_ARG; LogError("index out of bounds, result= %s", ENUM_TO_STRING(HTTP_HEADERS_RESULT, result)); } else { *destination = (char*)malloc(strlen(keys[index]) + COLON_AND_SPACE_LENGTH + strlen(values[index]) + 1); if (*destination == NULL) { /*Codes_SRS_HTTP_HEADERS_99_034:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs]*/ result = HTTP_HEADERS_ERROR; LogError("unable to malloc, result= %s", ENUM_TO_STRING(HTTP_HEADERS_RESULT, result)); } else { /*Codes_SRS_HTTP_HEADERS_99_016:[ The function shall store the name:value pair in such a way that when later retrieved by a call to GetHeader it will return a string that shall strcmp equal to the name+": "+value.]*/ /*Codes_SRS_HTTP_HEADERS_99_027:[ Calling this API shall produce the string value+": "+pair) for the index header in the *destination parameter.]*/ strcpy(*destination, keys[index]); strcat(*destination, COLON_AND_SPACE); strcat(*destination, values[index]); /*Codes_SRS_HTTP_HEADERS_99_035:[ The function shall return HTTP_HEADERS_OK when the function executed without error.]*/ result = HTTP_HEADERS_OK; } } } } return result; }
LOCK_RESULT Unlock(LOCK_HANDLE handle) { LOCK_RESULT result; if (handle == NULL) { /*SRS_LOCK_99_011:[ This API on NULL handle passed returns LOCK_ERROR]*/ result = LOCK_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(LOCK_RESULT, result)); } else { if (pthread_mutex_unlock((pthread_mutex_t*)handle) == 0) { /*SRS_LOCK_99_009:[ This API on success should return LOCK_OK]*/ result = LOCK_OK; } else { /*SRS_LOCK_99_010:[ This API on error should return LOCK_ERROR]*/ result = LOCK_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(LOCK_RESULT, result)); } } return result; }
HTTP_HEADERS_RESULT HTTPHeaders_GetHeaderCount(HTTP_HEADERS_HANDLE handle, size_t* headerCount) { HTTP_HEADERS_RESULT result; /*Codes_SRS_HTTP_HEADERS_99_024:[ The function shall return HTTP_HEADERS_INVALID_ARG when an invalid handle is passed.]*/ /*Codes_SRS_HTTP_HEADERS_99_025:[ The function shall return HTTP_HEADERS_INVALID_ARG when headersCount is NULL.]*/ if ((handle == NULL) || (headerCount == NULL)) { result = HTTP_HEADERS_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(HTTP_HEADERS_RESULT, result)); } else { HTTP_HEADERS_HANDLE_DATA *handleData = (HTTP_HEADERS_HANDLE_DATA *)handle; const char*const* keys; const char*const* values; /*Codes_SRS_HTTP_HEADERS_99_023:[ Calling this API shall provide the number of stored headers.]*/ if (Map_GetInternals(handleData->headers, &keys, &values, headerCount) != MAP_OK) { /*Codes_SRS_HTTP_HEADERS_99_037:[ The function shall return HTTP_HEADERS_ERROR when an internal error occurs.]*/ result = HTTP_HEADERS_ERROR; LogError("Map_GetInternals failed, result= %s", ENUM_TO_STRING(HTTP_HEADERS_RESULT, result)); } else { /*Codes_SRS_HTTP_HEADERS_99_026:[ The function shall write in *headersCount the number of currently stored headers and shall return HTTP_HEADERS_OK]*/ result = HTTP_HEADERS_OK; } } return result; }
THREADAPI_RESULT ThreadAPI_Join(THREAD_HANDLE threadHandle, int *res) { THREADAPI_RESULT result; thrd_t* thrd_t_ptr = (thrd_t*)threadHandle; if (threadHandle == NULL) { result = THREADAPI_INVALID_ARG; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { switch (thrd_join(*thrd_t_ptr, res)) { default: case thrd_error: result = THREADAPI_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); break; case thrd_success: result = THREADAPI_OK; break; case thrd_nomem: result = THREADAPI_NO_MEMORY; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); break; } free(thrd_t_ptr); } return result; }
LOCK_RESULT Lock_Deinit(LOCK_HANDLE handle) { LOCK_RESULT result=LOCK_OK ; if (NULL == handle) { /*SRS_LOCK_99_013:[ This API on NULL handle passed returns LOCK_ERROR]*/ result = LOCK_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(LOCK_RESULT, result)); } else { /*SRS_LOCK_99_012:[ This API frees the memory pointed by handle]*/ if(pthread_mutex_destroy((pthread_mutex_t*)handle)==0) { free(handle); handle = NULL; } else { result = LOCK_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(LOCK_RESULT, result)); } } return result; }
DATA_MARSHALLER_HANDLE DataMarshaller_Create(SCHEMA_MODEL_TYPE_HANDLE modelHandle, bool includePropertyPath) { DATA_MARSHALLER_HANDLE result; DATA_MARSHALLER_INSTANCE* dataMarshallerInstance; /*Codes_SRS_DATA_MARSHALLER_99_019:[ DataMarshaller_Create shall return NULL if any argument is NULL.]*/ if ( (modelHandle == NULL) ) { result = NULL; LogError("(result = %s)", ENUM_TO_STRING(DATA_MARSHALLER_RESULT, DATA_MARSHALLER_INVALID_ARG)); } else if ((dataMarshallerInstance = (DATA_MARSHALLER_INSTANCE*)malloc(sizeof(DATA_MARSHALLER_INSTANCE))) == NULL) { /* Codes_SRS_DATA_MARSHALLER_99_048:[On any other errors not explicitly specified, DataMarshaller_Create shall return NULL.] */ result = NULL; LogError("(result = %s)", ENUM_TO_STRING(DATA_MARSHALLER_RESULT, DATA_MARSHALLER_ERROR)); } else { /*everything ok*/ dataMarshallerInstance->ModelHandle = modelHandle; dataMarshallerInstance->IncludePropertyPath = includePropertyPath; /*Codes_SRS_DATA_MARSHALLER_99_018:[ DataMarshaller_Create shall create a new DataMarshaller instance and on success it shall return a non NULL handle.]*/ result = dataMarshallerInstance; } return result; }
MULTITREE_RESULT MultiTree_GetChild(MULTITREE_HANDLE treeHandle, size_t index, MULTITREE_HANDLE *childHandle) { MULTITREE_RESULT result; /*Codes_SRS_MULTITREE_99_031:[ If parameter treeHandle is NULL, the function returns MULTITREE_INVALID_ARG.]*/ if (treeHandle == NULL) { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } /*Codes_SRS_MULTITREE_99_033:[ If parameter childHandle is NULL, the function shall return MULTITREE_INVALID_ARG.]*/ else if (childHandle == NULL) { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } else { MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA *)treeHandle; /*Codes_SRS_MULTITREE_99_032:[If parameter index is out of range, the function shall return MULTITREE_OUT_OF_RANGE_INDEX]*/ if (node->nChildren <= index) { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } else { /*Codes_SRS_MULTITREE_99_030:[ This function writes in *childHandle parameter the "index"th child of the node pointed to by parameter treeHandle]*/ /*Codes_SRS_MULTITREE_99_035:[ The function returns MULTITREE_OK when *childHandle contains a handle to the "index"th child of the tree designated by parameter treeHandle.]*/ *childHandle = node->children[index]; result = MULTITREE_OK; } } return result; }
boost::python::dict controller::getILockStatesDefinition() { std::map< VELA_ENUM::ILOCK_STATE, std::string > m; m[ VELA_ENUM::ILOCK_STATE::ILOCK_BAD ] = ENUM_TO_STRING( VELA_ENUM::ILOCK_STATE::ILOCK_BAD ); m[ VELA_ENUM::ILOCK_STATE::ILOCK_GOOD ] = ENUM_TO_STRING( VELA_ENUM::ILOCK_STATE::ILOCK_GOOD ); m[ VELA_ENUM::ILOCK_STATE::ILOCK_ERROR ] = ENUM_TO_STRING( VELA_ENUM::ILOCK_STATE::ILOCK_ERROR ); return enumStringMapToPythonDict( m ); }
//______________________________________________________________________________ std::map< VELA_ENUM::ILOCK_NUMBER, std::string > shutterInterface::getILockStatesStr( const std::string & name ) { std::map< VELA_ENUM::ILOCK_NUMBER, std::string > r; if( entryExists( allShutterData, name ) ) for( auto it : allShutterData[ name ].iLockStates ) r[ it.first ] = ENUM_TO_STRING( it.second ); else r[ VELA_ENUM::ILOCK_NUMBER::ILOCK_ERR ] = ENUM_TO_STRING( VELA_ENUM::ILOCK_STATE::ILOCK_ERROR ); return r; }
/* Codes_SRS_MULTITREE_99_053:[ MultiTree_AddChild shall add a new node with the name childName to the multi tree node identified by treeHandle] */ MULTITREE_RESULT MultiTree_AddChild(MULTITREE_HANDLE treeHandle, const char* childName, MULTITREE_HANDLE* childHandle) { MULTITREE_RESULT result; /* Codes_SRS_MULTITREE_99_055:[ If any argument is NULL, MultiTree_AddChild shall return MULTITREE_INVALID_ARG.] */ if ((treeHandle == NULL) || (childName == NULL) || (childHandle == NULL)) { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } else { MULTITREE_HANDLE_DATA* childNode; /* Codes_SRS_MULTITREE_99_060:[ The value associated with the new node shall be NULL.] */ CREATELEAF_RESULT res = createLeaf((MULTITREE_HANDLE_DATA*)treeHandle, childName, NULL, &childNode); switch (res) { default: { result = MULTITREE_ERROR; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); break; } case CREATELEAF_ALREADY_EXISTS: { /* Codes_SRS_MULTITREE_99_061:[ If a child node with the same name already exists, MultiTree_AddChild shall return MULTITREE_ALREADY_HAS_A_VALUE.] */ result = MULTITREE_ALREADY_HAS_A_VALUE; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); break; } case CREATELEAF_OK: { /* Codes_SRS_MULTITREE_99_062:[ The new node handle shall be returned in the childHandle argument.] */ *childHandle = childNode; /* Codes_SRS_MULTITREE_99_054:[ On success, MultiTree_AddChild shall return MULTITREE_OK.] */ result = MULTITREE_OK; break; } case CREATELEAF_EMPTY_NAME: { /* Tests_SRS_MULTITREE_99_066:[ If the childName argument is an empty string, MultiTree_AddChild shall return MULTITREE_EMPTY_CHILD_NAME.] */ result = MULTITREE_EMPTY_CHILD_NAME; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); break; } } } return result; }
THREADAPI_RESULT ThreadAPI_Create(THREAD_HANDLE* threadHandle, THREAD_START_FUNC func, void* arg) { THREADAPI_RESULT result; if ((threadHandle == NULL) || (func == NULL)) { result = THREADAPI_INVALID_ARG; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { THREAD_INSTANCE* threadInstance = malloc(sizeof(THREAD_INSTANCE)); if (threadInstance == NULL) { result = THREADAPI_NO_MEMORY; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { threadInstance->ThreadStartFunc = func; threadInstance->Arg = arg; int createResult = pthread_create(&threadInstance->Pthread_handle, NULL, ThreadWrapper, threadInstance); switch (createResult) { default: free(threadInstance); result = THREADAPI_ERROR; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); break; case 0: *threadHandle = threadInstance; result = THREADAPI_OK; break; case EAGAIN: free(threadInstance); result = THREADAPI_NO_MEMORY; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); break; } } } return result; }
IOTHUB_CLIENT_RESULT IoTHubClient_LL_SetOption(IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, const char* optionName, const void* value) { IOTHUB_CLIENT_RESULT result; /*Codes_SRS_IOTHUBCLIENT_LL_02_034: [If iotHubClientHandle is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.]*/ /*Codes_SRS_IOTHUBCLIENT_LL_02_035: [If optionName is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */ /*Codes_SRS_IOTHUBCLIENT_LL_02_036: [If value is NULL then IoTHubClient_LL_SetOption shall return IOTHUB_CLIENT_INVALID_ARG.] */ if ( (iotHubClientHandle == NULL) || (optionName == NULL) || (value == NULL) ) { result = IOTHUB_CLIENT_INVALID_ARG; LogError("invalid argument (NULL)\r\n"); } else { IOTHUB_CLIENT_LL_HANDLE_DATA* handleData = (IOTHUB_CLIENT_LL_HANDLE_DATA*)iotHubClientHandle; /*Codes_SRS_IOTHUBCLIENT_LL_02_038: [Otherwise, IoTHubClient_LL shall call the function _SetOption of the underlying transport and return what that function is returning.] */ result = handleData->IoTHubTransport_SetOption(handleData->transportHandle, optionName, value); if (result != IOTHUB_CLIENT_OK) { LogError("underlying transport failed, returned = %s\r\n", ENUM_TO_STRING(IOTHUB_CLIENT_RESULT, result)); } } return result; }
static HTTPAPI_RESULT ConstructHeadersString(HTTP_HEADERS_HANDLE httpHeadersHandle, char* headers, size_t headersBufferSize) { HTTPAPI_RESULT result; size_t headersCount; headers[0] = '\0'; if (HTTPHeaders_GetHeaderCount(httpHeadersHandle, &headersCount) != HTTP_HEADERS_OK) { result = HTTPAPI_HTTP_HEADERS_FAILED; LogError("(result = %s)\r\n", ENUM_TO_STRING(HTTPAPI_RESULT, result)); } else { size_t i; for (i = 0; i < headersCount; i++) { char tempBuffer[TEMP_BUFFER_SIZE]; if (HTTPHeaders_GetHeader(httpHeadersHandle, i, tempBuffer, TEMP_BUFFER_SIZE) == HTTP_HEADERS_OK) { strcat_s(headers, headersBufferSize, tempBuffer); strcat_s(headers, headersBufferSize, "\r\n"); } } result = HTTPAPI_OK; } return result; }
IOTHUB_MESSAGE_RESULT IoTHubMessage_GetByteArray(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const unsigned char** buffer, size_t* size) { IOTHUB_MESSAGE_RESULT result; if ( (iotHubMessageHandle == NULL) || (buffer == NULL) || (size == NULL) ) { /*Codes_SRS_IOTHUBMESSAGE_01_014: [If any of the arguments passed to IoTHubMessage_GetByteArray is NULL IoTHubMessage_GetByteArray shall return IOTHUBMESSAGE_INVALID_ARG.] */ LogError("invalid parameter (NULL) to IoTHubMessage_GetByteArray IOTHUB_MESSAGE_HANDLE iotHubMessageHandle=%p, const unsigned char** buffer=%p, size_t* size=%p\r\n", iotHubMessageHandle, buffer, size); result = IOTHUB_MESSAGE_INVALID_ARG; } else { IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; if (handleData->contentType != IOTHUBMESSAGE_BYTEARRAY) { /*Codes_SRS_IOTHUBMESSAGE_02_021: [If iotHubMessageHandle is not a iothubmessage containing BYTEARRAY data, then IoTHubMessage_GetData shall write in *buffer NULL and shall set *size to 0.] */ result = IOTHUB_MESSAGE_INVALID_ARG; LogError("invalid type of message %s\r\n", ENUM_TO_STRING(IOTHUBMESSAGE_CONTENT_TYPE, handleData->contentType)); } else { /*Codes_SRS_IOTHUBMESSAGE_01_011: [The pointer shall be obtained by using BUFFER_u_char and it shall be copied in the buffer argument.]*/ *buffer = BUFFER_u_char(handleData->value.byteArray); /*Codes_SRS_IOTHUBMESSAGE_01_012: [The size of the associated data shall be obtained by using BUFFER_length and it shall be copied to the size argument.]*/ *size = BUFFER_length(handleData->value.byteArray); result = IOTHUB_MESSAGE_OK; } } return result; }
//______________________________________________________________________________ void shutterInterface::staticEntryShutterMonitor( const event_handler_args args ) { /// recast args.usr ( a void * ) to a monitor struct pointer shutterStructs::monitorStuct * ms = reinterpret_cast<shutterStructs::monitorStuct*>(args.usr); /// Not sure how to decode these apart from trial and error /// you can test with DBF_STRING as the callback type if( *(unsigned short*)args.dbr == 0 ) ms -> shutObj -> shutterState = VELA_ENUM::SHUTTER_STATE::SHUTTER_CLOSED; else if( *(unsigned short*)args.dbr == 1 ) ms -> shutObj -> shutterState = VELA_ENUM::SHUTTER_STATE::SHUTTER_OPEN; else ms -> shutObj -> shutterState = VELA_ENUM::SHUTTER_STATE::SHUTTER_ERROR; /// make debug messages easier to understand by using ENUM_TO_STRING ms -> interface -> debugMessage( ms -> shutObj -> name, " new state = ", ENUM_TO_STRING(ms->shutObj -> shutterState )); /// If subscribed to DBF_STRING use this to get the message //char * val = (char *)args.dbr; /// now we can switch based on the monitor type and then update the correct part of the shutter object data using val /// For the shutter this is basically redundant, there is only one monitor the "Sta" /// (apart from interlocks, these are handled in the base class) // switch( lms.monType ) // { // case shutterStructs::Sta: // .... // case SomeOtherPVType: // .... // } }
foreach (TransactionProxy* transaction, m_transactions) { QVariantMap props; props["name"] = transaction->name(); props["data"] = transaction->data(); props["role"] = ENUM_TO_STRING(Role,transaction->role()); tlist.append(props); }
THREADAPI_RESULT ThreadAPI_Join(THREAD_HANDLE threadHandle, int *res) { THREADAPI_RESULT result = THREADAPI_OK; if (threadHandle == NULL) { result = THREADAPI_INVALID_ARG; LogError("(result = %s)\r\n", ENUM_TO_STRING(THREADAPI_RESULT, result)); } else { DWORD returnCode = WaitForSingleObject(threadHandle, INFINITE); if( returnCode != WAIT_OBJECT_0) { result = THREADAPI_ERROR; LogError("Error waiting for Single Object. Return Code: %d. Error Code: %d\r\n", returnCode); } else if((res != NULL) && !GetExitCodeThread(threadHandle, res)) //If thread end is signaled we need to get the Thread Exit Code; { DWORD errorCode = GetLastError(); result = THREADAPI_ERROR; LogError("Error Getting Exit Code. Error Code: %d.\r\n", errorCode); } CloseHandle(threadHandle); } return result; }
void sendCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result, void* userContextCallback) { int messageTrackingId = (intptr_t)userContextCallback; (void)printf("Message Id: %d Received.\r\n", messageTrackingId); (void)printf("Result Call Back Called! Result is: %s \r\n", ENUM_TO_STRING(IOTHUB_CLIENT_CONFIRMATION_RESULT, result)); }
static void on_umock_c_error( UMOCK_C_ERROR_CODE error_code ) { char temp_str[256]; (void)snprintf(temp_str, sizeof(temp_str), "umock_c reported error :%s", ENUM_TO_STRING(UMOCK_C_ERROR_CODE, error_code)); ASSERT_FAIL(temp_str); }
//______________________________________________________________________________ std::map< VELA_ENUM::ILOCK_NUMBER, std::string > beamPositionMonitorInterface::getILockStatesStr( const std::string & name ) { std::map< VELA_ENUM::ILOCK_NUMBER, std::string > r; auto iter = allBPMData.find( name ); if( iter != allBPMData.end() ) for( auto it : iter -> second.iLockStates ) r[ it.first ] = ENUM_TO_STRING( it.second ); return r; }
DATA_PUBLISHER_HANDLE DataPublisher_Create(SCHEMA_MODEL_TYPE_HANDLE modelHandle, bool includePropertyPath) { DATA_PUBLISHER_HANDLE result; DATA_PUBLISHER_INSTANCE* dataPublisherInstance; /* Codes_SRS_DATA_PUBLISHER_99_042:[ If a NULL argument is passed to it, DataPublisher_Create shall return NULL.] */ if ( (modelHandle == NULL) ) { result = NULL; LogError("(result = %s)\r\n", ENUM_TO_STRING(DATA_PUBLISHER_RESULT, DATA_PUBLISHER_INVALID_ARG)); } else if ((dataPublisherInstance = (DATA_PUBLISHER_INSTANCE*)malloc(sizeof(DATA_PUBLISHER_INSTANCE))) == NULL) { /* Codes_SRS_DATA_PUBLISHER_99_047:[ For any other error not specified here, DataPublisher_Create shall return NULL.] */ result = NULL; LogError("(result = %s)\r\n", ENUM_TO_STRING(DATA_PUBLISHER_RESULT, DATA_PUBLISHER_ERROR)); } else { /* Codes_SRS_DATA_PUBLISHER_99_043:[ DataPublisher_Create shall initialize and hold a handle to a DataMarshaller instance.] */ /* Codes_SRS_DATA_PUBLISHER_01_001: [DataPublisher_Create shall pass the includePropertyPath argument to DataMarshaller_Create.] */ if ((dataPublisherInstance->DataMarshallerHandle = DataMarshaller_Create(modelHandle, includePropertyPath)) == NULL) { free(dataPublisherInstance); /* Codes_SRS_DATA_PUBLISHER_99_044:[ If the creation of the DataMarshaller instance fails, DataPublisher_Create shall return NULL.] */ result = NULL; LogError("(result = %s)\r\n", ENUM_TO_STRING(DATA_PUBLISHER_RESULT, DATA_PUBLISHER_MARSHALLER_ERROR)); } else { dataPublisherInstance->ModelHandle = modelHandle; /* Codes_SRS_DATA_PUBLISHER_99_041:[ DataPublisher_Create shall create a new DataPublisher instance and return a non-NULL handle in case of success.] */ result = dataPublisherInstance; } } return result; }
/* Codes_SRS_MULTITREE_99_063:[ MultiTree_GetChildByName shall retrieve the handle of the child node childName from the treeNode node.] */ MULTITREE_RESULT MultiTree_GetChildByName(MULTITREE_HANDLE treeHandle, const char* childName, MULTITREE_HANDLE *childHandle) { MULTITREE_RESULT result; /* Codes_SRS_MULTITREE_99_065:[ If any argument is NULL, MultiTree_GetChildByName shall return MULTITREE_INVALID_ARG.] */ if ((treeHandle == NULL) || (childHandle == NULL) || (childName == NULL)) { result = MULTITREE_INVALID_ARG; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } else { MULTITREE_HANDLE_DATA * node = (MULTITREE_HANDLE_DATA *)treeHandle; size_t i; for (i = 0; i < node->nChildren; i++) { if (strcmp(node->children[i]->name, childName) == 0) { break; } } if (i == node->nChildren) { /* Codes_SRS_MULTITREE_99_068:[ If the specified child is not found, MultiTree_GetChildByName shall return MULTITREE_CHILD_NOT_FOUND.] */ result = MULTITREE_CHILD_NOT_FOUND; LogError("(result = %s)", ENUM_TO_STRING(MULTITREE_RESULT, result)); } else { /* Codes_SRS_MULTITREE_99_067:[ The child node handle shall be returned in the childHandle argument.] */ *childHandle = node->children[i]; /* Codes_SRS_MULTITREE_99_064:[ On success, MultiTree_GetChildByName shall return MULTITREE_OK.] */ result = MULTITREE_OK; } } return result; }
//______________________________________________________________________________ void scopeConfigReader::addToPVStruct( std::vector< scopeStructs::pvStruct > & pvStruct_v, const std::vector<std::string> &keyVal ) { if( stringIsSubString( keyVal[0], "SUFFIX" ) ) { pvStruct_v.push_back( scopeStructs::pvStruct() ); /// Any way to avoid the ladders? pvStruct_v.back().pvSuffix = keyVal[1]; // NUMBER PVs if( keyVal[0] == UTL::PV_SUFFIX_P1 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::P1; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::NUM; } else if( keyVal[0] == UTL::PV_SUFFIX_P2 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::P2; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::NUM; } else if( keyVal[0] == UTL::PV_SUFFIX_P3 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::P3; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::NUM; } else if( keyVal[0] == UTL::PV_SUFFIX_P4 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::P4; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::NUM; } // TRACE PVs else if( keyVal[0] == UTL::PV_SUFFIX_TR1 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::TR1; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::ARRAY; } else if( keyVal[0] == UTL::PV_SUFFIX_TR2 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::TR2; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::ARRAY; } else if( keyVal[0] == UTL::PV_SUFFIX_TR3 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::TR3; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::ARRAY; } else if( keyVal[0] == UTL::PV_SUFFIX_TR4 ) { pvStruct_v.back().pvType = scopeStructs::SCOPE_PV_TYPE::TR4; pvStruct_v.back().scopeType = scopeStructs::SCOPE_TYPE::ARRAY; } debugMessage("Added ", pvStruct_v.back().pvSuffix, " suffix for ", ENUM_TO_STRING( pvStruct_v.back().pvType) ) ; } else addCOUNT_MASK_OR_CHTYPE( pvStruct_v, keyVal ); }