コード例 #1
0
Notificator::Notificator(const QString &programName, QSystemTrayIcon *trayicon, QWidget *parent):
    QObject(parent),
    parent(parent),
    programName(programName),
    mode(None),
    trayIcon(trayicon)
#ifdef USE_DBUS
    ,interface(0)
#endif
{
    if(trayicon && trayicon->supportsMessages())
    {
        mode = QSystemTray;
    }
#ifdef USE_DBUS
    interface = new QDBusInterface("org.freedesktop.Notifications",
          "/org/freedesktop/Notifications", "org.freedesktop.Notifications");
    if(interface->isValid())
    {
        mode = Freedesktop;
    }
#endif
#ifdef Q_OS_MAC
    // check if users OS has support for NSUserNotification
    if( MacNotificationHandler::instance()->hasUserNotificationCenterSupport()) {
        mode = UserNotificationCenter;
    }
    else {
        // Check if Growl is installed (based on Qt's tray icon implementation)
        CFURLRef cfurl;
        OSStatus status = LSGetApplicationForInfo(kLSUnknownType, kLSUnknownCreator, CFSTR("growlTicket"), kLSRolesAll, 0, &cfurl);
        if (status != kLSApplicationNotFoundErr) {
            CFBundleRef bundle = CFBundleCreate(0, cfurl);
            if (CFStringCompare(CFBundleGetIdentifier(bundle), CFSTR("com.Growl.GrowlHelperApp"), kCFCompareCaseInsensitive | kCFCompareBackwards) == kCFCompareEqualTo) {
                if (CFStringHasSuffix(CFURLGetString(cfurl), CFSTR("/Growl.app/")))
                    mode = Growl13;
                else
                    mode = Growl12;
            }
            CFRelease(cfurl);
            CFRelease(bundle);
    }
    }
#endif
}
コード例 #2
0
void	InitDeckLinkAPI_v7_6 (void)
{
	CFURLRef		bundleURL;

	bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true);
	if (bundleURL != NULL)
	{
		gBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
		if (gBundleRef != NULL)
		{
			gCreateIteratorFunc = (CreateIteratorFunc_v7_6)CFBundleGetFunctionPointerForName(gBundleRef, CFSTR("CreateDeckLinkIteratorInstance"));
			gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc_v7_6)CFBundleGetFunctionPointerForName(gBundleRef, CFSTR("CreateOpenGLScreenPreviewHelper"));
			gCreateCocoaPreviewFunc = (CreateCocoaScreenPreviewFunc_v7_6)CFBundleGetFunctionPointerForName(gBundleRef, CFSTR("CreateCocoaScreenPreview"));
			gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc_v7_6)CFBundleGetFunctionPointerForName(gBundleRef, CFSTR("CreateVideoConversionInstance"));
		}
		CFRelease(bundleURL);
	}
}
コード例 #3
0
ファイル: Dialogue.c プロジェクト: carriercomm/osx-2
static CFBundleRef
get_bundle(void)
{
    static CFBundleRef		bundle = NULL;
    CFURLRef			url;

    if (bundle != NULL) {
	return (bundle);
    }
    url = CFURLCreateWithFileSystemPath(NULL,
					CFSTR(kEAPOLControllerPath),
					kCFURLPOSIXPathStyle, FALSE);
    if (url != NULL) {
	bundle = CFBundleCreate(NULL, url);
	CFRelease(url);
    }
    return (bundle);
}
コード例 #4
0
ファイル: cgl_ctx.c プロジェクト: Sotsukun/RetroArch
static gfx_ctx_proc_t gfx_ctx_cgl_get_proc_address(const char *symbol_name)
{
   CFURLRef bundle_url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
         CFSTR
         ("/System/Library/Frameworks/OpenGL.framework"),
         kCFURLPOSIXPathStyle, true);
   CFBundleRef opengl_bundle_ref  = CFBundleCreate(kCFAllocatorDefault, bundle_url);
   CFStringRef function =  CFStringCreateWithCString(kCFAllocatorDefault, symbol_name,
         kCFStringEncodingASCII);
   gfx_ctx_proc_t ret = (gfx_ctx_proc_t)CFBundleGetFunctionPointerForName(
         opengl_bundle_ref, function);

   CFRelease(bundle_url);
   CFRelease(function);
   CFRelease(opengl_bundle_ref);

   return ret;
}
コード例 #5
0
int Vst::loadPlugin(std::string pathOnDisk)
{
    int error = 0;
    
    plugin = nullptr;
    
    CFStringRef pluginPathReference = CFStringCreateWithCString(nullptr, pathOnDisk.c_str(), kCFStringEncodingASCII);
    CFURLRef bundleUrl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pluginPathReference, kCFURLPOSIXPathStyle, true);
    
    if(bundleUrl == nullptr)
    {
        std::cout<<"Could't find reference to VST URL. It might not exist, or the path is wrong."<<std::endl;
        return -1;
    }
    
    CFBundleRef bundle = CFBundleCreate(kCFAllocatorDefault, bundleUrl);
    if(bundle == nullptr)
    {
        std::cout<<"Couldn't create VST Bundle reference. It might not be a VST, or corrupted"<<std::endl;
        CFRelease(bundleUrl);
        CFRelease(bundle);
        return -1;
    }
    
    VSTPlugin = (vstPluginFuncPtr)CFBundleGetFunctionPointerForName(bundle, CFSTR("VSTPluginMain"));
    
    plugin = VSTPlugin(hostCallback);
    
    if(plugin == nullptr)
    {
        std::cout<<"Couldn't create VST Main Entry Point"<<std::endl;
        CFBundleUnloadExecutable(bundle);
        CFRelease(bundle);
        return -1;
    }
    
    CFRelease(pluginPathReference);
    CFRelease(bundleUrl);
    
    error = configureCallbacks();
    error = startPlugin();
    
    return error;
}
コード例 #6
0
bool InjectedBundle::load(APIObject* initializationUserData)
{
    if (m_sandboxExtension) {
        if (!m_sandboxExtension->consume()) {
            fprintf(stderr, "InjectedBundle::load failed - Could not consume bundle sandbox extension for [%s].\n", m_path.utf8().data());
            return false;
        }

        m_sandboxExtension = 0;
    }
    
    RetainPtr<CFStringRef> injectedBundlePathStr(AdoptCF, CFStringCreateWithCharacters(0, reinterpret_cast<const UniChar*>(m_path.characters()), m_path.length()));
    if (!injectedBundlePathStr) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the path string.\n");
        return false;
    }
    
    RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(0, injectedBundlePathStr.get(), kCFURLPOSIXPathStyle, false));
    if (!bundleURL) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the url from the path string.\n");
        return false;
    }

    m_platformBundle = CFBundleCreate(0, bundleURL.get());
    if (!m_platformBundle) {
        fprintf(stderr, "InjectedBundle::load failed - Could not create the bundle.\n");
        return false;
    }
        
    if (!CFBundleLoadExecutable(m_platformBundle)) {
        fprintf(stderr, "InjectedBundle::load failed - Could not load the executable from the bundle.\n");
        return false;
    }

    WKBundleInitializeFunctionPtr initializeFunction = reinterpret_cast<WKBundleInitializeFunctionPtr>(CFBundleGetFunctionPointerForName(m_platformBundle, CFSTR("WKBundleInitialize")));
    if (!initializeFunction) {
        fprintf(stderr, "InjectedBundle::load failed - Could not find the initialize function in the bundle executable.\n");
        return false;
    }

    initializeFunction(toAPI(this), toAPI(initializationUserData));
    return true;
}
コード例 #7
0
/*
 * / Load a module (if needed)
 */
