示例#1
0
CPigEngine::~CPigEngine()
{
  XLock lock(this);

  // Release the Pigs collection object
  if (m_pPigs)
    m_pPigs->Release();

  // Signal the thread to exit and wait for it
  if (m_pth)
    m_pth->SignalExitAndWait();

  // Unload all of the scripts
  for (XScriptMapIt it = m_mapScripts.begin(); it != m_mapScripts.end(); ++it)
    UnloadScriptFile(it, false);
  m_mapScripts.clear();

  // Close the event logger, if any
  IAGCEventLoggerPtr spEventLogger(m_spEventLogger);
  if (NULL != spEventLogger)
  {
    // Release the event logger
    m_spEventLogger = NULL;

    // Terminate the event logger
    lock.Unlock();
    ZSucceeded(IAGCEventLoggerPrivatePtr(spEventLogger)->Terminate());
  }
}
示例#2
0
HRESULT CPigEngine::AddInvokeCommands(CPigBehaviorScriptType* pType)
{
  // Get the collection of invoke commands for the new object
  XBehaviorMap mapCommands;
  ZSucceeded(GetInvokeCommands(pType, mapCommands));

  // Iterate through each one and determine if it's already in the map
  XLock lock(this);
  for (XBehaviorMapIt it = mapCommands.begin(); it != mapCommands.end(); ++it)
  {
    XBehaviorMapIt itFind = m_mapBehaviors.find(it->first);
    if (m_mapBehaviors.end() != itFind)
    {
      pType->put_AppearsValid(VARIANT_FALSE);
      return AtlReportError(CLSID_PigSession, IDS_E_BEHAVIOR_INVCMD_REUSED,
        IID_IPigSession, 0, _Module.GetResourceInstance());
    }
  }

  // Add each one from the local map to the main map
  for (XScriptMapIt it = mapCommands.begin(); it != mapCommands.end(); ++it)
  {
    m_mapBehaviors.insert(*it);
    it->second->AddRef();
  }

  // Indicate success
  return S_OK;
}
/*-------------------------------------------------------------------------
 * RegisterCOMObjects
 *-------------------------------------------------------------------------
 * Purpose:
 *    Let COM know about our class objects
 *
 */
void CServiceModule::RegisterCOMObjects()
{
	// Make sure we haven't already been here
	assert(m_shevtMTAReady.IsNull());
	assert(m_shevtMTAExit.IsNull());
	assert(m_shthMTA.IsNull());

	// Create thread synchronization objects
	m_shevtMTAReady = CreateEvent(NULL, false, false, NULL);
	m_shevtMTAExit = CreateEvent(NULL, false, false, NULL);
	assert(!m_shevtMTAReady.IsNull());
	assert(!m_shevtMTAExit.IsNull());

	// Create the thread to keep the MTA alive and register the class objects
	DWORD dwID = 0;
	m_shthMTA = CreateThread(NULL, 8192, MTAKeepAliveThunk, this, 0, &dwID);
	assert(!m_shthMTA.IsNull());

	// Wait for the new thread to do its initialization work
	WaitForSingleObject(m_shevtMTAReady, INFINITE);

	// Close the 'Ready' event since we're done with it
	m_shevtMTAReady = NULL;

	// Check for failure
	if (FAILED(m_hrMTAKeepAlive))
		PrintSystemErrorMessage("Failed to register COM class objects for Admin Session.", m_hrMTAKeepAlive);

	ZSucceeded(m_hrMTAKeepAlive);
}
示例#4
0
HRESULT CPigEngine::get_AccountDispenser(IPigAccountDispenser** ppDispenser)
{
  // Get the computer name of the account server
  CComBSTR bstrServer;
  RETURN_FAILED(get_AccountServer(&bstrServer));
  if (!bstrServer.Length())
  {
    // Get the computer name of the mission server
    RETURN_FAILED(get_MissionServer(&bstrServer));
  }

  // Check for '.' to indicate this computer
  if (1 == bstrServer.Length() && OLESTR('.') == bstrServer[0])
    bstrServer.Empty();

  // Create the Pig Account Dispenser on the mission server
  COSERVERINFO si  = {0, bstrServer, NULL, 0};
  MULTI_QI     mqi = {&IID_IPigAccountDispenser, NULL, S_OK};
  RETURN_FAILED(CoCreateInstanceEx(CLSID_PigAccountDispenser, NULL,
    CLSCTX_SERVER, &si, 1, &mqi));

  // Copy the interface pointer to the [out] parameter
  ZSucceeded(mqi.hr);
  *ppDispenser = (IPigAccountDispenser*)mqi.pItf;

  // Indicate success
  return S_OK;
}
/*-------------------------------------------------------------------------
 * get_Server()
 *-------------------------------------------------------------------------
 * Purpose:
 *
 *
 */
