baseinterface.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: baseInterface.h
00004 
00005     DESCRIPTION: Base classes for various interfaces in MAX
00006 
00007     CREATED BY: John Wainwright
00008 
00009     HISTORY: created 9/5/00
00010 
00011  *> Copyright (c) 2000 Autodesk, All Rights Reserved.
00012  **********************************************************************/
00013 
00014 #pragma once
00015 
00016 #include "maxheap.h"
00017 #include "buildver.h"
00018 #include "maxtypes.h"
00019 #include "tab.h"
00020 
00021 class InterfaceServer;
00022 class BaseInterfaceServer;
00023 class BaseInterface;
00024 class InterfaceNotifyCallback;
00025 
00026 // ID for BaseInterfaces
00027 #define BASEINTERFACE_ID Interface_ID(0, 1)
00028 
00029 // Base class for those classes and interfaces in MAX that can serve interfaces.  
00038 class InterfaceServer: public MaxHeapOperators
00039 {
00040 public:
00041     // Note that this dtor should be pure virtual since this class is an interface 
00042     // and so it's meant to be instantiated directly.
00043     // Note that a virtual dtor requires an implementation.
00044     // For more info, see this MSDN article: ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_vclang/html/8d7d1303-b9e9-47ca-96cc-67bf444a08a9.htm
00046     UtilExport virtual ~InterfaceServer();
00047 
00054     UtilExport virtual BaseInterface* GetInterface(Interface_ID id);
00055 };
00056 
00057 // The base class for interfaces in MAX R4.  
00058 //   Provides basic identity, sub-interface access, lifetime management and 
00059 //   cloning methods.   The base class for FPInterface in the FnPub system.
00060 //  
00069 class BaseInterface : public InterfaceServer
00070 {
00071 public:
00072     // Note that this dtor should be pure virtual since this class is an interface 
00073     // and so it's meant to be instantiated directly.
00075     UtilExport virtual ~BaseInterface();
00076 
00077     // from InterfaceServer
00078     UtilExport BaseInterface* GetInterface(Interface_ID id);
00079 
00080     // identification
00082     UtilExport virtual Interface_ID GetID();
00083 
00084     // interface lifetime management
00085     //   there is an implied Acquire() whenever an interface is served via a GetInterface()
00086     //   normally requiring a matching Release() from the client
00087     //   can optionally use LifetimeControl() method to inquire about actual
00088     //   lifetime policy of client and provide a server-controlled delete notify callback
00089     //      'noRelease' means don't need to call release, use interface as long as you like. 
00090     //      'immediateRelease' means the interface is good for only one call, but the release 
00091     //          is implied, you don't need to call release.
00092     //      'wantsRelease' means the clients are controlling lifetime so the interface needs 
00093     //          a Release() when the client has finished (default).
00094     //      'serverControlled' means the server controls lifetime and will use the InterfaceNotifyCallback 
00095     //          to tell you when it is gone.
00096     enum LifetimeType { noRelease, immediateRelease, wantsRelease, serverControlled }; 
00097 
00098     // LifetimeControl returns noRelease since 
00099     // AcquireInterface and ReleaseInterface do not perform 
00100     // any real acquiring and releasing (reference counting, etc.)
00101     // If the implementation of AcquireInterface and ReleaseInterface changes
00102     // in this class or derived classes, the return value of LifetimeControl 
00103     // needs to be updated accordingly.
00104     // RegisterNotifyCallback returns true if the callback will be called at or before deletion
00121     virtual LifetimeType    LifetimeControl() { return noRelease; }
00122 
00129     virtual bool            RegisterNotifyCallback(InterfaceNotifyCallback* incb) { UNUSED_PARAM(incb); return false; }
00137     virtual void            UnRegisterNotifyCallback(InterfaceNotifyCallback* incb) { UNUSED_PARAM(incb); }
00144     virtual BaseInterface*  AcquireInterface() { return (BaseInterface*)this; }; 
00148     virtual void            ReleaseInterface() { };
00149 
00150     // direct interface delete request
00154     virtual void            DeleteInterface() { };
00155 
00156     // interface cloning
00163     virtual BaseInterface*  CloneInterface(void* remapDir = NULL) { UNUSED_PARAM(remapDir); return NULL; }
00164 };
00165 
00166 // BaseInterface server specializes InterfaceServer with an implementation
00167 //   based on a Tab<> of interface pointers for storing interfaces, 
00168 //   typically extension interfaces, and providing an interface iteration
00169 //   protocol.
00170 //   class IObject in the FnPub system specializes BaseInterfaceServer 
00181 class BaseInterfaceServer : public InterfaceServer
00182 {
00183 protected:
00184     Tab<BaseInterface*> interfaces;
00185 
00186 public:
00187     // interface serving, default implementation looks in interfaces table
00193     UtilExport virtual BaseInterface* GetInterface(Interface_ID id);
00194 
00195     // interface enumeration...
00199     UtilExport virtual int NumInterfaces() const;
00200 
00209     UtilExport virtual BaseInterface* GetInterfaceAt(int i) const;
00210 
00211     // Note that this dtor should be pure virtual since this class is an interface 
00212     // and so it's meant to be instantiated directly.
00215     UtilExport virtual ~BaseInterfaceServer();
00216 };
00217 
00218 // InterfaceNotifyCallback base class,  //   can be specialized by clients of an interface that controls its own lifetime
00219 //   so that they can be notified when the interface is deleted or other changes occur.
00220 //   registered with the interface via the lifetime control protocol 
00227 class InterfaceNotifyCallback: public MaxHeapOperators
00228 {
00229 public:
00230     // notify server is deleting  the interface
00238     virtual void InterfaceDeleted(BaseInterface* bi) { UNUSED_PARAM(bi); }
00239 
00240     // for future notification extensions
00247     virtual BaseInterface* GetInterface(Interface_ID id) { UNUSED_PARAM(id); return NULL; }
00248 };
00249