int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary)
{

	CFStringRef bundlePath;
	CFURLRef bundleURL;
	CFBundleRef bundle;

	*pvLHandle = 0;

	/*
	 * @@@ kCFStringEncodingMacRoman might be wrong on non US systems.
	 */

	bundlePath = CFStringCreateWithCString(NULL, pcLibrary,
		kCFStringEncodingMacRoman);
	if (bundlePath == NULL)
		return SCARD_E_NO_MEMORY;

	bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath,
		kCFURLPOSIXPathStyle, TRUE);
	CFRelease(bundlePath);
	if (bundleURL == NULL)
		return SCARD_E_NO_MEMORY;

	bundle = CFBundleCreate(NULL, bundleURL);
	CFRelease(bundleURL);
	if (bundle == NULL)
	{
		Log1(PCSC_LOG_ERROR, "CFBundleCreate");
		return SCARD_F_UNKNOWN_ERROR;
	}

	if (!CFBundleLoadExecutable(bundle))
	{
		Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable");
		CFRelease(bundle);
		return SCARD_F_UNKNOWN_ERROR;
	}

	*pvLHandle = (void *) bundle;

	return SCARD_S_SUCCESS;
}
コード例 #8
0
ファイル: FCError.cpp プロジェクト: TheNotary/FayeCpp
 void init()
 {
     CFBundleRef mainBundle = CFBundleGetMainBundle();
     if (mainBundle)
     {
         CFStringRef resourceName = CFStringCreateWithCString(NULL, kFayeCppBundleName ,kCFStringEncodingUTF8);
         if (resourceName)
         {
             CFURLRef url = CFBundleCopyResourceURL(mainBundle, resourceName, CFSTR("bundle"), NULL);
             CFRelease(resourceName);
             if (url)
             {
                 _localizedBundle = CFBundleCreate(NULL, url);
                 CFRelease(url);
             }
         }
         _localizedTableName = CFStringCreateWithCString(NULL, kFayeCppBundleLocalizationTableName ,kCFStringEncodingUTF8);
     }
 }
コード例 #9
0
static CFBundleRef createWebKitBundle()
{
    if (CFBundleRef existingBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebKit"))) {
        CFRetain(existingBundle);
        return existingBundle;
    }

    wchar_t dllPathBuffer[MAX_PATH];
    DWORD length = ::GetModuleFileNameW(instanceHandle(), dllPathBuffer, WTF_ARRAY_LENGTH(dllPathBuffer));
    ASSERT(length);
    ASSERT(length < WTF_ARRAY_LENGTH(dllPathBuffer));

    RetainPtr<CFStringRef> dllPath(AdoptCF, CFStringCreateWithCharactersNoCopy(0, reinterpret_cast<const UniChar*>(dllPathBuffer), length, kCFAllocatorNull));
    RetainPtr<CFURLRef> dllURL(AdoptCF, CFURLCreateWithFileSystemPath(0, dllPath.get(), kCFURLWindowsPathStyle, false));
    RetainPtr<CFURLRef> dllDirectoryURL(AdoptCF, CFURLCreateCopyDeletingLastPathComponent(0, dllURL.get()));
    RetainPtr<CFURLRef> resourcesDirectoryURL(AdoptCF, CFURLCreateCopyAppendingPathComponent(0, dllDirectoryURL.get(), CFSTR("WebKit.resources"), true));

    return CFBundleCreate(0, resourcesDirectoryURL.get());
}
コード例 #10
0
ファイル: minihost.cpp プロジェクト: oliviermohsen/eiosisTest
	bool loadLibrary (const char* fileName)
	{
	#if _WIN32
		module = LoadLibrary (fileName);
	#elif TARGET_API_MAC_CARBON
		CFStringRef fileNameString = CFStringCreateWithCString (NULL, fileName, kCFStringEncodingUTF8);
		if (fileNameString == 0)
			return false;
		CFURLRef url = CFURLCreateWithFileSystemPath (NULL, fileNameString, kCFURLPOSIXPathStyle, false);
		CFRelease (fileNameString);
		if (url == 0)
			return false;
		module = CFBundleCreate (NULL, url);
		CFRelease (url);
		if (module && CFBundleLoadExecutable ((CFBundleRef)module) == false)
			return false;
	#endif
		return module != 0;
	}
コード例 #11
0
static CFBundleRef
_glitz_agl_get_bundle (const char *name)
{
    CFBundleRef bundle = 0;
    FSRefParam ref_param;
    char framework_name[256];

    framework_name[0] = strlen (name);
    strcpy (&framework_name[1], name);

    memset (&ref_param, 0, sizeof (ref_param));

    if (FindFolder (kSystemDomain,
		    kFrameworksFolderType,
		    kDontCreateFolder,
		    &ref_param.ioVRefNum,
		    &ref_param.ioDirID) == noErr) {
	FSRef ref;

	memset (&ref, 0, sizeof (ref));

	ref_param.ioNamePtr = (unsigned char *) framework_name;
	ref_param.newRef = &ref;

	if (PBMakeFSRefSync (&ref_param) == noErr) {
	    CFURLRef url;

	    url = CFURLCreateFromFSRef (kCFAllocatorDefault, &ref);
	    if (url) {
		bundle = CFBundleCreate (kCFAllocatorDefault, url);
		CFRelease (url);

		if (!CFBundleLoadExecutable (bundle)) {
		    CFRelease (bundle);
		    return (CFBundleRef) 0;
		}
	    }
	}
    }

    return bundle;
}
コード例 #12
0
ファイル: CFError.c プロジェクト: cooljeanius/opencflite-code
/* Built-in callback for POSIX domain. Note that we will pick up localizations from ErrnoErrors.strings in /System/Library/CoreServices/CoreTypes.bundle, if the file happens to be there.
*/
static CFTypeRef _CFErrorPOSIXCallBack(CFErrorRef err, CFStringRef key) {
    if (!CFEqual(key, kCFErrorDescriptionKey) && !CFEqual(key, kCFErrorLocalizedFailureReasonKey)) return NULL;
    
    const char *errCStr = strerror(CFErrorGetCode(err));
    CFStringRef errStr = (errCStr && strlen(errCStr)) ? CFStringCreateWithCString(kCFAllocatorSystemDefault, errCStr, kCFStringEncodingUTF8) : NULL;
    
    if (!errStr) return NULL;
    if (CFEqual(key, kCFErrorDescriptionKey)) return errStr;	// If all we wanted was the non-localized description, we're done
    
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_WINDOWS
    // We need a kCFErrorLocalizedFailureReasonKey, so look up a possible localization for the error message
    // Look for the bundle in /System/Library/CoreServices/CoreTypes.bundle
    CFArrayRef paths = CFCopySearchPathForDirectoriesInDomains(kCFLibraryDirectory, kCFSystemDomainMask, false);
    if (paths) {
	if (CFArrayGetCount(paths) > 0) {
	    CFStringRef path = CFStringCreateWithFormat(kCFAllocatorSystemDefault, NULL, CFSTR("%@/CoreServices/CoreTypes.bundle"), CFArrayGetValueAtIndex(paths, 0));
	    CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorSystemDefault, path, kCFURLPOSIXPathStyle, false /* not a directory */);
	    if (url) {
		CFBundleRef bundle = CFBundleCreate(kCFAllocatorSystemDefault, url);
		if (bundle) {
		    // We only want to return a result if there was a localization
		    CFStringRef localizedErrStr = CFBundleCopyLocalizedString(bundle, errStr, errStr, CFSTR("ErrnoErrors"));
		    if (localizedErrStr == errStr) {
			CFRelease(localizedErrStr);
			CFRelease(errStr);
			errStr = NULL;
		    } else {
			CFRelease(errStr);
			errStr = localizedErrStr;
		    }
		    CFRelease(bundle);
		}
		CFRelease(url);
	    }
	    CFRelease(path);
	}
	CFRelease(paths);
    }
