hcp::Runtime::Runtime(hcp_tHost* osHost) { if (osHost->malloc_ == nullptr) { _state = nullptr; } else { _state = (hcp_tState*)osHost->malloc_(hcp_SizeOfState(),osHost->context); if (hcp_NewState(_state, osHost) != HCP_NOERROR) { if (osHost->free_ != nullptr) { osHost->free_(_state, osHost); _state = nullptr; } _state = nullptr; } else { auto error = HCP_INITIALIZEVECTOR(_state, &(_codecs.header), _codecs.fixed, hcp::tCodec, HCP_NULL, compareCodec, isCodec); if (error != HCP_NOERROR) { hcp_CloseState(_state); _state = nullptr; } // todo: logg this } } }
hcp_Int hcp_InitializeCommands(hcp_tState* pState, hcp_tCommandSet* pCommands, hcp_tModel* pTemplate) { hcp_Int error = HCP_INITIALIZEVECTOR(pState, &pCommands->header, pCommands->fixed, hcp_tCommand, HCP_NULL, hcp_CompareCommand, hcp_IsCommand); const hcp_Size_t length = pTemplate->commands.header.length; hcp_Size_t i = 0; for (i = 0; i < length; i++) { hcp_Size_t commandIndex = 0; error = hcp_PushEmpty(&pCommands->header, &commandIndex); if (error != HCP_NOERROR) { return error; } hcp_tCommand* command = (hcp_tCommand*)hcp_ValueAt(&pCommands->header, commandIndex); hcp_tCommandTemplate* t = (hcp_tCommandTemplate*)hcp_ValueAt(&pTemplate->commands.header, i); command->template_ = t; // create in-parameters error = hcp_InitializeParametersFromTemplate(pState, &command->inParams, &t->inParameters); if (error != HCP_NOERROR) { hcp_Pop(&pCommands->header, commandIndex); return error; } //create out-parameters error = hcp_InitializeParametersFromTemplate(pState, &command->outParams, &t->outParameters); if (error != HCP_NOERROR) { hcp_Pop(&pCommands->header, commandIndex); return error; } } return error; }
hcp_Int hcp_InitializeProtocol(hcp_tState* pState, hcp_tProtocol* pProtocol) { hcp_Int error = HCP_INITIALIZEVECTOR(pState, &pProtocol->header, pProtocol->fixed, hcp_tProtocolNode, HCP_NULL, hcp_CompareProtocolNode, hcp_IsProtocolNode); return error; }
hcp_Int hcp_InitializeCommandTemplates(hcp_tState* pState, hcp_tCommandTemplateSet* pTemplates) { hcp_Int error = HCP_INITIALIZEVECTOR(pState, &pTemplates->header, pTemplates->fixed, hcp_tCommandTemplate, HCP_NULL, hcp_CompareCommandTemplate, hcp_IsCommandTemplate); return error; }
hcp_Int hcp_InitializeParameterTemplates(hcp_tState* pState, hcp_tParameterTemplateSet* pParameterTemplates) { hcp_Int error = HCP_INITIALIZEVECTOR(pState, &pParameterTemplates->header, pParameterTemplates->fixed, hcp_tParameterTemplate, HCP_NULL, hcp_CompareParameterTemplate, hcp_IsParameterTemplate); return error; }