GME  13
Meta.cpp
Go to the documentation of this file.
00001 // Meta.cpp : Implementation of DLL Exports.
00002 
00003 
00004 // Note: Proxy/Stub Information
00005 //      To build a separate proxy/stub DLL, 
00006 //      run nmake -f Metaps.mk in the project directory.
00007 
00008 #include "stdafx.h"
00009 #include "resource.h"
00010 #include <initguid.h>
00011 
00012 #include "Meta_i.c"
00013 #include "MetaLib_i.c"
00014 #include "Core_i.c"
00015 #include "Gme_i.c"
00016 
00017 #include "CommonError.h"
00018 #include "CommonSmart.h"
00019 
00020 #include "MgaMetaProject.h"
00021 #include "MgaMetaFolder.h"
00022 #include "MgaMetaModel.h"
00023 #include "MgaMetaAspect.h"
00024 #include "MgaMetaRole.h"
00025 #include "MgaMetaAtom.h"
00026 #include "MgaMetaReference.h"
00027 #include "MgaMetaSet.h"
00028 #include "MgaMetaConnection.h"
00029 #include "MgaMetaConnJoint.h"
00030 #include "MgaMetaAttribute.h"
00031 #include "MgaMetaPointerSpec.h"
00032 #include "MgaMetaPointerItem.h"
00033 #include "MgaMetaPart.h"
00034 #include "MgaMetaRegNode.h"
00035 #include "MgaMetaEnumItem.h"
00036 #include "MgaMetaConstraint.h"
00037 
00038 CComModule _Module;
00039 
00040 BEGIN_OBJECT_MAP(ObjectMap)
00041 OBJECT_ENTRY(__uuidof(MgaMetaProject), CMgaMetaProject)
00042 OBJECT_ENTRY(__uuidof(MgaMetaFolder), CMgaMetaFolder)
00043 OBJECT_ENTRY(__uuidof(MgaMetaModel), CMgaMetaModel)
00044 OBJECT_ENTRY(__uuidof(MgaMetaAspect), CMgaMetaAspect)
00045 OBJECT_ENTRY(__uuidof(MgaMetaRole), CMgaMetaRole)
00046 OBJECT_ENTRY(__uuidof(MgaMetaAtom), CMgaMetaAtom)
00047 OBJECT_ENTRY(__uuidof(MgaMetaReference), CMgaMetaReference)
00048 OBJECT_ENTRY(__uuidof(MgaMetaSet), CMgaMetaSet)
00049 OBJECT_ENTRY(__uuidof(MgaMetaConnection), CMgaMetaConnection)
00050 OBJECT_ENTRY(__uuidof(MgaMetaConnJoint), CMgaMetaConnJoint)
00051 OBJECT_ENTRY(__uuidof(MgaMetaAttribute), CMgaMetaAttribute)
00052 OBJECT_ENTRY(__uuidof(MgaMetaPointerSpec), CMgaMetaPointerSpec)
00053 OBJECT_ENTRY(__uuidof(MgaMetaPointerItem), CMgaMetaPointerItem)
00054 OBJECT_ENTRY(__uuidof(MgaMetaPart), CMgaMetaPart)
00055 OBJECT_ENTRY(__uuidof(MgaMetaRegNode), CMgaMetaRegNode)
00056 OBJECT_ENTRY(__uuidof(MgaMetaEnumItem), CMgaMetaEnumItem)
00057 OBJECT_ENTRY(__uuidof(MgaMetaConstraint), CMgaMetaConstraint)
00058 
00059 OBJECT_ENTRY(__uuidof(MgaMetaFCOs), FCOsExCOMType)
00060 OBJECT_ENTRY(__uuidof(MgaMetaRoles), RolesExCOMType)
00061 END_OBJECT_MAP()
00062 
00064 // DLL Entry Point
00065 
00066 extern "C"
00067 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
00068 {
00069     if (dwReason == DLL_PROCESS_ATTACH)
00070     {
00071         _Module.Init(ObjectMap, hInstance, &__uuidof(__MGAMetaLib));
00072         DisableThreadLibraryCalls(hInstance);
00073     }
00074     else if (dwReason == DLL_PROCESS_DETACH)
00075         _Module.Term();
00076     return TRUE;    // ok
00077 }
00078 
00080 // Used to determine whether the DLL can be unloaded by OLE
00081 
00082 STDAPI DllCanUnloadNow(void)
00083 {
00084     return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
00085 }
00086 
00088 // Returns a class factory to create an object of the requested type
00089 
00090 STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
00091 {
00092     return _Module.GetClassObject(rclsid, riid, ppv);
00093 }
00094 
00096 // DllRegisterServer - Adds entries to the system registry
00097 
00098 STDAPI DllRegisterServer(void)
00099 {
00100     // registers object, typelib and all interfaces in typelib
00101     return _Module.RegisterServer(TRUE);
00102 }
00103 
00105 // DllUnregisterServer - Removes entries from the system registry
00106 
00107 STDAPI DllUnregisterServer(void)
00108 {
00109     return _Module.UnregisterServer(TRUE);
00110 }
00111 
00112 // --------------------------- Traverse
00113 
00114 void TraverseObject(CMgaMetaProject *metaproject, CCoreObjectPtr &me)
00115 {
00116         ASSERT( metaproject != NULL );
00117         ASSERT( me != NULL );
00118 
00119         me.Load();
00120 
00121         CComObjPtr<IMgaMetaBase> base;
00122         if( SUCCEEDED(QueryInterface(me, base)) )
00123         {
00124                 ASSERT( base != NULL );
00125 
00126                 objtype_enum objtype;
00127                 COMTHROW( base->get_ObjType(&objtype) );
00128 
00129                 switch(objtype)
00130                 {
00131                 case OBJTYPE_MODEL:
00132                         CMgaMetaModel::Traverse(metaproject, me);
00133                         break;
00134 
00135                 case OBJTYPE_ATOM:
00136                         CMgaMetaAtom::Traverse(metaproject, me);
00137                         break;
00138 
00139                 case OBJTYPE_REFERENCE:
00140                         CMgaMetaReference::Traverse(metaproject, me);
00141                         break;
00142 
00143                 case OBJTYPE_CONNECTION:
00144                         CMgaMetaConnection::Traverse(metaproject, me);
00145                         break;
00146 
00147                 case OBJTYPE_SET:
00148                         CMgaMetaSet::Traverse(metaproject, me);
00149                         break;
00150 
00151                 case OBJTYPE_FOLDER:
00152                         CMgaMetaFolder::Traverse(metaproject, me);
00153                         break;
00154 
00155                 case OBJTYPE_ASPECT:
00156                         CMgaMetaAspect::Traverse(metaproject, me);
00157                         break;
00158 
00159                 case OBJTYPE_ROLE:
00160                         CMgaMetaRole::Traverse(metaproject, me);
00161                         break;
00162 
00163                 case OBJTYPE_ATTRIBUTE:
00164                         CMgaMetaAttribute::Traverse(metaproject, me);
00165                         break;
00166 
00167                 case OBJTYPE_PART:
00168                         CMgaMetaPart::Traverse(metaproject, me);
00169                         break;
00170 
00171                 }
00172         }
00173         else
00174         {
00175                 CComObjPtr<IMgaMetaConnJoint> connjoint;
00176                 CComObjPtr<IMgaMetaPointerSpec> ptrspec;
00177                 CComObjPtr<IMgaMetaRegNode> regnode;
00178 
00179                 if( SUCCEEDED(QueryInterface(me, connjoint)) )
00180                         CMgaMetaConnJoint::Traverse(metaproject, me);
00181                 else if( SUCCEEDED(QueryInterface(me, ptrspec)) )
00182                         CMgaMetaPointerSpec::Traverse(metaproject, me);
00183                 else if( SUCCEEDED(QueryInterface(me, regnode)) )
00184                         CMgaMetaRegNode::Traverse(metaproject, me);
00185 
00186                 metaproject->core_object_cleanup.push_back(CComPtr<ICoreObject>(me.p));
00187         }
00188 }
00189 
00190 void TraverseCollection(CMgaMetaProject *metaproject, CCoreObjectPtr &me, attrid_type attrid)
00191 {
00192         ASSERT( metaproject != NULL );
00193         ASSERT( me != NULL );
00194 
00195         coreobjects_type coreobjects;
00196         me.LoadCollectionValue(attrid, coreobjects);
00197         coreobjects_iterator i = coreobjects.begin();
00198         coreobjects_iterator e = coreobjects.end();
00199         while( i != e )
00200         {
00201                 TraverseObject(metaproject, *i);
00202 
00203                 ++i;
00204         }
00205 }
00206 
00207 
00208 HRESULT check_location_compatibility(IMgaMetaBase *newobj, IMgaMetaBase *oldobj) {
00209         CComPtr<IMgaMetaProject> p, p2;
00210         HRESULT hr;
00211         if((hr = newobj->get_MetaProject(&p)) != S_OK) return hr;
00212         if(!oldobj) {
00213                 //if(p->Open != CMgaMetaProject::Open) return E_SAMEPROJECT;
00214                 if(&IMgaMetaProject::Open != &CMgaMetaProject::Open) return E_SAMEPROJECT;
00215         }
00216         else {
00217                 if((hr = oldobj->get_MetaProject(&p2)) != S_OK) return hr;
00218                 if(p != p2) return E_SAMEPROJECT;
00219         }
00220         return S_OK;
00221 }
00222