#endif
    
    return errStr;
}
コード例 #13
0
Image JUCE_API getIconFromApplication (const String& applicationPath, const int size)
{
    Image hostIcon;

    if (CFStringRef pathCFString = CFStringCreateWithCString (kCFAllocatorDefault, applicationPath.toRawUTF8(), kCFStringEncodingUTF8))
    {
        if (CFURLRef url = CFURLCreateWithFileSystemPath (kCFAllocatorDefault, pathCFString, kCFURLPOSIXPathStyle, 1))
        {
            if (CFBundleRef appBundle = CFBundleCreate (kCFAllocatorDefault, url))
            {
                if (CFTypeRef infoValue = CFBundleGetValueForInfoDictionaryKey (appBundle, CFSTR("CFBundleIconFile")))
                {
                    if (CFGetTypeID (infoValue) == CFStringGetTypeID())
                    {
                        CFStringRef iconFilename = reinterpret_cast<CFStringRef> (infoValue);
                        CFStringRef resourceURLSuffix = CFStringHasSuffix (iconFilename, CFSTR(".icns")) ? nullptr : CFSTR("icns");
                        if (CFURLRef iconURL = CFBundleCopyResourceURL (appBundle, iconFilename, resourceURLSuffix, nullptr))
                        {
                            if (CFStringRef iconPath = CFURLCopyFileSystemPath (iconURL, kCFURLPOSIXPathStyle))
                            {
                                File icnsFile (CFStringGetCStringPtr (iconPath, CFStringGetSystemEncoding()));
                                hostIcon = getIconFromIcnsFile (icnsFile, size);
                                CFRelease (iconPath);
                            }

                            CFRelease (iconURL);
                        }
                    }
                }

                CFRelease (appBundle);
            }

            CFRelease (url);
        }

        CFRelease (pathCFString);
    }

    return hostIcon;
}
コード例 #14
0
void	InitDeckLinkAPI (void)
{
	CFURLRef		bundleURL;

	bundleURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, CFSTR(kDeckLinkAPI_BundlePath), kCFURLPOSIXPathStyle, true);
	if (bundleURL != NULL)
	{
		gDeckLinkAPIBundleRef = CFBundleCreate(kCFAllocatorDefault, bundleURL);
		if (gDeckLinkAPIBundleRef != NULL)
		{
			gCreateIteratorFunc = (CreateIteratorFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkIteratorInstance_0003"));
			gCreateAPIInformationFunc = (CreateAPIInformationFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkAPIInformationInstance_0001"));
			gCreateOpenGLPreviewFunc = (CreateOpenGLScreenPreviewHelperFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateOpenGLScreenPreviewHelper_0001"));
			gCreateCocoaPreviewFunc = (CreateCocoaScreenPreviewFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateCocoaScreenPreview_0001"));
			gCreateVideoConversionFunc = (CreateVideoConversionInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateVideoConversionInstance_0001"));
            gCreateDeckLinkDiscoveryFunc = (CreateDeckLinkDiscoveryInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateDeckLinkDiscoveryInstance_0002"));
            gCreateVideoFrameAncillaryPacketsFunc = (CreateVideoFrameAncillaryPacketsInstanceFunc)CFBundleGetFunctionPointerForName(gDeckLinkAPIBundleRef, CFSTR("CreateVideoFrameAncillaryPacketsInstance_0001"));
		}
		CFRelease(bundleURL);
	}
}
コード例 #15
0
ファイル: fileio.cpp プロジェクト: KDE/kdepim
static void InitializeIO()
{
    if (sfwRefCount++) {
        return;
    }
    // race condition, infinitesimal risk

    FSRef theRef;
    if (FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, false, &theRef)
            == noErr) {
        CFURLRef fw = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &theRef);
        if (fw) {
            CFURLRef bd = CFURLCreateCopyAppendingPathComponent
                          (kCFAllocatorSystemDefault, fw, CFSTR("System.framework"), false);
            CFRelease(fw);
            if (bd) {
                systemFramework = CFBundleCreate(kCFAllocatorSystemDefault, bd);
                CFRelease(bd);
            }
        }
        if (!systemFramework || !CFBundleLoadExecutable(systemFramework)) {
            return;
        }
#define F(x) CFBundleGetFunctionPointerForName(systemFramework, CFSTR(#x))
        my_fopen = (FILE * (*)(const char *, const char *))F(fopen);
        my_fclose = (int(*)(FILE *))F(fclose);
        my_ftell = (long(*)(FILE *))F(ftell);
        my_fseek = (int(*)(FILE *, long, int))F(fseek);
        my_fread = (t4_u32(*)(void *ptr, t4_u32, t4_u32, FILE *))F(fread);
        my_fwrite = (t4_u32(*)(const void *ptr, t4_u32, t4_u32, FILE *))F(fwrite);
        my_ferror = (int(*)(FILE *))F(ferror);
        my_fflush = (int(*)(FILE *))F(fflush);
        my_fileno = (int(*)(FILE *))F(fileno);
        my_mmap = (char *(*)(char *, t4_u32, int, int, int, long long))F(mmap);
        my_munmap = (int(*)(char *, t4_u32))F(munmap);
#undef F
        d4_assert(my_fopen && my_fclose && my_ftell && my_fseek && my_fread &&
                  my_fwrite && my_ferror && my_fflush && my_fileno && my_mmap && my_munmap);
    }
}
コード例 #16
0
//------------------------------------------------------------------------
void CreateVSTGUIBundleRef ()
{
	openCount++;
	if (gBundleRef)
	{
		CFRetain (gBundleRef);
		return;
	}
#if TARGET_OS_IPHONE
	gBundleRef = CFBundleGetMainBundle ();
	CFRetain (gBundleRef);
#else
	Dl_info info;
	if (dladdr ((const void*)CreateVSTGUIBundleRef, &info))
	{
		if (info.dli_fname)
		{
			Steinberg::String name;
			name.assign (info.dli_fname);
			for (int i = 0; i < 3; i++)
			{
				int delPos = name.findLast ('/');
				if (delPos == -1)
				{
					fprintf (stdout, "Could not determine bundle location.\n");
					return; // unexpected
				}
				name.remove (delPos, name.length () - delPos);
			}
			CFURLRef bundleUrl = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*)name.text8 (), name.length (), true);
			if (bundleUrl)
			{
				gBundleRef = CFBundleCreate (0, bundleUrl);
				CFRelease (bundleUrl);
			}
		}
	}
#endif
}
コード例 #17
0
ファイル: utOpenGL.cpp プロジェクト: CalebVDW/smr-motion
void *platGetProcAddress( const char *funcName )
{
#if defined( PLATFORM_WIN )
	return (void *)wglGetProcAddress( funcName );
#elif defined( PLATFORM_WIN_CE )
	return (void *)eglGetProcAddress( funcName );
#elif defined( PLATFORM_MAC )
	CFStringRef functionName = CFStringCreateWithCString( kCFAllocatorDefault, funcName, kCFStringEncodingASCII );
	CFURLRef bundleURL = CFURLCreateWithFileSystemPath(
		kCFAllocatorDefault, CFSTR( "/System/Library/Frameworks/OpenGL.framework" ), kCFURLPOSIXPathStyle, true );
	CFBundleRef bundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
   
	void *function = CFBundleGetFunctionPointerForName( bundle, functionName );
   
	CFRelease( bundle );
	CFRelease( bundleURL );
	CFRelease( functionName );
   
	return function; 
#else
	return (void *)glXGetProcAddressARB( (const GLubyte *)funcName );
#endif
}
コード例 #18
0
LibraryHandle getLibraryHandleForPlugin(const CharString pluginAbsolutePath) {
  // Create a path to the bundle
  CFStringRef pluginPathStringRef = CFStringCreateWithCString(NULL, pluginAbsolutePath->data, kCFStringEncodingASCII);
  CFURLRef bundleUrl = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pluginPathStringRef, kCFURLPOSIXPathStyle, true);
  if(bundleUrl == NULL) {
    logError("Couldn't make URL reference for plugin");
    return NULL;
  }

  // Open the bundle
  CFBundleRef bundleRef = CFBundleCreate(kCFAllocatorDefault, bundleUrl);
  if(bundleRef == NULL) {
    logError("Couldn't create bundle reference");
    CFRelease(pluginPathStringRef);
    CFRelease(bundleUrl);
    return NULL;
  }

  // Clean up
  CFRelease(pluginPathStringRef);
  CFRelease(bundleUrl);

  return bundleRef;
}
コード例 #19
0
	static OSErr __msl_CreateFrameworkBundleFromName(CFStringRef theFrameworkName,
		CFBundleRef *theBundle)
	{
		OSErr theErr;
		FSRef theRef;
		CFURLRef theFrameworkURL;
		CFURLRef theBundleURL;
		
		/* Find the folder containing all the frameworks */
		theErr = FSFindFolder(kOnAppropriateDisk, kFrameworksFolderType, false, &theRef);
		
		if (theErr == noErr)
		{
			/* Turn the framework folder FSRef into a CFURL */
			theFrameworkURL = CFURLCreateFromFSRef(kCFAllocatorSystemDefault, &theRef);
			
			if (theFrameworkURL != NULL)
			{
				/* Create a CFURL pointing to the desired framework */
				theBundleURL = CFURLCreateCopyAppendingPathComponent(kCFAllocatorSystemDefault,
					theFrameworkURL, theFrameworkName, false);
				
				CFRelease(theFrameworkURL);
				
				if (theBundleURL != NULL)
				{
					/* Turn the CFURL into a bundle reference */
					*theBundle = CFBundleCreate(kCFAllocatorSystemDefault, theBundleURL);
					
					CFRelease(theBundleURL);
				}
			}
		}
		
		return theErr;
	}
