Пример #1
0
static void InitWorkerSignals() {
    struct sigaction act, oact;
    int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, signal_pipefd);
    SetNonBlocking(signal_pipefd[1]);
    assert(ret != -1);

    evCreateIOEvent(worker->poll, signal_pipefd[0], EV_READABLE, WorkerSignalHandler, NULL);

    SignalRegister(SIGCHLD, DispatchSignal, 1);
    SignalRegister(SIGTERM, DispatchSignal, 1);
    SignalRegister(SIGINT, DispatchSignal, 1);
    SignalRegister(SIGPIPE, SIG_IGN, 1)
}
Пример #2
0
/** 
* @brief Register a callback for suspended notification when
*        the device goes to sleep. There is no guarantee you will
*        receive this message before the system has gone alseep.
*
*        If you want a message before the system has gone alseep,
*        see PowerdSuspendRequestRegister() or late state
*        PowerdPrepareSuspendRegister().
* 
* @param  callback_function 
*/
void
PowerdSuspendedRegister(PowerdCallback callback_function)
{
    static CBH_INIT(helper);

    helper.callback = (void*)callback_function;

    if (helper.token)
    {
        SignalCancel(&helper);
    }

    SignalRegister("suspended", ClientNoParamCallback, &helper);
}
Пример #3
0
/** 
* @brief Register a callback for battery status notifications.
* 
* @param  callback_function 
* Callback is called with the following parameters:
* callback(percent, temperature, current, voltage);
*/
void
PowerdBatteryStatusRegister(PowerdCallback_Int32_4 callback_function)
{
    static CBH_INIT(helper);

    if (helper.token)
    {
        SignalCancel(&helper);
    }

    helper.callback = (void*)callback_function;

    SignalRegister("batteryStatus", _ClientBatteryStatusCallback, &helper);
}
Пример #4
0
/** 
* @brief User API to register a callback for 'prepareSuspend'
*        notification.
* 
* @param  callback_function 
*/
void
PowerdPrepareSuspendRegister(PowerdCallback callback_function)
{
    static CBH_INIT(helper);
    PowerdHandle *handle = PowerdGetHandle();

    helper.callback = (void*)callback_function;
    
    if (helper.token)
    {
        SignalCancel(&helper);
    }

    if (callback_function)
    {
        SignalRegister("prepareSuspend", ClientNoParamCallback, &helper);

        handle->prepareSuspendRegistered = true;
    }
    else
    {
        handle->prepareSuspendRegistered = false;
    }

    PowerdClientLock(handle);

    char *message = g_strdup_printf(
            "{\"register\":%s,\"clientId\":\"%s\"}",
            handle->prepareSuspendRegistered ? "true" : "false",
            handle->clientId ?: "(null)");

    PowerdClientUnlock(handle);

    SendMessage(NULL, "luna://" POWERD_IPC_NAME POWERD_DEFAULT_CATEGORY
            "prepareSuspendRegister", message);

    g_free(message);
}
Пример #5
0
BOOL TOOLHELPAPI NotifyRegister(
    HANDLE hTask,
    LPFNNOTIFYCALLBACK lpfn,
    WORD wFlags)
{
    NOTIFYSTRUCT *pInfo;
    NOTIFYSTRUCT *pTemp;

    /* Make sure TOOLHELP.DLL is installed */
    if (!wLibInstalled)
        return FALSE;

    /* If the notification hook has not yet been installed, install it */
    if (!wNotifyInstalled)
    {
        /* Make sure we can get a hook! */
        if (!NotifyInit())
            return FALSE;
        wNotifyInstalled = TRUE;
    }

    /* NULL hTask means current task */
    if (!hTask)
        hTask = GetCurrentTask();

    /* Register a death signal handler for this task (does nothing if one
     *  is already installed.
     */
    SignalRegister(hTask);

    /* Check to see if this task is already registered */
    for (pInfo = npNotifyHead ; pInfo ; pInfo = pInfo->pNext)
        if (pInfo->hTask == hTask)
            return FALSE;

    /* Allocate a new NOTIFYSTRUCT structure */
    pInfo = (NOTIFYSTRUCT *)LocalAlloc(LMEM_FIXED, sizeof (NOTIFYSTRUCT));
    if (!pInfo)
        return FALSE;

    /* Fill in the useful fields */
    pInfo->hTask = hTask;
    pInfo->wFlags = wFlags;
    pInfo->lpfn = lpfn;

    /* If this is the only handler, just insert it */
    if (!npNotifyHead)
    {
        pInfo->pNext = npNotifyHead;
        npNotifyHead = pInfo;
    }

    /* Otherwise, insert at the end of the list */
    else
    {
        for (pTemp = npNotifyHead ; pTemp->pNext ; pTemp = pTemp->pNext)
            ;
        pInfo->pNext = pTemp->pNext;
        pTemp->pNext = pInfo;
    }

    return TRUE;
}