|
////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2006 Werner Willemsens
//
////////////////////////////////////////////////////////////////////
// Gate.cpp : Implementation of CGate
#include "stdafx.h"
#include "Gate.h"
#include <comutil.h>
#include <comdef.h>
#include "StarGatePS.h"
#include "Error.h"
// CGate
CGate::CGate()
{
m_ChevronCount = 0;
for (int i=0; i<MAX_CHEVRON_COUNT; i++) m_ChevronEntered[i] = 0;
::InitializeCriticalSection(&m_ChevronProtect);
}
CGate::~CGate()
{
::DeleteCriticalSection(&m_ChevronProtect);
}
STDMETHODIMP CGate::InterfaceSupportsErrorInfo(REFIID riid)
{
// We will only arrive here when ISupportErrorInterface is properly marshalled
// so Proxy/Stub code needs to be available
static const IID* arr[] =
{
&IID_IGate
};
for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
{
if (InlineIsEqualGUID(*arr[i],riid))
return S_OK;
}
return S_FALSE;
}
void CGate::ProcessOpened(VARIANT *aValue)
{
// Call the next function if you don't want the events to be sent via a seperate workerthread
// DoFire_Opened(aValue);
// Call the next function if you want the events to be sent via a seperate workerthread
Fire_Opened(aValue);
}
STDMETHODIMP CGate::DialGate(LONG Chevron)
{
HRESULT hr = S_OK;
// Start protecting members
::EnterCriticalSection(&m_ChevronProtect);
if (m_ChevronCount < MAX_CHEVRON_COUNT)
if ((0 <= Chevron) && (Chevron <= MAX_CHEVRON_SYMBOL))
m_ChevronEntered[m_ChevronCount++] = Chevron;
else
hr = ThrowCOMError(CLSID_Gate, IID_IGate, IDS_E_INVALID_CHEVRON_SYMBOL);
else
hr = ThrowCOMError(CLSID_Gate, IID_IGate, IDS_E_TOO_MANY_CHEVRONS);
long ChevronCount = m_ChevronCount;
// Stop protecting members
::LeaveCriticalSection(&m_ChevronProtect);
if ((hr == S_OK) && (ChevronCount > MIN_CHEVRON_COUNT))
{
_bstr_t destination(_T("P"));
for (int i=0; i<ChevronCount; i++)
destination += _bstr_t(_variant_t(m_ChevronEntered[i]));
ProcessOpened(&_variant_t(destination));
}
return hr;
}
STDMETHODIMP CGate::CloseGate()
{
// Start protecting members
::EnterCriticalSection(&m_ChevronProtect);
m_ChevronCount = 0;
// Stop protecting members
::LeaveCriticalSection(&m_ChevronProtect);
ProcessOpened(&_variant_t(_bstr_t(_T(""))));
return S_OK;
}
STDMETHODIMP CGate::get_IsOpen(VARIANT_BOOL* pVal)
{
// Start protecting members
::EnterCriticalSection(&m_ChevronProtect);
if (m_ChevronCount >= MAX_CHEVRON_COUNT) *pVal = VARIANT_TRUE;
else *pVal = VARIANT_FALSE;
// Stop protecting members
::LeaveCriticalSection(&m_ChevronProtect);
return S_OK;
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.