plugin.h

Go to the documentation of this file.
00001 #pragma once
00002 
00003 // Copyright 2010 Autodesk, Inc.  All rights reserved. 
00004 //
00005 // This computer source code and related instructions and comments are the
00006 // unpublished confidential and proprietary information of Autodesk, Inc. and
00007 // are protected under applicable copyright and trade secret law.  They may
00008 // not be disclosed to, copied or used by any third party without the prior
00009 // written consent of Autodesk, Inc.
00010 
00011 #include "maxheap.h"
00012 #include "strclass.h"
00013 #include "plugapi.h"
00014 #include "Path.h"
00015 #include "Noncopyable.h"
00016 #include "BuildWarnings.h"
00017 #include "DataClassDesc.h"
00018 
00027 typedef const ULONG (*LibVersionProcPtr)();
00028 
00031 typedef const MCHAR* (*LibDescriptionProcPtr)();
00032 
00036 typedef int (*LibNumberClassesProcPtr)();
00037 
00041 typedef ClassDesc* (*LibClassDescProcPtr)(int i);
00043 
00053 typedef int (*LibInitializeProcPtr)();
00054 
00058 typedef int (*LibShutdownProcPtr)();
00059 
00065 typedef ULONG (*CanAutoDeferProcPtr)();
00067 
00090 class DllDesc: public MaxHeapOperators
00091 {
00092 public:
00095     CoreExport bool IsLoaded() const;
00096 
00098     CoreExport const MCHAR* Description() const;
00099 
00102     CoreExport int NumberOfClasses() const;
00103 
00107     CoreExport ClassDesc* operator[](int i) const;
00108 
00113     CoreExport ClassDesc* GetClassDesc(int i) const;
00114 
00116     CoreExport int operator==( const DllDesc& dd ) const;
00117 
00123     CoreExport bool HasRttiSupport() const;
00124 
00128     CoreExport bool IsBinaryCompatible() const;
00129 
00131     CoreExport ULONG GetVersion() const;
00132 
00134     CoreExport bool IsDeferrable() const;
00135 
00137     CoreExport bool ImplementsCanAutoDefer() const;
00138 
00147     CoreExport static bool IsPluginDllVersionValid(ULONG pluginDllVersion);
00148 
00150     CoreExport const MSTR& GetFullPath() const;
00151 
00153     CoreExport const MSTR& GetFileName() const;
00154 
00157     CoreExport const MSTR& GetDirectoryName() const;
00158 
00161     CoreExport const HINSTANCE GetHandle() const;
00162 
00165     CoreExport DWORD GetSize() const;
00166 
00168     CoreExport FILETIME GetTimeLastModified() const;
00169 
00176     MAX_DEPRECATED void Free();
00177 
00181     MAX_DEPRECATED BOOL Initialize();
00182 
00186     MAX_DEPRECATED BOOL Shutdown();
00187 
00188     // The following methods are supposed to be used only internally, therefore
00189     // they are not exported.
00190 
00191     // Constructor - Use it to create a DllDesc that represents a plug-in DLL that was 
00192     // loaded (had a valid HINSTANCE), as  opposed to being defer loaded.
00193     explicit DllDesc(
00194         HINSTANCE dllHandle, 
00195         const MCHAR* dllFullPath, 
00196         LibVersionProcPtr libVersionProcPtr,
00197         LibDescriptionProcPtr libDescriptionProcPtr,
00198         LibNumberClassesProcPtr libNumberClassesProcPtr,
00199         LibClassDescProcPtr libClassDescProcPtr,
00200         LibInitializeProcPtr libInitializeProcPtr,
00201         LibShutdownProcPtr libShutdownProcPtr,
00202         CanAutoDeferProcPtr canAutoDeferProcPtr,
00203         const FILETIME& timeLastWrite);
00204 
00205     // Constructor - Use it create a DllDesc that represents a defer loaded plug-in DLL
00206     explicit DllDesc(const MCHAR* dllFullPath, const MCHAR* dllDescription, const FILETIME& timeLastWrite);
00207     
00208     // Unloads the plug-in DLL that corresponds to this DllDesc instance
00209     void Unload();
00210 
00211     // Calls a plug-in's LibInitialize method
00212     BOOL CallInitialize();
00213 
00214     // Calls a plug-in's LibShutdown method 
00215     BOOL CallShutdown();
00216 
00217     // Copy constructor 
00218     DllDesc(const DllDesc& other);
00219 
00220     // Assignment operator
00221     DllDesc operator=(const DllDesc& other);
00222 
00223     // Destructor 
00224     ~DllDesc(); 
00225 
00226 private:
00227     class DllDescImpl;
00228     MaxSDK::AutoPtr<DllDescImpl> mImpl;
00229 
00230     // Disallowed method
00231     DllDesc();
00232 };
00233 
00234 /*-----------------------------------------------------------------
00235 We will build one big DllDir on startup.
00236 As we do this, we will build a set of lists, one for each SuperClass.
00237 For a given super class, we want to 
00238 (a) Enumerate all public subclasses 
00239 (b) Enumerate all subclasses
00240 (c) Find the subClass for a given subClass ID.
00241 
00242 --------------------------------------------------------------*/
00243 
00251 #pragma warning(push)
00252 #pragma warning(disable:4100)
00253 class ClassEntry : public MaxHeapOperators
00254 {
00255     public:
00256         CoreExport ClassEntry();
00257         CoreExport ClassEntry(const ClassEntry &ce);
00258         CoreExport ClassEntry(ClassDesc *cld, int dllN, int index, bool load);
00259         CoreExport ~ClassEntry();
00260 
00263         CoreExport int DllNumber() const;
00264         
00267         CoreExport int IsPublic() const;
00268         
00270         CoreExport Class_ID ClassID() const;
00271         
00273         CoreExport MSTR& ClassName() const;
00274         
00276         CoreExport MSTR& Category() const;
00277 
00279         CoreExport int UseCount() const;
00280 
00282         CoreExport void IncUseCount();
00283 
00285         CoreExport void SetUseCount(int i);
00286 
00291         CoreExport int IsAccType(int accType);
00292         
00294         CoreExport bool IsLoaded() const;
00295 
00297         CoreExport int ClassNumber() const;
00298 
00303         CoreExport ClassDesc* CD() const;
00304 
00311         CoreExport ClassDesc* FullCD();
00312 
00314         CoreExport ClassEntry& operator=( const ClassEntry &ce ); 
00315 
00317         CoreExport int operator==( const ClassEntry &ce ) const;
00318 
00322         CoreExport void Set(ClassDesc *cld, int dllN, int index, bool load);
00323 
00325         CoreExport int GetScroll() const;
00326 
00328         CoreExport void SetScroll(int s); 
00329 
00331         CoreExport BOOL PageStateSet() const; 
00332 
00334         CoreExport BOOL GetPageState(int i) const;
00335 
00337         CoreExport void SetPageState(int i,BOOL state);
00338 
00340         CoreExport DWORD GetPageState() const;
00342 
00343     private:
00344         class ClassEntryImpl;
00345         MaxSDK::Util::AutoPtr<ClassEntryImpl> mImpl;
00346 };
00347 
00348 
00352 #define ACC_PUBLIC 1 
00353 
00355 #define ACC_PRIVATE 2 
00356 
00357 #define ACC_ALL (ACC_PUBLIC|ACC_PRIVATE)
00358 
00359 
00367 class SClassUIInfo: public MaxHeapOperators
00368     {
00369     public:
00370         virtual ~SClassUIInfo() {}
00371     // A color associated with the superclass.  This is currently used to draw nodes
00372     // in the schematic view at extreme zoom-outs where it is impossible to draw
00373     // legible node names.
00380     CoreExport virtual COLORREF Color(SClass_ID superClassID) { return RGB(128, 128, 128); };
00381 
00382     // Draws an image which represents the superclass (usually an icon) in a rectangle
00383     // in a given Windows DC.  The implementation should attempt to draw the image as fast
00384     // as possible as this method is called repeatedly while drawing certain UI
00385     // components.  Return false if no image was drawn and a generic stand-in image will
00386     // be used.  The provided "bkColor" is the average background color of the surface on
00387     // which the image is being drawn.  It can be used, if desired, to antialias the image.
00406     CoreExport virtual bool DrawRepresentation(SClass_ID superClassID, COLORREF bkColor, HDC hDC, Rect &rect) { return false; }
00407 };
00408 
00409 
00414 class SubClassList : public MaxSDK::Util::Noncopyable
00415 {
00416     public:
00419     CoreExport ClassEntry& operator[](int i)const;
00420 
00423     CoreExport int FindClass(Class_ID classID) const;
00424     
00427     CoreExport int FindClass(const MCHAR *name) const;
00428     
00430     CoreExport void AddClass(ClassDesc *cld, int dllNum, int index, bool load); 
00431 
00437     CoreExport int  Count(int accType) const;
00438     
00440     CoreExport SClass_ID SuperID() const;
00441     
00446     CoreExport int GetFirst(int accType) const;
00447 
00452     CoreExport int GetNext(int accType) const;
00453 
00455     CoreExport int operator==( const SubClassList& lst ) const;
00457     CoreExport int operator==(const SubClassList &sl);
00458 
00459     CoreExport int DeleteClass(ClassDesc *cld); 
00460 
00465     CoreExport void SetUIInfo(SClassUIInfo *uiInfo);
00466 
00469     CoreExport SClassUIInfo* GetUIInfo() const;
00470 
00472     CoreExport void ReplaceClass(int idx, ClassDesc *cld, int dllNum, int index, bool load); 
00473 
00475     ~SubClassList();
00477     SubClassList(SClass_ID sid);
00478 
00479 private:
00480     class SubClassListImpl;
00481     MaxSDK::Util::AutoPtr<SubClassListImpl> mImpl;
00482 
00483 private:
00484     SubClassList(); // disallowed
00485 };
00486 #pragma warning(pop)
00487 
00500 class ClassDirectory : public MaxSDK::Util::Noncopyable 
00501 {
00502 public:
00504     CoreExport static ClassDirectory& GetInstance();
00505 
00508     CoreExport SubClassList* GetClassList(SClass_ID superClassID) const;
00509 
00511     CoreExport int Count() const;
00512 
00515     CoreExport SubClassList& operator[](int i) const;
00516 
00520     CoreExport ClassDesc* FindClass(SClass_ID superClassID, const Class_ID& classID) const;
00521 
00525     CoreExport ClassEntry* FindClassEntry(SClass_ID superClassID, const Class_ID& classID) const;
00526 
00536     CoreExport int AddClass(ClassDesc* cdesc, int dllNum, int index, bool load);
00537 
00540     CoreExport int DeleteClass(ClassDesc* cdesc);
00541 
00548     CoreExport bool SetUIInfoForSClass(SClass_ID superClassID, SClassUIInfo* uiInfo);
00549 
00554     CoreExport SClassUIInfo* GetUIInfoForSClass(SClass_ID superClassID) const;
00555 
00557     ClassDirectory();
00559     ~ClassDirectory();
00560 
00561 private:
00562     class ClassDirectoryImpl;
00563     MaxSDK::Util::AutoPtr<ClassDirectoryImpl> mImpl;
00564 
00566     void AddSuperClass(SClass_ID superClassID);
00567 };
00568 
00586 class DllDir : public MaxSDK::Util::Noncopyable
00587 {
00588     public:
00590         CoreExport static DllDir& GetInstance();
00591 
00592         /* Destructor */
00593         virtual  ~DllDir() = 0;
00594 
00596         CoreExport int Count() const;
00597 
00600         CoreExport const DllDesc& operator[](int i) const;
00601 
00604         CoreExport const DllDesc& GetDllDescription(int i) const;
00605 
00633         CoreExport int LoadDlls(const MCHAR* pluginWildcard, bool forceLoadDeferrablepluginDlls = false);
00634 
00645         CoreExport int LoadDllsFromDir(const MCHAR* pluginPath, const MCHAR* pluginWildcard, bool forceLoadDeferrablePluginDlls = false);
00646 
00655         CoreExport bool LoadADll(const MCHAR* pluginDllFileName, bool forceLoadDeferrablePluginDlls);
00657 
00659         CoreExport ClassDirectory& ClassDir() const;
00660 
00665         CoreExport const DllDesc* GetDllDescriptionForClass(SClass_ID superClassId, const Class_ID& classId);
00666 
00670         CoreExport int FindDllDescFromDllPath(const MaxSDK::Util::Path& aFullPath) const;
00671 
00675         CoreExport int FindDllDescFromHInstance(const HINSTANCE hInst) const;
00676 
00679         MAX_DEPRECATED void UnloadAllDlls();
00680 
00681     protected:
00682         // Constructor
00683         DllDir();
00684         class DllDirImpl;
00685         MaxSDK::AutoPtr<DllDirImpl> mImpl;
00686 
00687     private:
00688         bool LoadADllProxy(const MaxSDK::Util::Path& filePath, const MCHAR* description, const FILETIME& timeLastWrite);
00689 
00690 };
00691