コード例 #20
0
ファイル: VSTHost.cpp プロジェクト: Kassen/chugins
 int load(std::string name)
 {
     int rval = -1;
     vstPluginMain pluginMain = NULL;
     CFStringRef path = NULL;
     CFURLRef urlRef = NULL;
     CFURLRef exeRef = NULL;
     Boolean success;
     
     // Start clean
     m_bundle = NULL;
     
     // Don't really know what this should be initialize to
     m_resource = -1;
     
     // Convert the path to a CFSTring
     path = CFStringCreateWithCString(NULL, name.c_str(), kCFStringEncodingUTF8); 
     
     // Convert the path to a URL
     urlRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
                                            path,
                                            kCFURLPOSIXPathStyle,
                                            true);
     
     if (urlRef == NULL) goto error;        
     // Create the bundle using the URL
     m_bundle = CFBundleCreate(kCFAllocatorDefault, urlRef);
             
     // Bail if the bundle wasn't created
     if (m_bundle == NULL) goto error;
     
     // Retrieve a reference to the executable
     exeRef = CFBundleCopyExecutableURL(m_bundle);
     if (exeRef == NULL) goto error;
     
     // Convert back to path
     UInt8 exePath[PATH_MAX];
     if(!CFURLGetFileSystemRepresentation(exeRef, true, exePath, sizeof(exePath)))
         goto error;
     
     // Attempt to open it
     m_module = dlopen((char *) exePath, RTLD_NOW | RTLD_LOCAL);
     if (m_module == NULL) goto error;
     
     // Try to locate the new plugin entry point
     pluginMain = (vstPluginMain) dlsym(m_module, "VSTPluginMain");
     
     // If not found, try finding the old entry point
     if (pluginMain == NULL) {
         pluginMain = (vstPluginMain) dlsym(m_module, "main_macho");
     }
     
     // Must not be a VST plugin
     if (pluginMain == NULL) goto error;
     
     // Open the resource map ... some plugins (like GRM Tools) need this.
     m_resource = CFBundleOpenBundleResourceMap(m_bundle);
     
     // Initialize the plugin
     m_effect = pluginMain(audioMaster);
     
     // Was it successful?
     if(!m_effect) goto error;
     
     m_effect->user = this;
     
     //
     callDispatcher(effOpen, 0, 0, NULL, 0.0);
     
     // Ensure that it looks like a plugin and can deal with ProcessReplacing
     // calls.  Also exclude synths for now.
     if(m_effect->magic == kEffectMagic &&
        !(m_effect->flags & effFlagsIsSynth) &&
        m_effect->flags & effFlagsCanReplacing)
     {
         
         //                mVendor = GetString(effGetVendorString);
         //                mName = GetString(effGetEffectName);
         //                mInputs = mAEffect->numInputs;
         //                mOutputs = mAEffect->numOutputs;
         
         // We could even go so far as to run a small test here.
             
         rval = 0;
         goto cleanup;
     }
     else
     {
         goto error;
     }
     
 error:
     if(m_effect) { callDispatcher(effClose, 0, 0, NULL, 0.0); m_effect = NULL; }
     if(m_resource != -1) { CFBundleCloseBundleResourceMap(m_bundle, m_resource); m_resource = -1; }
     if(m_module) { dlclose(m_module); m_module = NULL; }
     if(m_bundle) { CFRelease(m_bundle); m_bundle = NULL; }
     if(pluginMain) { pluginMain = NULL; }
     
 cleanup:
     if(exeRef) { CFRelease(exeRef); exeRef = NULL; }
     if(urlRef) { CFRelease(urlRef); urlRef = NULL; }
     if(path) { CFRelease(path); path = NULL; }
     
     return rval;
 }
コード例 #21
0
ファイル: pix_freeframe.cpp プロジェクト: ch-nry/Gem
  bool open(std::string name, const t_canvas*canvas) {
    bool loud=false;
    const char*hookname="plugMain";
    if(name.empty())
      return false;

    if(m_plugin)
      close();

    FF_Main_FuncPtr plugmain = NULL;

    char buf[MAXPDSTRING];
    char buf2[MAXPDSTRING];
    char *bufptr=NULL;

    const char *extension=
#ifdef _WIN32
      ".dll";
#elif defined __APPLE__
    "";
#else
    ".so";
#endif

#ifdef __APPLE__
    char buf3[MAXPDSTRING];
#ifdef DL_OPEN
    snprintf(buf3, MAXPDSTRING, "%s.frf/Contents/MacOS/%s", name.c_str(), name.c_str());
#else
    // this can never work...
    snprintf(buf3, MAXPDSTRING, "%s.frf/%s", name.c_str(), name.c_str());
#endif
    buf3[MAXPDSTRING-1]=0;
    name=buf3;
#endif

    int fd=-1;
    if ((fd=canvas_open(const_cast<t_canvas*>(canvas), name.c_str(), extension, buf2, &bufptr, MAXPDSTRING, 1))>=0){
      ::close(fd);
#if defined __APPLE__ && 0
      snprintf(buf, MAXPDSTRING, "%s", buf2);
#else
      snprintf(buf, MAXPDSTRING, "%s/%s", buf2, bufptr);
#endif
      buf[MAXPDSTRING-1]=0;
    } else {
      if(canvas) {
        canvas_makefilename(const_cast<t_canvas*>(canvas), const_cast<char*>(name.c_str()), buf, MAXPDSTRING);
      } else {
        if(loud)::error("pix_freeframe[%s]: unfindeable", name.c_str());
        return false;
      }
    }
    name=buf;
    std::string libname = name;

    if(loud)::post("trying to load %s", buf);

#ifdef DL_OPEN
    if(loud)::post("dlopen %s", libname.c_str());
    m_dlhandle=dlopen(libname.c_str(), RTLD_NOW);
    if(!m_dlhandle){
      if(loud)::error("pix_freeframe[%s]: %s", libname.c_str(), dlerror());
      return NULL;
    }
    dlerror();

    plugmain = reinterpret_cast<FF_Main_FuncPtr>(dlsym(m_dlhandle, hookname));

#elif defined __APPLE__
    CFURLRef bundleURL = NULL;
    CFBundleRef theBundle = NULL;
    CFStringRef plugin = CFStringCreateWithCString(NULL,
                                                   libname.c_str(), kCFStringEncodingMacRoman);

    bundleURL = CFURLCreateWithFileSystemPath( kCFAllocatorSystemDefault,
                                               plugin,
                                               kCFURLPOSIXPathStyle,
                                               true );
    theBundle = CFBundleCreate( kCFAllocatorSystemDefault, bundleURL );

    // Get a pointer to the function.
    if (theBundle){
      plugmain = reinterpret_cast<FF_Main_FuncPtr>(CFBundleGetFunctionPointerForName(
                                                                                     theBundle, CFSTR("plugMain") )
                                                   );
    }else{
      if(loud)::post("%s: couldn't load", libname.c_str());
      return 0;
    }
    if(bundleURL != NULL) CFRelease( bundleURL );
    if(theBundle != NULL) CFRelease( theBundle );
    if(plugin != NULL)    CFRelease( plugin );
#elif defined _WIN32
    char buffer[MAXPDSTRING];
    sys_bashfilename(libname.c_str(), buffer);
    libname=buffer;
    m_w32handle = LoadLibrary(libname.c_str());
    if (!m_w32handle) {
      if(loud)::post("%s: couldn't load", libname.c_str());
      return false;
    }
    plugmain = reinterpret_cast<FF_Main_FuncPtr>(GetProcAddress(m_w32handle, hookname));
#else
# error no way to load dynamic linked libraries on this OS
#endif

    m_plugin=plugmain;
    return (NULL!=m_plugin);
  }
