import "oaidl.idl";
import "ocidl.idl";

#define UUID_IAppletSession         e65dc590-a4d9-11d2-b724-00104bc51339
#define UUID_IAppletSessionNotify   f7c10ec0-a4d9-11d2-b724-00104bc51339

#define UUID_IApplet                07970b30-a4da-11d2-b724-00104bc51339
#define UUID_IAppletNotify          16153670-a4da-11d2-b724-00104bc51339

#include "nmapptyp.h"

/* ------ octet string ------ */

typedef struct tagAppletOctetString
{ 
    ULONG   cbStrSize; 
    [size_is(cbStrSize)] BYTE* pbValue; 
}
    AppletOctetString;

typedef struct tagAppletLongString
{
	ULONG   nStrLen;
	[size_is(nStrLen)] ULONG *pnValue;
}
	AppletLongString;


/* ------ object, session, and registry keys ------ */

typedef struct tagAppletObjectKey
{
	AppletKeyType       eType;
	AppletLongString    lstrObjectID;
	AppletOctetString   ostrH221NonStdID;
}
	AppletObjectKey;

typedef struct tagAppletSessionKey
{
    AppletObjectKey             AppletProtocolKey;
    AppletSessionID             nSessionID;
}
    AppletSessionKey;

typedef struct tagAppletRegistryKey
{
    AppletSessionKey            SessionKey;
    AppletOctetString           ostrResourceID;
}
    AppletRegistryKey;


/* ------ registry request ------ */

typedef struct tagAppletRegistryRequest
{
    AppletRegistryCommand       eCommand;
    AppletRegistryKey           RegistryKey;
    // register channel
    AppletChannelID             nChannelID;
    // set parameter
    AppletOctetString           ostrParamValue;
    AppletModificationRights    eParamModifyRights;
    // allocate handle
    ULONG						cHandles;
}
    AppletRegistryRequest;


/* ------ channel request ------ */

typedef struct tagAppletChannelRequest
{
    AppletChannelCommand      eCommand;
    AppletChannelID           nChannelID;
    ULONG                     cUsers;
    [size_is(cUsers)] AppletUserID *aUsers;
}
    AppletChannelRequest;


/* ------ token request ------ */

typedef struct tagAppletTokenRequest
{
    AppletTokenCommand        eCommand;
    AppletTokenID             nTokenID;
    AppletUserID              uidGiveTo;
    HRESULT                   hrGiveResponse;
}
    AppletTokenRequest;


/* ------ capability ------ */

typedef struct tagAppletCapabilityID
{
    AppletCapIDType         eType;
    AppletObjectKey         nNonStdCap;
    ULONG                   nStdCap;
}
    AppletCapabilityID;


typedef struct tagAppletCapability
{
    AppletCapabilityID      CapID;
    AppletCapabilityClass   CapClass;
    ULONG                   cEntities;
}
    AppletCapability;

typedef struct tagAppletCapability2
{
    AppletCapabilityID      CapID;
    AppletOctetString      *pCapData;
}
    AppletCapability2;


typedef struct tagAppletProtocolEntity
{
    AppletSessionKey        SessionKey;
    AppletChannelType       eStartupChannelType;
    BOOL                    fMustBeInvoked;    
    ULONG                   cExpectedCapabilities;
    [size_is(cExpectedCapabilities)] AppletCapability **apExpectedCapabilities;
}
    AppletProtocolEntity;


//
// T120 Applet Session Callback
//

typedef struct tagAppletRecord
{
    AppletNodeID            nNodeID;
    AppletEntityID          nEntityID;
    BOOL                    fEnrolledActively;
    BOOL                    fConductingCapable;
    AppletChannelType       eStartupChannelType; 
    AppletUserID            nAppletUserID;
    ULONG                   cCapabilities;
    [size_is(cCapabilities)] AppletCapability2 **apCapabilities;
}
    AppletRecord;

typedef struct tagAppletRoster
{
    AppletSessionKey        SessionKey;
    BOOL                    fRosterChanged;
    ULONG                   nInstanceNumber;
    BOOL                    fNodesAdded;
    BOOL                    fNodesRemoved;
    BOOL                    fCapabilitiesChanged;
    ULONG                   cRecords;
    [size_is(cRecords)] AppletRecord **apAppletRecords;
    ULONG                   cCapabilities;
    [size_is(cCapabilities)] AppletCapability **apCapabilities;
}
    AppletRoster;