STDMETHODIMP CAdminSession::get_Server(IAdminServer** ppAdminServer)
{
	// Get the CAdminServer instance from the GIT
	HRESULT hr;
	assert(g.dwServerGITCookie);
	ZSucceeded(hr = GetAGCGlobal()->GetInterfaceFromGlobal(
		g.dwServerGITCookie, IID_IAdminServer, (void**)ppAdminServer));
	return hr;
}
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<ISoundTemplate> ptemplateBase; CastTo(ptemplateBase, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(CreateLoopingSoundTemplate(pTemplate, ptemplateBase));

        return pTemplate;
    }
// creates a sound template representing a redbook audio track
HRESULT CreateRedbookSoundTemplate(TRef<ISoundTemplate>& pstDest, TRef<IDiskPlayer> pdiskplayer, int nTrack)
{
    TRef<RedbookSoundTemplate> ptemplate = new RedbookSoundTemplate();
    HRESULT hr = ptemplate->Init(pdiskplayer, nTrack);
    
    if (ZSucceeded(hr))
        pstDest = ptemplate; 

    return hr;
}
/*-------------------------------------------------------------------------
 * CServiceModule::Init
 *-------------------------------------------------------------------------
 * Purpose:
 *    Init some COM/ATL/AGC stuff
 *
 */
HRESULT CServiceModule::Init(HINSTANCE hInst)
{
	// Initialize the ATL module
	HRESULT hr;
	ZSucceeded(hr = CComModule::Init(ObjectMap, hInst, &LIBID_ALLEGIANCESERVERLib));
	RETURN_FAILED(hr);

	// Indicate success
	return S_OK;
}
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<IDiskPlayer>    pdiskPlayer; CastTo(pdiskPlayer, (IObject*)stack.Pop());
        TRef<Number>         pnumTrack;   CastTo(pnumTrack, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(CreateRedbookSoundTemplate(pTemplate, pdiskPlayer, (int)pnumTrack->GetValue()));

        return pTemplate;
    }
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<ISoundTemplate> ptemplateBase1; CastTo(ptemplateBase1, (IObject*)stack.Pop());
        TRef<ISoundTemplate> ptemplateBase2; CastTo(ptemplateBase2, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(CreatePairedSoundTemplate(pTemplate, ptemplateBase1, ptemplateBase2));

        return pTemplate;
    }
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<Number>         pnumMinDist; CastTo(pnumMinDist, (IObject*)stack.Pop());
        TRef<ISoundTemplate> ptemplateBase; CastTo(ptemplateBase, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(Create3DSoundTemplate(pTemplate, ptemplateBase, pnumMinDist->GetValue()));

        return pTemplate;
    }
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<Number>         pnumPeriod;        CastTo(pnumPeriod, (IObject*)stack.Pop());
        TRef<Boolean>        pboolPlayMultiple; CastTo(pboolPlayMultiple, (IObject*)stack.Pop());
        TRef<ISoundTemplate> ptemplateBase;     CastTo(ptemplateBase, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(CreateIntermittentSoundTemplate(pTemplate, ptemplateBase, 
            pnumPeriod->GetValue(), pboolPlayMultiple->GetValue()));

        return pTemplate;
    }
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<IObjectList> plist; CastTo(plist, (IObject*)stack.Pop());
        TRef<IRandomSoundTemplate> pTemplate;

        ZSucceeded(CreateRandomSoundTemplate(pTemplate));

        plist->GetFirst();

        while (plist->GetCurrent() != NULL) {
            IObjectPair*      ppair;       CastTo(ppair,       plist->GetCurrent());
            TRef<ISoundTemplate>    ptemplateBase;  CastTo(ptemplateBase,  ppair->GetFirst()  );
            TRef<Number>            pnumWeight; CastTo(pnumWeight, ppair->GetSecond() );

            ZSucceeded(pTemplate->AddSoundTemplate(ptemplateBase, pnumWeight->GetValue()));

            plist->GetNext();
        }

        return pTemplate;
    }
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<Number>         pnumLoopStart; CastTo(pnumLoopStart, (IObject*)stack.Pop());
        TRef<Number>         pnumLoopLength; CastTo(pnumLoopLength, (IObject*)stack.Pop());
        TRef<ISoundTemplate> ptemplateBase; CastTo(ptemplateBase, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(CreateASRSoundTemplate(pTemplate, ptemplateBase, 
            pnumLoopStart->GetValue(), pnumLoopLength->GetValue()));

        return pTemplate;
    }
