import "unknwn.idl";
import "oaidl.idl";

interface IWTSPlugin;
interface IWTSListener;
interface IWTSListenerCallback;
interface IWTSVirtualChannelCallback;
interface IWTSVirtualChannelManager;
interface IWTSVirtualChannel;

cpp_quote("#define  WTS_PROPERTY_DEFAULT_CONFIG  L\"DefaultConfig\"") 

//
// =========================================================================
//
//  Interface:          IWTSPlugin
//
//  Implementation:     Plugin side (user)
//
//  Description:
//      Root interface implemented by the plugin for receiving notification
//      from the TS client. This is the default interface the COM object
//      should implement.
//
// =========================================================================
//
cpp_quote("EXTERN_C __declspec(selectany) const IID IID_IWTSPlugin = {0xA1230201, 0x1439, 0x4e62, { 0xa4, 0x14, 0x19, 0x0d, 0x0a, 0xc3, 0xd4, 0x0e}};")
[
    object,
    uuid(A1230201-1439-4e62-a414-190d0ac3d40e),
    oleautomation,
    helpstring("interface IWTSPlugin")
]
interface IWTSPlugin : IUnknown
{
    /*
     *  Called immediately after instantiating the COM class
     */
    [helpstring("Initialize")]
    HRESULT
    Initialize(
        [in] IWTSVirtualChannelManager *pChannelMgr
        );

    /*
     *  Called when the TS client is connected to the TS server
     */
    [helpstring("Connected")]
    HRESULT
    Connected();

    /*
     *  Called when the TS client is disconnected to the TS server
     *  Might be followed by another Connected() call
     */
    [helpstring("Disconnected")]
    HRESULT
    Disconnected(
        DWORD dwDisconnectCode
        );

    /*
     *  The last method called by the TS client before 
     *  terminating the object
     */
    [helpstring("Terminated")]
    HRESULT
    Terminated();
};

//
// =========================================================================
//
//  Interface:          IWTSListener
//
//  Implementation:     Client side (system)
//
//  Description:
//      With this interface the plugin can acquire configuration data for
//  for a listener. It is returned by 
//  IWTSVirtualChannelManager::CreateListener
//
// =========================================================================
//
cpp_quote("EXTERN_C __declspec(selectany) const IID IID_IWTSListener = {0xA1230206, 0x9a39, 0x4d58, {0x86, 0x74, 0xcd, 0xb4, 0xdf, 0xf4, 0xe7, 0x3b}};")
[
    object,
    uuid(A1230206-9a39-4d58-8674-cdb4dff4e73b),
    oleautomation,
    helpstring("interface IWTSListener")
]
interface IWTSListener : IUnknown
{
    [helpstring("GetConfiguration")]
    HRESULT
    GetConfiguration(
        [out] IPropertyBag ** ppPropertyBag
        ); 
};

//
// =========================================================================
//
//  Interface:          IWTSListenerCallback
//
//  Implementation:     Plugin side (user)
//
//  Description:
//      With this interface the plugin will receive notifications for
//      Incomming connected channels. Implemented by the client side
//      Set in IWTSVirtualChannelManager::CreateListener() method.
//
// =========================================================================
//
cpp_quote("EXTERN_C __declspec(selectany) const IID IID_IWTSListenerCallback = {0xA1230203, 0xd6a7, 0x11d8, {0xb9, 0xfd, 0x00, 0x0b, 0xdb, 0xd1, 0xf1, 0x98}};")
[
    object,
    uuid(A1230203-d6a7-11d8-b9fd-000bdbd1f198),
    oleautomation,
    helpstring("interface IWTSListenerCallback")

]
interface IWTSListenerCallback : IUnknown
{
    /*
     *  Called whenever a request for new channel connection
     *  from the server is received.
     */
    [helpstring("OnNewChannelConnection")]
    HRESULT
    OnNewChannelConnection (
        [in]            IWTSVirtualChannel   *pChannel,
        [in,ptr]        BSTR                data,           // optional data passed as part of the connect method
        [out]           BOOL                *pbAccept,      // the callee should return TRUE if connection is accepted
        [out]           IWTSVirtualChannelCallback **ppCallback
                                                            // connection related events
        );
};

