Exemplo n.º 1
0
int close(int fd) {
    rp_t rp = fd_rp(fd);

    if (!rp) {
        // is not valid file descriptor
        return -1;
    }

    if (fd_mode(fd) & ACCS_EVENT) {
        // stop listening to events
        free(rcall(rp, fd_getkey(fd, AC_EVENT), "un-listen"));
    }

    if (fd_mode(fd) & ACCS_WRITE) {
        // finish writing
        free(rcall(rp, fd_getkey(fd, AC_WRITE), "finish"));
    }

    // clear file descriptor entry
    return fd_set(fd, rp, 0);
}
Exemplo n.º 2
0
int close(int fd) {
	int mode = fd_mode(fd);
	rp_t rp  = fd_rp(fd);

	if (!rp) {
		// is not valid file descriptor
		return -1;
	}

	if (rp_clrstat(rp, mode)) {
		// could not close connection
		return -1;
	}

	// clear file descriptor entry
	return fd_set(fd, rp, 0);
}
Exemplo n.º 3
0
void setKeyboardValues() {
    QFile fd_brightness("/sys/devices/platform/clevo_xsm_wmi/kb_brightness");
    if(fd_brightness.open(QIODevice::WriteOnly | QIODevice::Text) && keyboard_settings.brightness >= 0) {
        QTextStream out(&fd_brightness);
        out << keyboard_settings.brightness;
        fd_brightness.close();
    } else {
        std::cerr << "[clevo-xsm-wmi] Failed to set brightness" << std::endl;
    }
    QFile fd_mode("/sys/devices/platform/clevo_xsm_wmi/kb_mode");
    if(fd_mode.open(QIODevice::WriteOnly | QIODevice::Text) && keyboard_settings.mode >= 0) {
        QTextStream out(&fd_mode);
        out << keyboard_settings.mode;
        fd_mode.close();
    } else {
        std::cerr << "[clevo-xsm-wmi] Failed to set mode" << std::endl;
    }
    QFile fd_color("/sys/devices/platform/clevo_xsm_wmi/kb_color");
    if(fd_color.open(QIODevice::WriteOnly | QIODevice::Text) && keyboard_settings.color_left >= 0) {
        QTextStream out(&fd_color);
        out << kb_colors[keyboard_settings.color_left].name
            << " " << kb_colors[keyboard_settings.color_center].name
            << " " << kb_colors[keyboard_settings.color_right].name
            << " " << kb_colors[keyboard_settings.color_extra].name;
        fd_color.close();
    } else {
        std::cerr << "[clevo-xsm-wmi] Failed to set colour" << std::endl;
    }
    QFile fd_state("/sys/devices/platform/clevo_xsm_wmi/kb_state");
    if(fd_state.open(QIODevice::WriteOnly | QIODevice::Text) && keyboard_settings.state >= 0) {
        QTextStream out(&fd_state);
        out << keyboard_settings.state;
        fd_state.close();
    } else {
        std::cerr << "[clevo-xsm-wmi] Failed to set state" << std::endl;
    }
}
Exemplo n.º 4
0
void readKeyboardValues() {
    /* Brightness */
    QFile fd_brightness("/sys/devices/platform/clevo_xsm_wmi/kb_brightness");
    if(fd_brightness.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QByteArray line = fd_brightness.readAll();
        int value = line.at(0) - 48;
        if(value == 1) {
            if((line.at(1) - 48) == 0)
                value = 10;
        }
        if(value >= 0 && value <= 10)
            keyboard_settings.brightness = value;
        else
            keyboard_settings.brightness = 0;
        fd_brightness.close();
    } else {
        keyboard_settings.brightness = -1;
        std::cerr << "[clevo-xsm-wmi] Failed to read brightness" << std::endl;
    }
    /* Mode */
    QFile fd_mode("/sys/devices/platform/clevo_xsm_wmi/kb_mode");
    if(fd_mode.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QByteArray line = fd_mode.readAll();
        int value = line.at(0) - 48;
        if(value >= 0 && value <= 7)
            keyboard_settings.mode = value;
        else
            keyboard_settings.mode = 0;
        fd_mode.close();
    } else {
        keyboard_settings.mode = -1;
        std::cerr << "[clevo-xsm-wmi] Failed to read mode" << std::endl;
    }
    /* color */
    QFile fd_color("/sys/devices/platform/clevo_xsm_wmi/kb_color");
    if(fd_color.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QByteArray line = fd_color.readAll();
        char left[8], right[8], center[8], extra[8];
        int i = sscanf(line, "%7s %7s %7s %7s", left, center, right, extra);
        if(i == 3)
            has_extra = false;
        if(i == 3 || i == 4) {
            for (unsigned int j = 0;
                j < (sizeof(kb_colors) / sizeof((kb_colors)[0])); j++) {
                if (!strcmp(left, kb_colors[j].name))
                    keyboard_settings.color_left = j;
                if (!strcmp(center, kb_colors[j].name))
                    keyboard_settings.color_center = j;
                if (!strcmp(right, kb_colors[j].name))
                    keyboard_settings.color_right = j;
                if (!strcmp(extra, kb_colors[j].name))
                    keyboard_settings.color_extra = j;
            }
        }
        fd_color.close();
    } else {
        keyboard_settings.color_left = -1;
        keyboard_settings.color_center = -1;
        keyboard_settings.color_right = -1;
        keyboard_settings.color_extra = -1;
        std::cerr << "[clevo-xsm-wmi] Failed to read colour" << std::endl;
    }
    /* State */
    QFile fd_state("/sys/devices/platform/clevo_xsm_wmi/kb_state");
    if(fd_state.open(QIODevice::ReadOnly | QIODevice::Text)) {
        QByteArray line = fd_state.readAll();
        int value = line.at(0) - 48;
        keyboard_settings.state = (value == 1 ? 1 : 0);
        fd_state.close();
    } else {
        keyboard_settings.state = -1;
        std::cerr << "[clevo-xsm-wmi] Failed to read state" << std::endl;
    }
}