Mac 용 C (Leopard)의 전원 알림 수신과 관련하여 작업해야하는 응용 프로그램을 작성 중입니다. sleep, wake-up, shutdown, restart. 로그인시 launchagent로 launchd
을 실행 한 다음 알림 모니터링을 시작합니다.Mac OSX에서 전원 알림 수신 (특히 종료)
/* ask for power notifications */
static void StartPowerNotification(void)
{
static io_connect_t rootPort;
IONotificationPortRef notificationPort;
io_object_t notifier;
rootPort = IORegisterForSystemPower(&rootPort, ¬ificationPort,
PowerCallback, ¬ifier);
if (!rootPort)
exit (1);
CFRunLoopAddSource (CFRunLoopGetCurrent(),
IONotificationPortGetRunLoopSource(notificationPort),
kCFRunLoopDefaultMode);
}
/* perform actions on receipt of power notifications */
void PowerCallback (void *rootPort, io_service_t y,
natural_t msgType, void *msgArgument)
{
switch (msgType)
{
case kIOMessageSystemWillSleep:
/* perform sleep actions */
break;
case kIOMessageSystemHasPoweredOn:
/* perform wakeup actions */
break;
case kIOMessageSystemWillRestart:
/* perform restart actions */
break;
case kIOMessageSystemWillPowerOff:
/* perform shutdown actions */
break;
}
}
그러나, 휴면 (kIOMessageSystemWillSleep
및 kIOMessageSystemHasPoweredOn
)의 최고 두 이제까지가 호출되는 다음과 같이 내가이 일을 사용하고 코드입니다. 재시작 또는 종료 (kIOMessageSystemWillRestart
및 kIOMessageSystemWillPowerOff
)에 대한 알림을받지 못했습니다.
내가 잘못 했나요? 또는 다시 시작 및 종료 알림을 제공하는 또 다른 API가 있습니까? 나는 C 프로그램으로 유지하고 싶다. (내가 익숙한 것으로서) 그러나 대안의 현명한 제안에 개방되어있다. (로그인/로그 아웃 훅을 살펴 보았다.하지만 이것들은 더 이상 사용되지 않을 것으로 보인다. 발사의).
미리 도움 주시면 감사하겠습니다.
감사합니다. 이러한 알림을 수신하기 위해 창이나 도킹 아이콘이 필요한지 알고 있습니까? – binarybob
아니요, 그렇지 않습니다. 몇 가지 샘플 코드를 추가했습니다. –
다시 한번 감사드립니다. Rob, 많이 고맙습니다. – binarybob