launcher.c

Interaction with the launcher of a simple window manager.

/*
* $QNXLicenseC:
* Copyright 2012, QNX Software Systems Limited. All Rights Reserved.
*
* This software is QNX Confidential Information subject to
* confidentiality restrictions. DISCLOSURE OF THIS SOFTWARE
* IS PROHIBITED UNLESS AUTHORIZED BY QNX SOFTWARE SYSTEMS IN
* WRITING.
*
* You must obtain a written license from and pay applicable license
* fees to QNX Software Systems Limited before you may reproduce, modify
* or distribute this software, or any work that includes all or part
* of this software. For more information visit
* http://licensing.qnx.com or email licensing@qnx.com.
*
* This file may contain contributions from others.  Please review
* this entire file for other proprietary rights or license notices,
* as well as the QNX Development Suite License Guide at
* http://licensing.qnx.com/license-guide/ for other information.
* $
*/

#include "struct.h"

int
launcher_pps(window_manager_t *winmgr)
{
    char *msg, *dat, *res, *err, *pkg, *errstr;

    // There must be a msg and a dat attribute
    msg = pps_lookup(winmgr, "msg");
    res = pps_lookup(winmgr, "res");
    err = pps_lookup(winmgr, "err");
    dat = pps_lookup(winmgr, "dat");
    pkg = pps_lookup(winmgr, "id");
    errstr = pps_lookup(winmgr, "errstr");
    if((msg == NULL && res == NULL) || (dat == NULL && err == NULL))
        return EINVAL;

    if(winmgr->verbose) {
        if (msg)
            SLOG_NOTICE("launcher - msg:%s dat:%s", msg, dat);
        else
            SLOG_NOTICE("launcher - res:%s dat/err:%s", res, dat ? dat : err);
    }

    if (msg) {
        if (strcmp(msg, CMD_STOPPED) == 0) {
            core_app_stopped(winmgr, dat);
        } else
        if (strcmp(msg, CMD_LOWMEM) == 0) {
            core_lowmem(winmgr, dat);
        }
    } else {
        if (strcmp(res, CMD_START) == 0) {
            core_app_started(winmgr, pkg, dat ? dat : err, dat ? 0 : 1, errstr);
        }
        if (strcmp(res, CMD_DEBUG) == 0) {
            core_app_started(winmgr, pkg, dat ? dat : err, dat ? 0 : 1, errstr);
        }
    }
    return EOK;
}

void
launcher_send(window_manager_t *winmgr, char *cmd, char *data, char *id)
{
    int msgsize;
    char msgbuf[4096];

    if (strcmp(cmd, CMD_START) == 0 || strcmp(cmd, CMD_DEBUG) == 0) {
        msgsize = snprintf(msgbuf, sizeof(msgbuf), "msg::%s\ndat::%s\nid::%s", cmd, data, id);
    } else {
        msgsize = snprintf(msgbuf, sizeof(msgbuf), "msg::%s\ndat::%s", cmd, data);
    }
    if (winmgr->verbose)
        SLOG_NOTICE("launch send - msg:%s dat:%s id:%s", cmd, data ? data : "", id ? id : "");

    if (pps_write(winmgr->pps_fd, msgbuf, msgsize) == -1 ) {
        SLOG_NOTICE("unable to write to launcher fd: %s", strerror(errno));
    }
}