Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move to old-code

svn path=/old-code/; revision=156243
  • Loading branch information...
commit 780148ada629f3b620f4f621d29677424ef459f9 1 parent bcd193e
Miguel de Icaza migueldeicaza authored
Showing with 13,795 additions and 0 deletions.
  1. +49 −0 acceptance-tests-ifolder/xnb/Attributes.cs
  2. +109 −0 acceptance-tests-ifolder/xnb/Authentication.cs
  3. +34 −0 acceptance-tests-ifolder/xnb/Auxiliary.cs
  4. +24 −0 acceptance-tests-ifolder/xnb/COPYING
  5. +150 −0 acceptance-tests-ifolder/xnb/CodeWriter.cs
  6. +221 −0 acceptance-tests-ifolder/xnb/Connection.cs
  7. +92 −0 acceptance-tests-ifolder/xnb/Extension.cs
  8. +1,003 −0 acceptance-tests-ifolder/xnb/Generator.cs
  9. +209 −0 acceptance-tests-ifolder/xnb/IOVector.cs
  10. +77 −0 acceptance-tests-ifolder/xnb/Makefile
  11. +16 −0 acceptance-tests-ifolder/xnb/Object.cs
  12. +19 −0 acceptance-tests-ifolder/xnb/README
  13. +84 −0 acceptance-tests-ifolder/xnb/Structs.cs
  14. +21 −0 acceptance-tests-ifolder/xnb/TestServer.cs
  15. +111 −0 acceptance-tests-ifolder/xnb/TestSimple.cs
  16. +38 −0 acceptance-tests-ifolder/xnb/TypeMap
  17. +486 −0 acceptance-tests-ifolder/xnb/X11.cs
  18. +73 −0 acceptance-tests-ifolder/xnb/XAuth.cs
  19. +94 −0 acceptance-tests-ifolder/xnb/XMarshaler.cs
  20. +102 −0 acceptance-tests-ifolder/xnb/XReader.cs
  21. +52 −0 acceptance-tests-ifolder/xnb/XRequestReader.cs
  22. +292 −0 acceptance-tests-ifolder/xnb/XResponseReader.cs
  23. +71 −0 acceptance-tests-ifolder/xnb/XServer.cs
  24. +124 −0 acceptance-tests-ifolder/xnb/XWriter.cs
  25. +271 −0 acceptance-tests-ifolder/xnb/Xau.cs
  26. +112 −0 acceptance-tests-ifolder/xnb/XcbConnection.cs
  27. +362 −0 acceptance-tests-ifolder/xnb/XcbSchema.cs
  28. +197 −0 acceptance-tests-ifolder/xnb/XcbSchema.xsd
  29. +45 −0 acceptance-tests-ifolder/xnb/XidManager.cs
  30. +36 −0 acceptance-tests-ifolder/xnb/proto/bigreq.xml
  31. +80 −0 acceptance-tests-ifolder/xnb/proto/composite.xml
  32. +78 −0 acceptance-tests-ifolder/xnb/proto/damage.xml
  33. +76 −0 acceptance-tests-ifolder/xnb/proto/dpms.xml
  34. +1,455 −0 acceptance-tests-ifolder/xnb/proto/glx.xml
  35. +147 −0 acceptance-tests-ifolder/xnb/proto/randr.xml
  36. +172 −0 acceptance-tests-ifolder/xnb/proto/record.xml
  37. +569 −0 acceptance-tests-ifolder/xnb/proto/render.xml
  38. +80 −0 acceptance-tests-ifolder/xnb/proto/res.xml
  39. +128 −0 acceptance-tests-ifolder/xnb/proto/screensaver.xml
  40. +147 −0 acceptance-tests-ifolder/xnb/proto/shape.xml
  41. +111 −0 acceptance-tests-ifolder/xnb/proto/shm.xml
  42. +177 −0 acceptance-tests-ifolder/xnb/proto/sync.xml
  43. +37 −0 acceptance-tests-ifolder/xnb/proto/xc_misc.xml
  44. +228 −0 acceptance-tests-ifolder/xnb/proto/xcb_types.xml
  45. +84 −0 acceptance-tests-ifolder/xnb/proto/xevie.xml
  46. +168 −0 acceptance-tests-ifolder/xnb/proto/xf86dri.xml
  47. +322 −0 acceptance-tests-ifolder/xnb/proto/xfixes.xml
  48. +325 −0 acceptance-tests-ifolder/xnb/proto/xprint.xml
  49. +1,657 −0 acceptance-tests-ifolder/xnb/proto/xproto.xml
  50. +429 −0 acceptance-tests-ifolder/xnb/proto/xv.xml
  51. +140 −0 acceptance-tests-ifolder/xnb/proto/xvmc.xml
  52. +147 −0 acceptance-tests-ifolder/xnb/shape.xml
  53. +37 −0 acceptance-tests-ifolder/xnb/xc_misc.xml
  54. +220 −0 acceptance-tests-ifolder/xnb/xcb.xsd
  55. +228 −0 acceptance-tests-ifolder/xnb/xcb_types.xml
  56. +322 −0 acceptance-tests-ifolder/xnb/xfixes.xml
  57. +1,657 −0 acceptance-tests-ifolder/xnb/xproto.xml