typedef struct tagAppletRegistryItem
{
    AppletRegistryItemType  ItemType;
    // channel
    AppletChannelID         nChannelID;
    // token
    AppletTokenID           nTokenID;
    // parameter
    AppletOctetString       ostrParamValue;
}
    AppletRegistryItem;

typedef struct tagAppletRegistryEntryOwner
{
    BOOL                    fEntryOwned;
    AppletNodeID            nOwnerNodeID;
    AppletEntityID          nOwnerEntityID;
}
    AppletRegistryEntryOwner;


typedef struct tagAppletSessionRequest
{
    // session specific
    AppletSessionKey        SessionKey;
    // applet enroll
    AppletChannelType       nStartupChannelType;
    // collapsed capability
    ULONG                   cCollapsedCaps;
    [size_is(cCollapsedCaps)] AppletCapability **apCollapsedCaps; 
    // non-collapsing capability
    ULONG                   cNonCollapsedCaps;
    [size_is(cNonCollapsedCaps)] AppletCapability2 **apNonCollapsedCaps; 
    // static channels
    ULONG                   cStaticChannels;
    [size_is(cStaticChannels)] AppletChannelID *aStaticChannels; 
    // dynamic channels
    ULONG                   cDynamicChannels;
    [size_is(cDynamicChannels)] AppletRegistryKey *aChannelRegistryKeys; 
}
    AppletSessionRequest;




[
    object,
    uuid(UUID_IAppletSessionNotify),
    pointer_default(unique)
]
interface IAppletSessionNotify : IUnknown
{
    HRESULT JoinSessionConfirm(
                    [in] HRESULT            hrResult,
                    [in] AppletUserID       uidMyself,
                    [in] AppletNodeID       nidMyself,
                    [in] AppletSessionID    sidMyself,
                    [in] AppletEntityID     eidMyself,
                    [in] ULONG              cDynamicChannels,
                    [in,size_is(cDynamicChannels)] AppletChannelID aDynamicChannels[]);

    HRESULT LeaveSessionIndication(
                    [in] AppletReason   eReason,
                    [in] AppletUserID   uidLeave);

    HRESULT SendDataIndication(
                    [in] BOOL               fUniformSend,
                    [in] AppletUserID       uidInitiator,
                    [in] AppletChannelID    nChannelID,
                    [in] AppletPriority     eDataPriority,
                    [in] AppletOctetString  Data);

    HRESULT RosterReportIndication(
                    [in] ULONG              cRosters,
                    [in,size_is(cRosters)] AppletRoster **apAppRosters);

    HRESULT InquireRosterConfirm(
                    [in] HRESULT            hrResult,
                    [in] ULONG              cRosters,
                    [in,size_is(cRosters)] AppletRoster **apAppRosters);

    HRESULT InvokeAppletConfirm(
                    [in] AppletRequestTag   nReqTag,
                    [in] HRESULT            hrResult);

    HRESULT RegistryConfirm(
                    [in] AppletRegistryCommand      eCommand,
                    [in] HRESULT                    hrResult,
                    [in] AppletRegistryKey         *pRegistryKey,
                    [in] AppletRegistryItem        *pRegistryItem,
                    [in] AppletRegistryEntryOwner  *pEntryOwner,
                    [in] AppletModificationRights   eRights);

    HRESULT AllocateHandleConfirm(
                    [in] HRESULT                hrResult,
                    [in] ULONG                  nFirstHandle,
                    [in] ULONG                  cHandles);

    HRESULT ChannelConfirm(
                    [in] AppletChannelCommand   eCommand,
                    [in] HRESULT                hrResult,
                    [in] AppletChannelID        nChannelID);

    HRESULT ChannelIndication(
                    [in] AppletChannelCommand   eCommand,
                    [in] AppletChannelID        nChannelID,
                    [in] AppletReason           eReason,
                    [in] AppletUserID           uidManager);

    HRESULT TokenConfirm(
                    [in] AppletTokenCommand     eCommand,
                    [in] HRESULT                hrResult,
                    [in] AppletTokenID          nTokenID);

    HRESULT TestTokenConfirm(
                    [in] AppletTokenID          nTokenID,
                    [in] AppletTokenStatus      eStatus);

