AutoAwayPlugin::AutoAwayPlugin(unsigned base, Buffer *config) : Plugin(base), EventReceiver(HighPriority) { load_data(autoAwayData, &data, config); #ifdef WIN32 HINSTANCE hLib = GetModuleHandleA("user32"); if (hLib != NULL){ (DWORD&)_GetLastInputInfo = (DWORD)GetProcAddress(hLib,"GetLastInputInfo"); }else{ hLibUI = LoadLibraryA("idleui.dll"); if (hLibUI != NULL) (DWORD&)_IdleUIGetLastInputTime = (DWORD)GetProcAddress(hLibUI, "IdleUIGetLastInputTime"); } #elif defined(HAVE_CARBON_CARBNON_H) && !defined(HAVE_X) CFBundleRef carbonBundle; if (LoadFrameworkBundle( CFSTR("Carbon.framework"), &carbonBundle ) == noErr) { InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName(carbonBundle, CFSTR("InstallEventLoopIdleTimer")); if (myInstallEventLoopIdleTimer){ EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP(Private::IdleTimerAction); (*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &mTimerRef); } } #endif Event ePlugin(EventGetPluginInfo, (void*)"_core"); pluginInfo *info = (pluginInfo*)(ePlugin.process()); core = static_cast<CorePlugin*>(info->plugin); bAway = false; bNA = false; bOff = false; m_timer = new QTimer(this); connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout())); m_timer->start(AUTOAWAY_TIME); }
bool Kopete::IdlePlatform::init() { // May already be init'ed. if ( d->mTimerRef ) return true; // According to the docs, InstallEventLoopIdleTimer is new in 10.2. // According to the headers, it has been around since 10.0. // One of them is lying. We'll play it safe and weak-link the function. // Load the "Carbon.framework" bundle. CFBundleRef carbonBundle; if ( LoadFrameworkBundle( CFSTR("Carbon.framework"), &carbonBundle ) != noErr ) return false; // Load the Mach-O function pointers for the routine we will be using. InstallEventLoopIdleTimerPtr myInstallEventLoopIdleTimer = (InstallEventLoopIdleTimerPtr)CFBundleGetFunctionPointerForName( carbonBundle, CFSTR("InstallEventLoopIdleTimer") ); if ( myInstallEventLoopIdleTimer == 0 ) return false; EventLoopIdleTimerUPP timerUPP = NewEventLoopIdleTimerUPP( Private::IdleTimerAction ); if ( (*myInstallEventLoopIdleTimer)(GetMainEventLoop(), kEventDurationSecond, kEventDurationSecond, timerUPP, 0, &d->mTimerRef) ) return true; return false; }
//----------------------------------------------------------------------------- DynamicLibrary::DynamicLibrary( const char *filename, bool reportErrors ) { char realname[1024]; hInst = NULL; #if defined(TORQUE_OS_MAC_CARB) if (platState.osX) { dSprintf(realname, 1024, "%s.framework", filename); err = LoadFrameworkBundle(CFSTR(realname), &((CFBundleRef)hInst)); } else #endif { dSprintf(realname, 1024, "\p%s", filename); err = GetSharedLibrary (realname, kAnyCFragArch, // as we want whatever form it is in kReferenceCFrag, // the new name for the kLoadLib flag &((CFragConnectionID)hInst), // holder of codefrag connection identifier NULL, // we don't care NULL); // we don't care } mError = false; mErrorReport = reportErrors; if ( !mInst ) { Con::errorf( "DynamicLibrary: Failed to load %s.", realname ); mInst = NULL; } }
static CFBundleRef getCorePrintingBundle() { static CFBundleRef printingBundle = NULL; // first time this is called we need to load the framework bundle if(!printingBundle){ OSStatus err = LoadFrameworkBundle(CFSTR("ApplicationServices.framework"), &printingBundle); if(err) printingBundle = NULL; } return printingBundle; }
static boolean unixshellcallinit (void) { /* 2006-01-10 creedon: added fcntlfunc, feoffunc and filenofunc 7.0b51 PBS: load the bundle and get the function pointers the first time called. */ if (unixshellcallinited) /*already inited*/ return (true); if (sysBundle == nil) if (LoadFrameworkBundle (CFSTR ("System.framework"), &sysBundle) != noErr) return (false); popenfunc = (popenptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("popen")); if (popenfunc == nil) return (false); freadfunc = (freadptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fread")); if (freadfunc == nil) return (false); pclosefunc = (pcloseptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("pclose")); if (pclosefunc == nil) return (false); fcntlfunc = (fcntlptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fcntl")); if (fcntlfunc == nil) return (false); feoffunc = (feofptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("feof")); if (feoffunc == nil) return (false); filenofunc = (filenoptr) CFBundleGetFunctionPointerForName (sysBundle, CFSTR ("fileno")); if (filenofunc == nil) return (false); unixshellcallinited = true; return (true); } /*unixshellcallinit*/
static void GetMissingQTFunctionPointers() { OSErr err; CFBundleRef sysBundle; err = LoadFrameworkBundle(CFSTR("QuickTime.framework"), &sysBundle); if (err == noErr) { mNewQTNextPtr = (NewQTNextTaskPtr) CFBundleGetFunctionPointerForName( sysBundle, CFSTR("NewQTNextTaskNeededSoonerCallbackUPP") ); mQTInstallNextPtr = (QTInstallNextTaskPtr) CFBundleGetFunctionPointerForName( sysBundle, CFSTR("QTInstallNextTaskNeededSoonerCallback") ); mQTGetTimeUntilNextTaskPtr = (QTGetTimeUntilNextTaskPtr) CFBundleGetFunctionPointerForName( sysBundle, CFSTR("QTGetTimeUntilNextTask") ); mDisposeQTNextTaskPtr = (DisposeQTNextTaskPtr)CFBundleGetFunctionPointerForName( sysBundle, CFSTR("DisposeQTNextTaskNeededSoonerCallbackUPP") ); mQTUninstallNextTaskPtr = (QTUninstallNextTaskPtr)CFBundleGetFunctionPointerForName( sysBundle, CFSTR("QTUninstallNextTaskNeededSoonerCallback") );; } }
int printOnOSXFormat(char * string,char *format) { CFBundleRef bundle; int(*fprintf_ptr)(FILE *stream, const char *format, ...) = NULL; int(*fcnFlush_ptr)(FILE *stream) = NULL; void* fcn_ptr = NULL; void* fcnFlushx_ptr = NULL; OSErr err; FILE* stderr_ptr = NULL; void* __sf_ptr = NULL; err = LoadFrameworkBundle( CFSTR("System.framework"), &bundle ); fcn_ptr = CFBundleGetFunctionPointerForName(bundle, CFSTR("fprintf")); fcnFlushx_ptr = CFBundleGetFunctionPointerForName(bundle, CFSTR("fflush")); __sf_ptr = CFBundleGetDataPointerForName(bundle, CFSTR("__sF")); if(fcn_ptr) { /* cast it */ fprintf_ptr = ( int(*)(FILE *stream, const char *format, ...) ) fcn_ptr; } else { /* it failed, handle that somehow */ return; } if(fcnFlushx_ptr) { /* cast it */ fcnFlush_ptr = ( int(*)(FILE *stream) ) fcnFlushx_ptr; } else { /* it failed, handle that somehow */ return; } if(__sf_ptr) { stderr_ptr = (FILE*) ( ((char*)__sf_ptr) + 176); /* 176 = 88*2, where 88=sizeof(FILE) under BSD */ } else { /* it failed */ return; } fprintf_ptr(stderr_ptr, format,string); fcnFlush_ptr(stderr_ptr); }
CFragConnectionID LoadLibViaPath(char *libName, char *pluginDirPath) { char tempDirPath[DOCUMENT_NAME_SIZE+1]; char cFileName[DOCUMENT_NAME_SIZE+1]; CFragConnectionID libHandle = 0; CFStringRef filePath; CFURLRef theURLRef; CFBundleRef theBundle; OSStatus err; strncpy(tempDirPath,pluginDirPath,DOCUMENT_NAME_SIZE); if (tempDirPath[strlen(tempDirPath)-1] != DELIMITERInt) strcat(tempDirPath,DELIMITER); if ((strlen(tempDirPath) + strlen(libName) + 7) > DOCUMENT_NAME_SIZE) return nil; strcat(tempDirPath,libName); strcat(tempDirPath,".bundle"); //Watch out for the bundle suffix, not a normal thing in squeak plugins /* copy the file name into a null-terminated C string */ sqFilenameFromStringOpen(cFileName, (int) &tempDirPath, strlen(tempDirPath)); #ifdef JMMDEBUG fprintf(stderr,"\nLoadLibViaPath file %s",cFileName); #endif filePath = CFStringCreateWithBytes(kCFAllocatorDefault,(UInt8 *)cFileName,strlen(cFileName),kCFStringEncodingUTF8,false); theURLRef = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,filePath,kCFURLPOSIXPathStyle,false); CFRelease(filePath); if (theURLRef == nil) { #ifdef JMMDEBUG fprintf(stderr,"\ntheURLRef was nil so bail"); #endif return nil; } theBundle = CFBundleCreate(NULL,theURLRef); CFRelease(theURLRef); if (theBundle == nil) { CFStringRef libNameCFString; #ifdef JMMDEBUG fprintf(stderr,"\nbundle was nil, trying to load from other system locations"); #endif libNameCFString = CFStringCreateWithCString(kCFAllocatorDefault,libName,gCurrentVMEncoding); err = LoadFrameworkBundle(kUserDomain,libNameCFString, &theBundle); if (err != noErr) err = LoadFrameworkBundle(kNetworkDomain,libNameCFString, &theBundle); if (err != noErr) err = LoadFrameworkBundle(kLocalDomain,libNameCFString, &theBundle); if (err != noErr) err = LoadFrameworkBundle(kSystemDomain,libNameCFString, &theBundle); CFRelease(libNameCFString); if (err != noErr) { #ifdef JMMDEBUG fprintf(stderr,"\nno bundle so bail, last error %i",err); #endif return nil; } } if (theBundle == nil) { #ifdef JMMDEBUG fprintf(stderr,"\nno bundle so bail"); #endif return nil; } if (!CFBundleLoadExecutable(theBundle)) { #ifdef JMMDEBUG fprintf(stderr,"\nBundle found but failed CFBundleLoadExecutable"); #endif CFRelease(theBundle); return nil; } libHandle = (CFragConnectionID) theBundle; #ifdef JMMDEBUG fprintf(stderr,"\nFound Bundle %i",libHandle); #endif return libHandle; }