[GME-commit] GMESRC/GME/MgaUtil MgaEventLogger.rgs,NONE,1.1 MgaEventLogger.h,NONE,1.1 MgaEventLogger.cpp,NONE,1.1

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Thu Jun 10 18:07:45 CDT 2004


Update of /var/lib/gme/GMESRC/GME/MgaUtil
In directory braindrain:/tmp/cvs-serv23201/GME/MgaUtil

Added Files:
	MgaEventLogger.rgs MgaEventLogger.h MgaEventLogger.cpp 
Log Message:
added IMgaEventLogger

CVS User: brianw

--- NEW FILE: MgaEventLogger.rgs ---
HKCR
{
	Mga.MgaEventLogger.1 = s 'MgaEventLogger Class'
	{
		CLSID = s '{98C2F832-0209-45c9-B665-829B88AA9399}'
	}
	Mga.MgaEventLogger = s 'MgaEventLogger Class'
	{
		CLSID = s '{98C2F832-0209-45c9-B665-829B88AA9399}'
		CurVer = s 'Mga.MgaEventLogger.1'
	}
	NoRemove CLSID
	{
		ForceRemove {98C2F832-0209-45c9-B665-829B88AA9399} = s 'MgaEventLogger Class'
		{
			ProgID = s 'Mga.MgaEventLogger.1'
			VersionIndependentProgID = s 'Mga.MgaEventLogger'
			ForceRemove 'Programmable'
			InprocServer32 = s '%MODULE%'
			{
				val ThreadingModel = s 'Apartment'
			}
			'TypeLib' = s '{98C2F832-0209-45c9-B665-829B88AA9399}'
		}
	}
}

--- NEW FILE: MgaEventLogger.h ---
// MgaEventLogger.h: interface for the CMgaEventLogger class.
//
//////////////////////////////////////////////////////////////////////

#ifndef MGA_MGAEVENTLOGGER_H
#define MGA_MGAEVENTLOGGER_H

#include <stdio.h>
#include <direct.h>

class ATL_NO_VTABLE CMgaEventLogger :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CMgaEventLogger, &CLSID_MgaEventLogger>,
	public IDispatchImpl<IMgaEventLogger, &IID_IMgaEventLogger, &LIBID_MGAUTILLib>  
{
public:
	CMgaEventLogger();
	~CMgaEventLogger();

DECLARE_REGISTRY_RESOURCEID(IDR_MGAEVENTLOGGER)

DECLARE_CLASSFACTORY_SINGLETON(CMgaEventLogger)

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CMgaEventLogger)
	COM_INTERFACE_ENTRY(IMgaEventLogger)
	//COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

public:
	STDMETHOD(LogEvent)(BSTR eventMsg);
	STDMETHOD(Initialize)();
	STDMETHOD(StopLogging)();
	STDMETHOD(EmergencyEvent)();

private:
	FILE *EventLog;
	bool initialized;
	bool newLine;

};

#endif // !defined(MGA_MGAEVENTLOGGER_H)

--- NEW FILE: MgaEventLogger.cpp ---
// MgaEventLogger.cpp: implementation of the CMgaEventLogger class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MgaEventLogger.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMgaEventLogger::CMgaEventLogger():initialized(false),newLine(true)
{
}

CMgaEventLogger::~CMgaEventLogger()
{

}

STDMETHODIMP CMgaEventLogger::LogEvent(BSTR eventMsg)
{
	if(initialized)
	{
		CString s(eventMsg);
		if(newLine)
		{
			CTime time = CTime::GetCurrentTime();
			CString CurrentTime = time.Format("%b %d, %H:%M:%S ");
			fprintf(EventLog,CurrentTime);
			newLine = false;
		}
		if(s.Find("\r\n")!=-1)
		{
			newLine = true;
		}
		fprintf(EventLog,s);
		fflush(EventLog);
	}
	return S_OK;
}

STDMETHODIMP CMgaEventLogger::Initialize()
{
	if(!initialized) //if already initialized, don't do anything
	{
		CString path;
		char gmepath[200];
		if(SHGetSpecialFolderPath( NULL, gmepath, CSIDL_APPDATA, true)) //most likely C:\Documents and Settings\<username>\Application Data
		{
			path = CString(gmepath) + "\\GME"; // add \GME to the path
			_mkdir(path.GetBuffer(4)); //in case GME dir not there, make it, if this function fails because GME already exists, don't care
			CTime time = CTime::GetCurrentTime(); //to make unique logfile names
			CString CurrentTime = time.Format( "\\GME_%b-%d_%H.%M.%S.log" );
			EventLog = fopen(path+CurrentTime,"w");

			if (EventLog != NULL) //fopen succeded
			{	
				initialized = true;
				newLine = true;
				CComBSTR b = "CMgaEventLogger::Initialize\r\n";
				LogEvent(b);
			}
		}
	}
	return S_OK;
}

STDMETHODIMP CMgaEventLogger::StopLogging()
{
	if(initialized)
	{
		CComBSTR b = "CMgaEventLogger::StopLogging\r\n";
		LogEvent(b);
		fflush(EventLog);
		fclose(EventLog);
	}
	initialized = false;
	EventLog = NULL;
	return S_OK;
}

STDMETHODIMP CMgaEventLogger::EmergencyEvent()
{
	CComBSTR b = "CMgaEventLogger::EmergencyEvent\r\n";
	LogEvent(b);
	StopLogging();
	return S_OK;
}


More information about the GME-commit mailing list