    HRESULT TokenIndication(
                    [in] AppletTokenCommand     eCommand,
                    [in] AppletReason           eReason,
                    [in] AppletTokenID          nTokenID,
                    [in] AppletUserID           uidInitiator);
};



[
    object,
    uuid(UUID_IAppletSession),
    pointer_default(unique)
]
interface IAppletSession : IUnknown
{
    /* ------ Basic Info ------ */

    HRESULT GetConfID([out] AppletConfID *pnConfID);

    HRESULT IsThisNodeTopProvider([out] BOOL *pfTopProvider);

    /* ------ Join Conference ------ */

    HRESULT Join([in] AppletSessionRequest *pRequest);

    HRESULT Leave(void);

    /* ------ Send Data ------ */

    HRESULT SendData(
                    [in] BOOL               fUniformSend,
                    [in] AppletChannelID    nChannelID,
                    [in] AppletPriority     ePriority,
                    [in] ULONG              cbBufSize,
                    [in,size_is(cbBufSize)] BYTE *pBuffer);

    /* ------ Invoke Applet ------ */

    HRESULT InvokeApplet(
                    [out] AppletRequestTag     *pnReqTag,
                    [in] AppletProtocolEntity  *pAPE,
                    [in] ULONG                  cNodes,
                    [in,size_is(cNodes)] AppletNodeID aNodeIDs[]);

    /* ------ Inquiry ------ */

    HRESULT InquireRoster([in] AppletSessionKey *pSessionKey);

    /* ------ Registry Services ------ */

    HRESULT RegistryRequest([in] AppletRegistryRequest *pRequest);

    /* ------ Channel Services ------ */

    HRESULT ChannelRequest([in] AppletChannelRequest *pRequest);

    /* ------ Token Services ------ */

    HRESULT TokenRequest([in] AppletTokenRequest *pRequest);

    /* ------ Notification registration / unregistration------ */

    HRESULT Advise( [in] IAppletSessionNotify   *pNotify,
                    [out] DWORD                 *pdwCookie);

    HRESULT UnAdvise([in] DWORD dwCookie);

};




[
    object,
    uuid(UUID_IAppletNotify),
    pointer_default(unique)
]
interface IAppletNotify : IUnknown
{
    HRESULT PermitToJoinSessionIndication(
                    [in] AppletConfID   nConfID,
                    [in] BOOL           fPermissionGranted);

    HRESULT AutoJoinSessionIndication(
                    [in] IAppletSession    *pSession,
                    [in] HRESULT            hrResult,
                    [in] AppletUserID       uidMyself,
                    [in] AppletNodeID       nidMyself,
                    [in] AppletSessionID    sidMyself,
                    [in] AppletEntityID     eidMyself,
                    [in] ULONG              cDynamicChannels,
                    [in,size_is(cDynamicChannels)] AppletChannelID aDynamicChannels[]);
};



[
    object,
    uuid(UUID_IApplet),
    pointer_default(unique)
]
interface IApplet : IUnknown
{
    /* ------ Initialization ------ */

    HRESULT Initialize(void);

    /* ------ Auto Join ------ */

    HRESULT RegisterAutoJoin([in] AppletSessionRequest *pRequest);

    HRESULT UnregisterAutoJoin(void);

    /* ------ Session ------ */

    HRESULT CreateSession(
                    [out] IAppletSession **ppSession,
                    [in] AppletConfID nConfID);

    /* ------ Notification registration / unregistration------ */

    HRESULT Advise( [in] IAppletNotify *pNotify,
                    [out] DWORD *pdwCookie);

    HRESULT UnAdvise([in] DWORD dwCookie);

};



// These version numbers should match the version attribute in the library definitoen below
cpp_quote("enum { NmApplet_Ver_Major = 1};")
cpp_quote("enum { NmApplet_Ver_Minor = 0};")
[
	uuid(8C3ADF96-CCFE-11d2-AD10-00C04F72DD47),
	version(1.0),
	helpstring("NmApplet 1.0 Type Library")
]
library NmApplet	
{
	importlib("stdole2.tlb");

	[
		uuid(8C3ADF99-CCFE-11d2-AD10-00C04F72DD47),
		helpstring("NetMeeting Applet")
	]
	coclass NmApplet
	{
		[default] interface IApplet;
	};
};