GME  13
CoreObject.h
Go to the documentation of this file.
00001 
00002 #ifndef MGA_COREOBJECT_H
00003 #define MGA_COREOBJECT_H
00004 
00005 #include "CoreTransactionItem.h"
00006 #include "CoreMetaObject.h"
00007 
00008 #include <list>
00009 //#include <slist>
00010 
00011 const locking_type PUT_DELETE_DONE_LOCK = 55;
00012 
00013 class CCoreProject;
00014 class CCoreAttribute;
00015 class CCoreLockAttribute;
00016 class CCoreMetaObject;
00017 
00018 // --------------------------- CCoreObject
00019 
00020 class ATL_NO_VTABLE CCoreObject : 
00021         public CComObjectRootEx<CComSingleThreadModel>,
00022         public IDispatchImpl<ICoreObject, &__uuidof(ICoreObject), &__uuidof(__MGACoreLib)>,
00023         public CCoreFinalTrItemImpl<&__uuidof(ICoreObject)>
00024 {
00025 public:
00026         CCoreObject();
00027         virtual ~CCoreObject();
00028 
00029 #ifdef DEBUG
00030         char footprint[4];
00031 #endif
00032 
00033         static CComObjPtr<CCoreObject> Create(CCoreProject *project, metaid_type metaid, objid_type objid);
00034 
00035 DECLARE_GET_CONTROLLING_UNKNOWN()
00036 
00037 BEGIN_COM_MAP(CCoreObject)
00038         COM_INTERFACE_ENTRY(ICoreObject)
00039         COM_INTERFACE_ENTRY(ISupportErrorInfo)
00040         COM_INTERFACE_ENTRY_FUNC_BLIND(0, &CCoreObject::AggregatedInterfaceLookup)
00041 END_COM_MAP()
00042 
00043         STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid)
00044         {
00045                 // TODO: go through all the aggregates and look for that interface?
00046                 return true ? S_OK : S_FALSE;
00047         }
00048 
00049         static HRESULT WINAPI AggregatedInterfaceLookup(void *pvThis, REFIID riid, LPVOID *ppv, DWORD_PTR dw);          
00050 
00051 // ------- COM methods
00052 
00053 public:
00054         STDMETHODIMP get_Project(ICoreProject **p);
00055         STDMETHODIMP get_MetaObject(ICoreMetaObject **p);
00056         STDMETHODIMP get_ObjID(objid_type *p);
00057         STDMETHODIMP get_Attribute(attrid_type attrid, ICoreAttribute **p);
00058         STDMETHODIMP GetAttributeDisp(attrid_type attrid, ICoreAttribute **p) { return get_Attribute( attrid, p); }
00059         STDMETHODIMP get_Attributes(ICoreAttributes **p);
00060         STDMETHODIMP get_AttributeValue(attrid_type attrid, VARIANT *p);
00061         STDMETHODIMP GetAttributeValueDisp(attrid_type attrid, VARIANT *p) { return get_AttributeValue( attrid, p); }
00062         STDMETHODIMP put_AttributeValue(attrid_type attrid, VARIANT p);
00063         STDMETHODIMP SetAttributeValueDisp(attrid_type attrid, VARIANT p) { return put_AttributeValue( attrid, p); }
00064         STDMETHODIMP get_LoadedAttrValue(attrid_type attrid, VARIANT *p);
00065         STDMETHODIMP GetLoadedAttrValueDisp(attrid_type attrid, VARIANT *p) { return get_LoadedAttrValue( attrid, p); }
00066         STDMETHODIMP get_PreviousAttrValue(attrid_type attrid, VARIANT *p);
00067         STDMETHODIMP GetPreviousAttrValueDisp(attrid_type attrid, VARIANT *p) { return get_PreviousAttrValue( attrid, p); }
00068         STDMETHODIMP get_PeerLockValue(attrid_type attrid, locking_type *p);
00069         STDMETHODIMP GetPeerLockValueDisp(attrid_type attrid, locking_type *p) { return get_PeerLockValue( attrid, p); }
00070         STDMETHODIMP SearchCollection(attrid_type coll_attrid, attrid_type search_attrid,
00071                 VARIANT search_value, ICoreObject **p);
00072         STDMETHODIMP get_IsDeleted(VARIANT_BOOL *p);
00073         STDMETHODIMP Delete();
00074         STDMETHODIMP Clone(ICoreObject **p);
00075 
00076 // ------- Properties
00077         
00078 protected:
00079         CComObjPtr<CCoreProject> project;
00080         CComObjPtr<CCoreMetaObject> metaobject;
00081         objid_type objid;
00082 
00083         typedef core::forward_list<CCoreAttribute*> attributes_type;
00084         typedef attributes_type::iterator attributes_iterator;
00085         attributes_type attributes;
00086 
00087         typedef core::forward_list< CComObjPtr<IUnknown> > aggregates_type;
00088         typedef aggregates_type::iterator aggregates_iterator;
00089         aggregates_type aggregates;
00090 
00091         typedef unsigned char status_type;
00092         status_type status;
00093 
00094 // ------- Creation 
00095 
00096 public:
00097         void CreateAttributes();
00098         void CreateAggregates();
00099         void FillAfterCreateObject();
00100 
00101 // ------- Methods
00102 
00103 public:
00104         objid_type GetObjID() const NOTHROW { return objid; }
00105         CCoreProject *GetProject() const NOTHROW { ASSERT( project ); return project; }
00106         CCoreMetaObject *GetMetaObject() const NOTHROW { ASSERT( metaobject ); return metaobject; }
00107         metaid_type GetMetaID() const NOTHROW { ASSERT( metaobject ); return metaobject->GetMetaID(); }
00108 
00109         CCoreAttribute *FindAttribute(attrid_type attrid) const NOTHROW;
00110 
00111         void RegisterAttribute(CCoreAttribute *attribute) NOTHROW;
00112         void UnregisterAttribute(CCoreAttribute *attribute) NOTHROW;
00113 
00114         template<class Functor, class UnwindFunctor>
00115         void GetAttributes(CCoreLockAttribute *lockattribute, Functor& f, UnwindFunctor& uf);
00116 
00117         void LoadAttributes(CCoreLockAttribute *lockattribute);
00118         void UnloadAttributes(CCoreLockAttribute *lockattribute) NOTHROW;
00119 
00120 // ------- Status
00121 
00122 #define COREOBJECT_DIRTY                                0x0001
00123 
00124 public:
00125         void SetStatusFlag(status_type flags) NOTHROW { status |= flags; }
00126         void ResetStatusFlag(status_type flags) NOTHROW { status &= ~flags; }
00127         bool GetStatusFlag(status_type flag) const NOTHROW { return (status & flag) != 0; }
00128 
00129 public:
00130         bool InTransaction() const NOTHROW;
00131         bool InWriteTransaction() const NOTHROW;
00132         bool IsZombie() const NOTHROW { return project == NULL; }
00133         void SetZombie() NOTHROW;
00134 
00135         bool IsDirty() const NOTHROW { return GetStatusFlag(COREOBJECT_DIRTY); }
00136         void SetDirty() NOTHROW { SetStatusFlag(COREOBJECT_DIRTY); }
00137         void ResetDirty() NOTHROW { ResetStatusFlag(COREOBJECT_DIRTY); }
00138 
00139         bool HasEmptyPointers() const NOTHROW;
00140         bool HasEmptyPointersAndLocks() const NOTHROW;
00141 
00142 // ------- Debug
00143 
00144 #ifdef _DEBUG
00145 public:
00146         void Dump();
00147 #endif
00148 
00149 // ------- FinalTrItem
00150 
00151 public:
00152         void RegisterFinalTrItem() NOTHROW;
00153 
00154         virtual void AbortFinalTransaction() NOTHROW;
00155         virtual void CommitFinalTransaction();
00156         virtual void CommitFinalTransactionFinish(bool undo) NOTHROW;
00157 #ifdef _ATL_DEBUG_INTERFACES
00158         std::vector<CComPtr<IUnknown> > cleanup;
00159 #endif
00160 };
00161 
00162 #ifndef _ATL_DEBUG_INTERFACES
00163 inline IUnknown *CastToUnknown(CCoreObject *p) { return (IUnknown*)(ICoreObject*)p; }
00164 inline CCoreObject *CastToObject(IUnknown *p) { return (CCoreObject*)(ICoreObject*)p; }
00165 inline IUnknown *CastToUnknown_Object(CCoreObject *p) { return CastToUnknown(p); }
00166 #else
00167 inline CComPtr<IUnknown> CastToUnknown(CCoreObject *p)
00168 {
00169         CComPtr<IUnknown> pUnk;
00170         p->QueryInterface(IID_IUnknown, (void**)&pUnk.p);
00171         p->cleanup.push_back(pUnk);
00172         return pUnk;
00173 }
00174 
00175 inline CComPtr<IUnknown> CastToUnknown_Object(CCoreObject *p)
00176 {
00177         CComPtr<IUnknown> pUnk;
00178         p->QueryInterface(IID_IUnknown, (void**)&pUnk.p);
00179         p->cleanup.push_back(pUnk);
00180 
00181         pUnk = 0;
00182         p->QueryInterface(__uuidof(ICoreObject), (void**)&pUnk.p);
00183         p->cleanup.push_back(pUnk);
00184         return pUnk;
00185 }
00186 
00187 bool IsQIThunk(IUnknown *p);
00188 
00189 inline CCoreObject *CastToObject(IUnknown *p) {
00190         if (IsQIThunk(p))
00191                 return (CCoreObject*)(ICoreObject*)((ATL::_QIThunk *)(p))->m_pUnk;
00192         else
00193                 return (CCoreObject*)(ICoreObject*)p;
00194 }
00195 #endif
00196 
00197 #endif//MGA_COREOBJECT_H