Example #1
2
/* initialise the plug-in */
static long VLCEyeTVPluginInitialize(VLCEyeTVPluginGlobals_t** globals, long apiVersion, EyeTVPluginCallbackProc callback)
{
    printf("VLC media player Plug-In: Initialize\n");
    long result = 0;
    
    /* init our own storage */
    i_deviceCount = 0;
    i_vlcSock = -1;
    
    /* notify a potential VLC instance about our initialisation */
    CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter(),
                                          CFSTR("PluginInit"), 
                                          CFSTR(VLC_NOTIFICATION_OBJECT), 
                                          /*userInfo*/ NULL, 
                                          TRUE );
    
    /* init our notification support */
    CFNotificationCenterAddObserver( CFNotificationCenterGetDistributedCenter(),
                                     /* observer */ NULL, 
                                     /* callBack */ VLCEyeTVPluginGlobalNotificationReceived,
                                     /* name, NULL==all */ NULL,
                                     CFSTR(VLC_NOTIFICATION_OBJECT), 
                                     CFNotificationSuspensionBehaviorDeliverImmediately );
    
    *globals = (VLCEyeTVPluginGlobals_t *) calloc(1, sizeof( VLCEyeTVPluginGlobals_t ) );
    ( *globals )->callback = callback;
        
    return result;
}
Example #2
0
cc_int32 ccs_os_notify_ccache_changed (ccs_cache_collection_t  io_cache_collection,
                                       const char             *in_ccache_name)
{
    cc_int32 err = ccNoError;

    if (!io_cache_collection) { err = cci_check_error (ccErrBadParam); }
    if (!in_ccache_name     ) { err = cci_check_error (ccErrBadParam); }

    if (!err) {
        CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter ();
        CFStringRef name = CFStringCreateWithCString (kCFAllocatorDefault,
                                                      in_ccache_name,
                                                      kCFStringEncodingUTF8);

        if (center && name) {
            CFNotificationCenterPostNotification (center,
                                                  kCCAPICCacheChangedNotification,
                                                  name, NULL, TRUE);
        }

        if (name) { CFRelease (name); }
    }

    return cci_check_error (err);
}
Example #3
0
/* called if a device is removed */
static long VLCEyeTVPluginDeviceRemoved(VLCEyeTVPluginGlobals_t *globals, EyeTVPluginDeviceID deviceID)
{
    printf("VLC media player Plug-In: DeviceRemoved\n");
    
    long result = 0;
        
    --i_deviceCount;
    if( 0 == i_deviceCount )
    {                
        /* notify a potential VLC instance about the removal */
        CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter(),
                                              CFSTR("DeviceRemoved"), 
                                              CFSTR(VLC_NOTIFICATION_OBJECT), 
                                              /*userInfo*/ NULL, 
                                              TRUE );
    }
    if( (i_vlcSock != -1) && (deviceID == globals->activeDeviceID) )
    {
        close(i_vlcSock);
        i_vlcSock = -1;
        printf( "data sending switched off\n" );
    }
    
    return result;
}
Example #4
0
void set_space_by_index(int space)
{
  
  CFNotificationCenterRef nc = CFNotificationCenterGetDistributedCenter();
  CFStringRef numstr = CFStringCreateWithFormat(NULL, nil, CFSTR("%d"), space);
  CFNotificationCenterPostNotification(nc, CFSTR("com.apple.switchSpaces"), numstr, NULL, TRUE);
}
Example #5
0
/* we will be terminated soon, clean up */
static long VLCEyeTVPluginTerminate(VLCEyeTVPluginGlobals_t *globals)
{
    long result = 0;
    
    printf("VLC media player Plug-In: Terminate\n");
    
    /* notify a potential VLC instance about our termination */
    CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (),
                                          CFSTR("PluginQuit"), 
                                          CFSTR(VLC_NOTIFICATION_OBJECT), 
                                          /*userInfo*/ NULL, 
                                          TRUE );
    
    /* remove us from the global notification centre */
    CFNotificationCenterRemoveEveryObserver( CFNotificationCenterGetDistributedCenter(),
                                             (void *)VLCEyeTVPluginGlobalNotificationReceived );
    
    /* close data connection */
    if( i_vlcSock != -1 )
    {
        close( i_vlcSock );
        i_vlcSock = -1;
    }
    
    free( globals );
    return result;
}
void SendSkypeCommand(CFStringRef command)
{
	if (delegate == NULL)
	{
		printf("Can't send message, no delegate set\n");
		return;
	}
	if (command == NULL)
		return;
	if (!client_id)
	{
		printf("Can't send message, not connected\n");
		return;
	}

	CFRetain(command);

	CFNumberRef id_number = CFNumberCreate(NULL, kCFNumberIntType, &client_id);
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
	const void *keys[] = {(void *)CFSTR("SKYPE_API_COMMAND"), (void *)CFSTR("SKYPE_API_CLIENT_ID")};
	const void *values[] = {command, id_number};
	CFDictionaryRef userInfo = CFDictionaryCreate(NULL, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);	
	
	//send message
	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPICommand"),
		NULL,
		userInfo,
		FALSE);
	
	CFRelease(command);
	CFRelease(id_number);
	CFRelease(userInfo);
}
Example #7
0
static void
post_notification(const osxfuse_notification_t  notification,
                  const char                   *dict[][2],
                  const int                     dict_count)
{
    CFNotificationCenterRef notification_center =
            CFNotificationCenterGetDistributedCenter();

    CFStringRef            name      = NULL;
    CFStringRef            object    = NULL;
    CFMutableDictionaryRef user_info = NULL;

    name   = CFStringCreateWithCString(kCFAllocatorDefault,
                                       osxfuse_notification_names[notification],
                                       kCFStringEncodingUTF8);
    object = CFStringCreateWithCString(kCFAllocatorDefault,
                                       osxfuse_notification_object,
                                       kCFStringEncodingUTF8);

    if (!name || !object) goto out;
    if (dict_count == 0)  goto post;

    user_info = CFDictionaryCreateMutable(kCFAllocatorDefault, dict_count,
                                          &kCFCopyStringDictionaryKeyCallBacks,
                                          &kCFTypeDictionaryValueCallBacks);

    CFStringRef key;
    CFStringRef value;
    int         i;
    for (i = 0; i < dict_count; i++) {
        key   = CFStringCreateWithCString(kCFAllocatorDefault, dict[i][0],
                                          kCFStringEncodingUTF8);
        value = CFStringCreateWithCString(kCFAllocatorDefault, dict[i][1],
                                          kCFStringEncodingUTF8);

        if (!key || !value) {
            if (key)   CFRelease(key);
            if (value) CFRelease(value);
            goto out;
        }

        CFDictionarySetValue(user_info, key, value);
        CFRelease(key); key = NULL;
        CFRelease(value); value = NULL;
    }

post:
    CFNotificationCenterPostNotification(notification_center, name, object,
                                         user_info, false);
out:
    if (name)      CFRelease(name);
    if (object)    CFRelease(object);
    if (user_info) CFRelease(user_info);
}
void refreshManager(void)
{
    CFStringRef observedObject = CFSTR("org.pureftpd.osx");
    CFNotificationCenterRef center =
        CFNotificationCenterGetDistributedCenter();
    CFNotificationCenterPostNotification(center,
                                         CFSTR("refreshStatus"),
                                         observedObject,
                                         NULL /* no dictionary */,
                                         TRUE);
}
void SendNotification(CFStringRef stockSymbol, double price) {
    CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
    CFNumberRef priceNum = CFNumberCreate(NULL, kCFNumberDoubleType, &price);
    CFMutableDictionaryRef stockInfoDict = CFDictionaryCreateMutable(NULL, 2,
        &kCFCopyStringDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

    CFDictionaryAddValue(stockInfoDict, CFSTR("Stock Symbol"), stockSymbol);
    CFDictionaryAddValue(stockInfoDict, CFSTR("New Price"), priceNum);
    CFRelease(priceNum);

    CFNotificationCenterPostNotification(center, CFSTR("Stock Price Changed Notification"), stockSymbol, stockInfoDict, FALSE);
    
    CFRelease(stockInfoDict);
}
int main(int argc, char **argv) {
 CFStringRef _key = ((CFStringRef) __builtin___CFStringMakeConstantString ("" "Process identifier" ""));
 int pid = 42;

 CFNumberRef _value = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &pid);
 CFDictionaryRef userInfo = CFDictionaryCreate(kCFAllocatorDefault, (const void **)&_key, (const void **)&_value, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 CFRelease(_value); // no-warning
 CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
           ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlPreferencesChanged" "")),
           ((CFStringRef) __builtin___CFStringMakeConstantString ("" "GrowlUserDefaults" "")),
           userInfo, 0);
 CFRelease(userInfo); // no-warning

 return 0;
}
Example #11
0
void shm_post_update(nmeaINFO* nmeaInfo, const char *buff, int buff_sz)
{	
	shm_append_ringbuf(buff, buff_sz);
	
	const int bestRatingResetTimeout = 3;
	
	static int lastSeenBestRatedSentence = 0;

	int currentRating = smask_rating(nmeaInfo->smask);
	
	static nmeaTIME lastTimestamp;
	
	// only do this for position sentences because 
	// sentences without embedded UTC get local device time
	// which will vary with each sentence
	
	if (currentRating > 0 && 
		0 != memcmp(&lastTimestamp, &nmeaInfo->utc, sizeof(nmeaTIME))) {
		lastTimestamp = nmeaInfo->utc;
		++lastSeenBestRatedSentence;
#ifdef DEBUG
		LogMsg("shm_post_update DEBUG: incrementing lastSeenBestRatedSentence to %u, current rating %u", 
			   lastSeenBestRatedSentence, currentRating);

#endif
	}

	static int bestRating = 0;

	if (lastSeenBestRatedSentence > bestRatingResetTimeout) {
		LogMsg("shm_post_update: resetting best rating (%u)", bestRating);
		bestRating = 0;
	}
	
	
	if (currentRating > bestRating) {
		bestRating = currentRating;
		LogMsg("shm_post_update: best rating set to (%u)", bestRating);
	}
	
	// always update shared mem to make it possible to show satellite positions before fix is available
	memcpy(&g_shm_info->nmeaInfo, nmeaInfo, sizeof(nmeaINFO));
	if (currentRating == bestRating && lastSeenBestRatedSentence != 0) {
		lastSeenBestRatedSentence = 0;
		CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), BtGpsNotificationName, nil, nil, TRUE);
	}
}
Example #12
0
// output a prompt (just a text string for this simple demo )
void Talk(string s, string curtag = string(""))
{
#ifdef __APPLE__
	CFStringRef text = CFStringCreateWithCString(NULL, s.c_str(), kCFStringEncodingUTF8);
	CFStringRef tag = CFStringCreateWithCString(NULL, curtag.c_str(), kCFStringEncodingUTF8);

	CFStringRef values[2] = { text, tag };
	CFStringRef keys[2] = { CFSTR("Text"), CFSTR("Tag") };

	CFDictionaryRef userInfo = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
	CFRelease(text);
	CFRelease(tag);

	CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), CFSTR("Talk"), NULL, userInfo, false);
	CFRelease(userInfo);
