私はCforthe Mac(Leopard)で、電源通知の受信時にスリープ、ウェイクアップ、シャットダウン、再起動などの作業を行う必要のあるアプリケーションを作成しています。launchd
ログイン時にlaunchagentとして実行され、通知の監視を開始します。これを行うために使用しているコードは次のとおりです。
/* 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
)の上位2つだけが呼び出されます。再起動またはシャットダウン(kIOMessageSystemWillRestart
およびkIOMessageSystemWillPowerOff
)の通知を受け取ることはありません。
私は何か間違ったことをしていますか?または、再起動とシャットダウンの通知を受け取る別のAPIはありますか?私はそれをCプログラムとして保持したいと思います(それは私が精通しているものです)が、代替案の賢明な提案を受け入れます(私はログイン/ログアウトフックを見てきましたが、これらは非推奨になっているようです起動の)。
ヘルプ/ヒントを事前に感謝します!