#include <windows.h>
#include "timedatafactory.h"
#include "ctimedta.h"
#include "main.h"


CTimeDataFactory::CTimeDataFactory (void)
{
    m_RefCount = 1 ;
	AddRef( ) ;   
    return;
}


CTimeDataFactory::~CTimeDataFactory(void)
{
    return;
}



STDMETHODIMP CTimeDataFactory::QueryInterface(REFIID riid, LPVOID *ppv)
{
    if (riid == IID_IUnknown || riid == IID_IClassFactory)
	{
        *ppv = (LPVOID)this;
		AddRef( ) ;
		return NOERROR;
	}
	else
	{
    	*ppv = NULL ;
    	return  E_NOINTERFACE ;
	}
        
}


STDMETHODIMP_(ULONG) CTimeDataFactory::AddRef(void)
{
    return ++m_RefCount;
}


STDMETHODIMP_(ULONG) CTimeDataFactory::Release(void)
{
	m_RefCount -- ;

    if (m_RefCount == 0)
	{
        delete this;
		return 0 ;
	}

    return m_RefCount ;
}




					  	
STDMETHODIMP CTimeDataFactory::CreateInstance(LPUNKNOWN pUnkOuter, 
	REFIID riid, LPVOID* ppvObj)
{
	    
/*
Check for aggregation request.  We don't do it.
*/
	if (pUnkOuter != NULL)
	{
		*ppvObj = NULL ;
		return  CLASS_E_NOAGGREGATION ;
	}

/*
Create a new data object.  QUery interface as requested.  If found,
go happily on our way.
*/

	CTimeData * pTD = new CTimeData ( ) ;

   	if (pTD->QueryInterface (riid, ppvObj) == NOERROR)
	{
		pTD->Release ( ) ;
		return S_OK ;
	}
	else
	{
		delete pTD ;
		return E_NOINTERFACE ;
	}
}


STDMETHODIMP CTimeDataFactory::LockServer(BOOL bLock)
{
	if (bLock == TRUE)
	{
		MyOwnLockServer ( ) ;
	}
	else
	{
		MyOwnUnlockServer ( ) ;
	}

	return S_OK ;
}
