HRESULT CDIL_CAN_STUB::CAN_PerformInitOperations(void) { HRESULT hResult = S_FALSE; // Initialize the critical section InitializeCriticalSection(&sg_CSBroker); // Create the notification event sg_hNotifyFinish = CreateEvent(NULL, false, false, NULL); if (NULL != sg_hNotifyFinish) { // Then create the broker worker thread sg_sBrokerObjBusEmulation.m_hActionEvent = CreateEvent(NULL, false, false, NULL); ResetEvent(sg_sBrokerObjBusEmulation.m_hActionEvent); sg_sBrokerObjBusEmulation.m_unActionCode = INACTION; if (sg_sBrokerObjBusEmulation.bStartThread(BrokerThreadBusEmulation)) { hResult = S_OK; } else { CloseHandle(sg_hNotifyFinish); sg_hNotifyFinish = NULL; } } return hResult; }
/* Function to start Msg read thread*/ BOOL bStartGraphReadThread() { BOOL bReturn = FALSE; //First stop the thread if running bStopGraphReadThread(); m_ouGraphReadThread.m_hActionEvent = NULL; m_ouGraphReadThread.m_unActionCode = IDLE; m_ouGraphReadThread.m_pBuffer = NULL; m_ouGraphReadThread.m_hActionEvent = m_ouMsgInterpretBuffer.hGetNotifyingEvent(); bReturn = m_ouGraphReadThread.bStartThread(SignalDataPlotterThread); return bReturn; }
HRESULT CSimENG::FinalConstruct() { // Initialise the random number generator srand((unsigned) time(NULL)); // To create the worker thread that relays messages to other nodes // First initialise the parameters sg_sThreadCtrlObj.m_hActionEvent = sg_MessageBuf.hGetNotifyingEvent(); sg_sThreadCtrlObj.m_pBuffer = &sg_MessageBuf; sg_sThreadCtrlObj.m_unActionCode = INVOKE_FUNCTION; // Now start the thread sg_sThreadCtrlObj.bStartThread(MsgDelegatingThread); //MessageBox(NULL, "in FinalConstruct()", "Member function", MB_OK); return S_OK; }
HRESULT Worker_Connect(ISimENG* pISimENGLoc, Base_WrapperErrorLogger* pIlogLoc) { if (GetCurrState() == STATE_PRIMORDIAL) { sg_acErrStr = "CAN_STUB_Connect called at STATE_PRIMORDIAL"; return S_FALSE; } else if (GetCurrState() != STATE_INITIALISED) { sg_pIlog->vLogAMessage(__FILE__, __LINE__, ("CAN_STUB_Connect called at improper state")); return S_FALSE; } sg_sParmRThreadStub.m_unActionCode = INVOKE_FUNCTION; if (sg_sParmRThreadStub.bStartThread(FlexMsgReadThreadProc_Stub) == FALSE) { sg_sParmRThreadStub.m_hActionEvent = NULL; // Unregister from the simulation engine for (UINT i = 0; i < sg_unClientCnt; i++) { sg_ushTempClientID = (USHORT)sg_asClientToBufMap[i].dwClientID; sg_hTmpClientHandle = sg_asClientToBufMap[i].hClientHandle; sg_hTmpPipeHandle = sg_asClientToBufMap[i].hPipeFileHandle; Worker_UnregisterClient(pISimENGLoc, pIlogLoc); sg_asClientToBufMap[i].dwClientID = 0; sg_asClientToBufMap[i].hClientHandle = NULL; sg_asClientToBufMap[i].hPipeFileHandle = NULL; } sg_pIlog->vLogAMessage(__FILE__, __LINE__, ("Unable to start the reading thread")); return S_FALSE; } // Reaching upto this point means all the necessary activities are over SetCurrState(STATE_REGISTERED); return S_OK; }
HRESULT CDIL_Ethernet_Interface:: Ethernet_StartHardware(void) { sg_bCurrState = STATE_HW_INTERFACE_SELECTED; //TODO: remove this line, added just to test VALIDATE_VALUE_RETURN_VAL(sg_bCurrState, STATE_HW_INTERFACE_SELECTED, ERR_IMPROPER_STATE); USES_CONVERSION; HRESULT hResult = S_OK; ResetEvent(g_hInformStopTx); //Connect to the network hResult = nConnect(TRUE); if (hResult == defERR_OK) { hResult = S_OK; sg_bCurrState = STATE_CONNECTED; // vCreateTimeModeMapping(g_hReadEventObject); } else { //log the error for open port failure vRetrieveAndLog(hResult, __FILE__, __LINE__); hResult = ERR_LOAD_HW_INTERFACE; } //If everything is ok start the read thread if (hResult == S_OK) { if (sg_sParmRThread.bStartThread(EthernetMsgReadThreadProc)) { hResult = S_OK; } else { sg_pIlog->vLogAMessage(A2T(__FILE__), __LINE__, _T(_("Could not start the read thread") )); } } return hResult; }