Esempio n. 1
0
void DAFileSystemListRefresh( void )
{
    struct stat status1;
    struct stat status2;

    /*
     * Determine whether the file system list is up-to-date.
     */

    if ( stat( FS_DIR_LOCATION, &status1 ) )
    {
        __gDAFileSystemListTime1.tv_sec  = 0;
        __gDAFileSystemListTime1.tv_nsec = 0;
    }

    if ( stat( ___FS_DEFAULT_DIR, &status2 ) )
    {
        __gDAFileSystemListTime2.tv_sec  = 0;
        __gDAFileSystemListTime2.tv_nsec = 0;
    }

    if ( __gDAFileSystemListTime1.tv_sec  != status1.st_mtimespec.tv_sec  ||
         __gDAFileSystemListTime1.tv_nsec != status1.st_mtimespec.tv_nsec ||
         __gDAFileSystemListTime2.tv_sec  != status2.st_mtimespec.tv_sec  ||
         __gDAFileSystemListTime2.tv_nsec != status2.st_mtimespec.tv_nsec )
    {
        __gDAFileSystemListTime1.tv_sec  = status1.st_mtimespec.tv_sec;
        __gDAFileSystemListTime1.tv_nsec = status1.st_mtimespec.tv_nsec;
        __gDAFileSystemListTime2.tv_sec  = status2.st_mtimespec.tv_sec;
        __gDAFileSystemListTime2.tv_nsec = status2.st_mtimespec.tv_nsec;

        /*
         * Clear the file system list.
         */

        CFArrayRemoveAllValues( gDAFileSystemList );
        CFArrayRemoveAllValues( gDAFileSystemProbeList );

        /*
         * Build the file system list.
         */

        __DAFileSystemListRefresh( FS_DIR_LOCATION );
        __DAFileSystemListRefresh( ___FS_DEFAULT_DIR );

        /*
         * Order the probe list.
         */

        CFArraySortValues( gDAFileSystemProbeList,
                           CFRangeMake( 0, CFArrayGetCount( gDAFileSystemProbeList ) ),
                           __DAFileSystemProbeListCompare,
                           NULL );
    }
}
Esempio n. 2
0
/* CF_EXPORT */ void
CFNetServiceBrowserInvalidate(CFNetServiceBrowserRef b) {

	__CFNetServiceBrowser* browser = (__CFNetServiceBrowser*)b;

	// Lock the browser
	__CFSpinLock(&(browser->_lock));

	// Release the user's context info if there is some and a release method
	if (browser->_client.info && browser->_client.release)
		browser->_client.release(browser->_client.info);

	// Cancel the outstanding trigger
	if (browser->_trigger) {

		// Remove the trigger from run loops and modes
		_CFTypeUnscheduleFromMultipleRunLoops(browser->_trigger, browser->_schedules);

		// Go ahead and invalidate the trigger
		_CFTypeInvalidate(browser->_trigger);

		// Release the browse now.
		CFRelease(browser->_trigger);
		browser->_trigger = NULL;
	}

	// Need to clean up the service discovery stuff if there is
	if (browser->_browse) {

		// Release the underlying service discovery reference
		DNSServiceRefDeallocate(browser->_browse);
		browser->_browse = NULL;

		// Dump all the lists of items.
		CFDictionaryRemoveAllValues(browser->_found);
		CFArrayRemoveAllValues(browser->_adds);
		CFArrayRemoveAllValues(browser->_removes);
	}

	// Zero out the callback and client context.
	browser->_callback = NULL;
	memset(&(browser->_client), 0, sizeof(browser->_client));

	// Unlock the browser.
	__CFSpinUnlock(&(browser->_lock));
}
static void _CFApplicationPreferencesSetSearchList(_CFApplicationPreferences *self, CFArrayRef newSearchList) {
    CFIndex idx, count;
    __CFSpinLock(&__CFApplicationPreferencesLock);
    CFArrayRemoveAllValues(self->_search);
    count = CFArrayGetCount(newSearchList);
    for (idx = 0; idx < count; idx ++) {
        CFArrayAppendValue(self->_search, CFArrayGetValueAtIndex(newSearchList, idx));
    }
    updateDictRep(self);
    __CFSpinUnlock(&__CFApplicationPreferencesLock);
}
Esempio n. 4
0
void DAMountMapListRefresh2( void )
{
    struct stat status;

    /*
     * Determine whether the mount map list is up-to-date.
     */

    if ( stat( _PATH_VSDB, &status ) )
    {
        __gDAMountMapListTime2.tv_sec  = 0;
        __gDAMountMapListTime2.tv_nsec = 0;
    }

    if ( __gDAMountMapListTime2.tv_sec  != status.st_mtimespec.tv_sec  ||
         __gDAMountMapListTime2.tv_nsec != status.st_mtimespec.tv_nsec )
    {
        __gDAMountMapListTime2.tv_sec  = status.st_mtimespec.tv_sec;
        __gDAMountMapListTime2.tv_nsec = status.st_mtimespec.tv_nsec;

        /*
         * Clear the mount map list.
         */

        CFArrayRemoveAllValues( gDAMountMapList2 );

        /*
         * Build the mount map list.
         */

        if ( setvsent( ) )
        {
            struct vsdb * item;

            while ( ( item = getvsent( ) ) )
            {
                CFDictionaryRef map;

                map = __DAMountMapCreate2( kCFAllocatorDefault, item );

                if ( map )
                {
                    CFArrayAppendValue( gDAMountMapList2, map );

                    CFRelease( map );
                }
            }

            endvsent( );
        }
    }
}
Esempio n. 5
0
static void __DAStageProbe( DADiskRef disk )
{
    /*
     * We commence the "probe" stage if the conditions are right.
     */

    if ( DAUnitGetState( disk, kDAUnitStateCommandActive ) == FALSE )
    {
        CFMutableArrayRef candidates;

        candidates = CFArrayCreateMutableCopy( kCFAllocatorDefault, 0, gDAFileSystemProbeList );

        if ( candidates )
        {
            CFNumberRef size;

            /*
             * Determine whether the disk is formatted.
             */

            size = DADiskGetDescription( disk, kDADiskDescriptionMediaSizeKey );

            if ( size )
            {
                if ( ___CFNumberGetIntegerValue( size ) == 0 )
                {
                    CFArrayRemoveAllValues( candidates );
                }
            }

            /*
             * Commence the probe.
             */

            CFRetain( disk );

            DADiskSetFileSystem( disk, NULL );

            DADiskSetContext( disk, candidates );

            DADiskSetState( disk, kDADiskStateStagedProbe, TRUE );

            DADiskSetState( disk, kDADiskStateCommandActive, TRUE );

            DAUnitSetState( disk, kDAUnitStateCommandActive, TRUE );

            __DAStageProbeCallback( -1, NULL, NULL, NULL, disk );

            CFRelease( candidates );
        }
    }
}
Esempio n. 6
0
void wxApp::OnIdle(wxIdleEvent& WXUNUSED(event))
{
    // If they are pending events, we must process them: pending events are
    // either events to the threads other than main or events posted with
    // wxPostEvent() functions
#ifndef __WXUNIVERSAL__
#if wxUSE_MENUS
  if (!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
    wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
#endif
#endif
    CFArrayRemoveAllValues( GetAutoReleaseArray() );
}
static Boolean synchronizeXMLDomain(CFTypeRef context, void *xmlDomain) {
    _CFXMLPreferencesDomain *domain = (_CFXMLPreferencesDomain *)xmlDomain;
    CFMutableDictionaryRef cachedDict;
    CFMutableArrayRef changedKeys;
    SInt32 idx,  count;
    Boolean success, tryAgain;
    
    __CFLock(&domain->_lock);
    cachedDict = domain->_domainDict;
    changedKeys = domain->_dirtyKeys;
    count = CFArrayGetCount(changedKeys);
    
    if (count == 0) {
        // no changes were made to this domain; just remove it from the cache to guarantee it will be taken from disk next access
        if (cachedDict) {
            CFRelease(cachedDict);
            domain->_domainDict = NULL;
        }
        __CFUnlock(&domain->_lock);
        return true;
    }

    domain->_domainDict = NULL; // This forces a reload.  Note that we now have a retain on cachedDict
    do {
        _loadXMLDomainIfStale((CFURLRef )context, domain);
        // now cachedDict holds our changes; domain->_domainDict has the latest version from the disk
        for (idx = 0; idx < count; idx ++) {
            CFStringRef key = (CFStringRef) CFArrayGetValueAtIndex(changedKeys, idx);
            CFTypeRef value = CFDictionaryGetValue(cachedDict, key);
            if (value)
                CFDictionarySetValue(domain->_domainDict, key, value);
            else
                CFDictionaryRemoveValue(domain->_domainDict, key);
        }
        success = _writeXMLFile((CFURLRef )context, domain->_domainDict, domain->_isWorldReadable, &tryAgain);
        if (tryAgain) {
            __CFMilliSleep(50);
        }
    } while (tryAgain);
    CFRelease(cachedDict);
    if (success) {
	CFArrayRemoveAllValues(domain->_dirtyKeys);
    }
    domain->_lastReadTime = CFAbsoluteTimeGetCurrent();
    __CFUnlock(&domain->_lock);
    return success;
}
Esempio n. 8
0
File: app.cpp Progetto: hgwells/tive
void wxApp::MacHandleOneEvent( WXEVENTREF evr )
{
    EventTargetRef theTarget;
    theTarget = GetEventDispatcherTarget();
    m_macCurrentEvent = evr ;

    OSStatus status = SendEventToEventTarget((EventRef) evr , theTarget);
    if (status == eventNotHandledErr)
        MacHandleUnhandledEvent(evr);

    wxMacProcessNotifierAndPendingEvents() ;

#if wxUSE_THREADS
    wxMutexGuiLeaveOrEnter();
#endif // wxUSE_THREADS

    CFArrayRemoveAllValues( GetAutoReleaseArray() );
}
Esempio n. 9
0
void mainThreadRunLoopSourceCallback(void *info)
{
    int pthreadError;
    CFArrayRef copiedQueueArray;
    CFIndex queueCount, queueIndex;
    
    // take the lock on the message queue
    pthreadError = pthread_mutex_lock(&queueLock);
    if (pthreadError) {
#if DEBUG
        printf("AddToMessageQueue: pthread_mutex_lock failed (%d)\n", pthreadError);
#endif
        return;
    }

    // copy the array of queued objects,
    copiedQueueArray = CFArrayCreateCopy(kCFAllocatorDefault, queueArray);
    // and remove the queued objects
    CFArrayRemoveAllValues(queueArray);

    // release the lock
    pthreadError = pthread_mutex_unlock(&queueLock);
    if (pthreadError) {
#if DEBUG
        printf("AddToMessageQueue: pthread_mutex_unlock failed (%d)\n", pthreadError);
#endif
        CFRelease(copiedQueueArray);
        return;
    }
    
    // for each object in the array, call a function to process it
    queueCount = CFArrayGetCount(copiedQueueArray);
    for (queueIndex = 0; queueIndex < queueCount; queueIndex++) {
        CFTypeRef object;

        object = (CFDictionaryRef)CFArrayGetValueAtIndex(copiedQueueArray, queueIndex);
        handler(object, handlerRefCon);        
    }

    CFRelease(copiedQueueArray);
    
    return;
}
CF_EXPORT void CFNotificationCenterRemoveObserver(CFNotificationCenterRef center, const void *observer, CFStringRef name, const void *object) {
    if (observer == NULL) {
        return;
    }
    OSSpinLockLock(&center->lock);
    CFNotificationObserver ctx = {
        .observer = observer,
        .name = name,
        .object = object,
        .context = center
    };
    struct __CFNotificationRemove notificationRemove = {
        .ctx = &ctx,
        .removed = 0,
        .more = 0
    };
    do {
        CFArrayApplyFunction(center->observers, CFRangeMake(0, CFArrayGetCount(center->observers)), (CFArrayApplierFunction)&removeObserver, &notificationRemove);
        for (int i=notificationRemove.removed-1; i >= 0; i--)
        {
            CFArrayRemoveValueAtIndex(center->observers, notificationRemove.removeIdx[i]);
        }
        if (notificationRemove.removed < __CFMaxRemove && !notificationRemove.more)
        {
            break;
        }
        notificationRemove.removed = 0;
        notificationRemove.more = 0;
    } while(1);
    OSSpinLockUnlock(&center->lock);
}

CF_EXPORT void CFNotificationCenterRemoveEveryObserver(CFNotificationCenterRef center, const void *observer) {
    OSSpinLockLock(&center->lock);
    CFArrayRemoveAllValues(center->observers);
    OSSpinLockUnlock(&center->lock);
}
static void tests(void)
{
    CFErrorRef error = NULL;
    CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
    CFStringRef cfaccount = CFSTR("*****@*****.**");

    CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);

    SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
    SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
    SOSAccountRef carole_account = CreateAccountForLocalChanges(CFSTR("Carole"), CFSTR("TestSource"));
    SOSAccountRef david_account = CreateAccountForLocalChanges(CFSTR("David"), CFSTR("TestSource"));
    
    ok(SOSAccountAssertUserCredentials(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
    
    // Bob wins writing at this point, feed the changes back to alice.
    is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, david_account, NULL), 1, "updates");

    ok(SOSAccountAssertUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
    CFReleaseNull(error);
    
    ok(SOSAccountAssertUserCredentials(carole_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
    CFReleaseNull(error);
    
    ok(SOSAccountAssertUserCredentials(david_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
    CFReleaseNull(cfpassword);
    CFReleaseNull(error);
    
    ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error);
    CFReleaseNull(error);
    
    // Lost Application Scenario
    is(ProcessChangesOnce(changes, alice_account, bob_account, carole_account, david_account, NULL), 1, "updates");

    ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error);
    CFReleaseNull(error);
    
    ok(SOSAccountJoinCircles(carole_account, &error), "Carole Applies too (%@)", error);
    CFReleaseNull(error);
    
    is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");
    
    accounts_agree("alice and carole agree", alice_account, carole_account);
    accounts_agree("alice and bob agree", alice_account, bob_account);
    
    {
        CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
        
        ok(applicants && CFArrayGetCount(applicants) == 2, "See two applicants %@ (%@)", applicants, error);
        CFReleaseNull(error);
        CFReleaseSafe(applicants);
    }
    
    is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, david_account, NULL), 1, "updates");

    accounts_agree("alice and carole agree", alice_account, carole_account);

    CFReleaseNull(error);
    
    {
        CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
        ok(applicants && CFArrayGetCount(applicants) == 2, "See two applicants %@ (%@)", applicants, error);
        ok(SOSAccountRejectApplicants(alice_account, applicants, &error), "Everyone out the pool");
        CFReleaseNull(error);
        CFReleaseSafe(applicants);
    }

    is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");

    accounts_agree("alice and carole agree", alice_account, carole_account);

    {
        CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
        ok(applicants && CFArrayGetCount(applicants) == 0, "See no applicants %@ (%@)", applicants, error);
        CFReleaseNull(error);
        CFReleaseSafe(applicants);
    }
    
    ok(SOSAccountJoinCircles(bob_account, &error), "Bob asks again");
    CFReleaseNull(error);

    is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, david_account, NULL), 2, "updates");

    {
        CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
        ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicants %@ (%@)", applicants, error);
        CFReleaseNull(error);
        ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Accept bob into the fold");
        CFReleaseNull(error);
        CFReleaseSafe(applicants);
    }

    is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, carole_account, david_account, NULL), 3, "updates");

