// RcParameterPassing.h : Declaration of the CRcParameterPassing
/**
This example demonstrates how to create command for execution from the script and how to pass parameters to it using connectors.

Command is registered into system command factory by describing it in CRsCmdFactory::EnumCommandDesc and by 
creating it in CRsCmdFactory::CreateInstance when requested. 

Type ExamplesPlugin.ParameterPassing(10.5,'some text') script call to execute example. 

*/
#pragma once


//Declare connector GUIDs

// {89922B45-A57B-4e88-8C06-20D930D7877E}
RS_DEFINE_GUID(CON_PP_FLOAT_PARAM, 0x89922b45, 0xa57b, 0x4e88, 0x8c, 0x6, 0x20, 0xd9, 0x30, 0xd7, 0x87, 0x7e);

// {D565D415-FEE8-4e9b-BEB6-EAF2E9DF075F}
RS_DEFINE_GUID(CON_PP_STRING_PARAM, 0xd565d415, 0xfee8, 0x4e9b, 0xbe, 0xb6, 0xea, 0xf2, 0xe9, 0xdf, 0x7, 0x5f);


// IRcParameterPassing
[
	object,
	uuid("BDB97084-7E22-4253-95F6-E6CA0100C9D1"),
	helpstring("IRcParameterPassing Interface"),
	pointer_default(unique)
]
__interface IRcParameterPassing :IUnknown
{
};


// CRcParameterPassing
class ATL_NO_VTABLE CRcParameterPassing : 
    public CComObjectRootEx<CComGlobalsThreadModel>,
    public IRsUnknownNode,
    public IRsCommand,
	public IRcParameterPassing
{
private:
    CComPtr<IUnknown> m_spUnkAgg;

public:
    CRcParameterPassing()
	{
	}

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

	STDMETHOD(Execute)(void);
    STDMETHOD(Undo)(void);
    STDMETHOD(Redo)(void);
    STDMETHOD(HasUndo)(RtBool* isUndoable);
    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(IRcParameterPassing, L"Parameter passing example command")

    BEGIN_COM_MAP(CRcParameterPassing)
        COM_INTERFACE_ENTRY(IRcParameterPassing)
        COM_INTERFACE_ENTRY(IRsUnknownNode)
        COM_INTERFACE_ENTRY(IRsCommand)
        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()
};