//
// =========================================================================
//
//  Interface:          IWTSVirtualChannelCallback
//
//  Implementation:     Plugin side (user)
//
//  Description:
//      This interface receives data and close notifications for a specific
//      channel. Implemented by the plugin. Set in 
//      IWTSLisneterCallback::OnNewChannelConnection() method
//
// =========================================================================
//
cpp_quote("EXTERN_C __declspec(selectany) const IID IID_IWTSVirtualChannelCallback = {0xA1230204, 0xd6a7, 0x11d8, {0xb9, 0xfd, 0x00, 0x0b, 0xdb, 0xd1, 0xf1, 0x98}};")
[
    object,
    uuid(A1230204-d6a7-11d8-b9fd-000bdbd1f198),
    oleautomation,
    helpstring("interface IWTSVirtualChannelCallback")

]
interface IWTSVirtualChannelCallback : IUnknown
{
    /*
     *  Called whenever a full message from the server is received
     *  The message is fully reassembled and has the exact size
     *  as the Write() call on the server
     */
    [helpstring("OnDataReceived")]
    HRESULT
    OnDataReceived(
        [in]            ULONG               cbSize,             // size of data in bytes
        [in, size_is(cbSize)] BYTE          *pBuffer            // data buffer
        );

    /*
     *  The channel is disconnected, all Write() calls will fail
     *  no more incomming data is expected. 
     */
    [helpstring("OnClose")]
    HRESULT
    OnClose();
};

//
// =========================================================================
//
//  Interface:          IWTSVirtualChannelManager
//
//  Implementation:     Client side (system)
//
//  Description:
//      This interface is used by the plugin as a class factory for
//      listener objects. Implemented by the client, supplied in
//      IWTSPlugin::Initialize() method.
//
// =========================================================================
//
cpp_quote("EXTERN_C __declspec(selectany) const IID IID_IWTSVirtualChannelManager = {0xA1230205,0xd6a7,0x11d8,{0xb9,0xfd,0x00,0x0b,0xdb,0xd1,0xf1,0x98}};")
cpp_quote("#define  TS_VC_LISTENER_STATIC_CHANNEL   0x00000001")
[
    object,
    uuid(A1230205-d6a7-11d8-b9fd-000bdbd1f198),
    oleautomation,
    helpstring("interface IWTSVirtualChannelManager")
]
interface IWTSVirtualChannelManager : IUnknown
{
    /*
     *  The plugin requests to create a listener object
     *  with specific name
     */
    [helpstring("CreateListener")]
    HRESULT
    CreateListener(
        [in, string]    const char          *pszChannelName,
        [in]            ULONG               uFlags,             // TS_VC_LISTENER_STATIC_XXX flags
        [in]            IWTSListenerCallback *pListenerCallback,
        [out]           IWTSListener        **ppListener        // optional
        );
}

//
// =========================================================================
//
//  Interface:          IWTSVirtualChannel
//
//  Implementation:     Client side (system)
//
//  Description:
//      This interface is used by the plugin to send data and closing specific
//      channel. Implemented by the TS client side. 
//      Supplied in IWTSLisneterCallback::OnNewChannelConnection()
//
// =========================================================================
//
cpp_quote("EXTERN_C __declspec(selectany) const IID IID_IWTSVirtualChannel = { 0xA1230207, 0xd6a7, 0x11d8, { 0xb9, 0xfd, 0x00, 0x0b, 0xdb, 0xd1, 0xf1, 0x98} };")
[
    object,
    uuid(A1230207-d6a7-11d8-b9fd-000bdbd1f198),
    oleautomation,
    helpstring("interface IWTSVirtualChannel")
]
interface IWTSVirtualChannel : IUnknown
{
    /*
     *  The plugin requests to send data with specific size
     */
    [helpstring("Write")]
    HRESULT Write(
        [in]            ULONG               cbSize,
        [in, size_is(cbSize)] BYTE          *pBuffer,
        [in]            IUnknown            *pReserved          // must be NULL
        );

    /*
     *  The plugin requests to close the channel
     *  This will result in TSVirtualChannelCallback::OnClose() call.
     *  All I/O will cease.
     */
    [helpstring("Close")]
    HRESULT
    Close ();

};

