Пример #1
0
void
NativeStateDRM::flip()
{
    gbm_bo* next = gbm_surface_lock_front_buffer(surface_);
    fb_ = fb_get_from_bo(next);
    unsigned int waiting(1);

    if (!crtc_set_) {
        int status = drmModeSetCrtc(fd_, encoder_->crtc_id, fb_->fb_id, 0, 0,
                                    &connector_->connector_id, 1, mode_);
        if (status >= 0) {
            crtc_set_ = true;
            bo_ = next;
        }
        else {
            Log::error("Failed to set crtc: %d\n", status);
        }
        return;
    }

    int status = drmModePageFlip(fd_, encoder_->crtc_id, fb_->fb_id,
                                 DRM_MODE_PAGE_FLIP_EVENT, &waiting);
    if (status < 0) {
        Log::error("Failed to enqueue page flip: %d\n", status);
        return;
    }

    fd_set fds;
    FD_ZERO(&fds);
    FD_SET(fd_, &fds);
    drmEventContext evCtx;
    evCtx.version = DRM_EVENT_CONTEXT_VERSION;
    evCtx.page_flip_handler = page_flip_handler;

    while (waiting) {
        status = select(fd_ + 1, &fds, 0, 0, 0);
        if (status < 0) {
            // Most of the time, select() will return an error because the
            // user pressed Ctrl-C.  So, only print out a message in debug
            // mode, and just check for the likely condition and release
            // the current buffer object before getting out.
            Log::debug("Error in select\n");
            if (should_quit()) {
                gbm_surface_release_buffer(surface_, bo_);
                bo_ = next;
            }
            return;
        }
        drmHandleEvent(fd_, &evCtx);
    }

    gbm_surface_release_buffer(surface_, bo_);
    bo_ = next;
}
Пример #2
0
/*
 * n1
 *  Polls the user for the name of a file and a node.
 *  Sends the file character by character to the node via special FIFO-based protocol.
 */
int main(int argc, char *argv[])
{
    char *filename, *contents;
    long n_chars;
    int write_child;
    int node;
    packet p;

    do {
        // Get filename and node number from user.
        get_user_input(&filename, &node);

        // Get contents of file.
        n_chars = get_file_contents(filename, &contents);

        // Send file data to node.
        send_data(1, node, n_chars, contents);

        // Receive acknowledgement packet from node.
        recv_acknowledge(1, node);

        free(filename);
        free(contents);
    } while (!should_quit());

    // Send exit message to all child nodes.
    p.data = END_OF_TRANSMISSION;
    for (int i = NUM_NODES; i > 1; i--) {
        write_child = get_link(1, i, WRITE);
        p.dest = i;
        send_packet(write_child, p);
        close(write_child);

        recv_acknowledge(1, i);
    }
    return 0;
}