#if 0
    
    {
        CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
        
        ok(applicants && CFArrayGetCount(applicants) == 1, "Bob automatically re-applied %@ (%@)", applicants, error);
        ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
        CFReleaseNull(error);
        CFReleaseNull(applicants);
    }
    
    is(countPeers(alice_account, 0), 3, "Bob is accepted after auto-reapply");
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    accounts_agree("alice and carole agree after bob gets in", alice_account, carole_account);
    
    // Rejected Application Scenario
    ok(SOSAccountJoinCircles(david_account, &error), "Dave Applies (%@)", error);
    CFReleaseNull(error);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    SOSAccountPurgePrivateCredential(alice_account);
    
    {
        CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
        
        ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
        ok(SOSAccountRejectApplicants(alice_account, applicants, &error), "Alice rejects (%@)", error);
        CFReleaseNull(error);
        CFReleaseNull(applicants);
    }
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    accounts_agree("alice and carole still agree after david is rejected", alice_account, carole_account);
    ok(SOSAccountTryUserCredentials(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
    CFReleaseNull(error);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    FillAllChanges(changes);
    
    ok(CFDictionaryGetCount(CarolChanges) == 0, "We converged. (%@)", CarolChanges);
    ok(CFDictionaryGetCount(BobChanges) == 0, "We converged. (%@)", BobChanges);
    ok(CFDictionaryGetCount(AliceChanges) == 0, "We converged. (%@)", AliceChanges);
    ok(CFDictionaryGetCount(DavidChanges) == 0, "We converged. (%@)", DavidChanges);
    
    accounts_agree("bob&alice pair", bob_account, alice_account);
    
    ok(SOSAccountJoinCirclesAfterRestore(carole_account, &error), "Carole cloud identiy joins (%@)", error);
    CFReleaseNull(error);
    
    is(countPeers(carole_account, false), 3, "Carole sees 3 valid peers after sliding in");
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL);
    
    FillAllChanges(changes);
    FeedChangesToMulti(AliceChanges, bob_account, carole_account, david_account, NULL);
    FeedChangesToMulti(BobChanges, alice_account, carole_account, david_account, NULL);
    FeedChangesToMulti(CarolChanges, bob_account, alice_account, david_account, NULL);
    FeedChangesToMulti(DavidChanges, bob_account, alice_account, carole_account, NULL); // Bob and carole see the final result.
    
    accounts_agree_internal("Carole's in", bob_account, alice_account, false);
    accounts_agree_internal("Carole's in - 2", bob_account, carole_account, false);
#endif
    CFReleaseNull(bob_account);
    CFReleaseNull(alice_account);
    CFReleaseNull(carole_account);
    
    SOSUnregisterAllTransportMessages();
    SOSUnregisterAllTransportCircles();
    SOSUnregisterAllTransportKeyParameters();
    CFArrayRemoveAllValues(key_transports);
    CFArrayRemoveAllValues(circle_transports);
    CFArrayRemoveAllValues(message_transports);
    
}
	void VectorCommand::SRemoveAllCommands( IOFireWireLibVectorCommandRef self )
	{
		VectorCommand * me = IOFireWireIUnknown::InterfaceMap<VectorCommand>::GetThis(self);
		
		CFArrayRemoveAllValues( me->mCommandArray );
	}
