GME  13
MgaTerritory.h
Go to the documentation of this file.
00001 // ----------------------------------------
00002 // Definition of MgaTerritory and MgaAddOn
00003 // ----------------------------------------
00004 #ifndef __MGATERRITORY_H_
00005 #define __MGATERRITORY_H_
00006 
00008 // CMgaTerritory
00009 
00010 
00011 
00012 class ATL_NO_VTABLE CMgaTerritory : 
00013         public CComObjectRootEx<CComSingleThreadModel>,
00014         public CComCoClass<CMgaTerritory, &__uuidof(MgaTerritory)>,
00015         public IDispatchImpl<IMgaTerritory, &__uuidof(IMgaTerritory), &__uuidof(__MGALib)>
00016         // TODO: ISupportErrorInfo
00017 {
00018 public:
00019     DEFSIG;
00020         typedef std::set<FCOPtr>        objsetcoll;
00021         objsetcoll inobjs;
00022         CMgaTerritory() {
00023                 INITSIG('T');
00024 #ifdef DEBUG
00025                 MGA_TRACE("Constructed: %s - %08X\n", sig, this);
00026 #endif
00027                 notified = false;
00028                 eventmask = 0xFFFFFFFF;
00029                 rweventmask = 0;
00030                 refcnt = 0;
00031         }
00032 
00033         ~CMgaTerritory()        { 
00034 #ifdef DEBUG
00035                 MGA_TRACE("Destructed: %s - %08X\n", sig, this);
00036 #endif
00037                 MARKSIG('9'); 
00038                 if(coreterr) Destroy(); 
00039         }
00040 
00041 DECLARE_PROTECT_FINAL_CONSTRUCT()
00042 
00043 BEGIN_COM_MAP(CMgaTerritory)
00044         COM_INTERFACE_ENTRY(IMgaTerritory)
00045         COM_INTERFACE_ENTRY(IDispatch)
00046 END_COM_MAP()
00047 
00048 // IMgaTerritory
00049 public:
00050         STDMETHOD(Flush)();
00051         STDMETHOD(Destroy)();
00052         STDMETHOD(put_EventMask)( unsigned long mask) { 
00053                 COMTRY {
00054                         if(!coreterr) COMTHROW(E_MGA_TARGET_DESTROYED);
00055                         eventmask = mask;
00056                 } COMCATCH(;);
00057         };
00058         STDMETHOD(put_RWEventMask)( unsigned long mask) { 
00059                 COMTRY {
00060                         if(!coreterr) COMTHROW(E_MGA_TARGET_DESTROYED);
00061                         rweventmask = mask;
00062                 } COMCATCH(;);
00063         };
00064         STDMETHOD(Associate)( IMgaObject *obj,  VARIANT userdata);
00065         STDMETHOD(get_Project)(IMgaProject **pVal) { 
00066                 COMTRY {
00067                         CHECK_OUTPTRPAR(pVal); 
00068                         if(!coreterr) COMTHROW(E_MGA_TARGET_DESTROYED);
00069                         *pVal = mgaproject; (*pVal)->AddRef(); 
00070                 } COMCATCH(;)
00071         } 
00072         STDMETHOD(CheckProject)( IMgaProject *project);  
00073         STDMETHOD(OpenObj)(IMgaObject *oldptr, IMgaObject **newptr);
00074         STDMETHOD(OpenFCO)(IMgaFCO *oldptr, IMgaFCO **newptr);
00075         STDMETHOD(OpenFCOs)(IMgaFCOs *oldptr, IMgaFCOs **newptr);
00076         STDMETHOD(CloseObj)(IMgaObject *obj);
00077         STDMETHOD(SetNamespace)( BSTR pNmsp);
00078         STDMETHOD(GetNamespace)( BSTR * pNmsp);
00079         CMgaProject *mgaproject;
00080         bool notified;
00081         unsigned long eventmask, rweventmask;
00082         CComPtr<ICoreTerritory> coreterr;    // non-null if object active 
00083         CComPtr<IMgaEventSink> handler, rwhandler;
00084         int refcnt;
00085         CComBSTR m_bstrCurrNamespace;
00086 };
00087 
00088 
00089 
00091 // CMgaAddOn
00092 class ATL_NO_VTABLE CMgaAddOn : 
00093         public CComObjectRootEx<CComSingleThreadModel>,
00094         public CComCoClass<CMgaAddOn, &__uuidof(MgaAddOn)>,
00095         public IDispatchImpl<IMgaAddOn, &__uuidof(IMgaAddOn), &__uuidof(__MGALib)>
00096 {
00097     DEFSIG;
00098         bool active;
00099         bool automatic;   // this addon was created automatically
00100 public:
00101         CMgaAddOn()     {
00102                 INITSIG('A');
00103 #ifdef DEBUG
00104                 MGA_TRACE("Constructed: %s - %08X\n", sig, this);
00105 #endif
00106                 active = true;
00107                 notified = false;
00108                 automatic = false;
00109         }
00110         ~CMgaAddOn()    {
00111 #ifdef DEBUG
00112                 MGA_TRACE("Destructed: %s - %08X\n", sig, this);
00113 #endif
00114                 MARKSIG('9'); 
00115                 if(active) Destroy();   
00116         }
00117 
00118         void SetAutomatic() { automatic = true; }
00119         bool IsAutomatic() { return automatic; }
00120 
00121 DECLARE_PROTECT_FINAL_CONSTRUCT()
00122 
00123 BEGIN_COM_MAP(CMgaAddOn)
00124         COM_INTERFACE_ENTRY(IMgaAddOn)
00125         COM_INTERFACE_ENTRY(IDispatch)
00126 END_COM_MAP()
00127 
00128 // IMgaAddOn
00129 public:
00130         STDMETHOD(get_Priority)( long *pVal);
00131         STDMETHOD(put_Priority)( long newVal);
00132         STDMETHOD(put_EventMask)( unsigned long mask) { 
00133                 COMTRY {
00134                         if(!handler) COMTHROW( E_MGA_TARGET_DESTROYED);
00135                         eventmask = mask;
00136                 } COMCATCH(;);
00137         };
00138         STDMETHOD(get_Project)(IMgaProject **pVal) { 
00139                 COMTRY {
00140                         if(!handler) COMTHROW( E_MGA_TARGET_DESTROYED);
00141                         CHECK_OUTPTRPAR(pVal); 
00142                         *pVal = mgaproject; (*pVal)->AddRef(); 
00143                 } COMCATCH(;);
00144         };
00145         STDMETHOD(CheckProject)( IMgaProject *project);  
00146         STDMETHOD(Destroy)();
00147 
00148         unsigned long eventmask;
00149         bool notified;
00150         CMgaProject *mgaproject;
00151         _bstr_t progid;
00152         CComPtr<IMgaEventSink> handler;    // non-null if object active 
00153 };
00154 
00155 #endif // __MGATERRITORY_H_