#endif
   printf("\n%s\n",s.c_str());
}
void
PA_DeviceControl::AnnounceDevice()
{
	CFMutableDictionaryRef userInfo = CFDictionaryCreateMutable(kCFAllocatorDefault, 1,
								    &kCFCopyStringDictionaryKeyCallBacks,
								    &kCFTypeDictionaryValueCallBacks);
	CFNumberRef number;
	CFStringRef str;
	PA_DeviceBackend *be = device->GetBackend();
	
	UInt32 n = getpid();
	number = CFNumberCreate(NULL, kCFNumberIntType, &n);
	CFDictionarySetValue(userInfo, CFSTR("pid"), number);
	CFRelease(number);
	
	CFDictionarySetValue(userInfo, CFSTR("procname"), be->GetProcessName());

	str = device->CopyDeviceName();
	CFDictionarySetValue(userInfo, CFSTR("audioDevice"), str);
	CFRelease(str);
	
	n = device->GetIOBufferFrameSize();
	number = CFNumberCreate(NULL, kCFNumberIntType, &n);
	CFDictionarySetValue(userInfo, CFSTR("IOBufferFrameSize"), number);
	CFRelease(number);

	CFStringRef serverName = be->GetHostName();
	CFDictionarySetValue(userInfo, CFSTR("serverName"), serverName);
	CFRelease(serverName);
	
	n = be->GetConnectionStatus();
	number = CFNumberCreate(NULL, kCFNumberIntType, &n);
	CFDictionarySetValue(userInfo, CFSTR("connectionStatus"), number);
	CFRelease(number);
	
	DebugLog();

	CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
					     CFSTR("announceDevice"),
					     LOCAL_OBJECT,
					     userInfo,
					     true);
	CFRelease(userInfo);
}
Example #14
0
cc_int32 ccs_os_notify_cache_collection_changed (ccs_cache_collection_t io_cache_collection)
{
    cc_int32 err = ccNoError;

    if (!io_cache_collection) { err = cci_check_error (ccErrBadParam); }

    if (!err) {
        CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter ();

        if (center) {
            CFNotificationCenterPostNotification (center,
                                                  kCCAPICacheCollectionChangedNotification,
                                                  NULL, NULL, TRUE);
        }
    }



    return cci_check_error (err);
}
int
IsSkypeAvailable(void)
{
	//is skype available?
	isavailable = 0;
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();

	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPIAvailabilityRequest"),
		NULL,
		NULL,
		TRUE);
	
	//Should only take 1 second or less to reply
	RunCurrentEventLoop(1);
	int avail = isavailable;
	isavailable = 0;
	return avail;
}
void
PA_DeviceControl::SignOffDevice()
{
	CFMutableDictionaryRef userInfo = CFDictionaryCreateMutable(kCFAllocatorDefault, 1,
								    &kCFCopyStringDictionaryKeyCallBacks,
								    &kCFTypeDictionaryValueCallBacks);
	CFNumberRef number;
	
	UInt32 pid = getpid();
	number = CFNumberCreate(NULL, kCFNumberIntType, &pid);
	CFDictionarySetValue(userInfo, CFSTR("pid"), number);
	CFRelease(number);
	
	CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
					     CFSTR("signOffDevice"),
					     LOCAL_OBJECT,
					     userInfo,
					     true);
	CFRelease(userInfo);
}
Example #17
0
/* called if a device is added */
static long VLCEyeTVPluginDeviceAdded(VLCEyeTVPluginGlobals_t *globals, EyeTVPluginDeviceID deviceID, EyeTVPluginDeviceType deviceType)
{
    printf("VLC media player Plug-In: Device with type %i and ID %i added\n", (int)deviceType, (int)deviceID);
    
    long result = 0;
    
    if( globals ) 
    {
        ++i_deviceCount;
        if( 1 == i_deviceCount )
        {                
            /* notify a potential VLC instance about the addition */
            CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter(),
                                                  CFSTR("DeviceAdded"), 
                                                  CFSTR(VLC_NOTIFICATION_OBJECT), 
                                                  /*userInfo*/ NULL, 
                                                  TRUE );
        }
    }
    return result;
}
void DisconnectFromSkype(void)
{
	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
		
	if (client_id)
	{
		CFNumberRef id_number = CFNumberCreate(NULL, kCFNumberIntType, &client_id);
		const void *keys[] = {(void *)CFSTR("SKYPE_API_CLIENT_ID")};
		const void *values[] = {id_number};
		CFDictionaryRef userInfo = CFDictionaryCreate(NULL, keys, values, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);	
	
		//disconnect
		CFNotificationCenterPostNotification(
			center,
			CFSTR("SKSkypeAPIDetachRequest"),
			NULL,
			userInfo,
			FALSE);
			
		client_id = 0;
	}
}
Example #19
0
// output a packet and return its sequence number
void ARec::OutPacket(PhraseType k, string wrd, string tag,
                     int pred, int alt, float ac, float lm, float score,
                     float confidence, float nact, HTime start, HTime end)
{
   OutMarkers(start);
   ++outseqnum;
   APhraseData *pd = (APhraseData *)new APhraseData(k,outseqnum,pred);
   pd->alt = alt; pd->ac = ac; pd->lm = lm; pd->score = score;
   pd->confidence = confidence;
   pd->word = wrd;  pd->tag = tag; pd->nact = nact;
   APacket p(pd);
   p.SetStartTime(start); p.SetEndTime(end);
   out->PutPacket(p);
   if (showRD) DrawOutLine(k,start,wrd,tag);
   if (trace&T_OUT) p.Show();
	
#ifdef __APPLE__
	CFMutableDictionaryRef userInfo = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);

	CFNumberRef cfPhraseType = CFNumberCreate(NULL, kCFNumberIntType, &k);
	CFDictionaryAddValue(userInfo, CFSTR("PhraseType"), cfPhraseType);
	CFRelease(cfPhraseType);
	
	CFStringRef cfWord = CFStringCreateWithCString(NULL, wrd.c_str(), kCFStringEncodingUTF8);
	CFDictionaryAddValue(userInfo, CFSTR("Word"), cfWord);
	CFRelease(cfWord);
	
	CFStringRef cfTag = CFStringCreateWithCString(NULL, tag.c_str(), kCFStringEncodingUTF8);
	CFDictionaryAddValue(userInfo, CFSTR("Tag"), cfTag);
	CFRelease(cfTag);
	
	CFNotificationCenterPostNotification(CFNotificationCenterGetLocalCenter(), CFSTR("ARec::OutPacket"), NULL, userInfo, false);
	
	CFRelease(userInfo);