Esempio n. 13
0
void logger::clearLog(){
	CFArrayRemoveAllValues(logArray);
	needUpdate == true;
}
Esempio n. 14
0
// Because language preferences are set on a per-user basis, we
// must get the preferred languages while set to the current 
// user, before the Apple Installer switches us to root.
// So we get the preferred languages here and write them to a
// temporary file to be retrieved by our PostInstall app.
static void GetPreferredLanguages() {
    DIR *dirp;
    struct dirent *dp;
    char temp[MAXPATHLEN];
    char searchPath[MAXPATHLEN];
    char savedWD[MAXPATHLEN];
    struct stat sbuf;
    CFMutableArrayRef supportedLanguages;
    CFStringRef aLanguage;
    char shortLanguage[32];
    CFArrayRef preferredLanguages;
    int i, j, k;
    char * language;
    char *uscore;
    FILE *f;

    getcwd(savedWD, sizeof(savedWD));
    snprintf(temp, sizeof(temp), "rm -dfR /tmp/%s/BOINC_payload", tempDirName);
    callPosixSpawn(temp);
    snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_payload", tempDirName);
    mkdir(temp, 0777);
    chmod(temp, 0777);  // Needed because mkdir sets permissions restricted by umask (022)
    chdir(temp);
    snprintf(temp, sizeof(temp), "cpio -i -I /tmp/%s/expanded_BOINC.pkg/BOINC.pkg/Payload", tempDirName);
    callPosixSpawn(temp);
    chdir(savedWD);

    // Create an array of all our supported languages
    supportedLanguages = CFArrayCreateMutable(kCFAllocatorDefault, 100, &kCFTypeArrayCallBacks);
    
    aLanguage = CFStringCreateWithCString(NULL, "en", kCFStringEncodingMacRoman);
    CFArrayAppendValue(supportedLanguages, aLanguage);
    CFRelease(aLanguage);
    aLanguage = NULL;

    dirp = opendir(Catalogs_Dir);
    if (!dirp) {
        REPORT_ERROR(true);
        goto cleanup;
    }
    while (true) {
        dp = readdir(dirp);
        if (dp == NULL)
            break;                  // End of list

        if (dp->d_name[0] == '.')
            continue;               // Ignore names beginning with '.'

        strlcpy(searchPath, Catalogs_Dir, sizeof(searchPath));
        strlcat(searchPath, dp->d_name, sizeof(searchPath));
        strlcat(searchPath, "/", sizeof(searchPath));
        strlcat(searchPath, Catalog_Name, sizeof(searchPath));
        strlcat(searchPath, ".mo", sizeof(searchPath));
        if (stat(searchPath, &sbuf) != 0) continue;
//        printf("Adding %s to supportedLanguages array\n", dp->d_name);
        aLanguage = CFStringCreateWithCString(NULL, dp->d_name, kCFStringEncodingMacRoman);
        CFArrayAppendValue(supportedLanguages, aLanguage);
        CFRelease(aLanguage);
        aLanguage = NULL;
        
        // If it has a region code ("it_IT") also try without region code ("it")
        // TODO: Find a more general solution
        strlcpy(shortLanguage, dp->d_name, sizeof(shortLanguage));
        uscore = strchr(shortLanguage, '_');
        if (uscore) {
            *uscore = '\0';
            aLanguage = CFStringCreateWithCString(NULL, shortLanguage, kCFStringEncodingMacRoman);
            CFArrayAppendValue(supportedLanguages, aLanguage);
            CFRelease(aLanguage);
            aLanguage = NULL;
        }
    }
    
    closedir(dirp);

    // Write a temp file to tell our PostInstall.app our preferred languages
    snprintf(temp, sizeof(temp), "/tmp/%s/BOINC_preferred_languages", tempDirName);
    f = fopen(temp, "w");
    if (!f) {
        REPORT_ERROR(true);
        goto cleanup;
    }

    for (i=0; i<MAX_LANGUAGES_TO_TRY; ++i) {
    
        preferredLanguages = CFBundleCopyLocalizationsForPreferences(supportedLanguages, NULL );
        
#if 0   // For testing
        int c = CFArrayGetCount(preferredLanguages);
        for (k=0; k<c; ++k) {
        CFStringRef s = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, k);
            printf("Preferred language %u is %s\n", k, CFStringGetCStringPtr(s, kCFStringEncodingMacRoman));
        }

#endif

        for (j=0; j<CFArrayGetCount(preferredLanguages); ++j) {
            aLanguage = (CFStringRef)CFArrayGetValueAtIndex(preferredLanguages, j);
            language = (char *)CFStringGetCStringPtr(aLanguage, kCFStringEncodingMacRoman);
            if (language == NULL) {
                if (CFStringGetCString(aLanguage, shortLanguage, sizeof(shortLanguage), kCFStringEncodingMacRoman)) {
                    language = shortLanguage;
                }
            }
            if (f && language) {
                fprintf(f, "%s\n", language);
#if CREATE_LOG
                print_to_log_file("Adding language: %s\n", language);
#endif
            }
            // Remove all copies of this language from our list of supported languages
            // so we can get the next preferred language in order of priority
            for (k=CFArrayGetCount(supportedLanguages)-1; k>=0; --k) {
                if (CFStringCompare(aLanguage, (CFStringRef)CFArrayGetValueAtIndex(supportedLanguages, k), 0) == kCFCompareEqualTo) {
                    CFArrayRemoveValueAtIndex(supportedLanguages, k);
                }
            }

            // Since the original strings are English, no 
            // further translation is needed for language en.
            if (language) {
                if (!strcmp(language, "en")) {
                    fclose(f);
                    CFRelease(preferredLanguages);
                    preferredLanguages = NULL;
                    goto cleanup;
                }
            }
        }
        
        CFRelease(preferredLanguages);
        preferredLanguages = NULL;

    }

    if (f) {
        fprintf(f, "en\n");
        fclose(f);
    }

