Receive CFMessagePortSendRequest notifications
Guillaume CERQUANT
gcerquant at gmail.com
Mon Oct 22 11:01:43 PDT 2007
Hello,
I found that you can notify the screensaver to re-read the values of
~/Library/com.apple.screensaver.plist with this code:
CFMessagePortRef port = CFMessagePortCreateRemote(NULL, CFSTR
("com.apple.loginwindow.notify"));
CFMessagePortSendRequest(port, 500, 0, 0, 0, 0, 0);
CFRelease(port);
This part works as expected: the screensaver read the new settings.
I'm now trying to subscribe to the notifications, in case the values
change not due to my program and a notification is sent.
Eg, if the user change the setting via System Preferences.app, I want
to catch the notification sent by System Preferences.app.
I tried this:
static CFDataRef *consoleMessage(CFMessagePortRef local, SInt32
priority, CFDataRef data, void *info) {
fprintf(stderr, "consoleMessage priority = %ld\n", priority);
return NULL;
}
- (id)init
{
CFMessagePortContext context;
context.version = 0;
context.info = self;
context.retain = 0;
context.release = 0;
context.copyDescription = 0;
CFMessagePortRef port = CFMessagePortCreateLocal(NULL,
kConsoleMessagePort, (CFMessagePortCallBack)&consoleMessage,
&context, NULL);
CFRunLoopSourceRef rls = CFMessagePortCreateRunLoopSource(NULL,
port, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), rls, kCFRunLoopDefaultMode);
CFRelease(rls);
self = [super init];
return self;
}
It doesn't work. Here is the log:
2007-10-22 19:19:22.559 SystemUIServer[22311] CFLog (0):
CFMessagePort: bootstrap_register(): failed 1103 (0x44f), port =
0x6403, name = 'com.apple.loginwindow.notify'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2007-10-22 19:19:22.563 SystemUIServer[22311] CFLog (99):
CFMessagePortCreateLocal(): failed to name Mach port
(com.apple.loginwindow.notify)
From what I understand, the service is already active and can't be
open twice.
That seems normal, as the port is already open and used to receive
the notifications by the screensaver engine (or whatever take care of
this).
How can I receive the notifications too?
I hope I'm being clear about my problem. Let me know if not.
Thank you for your time and help. It is appreciated.
--
Guillaume Cerquant
gcerquant at gmail.com
More information about the MacOSX-dev
mailing list