//------------------------------------------------------------------------ // // VisDataRenderList.cpp // // Handled rendiner a Vis, based on a DataRender. See the .H for more // info. // // ------------------------------------------------------------------- // * COPYRIGHT 2001, Greg Ratajik and Ratajik Software * // * All rights Reserved * // ------------------------------------------------------------------- // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // More information about this program can be found at: // http://www.ratajik.com/VisInterface // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-21-01 Ratajik Initial Development //------------------------------------------------------------------------ #include "stdafx.h" #include "VisDataRender.h" //------------------------------------------------------------------------ // // Function: WorkerThread // // Description: This thread will loop until the sem is unlocked by the // parent. Until that happens, it load the waveform // from the Data Render and Renders it via the Vis. // // Parms: LPVOID - Pointer to the CVisDataRender that made us. // // Return: UINT - comp code. // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-21-01 Ratajik Initial Development //_________________________________________________________________________ UINT WorkerThread(LPVOID lpParam) { CVisDataRender *pDataRender = (CVisDataRender *)lpParam; ASSERT(pDataRender != NULL); CSingleLock singleLock(&pDataRender->m_semStop); // // Run into the StopRendering() method is called // in the wrapper class. // while(pDataRender->m_SingleLock.IsLocked()) { // // Call the pass DataLoader, letting it load the data // pDataRender->m_pLoader->LoadData(pDataRender->m_pInterface->GetWaveformDataLeft (), pDataRender->m_pInterface->GetWaveformDataRight(), pDataRender->m_pInterface->GetSpectrumDataLeft (), pDataRender->m_pInterface->GetSpectrumDataRight()) ; // // Call the Vis and let it render // pDataRender->m_pInterface->Render(); // // Don't thrash the CPU. // Sleep(1); } // // Self-delete // pDataRender->m_pThread = NULL; // // Let our parent know we are stopped // pDataRender->m_SingleLock.Lock(); //TRACE0("2:Render done.\n"); return(0); } //------------------------------------------------------------------------ // // Method: Ctor // // Description: Ctor for the class. Call StartRendering() to actually // start. // // Parms: CWnd * - The parent window // CVisInterface * - The vis to render // CVisDataLoader * - The loader to use to load the wave and // spec channels. // // Return: N/A // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-21-01 Ratajik Initial Development //_________________________________________________________________________ CVisDataRender::CVisDataRender(CWnd *pParentWnd, CVisInterface *pInterface, CVisDataLoader *pLoader) : m_pParentWnd(pParentWnd), m_pInterface(pInterface), m_pLoader(pLoader), m_pThread(NULL), m_SingleLock(&m_semStop) { } //------------------------------------------------------------------------ // // Method: StartRendering // // Description: Start loading data and rendering it. This actually starts // a worker thread. // // Parms: void // // Return: void // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-21-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisDataRender::StartRendering( void ) { // // Already running. // if(m_pThread != NULL) return(true); // // Lock the "stop" sem. // m_SingleLock.Lock(); // // Start the thread. // m_pThread = AfxBeginThread(WorkerThread, (void *)this); if(m_pThread != NULL) return(true); else return(false); } //------------------------------------------------------------------------ // // Method: StopRendering // // Description: Stop the render thread. This will not return until the // thread has actually stopped. // // Parms: void // // Return: void // // Exceptions: N/A // // C H A N G E L O G // ===================================================================== // Change ID Date Programmer Description // ============ ========= =========== ================================ // 02-21-01 Ratajik Initial Development //_________________________________________________________________________ bool CVisDataRender::StopRendering ( void ) { //TRACE0("1:Req Render stop.\n"); // // By unlocking this sem, we are telling the thread // to stop. // m_SingleLock.Unlock(); // // Wait until it actually stopped (if you don't do this, // and exit the program before the thread stops, it can cause // a trap. // while(!m_SingleLock.IsLocked()) Sleep(1); //TRACE0("3:Render Reported stop, returning.\n"); return(true); }