1import xcffib
2import struct
3import six
4MAJOR_VERSION = 1
5MINOR_VERSION = 1
6key = xcffib.ExtensionKey("XC-MISC")
7_events = {}
8_errors = {}
9class GetVersionReply(xcffib.Reply):
10    def __init__(self, unpacker):
11        if isinstance(unpacker, xcffib.Protobj):
12            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
13        xcffib.Reply.__init__(self, unpacker)
14        base = unpacker.offset
15        self.server_major_version, self.server_minor_version = unpacker.unpack("xx2x4xHH")
16        self.bufsize = unpacker.offset - base
17class GetVersionCookie(xcffib.Cookie):
18    reply_type = GetVersionReply
19class GetXIDRangeReply(xcffib.Reply):
20    def __init__(self, unpacker):
21        if isinstance(unpacker, xcffib.Protobj):
22            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
23        xcffib.Reply.__init__(self, unpacker)
24        base = unpacker.offset
25        self.start_id, self.count = unpacker.unpack("xx2x4xII")
26        self.bufsize = unpacker.offset - base
27class GetXIDRangeCookie(xcffib.Cookie):
28    reply_type = GetXIDRangeReply
29class GetXIDListReply(xcffib.Reply):
30    def __init__(self, unpacker):
31        if isinstance(unpacker, xcffib.Protobj):
32            unpacker = xcffib.MemoryUnpacker(unpacker.pack())
33        xcffib.Reply.__init__(self, unpacker)
34        base = unpacker.offset
35        self.ids_len, = unpacker.unpack("xx2x4xI20x")
36        self.ids = xcffib.List(unpacker, "I", self.ids_len)
37        self.bufsize = unpacker.offset - base
38class GetXIDListCookie(xcffib.Cookie):
39    reply_type = GetXIDListReply
40class xc_miscExtension(xcffib.Extension):
41    def GetVersion(self, client_major_version, client_minor_version, is_checked=True):
42        buf = six.BytesIO()
43        buf.write(struct.pack("=xx2xHH", client_major_version, client_minor_version))
44        return self.send_request(0, buf, GetVersionCookie, is_checked=is_checked)
45    def GetXIDRange(self, is_checked=True):
46        buf = six.BytesIO()
47        buf.write(struct.pack("=xx2x"))
48        return self.send_request(1, buf, GetXIDRangeCookie, is_checked=is_checked)
49    def GetXIDList(self, count, is_checked=True):
50        buf = six.BytesIO()
51        buf.write(struct.pack("=xx2xI", count))
52        return self.send_request(2, buf, GetXIDListCookie, is_checked=is_checked)
53xcffib._add_ext(key, xc_miscExtension, _events, _errors)
54