示例#15
0
HRESULT CServiceModule::UnregisterServer()
{
	// Enter the COM MTA
	TCCoInit init(COINIT_MULTITHREADED);
	if (init.Failed())
		return init;

	// Initialize the ATL module
	HRESULT hr = _Module.Init(g.hInst); // init COM and/or NT service stuff
	ZSucceeded(hr);

	// Create the component category manager
	CComPtr<ICatRegister> spCatReg;
	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_ALL,
		IID_ICatRegister, (void**)&spCatReg);
	ZSucceeded(hr);

	if (SUCCEEDED(hr))
	{
		// Unregister our component category
		CATID catid = CATID_AllegianceAdmin;
		spCatReg->UnRegisterCategories(1, &catid);
		spCatReg = NULL;
	}

	// Remove service entries
	UpdateRegistryFromResource(IDR_AllSrv, FALSE);
	// uninstall service
	if (IsInServiceControlManager())
	{
		RemoveService();
	}
	// Remove object entries
	CComModule::UnregisterServer(TRUE);

	// Terminate the ATL module
	_Module.Term();
	return hr;
}
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<Number>         pnumInnerAngle; CastTo(pnumInnerAngle, (IObject*)stack.Pop());
        TRef<Number>         pnumOuterAngle; CastTo(pnumOuterAngle, (IObject*)stack.Pop());
        TRef<Number>         pnumOuterGain; CastTo(pnumOuterGain, (IObject*)stack.Pop());
        TRef<ISoundTemplate> ptemplateBase; CastTo(ptemplateBase, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(CreateSoundConeTemplate(pTemplate, ptemplateBase, 
            pnumInnerAngle->GetValue(), pnumOuterAngle->GetValue(), pnumOuterGain->GetValue()));

        return pTemplate;
    }
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<Number>         pnumRepeatRate; CastTo(pnumRepeatRate, (IObject*)stack.Pop());
        TRef<ISoundTemplate> ptemplateBase; CastTo(ptemplateBase, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        if (ZFailed(CreateRepeatingFireSoundTemplate(pTemplate, ptemplateBase, pnumRepeatRate->GetValue())))
        {
            // Fail over to a dummy sound template
            ZSucceeded(CreateDummySoundTemplate(pTemplate));
        }

        return pTemplate;
    }
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<ISoundMutex>    pmutex;              CastTo(pmutex, (IObject*)stack.Pop());
        TRef<Number>         pnumTimeout;         CastTo(pnumTimeout, (IObject*)stack.Pop());
        TRef<Number>         pnumPriority;        CastTo(pnumPriority, (IObject*)stack.Pop());
        TRef<Boolean>        pboolSingleInstance; CastTo(pboolSingleInstance, (IObject*)stack.Pop());
        TRef<ISoundTemplate> ptemplateBase;       CastTo(ptemplateBase, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

        ZSucceeded(CreateSerializedSoundTemplate(pTemplate, ptemplateBase, pmutex,
            pnumTimeout->GetValue(), pnumPriority->GetValue(), pboolSingleInstance->GetValue()));

        return pTemplate;
    }
