// RcUpdate3DLoader.h : Declaration of the CRcUpdate3DLoader
// This command is created by Rn3DLoader node object to update itself.
// The purpose is to get some CPU time to access the Dependency Graph.
//
// RcUpdate3DLoader could be used by more than just one node, therefore
// we need to specify which node should be updated. The identification
// is stored in CON_CMD_3DLOADERUPDCMD_NODE_ID connector.

#pragma once

#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

// NodeId: 3DLoader node ID
// {212CD74F-3C8C-409a-A0E3-F2CE2F43BD4F}
RS_DEFINE_GUID(CON_CMD_3DLOADERUPDCMD_NODE_ID,
0x212cd74f, 0x3c8c, 0x409a, 0xa0, 0xe3, 0xf2, 0xce, 0x2f, 0x43, 0xbd, 0x4f);

// IRcUpdate3DLoader
MIDL_INTERFACE("C511A768-46F8-4c4a-9F62-FD689C89B930")
IRcUpdate3DLoader :IUnknown
{
};

// CRcUpdate3DLoader
class ATL_NO_VTABLE CRcUpdate3DLoader :
    public CComObjectRootEx<CComGlobalsThreadModel>,
    public IRsUnknownNode,
    public IRsCommand,
	public IRcUpdate3DLoader
{
public:
    CRcUpdate3DLoader()
	{
	}

	HRESULT FinalConstruct();
	
	void FinalRelease() 
	{
        m_spUnkAgg.Release();
	}

    // IRsCommand
	STDMETHOD(Execute)(void);
    STDMETHOD(Undo)(void);
    STDMETHOD(Redo)(void);
    STDMETHOD(HasUndo)(RtBool* isUndoable);

    // IRsUnknownNode
    STDMETHOD(OnGetValue)(CONID con_id, IRsDataCache* pDataCache, VARIANT* pVtData, RtBool* pHandled);
    STDMETHOD(OnSetValue)(CONID con_id, IRsDataCache* pDataCache, VARIANT* pvtData, RtBool* pHandled);
    STDMETHOD(OnDefaultValue)(CONID con_id, VARIANT* pVtData, RtBool* pHandled);
    STDMETHOD(OnInvalidate)(CONID con_id, RtBool* pHandled);
    STDMETHOD(OnInitialize)(void);
    STDMETHOD(OnLoadDefault)(void);
    STDMETHOD(OnDestroy)(void);

    // IRsObject
    RS_DECLARE_IRS_OBJECT(IRcUpdate3DLoader, L"Update3DLoader command")

    BEGIN_COM_MAP(CRcUpdate3DLoader)
        COM_INTERFACE_ENTRY(IRsUnknownNode)
        COM_INTERFACE_ENTRY(IRsCommand)
        COM_INTERFACE_ENTRY(IRcUpdate3DLoader)
        COM_INTERFACE_ENTRY2(IUnknown, IRsUnknownNode)
        COM_INTERFACE_ENTRY2(IRsObject, IRsUnknownNode)
        COM_INTERFACE_ENTRY_AGGREGATE(DEF_GUIDNAME(IRsBaseNode), m_spUnkAgg.p)
        COM_INTERFACE_ENTRY_AGGREGATE_BLIND(m_spUnkAgg.p)    // Just for safety, the speed is slower only for unknown interfaces
    END_COM_MAP()

    DECLARE_GET_CONTROLLING_UNKNOWN()
    DECLARE_PROTECT_FINAL_CONSTRUCT()

private:
    CComPtr<IUnknown> m_spUnkAgg;
};
