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

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 int main(void)
00032 {
00033 }
00034 
00035 namespace CEGUI 
00036 {
00037      
00038      CFBundleRef mac_loadExeBundle(const char* name) 
00039      {
00040           Logger::getSingleton().logEvent((utf8*)"---- Beginning exe bundle loading ----");
00041           Logger::getSingleton().logEvent((utf8*)name);
00042           
00043           Logger::getSingleton().logEvent((utf8*)"Get reference to base bundle", Insane);
00044           CFBundleRef baseBundle = CFBundleGetBundleWithIdentifier(CFSTR("net.sourceforge.crayzedsgui.CEGUIBase"));
00045 
00046           Logger::getSingleton().logEvent((utf8*)"Get reference to main bundle", Insane);
00047           CFBundleRef mainBundle = CFBundleGetMainBundle();
00048           
00049           Logger::getSingleton().logEvent((utf8*)"Create name", Insane);
00050           CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
00051           CFURLRef bundleURL = 0; //URL of bundle to load
00052           CFBundleRef bundle = 0; //bundle to load
00053           
00054           // Cut off .bundle if present.
00055           Logger::getSingleton().logEvent((utf8*)"Check if .bundle suffix is on name", Insane);
00056           if(CFStringHasSuffix(nameRef, CFSTR(".bundle"))) 
00057           {
00058                Logger::getSingleton().logEvent((utf8*)"Create temporary name reference", Insane);
00059                CFStringRef nameTempRef = nameRef;
00060                int end = CFStringGetLength(nameTempRef) - CFStringGetLength(CFSTR(".bundle"));
00061                nameRef = CFStringCreateWithSubstring(NULL, nameTempRef, CFRangeMake(0, end));
00062 
00063                Logger::getSingleton().logEvent((utf8*)"Release temporary name reference", Insane);
00064                CFRelease(nameTempRef);
00065           }
00066           
00067           // Assume relative to Resources/ directory of application's bundle.
00068           Logger::getSingleton().logEvent((utf8*)"Create bundle URL", Insane);
00069           bundleURL = CFBundleCopyResourceURL(mainBundle, nameRef, CFSTR("bundle"), NULL);
00070           if(bundleURL)
00071           {
00072                Logger::getSingleton().logEvent((utf8*)"Create bundle from URL", Insane);
00073                bundle = CFBundleCreate(NULL, bundleURL);
00074                
00075                Logger::getSingleton().logEvent((utf8*)"Release bundle URL", Insane);
00076                CFRelease(bundleURL);
00077           }
00078           
00079           // Otherwise, try Resources/ directory of CEGUI Framework bundle.
00080           if(!bundle) 
00081           {
00082                Logger::getSingleton().logEvent((utf8*)"Couldn't get bundle from main bundle reference; try base");
00083                bundleURL = CFBundleCopyResourceURL(baseBundle, nameRef, CFSTR("bundle"), NULL);
00084                if(bundleURL) 
00085                {
00086                     Logger::getSingleton().logEvent((utf8*)"Create bundle from URL", Insane);
00087                     bundle = CFBundleCreate(NULL, bundleURL);
00088                     
00089                     Logger::getSingleton().logEvent((utf8*)"Release bundle URL", Insane);
00090                     CFRelease(bundleURL);
00091                }
00092           }
00093           Logger::getSingleton().logEvent((utf8*)"Release name reference", Insane);
00094           CFRelease(nameRef);
00095           
00096           if(bundle) 
00097           {
00098                Logger::getSingleton().logEvent((utf8*)"Load the bundle executable.", Insane);
00099                if(CFBundleLoadExecutable(bundle)) 
00100                {
00101                     Logger::getSingleton().logEvent((utf8*)"Bundle loaded successfully.");
00102                     return bundle;
00103                }
00104                else 
00105                {
00106                     Logger::getSingleton().logEvent((utf8*)"Bundle loading failed!");
00107                     CFRelease(bundle);
00108                }
00109           }
00110           
00111           Logger::getSingleton().logEvent((utf8*)"Failure; return 0", Insane);
00112           return 0;
00113      }
00114      
00115      void* mac_getBundleSym(CFBundleRef bundle, const char* name) 
00116      {
00117           Logger::getSingleton().logEvent((utf8*)"---- Getting bundle symbol ----", Insane);
00118           CFStringRef nameRef = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
00119           
00120           Logger::getSingleton().logEvent((utf8*)"Find function pointer for name: ", Insane);
00121           Logger::getSingleton().logEvent((utf8*)name, Insane);
00122           void* sym = CFBundleGetFunctionPointerForName(bundle, nameRef);
00123           
00124           Logger::getSingleton().logEvent((utf8*)"Release bundle name", Insane);
00125           CFRelease(nameRef);
00126           
00127           Logger::getSingleton().logEvent((utf8*)"---- Done getting bundle symbol ----", Insane);
00128           return sym;
00129      }
00130           
00131      // Returns 1 on error, 0 otherwise.
00132      bool mac_unloadExeBundle(CFBundleRef bundle) 
00133      {
00134           Logger::getSingleton().logEvent((utf8*)"---- Beginning exe bundle unloading ----");
00135           
00136           if(bundle) 
00137           {
00138                Logger::getSingleton().logEvent((utf8*)"Bundle unloaded.", Insane);
00139 
00140                // No-op, can't unload Obj-C bundles without crashing.
00141                return 0;
00142           }
00143           
00144           Logger::getSingleton().logEvent((utf8*)"---- Ending exe bundle unloading ----");
00145           return 1;
00146      }
00147      
00148      const char* mac_errorBundle() 
00149      {
00150           return "Unknown Error";
00151      }
00152 
00153 }

Generated on Wed Sep 7 09:56:35 2005 for Crazy Eddies GUI System by  doxygen 1.4.3