cleanup:
    CFArrayRemoveAllValues(supportedLanguages);
    CFRelease(supportedLanguages);
    supportedLanguages = NULL;
#if CREATE_LOG
    print_to_log_file("Exiting GetPreferredLanguages");
#endif
}
Esempio n. 15
0
/* static */ void
_BrowseReply(DNSServiceRef sdRef, DNSServiceFlags flags, uint32_t interfaceIndex,
			 DNSServiceErrorType errorCode, const char* serviceName, const char* regtype,
			 const char* replyDomain, void* context)
{
	__CFNetServiceBrowser* browser = context;
	CFNetServiceBrowserClientCallBack cb = NULL;
	CFStreamError error = {0, 0};
	void* info = NULL;
	CFNetServiceRef service = NULL;

	// Retain here to guarantee safety really after the trigger release,
	// but definitely before the callback.
	CFRetain(browser);

	// Lock the browser
	__CFSpinLock(&browser->_lock);

	// If the browse canceled, don't need to do any of this.
	if (browser->_browse) {

		// If there is an error, fold the browse.
		if (errorCode) {

			// Save the error
			browser->_error.error = _DNSServiceErrorToCFNetServiceError(errorCode);
			browser->_error.domain = kCFStreamErrorDomainNetServices;

			// Remove the browse from run loops and modes
			_CFTypeUnscheduleFromMultipleRunLoops(browser->_trigger, browser->_schedules);

			// Go ahead and invalidate the socket
			CFSocketInvalidate((CFSocketRef)(browser->_trigger));

			// Release the browse now.
			CFRelease(browser->_trigger);
			browser->_trigger = NULL;

			// Clean up the underlying service discovery stuff
			DNSServiceRefDeallocate(browser->_browse);
			browser->_browse = NULL;

			// Dump all the lists of items.
			CFDictionaryRemoveAllValues(browser->_found);
			CFArrayRemoveAllValues(browser->_adds);
			CFArrayRemoveAllValues(browser->_removes);
		}

		// If got service info from service discovery, create the CFNetServiceRef.
		else if (serviceName && regtype && replyDomain) {

			// Create CFString's for each of the service components
			CFAllocatorRef alloc = CFGetAllocator(browser);
			CFStringRef domain = CFStringCreateWithCString(alloc, replyDomain, kCFStringEncodingUTF8);
			CFStringRef type = CFStringCreateWithCString(alloc, regtype, kCFStringEncodingUTF8);
			CFStringRef name = CFStringCreateWithCString(alloc, serviceName, kCFStringEncodingUTF8);

			// Can only make the service if all the strings were created.  This
			// will skip over items that are not properly UTF8 encoded on the wire.
			if (domain && type && name)
				service = _CFNetServiceCreateCommon(alloc, domain, type, name, 0);

			if (domain) CFRelease(domain);
			if (type) CFRelease(type);
			if (name) CFRelease(name);

			if (service) {

				intptr_t count = (intptr_t)CFDictionaryGetValue(browser->_found, service);

				if (flags & kDNSServiceFlagsAdd) {

					count++;

					if (count != 1)
						CFDictionaryReplaceValue(browser->_found, service, (const void*)count);

					else {
						CFIndex i = CFArrayGetFirstIndexOfValue(browser->_removes,
																CFRangeMake(0, CFArrayGetCount(browser->_removes)),
																service);

						CFDictionaryAddValue(browser->_found, service, (const void*)count);
						CFArrayAppendValue(browser->_adds, service);

						if (i != kCFNotFound)
							CFArrayRemoveValueAtIndex(browser->_removes, i);
					}
				}

				else {

					count--;
					if (count > 0)
						CFDictionaryReplaceValue(browser->_found, service, (const void*)count);
					else {
						CFIndex i = CFArrayGetFirstIndexOfValue(browser->_adds,
																CFRangeMake(0, CFArrayGetCount(browser->_adds)),
																service);

						CFDictionaryRemoveValue(browser->_found, service);
						CFArrayAppendValue(browser->_removes, service);

						if (i != kCFNotFound)
							CFArrayRemoveValueAtIndex(browser->_adds, i);
					}
				}

				CFRelease(service);
			}
		}

		cb = browser->_callback;

		// Save the error and client information for the callback
		memmove(&error, &(browser->_error), sizeof(error));
		info = browser->_client.info;

	}

	// If there is a callback, inform the client of the error.
	if (cb && error.error) {

		// Unlock the browser so the callback can be made safely.
		__CFSpinUnlock(&browser->_lock);

		cb((CFNetServiceBrowserRef)browser, 0, NULL, &error, info);
	}

	else if (cb && ((flags & kDNSServiceFlagsMoreComing) == 0)) {

		CFIndex i, adds = CFArrayGetCount(browser->_adds);
		CFIndex removes = CFArrayGetCount(browser->_removes);
		CFIndex total = adds + removes;

		for (i = 0; i < adds; i++) {

			const void* saved = browser->_trigger;
			service = (CFNetServiceRef)CFArrayGetValueAtIndex(browser->_adds, i);

			// Unlock the browser so the callback can be made safely.
			__CFSpinUnlock(&browser->_lock);

			cb((CFNetServiceBrowserRef)browser,
			   (i == (total - 1)) ? 0 : kCFNetServiceFlagMoreComing,
			   service,
			   &error,
			   info);

			// Lock the browser
			__CFSpinLock(&browser->_lock);

			if (saved != browser->_trigger) {
				cb = NULL;
				break;
			}
		}

		if (cb) {
			for (i = 0; i < removes; i++) {

				const void* saved = browser->_trigger;
				service = (CFNetServiceRef)CFArrayGetValueAtIndex(browser->_removes, i);

				// Unlock the browser so the callback can be made safely.
				__CFSpinUnlock(&browser->_lock);

				cb((CFNetServiceBrowserRef)browser,
				   kCFNetServiceFlagRemove | ((i == (removes - 1)) ? 0 : kCFNetServiceFlagMoreComing),
				   service,
				   &error,
				   info);

				// Lock the browser
				__CFSpinLock(&browser->_lock);

				if (saved != browser->_trigger)
					break;
			}
		}

		// Dump the lists of items, so can start new again.
		CFArrayRemoveAllValues(browser->_adds);
		CFArrayRemoveAllValues(browser->_removes);

		// Unlock the browser so the callback can be made safely.
		__CFSpinUnlock(&browser->_lock);
	}
	else
		__CFSpinUnlock(&browser->_lock);

	// Go ahead and release now that the callback is done.
	CFRelease(browser);
}
Esempio n. 16
0
/* CF_EXPORT */ void
CFNetServiceBrowserStopSearch(CFNetServiceBrowserRef b, CFStreamError* error) {

	__CFNetServiceBrowser* browser = (__CFNetServiceBrowser*)b;

	// By default, the error is marked as a cancel
	CFStreamError extra = {kCFStreamErrorDomainNetServices , kCFNetServicesErrorCancel};

	// Make sure error has a value.
	if (!error)
		error = &extra;

	// Lock down the browser
	__CFSpinLock(&(browser->_lock));

	// Make sure there is something to cancel.
	if (browser->_trigger) {

		CFRunLoopSourceContext ctxt = {
			0,									// version
			browser,							// info
			NULL,								// retain
			NULL,								// release
			NULL,								// copyDescription
			NULL,								// equal
			NULL,								// hash
			NULL,								// schedule
			NULL,								// cancel
			(void(*)(void*))(&_BrowserCancel)  // perform
		};

		// Remove the trigger from run loops and modes
		_CFTypeUnscheduleFromMultipleRunLoops(browser->_trigger, browser->_schedules);

		// Go ahead and invalidate the trigger
		_CFTypeInvalidate(browser->_trigger);

		// Release the trigger now.
		CFRelease(browser->_trigger);

		// Need to clean up the service discovery stuff if there is
		if (browser->_browse) {

			// Release the underlying service discovery reference
			DNSServiceRefDeallocate(browser->_browse);
			browser->_browse = NULL;

			// Dump all the lists of items.
			CFDictionaryRemoveAllValues(browser->_found);
			CFArrayRemoveAllValues(browser->_adds);
			CFArrayRemoveAllValues(browser->_removes);
		}

		// Copy the error into place
		memmove(&(browser->_error), error, sizeof(error[0]));

		// Create the cancel source
		browser->_trigger = CFRunLoopSourceCreate(CFGetAllocator(browser), 0, &ctxt);

		// If the cancel was created, need to schedule and signal it.
		if (browser->_trigger) {

			CFArrayRef schedules = browser->_schedules;
			CFIndex i, count = CFArrayGetCount(schedules);

			// Schedule the new trigger
			_CFTypeScheduleOnMultipleRunLoops(browser->_trigger, schedules);

			// Signal the cancel for immediate attention.
			CFRunLoopSourceSignal((CFRunLoopSourceRef)(browser->_trigger));

			// Make sure the signal can make it through
			for (i = 0; i < count; i += 2) {

				// Grab the run loop for checking
				CFRunLoopRef runloop = (CFRunLoopRef)CFArrayGetValueAtIndex(schedules, i);

				// If it's sleeping, need to further check it.
				if (CFRunLoopIsWaiting(runloop)) {

					// Grab the mode for further check
					CFStringRef mode = CFRunLoopCopyCurrentMode(runloop);

					if (mode) {

						// If the trigger is in the right mode, need to wake up the run loop.
						if (CFRunLoopContainsSource(runloop, (CFRunLoopSourceRef)(browser->_trigger), mode)) {
							CFRunLoopWakeUp(runloop);
						}

						// Don't need this anymore.
						CFRelease(mode);
					}
				}
			}
		}
	}

	// Unlock the browser
	__CFSpinUnlock(&(browser->_lock));
}
Esempio n. 17
0
bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
                                          bool fixedWidthOnly)
{
     wxArrayString fontFamilies ;

    wxUint32 macEncoding = wxMacGetSystemEncFromFontEnc(encoding) ;

    {
        CFArrayRef cfFontFamilies = nil;

#if wxOSX_USE_COCOA_OR_CARBON
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6)
        if ( UMAGetSystemVersion() >= 0x1060 )
            cfFontFamilies = CTFontManagerCopyAvailableFontFamilyNames();
        else
#endif
        {
#if (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6)
            //
            // From Apple's QA 1471 http://developer.apple.com/qa/qa2006/qa1471.html
            //
            
            CFMutableArrayRef atsfontnames = CFArrayCreateMutable(kCFAllocatorDefault,0,&kCFTypeArrayCallBacks);;
            
            ATSFontFamilyIterator theFontFamilyIterator = NULL;
            ATSFontFamilyRef theATSFontFamilyRef = 0;
            OSStatus status = noErr;
            
            // Create the iterator
            status = ATSFontFamilyIteratorCreate(kATSFontContextLocal, nil,nil,
                                                 kATSOptionFlagsUnRestrictedScope,
                                                 &theFontFamilyIterator );
            
            while (status == noErr)
            {
                // Get the next font in the iteration.
                status = ATSFontFamilyIteratorNext( theFontFamilyIterator, &theATSFontFamilyRef );
                if(status == noErr)
                {
                    CFStringRef theName = NULL;
                    ATSFontFamilyGetName(theATSFontFamilyRef, kATSOptionFlagsDefault, &theName);
                    CFArrayAppendValue(atsfontnames, theName);
                    CFRelease(theName);
                    
                }
                else if (status == kATSIterationScopeModified) // Make sure the font database hasn't changed.
                {
                    // reset the iterator
                    status = ATSFontFamilyIteratorReset (kATSFontContextLocal, nil, nil,
                                                         kATSOptionFlagsUnRestrictedScope,
                                                         &theFontFamilyIterator);
                    CFArrayRemoveAllValues(atsfontnames);
                }
            }
            ATSFontFamilyIteratorRelease(&theFontFamilyIterator);
            cfFontFamilies = atsfontnames;
#endif
        }
#elif wxOSX_USE_IPHONE
        cfFontFamilies = CopyAvailableFontFamilyNames();
#endif
        
        CFIndex count = CFArrayGetCount(cfFontFamilies);
        for(CFIndex i = 0; i < count; i++)
        {
            CFStringRef fontName = (CFStringRef)CFArrayGetValueAtIndex(cfFontFamilies, i);

            if ( encoding != wxFONTENCODING_SYSTEM || fixedWidthOnly)
            {
                wxCFRef<CTFontRef> font(CTFontCreateWithName(fontName, 12.0, NULL));
                if ( encoding != wxFONTENCODING_SYSTEM )
                {
                    CFStringEncoding fontFamiliyEncoding = CTFontGetStringEncoding(font);
                    if ( fontFamiliyEncoding != macEncoding )
                        continue;
                }
                
                if ( fixedWidthOnly )
                {
                    CTFontSymbolicTraits traits = CTFontGetSymbolicTraits(font);
                    if ( (traits & kCTFontMonoSpaceTrait) == 0 )
                        continue;
                }
                
            }
            
            wxCFStringRef cfName(wxCFRetain(fontName)) ;
            fontFamilies.Add(cfName.AsString(wxLocale::GetSystemEncoding()));
        }
        
        CFRelease(cfFontFamilies);
    }
    for ( size_t i = 0 ; i < fontFamilies.Count() ; ++i )
    {
        if ( OnFacename( fontFamilies[i] ) == false )
            break ;
    }

    return true;
}
Esempio n. 18
0
XAErrorCode XAFileLoadAttributes(XAFileRef fileRef)
{
	XAErrorCode eCode = XAErrorImmaterial;
	
	CFIndex bSize = CFStringGetLength(fileRef->path) + 0x01;
	
	char *buffer = calloc(bSize, sizeof(*buffer));
	
	if(CFStringGetCString(fileRef->path, buffer, bSize, kCFStringEncodingUTF8))
	{
		int fd = open(buffer, O_RDONLY, 0x00);

		if(fd > 0x00)
		{
			char *keys = 0x00; size_t size = 0x00; int options = 0x00;
			
			CFArrayRemoveAllValues(fileRef->attributes);

			size = flistxattr(fd, keys, size, options);

			if(size > 0x00)
			{
				CFAllocatorRef allocator = CFGetAllocator(fileRef);
				
				char *key = 0x00;
				
				keys = calloc(size, sizeof(*keys));
				
				size = flistxattr(fd, keys, size, options);
				
				eCode = XAErrorNone;
				
				for(key = keys; key < keys + size; key += 0x01 + strlen(key))
				{
					XAAttributeRef attributeRef = 0x00;
					
					attributeRef = XAAttributeCreate(allocator);
					
					if(XAAttributeLoadFileDescriptor(attributeRef, fd, key))
					{
						CFArrayAppendValue(fileRef->attributes, attributeRef);	
						
						CFRelease(attributeRef);
					}else
					{
						CFRelease(attributeRef);

						eCode = XAErrorImmaterial;
						break;
					}
					
				}
				
			}else
			{
				eCode = XAErrorImmaterial;
				//fprintf(stderr, "listxattr error: %s\n", strerr(errno));
			}

			close(fd);

		}

	}
	fileRef->edited = 0x00;
	
	free(buffer);
	
	return(eCode);
}