コード例 #22
0
bool QLibraryPrivate::load_sys()
{
    QString attempt;
#if !defined(QT_NO_DYNAMIC_LIBRARY)
    QFileSystemEntry fsEntry(fileName);

    QString path = fsEntry.path();
    QString name = fsEntry.fileName();
    if (path == QLatin1String(".") && !fileName.startsWith(path))
        path.clear();
    else
        path += QLatin1Char('/');

    QStringList suffixes;
    QStringList prefixes;
    if (pluginState != IsAPlugin) {
        prefixes << QLatin1String("lib");
#if defined(Q_OS_HPUX)
        // according to
        // http://docs.hp.com/en/B2355-90968/linkerdifferencesiapa.htm

        // In PA-RISC (PA-32 and PA-64) shared libraries are suffixed
        // with .sl. In IPF (32-bit and 64-bit), the shared libraries
        // are suffixed with .so. For compatibility, the IPF linker
        // also supports the .sl suffix.

        // But since we don't know if we are built on HPUX or HPUXi,
        // we support both .sl (and .<version>) and .so suffixes but
        // .so is preferred.
# if defined(__ia64)
        if (!fullVersion.isEmpty()) {
            suffixes << QString::fromLatin1(".so.%1").arg(fullVersion);
        } else {
            suffixes << QLatin1String(".so");
        }
# endif
        if (!fullVersion.isEmpty()) {
            suffixes << QString::fromLatin1(".sl.%1").arg(fullVersion);
            suffixes << QString::fromLatin1(".%1").arg(fullVersion);
        } else {
            suffixes << QLatin1String(".sl");
        }
#elif defined(Q_OS_AIX)
        suffixes << ".a";

#else
        if (!fullVersion.isEmpty()) {
            suffixes << QString::fromLatin1(".so.%1").arg(fullVersion);
        } else {
            suffixes << QLatin1String(".so");
        }
#endif
# ifdef Q_OS_MAC
        if (!fullVersion.isEmpty()) {
            suffixes << QString::fromLatin1(".%1.bundle").arg(fullVersion);
            suffixes << QString::fromLatin1(".%1.dylib").arg(fullVersion);
        } else {
            suffixes << QLatin1String(".bundle") << QLatin1String(".dylib");
        }
#endif
    }
    int dlFlags = 0;
#if defined(QT_HPUX_LD)
    dlFlags = DYNAMIC_PATH | BIND_NONFATAL;
    if (loadHints & QLibrary::ResolveAllSymbolsHint) {
        dlFlags |= BIND_IMMEDIATE;
    } else {
        dlFlags |= BIND_DEFERRED;
    }
#else
    if (loadHints & QLibrary::ResolveAllSymbolsHint) {
        dlFlags |= RTLD_NOW;
    } else {
        dlFlags |= RTLD_LAZY;
    }
    if (loadHints & QLibrary::ExportExternalSymbolsHint) {
        dlFlags |= RTLD_GLOBAL;
    }
#if !defined(Q_OS_CYGWIN)
    else {
#if defined(Q_OS_MAC)
        if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_4)
#endif
            dlFlags |= RTLD_LOCAL;
    }
#endif

    // Provide access to RTLD_NODELETE flag on Unix
    // From GNU documentation on RTLD_NODELETE:
    // Do not unload the library during dlclose(). Consequently, the
    // library's specific static variables are not reinitialized if the
    // library is reloaded with dlopen() at a later time.
#ifdef RTLD_NODELETE
    if (loadHints & QLibrary::PreventUnloadHint) {
        dlFlags |= RTLD_NODELETE;
    }
#endif

#if defined(Q_OS_AIX)	// Not sure if any other platform actually support this thing.
    if (loadHints & QLibrary::LoadArchiveMemberHint) {
        dlFlags |= RTLD_MEMBER;
    }
#endif
#endif // QT_HPUX_LD

    // If the filename is an absolute path then we want to try that first as it is most likely
    // what the callee wants. If we have been given a non-absolute path then lets try the
    // native library name first to avoid unnecessary calls to dlopen().
    if (fsEntry.isAbsolute()) {
        suffixes.prepend(QString());
        prefixes.prepend(QString());
    } else {
        suffixes.append(QString());
        prefixes.append(QString());
    }

    bool retry = true;
    for(int prefix = 0; retry && !pHnd && prefix < prefixes.size(); prefix++) {
        for(int suffix = 0; retry && !pHnd && suffix < suffixes.size(); suffix++) {
            if (!prefixes.at(prefix).isEmpty() && name.startsWith(prefixes.at(prefix)))
                continue;
            if (!suffixes.at(suffix).isEmpty() && name.endsWith(suffixes.at(suffix)))
                continue;
            if (loadHints & QLibrary::LoadArchiveMemberHint) {
                attempt = name;
                int lparen = attempt.indexOf(QLatin1Char('('));
                if (lparen == -1)
                    lparen = attempt.count();
                attempt = path + prefixes.at(prefix) + attempt.insert(lparen, suffixes.at(suffix));
            } else {
                attempt = path + prefixes.at(prefix) + name + suffixes.at(suffix);
            }
#if defined(QT_HPUX_LD)
            pHnd = (void*)shl_load(QFile::encodeName(attempt), dlFlags, 0);
#else
            pHnd = dlopen(QFile::encodeName(attempt), dlFlags);
#endif

            if (!pHnd && fileName.startsWith(QLatin1Char('/')) && QFile::exists(attempt)) {
                // We only want to continue if dlopen failed due to that the shared library did not exist.
                // However, we are only able to apply this check for absolute filenames (since they are
                // not influenced by the content of LD_LIBRARY_PATH, /etc/ld.so.cache, DT_RPATH etc...)
                // This is all because dlerror is flawed and cannot tell us the reason why it failed.
                retry = false;
            }
        }
    }

#ifdef Q_OS_MAC
    if (!pHnd) {
        QByteArray utf8Bundle = fileName.toUtf8();
        QCFType<CFURLRef> bundleUrl = CFURLCreateFromFileSystemRepresentation(NULL, reinterpret_cast<const UInt8*>(utf8Bundle.data()), utf8Bundle.length(), true);
        QCFType<CFBundleRef> bundle = CFBundleCreate(NULL, bundleUrl);
        if(bundle) {
            QCFType<CFURLRef> url = CFBundleCopyExecutableURL(bundle);
            char executableFile[FILENAME_MAX];
            CFURLGetFileSystemRepresentation(url, true, reinterpret_cast<UInt8*>(executableFile), FILENAME_MAX);
            attempt = QString::fromUtf8(executableFile);
            pHnd = dlopen(QFile::encodeName(attempt), dlFlags);
        }
    }