示例#19
0
void CServiceModule::TermAGC()
{
	// Shutdown the event logger object
	if (NULL != m_spEventLogger)
	{
		IAGCEventLoggerPrivatePtr spPrivate(m_spEventLogger);
		assert(NULL != spPrivate);

		// Terminate the event logger
		ZSucceeded(spPrivate->Terminate());

		// Unhook the event logger for DB event logging
		{
			ZSucceeded(spPrivate->put_HookForDBLogging(NULL));
		}

		// Release the event logger
		spPrivate = NULL;
		m_spEventLogger = NULL;
	}

	// Terminate AGC
	_AGCModule.Term();
}
示例#20
0
HRESULT CServiceModule::InitAGC()
{
	// Initialize AGC
	HRESULT hr;
	ZSucceeded(hr = _AGCModule.Init());
	RETURN_FAILED(hr);

	_AGCModule.SetDebugBreakOnErrors(g.fWantInt3);

#ifdef _DEBUG
	_AGCModule.GetAGCGlobal()->SetDebugHook(&g_DebugHook);
#endif // _DEBUG

	// Create the set of available AGCEventID ranges
	CComPtr<IAGCEventIDRanges> spRanges;
	ZSucceeded(hr = spRanges.CoCreateInstance(L"AGC.EventIDRanges"));
	RETURN_FAILED(hr);

	// Add our ranges to it
	ZSucceeded(spRanges->AddByValues(EventID_AGC_LowerBound, EventID_AGC_UpperBound));
	ZSucceeded(spRanges->AddByValues(AllsrvEventID_Allsrv_LowerBound, AllsrvEventID_Allsrv_UpperBound));
	ZSucceeded(spRanges->AddByValues(EventID_Admin_LowerBound, EventID_Admin_UpperBound));

	// Set the ranges of available events
	GetAGCGlobal()->SetAvailableEventIDRanges(spRanges);

	// Create the event logger object
	ZSucceeded(hr = m_spEventLogger.CreateInstance("AGC.EventLogger"));
	RETURN_FAILED(hr);

	// Initialize the event logger object
	CComBSTR bstrEventSource(__MODULE__);
	CComBSTR bstrRegKey("HKLM\\" HKLM_FedSrvA);
	IAGCEventLoggerPrivatePtr spPrivate(m_spEventLogger);
	hr = spPrivate->Initialize(bstrEventSource, bstrRegKey);
	ZSucceeded(hr);
	RETURN_FAILED(hr);

	// Hook the event logger for DB event logging
	ZSucceeded(hr = spPrivate->put_HookForDBLogging(&g_DBLoggingHook));

	// Indicate success
	return S_OK;
}
示例#21
0
void CPigEngine::AddScriptFile(const WIN32_FIND_DATA* pffd,
  tstring strFileName)
{
  // Create a new CPigBehaviorScriptType object
  CComObject<CPigBehaviorScriptType>* pScript = NULL;
  HRESULT hr = pScript->CreateInstance(&pScript);
  ZSucceeded(hr);
  if (SUCCEEDED(hr))
  {
    // AddRef the new object
    pScript->AddRef();

    // Initialize the new object
    LoadScriptFile(pScript, pffd, strFileName);

    // Add the new object to the map of scripts
    XLock lock(this);
    m_mapScripts.insert(std::make_pair(strFileName, pScript));
  }
}
示例#22
0
void CAGCEventDef::Initialize()
{
  TCSimpleLock spinLock(s_nInitSync);
  TCObjectLock<TCSimpleLock> lock(&spinLock);
  if (s_bInitialized)
    return;

  // Map all of the event names to ID's
  s_pNameMap = new XNameMap;
  for (const XEventDef* it = begin(); end() != it; ++it)
  {
    if (HIWORD(reinterpret_cast<DWORD>(it->m_pszName)))
      (*s_pNameMap)[it->m_pszName] = it->m_id;
    else
    {
      BSTR bstrName;
      ZSucceeded(GetString(it->m_pszName, &bstrName));
      (*s_pNameMap)[bstrName] = it->m_id;
    }
  }
  s_bInitialized = true;
}
    TRef<IObject> Apply(ObjectStack& stack)
    {
        TRef<StringValue> pstring; CastTo(pstring, (IObject*)stack.Pop());
        TRef<ISoundTemplate> pTemplate;

		// mdvalley: Look for files in this order: Soundpack WAV, Soundpack OGG, Artwork WAV, Artwork OGG
        // pkk: Removed SoundPack support, Allegiance no longer looking for files in a not existing folder
		// Load wave from artwork directory
        ZString strFilename = m_pmodeler->GetArtPath() + "\\..\\" + pstring->GetValue() + ".wav";
		
		if (!FileExists(strFilename))
		{
		    // Load ogg file, if wave file doesn't exisits
			strFilename = m_pmodeler->GetArtPath() + "\\" + pstring->GetValue() + ".ogg";
		}
		
        if (FAILED(CreateWaveFileSoundTemplate(pTemplate, strFilename)))
        {
            // Fail over to a dummy sound template
            ZSucceeded(CreateDummySoundTemplate(pTemplate));
        }

        return pTemplate;
    }
