Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

macPlugins.cpp

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of CrazyEddiesGUI
00004     (but borrowed from OGRE, see http://www.ogre3d.org/)
00005 
00006 Copyright � 2000-2002 The OGRE Team
00007 Also see acknowledgements in Readme.html
00008 
00009 This program is free software; you can redistribute it and/or modify it under
00010 the terms of the GNU Lesser General  License as published by the Free Software
00011 Foundation; either version 2 of the License, or (at your option) any later
00012 version.
00013 
00014 This program is distributed in the hope that it will be useful, but WITHOUT
00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016 FOR A PARTICULAR PURPOSE. See the GNU Lesser General  License for more details.
00017 
00018 You should have received a copy of the GNU Lesser General  License along with
00019 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
00020 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
00021 http://www.gnu.org/copyleft/lesser.txt.
00022 -----------------------------------------------------------------------------
00023 */
00024 
00025 #include <CoreFoundation/CoreFoundation.h>
00026 
00027 #include "macPlugins.h"
00028 
00029 #include "CEGUILogger.h"
00030 
00031 namespace CEGUI 
00032 {
00033      
00034      CFBundleRef mac_loadExeBundle(const char* name) 
00035      {
00036           Logger::getSingleton().logEvent((utf8*)"---- Beginning exe bundle loading ----");
00037           Logger::getSingleton().logEvent((utf8*)name);
00038           
00039           Logger::getSingleton().logEvent((utf8*)"Get reference to base bundle", Insane);
00040           CFBundleRef baseBundle = CFBundleGetBundleWithIdentifier(CFSTR("net.sourceforge.crayzedsgui.CEGUIBase"));
00041 
00042           Logger::getSingleton().logEvent((utf8*)"Get reference to main bundle", Insane);
00043           CFBundleRef mainBundle = CFBundleGetMainBundle();
00044           
00045           Logger::getSingleton().logEvent((utf8*)"Create name", Insane);
00046           CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
00047           CFURLRef bundleURL = 0; //URL of bundle to load
00048           CFBundleRef bundle = 0; //bundle to load
00049           
00050           // Cut off .bundle if present.
00051           Logger::getSingleton().logEvent((utf8*)"Check if .bundle suffix is on name", Insane);
00052           if(CFStringHasSuffix(nameRef, CFSTR(".bundle"))) 
00053           {
00054                Logger::getSingleton().logEvent((utf8*)"Create temporary name reference", Insane);
00055                CFStringRef nameTempRef = nameRef;
00056                int end = CFStringGetLength(nameTempRef) - CFStringGetLength(CFSTR(".bundle"));
00057                nameRef = CFStringCreateWithSubstring(NULL, nameTempRef, CFRangeMake(0, end));
00058 
00059                Logger::getSingleton().logEvent((utf8*)"Release temporary name reference", Insane);
00060                CFRelease(nameTempRef);
00061           }
00062           
00063           // Assume relative to Resources/ directory of application's bundle.
00064           Logger::getSingleton().logEvent((utf8*)"Create bundle URL", Insane);
00065           bundleURL = CFBundleCopyResourceURL(mainBundle, nameRef, CFSTR("bundle"), NULL);
00066           if(bundleURL)
00067           {
00068                Logger::getSingleton().logEvent((utf8*)"Create bundle from URL", Insane);
00069                bundle = CFBundleCreate(NULL, bundleURL);
00070                
00071                Logger::getSingleton().logEvent((utf8*)"Release bundle URL", Insane);
00072                CFRelease(bundleURL);
00073           }
00074           
00075           // Otherwise, try Resources/ directory of CEGUI Framework bundle.
00076           if(!bundle) 
00077           {
00078                Logger::getSingleton().logEvent((utf8*)"Couldn't get bundle from main bundle reference; try base");
00079                bundleURL = CFBundleCopyResourceURL(baseBundle, nameRef, CFSTR("bundle"), NULL);
00080                if(bundleURL) 
00081                {
00082                     Logger::getSingleton().logEvent((utf8*)"Create bundle from URL", Insane);
00083                     bundle = CFBundleCreate(NULL, bundleURL);
00084                     
00085                     Logger::getSingleton().logEvent((utf8*)"Release bundle URL", Insane);
00086                     CFRelease(bundleURL);
00087                }
00088           }
00089           Logger::getSingleton().logEvent((utf8*)"Release name reference", Insane);
00090           CFRelease(nameRef);
00091           
00092           if(bundle) 
00093           {
00094                Logger::getSingleton().logEvent((utf8*)"Load the bundle executable.", Insane);
00095                if(CFBundleLoadExecutable(bundle)) 
00096                {
00097                     Logger::getSingleton().logEvent((utf8*)"Bundle loaded successfully.");
00098                     return bundle;
00099                }
00100                else 
00101                {
00102                     Logger::getSingleton().logEvent((utf8*)"Bundle loading failed!");
00103                     CFRelease(bundle);
00104                }
00105           }
00106           
00107           Logger::getSingleton().logEvent((utf8*)"Failure; return 0", Insane);
00108           return 0;
00109      }
00110      
00111      void* mac_getBundleSym(CFBundleRef bundle, const char* name) 
00112      {
00113           Logger::getSingleton().logEvent((utf8*)"---- Getting bundle symbol ----", Insane);
00114           CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
00115           
00116           Logger::getSingleton().logEvent((utf8*)"Find function pointer for name: ", Insane);
00117           Logger::getSingleton().logEvent((utf8*)name, Insane);
00118           void* sym = CFBundleGetFunctionPointerForName(bundle, nameRef);
00119           
00120           Logger::getSingleton().logEvent((utf8*)"Release bundle name", Insane);
00121           CFRelease(nameRef);
00122           
00123           Logger::getSingleton().logEvent((utf8*)"---- Done getting bundle symbol ----", Insane);
00124           return sym;
00125      }
00126           
00127      // Returns 1 on error, 0 otherwise.
00128      bool mac_unloadExeBundle(CFBundleRef bundle) 
00129      {
00130           Logger::getSingleton().logEvent((utf8*)"---- Beginning exe bundle unloading ----");
00131           
00132           if(bundle) 
00133           {
00134                Logger::getSingleton().logEvent((utf8*)"Bundle unloaded.", Insane);
00135 
00136                // No-op, can't unload Obj-C bundles without crashing.
00137                return 0;
00138           }
00139           
00140           Logger::getSingleton().logEvent((utf8*)"---- Ending exe bundle unloading ----");
00141           return 1;
00142      }
00143      
00144      const char* mac_errorBundle() 
00145      {
00146           return "Unknown Error";
00147      }
00148 
00149 }

Generated on Wed Feb 16 12:41:08 2005 for Crazy Eddies GUI System by  doxygen 1.3.9.1