/* This example node shows how to add connectors into node and handle their evaluation.
Lazy evaluation is used to determine output connector value all the time. That means, connector
is recalculated only when explicitly required

In this particular example, node contains two input and one output connectors containing numbers.
Whenever one of input connectors changes, output connector is invalidated. Value of output connector
is sum of two numeric input connectors.

Additionally, node contains two bitmap connectors intended to demonstrate how to handle data types
in connectors. It converts input bitmap to grayscale and feeds it to output.

Node contains one registered connector which can also be used outside package as it is 
specified in ExamplesPluginGUIDS.h
*/


#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

// local input connector for connector example node
// {C9A5D2F7-EEE3-476f-926B-3222F2837974}
RS_DEFINE_GUID(CON_CONEX_LOCAL_CONNECTOR, 0xc9a5d2f7, 0xeee3, 0x476f, 0x92, 0x6b, 0x32, 0x22, 0xf2, 0x83, 0x79, 0x74);

// output (result) connector for connector example node
// {26F10DEC-3088-4314-8464-F741197CC606}
RS_DEFINE_GUID(CON_CONEX_RESULT, 0x26f10dec, 0x3088, 0x4314, 0x84, 0x64, 0xf7, 0x41, 0x19, 0x7c, 0xc6, 0x6);

// input bitmap connector
// {63B7F4A4-262D-4f86-8005-AD534CE55CBC}
RS_DEFINE_GUID(CON_CONEX_INPUT_BITMAP, 0x63b7f4a4, 0x262d, 0x4f86, 0x80, 0x5, 0xad, 0x53, 0x4c, 0xe5, 0x5c, 0xbc);

// output bitmap connector
// {97DFF740-46F5-4a87-BB90-B21F5FBE3D91}
RS_DEFINE_GUID(CON_CONEX_BITMAP, 0x97dff740, 0x46f5, 0x4a87, 0xbb, 0x90, 0xb2, 0x1f, 0x5f, 0xbe, 0x3d, 0x91);



// IRnConnectorExample
MIDL_INTERFACE("6E216FC9-248E-4310-8C1E-75620A65919A")
IRnConnectorExample :IUnknown
{
};

// CRnConnectorExample
class ATL_NO_VTABLE CRnConnectorExample : 
    public CComObjectRootEx<CComGlobalsThreadModel>,
    public IRsUnknownNode,
    public IRnConnectorExample
{
private:
    CComPtr<IUnknown> m_spUnkAgg;

public:
    CRnConnectorExample()
    {
    }

    HRESULT FinalConstruct();

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


    // 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(IRnConnectorExample, L"Connector example node")

        BEGIN_COM_MAP(CRnConnectorExample)
            COM_INTERFACE_ENTRY(IRnConnectorExample)
            COM_INTERFACE_ENTRY(IRsUnknownNode)
            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()
};

