STDMETHODIMP TCUtilImpl::CreateObject(BSTR bstrProgID, BSTR bstrComputer, IUnknown** ppUnk) { // Initialize the [out] parameter CLEAROUT(ppUnk, (IUnknown*)NULL); // Convert the specified ProgID to a CLSID CLSID clsid; if (!BSTRLen(bstrProgID)) return E_INVALIDARG; RETURN_FAILED(CLSIDFromProgID(bstrProgID, &clsid)); // Initialize the COSERVERINFO and MULTI_QI structures COSERVERINFO csi = {0, bstrComputer, NULL, 0}; MULTI_QI mqi[] = { {&IID_IUnknown , NULL, S_OK}, {&IID_IDispatch , NULL, S_OK}, {&IID_IConnectionPointContainer, NULL, S_OK}, }; const static ULONG cMQI = sizeofArray(mqi); // Determine if the specified computer name is definitely local bool bLocalForSure = true; if (BSTRLen(bstrComputer)) { TCHAR szLocal[MAX_COMPUTERNAME_LENGTH + 1]; DWORD cchLocal = sizeofArray(szLocal); GetComputerName(szLocal, &cchLocal); USES_CONVERSION; bLocalForSure = !_tcsicmp(szLocal, OLE2CT(bstrComputer)); } DWORD dwClsCtx = bLocalForSure ? CLSCTX_SERVER : CLSCTX_REMOTE_SERVER; // Attempt to create the instance HRESULT hr = CoCreateInstanceEx(clsid, NULL, dwClsCtx, &csi, cMQI, mqi); if (FAILED(hr)) { _TRACE_BEGIN _TRACE_PART1("TCCreateObject failed: hr=0x%08X", hr); _TRACE_PART1(", dwClsCtx=%hs", (CLSCTX_SERVER == dwClsCtx) ? "CLSCTX_SERVER" : "CLSCTX_REMOTE_SERVER"); _TRACE_PART1(", ProgID=\"%ls\"", bstrProgID); _TRACE_PART1(", Computer= \"%ls\"\n", bstrComputer ? bstrComputer : L""); _TRACE_END return hr; } // Copy the IUnknown interface pointer to the [out] parameter *ppUnk = mqi[0].pItf; // Release each interface not being returned for (ULONG i = 1; i < cMQI; ++i) if (mqi[i].pItf) mqi[i].pItf->Release(); // Return the result of the QI for IUnknown return mqi[0].hr; }
CPigSessionEventSink::CPigSessionEventSink() : m_pSession(NULL), m_dwGITCookie(0) { // #define CPigSessionEventSink_TRACE_CONSTRUCTION #ifdef CPigSessionEventSink_TRACE_CONSTRUCTION _TRACE_BEGIN DWORD id = GetCurrentThreadId(); _TRACE_PART2("CPigSessionEventSink::CPigSessionEventSink(): ThreadId = %d (0x%X)\n", id, id); _TRACE_PART1("\tRaw pointer = 0x%08X", this); _TRACE_PART1(", IAGCEventSink* = 0x%08X\n", static_cast<IAGCEventSink*>(this)); _TRACE_END #endif // !CPigSessionEventSink_TRACE_CONSTRUCTION }
STDMETHODIMP CPigSessionEventSink::OnEventTriggered(IAGCEvent* pEvent) { assert(m_pSession); #define CPigSessionEventSink_TRACE_OnEventTriggered #ifdef CPigSessionEventSink_TRACE_OnEventTriggered _TRACE_BEGIN DWORD id = GetCurrentThreadId(); _TRACE_PART2("CPigSessionEventSink::OnEventTriggered(): ThreadId = %d (0x%X)\n", id, id); _TRACE_PART1("\tRaw pointer = 0x%08X", this); _TRACE_PART1(", IAGCEventSink* = 0x%08X\n", static_cast<IAGCEventSink*>(this)); _TRACE_PART1("\tIAGCEvent* = 0x%08X", pEvent); _TRACE_PART1(", refcount = %d\n", m_dwRef); _TRACE_END #endif // !CPigSessionEventSink_OnEventTriggered m_pSession->Fire_OnEvent(pEvent); return S_OK; }
HRESULT CAdminSession::FinalConstruct() { // #define CAdminSession_TRACE_CONSTRUCTION #ifdef CAdminSession_TRACE_CONSTRUCTION _TRACE_BEGIN DWORD id = GetCurrentThreadId(); _TRACE_PART2("CAdminSession::FinalConstruct(): ThreadId = %d (0x%X)\n", id, id); _TRACE_PART1("\tRaw pointer = 0x%08X\n", this); _TRACE_END #endif // CAdminSession_TRACE_CONSTRUCTION // Create the event sink object CComObject<CAdminSessionEventSink>* pEventSink = NULL; RETURN_FAILED(pEventSink->CreateInstance(&pEventSink)); pEventSink->AddRef(); pEventSink->Init(this); m_pEventSink = pEventSink; // Indicate success return S_OK; }
void CPigEngine::ProcessScriptDirChanges() { XLock lock(this); // Copy the map of scripts XScriptMap mapScripts(m_mapScripts); // Loop thru the "*.pig" files in the script directory WIN32_FIND_DATA ffd; USES_CONVERSION; LPSTR pszScriptDirPatt = OLE2A(m_bstrScriptDir + "*.pig"); TCFileFindHandle hff = FindFirstFile(pszScriptDirPatt, &ffd); bool bContinue = !hff.IsNull() && INVALID_HANDLE_VALUE != hff; while (bContinue) { // Do not process directories, temporary or hidden files const DWORD dwIgnoreAttributes = FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_TEMPORARY | FILE_ATTRIBUTE_HIDDEN; if (!(ffd.dwFileAttributes & dwIgnoreAttributes)) { // Attempt to find the file name in the map of scripts tstring strFile(ffd.cFileName); XScriptMapIt it = mapScripts.find(strFile); if (mapScripts.end() == it) AddScriptFile(&ffd, strFile); else { if (it->second->IsModified(&ffd)) ReloadScriptFile(&ffd, it); mapScripts.erase(it); } } // Get the next file in the directory bContinue = !!FindNextFile(hff, &ffd); } // Unload all files remaining in the local copy of the map of Scripts for (XScriptMapIt it = mapScripts.begin(); it != mapScripts.end(); ++it) UnloadScriptFile(it->first); /////////////////////////////////////////////////////////////////////////// // File Reconcilation is complete, now validate the files /////////////////////////////////////////////////////////////////////////// // Create a map of all behavior names, invalid or not XBehaviorMap mapGoodBadUgly; for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; // Get the collection of invoke commands for the new object XBehaviorMap mapCommands; ZSucceeded(GetInvokeCommands(pType, mapCommands)); // Add each invoke command to the map for (XBehaviorMapIt itCmd = mapCommands.begin(); itCmd != mapCommands.end(); ++itCmd) { mapGoodBadUgly.insert(*itCmd); debugf("inv command: %s\n", itCmd->first.c_str()); } } // Check for base behaviors that don't exist for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; if (pType->IsValid()) { tstring strBaseBehavior(pType->GetBaseBehaviorName()); if (strBaseBehavior.size() && _tcslen(strBaseBehavior.c_str())) { XBehaviorMapIt itFind = mapGoodBadUgly.find(strBaseBehavior); if (mapGoodBadUgly.end() == itFind) { RemoveInvokeCommands(pType); pType->SetBaseNonExistant(); } } } } // Check for recursive behavior derivations for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; if (pType->IsValid()) { std::set<tstring, ci_less> setNames; CPigBehaviorScriptType* pTypeBase = pType; while (!pTypeBase->GetBaseBehaviorName().empty()) { setNames.insert(pTypeBase->GetName()); if (setNames.end() == setNames.find(pTypeBase->GetBaseBehaviorName())) { XScriptMapIt itBase = mapGoodBadUgly.find(pTypeBase->GetBaseBehaviorName()); if (mapGoodBadUgly.end() != itBase) // KG- fix debug assert - was : m_mapBehaviors.end() != itBase { pTypeBase = itBase->second; continue; } } RemoveInvokeCommands(pType); pType->SetRecursionError(); break; } } } // Check for behaviors that have base behaviors with errors for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) { CPigBehaviorScriptType* pType = it->second; if (pType->IsValid()) { std::vector<CPigBehaviorScriptType*> vecBaseTypes; vecBaseTypes.push_back(pType); tstring strBaseBehavior(pType->GetBaseBehaviorName()); while (strBaseBehavior.size() && _tcslen(strBaseBehavior.c_str())) { XBehaviorMapIt itBase = mapGoodBadUgly.find(strBaseBehavior); assert(mapGoodBadUgly.end() != itBase); pType = itBase->second; vecBaseTypes.push_back(pType); strBaseBehavior = pType->GetBaseBehaviorName(); } std::vector<CPigBehaviorScriptType*>::reverse_iterator rit1, rit2; rit1 = rit2 = vecBaseTypes.rbegin(); for (++rit2; rit2 != vecBaseTypes.rend(); ++rit1, ++rit2) { CPigBehaviorScriptType* pTypeBase = *rit1; CPigBehaviorScriptType* pType = *rit2; if (!pTypeBase->IsValid() && pType->IsValid()) { RemoveInvokeCommands(pType); pType->SetBaseError(); } } } } // Compute the stats on how many good and bad scripts are available int nValid = 0; for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it) if (it->second->IsValid()) ++nValid; // Display the stats on how many good and bad scripts are available #ifdef _DEBUG _TRACE_BEGIN _TRACE_PART1("CPigEngine::ProcessScriptDirChanges(): %d scripts loaded, ", m_mapScripts.size()); _TRACE_PART1("%d appear to be valid.\n", nValid); _TRACE_END #endif // _DEBUG // Trigger an event _AGCModule.TriggerEvent(NULL, PigEventID_ScriptsLoaded, L"", -1, -1, -1, 2, "TotalCount", VT_I4, m_mapScripts.size(), "ValidCount", VT_I4, nValid); }
void CAGCEventLogger::LogEvent(IAGCEvent* pEvent, bool bSynchronous) { PRIVATE_ASSERTE(pEvent); XLock lock(this); // Determine if we can log to either event log type bool bLogToNT = m_bLoggingToNTEnabled && !m_shEventLog.IsNull(); bool bLogToDB = m_bLoggingToDBEnabled && m_ds.m_spInit != NULL; // Get the event ID AGCEventID idEvent; PRIVATE_VERIFYE(SUCCEEDED(pEvent->get_ID(&idEvent))); // Determine if the event is enabled for each event log type VARIANT_BOOL bEnabled; if (bLogToNT && NULL != m_spRangesNT && SUCCEEDED(m_spRangesNT->get_IntersectsWithValue(idEvent, &bEnabled))) bLogToNT = !!bEnabled; if (bLogToDB && NULL != m_spRangesDB && SUCCEEDED(m_spRangesDB->get_IntersectsWithValue(idEvent, &bEnabled))) bLogToDB = !!bEnabled; // Unlock the CritSec lock.Unlock(); // Do nothing if we're not logging this event anywhere if (!bLogToNT && !bLogToDB) return; // Find the event definition const CAGCEventDef::XEventDef* pEventDef = CAGCEventDef::find(idEvent); PRIVATE_ASSERTE(pEventDef); // Output the event to the debug monitor #if 0 && defined(_DEBUG) { CComBSTR bstrDescription, bstrSubjectName; PRIVATE_VERIFYE(SUCCEEDED(pEvent->get_Description(&bstrDescription))); PRIVATE_VERIFYE(SUCCEEDED(pEvent->get_SubjectName (&bstrSubjectName))); int cchDbg = bstrSubjectName.Length() + bstrDescription.Length() + 16; _TRACE_BEGIN_SIZE(cchDbg) if (bstrSubjectName.Length()) _TRACE_PART1("%ls:\n", (BSTR)bstrSubjectName); if (bstrDescription.Length()) _TRACE_PART1("%ls\n" , (BSTR)bstrDescription); _TRACE_END } #endif // defined(_DEBUG) // Log the event to the NT Event Log, if specified if (bLogToNT) { PRIVATE_ASSERTE(IsWinNT()); IAGCEventLoggerHookPtr spHook; get_HookForNTLogging(&spHook); if (NULL == spHook || S_FALSE == spHook->LogEvent(pEvent, VARBOOL(bSynchronous))) { XLock lockNT(this); if (m_bLoggingToNTEnabled && !m_shEventLog.IsNull()) { // Get the event severity WORD wSeverity = pEventDef->m_wSeverity; // Create the full event id (regarding the MC-generated id's) UINT nBits; switch (wSeverity) { case EVENTLOG_INFORMATION_TYPE: nBits = 0x01 << 30; break; case EVENTLOG_WARNING_TYPE : nBits = 0x02 << 30; break; case EVENTLOG_ERROR_TYPE : nBits = 0x03 << 30; break; case EVENTLOG_SUCCESS : nBits = 0x00 << 30; break; default : PRIVATE_ASSERTE(!"Bad severity code."); } DWORD dwEventID = nBits | idEvent; // Get the event replacement parameters CAGCEventDef::XParamStrings vecParamStrings; PRIVATE_VERIFYE(SUCCEEDED(CAGCEventDef::GetEventParameters(pEvent, vecParamStrings, pEventDef))); // mdvalley: prevent crashes when no %Parameter% in strings. // That took so long to figure out. WORD NumStrings = vecParamStrings.size(); LPCWSTR* lpStrings = NULL; if(NumStrings) lpStrings = (LPCWSTR*)(&(*vecParamStrings.begin())); // Report the event to the NT Event log ReportEventW(m_shEventLog, wSeverity, 0, dwEventID, NULL, vecParamStrings.size(), 0, // VS.Net 2003 port #if _MSC_VER >= 1310 lpStrings, NULL); // (LPCWSTR*)(&(*vecParamStrings.begin())), NULL); #else (LPCWSTR*)(vecParamStrings.begin()), NULL); #endif // Free the replacement parameters BSTR's for (CAGCEventDef::XParamStrings::iterator it = vecParamStrings.begin(); it != vecParamStrings.end(); ++it) SysFreeString(*it); } }