GME  13
MgaTerritory.cpp
Go to the documentation of this file.
00001 #include "stdAfx.h"
00002 #include "MgaTerritory.h"
00003 // ----------------------------------------
00004 // Implementation for the MgaTerritory and MgaAddOn  classes
00005 // ----------------------------------------
00006 
00007 
00008 
00009 STDMETHODIMP CMgaTerritory::Associate( IMgaObject *obj,  VARIANT userdata) { 
00010         COMTRY {
00011                         CHECK_MYINPTRPAR(obj);
00012                         if(!coreterr) COMTHROW( E_MGA_TARGET_DESTROYED);
00013                         ObjFor(obj)->objsetuserdata(this, userdata);
00014         } COMCATCH(;);
00015                         
00016 };
00017 
00018 STDMETHODIMP CMgaTerritory::OpenObj(IMgaObject *oldptr, IMgaObject **newptr) { 
00019         COMTRY {
00020                 CHECK_MYINPTRPAR(oldptr); 
00021                 CHECK_OUTPAR(newptr); 
00022                 CComPtr<IMgaObject> np;
00023                 if(!coreterr) COMTHROW(E_MGA_TARGET_DESTROYED);
00024                 ObjFor(oldptr)->getinterface(&np,this);
00025                 *newptr = np.Detach();
00026         } COMCATCH(;) 
00027 }
00028 
00029 STDMETHODIMP CMgaTerritory::OpenFCO(IMgaFCO *oldptr, IMgaFCO **newptr) { 
00030         COMTRY {
00031                 CHECK_MYINPTRPAR(oldptr); 
00032                 CHECK_OUTPAR(newptr); 
00033                 CComPtr<IMgaFCO> np;
00034                 if(!coreterr) COMTHROW(E_MGA_TARGET_DESTROYED);
00035                 ObjFor(oldptr)->getinterface(&np,this);
00036                 *newptr = np.Detach();
00037         } COMCATCH(;) 
00038 }
00039 
00040 STDMETHODIMP CMgaTerritory::OpenFCOs(IMgaFCOs *oldptr, IMgaFCOs **newptr) { 
00041         COMTRY {
00042                 CHECK_MYINPTRSPAR(oldptr); 
00043                 CHECK_OUTPAR(newptr); 
00044                 CREATEEXCOLLECTION_FOR(MgaFCO, q);
00045                 if(!coreterr) COMTHROW(E_MGA_TARGET_DESTROYED);
00046                 MGACOLL_ITERATE(IMgaFCO, oldptr) {
00047                         CComPtr<IMgaFCO> bb;
00048                     ObjFor(MGACOLL_ITER)->getinterface(&bb);
00049                         q->Add(bb);
00050                 }
00051                 MGACOLL_ITERATE_END;
00052                 *newptr = q.Detach();
00053         } COMCATCH(;) 
00054 }
00055 
00056 
00057 STDMETHODIMP CMgaTerritory::CloseObj(IMgaObject *obj) {
00058         COMTRY {
00059                 CHECK_MYINPTRPAR(obj); 
00060                 if(!coreterr) COMTHROW(E_MGA_TARGET_DESTROYED);
00061                 COMTHROW(obj->Close());
00062         } COMCATCH(;) 
00063 }
00064 
00065 STDMETHODIMP CMgaTerritory::Flush() {
00066         COMTRY {
00067                 if(coreterr) {
00068                         HRESULT hr = coreterr->Clear();
00069                         if (FAILED(hr))
00070                                 COMRETURN(hr);
00071                 }
00072         } COMCATCH(;);
00073         
00074 };
00075 
00076 
00077 STDMETHODIMP CMgaTerritory::CheckProject(IMgaProject *project) {
00078         return(project == mgaproject? S_OK : E_MGA_FOREIGN_PROJECT);
00079 }
00080 
00081 
00082 STDMETHODIMP CMgaTerritory::Destroy() {
00083         COMTRY {
00084                 if (!coreterr) 
00085                         return E_MGA_TARGET_DESTROYED;
00086                 // n.b. Flush fails if the project has been closed, but if we're being destructed, we must still remove
00087                 // this from allterrs, or MgaProject::~MgaProject will crash (as allterrs does not count references)
00088                 HRESULT hr = Flush();
00089                 CMgaProject::tercoll::iterator i = mgaproject->allterrs.begin(), end = mgaproject->allterrs.end();
00090                 for(;i != end; ++i) {
00091                         if(*i == this) {
00092                                 mgaproject->allterrs.erase(i);
00093                                 coreterr = NULL;   // release CoreTerritory object
00094                                 handler = NULL; // release sink
00095                                 rwhandler = NULL;       // release sink
00096                                 COMRETURN(hr);
00097                         }
00098                         
00099                 }
00100                 ASSERT(false);  // not found among project territories
00101                 COMRETURN(hr);
00102         } COMCATCH(;)
00103 }
00104 
00105 
00106 STDMETHODIMP CMgaTerritory::SetNamespace( BSTR pNmsp)
00107 {
00108         COMTRY {
00109                 m_bstrCurrNamespace = pNmsp;
00110                 mgaproject->SetNmspaceInMeta(); // set into the metaproject if open
00111         } COMCATCH(;)
00112 }
00113 
00114 STDMETHODIMP CMgaTerritory::GetNamespace( BSTR * pNmsp)
00115 {
00116         COMTRY {
00117                 if( m_bstrCurrNamespace.Length() > 0) // namespace set
00118                 {
00119                         CComBSTR res;
00120                         COMTHROW(res.AppendBSTR( m_bstrCurrNamespace));
00121                         *pNmsp = res.Detach();
00122                 }
00123                 else
00124                 {
00125                         *pNmsp = nullptr;
00126                 }
00127         } COMCATCH(;)
00128 }
00129 
00130 STDMETHODIMP CMgaAddOn::CheckProject(IMgaProject *project) {
00131         return(project == mgaproject? S_OK : E_MGA_FOREIGN_PROJECT);
00132 }
00133 
00134 
00135 STDMETHODIMP CMgaAddOn::Destroy() {
00136         COMTRY {
00137                 MARKSIG('8'); 
00138                 if(!handler) COMTHROW(E_MGA_TARGET_DESTROYED);
00139                 CMgaProject::addoncoll::iterator i = mgaproject->alladdons.begin(), end = mgaproject->alladdons.end();
00140                 for(;i != end; ++i) {
00141                         if(*i == this) {
00142                                 mgaproject->alladdons.erase(i);
00143                                 if(mgaproject->alladdons.empty()) mgaproject->reserveterr = NULL;   // release 
00144                                 handler = NULL; // release sink
00145                                 return S_OK;
00146                         }
00147                         
00148                 }
00149                 ASSERT(("addon not found among project addons",false)); 
00150                 active = false;
00151         } COMCATCH(;)
00152 }
00153 
00154 
00155 STDMETHODIMP CMgaAddOn::get_Priority( long *pVal) { return E_MGA_NOT_IMPLEMENTED; }
00156 STDMETHODIMP CMgaAddOn::put_Priority( long newVal) { return E_MGA_NOT_IMPLEMENTED; }
00157 
00158