#endif

}
void
ConnectToSkype(void)
{
	if (!delegate || !delegate->clientApplicationName)
	{
		printf("Error: Delegate not set\n");
		return;
	}
	
	if (!IsSkypeAvailable())
	{
		printf("Error: Skype not available\n");
	}

	CFNotificationCenterRef center = CFNotificationCenterGetDistributedCenter();
			
	//do the connect
	CFNotificationCenterPostNotification(
		center,
		CFSTR("SKSkypeAPIAttachRequest"),
		delegate->clientApplicationName,
		NULL,
		TRUE);
}
Example #21
0
static PyObject * growl_PostDictionary(CFStringRef name, PyObject *self, PyObject *args) {
	int i, j;

	PyObject *inputDict;
	PyObject *pKeys = NULL;
	PyObject *pKey, *pValue;

	CFMutableDictionaryRef note = CFDictionaryCreateMutable(kCFAllocatorDefault,
															/*capacity*/ 0,
															&kCFTypeDictionaryKeyCallBacks,
															&kCFTypeDictionaryValueCallBacks);

	if (!PyArg_ParseTuple(args, "O!", &PyDict_Type, &inputDict))
		goto error;

	pKeys = PyDict_Keys(inputDict);
	for (i = 0; i < PyList_Size(pKeys); ++i) {
		CFStringRef convertedKey;

		/* Converting the PyDict key to NSString and used for key in note */
		pKey = PyList_GetItem(pKeys, i);
		if (!pKey)
			// Exception already set
			goto error;
		pValue = PyDict_GetItem(inputDict, pKey);
		if (!pValue) {
			// XXX Neeed a real Error message here.
			PyErr_SetString(PyExc_TypeError," ");
			goto error;
		}
		if (PyUnicode_Check(pKey)) {
			convertedKey = CFStringCreateWithBytes(kCFAllocatorDefault,
												   (const UInt8 *)PyUnicode_AS_DATA(pKey),
												   PyUnicode_GET_DATA_SIZE(pKey),
												   kCFStringEncodingUnicode,
												   false);
		} else if (PyString_Check(pKey)) {
			convertedKey = CFStringCreateWithCString(kCFAllocatorDefault,
													 PyString_AsString(pKey),
													 kCFStringEncodingUTF8);
		} else {
			PyErr_SetString(PyExc_TypeError,"The Dict keys must be strings/unicode");
			goto error;
		}

		/* Converting the PyDict value to NSString or NSData based on class  */
		if (PyString_Check(pValue)) {
			CFStringRef convertedValue = CFStringCreateWithCString(kCFAllocatorDefault,
																   PyString_AS_STRING(pValue),
																   kCFStringEncodingUTF8);
			CFDictionarySetValue(note, convertedKey, convertedValue);
			CFRelease(convertedValue);
		} else if (PyUnicode_Check(pValue)) {
			CFStringRef convertedValue = CFStringCreateWithBytes(kCFAllocatorDefault,
																 (const UInt8 *)PyUnicode_AS_DATA(pValue),
																 PyUnicode_GET_DATA_SIZE(pValue),
																 kCFStringEncodingUnicode,
																 false);
			CFDictionarySetValue(note, convertedKey, convertedValue);
			CFRelease(convertedValue);
		} else if (PyInt_Check(pValue)) {
			long v = PyInt_AS_LONG(pValue);
			CFNumberRef convertedValue = CFNumberCreate(kCFAllocatorDefault,
														kCFNumberLongType,
														&v);
			CFDictionarySetValue(note, convertedKey, convertedValue);
			CFRelease(convertedValue);
		} else if (pValue == Py_None) {
			CFDataRef convertedValue = CFDataCreate(kCFAllocatorDefault, NULL, 0);
			CFDictionarySetValue(note, convertedKey, convertedValue);
			CFRelease(convertedValue);
		} else if (PyList_Check(pValue)) {
			int size = PyList_Size(pValue);
			CFMutableArrayRef listHolder = CFArrayCreateMutable(kCFAllocatorDefault,
																size,
																&kCFTypeArrayCallBacks);
			for (j = 0; j < size; ++j) {
				PyObject *lValue = PyList_GetItem(pValue, j);
				if (PyString_Check(lValue)) {
					CFStringRef convertedValue = CFStringCreateWithCString(kCFAllocatorDefault,
																		   PyString_AS_STRING(lValue),
																		   kCFStringEncodingUTF8);
					CFArrayAppendValue(listHolder, convertedValue);
					CFRelease(convertedValue);
				} else if (PyUnicode_Check(lValue)) {
					CFStringRef convertedValue = CFStringCreateWithBytes(kCFAllocatorDefault,
																		 (const UInt8 *)PyUnicode_AS_DATA(lValue),
																		 PyUnicode_GET_DATA_SIZE(lValue),
																		 kCFStringEncodingUnicode,
																		 false);
					CFArrayAppendValue(listHolder, convertedValue);
					CFRelease(convertedValue);
				} else {
					CFRelease(convertedKey);
					PyErr_SetString(PyExc_TypeError,"The lists must only contain strings");
					goto error;
				}
			}
			CFDictionarySetValue(note, convertedKey, listHolder);
			CFRelease(listHolder);
		} else if (PyObject_HasAttrString(pValue, "rawImageData")) {
			PyObject *lValue = PyObject_GetAttrString(pValue, "rawImageData");
			if (!lValue) {
				goto error;
			} else if (PyString_Check(lValue)) {
				CFDataRef convertedValue = CFDataCreate(kCFAllocatorDefault,
														(const UInt8 *)PyString_AsString(lValue),
														PyString_Size(lValue));
				CFDictionarySetValue(note, convertedKey, convertedValue);
				CFRelease(convertedValue);
			} else {
				CFRelease(convertedKey);
				PyErr_SetString(PyExc_TypeError, "Icon with rawImageData attribute present must ensure it is a string.");
				goto error;
			}
		} else {
			CFRelease(convertedKey);
			PyErr_SetString(PyExc_TypeError, "Value is not of Str/List");
			goto error;
		}
		CFRelease(convertedKey);
	}

	Py_BEGIN_ALLOW_THREADS
	CFNotificationCenterPostNotification(CFNotificationCenterGetDistributedCenter(),
										 /*name*/ name,
										 /*object*/ NULL,
										 /*userInfo*/ note,
										 /*deliverImmediately*/ false);
	CFRelease(note);
	Py_END_ALLOW_THREADS

	Py_DECREF(pKeys);

	Py_INCREF(Py_None);
	return Py_None;

error:
	CFRelease(note);

	Py_XDECREF(pKeys);

	return NULL;
}
Example #22
0
/* called if we received a global notification */
void VLCEyeTVPluginGlobalNotificationReceived( CFNotificationCenterRef center, 
                                              void *observer, 
                                              CFStringRef name, 
                                              const void *object, 
                                              CFDictionaryRef userInfo )
{
    /* when VLC launches after us, we need to inform it about our existance and the current state of available devices */
    if( CFStringCompare( name, CFSTR( "VLCOSXGUIInit" ), 0) == kCFCompareEqualTo )
    {
        /* we're here */
        CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (),
                                              CFSTR("PluginInit"), 
                                              CFSTR(VLC_NOTIFICATION_OBJECT), 
                                              /*userInfo*/ NULL, 
                                              TRUE );
        if( i_deviceCount > 0 )
        {
            /* at least one device is apparently connected */
            CFNotificationCenterPostNotification( CFNotificationCenterGetDistributedCenter (),
                                                  CFSTR("DeviceAdded"), 
                                                  CFSTR(VLC_NOTIFICATION_OBJECT), 
                                                  /*userInfo*/ NULL, 
                                                  TRUE );
        }
    }
    
    /* VLC wants us to start sending data */
    if( CFStringCompare( name, CFSTR( "VLCAccessStartDataSending" ), 0) == kCFCompareEqualTo )
    {
        if( i_vlcSock == -1 )
        {
            int peerSock;
         
            /* set-up data socket */
            peerSock = socket(AF_UNIX, SOCK_STREAM, 0);
            if( peerSock != -1 )
            {
                struct sockaddr_un peerAddr;
                /* set-up connection address */
                memset(&peerAddr, 0, sizeof(peerAddr));
                peerAddr.sun_family = AF_UNIX;
                strncpy(peerAddr.sun_path, "/tmp/.vlc-eyetv-bridge", sizeof(peerAddr.sun_path)-1);
                
                /* connect */
                printf("data connect in progess...\n");
                if( connect(peerSock, (struct sockaddr *)&peerAddr, sizeof(struct sockaddr_un)) != -1 )
                {
                    printf("data sending switched on\n");
					
                    i_vlcSock = peerSock;
                }
                else
                    printf("connect data socket failed (errno=%d)\n", errno );
            }
            else
                printf("create data socket failed (errno=%d)\n", errno );
        }
    }
    
    /* VLC wants us to stop sending data */
    if( CFStringCompare( name, CFSTR( "VLCAccessStopDataSending" ), 0) == kCFCompareEqualTo )
    {
        if( i_vlcSock != -1 )
        {
            close( i_vlcSock );
            i_vlcSock = -1;
            printf( "data sending switched off\n" );
        }
    }
}
Example #23
0
static int
post_notification(char   *name,
                  char   *udata_keys[],
                  char   *udata_values[],
                  CFIndex nf_num)
{
    CFIndex i;
    CFStringRef nf_name   = NULL;
    CFStringRef nf_object = NULL;
    CFMutableDictionaryRef nf_udata  = NULL;

    CFNotificationCenterRef distributedCenter;
    CFStringEncoding encoding = kCFStringEncodingUTF8;

    distributedCenter = CFNotificationCenterGetDistributedCenter();

    if (!distributedCenter) {
        return -1;
    }

    nf_name = CFStringCreateWithCString(kCFAllocatorDefault, name, encoding);
      
    nf_object = CFStringCreateWithCString(kCFAllocatorDefault,
                                          LIBFUSE_UNOTIFICATIONS_OBJECT,
                                          encoding);
 
    nf_udata = CFDictionaryCreateMutable(kCFAllocatorDefault,
                                         nf_num,
                                         &kCFCopyStringDictionaryKeyCallBacks,
                                         &kCFTypeDictionaryValueCallBacks);

    if (!nf_name || !nf_object || !nf_udata) {
        goto out;
    }

    for (i = 0; i < nf_num; i++) {
        CFStringRef a_key = CFStringCreateWithCString(kCFAllocatorDefault,
                                                      udata_keys[i],
                                                      kCFStringEncodingUTF8);
        CFStringRef a_value = CFStringCreateWithCString(kCFAllocatorDefault,
                                                        udata_values[i],
                                                        kCFStringEncodingUTF8);
        CFDictionarySetValue(nf_udata, a_key, a_value);
        CFRelease(a_key);
        CFRelease(a_value);
    }

    CFNotificationCenterPostNotification(distributedCenter,
                                         nf_name, nf_object, nf_udata, false);

out:
    if (nf_name) {
        CFRelease(nf_name);
    }

    if (nf_object) {
        CFRelease(nf_object);
    }

    if (nf_udata) {
        CFRelease(nf_udata);
    }

    return 0;
}