From: <ad...@us...> - 2003-02-13 10:50:21
|
Update of /cvsroot/bdadev/CleverTelly In directory sc8-pr-cvs1:/tmp/cvs-serv11441 Modified Files: CleverTelly.cpp CleverTelly.h StdAfx.h Added Files: Module.cpp Module.h Log Message: Split out Module stuff and tidy up auto generated ATL code --- NEW FILE: Module.cpp --- ///////////////////////////////////////////////////////////////////////////// // $Id: Module.cpp,v 1.1 2003/02/13 10:50:17 adcockj Exp $ ///////////////////////////////////////////////////////////////////////////// // CleverTelly - BDA DVB TV Application // Copyright (c) 2003 John Adcock. All rights reserved. ///////////////////////////////////////////////////////////////////////////// // // This file is subject to the terms of the GNU General Public License as // published by the Free Software Foundation. A copy of this license is // included with this software distribution in the file COPYING.txt. If you // do not have a copy, you may obtain a copy by writing to the Free // Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // // This software 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 // ///////////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "resource.h" #include "Module.h" // global instance of Module CExeModule _Module; const DWORD CExeModule::dwTimeOut = 5000; const DWORD CExeModule::dwPause = 1000; // Passed to CreateThread to monitor the shutdown event static DWORD WINAPI MonitorProc(void* pv) { CExeModule* p = (CExeModule*)pv; p->MonitorShutdown(); return 0; } LONG CExeModule::Unlock() { LONG l = CComModule::Unlock(); if (l == 0) { bActivity = true; SetEvent(hEventShutdown); // tell monitor that we transitioned to zero } return l; } //Monitors the shutdown event void CExeModule::MonitorShutdown() { while (1) { WaitForSingleObject(hEventShutdown, INFINITE); DWORD dwWait=0; do { bActivity = false; dwWait = WaitForSingleObject(hEventShutdown, dwTimeOut); } while (dwWait == WAIT_OBJECT_0); // timed out if (!bActivity && m_nLockCnt == 0) // if no activity let's really bail { #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) CoSuspendClassObjects(); if (!bActivity && m_nLockCnt == 0) #endif break; } } CloseHandle(hEventShutdown); PostThreadMessage(dwThreadID, WM_QUIT, 0, 0); } bool CExeModule::StartMonitor() { hEventShutdown = CreateEvent(NULL, false, false, NULL); if (hEventShutdown == NULL) { return false; } DWORD dwThreadID; HANDLE h = CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID); return (h != NULL); } ///////////////////////////////////////////////////////////////////////////// // CVS Log // // $Log: Module.cpp,v $ // Revision 1.1 2003/02/13 10:50:17 adcockj // Split out Module stuff and tidy up auto generated ATL code // // Revision 1.1.1.1 2003/02/13 10:19:07 adcockj // Initial Import // ///////////////////////////////////////////////////////////////////////////// --- NEW FILE: Module.h --- ///////////////////////////////////////////////////////////////////////////// // $Id: Module.h,v 1.1 2003/02/13 10:50:17 adcockj Exp $ ///////////////////////////////////////////////////////////////////////////// // CleverTelly - BDA DVB TV Application // Copyright (c) 2003 John Adcock. All rights reserved. ///////////////////////////////////////////////////////////////////////////// // // This file is subject to the terms of the GNU General Public License as // published by the Free Software Foundation. A copy of this license is // included with this software distribution in the file COPYING.txt. If you // do not have a copy, you may obtain a copy by writing to the Free // Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. // // This software 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 // ///////////////////////////////////////////////////////////////////////////// #pragma once //You may derive a class from CComModule and use it if you want to override //something, but do not change the name of _Module class CExeModule : public CComModule { public: LONG Unlock(); DWORD dwThreadID; HANDLE hEventShutdown; void MonitorShutdown(); bool StartMonitor(); bool bActivity; /// Time to wait for threads to finish up static const DWORD dwPause; /// time for EXE to be idle before shutting down static const DWORD dwTimeOut; }; extern CExeModule _Module; Index: CleverTelly.cpp =================================================================== RCS file: /cvsroot/bdadev/CleverTelly/CleverTelly.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** CleverTelly.cpp 13 Feb 2003 10:19:07 -0000 1.1.1.1 --- CleverTelly.cpp 13 Feb 2003 10:50:17 -0000 1.2 *************** *** 27,91 **** #include "MSVidCtlComp.h" - - const DWORD dwTimeOut = 5000; // time for EXE to be idle before shutting down - const DWORD dwPause = 1000; // time to wait for threads to finish up - - // Passed to CreateThread to monitor the shutdown event - static DWORD WINAPI MonitorProc(void* pv) - { - CExeModule* p = (CExeModule*)pv; - p->MonitorShutdown(); - return 0; - } - - LONG CExeModule::Unlock() - { - LONG l = CComModule::Unlock(); - if (l == 0) - { - bActivity = true; - SetEvent(hEventShutdown); // tell monitor that we transitioned to zero - } - return l; - } - - //Monitors the shutdown event - void CExeModule::MonitorShutdown() - { - while (1) - { - WaitForSingleObject(hEventShutdown, INFINITE); - DWORD dwWait=0; - do - { - bActivity = false; - dwWait = WaitForSingleObject(hEventShutdown, dwTimeOut); - } while (dwWait == WAIT_OBJECT_0); - // timed out - if (!bActivity && m_nLockCnt == 0) // if no activity let's really bail - { - #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) - CoSuspendClassObjects(); - if (!bActivity && m_nLockCnt == 0) - #endif - break; - } - } - CloseHandle(hEventShutdown); - PostThreadMessage(dwThreadID, WM_QUIT, 0, 0); - } - - bool CExeModule::StartMonitor() - { - hEventShutdown = CreateEvent(NULL, false, false, NULL); - if (hEventShutdown == NULL) - return false; - DWORD dwThreadID; - HANDLE h = CreateThread(NULL, 0, MonitorProc, this, 0, &dwThreadID); - return (h != NULL); - } - - CExeModule _Module; - BEGIN_OBJECT_MAP(ObjectMap) OBJECT_ENTRY(CLSID_MSVidCtlComp, CMSVidCtlComp) --- 27,30 ---- *************** *** 121,124 **** --- 60,64 ---- HRESULT hRes = CoInitialize(NULL); #endif + _ASSERTE(SUCCEEDED(hRes)); _Module.Init(ObjectMap, hInstance, &LIBID_CLEVERTELLYLib); *************** *** 151,163 **** { _Module.StartMonitor(); #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) ! hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, ! REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else ! hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, ! REGCLS_MULTIPLEUSE); #endif _ASSERTE(SUCCEEDED(hRes)); --- 91,103 ---- { _Module.StartMonitor(); + #if _WIN32_WINNT >= 0x0400 & defined(_ATL_FREE_THREADED) ! hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED); _ASSERTE(SUCCEEDED(hRes)); hRes = CoResumeClassObjects(); #else ! hRes = _Module.RegisterClassObjects(CLSCTX_LOCAL_SERVER, REGCLS_MULTIPLEUSE); #endif + _ASSERTE(SUCCEEDED(hRes)); *************** *** 180,189 **** while (GetMessage(&msg, 0, 0, 0)) { ! TranslateMessage(&msg); DispatchMessage(&msg); } _Module.RevokeClassObjects(); ! Sleep(dwPause); //wait for any threads to finish } --- 120,129 ---- while (GetMessage(&msg, 0, 0, 0)) { ! TranslateMessage(&msg); DispatchMessage(&msg); } _Module.RevokeClassObjects(); ! Sleep(CExeModule::dwPause); //wait for any threads to finish } *************** *** 197,200 **** --- 137,143 ---- // // $Log$ + // Revision 1.2 2003/02/13 10:50:17 adcockj + // Split out Module stuff and tidy up auto generated ATL code + // // Revision 1.1.1.1 2003/02/13 10:19:07 adcockj // Initial Import Index: CleverTelly.h =================================================================== RCS file: /cvsroot/bdadev/CleverTelly/CleverTelly.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** CleverTelly.h 13 Feb 2003 10:19:07 -0000 1.1.1.1 --- CleverTelly.h 13 Feb 2003 10:50:17 -0000 1.2 *************** *** 3,7 **** /* File created by MIDL compiler version 5.01.0164 */ ! /* at Thu Feb 13 10:13:41 2003 */ /* Compiler settings for C:\Source\Bdadev\CleverTelly\CleverTelly.idl: --- 3,7 ---- /* File created by MIDL compiler version 5.01.0164 */ ! /* at Thu Feb 13 10:23:31 2003 */ /* Compiler settings for C:\Source\Bdadev\CleverTelly\CleverTelly.idl: Index: StdAfx.h =================================================================== RCS file: /cvsroot/bdadev/CleverTelly/StdAfx.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** StdAfx.h 13 Feb 2003 10:19:08 -0000 1.1.1.1 --- StdAfx.h 13 Feb 2003 10:50:17 -0000 1.2 *************** *** 31,50 **** #include <Msvidctl.h> ! //You may derive a class from CComModule and use it if you want to override ! //something, but do not change the name of _Module ! class CExeModule : public CComModule ! { ! public: ! LONG Unlock(); ! DWORD dwThreadID; ! HANDLE hEventShutdown; ! void MonitorShutdown(); ! bool StartMonitor(); ! bool bActivity; ! }; ! extern CExeModule _Module; #include <atlcom.h> #include <atlhost.h> #include <atlctl.h> //{{AFX_INSERT_LOCATION}} --- 31,40 ---- #include <Msvidctl.h> ! #include "Module.h" ! #include <atlcom.h> #include <atlhost.h> #include <atlctl.h> + //{{AFX_INSERT_LOCATION}} |