GME  13
GMEEventLogger.h
Go to the documentation of this file.
00001 // GMEEventLogger.h: interface for the CGMEEventLogger class.
00002 //
00004 
00005 #if !defined(AFX_GMEEVENTLOGGER_H__A65D0066_7479_4B9B_8B3D_37EAAAD5C67E__INCLUDED_)
00006 #define AFX_GMEEVENTLOGGER_H__A65D0066_7479_4B9B_8B3D_37EAAAD5C67E__INCLUDED_
00007 
00008 #if _MSC_VER > 1000
00009 #pragma once
00010 #endif // _MSC_VER > 1000
00011 
00012 #include <stdio.h>
00013 #include <direct.h>
00014 #include "MgaUtil.h"
00015 
00016 #define GMEEVENTLOG_GUIOBJS(guiobjlist) \
00017 { \
00018         CString gmelog = "    "; \
00019         POSITION pos = guiobjlist.GetHeadPosition(); \
00020         while(pos) { \
00021                 CGuiObject *obj = guiobjlist.GetNext(pos); \
00022                 gmelog = gmelog + obj->GetName()+" "+obj->GetID()+", "; \
00023         } \
00024         gmelog = gmelog+"\r\n"; \
00025         CGMEEventLogger::LogGMEEvent(gmelog); \
00026 } \
00027 
00028 
00029 #define GMEEVENTLOG_GUIANNOTATORS(guiannlist) \
00030 { \
00031         CString gmelog = "    "; \
00032         POSITION pos = guiannlist.GetHeadPosition(); \
00033         while(pos) { \
00034                 CGuiAnnotator *ann = guiannlist.GetNext(pos); \
00035                 gmelog = gmelog + ann->GetName()+" "; \
00036         } \
00037         gmelog = gmelog+"\r\n"; \
00038         CGMEEventLogger::LogGMEEvent(gmelog); \
00039 } \
00040 
00041 
00042 #define GMEEVENTLOG_GUIFCOS(guifcolist) \
00043 { \
00044         CString gmelog = "    "; \
00045         POSITION pos = guifcolist.GetHeadPosition(); \
00046         while(pos) { \
00047                 CGuiFco *fco = guifcolist.GetNext(pos); \
00048                 gmelog = gmelog + fco->GetName()+" "+fco->GetID()+", "; \
00049         } \
00050         gmelog = gmelog+"\r\n"; \
00051         CGMEEventLogger::LogGMEEvent(gmelog); \
00052 } \
00053 
00054 class CGMEEventLogger  
00055 {
00056 public:
00057         CGMEEventLogger();
00058         virtual ~CGMEEventLogger();
00059          
00060 
00061         static void initialize(CString filePathAndName) //depracated
00062         {
00063                 initialize();
00064         };
00065 
00066         static void initialize()
00067         {
00068                 if( comLogger == NULL) // check introd by zolmol
00069                 {
00070                         COMTHROW( comLogger.CoCreateInstance(L"Mga.MgaEventLogger"));
00071                         COMTHROW( comLogger->StartLogging() );
00072                 }
00073         };
00074 
00075         static void StopLogging()
00076         {
00077                 if(comLogger != NULL)
00078                         COMTHROW( comLogger->StopLogging());
00079         };
00080 
00081         static void EmergencyEvent()
00082         {
00083                 if(comLogger != NULL)
00084                         COMTHROW( comLogger->EmergencyEvent());
00085         };
00086 
00087         static void LogGMEEvent(CString s)
00088         {
00089                 if(comLogger != NULL)
00090                 {
00091                         CComBSTR b = s;
00092                         COMTHROW( comLogger->LogEvent(b));
00093                 }
00094 
00095         };
00096 
00097         // %Z for first fco %z for second ONLY WORKS IN TRANSACTION - this function does not make it's own transaction
00098         static void GMEEventPrintf(const TCHAR *format, IMgaObject *objOne, IMgaObject *objTwo, ...) //Only works in Transaction!!!!!!!!!
00099         {
00100                 if(comLogger != NULL)
00101                 {
00102                         CString output(format);
00103                         if(output.Find(_T("%Z"))) {
00104                                 if(objOne == NULL)
00105                                         output.Replace(CString(_T("%Z")),CString(_T("")));
00106                                 else
00107                                 {
00108                                         CComBSTR ID;
00109                                         CComPtr<IMgaObject> ONE = objOne;
00110                                         COMTHROW(ONE->get_ID(&ID));
00111                                         output.Replace(CString(_T("%Z")),CString(ID));
00112                                 }
00113                         }
00114 
00115                         if(output.Find(_T("%z"))) {
00116                                 if(objTwo == NULL)
00117                                         output.Replace(CString(_T("%z")),CString(_T("")));
00118                                 else
00119                                 {
00120                                         CComBSTR ID;
00121                                         CComPtr<IMgaObject> TWO = objTwo;
00122                                         COMTHROW(TWO->get_ID(&ID));
00123                                         output.Replace(CString(_T("%z")),CString(ID));
00124                                 }
00125                         }
00126                         TCHAR buffer[250];
00127                         va_list v1;
00128                         va_start(v1,objTwo);
00129                         _vstprintf_s(buffer,output,v1);
00130                         va_end(v1);
00131 
00132                         CComBSTR b = buffer;
00133                         COMTHROW( comLogger->LogEvent(b));
00134 
00135                 }
00136 
00137         };
00138 
00139 
00140 private:
00141 
00142         static FILE *EventLog;
00143         static BOOL initialized;
00144         static BOOL newLine;
00145         static CComPtr<IMgaEventLogger> comLogger; //new com object that lives in MgaUtil
00146 
00147         
00148         
00149 
00150 };
00151 
00152 #endif // !defined(AFX_GMEEVENTLOGGER_H__A65D0066_7479_4B9B_8B3D_37EAAAD5C67E__INCLUDED_)
00153