#endif
#endif // QT_NO_DYNAMIC_LIBRARY
    if (!pHnd) {
        errorString = QLibrary::tr("Cannot load library %1: %2").arg(fileName).arg(qdlerror());
    }
    if (pHnd) {
        qualifiedFileName = attempt;
        errorString.clear();
    }
    return (pHnd != 0);
}
コード例 #23
0
static CFBundleRef findMe()
{
    CFURLRef    bundleURL;
    CFBundleRef myBundle;
    Boolean didLoad = false;
    // Make a CFURLRef from the CFString representation of the 
    // bundle's path. See the Core Foundation URL Services chapter 
    // for details.
    bundleURL = CFURLCreateWithFileSystemPath( 
                    kCFAllocatorDefault, 
                    CFSTR("/System/Library/Extensions/DVFamily.bundle"),
                    kCFURLPOSIXPathStyle,
                    true );
    
    printf("Bundle URL: %p\n", bundleURL);
    // Make a bundle instance using the URLRef.
    myBundle = CFBundleCreate( kCFAllocatorDefault, bundleURL );
    printf("Bundle: %p\n", myBundle);

    // Try to load the executable from my bundle.
    didLoad = CFBundleLoadExecutable( myBundle );
    printf("loaded? %d\n", didLoad);
    
    sDVFuncs.fDVCountDevices = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVCountDevices") );
    sDVFuncs.fDVGetIndDevice = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetIndDevice") );
    sDVFuncs.fDVSetDeviceName = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVSetDeviceName") );
    sDVFuncs.fDVGetDeviceName = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetDeviceName") );
    sDVFuncs.fDVOpenDriver = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVOpenDriver") );
    sDVFuncs.fDVCloseDriver = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVCloseDriver") );

// AVC Stuff
    sDVFuncs.fDVDoAVCTransaction = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDoAVCTransaction") );

    sDVFuncs.fDVIsEnabled = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVIsEnabled") );
    sDVFuncs.fDVGetDeviceStandard = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetDeviceStandard") );

// Isoch I/O
    sDVFuncs.fDVEnableRead = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVEnableRead") );
    sDVFuncs.fDVDisableRead = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDisableRead") );
    sDVFuncs.fDVReadFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVReadFrame") );
    sDVFuncs.fDVReleaseFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVReleaseFrame") );
    sDVFuncs.fDVEnableWrite = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVEnableWrite") );
    sDVFuncs.fDVDisableWrite = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDisableWrite") );
    sDVFuncs.fDVGetEmptyFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVGetEmptyFrame") );
    sDVFuncs.fDVWriteFrame = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVWriteFrame") );

// Notifications
    sDVFuncs.fDVNewNotification = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVNewNotification") );
    sDVFuncs.fDVNotifyMeWhen = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVNotifyMeWhen") );
    sDVFuncs.fDVCancelNotification = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVCancelNotification") );
    sDVFuncs.fDVDisposeNotification = CFBundleGetFunctionPointerForName( 
                myBundle, CFSTR("DVDisposeNotification") );

    // Any CF objects returned from functions with "create" or 
    // "copy" in their names must be released by us!
    CFRelease( bundleURL );
    return myBundle;
}
コード例 #24
0
ファイル: load_bundle.c プロジェクト: mutru/growl
	mach_error_t
load_bundle_package(
		const char *bundlePackageFileSystemRepresentation )
{
	printf("LBP\n");
	assert( bundlePackageFileSystemRepresentation );
	assert( strlen( bundlePackageFileSystemRepresentation ) );
	
	mach_error_t err = err_none;
	mach_error("mach error on bundle load", err);

	//	Morph the FSR into a URL.
	CFURLRef bundlePackageURL = NULL;
	if( !err ) {
		bundlePackageURL = CFURLCreateFromFileSystemRepresentation(
			kCFAllocatorDefault,
			(const UInt8*)bundlePackageFileSystemRepresentation,
			strlen(bundlePackageFileSystemRepresentation),
			true );
		if( bundlePackageURL == NULL )
			err = err_load_bundle_url_from_path;
	}
	mach_error("mach error on bundle load", err);

	//	Create bundle.
	CFBundleRef bundle = NULL;
	if( !err ) {
		bundle = CFBundleCreate( kCFAllocatorDefault, bundlePackageURL );
		if( bundle == NULL )
			err = err_load_bundle_create_bundle;
	}
	mach_error("mach error on bundle load", err);

	//	Discover the bundle's executable file.
	CFURLRef bundleExecutableURL = NULL;
	if( !err ) {
		assert( bundle );
		bundleExecutableURL = CFBundleCopyExecutableURL( bundle );
		if( bundleExecutableURL == NULL )
			err = err_load_bundle_package_executable_url;
	}
	mach_error("mach error on bundle load", err);

	//	Morph the executable's URL into an FSR.
	char bundleExecutableFileSystemRepresentation[PATH_MAX];
	if( !err ) {
		assert( bundleExecutableURL );
		if( !CFURLGetFileSystemRepresentation(
			bundleExecutableURL,
			true,
			(UInt8*)bundleExecutableFileSystemRepresentation,
			sizeof(bundleExecutableFileSystemRepresentation) ) )
		{
			err = err_load_bundle_path_from_url;
		}
	}
	mach_error("mach error on bundle load", err);

	//	Do the real work.
	if( !err ) {
		assert( strlen(bundleExecutableFileSystemRepresentation) );
		err = load_bundle_executable( bundleExecutableFileSystemRepresentation);
	}
	
	//	Clean up.
	if( bundleExecutableURL )
		CFRelease( bundleExecutableURL );
	/*if( bundle )
		CFRelease( bundle );*/
	if( bundlePackageURL )
		CFRelease( bundlePackageURL );
	
	mach_error("mach error on bundle load", err);
	return err;
}
コード例 #25
0
ファイル: vsthost.cpp プロジェクト: Angeldude/pd
// hdll, pluginmain and audiomaster are set here
// must be NULL beforehand!
bool VSTPlugin::NewPlugin(const char *plugname)
{
    FLEXT_ASSERT(!pluginmain && !audiomaster);

    dllname = plugname;

#if FLEXT_OS == FLEXT_OS_WIN
    hdll = LoadLibraryEx(dllname.c_str(),NULL,0 /*DONT_RESOLVE_DLL_REFERENCES*/);
/*
    char buf[255],*c;
    strcpy(buf,dllname.c_str());
    for(c = buf; *c; ++c) 
        if(*c == '/') 
            *c = '\\';
    char *sl = strrchr(buf,'\\');
    if(sl) *sl = 0;
    SetCurrentDirectory(buf);
    hdll = LoadLibrary(dllname.c_str());
*/
    if(hdll) pluginmain = (PVSTMAIN)GetProcAddress(hdll,"main");
    audiomaster = Master;  

#elif FLEXT_OS == FLEXT_OS_MAC

#if 1
	CFStringRef fileNameString = CFStringCreateWithCString(NULL, fileName, kCFStringEncodingUTF8);
	if(fileNameString == 0) goto bail;
	CFURLRef url = CFURLCreateWithFileSystemPath(NULL, fileNameString, kCFURLPOSIXPathStyle, false);
	CFRelease(fileNameString);
	if(url == 0) goto bail;
	hdll = CFBundleCreate(NULL, url);
	CFRelease (url);
	if(hdll && !CFBundleLoadExecutable(hdll)) goto bail;

    PVSTMAIN mainaddr = PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("VSTPluginMain"));
	if(!mainaddr)
		mainaddr = (PluginEntryProc)CFBundleGetFunctionPointerForName(hdll, CFSTR("main_macho"));
#ifdef __CFM__
    pluginmain = (PVSTMAIN)NewMachOFromCFM(mainaddr);
    audiomaster = NewCFMFromMachO(Master);
#else
    pluginmain = (PVSTMAIN)mainaddr;
    audiomaster = Master;
#endif

#else
    short   resFileID;
    FSSpec  spec;
    OSErr err;

    err = FSPathMakeFSSpec(dllname.c_str(),&spec,NULL);
    resFileID = FSpOpenResFile(&spec, fsRdPerm);
    short cResCB = Count1Resources('aEff');

    for(int i = 0; i < cResCB; i++) {
        Handle             codeH;
        CFragConnectionID  connID;
        Ptr                mainAddr;
        Str255             errName;
        Str255             fragName;
        char               fragNameCStr[256];
        short              resID;
        OSType             resType;

        codeH = Get1IndResource('aEff', short(i+1));
        if(!codeH) continue;

        GetResInfo(codeH, &resID, &resType, fragName);
        DetachResource(codeH);
        HLock(codeH);

        err = GetMemFragment(*codeH,
                             GetHandleSize(codeH),
                             fragName,
                             kPrivateCFragCopy,
                             &connID, (Ptr *) & mainAddr, errName);

        if(!err) {
           #ifdef __CFM__
           pluginmain = (PVSTMAIN)NewMachOFromCFM(mainAddr);
           #else
           pluginmain = (PVSTMAIN)mainAddr;
           #endif
        }
    }
    CloseResFile(resFileID);

    audiomaster = 
#ifdef __CFM__
        NewCFMFromMachO(Master);
#else
        Master;
#endif

#endif

#else
#error Platform not supported
#endif    

