use crate::base::{self, BaseError, BaseEvent, GeEvent, Raw, Reply, WiredIn, WiredOut, Xid};
use crate::ext;
use crate::ffi::base::*;
use crate::ffi::ext::*;
use crate::lat1_str::{Lat1Str, Lat1String, Lat1StrF};
use crate::xproto;
use crate::xproto::PropEl;
use bitflags::bitflags;
use libc::{self, iovec};
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::os::unix::io::RawFd;
pub const XNAME: &str = "SYNC";
pub const MAJOR_VERSION: u32 = 3;
pub const MINOR_VERSION: u32 = 1;
pub const VERSION_STRING: &str = "3.1";
pub(crate) static mut FFI_EXT: xcb_extension_t = xcb_extension_t {
name: "SYNC\0".as_ptr() as *const _,
global_id: 0,
};
pub fn prefetch_extension_data(conn: &base::Connection) {
unsafe {
xcb_prefetch_extension_data(conn.get_raw_conn(), &mut FFI_EXT as *mut _);
}
}
pub fn get_extension_data(conn: &base::Connection) -> std::option::Option<ext::ExtensionData> {
unsafe {
let reply = xcb_get_extension_data(conn.get_raw_conn(), &mut FFI_EXT as *mut _);
assert!(!reply.is_null(), "Could not fetch Sync extension data");
let reply = xproto::QueryExtensionReply::from_raw(reply);
if !reply.present() {
std::mem::forget(reply);
return None;
}
let res = ext::ExtensionData{
ext: ext::Extension::Sync,
major_opcode: reply.major_opcode(),
first_event: reply.first_event(),
first_error: reply.first_error(),
};
std::mem::forget(reply);
Some(res)
}
}
pub struct CounterError {
raw: *mut xcb_generic_error_t,
}
impl base::Raw<xcb_generic_error_t> for CounterError {
unsafe fn from_raw(raw: *mut xcb_generic_error_t) -> Self { CounterError { raw } }
fn as_raw(&self) -> *mut xcb_generic_error_t {
self.raw
}
}
impl base::BaseError for CounterError {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Sync);
const NUMBER: u32 = 0;
}
impl CounterError {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
fn wire_len(&self) -> usize { 32 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn error_code(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn bad_counter(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn minor_opcode(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn major_opcode(&self) -> u8 {
unsafe {
let offset = 10usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for CounterError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CounterError")
.field("response_type", &self.response_type())
.field("error_code", &self.error_code())
.field("sequence", &self.sequence())
.field("bad_counter", &self.bad_counter())
.field("minor_opcode", &self.minor_opcode())
.field("major_opcode", &self.major_opcode())
.finish()
}
}
impl Drop for CounterError {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for CounterError {}
unsafe impl Sync for CounterError {}
pub struct AlarmError {
raw: *mut xcb_generic_error_t,
}
impl base::Raw<xcb_generic_error_t> for AlarmError {
unsafe fn from_raw(raw: *mut xcb_generic_error_t) -> Self { AlarmError { raw } }
fn as_raw(&self) -> *mut xcb_generic_error_t {
self.raw
}
}
impl base::BaseError for AlarmError {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Sync);
const NUMBER: u32 = 1;
}
impl AlarmError {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
fn wire_len(&self) -> usize { 32 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn error_code(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn bad_alarm(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn minor_opcode(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn major_opcode(&self) -> u8 {
unsafe {
let offset = 10usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for AlarmError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AlarmError")
.field("response_type", &self.response_type())
.field("error_code", &self.error_code())
.field("sequence", &self.sequence())
.field("bad_alarm", &self.bad_alarm())
.field("minor_opcode", &self.minor_opcode())
.field("major_opcode", &self.major_opcode())
.finish()
}
}
impl Drop for AlarmError {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for AlarmError {}
unsafe impl Sync for AlarmError {}
#[derive(Debug)]
pub enum Error {
Counter(CounterError),
Alarm(AlarmError),
}
impl base::ResolveWireError for Error {
unsafe fn resolve_wire_error(first_error: u8, raw: *mut xcb_generic_error_t) -> Self {
debug_assert!(!raw.is_null());
let error_code = (*raw).error_code;
match error_code - first_error {
0 => Error::Counter(CounterError::from_raw(raw)),
1 => Error::Alarm(AlarmError::from_raw(raw)),
_ => unreachable!(
"Could not resolve sync Error with error_code {} and first_error {}",
error_code, first_error
),
}
}
}
pub struct CounterNotifyEvent {
raw: *mut xcb_generic_event_t,
}
impl base::Raw<xcb_generic_event_t> for CounterNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_generic_event_t) -> Self { CounterNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_generic_event_t {
self.raw
}
}
impl base::BaseEvent for CounterNotifyEvent {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Sync);
const NUMBER: u32 = 0;
}
impl CounterNotifyEvent {
pub fn new(event_base: u8,
kind: u8,
counter: Counter,
wait_value: Int64,
counter_value: Int64,
timestamp: xproto::Timestamp,
count: u16,
destroyed: bool,
) -> CounterNotifyEvent {
unsafe {
let ptr = libc::malloc(32) as *mut u8;
let wire_buf = std::slice::from_raw_parts_mut(ptr, 32);
let mut wire_off = 0usize;
let response_type = event_base;
let sequence = 0u16;
wire_off += response_type.serialize(&mut wire_buf[wire_off ..]);
wire_off += kind.serialize(&mut wire_buf[wire_off ..]);
wire_off += sequence.serialize(&mut wire_buf[wire_off ..]);
wire_off += counter.serialize(&mut wire_buf[wire_off ..]);
wire_off += wait_value.serialize(&mut wire_buf[wire_off ..]);
wire_off += counter_value.serialize(&mut wire_buf[wire_off ..]);
wire_off += timestamp.serialize(&mut wire_buf[wire_off ..]);
wire_off += count.serialize(&mut wire_buf[wire_off ..]);
let destroyed: u8 = if destroyed { 1 } else { 0 };
destroyed.serialize(&mut wire_buf[wire_off ..]);
CounterNotifyEvent::from_raw(ptr as *mut xcb_generic_event_t)
}
}
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn kind(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn counter(&self) -> Counter {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const Counter;
base::value_from_ptr(ptr)
}
}
pub fn wait_value(&self) -> Int64 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
pub fn counter_value(&self) -> Int64 {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
pub fn timestamp(&self) -> xproto::Timestamp {
unsafe {
let offset = 24usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Timestamp;
base::value_from_ptr(ptr)
}
}
pub fn count(&self) -> u16 {
unsafe {
let offset = 28usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn destroyed(&self) -> bool {
let val = unsafe { *(self.wire_ptr().add(30usize)) };
val != 0
}
}
impl std::fmt::Debug for CounterNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CounterNotifyEvent")
.field("response_type", &self.response_type())
.field("kind", &self.kind())
.field("sequence", &self.sequence())
.field("counter", &self.counter())
.field("wait_value", &self.wait_value())
.field("counter_value", &self.counter_value())
.field("timestamp", &self.timestamp())
.field("count", &self.count())
.field("destroyed", &self.destroyed())
.field("pad", &1)
.finish()
}
}
impl base::WiredOut for CounterNotifyEvent {
fn wire_len(&self) -> usize {
32usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for CounterNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize {
32
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_generic_event_t;
std::ptr::copy(ptr as *const xcb_generic_event_t, raw, sz);
CounterNotifyEvent { raw }
}
}
impl Drop for CounterNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for CounterNotifyEvent {}
unsafe impl Sync for CounterNotifyEvent {}
pub struct AlarmNotifyEvent {
raw: *mut xcb_generic_event_t,
}
impl base::Raw<xcb_generic_event_t> for AlarmNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_generic_event_t) -> Self { AlarmNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_generic_event_t {
self.raw
}
}
impl base::BaseEvent for AlarmNotifyEvent {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Sync);
const NUMBER: u32 = 1;
}
impl AlarmNotifyEvent {
pub fn new(event_base: u8,
kind: u8,
alarm: Alarm,
counter_value: Int64,
alarm_value: Int64,
timestamp: xproto::Timestamp,
state: Alarmstate,
) -> AlarmNotifyEvent {
unsafe {
let ptr = libc::malloc(32) as *mut u8;
let wire_buf = std::slice::from_raw_parts_mut(ptr, 32);
let mut wire_off = 0usize;
let response_type = 1u8 + event_base;
let sequence = 0u16;
wire_off += response_type.serialize(&mut wire_buf[wire_off ..]);
wire_off += kind.serialize(&mut wire_buf[wire_off ..]);
wire_off += sequence.serialize(&mut wire_buf[wire_off ..]);
wire_off += alarm.serialize(&mut wire_buf[wire_off ..]);
wire_off += counter_value.serialize(&mut wire_buf[wire_off ..]);
wire_off += alarm_value.serialize(&mut wire_buf[wire_off ..]);
wire_off += timestamp.serialize(&mut wire_buf[wire_off ..]);
(std::mem::transmute::<_, u32>(state) as u8).serialize(&mut wire_buf[wire_off ..]);
AlarmNotifyEvent::from_raw(ptr as *mut xcb_generic_event_t)
}
}
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn kind(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn alarm(&self) -> Alarm {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const Alarm;
base::value_from_ptr(ptr)
}
}
pub fn counter_value(&self) -> Int64 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
pub fn alarm_value(&self) -> Int64 {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
pub fn timestamp(&self) -> xproto::Timestamp {
unsafe {
let offset = 24usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Timestamp;
base::value_from_ptr(ptr)
}
}
pub fn state(&self) -> Alarmstate {
unsafe {
let offset = 28usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, Alarmstate>(val)
}
}
}
impl std::fmt::Debug for AlarmNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("AlarmNotifyEvent")
.field("response_type", &self.response_type())
.field("kind", &self.kind())
.field("sequence", &self.sequence())
.field("alarm", &self.alarm())
.field("counter_value", &self.counter_value())
.field("alarm_value", &self.alarm_value())
.field("timestamp", &self.timestamp())
.field("state", &self.state())
.field("pad", &3)
.finish()
}
}
impl base::WiredOut for AlarmNotifyEvent {
fn wire_len(&self) -> usize {
32usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for AlarmNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize {
32
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_generic_event_t;
std::ptr::copy(ptr as *const xcb_generic_event_t, raw, sz);
AlarmNotifyEvent { raw }
}
}
impl Drop for AlarmNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for AlarmNotifyEvent {}
unsafe impl Sync for AlarmNotifyEvent {}
#[derive(Debug)]
pub enum Event {
CounterNotify(CounterNotifyEvent),
AlarmNotify(AlarmNotifyEvent),
}
impl Event {
pub fn as_raw(&self) -> *mut xcb_generic_event_t {
match self {
Self::CounterNotify(e) => e.as_raw(),
Self::AlarmNotify(e) => e.as_raw(),
}
}
}
impl base::ResolveWireEvent for Event {
unsafe fn resolve_wire_event(first_event: u8, raw: *mut xcb_generic_event_t) -> std::option::Option<Self> {
debug_assert!(!raw.is_null());
let response_type = (*raw).response_type & 0x7F;
debug_assert!(response_type != 0, "This is not an event but an error!");
debug_assert!(response_type != XCB_GE_GENERIC, "This is a GE_GENERIC event!");
match response_type - first_event {
0 => Some(Event::CounterNotify(CounterNotifyEvent::from_raw(raw))),
1 => Some(Event::AlarmNotify(AlarmNotifyEvent::from_raw(raw))),
_ => None,
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct Alarm {
res_id: u32,
}
impl base::Xid for Alarm {
fn none() -> Self { Alarm { res_id: 0 } }
fn resource_id(&self) -> u32 { self.res_id }
}
impl base::XidNew for Alarm {
unsafe fn new(res_id: u32) -> Self { Alarm { res_id } }
}
#[test]
fn test_sizeof_alarm() {
assert_eq!(std::mem::size_of::<Alarm>(), 4);
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum Alarmstate {
Active = 0,
Inactive = 1,
Destroyed = 2,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct Counter {
res_id: u32,
}
impl base::Xid for Counter {
fn none() -> Self { Counter { res_id: 0 } }
fn resource_id(&self) -> u32 { self.res_id }
}
impl base::XidNew for Counter {
unsafe fn new(res_id: u32) -> Self { Counter { res_id } }
}
#[test]
fn test_sizeof_counter() {
assert_eq!(std::mem::size_of::<Counter>(), 4);
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct Fence {
res_id: u32,
}
impl base::Xid for Fence {
fn none() -> Self { Fence { res_id: 0 } }
fn resource_id(&self) -> u32 { self.res_id }
}
impl base::XidNew for Fence {
unsafe fn new(res_id: u32) -> Self { Fence { res_id } }
}
#[test]
fn test_sizeof_fence() {
assert_eq!(std::mem::size_of::<Fence>(), 4);
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum Testtype {
PositiveTransition = 0,
NegativeTransition = 1,
PositiveComparison = 2,
NegativeComparison = 3,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum Valuetype {
Absolute = 0,
Relative = 1,
}
bitflags! {
pub struct CaMask: u32 {
const COUNTER = 0x00000001;
const VALUE_TYPE = 0x00000002;
const VALUE = 0x00000004;
const TEST_TYPE = 0x00000008;
const DELTA = 0x00000010;
const EVENTS = 0x00000020;
}
}
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct Int64 {
pub hi: i32,
pub lo: u32,
}
#[test]
fn test_sizeof_int64() {
assert_eq!(std::mem::size_of::<Int64>(), 8);
}
impl base::WiredOut for Int64 {
fn wire_len(&self) -> usize { 8 }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
let me = unsafe {
std::slice::from_raw_parts(self as *const Int64 as _, 8)
};
(&mut wire_buf[..me.len()]).copy_from_slice(me);
8
}
}
impl base::WiredIn for Int64 {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize { 8 }
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
*offset += 8;
*(ptr as *const Int64)
}
}
pub struct Systemcounter {
data: [u8],
}
#[allow(unused_parens)]
impl Systemcounter {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &Systemcounter {
debug_assert_eq!(data.as_ref().len(), <&Systemcounter as base::WiredIn>::compute_wire_len(data.as_ref().as_ptr(), ()));
&*(data.as_ref() as *const [u8] as *const Systemcounter)
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
pub fn counter(&self) -> Counter {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const Counter;
base::value_from_ptr(ptr)
}
}
pub fn resolution(&self) -> Int64 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
fn name_len(&self) -> u16 {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn name(&self) -> &Lat1Str {
unsafe {
let offset = 14usize;
let len = (self.name_len() as usize) as _;
let ptr = self.wire_ptr().add(offset);
let bytes = std::slice::from_raw_parts(ptr, len);
Lat1Str::from_bytes(bytes)
}
}
}
impl base::WiredOut for Systemcounter {
fn wire_len(&self) -> usize { self.data.len() }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for &Systemcounter {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 4usize;
sz += 8usize;
let name_len = *(ptr.add(sz) as *const u16);
sz += 2usize;
sz += (name_len as usize);
sz += base::align_pad(sz, 4);
sz
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
Systemcounter::from_data(data)
}
}
#[derive(Clone)]
pub struct SystemcounterBuf {
data: Vec<u8>,
}
impl SystemcounterBuf {
pub(crate) unsafe fn from_data(data: Vec<u8>) -> SystemcounterBuf {
debug_assert_eq!(<&Systemcounter>::compute_wire_len(data.as_ptr(), ()), data.len());
SystemcounterBuf { data }
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
counter: Counter,
resolution: Int64,
name: &[u8],
) -> SystemcounterBuf {
unsafe {
let mut wire_sz = 0usize;
wire_sz += 4; wire_sz += 8; wire_sz += 2; wire_sz += name.len();
wire_sz += base::align_pad(wire_sz, 4);
let mut wire_buf = vec![0u8; wire_sz];
let mut wire_off = 0usize;
wire_off += counter.serialize(&mut wire_buf[wire_off .. ]);
wire_off += resolution.serialize(&mut wire_buf[wire_off .. ]);
wire_off += (name.len() as u16).serialize(&mut wire_buf[wire_off .. ]);
wire_buf[wire_off .. wire_off + name.len()].copy_from_slice(name);
wire_off += name.len();
wire_off += base::align_pad(wire_off, 4);
SystemcounterBuf { data: wire_buf }
}
}
}
impl base::WiredIn for SystemcounterBuf {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, params: ()) -> usize {
<&Systemcounter>::compute_wire_len(ptr, params)
}
unsafe fn unserialize(ptr: *const u8, params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, params);
*offset += sz;
let data = std::slice::from_raw_parts(ptr, sz);
SystemcounterBuf::from_data(data.to_vec())
}
}
impl std::ops::Deref for SystemcounterBuf {
type Target = Systemcounter;
fn deref(&self) -> &Self::Target {
unsafe { Systemcounter::from_data(&self.data) }
}
}
impl std::borrow::Borrow<Systemcounter> for SystemcounterBuf {
fn borrow(&self) -> &Systemcounter {
unsafe { Systemcounter::from_data(&self.data) }
}
}
impl std::borrow::ToOwned for Systemcounter {
type Owned = SystemcounterBuf;
fn to_owned(&self) -> Self::Owned {
SystemcounterBuf {
data: self.data.to_vec()
}
}
}
impl std::fmt::Debug for Systemcounter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Systemcounter")
.field("counter", &self.counter())
.field("resolution", &self.resolution())
.field("name_len", &self.name_len())
.field("name", &self.name())
.field("align_pad", &4)
.finish()
}
}
impl std::fmt::Debug for SystemcounterBuf {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("SystemcounterBuf")
.field("counter", &self.counter())
.field("resolution", &self.resolution())
.field("name_len", &self.name_len())
.field("name", &self.name())
.field("align_pad", &4)
.finish()
}
}
#[derive(Clone)]
pub struct SystemcounterIterator<'a> {
pub(crate) params: (),
pub(crate) rem: usize,
pub(crate) ptr: *const u8,
pub(crate) phantom: std::marker::PhantomData<&'a Systemcounter>,
}
impl<'a> Iterator for SystemcounterIterator<'a> {
type Item = &'a Systemcounter;
fn next(&mut self) -> std::option::Option<Self::Item> {
if self.rem == 0 {
None
} else { unsafe {
self.rem -= 1;
let mut offset = 0;
let res = <&Systemcounter>::unserialize(self.ptr, self.params, &mut offset);
self.ptr = self.ptr.add(offset);
Some(res)
}}
}
}
impl<'a> std::fmt::Debug for SystemcounterIterator<'a> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_list().entries(self.clone()).finish()
}
}
#[derive(Copy, Clone)]
pub struct Trigger {
data: [u8; 20],
}
#[allow(unused_parens)]
impl Trigger {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &Trigger {
debug_assert_eq!(data.as_ref().len(), 20);
&*(data.as_ref() as *const [u8] as *const Trigger)
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
counter: Counter,
wait_type: Valuetype,
wait_value: Int64,
test_type: Testtype,
) -> Trigger {
unsafe {
let mut wire_buf = [0u8; 20];
let mut wire_off = 0usize;
wire_off += counter.serialize(&mut wire_buf[wire_off .. ]);
wire_off += std::mem::transmute::<_, u32>(wait_type).serialize(&mut wire_buf[wire_off .. ]);
wire_off += wait_value.serialize(&mut wire_buf[wire_off .. ]);
wire_off += std::mem::transmute::<_, u32>(test_type).serialize(&mut wire_buf[wire_off .. ]);
Trigger { data: wire_buf }
}
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
fn wire_len(&self) -> usize { self.data.len() }
pub fn counter(&self) -> Counter {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const Counter;
base::value_from_ptr(ptr)
}
}
pub fn wait_type(&self) -> Valuetype {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, Valuetype>(val)
}
}
pub fn wait_value(&self) -> Int64 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
pub fn test_type(&self) -> Testtype {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, Testtype>(val)
}
}
}
#[test]
fn test_sizeof_trigger() {
assert_eq!(std::mem::size_of::<Trigger>(), 20);
}
impl base::WiredOut for Trigger {
fn wire_len(&self) -> usize { 20 }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for Trigger {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize { 20 }
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
*offset += 20;
*(ptr as *const Trigger)
}
}
impl std::fmt::Debug for Trigger {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Trigger")
.field("counter", &self.counter())
.field("wait_type", &self.wait_type())
.field("wait_value", &self.wait_value())
.field("test_type", &self.test_type())
.finish()
}
}
#[derive(Copy, Clone)]
pub struct Waitcondition {
data: [u8; 28],
}
#[allow(unused_parens)]
impl Waitcondition {
pub(crate) unsafe fn from_data<D: AsRef<[u8]> + ?Sized>(data: &D) -> &Waitcondition {
debug_assert_eq!(data.as_ref().len(), 28);
&*(data.as_ref() as *const [u8] as *const Waitcondition)
}
#[allow(unused_assignments, unused_unsafe)]
pub fn new(
trigger: Trigger,
event_threshold: Int64,
) -> Waitcondition {
unsafe {
let mut wire_buf = [0u8; 28];
let mut wire_off = 0usize;
wire_off += trigger.serialize(&mut wire_buf[wire_off .. ]);
wire_off += event_threshold.serialize(&mut wire_buf[wire_off .. ]);
Waitcondition { data: wire_buf }
}
}
fn wire_ptr(&self) -> *const u8 { self.data.as_ptr() }
fn wire_len(&self) -> usize { self.data.len() }
pub fn trigger(&self) -> &Trigger {
unsafe {
let offset = 0usize;
let len = 20usize;
let data = std::slice::from_raw_parts(self.wire_ptr().add(offset), len);
Trigger::from_data(data)
}
}
pub fn event_threshold(&self) -> Int64 {
unsafe {
let offset = 20usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
}
#[test]
fn test_sizeof_waitcondition() {
assert_eq!(std::mem::size_of::<Waitcondition>(), 28);
}
impl base::WiredOut for Waitcondition {
fn wire_len(&self) -> usize { 28 }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
(&mut wire_buf[..self.data.len()]).copy_from_slice(&self.data);
self.data.len()
}
}
impl base::WiredIn for Waitcondition {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize { 28 }
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
*offset += 28;
*(ptr as *const Waitcondition)
}
}
impl std::fmt::Debug for Waitcondition {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Waitcondition")
.field("trigger", &self.trigger())
.field("event_threshold", &self.event_threshold())
.finish()
}
}
#[derive(Copy, Clone, Debug)]
pub struct CaParams {
pub value_mask: usize,
}
#[derive(Clone, Debug)]
pub enum Ca {
Counter(Counter),
ValueType(Valuetype),
Value(Int64),
TestType(Testtype),
Delta(Int64),
Events(u32),
}
impl Ca {
pub(crate) fn get_mask(slice: &[Ca]) -> CaMask {
let mut res = CaMask::empty();
for el in slice {
match el {
Ca::Counter{..} => {
res |= CaMask::COUNTER;
}
Ca::ValueType{..} => {
res |= CaMask::VALUE_TYPE;
}
Ca::Value{..} => {
res |= CaMask::VALUE;
}
Ca::TestType{..} => {
res |= CaMask::TEST_TYPE;
}
Ca::Delta{..} => {
res |= CaMask::DELTA;
}
Ca::Events{..} => {
res |= CaMask::EVENTS;
}
}
}
res
}
pub(crate) fn is_sorted_distinct(slice: &[Ca]) -> bool {
if slice.len() <= 1 {
true
} else {
let mut last = slice[0].get_ord();
slice[1..].iter().map(|el| el.get_ord()).all(|o| {
let lasto = last;
last = o;
lasto < o
})
}
}
fn get_ord(&self) -> u32 {
match self {
Ca::Counter{..} => 0,
Ca::ValueType{..} => 1,
Ca::Value{..} => 2,
Ca::TestType{..} => 3,
Ca::Delta{..} => 4,
Ca::Events{..} => 5,
}
}
}
impl base::WiredOut for &[Ca] {
fn wire_len(&self) -> usize {
let mut sz = 0usize;
for el in self.iter() {
match el {
Ca::Counter(
..
) => {
sz += 4;
}
Ca::ValueType(
..
) => {
sz += 4;
}
Ca::Value(
..
) => {
sz += 8;
}
Ca::TestType(
..
) => {
sz += 4;
}
Ca::Delta(
..
) => {
sz += 8;
}
Ca::Events(
..
) => {
sz += 4;
}
}
}
sz
}
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
let mut offset = 0usize;
for el in self.iter() {
match el {
Ca::Counter(
counter,
..
) => {
offset += counter.serialize(&mut wire_buf[offset..]);
}
Ca::ValueType(
value_type,
..
) => {
offset += (unsafe { std::mem::transmute::<_, u32>(*value_type) } as u32).serialize(&mut wire_buf[offset..]);
}
Ca::Value(
value,
..
) => {
offset += value.serialize(&mut wire_buf[offset..]);
}
Ca::TestType(
test_type,
..
) => {
offset += (unsafe { std::mem::transmute::<_, u32>(*test_type) } as u32).serialize(&mut wire_buf[offset..]);
}
Ca::Delta(
delta,
..
) => {
offset += delta.serialize(&mut wire_buf[offset..]);
}
Ca::Events(
events,
..
) => {
offset += events.serialize(&mut wire_buf[offset..]);
}
}
}
offset
}
}
impl base::WiredIn for Vec<Ca> {
type Params = CaParams;
unsafe fn compute_wire_len(ptr: *const u8, params: Self::Params) -> usize {
let CaParams {
value_mask,
} = params;
let expr = (value_mask as usize);
let mut sz = 0usize;
if expr & (CaMask::COUNTER.bits() as usize) != 0 {
sz += 4usize;
}
if expr & (CaMask::VALUE_TYPE.bits() as usize) != 0 {
sz += 4usize;
}
if expr & (CaMask::VALUE.bits() as usize) != 0 {
sz += 8usize;
}
if expr & (CaMask::TEST_TYPE.bits() as usize) != 0 {
sz += 4usize;
}
if expr & (CaMask::DELTA.bits() as usize) != 0 {
sz += 8usize;
}
if expr & (CaMask::EVENTS.bits() as usize) != 0 {
sz += 4usize;
}
sz
}
#[allow(unused_assignments)]
unsafe fn unserialize(wire_data: *const u8, params: CaParams, out_offset: &mut usize) -> Vec<Ca> {
let CaParams{
value_mask,
} = params;
let expr = (value_mask as usize);
let mut result = Vec::new();
if expr & (CaMask::COUNTER.bits() as usize) != 0 {
let mut offset = 0usize;
let counter = *(wire_data.add(offset) as *const Counter);
offset += std::mem::size_of::<Counter>();
*out_offset += offset;
result.push(Ca::Counter(
counter,
));
}
if expr & (CaMask::VALUE_TYPE.bits() as usize) != 0 {
let mut offset = 0usize;
let value_type = std::mem::transmute::<_, Valuetype>(*(wire_data.add(offset) as *const u32) as u32);
offset += 4;
*out_offset += offset;
result.push(Ca::ValueType(
value_type,
));
}
if expr & (CaMask::VALUE.bits() as usize) != 0 {
let mut offset = 0usize;
let value = *(wire_data.add(offset) as *const Int64);
offset += std::mem::size_of::<Int64>();
*out_offset += offset;
result.push(Ca::Value(
value,
));
}
if expr & (CaMask::TEST_TYPE.bits() as usize) != 0 {
let mut offset = 0usize;
let test_type = std::mem::transmute::<_, Testtype>(*(wire_data.add(offset) as *const u32) as u32);
offset += 4;
*out_offset += offset;
result.push(Ca::TestType(
test_type,
));
}
if expr & (CaMask::DELTA.bits() as usize) != 0 {
let mut offset = 0usize;
let delta = *(wire_data.add(offset) as *const Int64);
offset += std::mem::size_of::<Int64>();
*out_offset += offset;
result.push(Ca::Delta(
delta,
));
}
if expr & (CaMask::EVENTS.bits() as usize) != 0 {
let mut offset = 0usize;
let events = *(wire_data.add(offset) as *const u32);
offset += std::mem::size_of::<u32>();
*out_offset += offset;
result.push(Ca::Events(
events,
));
}
result
}
}
pub(crate) fn request_name(opcode: u16) -> std::option::Option<&'static str> {
match opcode {
0 => Some("sync::Initialize"),
1 => Some("sync::ListSystemCounters"),
2 => Some("sync::CreateCounter"),
6 => Some("sync::DestroyCounter"),
5 => Some("sync::QueryCounter"),
7 => Some("sync::Await"),
4 => Some("sync::ChangeCounter"),
3 => Some("sync::SetCounter"),
8 => Some("sync::CreateAlarm"),
9 => Some("sync::ChangeAlarm"),
11 => Some("sync::DestroyAlarm"),
10 => Some("sync::QueryAlarm"),
12 => Some("sync::SetPriority"),
13 => Some("sync::GetPriority"),
14 => Some("sync::CreateFence"),
15 => Some("sync::TriggerFence"),
16 => Some("sync::ResetFence"),
17 => Some("sync::DestroyFence"),
18 => Some("sync::QueryFence"),
19 => Some("sync::AwaitFence"),
_ => None,
}
}
pub struct InitializeReply {
raw: *const u8,
}
impl InitializeReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn major_version(&self) -> u8 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn minor_version(&self) -> u8 {
unsafe {
let offset = 9usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for InitializeReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for InitializeReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("InitializeReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("major_version", &self.major_version())
.field("minor_version", &self.minor_version())
.field("pad", &22)
.finish()
}
}
impl Drop for InitializeReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for InitializeReply {}
unsafe impl std::marker::Sync for InitializeReply {}
#[derive(Debug)]
pub struct InitializeCookie {
seq: u64,
}
#[derive(Debug)]
pub struct InitializeCookieUnchecked {
seq: u64,
}
impl base::Cookie for InitializeCookie {
unsafe fn from_sequence(seq: u64) -> Self {
InitializeCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for InitializeCookie {
}
unsafe impl base::CookieWithReplyChecked for InitializeCookie {
type Reply = InitializeReply;
}
impl base::Cookie for InitializeCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
InitializeCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for InitializeCookieUnchecked {
type Reply = InitializeReply;
}
#[derive(Clone, Debug)]
pub struct Initialize {
pub desired_major_version: u8,
pub desired_minor_version: u8,
}
unsafe impl base::RawRequest for Initialize {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 0,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 6];
self.desired_major_version.serialize(&mut buf0[4 .. ]);
self.desired_minor_version.serialize(&mut buf0[5 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 6;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for Initialize {
type Cookie = InitializeCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for Initialize {
type Reply = InitializeReply;
type Cookie = InitializeCookie;
type CookieUnchecked = InitializeCookieUnchecked;
}
pub struct ListSystemCountersReply {
raw: *const u8,
}
impl ListSystemCountersReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
unsafe fn compute_len(ptr: *const u8, _params: ()) -> usize {
let mut sz = 0;
sz += 1usize;
sz += 1usize;
sz += 2usize;
sz += 4usize;
let counters_len = *(ptr.add(sz) as *const u32);
sz += 4usize;
sz += 20usize;
for _ in 0 .. (counters_len as usize) {
sz += <&Systemcounter>::compute_wire_len(ptr.add(sz), ());
}
sz
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
fn counters_len(&self) -> u32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn counters(&self) -> SystemcounterIterator {
unsafe {
let offset = 32usize;
SystemcounterIterator {
params: (),
rem: (self.counters_len() as usize),
ptr: self.wire_ptr().add(offset),
phantom: std::marker::PhantomData,
}
}
}
}
impl base::Reply for ListSystemCountersReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for ListSystemCountersReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ListSystemCountersReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("counters_len", &self.counters_len())
.field("pad", &20)
.field("counters", &self.counters())
.finish()
}
}
impl Drop for ListSystemCountersReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for ListSystemCountersReply {}
unsafe impl std::marker::Sync for ListSystemCountersReply {}
#[derive(Debug)]
pub struct ListSystemCountersCookie {
seq: u64,
}
#[derive(Debug)]
pub struct ListSystemCountersCookieUnchecked {
seq: u64,
}
impl base::Cookie for ListSystemCountersCookie {
unsafe fn from_sequence(seq: u64) -> Self {
ListSystemCountersCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for ListSystemCountersCookie {
}
unsafe impl base::CookieWithReplyChecked for ListSystemCountersCookie {
type Reply = ListSystemCountersReply;
}
impl base::Cookie for ListSystemCountersCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
ListSystemCountersCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for ListSystemCountersCookieUnchecked {
type Reply = ListSystemCountersReply;
}
#[derive(Clone, Debug)]
pub struct ListSystemCounters {
}
unsafe impl base::RawRequest for ListSystemCounters {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 1,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 4];
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 4;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for ListSystemCounters {
type Cookie = ListSystemCountersCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for ListSystemCounters {
type Reply = ListSystemCountersReply;
type Cookie = ListSystemCountersCookie;
type CookieUnchecked = ListSystemCountersCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct CreateCounter {
pub id: Counter,
pub initial_value: Int64,
}
unsafe impl base::RawRequest for CreateCounter {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 2,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 16];
self.id.serialize(&mut buf0[4 .. ]);
self.initial_value.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 16;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for CreateCounter {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for CreateCounter {
}
#[derive(Clone, Debug)]
pub struct DestroyCounter {
pub counter: Counter,
}
unsafe impl base::RawRequest for DestroyCounter {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 6,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.counter.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for DestroyCounter {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for DestroyCounter {
}
pub struct QueryCounterReply {
raw: *const u8,
}
impl QueryCounterReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn counter_value(&self) -> Int64 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for QueryCounterReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryCounterReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryCounterReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("counter_value", &self.counter_value())
.finish()
}
}
impl Drop for QueryCounterReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryCounterReply {}
unsafe impl std::marker::Sync for QueryCounterReply {}
#[derive(Debug)]
pub struct QueryCounterCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryCounterCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryCounterCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryCounterCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryCounterCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryCounterCookie {
type Reply = QueryCounterReply;
}
impl base::Cookie for QueryCounterCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryCounterCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryCounterCookieUnchecked {
type Reply = QueryCounterReply;
}
#[derive(Clone, Debug)]
pub struct QueryCounter {
pub counter: Counter,
}
unsafe impl base::RawRequest for QueryCounter {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 5,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.counter.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryCounter {
type Cookie = QueryCounterCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryCounter {
type Reply = QueryCounterReply;
type Cookie = QueryCounterCookie;
type CookieUnchecked = QueryCounterCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct Await<'a> {
pub wait_list: &'a [Waitcondition],
}
unsafe impl<'a> base::RawRequest for Await<'a> {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 4,
ext: (&mut FFI_EXT) as *mut _,
opcode: 7,
isvoid: 1,
};
let mut sections: [iovec; 6] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 6];
let buf0: &mut [u8] = &mut [0; 4];
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 4;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
sections[4].iov_base = self.wait_list.as_ptr() as *mut _;
sections[4].iov_len = self.wait_list.len() * std::mem::size_of::<Waitcondition>();
sections[5].iov_len = base::align_pad(sections[4].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl<'a> base::Request for Await<'a> {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl<'a> base::RequestWithoutReply for Await<'a> {
}
#[derive(Clone, Debug)]
pub struct ChangeCounter {
pub counter: Counter,
pub amount: Int64,
}
unsafe impl base::RawRequest for ChangeCounter {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 4,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 16];
self.counter.serialize(&mut buf0[4 .. ]);
self.amount.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 16;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for ChangeCounter {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for ChangeCounter {
}
#[derive(Clone, Debug)]
pub struct SetCounter {
pub counter: Counter,
pub value: Int64,
}
unsafe impl base::RawRequest for SetCounter {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 3,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 16];
self.counter.serialize(&mut buf0[4 .. ]);
self.value.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 16;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for SetCounter {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for SetCounter {
}
#[derive(Clone, Debug)]
pub struct CreateAlarm<'a> {
pub id: Alarm,
pub value_list: &'a [Ca],
}
unsafe impl<'a> base::RawRequest for CreateAlarm<'a> {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
assert!(Ca::is_sorted_distinct(self.value_list), "CreateAlarm::value_list must be sorted!");
let mut protocol_request = xcb_protocol_request_t {
count: 4,
ext: (&mut FFI_EXT) as *mut _,
opcode: 8,
isvoid: 1,
};
let mut sections: [iovec; 6] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 6];
let buf0: &mut [u8] = &mut [0; 12];
self.id.serialize(&mut buf0[4 .. ]);
(Ca::get_mask(self.value_list).bits() as u32).serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let len1 = self.value_list.wire_len();
let mut buf1 = vec![0u8; len1];
self.value_list.serialize(&mut buf1);
sections[4].iov_base = buf1.as_ptr() as *mut _;
sections[4].iov_len = buf1.len();
sections[5].iov_len = base::align_pad(sections[4].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl<'a> base::Request for CreateAlarm<'a> {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl<'a> base::RequestWithoutReply for CreateAlarm<'a> {
}
#[derive(Clone, Debug)]
pub struct ChangeAlarm<'a> {
pub id: Alarm,
pub value_list: &'a [Ca],
}
unsafe impl<'a> base::RawRequest for ChangeAlarm<'a> {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
assert!(Ca::is_sorted_distinct(self.value_list), "ChangeAlarm::value_list must be sorted!");
let mut protocol_request = xcb_protocol_request_t {
count: 4,
ext: (&mut FFI_EXT) as *mut _,
opcode: 9,
isvoid: 1,
};
let mut sections: [iovec; 6] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 6];
let buf0: &mut [u8] = &mut [0; 12];
self.id.serialize(&mut buf0[4 .. ]);
(Ca::get_mask(self.value_list).bits() as u32).serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let len1 = self.value_list.wire_len();
let mut buf1 = vec![0u8; len1];
self.value_list.serialize(&mut buf1);
sections[4].iov_base = buf1.as_ptr() as *mut _;
sections[4].iov_len = buf1.len();
sections[5].iov_len = base::align_pad(sections[4].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl<'a> base::Request for ChangeAlarm<'a> {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl<'a> base::RequestWithoutReply for ChangeAlarm<'a> {
}
#[derive(Clone, Debug)]
pub struct DestroyAlarm {
pub alarm: Alarm,
}
unsafe impl base::RawRequest for DestroyAlarm {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 11,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.alarm.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for DestroyAlarm {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for DestroyAlarm {
}
pub struct QueryAlarmReply {
raw: *const u8,
}
impl QueryAlarmReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn trigger(&self) -> &Trigger {
unsafe {
let offset = 8usize;
let len = 20usize;
let data = std::slice::from_raw_parts(self.wire_ptr().add(offset), len);
Trigger::from_data(data)
}
}
pub fn delta(&self) -> Int64 {
unsafe {
let offset = 28usize;
let ptr = self.wire_ptr().add(offset) as *const Int64;
base::value_from_ptr(ptr)
}
}
pub fn events(&self) -> bool {
let val = unsafe { *(self.wire_ptr().add(36usize)) };
val != 0
}
pub fn state(&self) -> Alarmstate {
unsafe {
let offset = 37usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, Alarmstate>(val)
}
}
}
impl base::Reply for QueryAlarmReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryAlarmReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryAlarmReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("trigger", &self.trigger())
.field("delta", &self.delta())
.field("events", &self.events())
.field("state", &self.state())
.field("pad", &2)
.finish()
}
}
impl Drop for QueryAlarmReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryAlarmReply {}
unsafe impl std::marker::Sync for QueryAlarmReply {}
#[derive(Debug)]
pub struct QueryAlarmCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryAlarmCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryAlarmCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryAlarmCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryAlarmCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryAlarmCookie {
type Reply = QueryAlarmReply;
}
impl base::Cookie for QueryAlarmCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryAlarmCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryAlarmCookieUnchecked {
type Reply = QueryAlarmReply;
}
#[derive(Clone, Debug)]
pub struct QueryAlarm {
pub alarm: Alarm,
}
unsafe impl base::RawRequest for QueryAlarm {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 10,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.alarm.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryAlarm {
type Cookie = QueryAlarmCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryAlarm {
type Reply = QueryAlarmReply;
type Cookie = QueryAlarmCookie;
type CookieUnchecked = QueryAlarmCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct SetPriority {
pub id: u32,
pub priority: i32,
}
unsafe impl base::RawRequest for SetPriority {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 12,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.id.serialize(&mut buf0[4 .. ]);
self.priority.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for SetPriority {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for SetPriority {
}
pub struct GetPriorityReply {
raw: *const u8,
}
impl GetPriorityReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn priority(&self) -> i32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const i32;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for GetPriorityReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for GetPriorityReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GetPriorityReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("priority", &self.priority())
.finish()
}
}
impl Drop for GetPriorityReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for GetPriorityReply {}
unsafe impl std::marker::Sync for GetPriorityReply {}
#[derive(Debug)]
pub struct GetPriorityCookie {
seq: u64,
}
#[derive(Debug)]
pub struct GetPriorityCookieUnchecked {
seq: u64,
}
impl base::Cookie for GetPriorityCookie {
unsafe fn from_sequence(seq: u64) -> Self {
GetPriorityCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for GetPriorityCookie {
}
unsafe impl base::CookieWithReplyChecked for GetPriorityCookie {
type Reply = GetPriorityReply;
}
impl base::Cookie for GetPriorityCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
GetPriorityCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for GetPriorityCookieUnchecked {
type Reply = GetPriorityReply;
}
#[derive(Clone, Debug)]
pub struct GetPriority {
pub id: u32,
}
unsafe impl base::RawRequest for GetPriority {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 13,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.id.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for GetPriority {
type Cookie = GetPriorityCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for GetPriority {
type Reply = GetPriorityReply;
type Cookie = GetPriorityCookie;
type CookieUnchecked = GetPriorityCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct CreateFence {
pub drawable: xproto::Drawable,
pub fence: Fence,
pub initially_triggered: bool,
}
unsafe impl base::RawRequest for CreateFence {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 14,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 13];
self.drawable.serialize(&mut buf0[4 .. ]);
self.fence.serialize(&mut buf0[8 .. ]);
(if self.initially_triggered { 1u8 } else { 0u8 }).serialize(&mut buf0[12 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 13;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for CreateFence {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for CreateFence {
}
#[derive(Clone, Debug)]
pub struct TriggerFence {
pub fence: Fence,
}
unsafe impl base::RawRequest for TriggerFence {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 15,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.fence.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for TriggerFence {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for TriggerFence {
}
#[derive(Clone, Debug)]
pub struct ResetFence {
pub fence: Fence,
}
unsafe impl base::RawRequest for ResetFence {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 16,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.fence.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for ResetFence {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for ResetFence {
}
#[derive(Clone, Debug)]
pub struct DestroyFence {
pub fence: Fence,
}
unsafe impl base::RawRequest for DestroyFence {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 17,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.fence.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for DestroyFence {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for DestroyFence {
}
pub struct QueryFenceReply {
raw: *const u8,
}
impl QueryFenceReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn triggered(&self) -> bool {
let val = unsafe { *(self.wire_ptr().add(8usize)) };
val != 0
}
}
impl base::Reply for QueryFenceReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryFenceReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryFenceReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("triggered", &self.triggered())
.field("pad", &23)
.finish()
}
}
impl Drop for QueryFenceReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryFenceReply {}
unsafe impl std::marker::Sync for QueryFenceReply {}
#[derive(Debug)]
pub struct QueryFenceCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryFenceCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryFenceCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryFenceCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryFenceCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryFenceCookie {
type Reply = QueryFenceReply;
}
impl base::Cookie for QueryFenceCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryFenceCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryFenceCookieUnchecked {
type Reply = QueryFenceReply;
}
#[derive(Clone, Debug)]
pub struct QueryFence {
pub fence: Fence,
}
unsafe impl base::RawRequest for QueryFence {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 18,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.fence.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryFence {
type Cookie = QueryFenceCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryFence {
type Reply = QueryFenceReply;
type Cookie = QueryFenceCookie;
type CookieUnchecked = QueryFenceCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct AwaitFence<'a> {
pub fence_list: &'a [Fence],
}
unsafe impl<'a> base::RawRequest for AwaitFence<'a> {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 4,
ext: (&mut FFI_EXT) as *mut _,
opcode: 19,
isvoid: 1,
};
let mut sections: [iovec; 6] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 6];
let buf0: &mut [u8] = &mut [0; 4];
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 4;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
sections[4].iov_base = self.fence_list.as_ptr() as *mut _;
sections[4].iov_len = self.fence_list.len() * std::mem::size_of::<Fence>();
sections[5].iov_len = base::align_pad(sections[4].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl<'a> base::Request for AwaitFence<'a> {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl<'a> base::RequestWithoutReply for AwaitFence<'a> {
}