Beispiel #1
0
enum protoCmd rx_request(struct protocol *req, int fd)
{
    struct item  *item;

    // Upgrade version 1 and 2 to  version 3
    if (req->ver == 1) {
        strcpy(req->xmlname, "default");
    } 
    if (req->ver < 3) {
        strcpy(req->mimetype,"image/png"); 
        strcpy(req->options,"");
    } else if (req->ver != 3) {
        syslog(LOG_ERR, "Bad protocol version %d", req->ver);
        return cmdNotDone;
    }

    syslog(LOG_DEBUG, "DEBUG: Got command %s fd(%d) xml(%s), z(%d), x(%d), y(%d), mime(%s), options(%s)",
           cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y, req->mimetype, req->options);

    if ((req->cmd != cmdRender) && (req->cmd != cmdRenderPrio) && (req->cmd != cmdRenderLow) && (req->cmd != cmdDirty) && (req->cmd != cmdRenderBulk)) {
        syslog(LOG_WARNING, "WARNING: Ignoring unknown command %s fd(%d) xml(%s), z(%d), x(%d), y(%d)",
                    cmdStr(req->cmd), fd, req->xmlname, req->z, req->x, req->y);
        return cmdNotDone;
    }

    item = (struct item *)malloc(sizeof(*item));
    if (!item) {
            syslog(LOG_ERR, "malloc failed");
            return cmdNotDone;
    }

    item->req = *req;
    item->duplicates = NULL;
    item->fd = (req->cmd == cmdDirty) ? FD_INVALID : fd;

#ifdef METATILE
    /* Round down request co-ordinates to the neareast N (should be a power of 2)
     * Note: request path is no longer consistent but this will be recalculated
     * when the metatile is being rendered.
     */
    item->mx = item->req.x & ~(METATILE-1);
    item->my = item->req.y & ~(METATILE-1);
#else
    item->mx = item->req.x;
    item->my = item->req.y;
#endif

    return request_queue_add_request(render_request_queue, item);
}
void *addition_thread(void * arg) {
    struct request_queue * queue = (struct request_queue *)arg;
    struct item * item;
    enum protoCmd res;
    struct timespec time;
    unsigned int seed = syscall(SYS_gettid);
    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &time);
    seed *= (unsigned int)time.tv_nsec;

    for (int i = 0; i < NO_QUEUE_REQUESTS; i++) {
        item = init_render_request(cmdDirty);
        item->mx = rand_r(&seed);
        res = request_queue_add_request(queue, item);
    }
}