bail:
    if(pluginmain && audiomaster)
        return true;
    else {
        FreePlugin();
        return false;
    }
}
コード例 #26
0
ファイル: tclMacOSXBundle.c プロジェクト: lmiadowicz/tcl
int
Tcl_MacOSXOpenVersionedBundleResources(
    Tcl_Interp *interp,
    const char *bundleName,
    const char *bundleVersion,
    int hasResourceFile,
    int maxPathLen,
    char *libraryPath)
{
#ifdef HAVE_COREFOUNDATION
    CFBundleRef bundleRef, versionedBundleRef = NULL;
    CFStringRef bundleNameRef;
    CFURLRef libURL;

    libraryPath[0] = '\0';

    bundleNameRef = CFStringCreateWithCString(NULL, bundleName,
	    kCFStringEncodingUTF8);

    bundleRef = CFBundleGetBundleWithIdentifier(bundleNameRef);
    CFRelease(bundleNameRef);

    if (bundleVersion && bundleRef) {
	/*
	 * Create bundle from bundleVersion subdirectory of 'Versions'.
	 */

	CFURLRef bundleURL = CFBundleCopyBundleURL(bundleRef);

	if (bundleURL) {
	    CFStringRef bundleVersionRef = CFStringCreateWithCString(NULL,
		    bundleVersion, kCFStringEncodingUTF8);

	    if (bundleVersionRef) {
		CFStringRef bundleTailRef = CFURLCopyLastPathComponent(
			bundleURL);

		if (bundleTailRef) {
		    if (CFStringCompare(bundleTailRef, bundleVersionRef, 0) ==
			    kCFCompareEqualTo) {
			versionedBundleRef = (CFBundleRef) CFRetain(bundleRef);
		    }
		    CFRelease(bundleTailRef);
		}
		if (!versionedBundleRef) {
		    CFURLRef versURL = CFURLCreateCopyAppendingPathComponent(
			    NULL, bundleURL, CFSTR("Versions"), TRUE);

		    if (versURL) {
			CFURLRef versionedBundleURL =
				CFURLCreateCopyAppendingPathComponent(
				NULL, versURL, bundleVersionRef, TRUE);
			if (versionedBundleURL) {
			    versionedBundleRef = CFBundleCreate(NULL,
				    versionedBundleURL);
			    CFRelease(versionedBundleURL);
			}
			CFRelease(versURL);
		    }
		}
		CFRelease(bundleVersionRef);
	    }
	    CFRelease(bundleURL);
	}
	if (versionedBundleRef) {
	    bundleRef = versionedBundleRef;
	}
    }

    if (bundleRef) {
	if (hasResourceFile) {
	    /*
	     * Dynamically acquire address for CFBundleOpenBundleResourceMap
	     * symbol, since it is only present in full CoreFoundation on Mac
	     * OS X and not in CFLite on pure Darwin.
	     */

	    static int initialized = FALSE;
	    static short (*openresourcemap)(CFBundleRef) = NULL;

	    if (!initialized) {
#if TCL_DYLD_USE_DLFCN
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1040
		if (tclMacOSXDarwinRelease >= 8)
#endif
		{
		    const char *errMsg = nil;
		    openresourcemap = dlsym(RTLD_NEXT,
			    "CFBundleOpenBundleResourceMap");
		    if (!openresourcemap) {
			errMsg = dlerror();
			TclLoadDbgMsg("dlsym() failed: %s", errMsg);
		    }
		}
		if (!openresourcemap)
#endif
		{
#if TCL_DYLD_USE_NSMODULE
		    NSSymbol nsSymbol = NULL;
		    if (NSIsSymbolNameDefinedWithHint(
			    "_CFBundleOpenBundleResourceMap",
			    "CoreFoundation")) {
			nsSymbol = NSLookupAndBindSymbolWithHint(
				"_CFBundleOpenBundleResourceMap",
				"CoreFoundation");
			if (nsSymbol) {
			    openresourcemap = NSAddressOfSymbol(nsSymbol);
			}
		    }
#endif
		}
		initialized = TRUE;
	    }

	    if (openresourcemap) {
		short refNum;

		refNum = openresourcemap(bundleRef);
	    }
	}

	libURL = CFBundleCopyResourceURL(bundleRef, CFSTR("Scripts"),
		NULL, NULL);

	if (libURL) {
	    /*
	     * FIXME: This is a quick fix, it is probably not right for
	     * internationalization.
	     */

	    CFURLGetFileSystemRepresentation(libURL, TRUE,
		    (unsigned char*) libraryPath, maxPathLen);
	    CFRelease(libURL);
	}
	if (versionedBundleRef) {
	    CFRelease(versionedBundleRef);
	}
    }

    if (libraryPath[0]) {
	return TCL_OK;
    } else {
	return TCL_ERROR;
    }
#else  /* HAVE_COREFOUNDATION */
    return TCL_ERROR;
#endif /* HAVE_COREFOUNDATION */
}
コード例 #27
0
	mach_error_t
mach_inject_bundle_pid(
		const char	*bundlePackageFileSystemRepresentation,
		pid_t		pid )
{
	assert( bundlePackageFileSystemRepresentation );
	assert( pid > 0 );
	
	mach_error_t	err = err_none;
	
    /*
	//	Get the framework's bundle.
	CFBundleRef frameworkBundle = NULL;
	if( !err ) {
		frameworkBundle = CFBundleGetBundleWithIdentifier(
			CFSTR("com.flyingmeat.JSTalk"));
		if( frameworkBundle == NULL )
			err = err_mach_inject_bundle_couldnt_load_framework_bundle;
	}
	
	//	Find the injection bundle by name.
	CFURLRef injectionURL = NULL;
	if( !err ) {
		injectionURL = CFBundleCopyResourceURL( frameworkBundle,
			CFSTR("mach_inject_bundle_stub.bundle"), NULL, NULL );
		if( !injectionURL )
			err = err_mach_inject_bundle_couldnt_find_injection_bundle;
	}
	*/
    
    CFStringRef filePath = CFStringCreateWithCString(nil, bundlePackageFileSystemRepresentation, kCFStringEncodingUTF8);
    CFURLRef injectionURL = CFURLCreateWithFileSystemPath(nil, filePath, kCFURLPOSIXPathStyle, true);
    
    //CFRelease(filePath);
    
	//	Create injection bundle instance.
	CFBundleRef injectionBundle = NULL;
	if( !err ) {
		injectionBundle = CFBundleCreate( kCFAllocatorDefault, injectionURL );
		if( !injectionBundle )
			err = err_mach_inject_bundle_couldnt_load_injection_bundle;
	}
	
	//	Load the thread code injection.
	void *injectionCode = injectEntry;
    /*
	if( !err ) {
		injectionCode = CFBundleGetFunctionPointerForName( injectionBundle,
			CFSTR( INJECT_ENTRY_SYMBOL ));
		if( injectionCode == NULL )
			err = err_mach_inject_bundle_couldnt_find_inject_entry_symbol;
	}
	*/
    
	//	Allocate and populate the parameter block.
	mach_inject_bundle_stub_param *param = NULL;
	size_t paramSize;
	if( !err ) {
		size_t bundlePathSize = strlen( bundlePackageFileSystemRepresentation )
			+ 1;
		paramSize = sizeof( ptrdiff_t ) + bundlePathSize;
		param = malloc( paramSize );
		bcopy( bundlePackageFileSystemRepresentation,
			   param->bundlePackageFileSystemRepresentation,
			   bundlePathSize );
	}
	
	//	Inject the code.
	if( !err ) {
		err = mach_inject( injectionCode, param, paramSize, pid, 0 );
	}
	
	//	Clean up.
	if( param )
		free( param );
	if( injectionBundle )
		CFRelease( injectionBundle );
	if( injectionURL )
		CFRelease( injectionURL );
	
	return err;
}
コード例 #28
0
/*
 * LoadGlxBundle
 *  The Quartz mode X server needs to dynamically load the appropriate
 *  bundle before initializing GLX.
 */
