// RpAnimPlugin.h : Declaration of the CRpAnimPlugin
// CRpAnimPlugin represents the plugin. We implement here the
// IRsUnknownPackage interface that is asked during the plugin loading.
// The interface then enable communication with system and all other
// packages.

#pragma once

#define ANIMSAMPLE_PACKAGE_VERSION1			1	// package version
#define ANIMSAMPLE_PACKAGE_VERSION2			2	// added toolbar look up code
#define ANIMSAMPLE_PACKAGE_VERSION			ANIMSAMPLE_PACKAGE_VERSION2  

[
	object,
	helpstring("IRpAnimPlugin Interface"),
	uuid("E45AD096-F444-4e53-831E-AB532F35669D"),
	pointer_default(unique)
]
__interface IRpAnimPlugin : public IUnknown
{
public:
};



[
	ATTRIBUTE_COCLASS,
	threading(both),
	vi_progid("RsViewPlugin.RpAnimPlugin"),
	progid("RsViewPlugin.RpAnimPlugin.1"),
	version(1.0),
	uuid("E9A99664-44EB-4a53-BC5E-993DCC912AC8"),
	helpstring("RpAnimPlugin Class")
]
class ATL_NO_VTABLE CRpAnimPlugin: 
	public IRpAnimPlugin,
    public IRsUnknownPackage,
    public IRsModulePackage,
	public IRsPackageDesc
{
public:
    CRpAnimPlugin()
    {
    }

    HRESULT FinalConstruct()
    {
        return S_OK;
    }

    void FinalRelease() 
    {
    }

    BEGIN_COM_MAP(CRpAnimPlugin)
        COM_INTERFACE_ENTRY(IRpAnimPlugin)
        COM_INTERFACE_ENTRY2(IRsObject, IRsUnknownPackage)
        COM_INTERFACE_ENTRY(IRsUnknownPackage)
        COM_INTERFACE_ENTRY(IRsModulePackage)
    END_COM_MAP()

    DECLARE_CLASSFACTORY_SINGLETON(CRpAnimPlugin)
    DECLARE_NOT_AGGREGATABLE(CRpAnimPlugin)
    DECLARE_PROTECT_FINAL_CONSTRUCT()

    // IRsUnknownPackage
    STDMETHOD(Initialize)(IRsUnknownPackage *pParentPackage);           // Called to initialize this package
    STDMETHOD(UnInitialize)();                                          // This method releases m_pKernelPackage.
    STDMETHOD(OnSysMessage)(MSGID msgId, IRsUnknownMsg* pMsg);          // package messages handler
    STDMETHOD(GetNodeFactory)(IRsNodeFactory** ppNodeFactory);          // returns NodeFactory interface provided by package
    STDMETHOD(GetCmdFactory)(IRsCmdFactory** ppCmdFactory);             // returns Command Factory interface provided by package
    STDMETHOD(GetDataObjFactory)(IRsDataObjFactory** ppDataObjFactory); // returns Data Object Factory interface provided by package
    STDMETHOD(GetModuleInstance)(RtInstance* pInstance);                // returns Package module instance
    STDMETHOD(GetResourceInstance)(RtInstance* pInstance);              // returns Package resource instance

    // IRsObject Methods
    RS_DECLARE_IRS_OBJECT(CRpAnimPlugin, L"AnimPlugin Package");

    // package version
    RS_DECLARE_PACKAGE_VERSION(PRODUCT_VERSION, ANIMSAMPLE_PACKAGE_VERSION);
	RS_PACKAGE_DESCRIPTION(L"Procedural animation sdk example");

public:
    // Helper functions
	static HRESULT GetKernelPackage(IRpKernel** ppPackage); // Returns kernel package interface
	static HRESULT GetKernelNode(IRnKernel** ppKernelNode); // Returns kernel node 
	static HRESULT GetSysFactory(IRsSysFactory** ppSysFactory); // Returns system factory 
    static HRESULT CreateDataObj(const IID* piid, IRsDataObject** ppDataObj);
    static HRESULT CreateCmdObj(const IID *piid, IRsNode **ppCmd);
    static HRESULT CreateNode(const IID *piid, IRsNode **ppNode);
    static HRESULT ExecuteCommand(IRsNode *pCmdNode);   // Call to synchronous execution of commands
	static HRESULT SendCommand(IRsNode *pCmdNode);      // Send command to commands' queue
    
    // Log support
    RS_LOG_ACCESS(m_spKernelPackage)
    #define RS_LOG(lev, hr, text) CRpAnimPlugin::MyLogEntry(lev, hr, text, __FILE__, __LINE__);   

	// sends the command for openning plugin toolbar
	HRESULT OpenPluginToolbar(void);

private:
    // Pointer to kernel Package.
    static CComPtr<IRpKernel>			m_spKernelPackage;
    // Pointer to sys factory for creating rs objects
    static CComPtr<IRsSysFactory>		m_spSysFactory;
    // Pointer to sys core for synchronous command processing
    static CComPtr<IRsSysCore>			m_spSysCore;

    // node factory
    CComPtr<IRsNodeFactory>				m_spNodeFactory;
    // command factory
    CComPtr<IRsCmdFactory>				m_spCmdFactory;
};