示例#24
0
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);
}
示例#25
0
HRESULT CServiceModule::RegisterServer(BOOL bReRegister, BOOL bRegTypeLib, BOOL bService, int argc, char * argv[])
{
	// Enter the COM MTA
	TCCoInit init(COINIT_MULTITHREADED);
	if (init.Failed())
		return init;

	// Initialize the ATL module
	HRESULT hr = _Module.Init(g.hInst); // init COM and/or NT service stuff
	ZSucceeded(hr);

	if (IsWin9x())
		bService = false; // Windows 9x doesn't support services

	  // Remove any previous service since it may point to
	  // the incorrect file
	if (IsInServiceControlManager() && !bReRegister)
		RemoveService();

	// Add service entries
	_Module.UpdateRegistryFromResource(IDR_AllSrv, true,
		_AGCModule.GetRegMapEntries());

#ifdef MONOLITHIC_DPLAY
	// Register custom dplay bits
	RegisterMonolithicDPlay();
#endif

	// Create the component category manager
	CComPtr<ICatRegister> spCatReg;
	hr = CoCreateInstance(CLSID_StdComponentCategoriesMgr, NULL, CLSCTX_ALL,
		IID_ICatRegister, (void**)&spCatReg);
	ZSucceeded(hr);

	if (SUCCEEDED(hr))
	{
		// Determine the LCID for US English
		const LANGID langid = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US);
		const LCID lcid = MAKELCID(langid, SORT_DEFAULT);

		// Register the component category
		CATEGORYINFO catinfo;
		catinfo.catid = CATID_AllegianceAdmin;
		catinfo.lcid = lcid;
		wcscpy(catinfo.szDescription, L"Allegiance Admin Objects");
		hr = spCatReg->RegisterCategories(1, &catinfo);
		ZSucceeded(hr);

		// Explicitly release the smart pointer
		spCatReg = NULL;
	}

	if (!bReRegister)
	{
		// Adjust the AppID for Local Server or Service
		CRegKey keyAppID;

		DWORD lRes = keyAppID.Open(HKEY_CLASSES_ROOT, _T("AppID"), KEY_WRITE);
		if (lRes != ERROR_SUCCESS)
			return lRes;

		CRegKey key;
		lRes = key.Open(keyAppID, _T("{E4E8767E-DFDB-11d2-8B46-00C04F681633}"), KEY_WRITE);
		if (lRes != ERROR_SUCCESS)
			return lRes;

		key.DeleteValue(_T("LocalService"));

		if (bService)
		{
			// mdvalley: I hate my ATL libraries sometimes (SetStringValue)
			key.SetValue(_T(__MODULE__), _T("LocalService"));
			key.SetValue(_T("-Service"), _T("ServiceParameters"));
			// Create service
			InstallService(argc, argv);
		}
	}

	// Add object entries
	hr = _Module.CComModule::RegisterServer(bRegTypeLib);

	// Terminate the ATL module
	_Module.Term();
	return hr;
}
STDMETHODIMP CAdminEventLoggerHook::LogEvent(IAGCEvent* pEvent, VARIANT_BOOL bSynchronous)
{
  // Do nothing if SQLCore has not been initialized
  if (!g.sql.GetNotifyThreadID())
    return S_OK;

  // Get the fields of the specified event object
  AGCEventID idEvent;
  long       idSubject;
  CComBSTR   bstrComputerName, bstrSubjectName, bstrContext;
  ZSucceeded(pEvent->get_ID(&idEvent));
  ZSucceeded(pEvent->get_SubjectID   (&idSubject       ));
  ZSucceeded(pEvent->get_ComputerName(&bstrComputerName));
  ZSucceeded(pEvent->get_SubjectName (&bstrSubjectName ));
  ZSucceeded(pEvent->get_Context     (&bstrContext     ));

  // Use a callback if event is synchronous
  void (*pfnDataReady)(CQLogEvent* pquery) = bSynchronous ? EventLogged : NULL;

  // Create the database update query
  CQLogEvent*  pquery = new CQLogEvent(pfnDataReady);
  CQLogEventData* pqd = pquery->GetData();

  // Ensure that the callback does NOT go through the message queue
  pquery->SetCallbackOnMainThread(false);

  // Populate the query parameters from the event fields
  USES_CONVERSION;
	pqd->nEvent   = idEvent;
	pqd->nSubject = idSubject;
  if (bstrComputerName.Length())
    lstrcpyn(pqd->szComputerName, OLE2CT(bstrComputerName), sizeofArray(pqd->szComputerName));
  else
    pqd->szComputerName[0] = TEXT('\0');
  if (bstrSubjectName.Length())
    lstrcpyn(pqd->szSubjectName, OLE2CT(bstrSubjectName), sizeofArray(pqd->szSubjectName));
  else
    pqd->szSubjectName[0] = TEXT('\0');
  if (bstrContext.Length())
    lstrcpyn(pqd->szContext, OLE2CT(bstrContext), sizeofArray(pqd->szContext));
  else
    pqd->szContext[0] = TEXT('\0');

  // Get the event object as a string
  assert(IPersistStreamInitPtr(pEvent) != NULL || IPersistStreamPtr(pEvent) != NULL);
  assert(IMarshalPtr(pEvent) != NULL);
  CComBSTR bstrTemp;
  ZSucceeded(pEvent->SaveToString(&bstrTemp));
  WideCharToMultiByte(CP_ACP, 0, bstrTemp, -1,
    pqd->szObjectRef, sizeof(pqd->szObjectRef), 0, 0);

  // Create an event upon which to wait, if event is synchronous
  TCHandle shevt;
  if (bSynchronous)
    shevt = ::CreateEvent(NULL, false, false, NULL);
  pqd->hevt = shevt.GetHandle();

  // Post the query for async completion
  g.sql.PostQuery(pquery);

  // Wait for the event, if event is synchronous
  if (!shevt.IsNull())
    ::WaitForSingleObject(shevt, INFINITE);

  // Indicate that we handled it
  return S_OK;
}
 void ChildChanged(Value* pvalue, Value* pvalueNew)
 {
     // the only child is the gain value, so let's adjust that.  
     ZSucceeded(SetGain(m_fCurrentGain));
 };