static void LoadGlxBundle(void)
{
    CFBundleRef mainBundle;
    CFStringRef bundleName;
    CFURLRef    bundleURL;
    CFBundleRef glxBundle;

    // Get the main bundle for the application
    mainBundle = CFBundleGetMainBundle();

    // Choose the bundle to load
    ErrorF("Loading GLX bundle ");
    if (/*quartzUseAGL*/0) {
        bundleName = CFStringCreateWithCStringNoCopy(kCFAllocatorDefault,
                                                     quartzOpenGLBundle,
                                                     kCFStringEncodingASCII,
                                                     kCFAllocatorNull);
        ErrorF("%s (using Apple's OpenGL)\n", quartzOpenGLBundle);
    } else {
        bundleName = CFSTR("glxMesa.bundle");
        CFRetain(bundleName);			// so we can release later
        ErrorF("glxMesa.bundle (using Mesa)\n");
    }

    // Look for the appropriate GLX bundle in the main bundle by name
    bundleURL = CFBundleCopyResourceURL(mainBundle, bundleName,
                                        NULL, NULL);
    if (!bundleURL) {
        FatalError("Could not find GLX bundle.");
    }

    // Make a bundle instance using the URLRef
    glxBundle = CFBundleCreate(kCFAllocatorDefault, bundleURL);

    if (!CFBundleLoadExecutable(glxBundle)) {
        FatalError("Could not load GLX bundle.");
    }

    // Find the GLX init functions


    __DarwinglXMesaProvider = (void *) CFBundleGetDataPointerForName(
			       glxBundle, CFSTR("__glXMesaProvider"));

    GlxPushProvider = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxPushProvider"));

    GlxExtensionInit = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxExtensionInit"));

    GlxWrapInitVisuals = (void *) CFBundleGetFunctionPointerForName(
                                glxBundle, CFSTR("GlxWrapInitVisuals"));

    if (!GlxExtensionInit || !GlxWrapInitVisuals) {
        FatalError("Could not initialize GLX bundle.");
    }

    // Release the CF objects
    CFRelease(bundleName);
    CFRelease(bundleURL);
}
コード例 #29
0
CVST2KSPIPlugIn::CVST2KSPIPlugIn(CVST2KSPIModule* pModule, const std::string& sEffectPathName)
	: CBasePlugIn(dynamic_cast<CBaseModule*>(pModule), giAudioMaxBufferSize, dynamic_cast<CBaseDSPEngine*>(new CEcho()), 0, COMPANY_NAME, PRODUCT_NAME),
	mbUpdateGUISettings(true),
	mbBypass(false), mbShowDemoExpiredDialog(false),
	mbRegistered(false),
	miNoiseMode(0), miNoiseCounter(0),
	msEffectPathName(sEffectPathName),
	mpVSTEffect(NULL)
{
	dynamic_cast<CEcho*>(mpDSPEngine)->SetChannels(2);

	mpDezipper->SetCallback(dynamic_cast<IBaseDezipperCallback*>(this));

	mbCanProcess = true;

	muiTimeWhenStarted = ITime::GetTimeMS();

	miRandom = 0x123456;

#ifdef WIN32
	{
		HMODULE hDLL;

		// Load plug-in
		std::string s2 = msEffectPathName;
		ModifyPathName(s2);
		hDLL = LoadLibrary(s2.c_str());
		if (hDLL == NULL) {
		}
			
		VSTMainFunc mainFunc = (VSTMainFunc)(void*)GetProcAddress(hDLL, "VSTPluginMain");
		if (mainFunc == NULL) {
		}

		try {
			mpVSTEffect = mainFunc(audioMasterCallbackPlugIn);
			mpVSTEffect->dispatcher(mpVSTEffect, effOpen, 0, 0, 0, 0.0);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetSampleRate, 0, 0, 0, 44100.0f);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetBlockSize, 0, 32, 0, 0.0);
		}
		catch(...) {
			// Plug-in crashed
			mpVSTEffect = NULL;
		}
	}
#else	// WIN32
	{
		CFBundleRef BundleRef;

		// Make a CFURLRef from the CFString representation of the bundle's path.
		tchar pszPathName[1024];
		strcpy(pszPathName, msEffectPathName.c_str());
		ToUnix(pszPathName);
		CFURLRef bundleURL = CFURLCreateWithFileSystemPath( 
			kCFAllocatorDefault, 
			__CFStringMakeConstantString(pszPathName),
			kCFURLPOSIXPathStyle,
			true );
		if ( !bundleURL ) {
		}

		// Make a bundle instance using the URLRef.
		BundleRef = CFBundleCreate( kCFAllocatorDefault, bundleURL );

		// We don't need the URL anymore
		CFRelease( bundleURL );	

		if ( !BundleRef ) {
		}

		if ( !CFBundleLoadExecutable( BundleRef ) )
		{
			CFRelease( BundleRef );
			BundleRef = NULL;
		}

		VSTMainFunc mainFunc = (VSTMainFunc)CFBundleGetFunctionPointerForName( 
					BundleRef, CFSTR("VSTPluginMain") );
		if (mainFunc == NULL) {
		}

		try {
			mpVSTEffect = mainFunc(audioMasterCallbackPlugIn);
			mpVSTEffect->dispatcher(mpVSTEffect, effOpen, 0, 0, 0, 0.0);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetSampleRate, 0, 0, 0, 44100.0f);
			mpVSTEffect->dispatcher(mpVSTEffect, effSetBlockSize, 0, 32, 0, 0.0);
		}
		catch(...) {
			// Plug-in crashed
			mpVSTEffect = NULL;
		}
	}
#endif	// WIN32 / else
}
コード例 #30
0
ファイル: WebInterface.cpp プロジェクト: dreamerc/amule
bool CamulewebApp::GetTemplateDir(const wxString& templateName, wxString& templateDir)
{
	wxString dir;
	m_localTemplate = false;

	DebugShow(wxT("looking for template: ") + templateName + wxT("\n"));

#ifdef __WXMAC__
	CFURLRef amuleBundleUrl;
	OSStatus status = LSFindApplicationForInfo(
		kLSUnknownCreator,
		// This magic string is the bundle identifier in aMule.app's Info.plist
		CFSTR("org.amule.aMule"),
		NULL, NULL, &amuleBundleUrl);
	if (status == noErr && amuleBundleUrl) {
		CFBundleRef amuleBundle = CFBundleCreate(NULL, amuleBundleUrl);
		CFRelease(amuleBundleUrl);
		if (amuleBundle) {
			CFURLRef webserverDirUrl = CFBundleCopyResourceURL(
				amuleBundle,
				CFSTR("webserver"),
				NULL, NULL);
			CFRelease(amuleBundle);
			if (webserverDirUrl) {
				CFURLRef absoluteURL =
					CFURLCopyAbsoluteURL(webserverDirUrl);
				CFRelease(webserverDirUrl);
				if (absoluteURL) {
					CFStringRef pathString =
						CFURLCopyFileSystemPath(
							absoluteURL,
							kCFURLPOSIXPathStyle);
					CFRelease(absoluteURL);
					#if wxCHECK_VERSION(2, 9, 0)
						dir = wxCFStringRef(pathString).
						AsString(wxLocale::GetSystemEncoding());
					#else
						dir = wxMacCFStringHolder(pathString).
						AsString(wxLocale::GetSystemEncoding());
					#endif
					if (CheckDirForTemplate(dir, templateName)) {
						templateDir = dir;
						return true;
					}
				}
			}
		}
	}
#endif

	dir = GetConfigDir(wxT("remote.conf")) + wxT("webserver");
	if (CheckDirForTemplate(dir, templateName)) {
		templateDir = dir;
		m_localTemplate = true;
		return true;
	}
#ifdef WEBSERVERDIR
	dir = wxT(WEBSERVERDIR);
	if (CheckDirForTemplate(dir, templateName)) {
		templateDir = dir;
		return true;
	}
#endif
	
	dir = wxStandardPaths::Get().GetResourcesDir();	// Returns 'aMule' when we use 'amule' elsewhere
#if !defined(__WXMSW__) && !defined(__WXMAC__)
	dir = dir.BeforeLast(wxFileName::GetPathSeparator());
	dir = JoinPaths(dir, wxT("amule"));
#endif
	dir = JoinPaths(dir, wxT("webserver"));
	if (CheckDirForTemplate(dir, templateName)) {
		templateDir = dir;
		return true;
	}
	
	// template not found. reverting to default
	const wxChar* const defaultTemplateName = wxT("default");

	if ( templateName == defaultTemplateName ) {
		return false;
	}
	Show(wxT("Template ") + templateName + wxT(" not found, reverting to default\n\n"));
	return GetTemplateDir(defaultTemplateName, templateDir);
}