49 acceptance-tests-ifolder/xnb/Attributes.cs
View
@@ -0,0 +1,49 @@
+using System;
+
+namespace Xnb
+{
+ /*
+ public class OpAttribute : Attribute
+ {
+ public OpAttribute (int opcode)
+ {
+ }
+ }
+ */
+
+ [AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct)]
+ public class RequestAttribute : Attribute
+ {
+ public RequestAttribute (int opcode)
+ {
+ }
+ }
+
+ [AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method)]
+ public class ReplyAttribute : Attribute
+ {
+ public ReplyAttribute (Type reply)
+ {
+ }
+
+ public ReplyAttribute (int opcode)
+ {
+ }
+ }
+
+ [AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct)]
+ public class EventAttribute : Attribute
+ {
+ public EventAttribute (int number)
+ {
+ }
+ }
+
+ [AttributeUsage (AttributeTargets.Class | AttributeTargets.Struct)]
+ public class ErrorAttribute : Attribute
+ {
+ public ErrorAttribute (int number)
+ {
+ }
+ }
+}
109 acceptance-tests-ifolder/xnb/Authentication.cs
View
@@ -0,0 +1,109 @@
+using System;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.InteropServices;
+
+using System.Net.Sockets;
+
+using Mono.Unix;
+using Mono.Unix.Native;
+
+namespace Xnb
+{
+ using Auth;
+
+ //System.Net.IPAddress.NetworkToHostOrder();
+ public class Authenticator
+ {
+ public static void GetAuthInfoHack (int fd, out AuthInfo authinfo)
+ {
+ /*
+ string fname = UnixMarshal.PtrToStringUnix (XauFileName ());
+ Trace.WriteLine ("auth fname: " + fname);
+ */
+
+ Xau xau = new Xau ();
+ //string fname = xau.GetFileName ();
+
+ //foreach (Xauth xauth in xau.ReadAuths (fname))
+ foreach (Xauth xauth in xau) {
+ Trace.WriteLine (xauth.Name);
+ }
+
+ /*
+ UnixFileInfo ufi = new UnixFileInfo (fname);
+
+ UnixStream us = ufi.OpenRead ();
+
+ Trace.WriteLine ("a: " + us.Handle);
+ IntPtr auth = XauReadAuth (us.Handle);
+ Trace.WriteLine ("auth: " + auth);
+
+ us.Close ();
+ */
+
+ IntPtr authPtr = XauGetAuthByAddr ((ushort)AddressFamily.Unix, (ushort) 5, "rover", 1, "1");
+ Trace.WriteLine ("authPtr: " + authPtr);
+
+ authinfo = new AuthInfo ();
+ }
+
+ //TODO
+ public static AuthInfo GetAuthInfo (Socket sock)
+ {
+ return new AuthInfo ();
+ }
+
+ public AuthInfo GetAuthInfo (int fd)
+ {
+ string sockName = "";
+ IntPtr authPtr = GetAuthPtr (sockName);
+
+ //return null;
+ return new AuthInfo ();
+ }
+
+ string[] authnames = {"MIT-MAGIC-COOKIE-1"};
+
+ [DllImport ("Xau")]
+ //[return: MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Mono.Unix.Native.FileNameMarshaler))]
+ //static extern string XauFileName ();
+ static extern IntPtr XauFileName ();
+ //[DllImport ("X11")]
+ [DllImport ("Xau")]
+ static extern IntPtr XauReadAuth (int fd);
+ //static extern IntPtr XauReadAuth (int fd);
+
+ [DllImport ("Xau")]
+ //Xauth *XauGetAuthByAddr (unsigned short family, unsigned short address_length, char *address, unsigned short number_length, char *number);
+ static extern IntPtr XauGetAuthByAddr (ushort family, ushort address_length, string address, ushort number_length, string number);
+
+ [DllImport ("Xau")]
+ //Xauth *XauGetBestAuthByAddr (unsigned short family, unsigned short address_length, char *address, unsigned short number_length, char *number, int types_length, char **types, int *type_lengths);
+ static extern IntPtr XauGetBestAuthByAddr (ushort family, ushort address_length, string address, ushort number_length, string number, int types_length, string[] types, int[] type_lengths);
+
+ public IntPtr GetAuthPtr (string sockName)
+ {
+ int[] authnamelens = new int[authnames.Length];
+
+ for (int i = 0 ; i != authnames.Length ; i++)
+ authnamelens[i] = authnames[i].Length;
+
+ IntPtr authPtr = XauGetBestAuthByAddr (0, 0, "", 0, "", authnames.Length, authnames, authnamelens);
+
+ return authPtr;
+ }
+ }
+
+ //TODO: maybe this is an IMessagePart?
+ [StructLayout (LayoutKind.Sequential, CharSet=CharSet.Ansi)]
+ public struct AuthInfo
+ {
+ public int NameLen;
+ public string Name;
+ public int DataLen;
+ //public byte[] Data;
+ public IntPtr Data;
+ }
+}
+
34 acceptance-tests-ifolder/xnb/Auxiliary.cs
View
@@ -0,0 +1,34 @@
+using System;
+using System.Diagnostics;
+
+namespace Xnb
+{
+ using Protocol.Xnb;
+
+ public static class Aux
+ {
+ public static byte GetDepth (Connection c, Screen screen)
+ {
+ //Drawable drawable;
+
+ //drawable.Window = screen.Root;
+
+ return 0;
+ }
+
+ public static Screen GetScreen (Connection c, int screen)
+ {
+ //foreach (Screen s in c.Setup.Roots) {}
+
+ //Trace.WriteLine (c.Setup.Roots.Length);
+ //return c.Setup.Roots[screen];
+
+ return new Screen ();
+ }
+
+ public static Visualtype GetVisualtype (Connection c, int scr, uint vid)
+ {
+ return new Visualtype ();
+ }
+ }
+}
24 acceptance-tests-ifolder/xnb/COPYING
View
@@ -0,0 +1,24 @@
+The MIT X11 License covers the files in Xnb
+
+
+Copyright (c) 2006 Alp Toker
+Parts Copyright (c) The Xcb Project
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
150 acceptance-tests-ifolder/xnb/CodeWriter.cs
View
@@ -0,0 +1,150 @@
+using System;
+using System.IO;
+
+class CodeWriter
+{
+ enum Language
+ {
+ CSharp, C,
+ }
+
+ private StreamWriter w;
+
+ public CodeWriter (string fname)
+ {
+ Init (fname);
+ }
+
+ Language lang;
+
+ Language LanguageForExtension (string ext)
+ {
+ switch (ext) {
+ case ".h":
+ case ".c":
+ return Language.C;
+ case ".cs":
+ default:
+ return Language.CSharp;
+ }
+ }
+
+ void Init (string fname)
+ {
+ if (File.Exists (fname)) {
+ File.Delete (fname);
+ }
+
+ lang = LanguageForExtension (Path.GetExtension (fname));
+
+ switch (lang) {
+ case Language.C:
+ Indenter = " ";
+ break;
+
+ case Language.CSharp:
+ default:
+ Indenter = "\t";
+ break;
+ }
+
+ FileStream fs = new FileStream (fname, FileMode.OpenOrCreate, FileAccess.Write);
+ w = new StreamWriter (fs);
+
+ if (lang == Language.CSharp) {
+ w.WriteLine ("//------------------------------------------------------------------------------");
+ w.WriteLine ("// <auto-generated>");
+ w.WriteLine ("// This code was generated by a tool.");
+ w.WriteLine ("// </auto-generated>");
+ w.WriteLine ("//------------------------------------------------------------------------------");
+ w.WriteLine ();
+ } else {
+ WriteComment ("This code was generated by a tool.");
+ }
+
+ }
+
+ public string Indenter = "\t";
+ string cur_indent = "";
+ int level = 0;
+
+ public void Indent ()
+ {
+ level++;
+ cur_indent = "";
+ for (int i = 0; i != level ; i++) cur_indent += Indenter;
+ }
+
+ public void Unindent ()
+ {
+ level--;
+ cur_indent = "";
+ for (int i = 0; i != level ; i++) cur_indent += Indenter;
+ }
+
+ public void Write (string text)
+ {
+ w.Write (text);
+ }
+
+ public void WriteLine (string text)
+ {
+ WriteLine (text, true);
+ }
+
+ public void WriteLine (string text, bool autoindent)
+ {
+ char[] opentags = {'{', '('};
+ char[] closetags = {'}', ')'};
+
+ if (autoindent && text.TrimStart (closetags) != text)
+ Unindent ();
+
+ if (!text.StartsWith ("#"))
+ w.Write (cur_indent);
+
+ w.WriteLine (text);
+
+ if (autoindent && text.TrimEnd (opentags) != text)
+ Indent ();
+ }
+
+ public void WriteLine (string text, params CodeWriter[] ccs)
+ {
+ foreach (CodeWriter cc in ccs)
+ WriteLine (text, "", cc, "");
+ }
+
+ public void WriteLine (string text, CodeWriter cc, string suffix)
+ {
+ WriteLine (text, "", cc, suffix);
+ }
+
+ public void WriteLine (string text, string prefix, CodeWriter cc)
+ {
+ WriteLine (text, prefix, cc, "");
+ }
+
+ public void WriteLine (string text, string prefix, CodeWriter cc, string suffix)
+ {
+ WriteLine (text);
+ cc.WriteLine (prefix + text + suffix);
+ }
+
+ public void WriteComment (string text)
+ {
+ w.WriteLine ("/* " + text + " */");
+ }
+
+ public void WriteLine ()
+ {
+ w.WriteLine ("");
+ }
+
+ public void Close ()
+ {
+ w.Flush ();
+ w.Close ();
+ }
+}
+
221 acceptance-tests-ifolder/xnb/Connection.cs
View
@@ -0,0 +1,221 @@
+using System;
+using System.Diagnostics;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Net.Sockets;
+
+using System.Runtime.InteropServices;
+
+using Mono.Unix;
+using Mono.Unix.Native;
+
+namespace Xnb
+{
+ using Protocol.Xnb;
+
+ public class Connection
+ {
+ public const int X_PROTOCOL = 11;
+ public const int X_PROTOCOL_REVISION = 0;
+ const int X_TCP_PORT = 6000;
+ //TODO: get this from environment? windows?
+ const string BASE = "/tmp/.X11-unix/X";
+
+ public Connection (int display) : this (null, display) {}
+
+ public Connection (string host, int display)
+ {
+ string hst;
+ int dpy, scr;
+
+ Trace.Listeners.Add (new TextWriterTraceListener (Console.Error));
+
+ ParseDisplay (null, out hst, out dpy, out scr);
+ sock = Open (hst, dpy);
+
+ //Auth.Xauth auth = Auth.Xau.GetAuthByAddr (sock.RemoteEndPoint.Serialize (), "0");
+ Auth.Xauth auth = Auth.Xau.GetAuthByHack (hst, dpy);
+ ConnectToSocket (sock, auth);
+ }
+
+ public XResponseReader xrr;
+ public XWriter xw;
+
+ //TODO: take into account given values (ref), unit tests
+ bool ParseDisplay (string name, out string host, out int display, out int screen)
+ {
+ host = null;
+ display = 0;
+ screen = 0;
+
+ if (name == null)
+ name = System.Environment.GetEnvironmentVariable ("DISPLAY");
+
+ if (name == null)
+ return false;
+
+ string[] parts = name.Split (':');
+
+ if (parts.Length > 2)
+ return false;
+
+ if (parts.Length < 1)
+ return false;
+
+ if (parts[0] != "")
+ host = parts[0];
+
+ if (parts.Length < 2)
+ return true;
+
+ parts = parts[1].Split ('.');
+
+ if (parts.Length > 2)
+ return false;
+
+ if (parts.Length < 1)
+ return true;
+
+ if (parts[0] != "")
+ display = Int32.Parse (parts[0]);
+
+ if (parts.Length < 2)
+ return true;
+
+ if (parts[1] != "")
+ screen = Int32.Parse (parts[1]);
+
+ return true;
+ }
+
+ Socket Open (string host, int display)
+ {
+ if (host != null) {
+ int port = X_TCP_PORT + display;
+ return OpenTCP (host, port);
+ } else {
+ string path = BASE + display;
+ return OpenUnix (path);
+ }
+ }
+
+ NetworkStream stream = null;
+
+ TcpClient tcpClient = null;
+ Socket OpenTCP (string host, int port)
+ {
+ TcpClient tc = new TcpClient (host, port);
+ tcpClient = tc;
+ //Socket client = new Socket (AddressFamily.InterNetwork, SocketType.Stream, 0);
+
+ return tc.Client;
+ }
+
+ Socket sock;
+ UnixEndPoint remoteEndPoint;
+
+ Socket OpenUnix (string path)
+ {
+ Socket client = new Socket (AddressFamily.Unix, SocketType.Stream, 0);
+ //UnixEndPoint remoteEndPoint = new UnixEndPoint (path);
+ remoteEndPoint = new UnixEndPoint (path);
+ client.Connect (remoteEndPoint);
+
+ return client;
+ }
+
+ public void ConnectToSocket (Socket sock, Auth.Xauth auth_info)
+ {
+ sock.Blocking = false;
+
+ xrr = new XResponseReader (stream);
+ xw = new XWriter (stream);
+ xrr.sock = sock;
+ xw.sock = sock;
+ xrr.fd = (int)sock.Handle;
+ xw.fd = (int)sock.Handle;
+
+ WriteSetup (auth_info);
+ ReadSetup ();
+ }
+
+ public int GenerateId ()
+ {
+ return 0;
+ }
+
+ ConnSetupSuccessRep setup = null;
+
+ public ConnSetupSuccessRep Setup
+ {
+ get {
+ if (setup != null)
+ return setup;
+
+ return null;
+
+ /*
+ int sz = 153*4;
+
+ for (int i = 0 ; i != sz ; i++) {
+ byte b = Marshal.ReadByte (ptr, i);
+ Trace.WriteLine (i + " : " + b);
+ }
+ */
+
+ //setup = new ConnSetupSuccessRep ();
+ //setup.Read (ptr);
+
+ return setup;
+ }
+ }
+
+ private const int FD_CLOEXEC = 1;
+ void SetFDFlags (int fd)
+ {
+ /*
+ OpenFlags flags = (OpenFlags) Syscall.fcntl (fd, FcntlCommand.F_GETFL, (long)0);
+ flags |= OpenFlags.O_NONBLOCK;
+ //flags |= OpenFlags.O_SYNC;
+ Syscall.fcntl (fd, FcntlCommand.F_SETFL, (long)flags);
+ //Syscall.fcntl (fd, FcntlCommand.F_SETFD, FD_CLOEXEC);
+
+ OpenFlags flags = (OpenFlags) Syscall.fcntl (fd, FcntlCommand.F_GETFD, (long)0);
+ */
+ Syscall.fcntl (fd, FcntlCommand.F_SETFD, FD_CLOEXEC); //FD_CLOEXEC = 1
+ }
+
+ void WriteSetup (Auth.Xauth auth_info)
+ {
+ ConnSetupReq o = new ConnSetupReq ();
+
+ /* B = 0x42 = MSB first, l = 0x6c = LSB first */
+ //MSB
+ //o.ByteOrder = 0x42;
+ //LSB
+ //o.ByteOrder = 0x6c;
+ o.ByteOrder = 0x6c;
+ o.ProtocolMajorVersion = X_PROTOCOL;
+ o.ProtocolMinorVersion = X_PROTOCOL_REVISION;
+
+ if (auth_info != null) {
+ o.AuthorizationProtocolNameLen = (ushort)auth_info.Name.Length;
+ o.AuthorizationProtocolDataLen = (ushort)auth_info.Data.Length;
+
+ o.AuthorizationProtocolName = auth_info.Name;
+ o.AuthorizationProtocolData = auth_info.Data;
+ }
+
+ xw.Send (o, false);
+ }
+
+ void ReadSetup ()
+ {
+ //ConnSetupFailedRep frep = new ConnSetupFailedRep ();
+ //setup = new ConnSetupSuccessRep ();
+ xrr.ReadSetupResponse ();
+ setup = xrr.succ;
+ }
+ }
+}
92 acceptance-tests-ifolder/xnb/Extension.cs
View
@@ -0,0 +1,92 @@
+using System;
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using Mono.Unix;
+
+namespace Xnb
+{
+ using Protocol.Xnb;
+ using Protocol.XProto;
+
+ [StructLayout (LayoutKind.Explicit, Pack=1, Size=4)]
+ public struct Request
+ {
+ [FieldOffset(0)]
+ public byte Opcode;
+ //[FieldOffset(1)]
+ //public byte Data;
+ [FieldOffset(2)]
+ public ushort Length;
+ }
+
+ [StructLayout (LayoutKind.Explicit, Pack=1, Size=4)]
+ public struct ExtensionRequest
+ {
+ [FieldOffset(0)]
+ public byte MajorOpcode;
+ [FieldOffset(1)]
+ public byte MinorOpcode;
+ [FieldOffset(2)]
+ public ushort Length;
+ }
+
+ public abstract class Extension
+ {
+ protected Extension () {}
+
+ protected Connection c;
+ public Connection Connection
+ {
+ get {
+ return c;
+ }
+ }
+
+ public abstract string XName {get;}
+
+ public byte GlobalId = 0;
+
+ public void Init (Connection connection)
+ {
+ c = connection;
+
+ //no extension
+ if (XName == "")
+ return;
+
+ XProto xp = new XProto ();
+ xp.Init (c);
+
+ //QueryExtensionReply rep = xp.QueryExtension ((ushort)XName.Length, XName);
+ Cookie<QueryExtensionReply> repCookie = xp.QueryExtension ((ushort)XName.Length, XName);
+ //QueryExtensionReply rep = new QueryExtensionReply ();
+ //repCookie.ReadReply (rep);
+
+ QueryExtensionReply rep = repCookie;
+ //req.Length = 2 + (7+1)/4; //4 + 10;
+
+ GlobalId = rep.MajorOpcode;
+
+ Trace.WriteLine ("Extension present: " + rep.Present + ", major opcode " + rep.MajorOpcode);
+ //Trace.WriteLine (rep.FirstEvent);
+ //Trace.WriteLine (rep.FirstError);
+ }
+ }
+
+ [StructLayout (LayoutKind.Explicit, Pack=1, CharSet=CharSet.Ansi)]
+ public struct Id
+ {
+ [FieldOffset (0)]
+ private uint Value;
+
+ public Id (uint value)
+ {
+ this.Value = value;
+ }
+
+ public static implicit operator uint (Id x)
+ {
+ return x.Value;
+ }
+ }
+}
1,003 acceptance-tests-ifolder/xnb/Generator.cs
View
@@ -0,0 +1,1003 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+using Mono.GetOptions;
+
+using Schemas;
+
+public class XnbGenOptions : Options
+{
+ public XnbGenOptions (string[] args) : base (args) {}
+
+ [Option("Reference", 'r', "ref")]
+ //public string[] References;
+ public string Reference;
+
+ [Option("Output name", 'o', "out")]
+ public string OutName;
+
+ //[Option("Xcb spec xml input", 'r', "ref")]
+ //public string XcbSpec;
+}
+
+public class Driver
+{
+ public static int Main (string[] args)
+ {
+ XnbGenOptions opts = new XnbGenOptions (args);
+ string[] srcFiles = opts.RemainingArguments;
+
+ LoadTypeMap ("TypeMap");
+
+ //foreach (string srcRef in opts.References)
+ // LoadTypeMap (srcRef + ".TypeMap");
+
+ LoadTypeMap (opts.Reference + "TypeMap");
+
+ foreach (string src in srcFiles) {
+ Generate (src, opts.OutName);
+ SaveTypeMap (opts.OutName + "TypeMap");
+ }
+
+ return 0;
+ }
+
+ static bool isExtension;
+ static string extName;
+
+ //FIXME: refactor name
+ static CodeWriter cw;
+ static CodeWriter cwt;
+ static CodeWriter cwi;
+
+ public static void Generate (string fname, string name)
+ {
+ StreamReader sr = new StreamReader (fname);
+ XmlSerializer sz = new XmlSerializer (typeof (xcb));
+ xcb xcb = (xcb)sz.Deserialize (sr);
+
+ extName = xcb.extensionxname == null ? "" : xcb.extensionxname;
+ isExtension = extName != "";
+
+ cw = new CodeWriter (name + ".cs");
+ cwt = new CodeWriter (name + "Types.cs");
+ cwi = new CodeWriter (name + "Iface.cs");
+
+ cw.WriteLine ("using System;", cwt, cwi);
+ cw.WriteLine ("using System.Collections;", cwt);
+ cw.WriteLine ("using System.Collections.Generic;", cwt);
+ cw.WriteLine ("using System.Runtime.InteropServices;", cwt);
+ cw.WriteLine ("using Mono.Unix;", cwt);
+ cw.WriteLine ("using Xnb.Protocol." + "Xnb" + ";", cwt);
+ cw.WriteLine ("using Xnb.Protocol." + "XProto" + ";", cwt);
+ cw.WriteLine ("", cwt, cwi);
+ //cw.WriteLine ("namespace Xnb", cwt);
+
+ cw.WriteLine ("namespace Xnb");
+ cwt.WriteLine ("namespace Xnb.Protocol." + name);
+
+ cw.WriteLine ("{", cwt);
+ cw.WriteLine ("using Protocol." + name + ";");
+ cw.WriteLine ("public class " + name + " : Extension");
+ cwi.WriteLine ("public interface I" + name);
+ cw.WriteLine ("{", cwi);
+ cw.WriteLine ("public override string XName");
+ cw.WriteLine ("{");
+ cw.WriteLine ("get {");
+ cw.WriteLine ("return \"" + extName + "\";");
+ cw.WriteLine ("}");
+ cw.WriteLine ("}");
+ cw.WriteLine ();
+
+ cwt.WriteLine ("#pragma warning disable 0169, 0414");
+
+ foreach (object o in xcb.Items) {
+ if (o == null)
+ continue;
+ else if (o is @xidtype)
+ GenXidType (o as @xidtype);
+ else if (o is @errorcopy)
+ GenErrorCopy (o as @errorcopy);
+ else if (o is @eventcopy)
+ GenEventCopy (o as @eventcopy);
+ else if (o is @struct)
+ GenStruct (o as @struct);
+ else if (o is @union)
+ GenUnion (o as @union);
+ else if (o is @enum)
+ GenEnum (o as @enum);
+ else if (o is @event)
+ GenEvent (o as @event, name);
+ else if (o is @request) {
+ GenRequest (o as @request, name);
+ GenFunction (o as @request, name);
+ } else if (o is @error)
+ GenError (o as @error, name);
+ }
+
+ cwt.WriteLine ("#pragma warning restore 0169, 0414");
+
+ cwi.WriteLine ("}");
+ cw.WriteLine ("}");
+ cw.WriteLine ("}", cwt);
+
+ cw.Close ();
+ cwt.Close ();
+ cwi.Close ();
+ }
+
+ static void GenXidType (@xidtype x)
+ {
+ if (x.name == null)
+ return;
+
+ /*
+ field f = new field ();
+ f.type = "CARD32";
+ f.name = "Id";
+
+ field[] xItems = new field[1];
+ xItems[0] = f;
+
+ GenClass (NewTypeToCs (x.name), xItems);
+ */
+
+ string xName = NewTypeToCs (x.name, "Id");
+
+ cwt.WriteLine ("[StructLayout (LayoutKind.Explicit, Pack=1, CharSet=CharSet.Ansi)]");
+ cwt.WriteLine ("public struct " + xName);
+ idMap.Add (xName, "uint");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("[FieldOffset (0)]");
+ cwt.WriteLine ("private uint Value;");
+ cwt.WriteLine ();
+ cwt.WriteLine ("public " + xName + " (uint value)");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("this.Value = value;");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ cwt.WriteLine ("public static implicit operator uint (" + xName + " x)");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("return x.Value;");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ cwt.WriteLine ("public static implicit operator Id (" + xName + " x)");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("return new Id (x);");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ //TODO: generalize
+ if (xName == "AtomId") {
+ cwt.WriteLine ("public static implicit operator " + xName + " (" + "Atom" + "Type" + " xt)");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("return new " + xName + " ((uint)xt);");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ }
+ /*
+ cwt.WriteLine ("public static explicit operator " + xName + " (uint xid)");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("return new " + xName + " (xid);");
+ cwt.WriteLine ("}");
+ */
+
+ cwt.WriteLine ("public static explicit operator " + xName + " (Id x)");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("return new " + xName + " (x);");
+ cwt.WriteLine ("}");
+
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ }
+
+ static void GenEventCopy (@eventcopy e)
+ {
+ if (e.name == null)
+ return;
+
+ cwt.WriteLine ("[Event (" + e.number + ")]");
+ GenClass (NewTypeToCs (ToCs (e.name) + "Event"), null, " : " + ToCs (e.@ref) + "Event");
+ }
+
+ static void GenErrorCopy (@errorcopy e)
+ {
+ if (e.name == null)
+ return;
+
+ cwt.WriteLine ("[Error (" + e.number + ")]");
+ GenClass (NewTypeToCs (ToCs (e.name) + "Error"), null, " : " + ToCs (e.@ref) + "Error");
+ }
+
+ static void GenError (@error e, string name)
+ {
+ if (e.name == null)
+ return;
+
+ cwt.WriteLine ("[Error (" + e.number + ")]");
+ //GenClass (NewTypeToCs (ToCs (e.name) + "Error"), e.field, " : " + "Error");
+ GenClass (NewTypeToCs (TypeToCs (e.name) + "Error"), e.field);
+ }
+
+ static void GenEvent (@event e, string name)
+ {
+ if (e.name == null)
+ return;
+
+ cwt.WriteLine ("[Event (" + e.number + ")]");
+ //GenClass (NewTypeToCs (ToCs (e.name) + "Event"), eItem, " : " + "Event");
+ GenClass (NewTypeToCs (ToCs (e.name) + "Event"), e.Items, " : " + "EventArgs");
+
+ cw.WriteLine ("public event " + "EventHandler<" + (ToCs (e.name) + "Event") + "> " + (ToCs (e.name) + "Event") + ";");
+ cw.WriteLine ();
+ }
+
+ static void GenRequest (@request r, string name)
+ {
+ if (r.name == null)
+ return;
+
+ string inherits;
+ if (isExtension)
+ inherits = "ExtensionRequest";
+ else
+ inherits = "Request";
+
+ cwt.WriteLine ("[Request (" + r.opcode + ")]");
+ GenClass (NewTypeToCs (ToCs (r.name) + "Request"), r.Items);
+
+ if (r.reply != null) {
+ cwt.WriteLine ("[Reply (" + r.opcode + ")]");
+ //GenClass (NewTypeToCs (ToCs (r.name) + "Reply"), r.reply.Items, " : " + "Reply");
+ GenClass (NewTypeToCs (ToCs (r.name) + "Reply"), r.reply.Items);
+ }
+ }
+
+ static void GenFunction (@request r, string name)
+ {
+ if (r.name == null)
+ return;
+
+ //TODO: share code with struct
+ string parms = "";
+ List<string> parmList1 = new List<string> ();
+ List<string> parmList2 = new List<string> ();
+ if (r.Items != null) {
+
+ foreach (object ob in r.Items) {
+ if (ob is field) {
+ field f = ob as field;
+ if (f.name == null)
+ continue;
+
+ //if (f.name.EndsWith ("_len"))
+ // continue;
+
+ parms += ", " + TypeToCs (f.type) + " @" + ToParm (ToCs (f.name));
+ parmList1.Add (ToCs (f.name));
+ } else if (ob is list) {
+ list l = ob as list;
+ if (l.name == null)
+ continue;
+ if (l.type == "char") {
+ parms += ", " + "string" + " @" + ToParm (ToCs (l.name));
+ parmList2.Add (ToCs (l.name));
+ } else if (l.type == "CARD32") {
+ parms += ", " + "uint[]" + " @" + ToParm (ToCs (l.name));
+ parmList2.Add (ToCs (l.name));
+ }
+ } else if (ob is valueparam) {
+ valueparam v = ob as valueparam;
+ string vName = "Values";
+
+ if (v.valuelistname != null)
+ vName = ToCs (v.valuelistname);
+
+ string vType = TypeToCs (v.valuemasktype);
+
+ if (vType == "uint") {
+ parms += ", " + "uint[]" + " @" + ToParm (vName);
+ parmList2.Add (vName);
+ }
+ }
+ }
+
+ parms = parms.Trim (',', ' ');
+ }
+
+ /*
+ if (r.reply != null)
+ cw.WriteLine ("[Reply (typeof (" + ToCs (r.name) + "Reply" + "))]");
+ cw.WriteLine ("public void " + ToCs (r.name) + " (" + parms + ")");
+ */
+
+ if (r.reply != null)
+ cw.WriteLine ("public " + "Cookie<" + ToCs (r.name) + "Reply" + ">" + " " + ToCs (r.name) + " (" + parms + ")", cwi, ";");
+ else
+ cw.WriteLine ("public " + "void" + " " + ToCs (r.name) + " (" + parms + ")", cwi, ";");
+
+ cw.WriteLine ("{");
+
+ //cw.WriteLine ("ProtocolRequest req = new ProtocolRequest ();");
+ /*
+ cw.WriteLine ("req.Count = " + 2 + ";");
+ cw.WriteLine ("req.Extension = " + 0 + ";");
+ cw.WriteLine ("req.Opcode = " + r.opcode + ";");
+ cw.WriteLine ("req.IsVoid = " + (r.reply == null ? "1" : "0") + ";");
+ */
+ /*
+ cw.WriteLine ("req.Opcode = " + r.opcode + ";");
+ cw.WriteLine ("req.Data = " + 0 + ";");
+ cw.WriteLine ("req.Length = " + 4 + ";");
+ cw.WriteLine ();
+ */
+
+ cw.WriteLine ("" + ToCs (r.name) + "Request req = new " + ToCs (r.name) + "Request ();");
+
+ if (isExtension) {
+ cw.WriteLine ("req.MessageData.ExtHeader.MajorOpcode = GlobalId;");
+ cw.WriteLine ("req.MessageData.ExtHeader.MinorOpcode = " + r.opcode + ";");
+ } else {
+ cw.WriteLine ("req.MessageData.Header.Opcode = " + r.opcode + ";");
+ }
+ cw.WriteLine ();
+
+ /*
+ if (r.Items != null)
+ foreach (object ob in r.Items) {
+ if (ob is field) {
+ field f = ob as field;
+ if (f.name != null) {
+ if (f.name == "roots")
+ Console.Error.WriteLine (f.type);
+ cw.WriteLine ("req.MessageData.@" + ToCs (f.name) + " = @" + ToParm (ToCs (f.name)) + ";");
+ }
+ }
+ }
+ */
+ foreach (string par in parmList1)
+ cw.WriteLine ("req.MessageData.@" + par + " = @" + ToParm (par) + ";");
+
+ foreach (string par in parmList2)
+ cw.WriteLine ("req.@" + par + " = @" + ToParm (par) + ";");
+
+ /*
+ cw.WriteLine ("unsafe {");
+ //cw.WriteLine (ToCs (r.name) + "RequestData* dp;");
+ cw.WriteLine ("fixed (" + ToCs (r.name) + "RequestData* dp = &req.MessageData) {");
+ cw.WriteLine ("c.Send ((IntPtr)dp, sizeof (" + ToCs (r.name) + "RequestData" + "));");
+ cw.WriteLine ("}");
+ cw.WriteLine ("}");
+ cw.WriteLine ("IntPtr ptr;");
+ */
+
+ if (r.Items != null)
+ foreach (object ob in r.Items) {
+ if (ob is list) {
+ list l = ob as list;
+ if (l.name == null)
+ continue;
+ if (l.type != "char")
+ continue;
+
+ /*
+ cw.WriteLine ();
+ cw.WriteLine ("ptr = UnixMarshal.StringToHeap (@" + ToParm (ToCs (l.name)) + ");");
+ cw.WriteLine ("c.Send (ptr, @" + ToParm (ToCs (l.name)) + ".Length);");
+ */
+ cw.WriteLine ("req.@" + ToCs (l.name) + " = @" + ToParm (ToCs (l.name)) + ";");
+ }
+ }
+
+ cw.WriteLine ();
+ cw.WriteLine ("c.xw.Send (req);");
+ cw.WriteLine ();
+
+ if (r.reply != null) {
+ cw.WriteLine ();
+ cw.WriteLine ("return c.xrr.GenerateCookie" + "<" + ToCs (r.name) + "Reply" + ">" + " ();");
+ }
+
+ cw.WriteLine ("}");
+ cw.WriteLine ();
+ }
+
+
+ static void GenEnum (@enum e)
+ {
+ if (e.name == null)
+ return;
+
+ cwt.WriteLine ("public enum " + ToCs (e.name) + " : uint");
+
+ cwt.WriteLine ("{");
+
+ foreach (item it in e.item) {
+ cwt.WriteLine (ToCs (it.name) + ",");
+ //cwt.WriteLine (ToCs (it.name) + " = " + it.op.value[0] + " " + it.op.op2 + " " + it.op.value[1] + ",");
+ }
+
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ }
+
+ static void GenUnion (@union u)
+ {
+ return;
+
+ //FIXME
+
+ if (u.name != null) {
+ //FIXME: Field offsets as 0
+ GenClass (NewTypeToCs (u.name), u.Items);
+ }
+ }
+
+
+ static void GenStruct (@struct s)
+ {
+ if (s.name == null)
+ return;
+
+ //FIXME: just check to see if it contains complex (list etc.) values instead of this
+ basic = true;
+ if (s.name.EndsWith ("Rep"))
+ basic = false;
+ if (s.name.EndsWith ("Req"))
+ basic = false;
+ if (s.name == "DEPTH")
+ basic = false;
+ if (s.name == "SCREEN")
+ basic = false;
+ if (s.name == "STR")
+ basic = false;
+ if (s.name == "HOST")
+ basic = false;
+ GenClass (NewTypeToCs (s.name), s.Items);
+ basic = false;
+ }
+
+ static void GenClass (string sName, object[] sItems)
+ {
+ GenClass (sName, sItems, "");
+ }
+
+ //FIXME: needs to know about sizes of known structs
+ //FIXME: needs to know about Size=0 structs/unions
+ static int StructSize (object[] sItems)
+ {
+ if (sItems == null)
+ return 0;
+
+ int offset = 0;
+
+ foreach (object ob in sItems) {
+ if (ob is field) {
+ field f = ob as field;
+ string fType = TypeToCs (f.type);
+ offset += SizeOfType (fType);
+ } else if (ob is pad) {
+ pad p = ob as pad;
+
+ int padding = Int32.Parse (p.bytes);
+ offset += padding;
+ }
+ }
+
+ return offset;
+ }
+
+ static bool basic = false;
+ static void GenClass (string sName, object[] sItems, string suffix)
+ {
+ Dictionary<string,int> sizeParams = new Dictionary<string,int> ();
+
+ //bool basicStruct = false;
+ bool basicStruct = basic;
+
+ if (sName == "GContext")
+ basicStruct = true;
+
+ if (sName == "Drawable")
+ basicStruct = true;
+
+ if (sName == "Fontable")
+ basicStruct = true;
+
+ //if (sName == "ClientMessageData")
+ // basicStruct = true;
+
+ bool isRequest = sName.EndsWith ("Request");
+ bool isEvent = sName.EndsWith ("Event");
+
+ if (!basicStruct) {
+ int structSize = StructSize (sItems);
+ cwt.WriteLine ("[StructLayout (LayoutKind.Explicit, Pack=1, CharSet=CharSet.Ansi, Size=" + structSize + ")]");
+ cwt.WriteLine ("public struct @" + sName + "Data");
+ cwt.WriteLine ("{");
+ if (isRequest) { //TODO: generate one or the other
+ cwt.WriteLine ("[FieldOffset (0)]");
+ cwt.WriteLine ("public Request Header;");
+ cwt.WriteLine ("[FieldOffset (0)]");
+ cwt.WriteLine ("public ExtensionRequest ExtHeader;");
+ }
+ GenClassData (sName + "Data", sItems, "", true);
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ }
+
+ if (basicStruct) {
+ int structSize = StructSize (sItems);
+ cwt.WriteLine ("[StructLayout (LayoutKind.Explicit, Pack=1, CharSet=CharSet.Ansi, Size=" + structSize + ")]");
+ cwt.WriteLine ("public struct @" + sName + suffix);
+ } else {
+ //TODO: clean up hack
+ if (suffix == "")
+ suffix += " : ";
+ else
+ suffix += ", ";
+
+ suffix += "IMessagePart";
+ cwt.WriteLine ("public class @" + sName + suffix);
+ }
+ cwt.WriteLine ("{");
+ if (!basicStruct) {
+ cwt.WriteLine ("public " + sName + "Data" + " MessageData;");
+ }
+
+ int offset = GenClassData (sName, sItems, "", basicStruct);
+
+ if (!basicStruct) {
+ //cwt.WriteLine ("public byte[] dat;");
+ /*
+ cwt.WriteLine ("public int Read (IntPtr ptr)");
+ cwt.WriteLine ("{");
+ //cwt.WriteLine ("MessageData = (" + sName + "Data" + ")Marshal.PtrToStructure (ptr, typeof(" + sName + "Data" + "));");
+ cwt.WriteLine ("unsafe {");
+ cwt.WriteLine ("MessageData = *(" + sName + "Data" + "*)ptr;");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ("return 0;");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ */
+ cwt.WriteLine ("public int Read (IntPtr ptr)");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("int offset = 0;");
+ cwt.WriteLine ("unsafe {");
+ cwt.WriteLine ("MessageData = *(" + sName + "Data" + "*)ptr;");
+ cwt.WriteLine ("offset += sizeof (" + sName + "Data" + ");");
+ cwt.WriteLine ("}");
+
+ if (sItems != null)
+ foreach (object ob in sItems) {
+ if (ob is list) {
+ list l = ob as list;
+
+ string lName = ToCs (l.name);
+ string lType = TypeToCs (l.type);
+ if (lName == sName) {
+ Console.Error.WriteLine ("Warning: list field renamed: " + lName);
+ lName = "Values";
+ }
+ if (l.type == "CHAR2B" || lType == "sbyte") {
+ cwt.WriteLine ("//if (@" + lName + " != null)");
+ cwt.WriteLine ("//yield return XMarshal.Do (@" + lName + ");");
+ //cwt.WriteLine (lName + " = Marshal.PtrToStringAnsi (new IntPtr ((int)ptr + offset), MessageData.@" + ToCs (l.fieldref) + ");");
+ cwt.WriteLine ("//" + lName + " = Marshal.PtrToStringAnsi (new IntPtr ((int)ptr + offset), MessageData.@" + (lName + "Len") + ");");
+ cwt.WriteLine ("//offset += " + (lName + "Len") + ";");
+ }
+
+ } else if (ob is valueparam) {
+ valueparam v = ob as valueparam;
+ string vName = "Values";
+
+ if (v.valuelistname != null)
+ vName = ToCs (v.valuelistname);
+
+ string vType = TypeToCs (v.valuemasktype);
+
+ if (vType == "uint") {
+ cwt.WriteLine ("//if (@" + vName + " != null)");
+ cwt.WriteLine ("//yield return XMarshal.Do (ref @" + vName + ");");
+ }
+ }
+ }
+
+ cwt.WriteLine ("return offset;");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+
+
+ cwt.WriteLine ("IEnumerator IEnumerable.GetEnumerator () { return GetEnumerator (); }");
+ cwt.WriteLine ();
+ cwt.WriteLine ("public IEnumerator<IOVector> GetEnumerator ()");
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("yield return XMarshal.Do (ref MessageData);");
+
+ if (sItems != null)
+ foreach (object ob in sItems) {
+ if (ob is list) {
+ list l = ob as list;
+
+ string lName = ToCs (l.name);
+ string lType = TypeToCs (l.type);
+ if (lName == sName) {
+ Console.Error.WriteLine ("Warning: list field renamed: " + lName);
+ lName = "Values";
+ }
+ if (l.type == "CHAR2B" || lType == "sbyte" || lType == "byte") {
+ cwt.WriteLine ("if (@" + lName + " != null)");
+ cwt.WriteLine ("yield return XMarshal.Do (ref @" + lName + ");");
+ }
+ } else if (ob is valueparam) {
+ valueparam v = ob as valueparam;
+ string vName = "Values";
+
+ if (v.valuelistname != null)
+ vName = ToCs (v.valuelistname);
+
+ string vType = TypeToCs (v.valuemasktype);
+
+ if (vType == "uint") {
+ cwt.WriteLine ("if (@" + vName + " != null)");
+ cwt.WriteLine ("yield return XMarshal.Do (ref @" + vName + ");");
+ }
+ }
+ }
+
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ }
+
+ if (sItems != null)
+ foreach (object ob in sItems) {
+ if (ob is list) {
+ list l = ob as list;
+
+ string lName = ToCs (l.name);
+ if (lName == sName) {
+ Console.Error.WriteLine ("Warning: list field renamed: " + lName);
+ lName = "Values";
+ }
+
+ string lType = TypeToCs (l.type);
+ //cwt.WriteLine ("//" + l.type);
+ if (!sizeParams.ContainsKey (l.name)) {
+ Console.Error.WriteLine ("Warning: No length given for " + lName);
+ cwt.WriteLine ("//FIXME: No length given");
+ } else {
+ if (l.type == "CHAR2B" || lType == "sbyte")
+ cwt.WriteLine ("//[MarshalAs (UnmanagedType.LPStr, SizeParamIndex=" + sizeParams[l.name] + ")]");
+ else
+ cwt.WriteLine ("[MarshalAs (UnmanagedType.LPArray, SizeParamIndex=" + sizeParams[l.name] + ")]");
+ }
+ ////cwt.WriteLine ("//public " + lType + "[]" + " @" + lName + ";");
+ //cwt.WriteLine ("[FieldOffset (" + offset + ")]");
+ ////cwt.WriteLine ("//public ValueList<" + lType + ">" + " @" + lName + ";");
+ if (l.type == "CHAR2B" || lType == "sbyte")
+ cwt.WriteLine ("public " + "string" + " @" + lName + ";");
+ else
+ cwt.WriteLine ("public " + lType + "[]" + " @" + lName + ";");
+
+ offset += 4;
+ } else if (ob is valueparam) {
+ valueparam v = ob as valueparam;
+ string vName = "Values";
+
+ if (v.valuelistname != null)
+ vName = ToCs (v.valuelistname);
+
+ string vType = TypeToCs (v.valuemasktype);
+ //cwt.WriteLine ("[FieldOffset (" + offset + ")]");
+ //cwt.WriteLine ("public ValueList<" + TypeToCs (v.valuemasktype) + "> @" + "Values" + ";");
+ cwt.WriteLine ("//public ValueList<" + vType + "> @" + vName + ";");
+ cwt.WriteLine ("public " + vType + "[] @" + vName + ";");
+ offset += 4;
+ }
+ }
+ cwt.WriteLine ("}");
+ cwt.WriteLine ();
+ }
+
+ static int GenClassData (string sName, object[] sItems, string suffix, bool withOffsets)
+ {
+ string sizeString = "";
+
+ //FIXME: EndsWith hack
+ bool isRequest = sName.EndsWith ("RequestData");
+ bool isEvent = sName.EndsWith ("EventData");
+ bool isError = sName.EndsWith ("ErrorData");
+ //FIXME: Rep shouldn't have offsets/inherits
+ bool isReply = sName.EndsWith ("ReplyData");
+
+ bool isStruct = (!isRequest && !isEvent && !isError && !isReply && !sName.EndsWith ("RepData"));
+
+
+ if (sName.EndsWith ("EventData") || sName.EndsWith ("ErrorData"))
+ sizeString = ", Size=" + 28;
+
+ //FIXME: incorrect hack
+ //if (sName.EndsWith ("Reply"))
+ // sizeString = ", Size=" + 32;
+
+ //sName = NewTypeToCs (sName);
+ //FIXME: figure out actual size first
+
+ //if (isStruct)
+ //cwt.WriteLine ("public struct @" + sName);
+ //else
+ // cwt.WriteLine ("public class @" + sName + suffix);
+
+ //cwt.WriteLine ("{");
+
+ Dictionary<string,int> sizeParams = new Dictionary<string,int> ();
+
+ int index = 0, offset = 0;
+
+ if (sItems != null) {
+
+ if (isRequest)
+ offset += 4;
+
+ if (isError || isEvent)
+ offset += 4;
+
+ if (isReply && !sName.EndsWith ("RepData"))
+ offset += 8;
+
+ bool first = true;
+
+ foreach (object ob in sItems) {
+ //bool isData = (offset == startOffset) && (isReply || (isRequest && !isExtension));
+ bool isData = first && (isReply || (isRequest && !isExtension));
+ first = false;
+
+ if (ob is field) {
+ field f = ob as field;
+ if (f.name != null) {
+ string fName = ToCs (f.name);
+ if (fName == sName || fName + "Data" == sName) {
+ Console.Error.WriteLine ("Warning: field renamed: " + fName);
+ fName = "Value";
+ }
+
+ string fType = TypeToCs (f.type);
+
+ //in non-extension requests, the data field carries the first element
+ if (withOffsets) {
+ if (isData)
+ cwt.WriteLine ("[FieldOffset (" + 1 + ")]");
+ else {
+ cwt.WriteLine ("[FieldOffset (" + offset + ")]");
+ offset += SizeOfType (fType);
+ }
+ }
+
+ /*
+ //TODO: use fieldref
+ if (f.name.EndsWith ("_len")) {
+ string fNameArray = f.name.Substring (0, f.name.Length - 4);
+ sizeParams[fNameArray] = index;
+ cwt.WriteLine ("//TODO: private");
+ cwt.WriteLine ("//public " + fType + " @" + fName + ";");
+ } else {
+ */
+ if (withOffsets) {
+ cwt.WriteLine ("public " + fType + " @" + fName + ";");
+ } else {
+ cwt.WriteLine ("public " + fType + " @" + fName);
+ cwt.WriteLine ("{");
+ cwt.WriteLine ("get {");
+ cwt.WriteLine ("return MessageData.@" + fName + ";");
+ cwt.WriteLine ("} set {");
+ cwt.WriteLine ("MessageData.@" + fName + " = value;");
+ cwt.WriteLine ("}");
+ cwt.WriteLine ("}");
+ }
+ //}
+ index++;
+ }
+ } else if (ob is pad) {
+ if (!withOffsets)
+ continue;
+
+ pad p = ob as pad;
+
+ int padding = Int32.Parse (p.bytes);
+
+ if (isData)
+ padding--;
+
+ if (padding > 0) {
+ cwt.WriteLine ("//byte[" + padding + "]");
+ offset += padding;
+ }
+ }
+ }
+ }
+
+ return offset;
+ }
+
+ static int SizeOfType (string t)
+ {
+ switch (t) {
+ case "sbyte":
+ case "byte":
+ case "bool":
+ return 1;
+ case "short":
+ case "ushort":
+ case "char":
+ case "uchar":
+ return 2;
+ case "int":
+ case "uint":
+ return 4;
+ case "long":
+ case "ulong":
+ return 8;
+ }
+
+ //FIXME: these are hacks, add SizeMap stanza to TypeMap
+ if (t.EndsWith ("Id"))
+ return 4;
+
+ if (idMap.ContainsKey (t))
+ return SizeOfType (idMap[t]);
+
+ Console.Error.WriteLine ("Error: Size not known for type: " + t);
+ return 0;
+ }
+
+ static string Studlify (string name)
+ {
+ string r = "";
+
+ foreach (string s in name.Split ('_'))
+ r += Char.ToUpper (s[0]) + s.Substring (1);
+
+ return r;
+ }
+
+ //TODO: numbers etc? Write tests
+ //GetXidRange GetXIDRange GetX, numbers etc.
+ static string Destudlify (string s)
+ {
+ string o = "";
+
+ bool xC = true;
+ bool Cx = false;
+
+ for (int i = 0 ; i != s.Length ; i++) {
+
+ if (i != 0)
+ xC = Char.IsLower (s[i-1]);
+
+ if (i != s.Length - 1)
+ Cx = Char.IsLower (s[i+1]);
+
+ if (i == 0) {
+ o += Char.ToLower (s[i]);
+ continue;
+ }
+
+ if (Char.IsUpper (s[i]))
+ if (Cx || xC && !Cx)
+ o += '_';
+
+ o += Char.ToLower (s[i]);
+ }
+
+ return o;
+ }
+
+ static string ToParm (string name)
+ {
+ return name.Substring (0, 1).ToLower () + name.Substring (1, name.Length - 1);
+ }
+
+ static string ToCs (string name)
+ {
+ return Studlify (Destudlify (name));
+ }
+
+ static string TypeToCs (string name)
+ {
+ if (typeMap.ContainsKey (name))
+ return typeMap[name];
+
+ Console.Error.WriteLine ("Warning: typeMap doesn't contain " + name);
+ //return "IntPtr";
+ return ToCs (name);
+ }
+
+ static string NewTypeToCs (string name)
+ {
+ return NewTypeToCs (name, "");
+ }
+
+ static string NewTypeToCs (string name, string suffix)
+ {
+ //TODO: don't look in typeMap twice?
+ //TODO: error reporting?
+
+ string cs;
+
+ if (typeMap.ContainsKey (name)) {
+ cs = typeMap[name];
+ if (cs.ToLower () == name.ToLower ()) {
+ caseMap[name.ToLower ()] = cs;
+ } else {
+ //this type is already defined as a primitive
+ return NewTypeToCs (name + "_fake");
+ }
+ } else
+ {
+ cs = ToCs (name) + suffix;
+ typeMap[name] = cs;
+ }
+
+ return cs;
+ }
+
+ static Dictionary<string,string> idMap = new Dictionary<string,string> ();
+ static Dictionary<string,string> typeMap = new Dictionary<string,string> ();
+ //TODO: use caseMap for field case corrections?
+ static Dictionary<string,string> caseMap = new Dictionary<string,string> ();
+ static void LoadTypeMap (string fname)
+ {
+ char[] delim = {'\t'};
+
+ StreamReader sr = new StreamReader (new FileStream (fname, FileMode.Open, FileAccess.Read));
+
+ string ln;
+ while ((ln = sr.ReadLine ()) != null) {
+ ln = ln.Trim ();
+
+ if (ln == "")
+ continue;
+
+ if (ln.StartsWith ("#"))
+ continue;
+
+ string[] parts = ln.Split (delim);
+ if (parts.Length != 2) {
+ Console.Error.WriteLine ("Error: Bad type map file: " + fname);
+ continue;
+ }
+
+ string key = parts[0].Trim ();
+ string value = parts[1].Trim ();
+
+ typeMap[key] = value;
+ }
+
+ sr.Close ();
+ }
+
+ static void SaveTypeMap (string fname)
+ {
+ StreamWriter sw = new StreamWriter (new FileStream (fname, FileMode.Create, FileAccess.Write));
+ sw.WriteLine ("#TypeMap for " + "[]");
+ sw.WriteLine ("#Generated by xnb-generator");
+ sw.WriteLine ();
+
+ /*
+ foreach (KeyValuePair<string,string> entry in sizeMap)
+ sw.WriteLine (entry.Key + "\t" + entry.Value);
+ sw.WriteLine ();
+ */
+
+ foreach (KeyValuePair<string,string> entry in typeMap)
+ sw.WriteLine (entry.Key + "\t" + entry.Value);
+
+ /*
+ foreach (KeyValuePair<string,string> entry in idMap)
+ sw.WriteLine (entry.Key + "\t" + entry.Value);
+ */
+
+ sw.Close ();
+ }
+}
209 acceptance-tests-ifolder/xnb/IOVector.cs
View
@@ -0,0 +1,209 @@
+using System;
+using System.Diagnostics;
+using System.Collections;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+using Mono.Unix;
+
+namespace Xnb
+{
+ public struct IOVector
+ {
+ public IntPtr Base;
+ public int Length;
+ }
+
+ /*
+ public class VectorSet : IEnumerable<IOVector>
+ {
+ public IEnumerator<IOVector> GetEnumerator()
+ {
+ yield return new IOVector ();
+ }
+ }
+ */
+
+ public class VectorIO
+ {
+ /*
+ public static void Write (IOVector[] vec)
+ {
+ foreach (IOVector v in vec) {
+ Trace.WriteLine (v.Base);
+ Trace.WriteLine (v.Length);
+ Trace.WriteLine ();
+ }
+ }
+ */
+
+ public static void Print (IOVector[] vector, bool dirOut)
+ {
+ Trace.WriteLine ("<message>");
+ Trace.Indent ();
+
+ foreach (IOVector v in vector) {
+ //Trace.WriteLine (v.Base);
+ Trace.WriteLine ("Vector Length: " + v.Length);
+ for (int i = 0 ; i != v.Length ; i++) {
+ byte b = Marshal.ReadByte (v.Base, i);
+ if (dirOut)
+ Trace.WriteLine ("-> " + i + " " + b);
+ else
+ Trace.WriteLine ("<- " + i + " " + b);
+ }
+ }
+
+ Trace.Unindent ();
+ Trace.WriteLine ("</message>");
+ Trace.WriteLine ("");
+ }
+
+ public static int Read (int fd, IOVector[] vector)
+ {
+ int ret;
+ ret = readv (fd, vector, vector.Length);
+ Print (vector, false);
+ Trace.WriteLine ("Actually read: " + ret);
+ return ret;
+ }
+
+ public static int Write (int fd, IOVector[] vector)
+ {
+ int ret;
+ Print (vector, true);
+ ret = writev (fd, vector, vector.Length);
+ Trace.WriteLine ("Actually wrote: " + ret);
+ return ret;
+ }
+
+ [DllImport ("libc")]
+ protected static extern int readv (int filedes, IOVector[] vector, int count);
+ [DllImport ("libc")]
+ protected static extern int writev (int filedes, IOVector[] vector, int count);
+ }
+
+ /*
+#include <sys/uio.h>
+
+int readv(int filedes, const struct iovec *vector,
+size_t count);
+
+int writev(int filedes, const struct iovec *vector,
+size_t count);
+
+*/
+
+ public interface IMessagePart : IEnumerable<IOVector>, IEnumerable
+ {
+ int Read (IntPtr ptr);
+
+ //IEnumerator<IOVector> GetEnumerator();
+ //IOVector[] GetVectors ();
+ }
+
+ public static class XMarshal
+ {
+ public unsafe static IOVector Do (ref byte[] ary)
+ {
+ IOVector vec = new IOVector ();
+
+ unsafe {
+ fixed(byte* pData = &ary[0]) {
+ vec.Base = (IntPtr)pData;
+ vec.Length = sizeof(byte)*ary.Length;
+ }
+ //vec.Length = ary.Length;
+ }
+
+ return vec;
+ }
+
+ public unsafe static IOVector Do (ref uint[] ary)
+ {
+ IOVector vec = new IOVector ();
+
+ unsafe {
+ fixed(uint* pData = &ary[0]) {
+ vec.Base = (IntPtr)pData;
+ vec.Length = sizeof(uint)*ary.Length;
+ }
+ //vec.Length = ary.Length;
+ }
+
+ return vec;
+ }
+
+ public unsafe static IOVector Do (void* ptr, int len)
+ {
+ return new IOVector ();
+ }
+
+ public static IOVector Do (IntPtr ptr, int len)
+ {
+ return new IOVector ();
+ }
+
+ /*
+ public static IOVector Do<T> (ref T[] ary) where T: struct
+ {
+ IOVector vec = new IOVector ();
+
+ unsafe {
+ fixed(T* pData = &ary[0]) {
+ vec.Base = (IntPtr)pData;
+ vec.Length = sizeof(T)*ary.Length;
+ }
+ }
+
+ return vec;
+ }
+ */
+
+ public static IOVector Do<T> (ref T data)// where T: struct
+ {
+ IOVector vec = new IOVector ();
+
+ GCHandle gch = GCHandle.Alloc(data, GCHandleType.Pinned);
+ vec.Base = gch.AddrOfPinnedObject ();
+ vec.Length = Padded (Marshal.SizeOf (typeof(T)));
+ gch.Free ();
+
+ /*
+ unsafe {
+ fixed (void* ptr = &data) {
+ vec.Base = (IntPtr)ptr;
+ vec.Length = sizeof(T);
+ }
+ }
+ */
+
+ return vec;
+ }
+
+ //maybe return iovec tree or array
+ public static IOVector Do (ref string value)
+ {
+ IOVector vec = new IOVector ();
+
+ //FIXME: SECURITY: uncleared memory used for padding
+ vec.Base = UnixMarshal.StringToHeap (@value);
+ vec.Length = Padded (value.Length);
+ //TODO: use pad func and custom stringtoheap
+
+ return vec;
+ }
+
+ public static int Pad (int len)
+ {
+ int pad = len % 4;
+ pad = pad == 0 ? 0 : 4 - pad;
+
+ return pad;
+ }
+
+ public static int Padded (int len)
+ {
+ return len + Pad (len);
+ }
+ }
+}
77 acceptance-tests-ifolder/xnb/Makefile
View
@@ -0,0 +1,77 @@
+CSC_DEBUGFLAGS=-debug -d:TRACE
+CSC=gmcs $(CSC_DEBUGFLAGS)
+MONO_DEBUGFLAGS=--debug
+RUNTIME=mono $(MONO_DEBUGFLAGS)
+
+#PKGCONFIG=pkg-config
+#Xnb_PROTO_DIR=$(shell $(PKGCONFIG) --variable=xcbincludedir xcb-proto)
+
+XMLTOOL=mono-xmltool
+XCB_SCHEMA=xcb.xsd
+
+#EXTENSIONS=bigreq randr shape xevie xvmc composite record shm xf86dri xv damage render sync xfixes dpms res xcb_types xprint glx screensaver xc_misc xproto
+EXTENSIONS=bigreq randr shape xevie xvmc composite record shm xf86dri xv damage render sync xfixes dpms res xcb_types screensaver xc_misc xproto
+EXTENSION_XML=$(addprefix proto/,$(addsuffix .xml, $(EXTENSIONS)))
+
+ASSEMBLIES=xnb-generator.exe Xnb.dll nxauth.exe testsimple.exe
+DEBUG=$(addsuffix .mdb, $(ASSEMBLIES))
+GENSOURCES=Xnb.cs XnbTypes.cs XProto.cs XProtoTypes.cs XCMisc.cs XCMiscTypes.cs XFixes.cs XFixesTypes.cs
+EXTS=Xnb XProto XCMisc
+#GENSOURCES=$(addsuffix .cs,$(foreach f,$(f)Types %Proto,$(EXTS)))
+
+all: $(ASSEMBLIES)
+
+XNB_SOURCES=$(GENSOURCES) Connection.cs Xau.cs Authentication.cs IOVector.cs XReader.cs XWriter.cs XMarshaler.cs Extension.cs Structs.cs XResponseReader.cs XidManager.cs Auxiliary.cs Attributes.cs X11.cs
+
+Xnb.dll: $(XNB_SOURCES)
+ $(CSC) -unsafe -out:$@ -t:library -r:Mono.Posix $(XNB_SOURCES)
+
+testsimple.exe: Xnb.dll TestSimple.cs
+ $(CSC) -out:$@ -r:Xnb.dll TestSimple.cs
+
+testserver.exe: Xnb.dll XServer.cs TestServer.cs
+ $(CSC) -out:$@ -r:Mono.Posix -r:Mono.GetOptions -r:Xnb.dll XServer.cs TestServer.cs
+
+XFixes.cs XFixesTypes.cs XFixesTypeMap: xnb-generator.exe xfixes.xml XCMiscTypeMap
+ $(RUNTIME) xnb-generator.exe -o:XFixes -r:XCMisc xfixes.xml
+
+XCMisc.cs XCMiscTypes.cs XCMiscTypeMap: xnb-generator.exe xc_misc.xml XProtoTypeMap
+ $(RUNTIME) xnb-generator.exe -o:XCMisc -r:XProto xc_misc.xml
+
+XProto.cs XProtoTypes.cs XProtoTypeMap: xnb-generator.exe xproto.xml XnbTypeMap
+ $(RUNTIME) xnb-generator.exe -o:XProto -r:Xnb xproto.xml
+
+Xnb.cs XnbTypes.cs XnbTypeMap: xnb-generator.exe xcb_types.xml TypeMap
+ $(RUNTIME) xnb-generator.exe -o:Xnb xcb_types.xml
+
+xnb-generator.exe: Generator.cs CodeWriter.cs XcbSchema.cs
+ $(CSC) -out:$@ -r:Mono.GetOptions Generator.cs CodeWriter.cs XcbSchema.cs
+
+XcbSchema.cs: XcbSchema.xsd
+ xsd XcbSchema.xsd /c
+
+#XcbSchema.xsd: xproto.xml xcb_types.xml
+# trang -I xml -O xsd xproto.xml xcb_types.xml $@
+
+nxauth.exe: Xnb.dll XAuth.cs
+ $(CSC) -out:$@ -r:Mono.GetOptions -r:Mono.Posix -r:Xnb.dll XAuth.cs
+
+
+
+#temporary hack to make the demo work
+XDPY_DEPTH=$(shell xdpyinfo | grep "depth of root window:" | sed -e 's/^.*://' | sed -e 's/ planes//')
+XDPY_WID=$(shell xdpyinfo | grep "root window id:" | sed -e 's/^.*0x//')
+XDPY_VIS=$(shell xdpyinfo | grep "default visual id:" | sed -e 's/^.*0x//')
+
+.PHONY: run
+run: testsimple.exe
+ $(RUNTIME) testsimple.exe $(XDPY_DEPTH) $(XDPY_WID) $(XDPY_VIS)
+
+.PHONY: validate
+validate: $(EXTENSION_XML)
+ $(XMLTOOL) --validate $(XCB_SCHEMA) $(EXTENSION_XML)
+
+.PHONY: clean
+clean:
+ -rm $(ASSEMBLIES) $(DEBUG) $(GENSOURCES)
+
16 acceptance-tests-ifolder/xnb/Object.cs
View
@@ -0,0 +1,16 @@
+using System;
+
+namespace Xnb
+{
+ public abstract class XObject
+ {
+ protected uint xid;
+
+ public uint Xid
+ {
+ get {
+ return xid;
+ }
+ }
+ }
+}
19 acceptance-tests-ifolder/xnb/README
View
@@ -0,0 +1,19 @@
+Xnb: X protocol libraries for C#/.NET
+=====================================
+Part of the Mono Project
+
+This software is not yet ready for use.
+
+These files have been imported verbatim from Xcb CVS (of late Jan '06):
+ xcb_types.xml xc_misc.xml xproto.xml
+
+They are maintained by the Xcb project but included here for stability during
+development.
+
+Status
+======
+
+Work is ongoing.
+
+--
+Alp Toker <alp@atoker.com>
84 acceptance-tests-ifolder/xnb/Structs.cs
View
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Runtime.InteropServices;
+
+namespace Xnb
+{
+ [StructLayout (LayoutKind.Explicit, Pack=1)]
+ public struct Response
+ {
+ [FieldOffset(0)]
+ public byte ResponseType;
+ //pad[1]
+ [FieldOffset(2)]
+ public ushort Sequence;
+ }
+
+ [StructLayout (LayoutKind.Explicit, Pack=1)]
+ public struct Reply
+ {
+ [FieldOffset(2)]
+ public ushort Sequence;
+ [FieldOffset(4)]
+ public uint Length;
+ }
+
+
+ [StructLayout (LayoutKind.Explicit, Pack=1)]
+ public struct Error
+ {
+ [FieldOffset(1)]
+ public byte Code;
+ [FieldOffset(2)]
+ public ushort Sequence;
+ }
+
+ /*
+ [StructLayout (LayoutKind.Explicit, Pack=1, Size=0)]
+ public struct Event : Response
+ {
+ }
+ */
+
+ /*
+ [StructLayout (LayoutKind.Explicit, Pack=1, Size=4)]
+ public struct Request
+ {
+ public Request (byte opcode, ushort length)
+ {
+ this.Opcode = opcode;
+ this.Length = length;
+ }
+
+ [FieldOffset(0)]
+ public byte Opcode;
+ //[FieldOffset(1)]
+ //public byte Data;
+ [FieldOffset(2)]
+ public ushort Length;
+ }
+
+ //TODO
+ [StructLayout (LayoutKind.Explicit, Pack=1, Size=4)]
+ public struct ExtensionRequest
+ {
+ [FieldOffset(0)]
+ public byte Opcode;
+ //[FieldOffset(1)]
+ //public byte Data;
+ [FieldOffset(2)]
+ public ushort Length;
+ }
+ */
+
+ /*
+ [StructLayout (LayoutKind.Explicit, Pack=1, Size=4)]
+ public struct ExtensionRequest : Request
+ {
+ [FieldOffset(0)]
+ public byte MajorOpcode;
+ [FieldOffset(1)]
+ public byte MinorOpcode;
+ }
+ */
+}
21 acceptance-tests-ifolder/xnb/TestServer.cs
View
@@ -0,0 +1,21 @@
+using System;
+using Xnb;
+
+using Mono.GetOptions;
+
+public class TestServer
+{
+ public class TestXServerOptions : XServerOptions
+ {
+ public TestXServerOptions (string[] args) : base (args) {}
+ }
+
+ public static void Main (string[] args)
+ {
+ TestXServerOptions opts = new TestXServerOptions (args);
+ string[] dpy = opts.RemainingArguments;
+
+ XServer xs = new XServer ();
+ xs.InitUnix ();
+ }
+}
111 acceptance-tests-ifolder/xnb/TestSimple.cs
View
@@ -0,0 +1,111 @@
+using System;
+using Xnb;
+using Xnb.Protocol.Xnb;
+using Xnb.Protocol.XProto;
+
+using System.Runtime.InteropServices;
+
+public class Driver
+{
+ public static void Main (string[] args)
+ {
+ if (args.Length != 3) {
+ Console.Error.WriteLine ("Usage: testsimple [depth] [root] [visual]");
+ return;
+ }
+
+ Connection c = new Connection (null, 0);
+ //Connection c = new Connection ("localhost", 0);
+
+ Console.WriteLine ("Release: " + c.Setup.ReleaseNumber);
+ Console.WriteLine ("Vendor: " + c.Setup.Vendor);
+ Console.WriteLine ("VendorLen: " + c.Setup.VendorLen);
+ Console.WriteLine ("RootsLen: " + c.Setup.RootsLen);
+ Console.WriteLine ("PixmapFormatsLen: " + c.Setup.PixmapFormatsLen);
+
+ /*
+ Screen root;
+ int screen_num = 0;
+ root = Aux.GetScreen (c, screen_num);
+ int depth = 1;
+ Console.WriteLine (root);
+ Console.WriteLine (root.Root);
+ Console.WriteLine (root.WhitePixel);
+ Console.WriteLine (root.WidthInPixels);
+ Console.WriteLine (root.HeightInPixels);
+ */
+
+ XCMisc xcmisc = new XCMisc ();
+ xcmisc.Init (c);
+
+ /*
+ XFixes xfixes = new XFixes ();
+ xfixes.Init (c);
+ */
+
+ XidManager xm = new XidManager (xcmisc);
+
+ XProto xp = new XProto ();
+ xp.Init (c);
+
+ WindowId wid = (WindowId)xm.Generate ();
+ Console.WriteLine ("New xid: " + (uint)wid);
+
+ //use xdpyinfo to find root window id
+ WindowId parentId = new WindowId ((uint)Int32.Parse (args[1], System.Globalization.NumberStyles.HexNumber));
+
+ //use xdpyinfo to find a visual
+ //uint visualId = 0x23;
+ uint visualId = (uint)Int32.Parse (args[2], System.Globalization.NumberStyles.HexNumber);
+
+ //byte depth = 16;
+ byte depth = (byte)Int32.Parse (args[0]);
+
+ uint[] flags = new uint[4];
+
+ //Mask
+ flags[0] = (uint) (WindowValueMask.BackgroundPixel | WindowValueMask.EventMask | WindowValueMask.DoNotPropagateMask);
+ //flags[0] = (uint) (Cw.BackPixel | Cw.EventMask | Cw.DontPropagate);
+ //flags[0] = 0x00000100 | 0x00000800 | 0x00001000;
+
+ //BackgroundPixel
+ flags[1] = 0xffff0000;
+
+ //EventMask
+ //flags[2] = (uint) (EventMask.ButtonReleaseMask | EventMask.ExposureMask);
+ flags[2] = 0x00000008 | 0x00008000;
+
+ //DoNotPropagateMask
+ //flags[3] = (uint) (EventMask.ButtonPressMask);
+ flags[3] = 0x00000004;
+
+ xp.CreateWindow (depth, wid, parentId, 10, 10, 100, 100, 0, (ushort)WindowClass.InputOutput, visualId, flags);
+
+ xp.ChangeProperty ((byte)PropertyMode.Replace, wid, AtomType.WM_NAME, AtomType.STRING, 8, 0);
+
+ xp.MapWindow (wid);
+
+ PixmapId pid = (PixmapId)xm.Generate ();
+ xp.CreatePixmap (depth, pid, wid, 100, 100);
+
+ Rectangle rect = new Rectangle ();
+ rect.X = 0;
+ rect.Y = 0;
+ rect.Width = 100;
+ rect.Height = 100;
+
+ Rectangle[] rects = new Rectangle[1];
+ rects[0] = rect;
+
+ //xc.PolyFillRectangle (pid, whitegc, rects);
+
+ xp.ClearArea (false, wid, 10, 10, 20, 20);
+
+ //Sync:
+ //xp.GetInputFocus ();
+
+ while (true) {
+ c.xrr.ReadMessage ();
+ }
+ }
+}
38 acceptance-tests-ifolder/xnb/TypeMap
View
@@ -0,0 +1,38 @@
+# primitive types
+char sbyte
+CHAR2B char
+BOOL bool
+BYTE sbyte
+INT8 sbyte
+INT16 short
+INT32 int
+CARD8 byte
+CARD16 ushort
+CARD32 uint
+
+VISUALID uint
+TIMESTAMP uint
+ID uint
+KEYSYM uint
+KEYCODE byte
+BUTTON byte
+
+# Xid
+XID Id
+
+# hacks: should come from Render and Shape
+PICTURE Id
+SHAPE_KIND byte
+
+#TODO: replace with generic parameter
+void IntPtr
+#FIXME: union workarounds
+ClientMessageData uint
+DRAWABLE Id
+FONTABLE Id
+
+#Case correction
+GCONTEXT GContext
+
+# Non-primitive
+STR string
486 acceptance-tests-ifolder/xnb/X11.cs
View
@@ -0,0 +1,486 @@
+using System;
+
+namespace Xnb
+{
+ public enum Gravity
+ {
+ //protected?
+ Forget,
+ NorthWest,
+ North,
+ NorthEast,
+ West,
+ Center,
+ East,
+ SouthWest,
+ South,
+ SouthEast,
+ Static,
+ }
+
+ public enum HostFamily
+ {
+ Internet,
+ DECnet,
+ Chaos,
+ //FIXME
+ Unused0,
+ Unused1,
+ ServerInterpreted,
+ InternetV6,
+ }
+
+ /*
+ 0x42 MSB first
+ 0x6C LSB first
+
+ public enum ByteOrder
+ {
+ LSBFirst,
+ MSBFirst,
+ }
+
+ public enum ByteOrder
+ {
+ LeastSignificant,
+ MostSignificant,
+ }
+ */
+
+ public enum BackingStoreUsage
+ {
+ Never,
+ NotUseful = Never,
+ WhenMapped,
+ Always,
+ }
+
+ public enum VisualType
+ {
+ StaticGray,
+ //formerly GrayScale
+ Grayscale,
+ StaticColor,
+ PseudoColor,
+ TrueColor,
+ DirectColor,
+ }
+
+ //also for PIXMAP, so DrawableClass?
+ public enum WindowClass : ushort
+ {
+ CopyFromParent,
+ //ParentRelative = CopyFromParent,
+ InputOutput,
+ InputOnly,
+ }
+
+ /*
+ public enum WindowFOO : ushort
+ {
+ None,
+ ParentRelative,
+ }
+ */
+
+ public enum MapState
+ {
+ Unmapped,
+ Unviewable,
+ Viewable,
+ }
+
+ public enum SaveSetMode : byte
+ {
+ Insert,
+ Delete,
+ }
+
+ /*
+
+ //from xfixes.xml
+ public enum SaveSetTarget
+ {
+ Nearest,
+ Root,
+ }
+ */
+
+ public enum StackMode
+ {
+ Above,
+ Below,
+ TopIf,
+ BottomIf,
+ Opposite,
+ }
+
+ public enum CirculateDirection : byte
+ {
+ RaiseLowest,
+ LowerHighest,
+ }
+
+ public enum PropertyMode : byte
+ {
+ Replace,
+ Prepend,
+ Append,
+ }
+
+ public enum EventDestination
+ {
+ PointerWindow,
+ InputFocus,
+ }
+
+ public enum GrabMode
+ {
+ Synchronous,
+ Asynchronous,
+ }
+
+ public enum GrabStatus
+ {
+ Success,
+ AlreadyGrabbed,
+ InvalidTime,
+ NotViewable,
+ Frozen,
+ }
+
+ /*
+ {
+ AsyncPointer,
+ SyncPointer,
+ ReplayPointer,
+ AsyncKeyboard,
+ SyncKeyboard,
+ ReplayKeyboard,
+ AsyncBoth,
+ SyncBoth,
+ }
+ */
+
+ public enum FocusRevert
+ {
+ None,
+ PointerRoot,
+ Parent,
+ }
+
+ //DrawDirection
+ public enum Direction
+ {
+ LeftToRight,
+ RightToLeft,
+ }
+
+ public enum LineStyle
+ {
+ Solid,
+ OnOffDash,
+ DoubleDash,
+ }
+
+ public enum CapStyle
+ {
+ NotLast,
+ Butt,
+ Round,
+ Projecting,
+ }
+
+ public enum JoinStyle
+ {
+ Miter,
+ Round,
+ Bevel,
+ }
+
+ public enum FillStyle
+ {
+ Solid,
+ Tiled,
+ Stippled,
+ OpaqueStippled,
+ }
+
+ public enum FillRule
+ {
+ EvenOdd,
+ Winding,
+ }
+
+ public enum SubwindowMode
+ {
+ ClipByChildren,
+ IncludeInferiors,
+ }
+
+ public enum ArcMode
+ {
+ Chord,
+ PieSlice,
+ }
+
+ public enum Ordering
+ {
+ UnSorted,
+ YSorted,
+ YXSorted,
+ YXBanded,
+ }
+
+ /*
+ public enum CoordinateMode
+ {
+ Origin,
+ Previous,
+ }
+ */
+
+ //names refactored
+ public enum CoordinateMode
+ {
+ Absolute,
+ Relative,
+ }
+
+ public enum ShapeType
+ {
+ Complex,
+ Nonconvex,
+ Convex,
+ }
+
+ public enum ImageFormat
+ {
+ Bitmap,
+ XYPixmap,
+ ZPixmap,
+ }
+
+ public enum Allocation
+ {
+ None,
+ All,
+ }
+
+ public enum QueryClass
+ {
+ Cursor,
+ Tile,
+ Stipple,
+ }
+
+ /*
+ public enum led-mode/toggle
+ {
+ Off,
+ On,
+ Default,
+ }
+
+ public enum Blanking
+ {
+ No,
+ Yes,
+ Default,
+ }
+
+ {
+ Disabled,
+ Enabled,
+ }
+
+ {
+ Disable,
+ Enable,
+ }
+ */
+
+ public enum CloseDownMode
+ {
+ Destroy,
+ RetainPermanent,
+ RetainTemporary,
+ }
+
+ public enum ForceMode
+ {
+ Reset,
+ Activate,
+ }
+
+ public enum Success
+ {
+ Busy,
+ Failed,
+ }
+
+ public enum NotifyType
+ {
+ Normal,
+ Hint,
+ }
+
+ //TODO: event DETAILS!
+
+ //names refactored
+ public enum Visibility
+ {
+ Full,
+ Partial,
+ None,
+ }
+
+ /*
+ public enum VisibilityState
+ {
+ Unobscured,
+ PartiallyObscured,
+ FullyObscured,
+ }
+ */
+
+ public enum ColormapState
+ {
+ Uninstalled,
+ Installed,
+ }
+
+ public enum MappingRequestType
+ {
+ Modifer,
+ Keyboard,
+ Pointer,
+ }
+
+ public enum Place
+ {
+ Top,
+ Bottom,
+ }
+
+ //GCFunction?
+ public enum GraphicsFunction
+ {
+ Clear,
+ And,
+ AndReverse,
+ Copy,
+ AndInverted,
+ NoOp,
+ Xor,
+ Or,
+ Nor,
+ Equiv,
+ Invert,
+ OrReverse,
+ CopyInverted,
+ OrInverted,
+ Nand,
+ Set,
+ }
+
+ //masks, until they are done more intelligently
+ //seems to be XA_PRIMARY << value_index
+ [Flags]
+ public enum WindowValueMask : uint
+ {
+ BackgroundPixmap = 1 << 0,
+ BackgroundPixel = 1 << 1,
+ BorderPixmap = 1 << 2,
+ BorderPixel = 1 << 3,
+ BitGravity = 1 << 4,
+ WinGravity = 1 << 5,