Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit; no build system, just at concept stage

  • Loading branch information...
commit 2bd472d87a120ba4aca3ac3f441926e4ea8a6bd6 0 parents
Alp Toker authored
Showing with 230 additions and 0 deletions.
  1. +20 −0 COPYING
  2. +8 −0 README
  3. +125 −0 glib/GIO.cs
  4. +77 −0 glib/TestGlib.cs
20 COPYING
@@ -0,0 +1,20 @@
+Copyright 2006 Alp Toker <alp@atoker.com>
+
+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.
8 README
@@ -0,0 +1,8 @@
+This code provides GLib integration for Managed DBus
+
+See http://www.ndesk.org/DBusSharp
+
+It is currently at concept stage.
+
+--
+Alp Toker <alp@atoker.com>
125 glib/GIO.cs
@@ -0,0 +1,125 @@
+// Copyright 2006 Alp Toker <alp@atoker.com>
+// This software is made available under the MIT License
+// See COPYING for details
+
+using System;
+using System.Collections;
+using System.Runtime.InteropServices;
+
+namespace GLib
+{
+ public delegate bool IOFunc (IOChannel source, IOCondition condition, IntPtr data);
+
+ //this is actually somewhat like Stream, but we don't use it that way
+ [StructLayout (LayoutKind.Sequential)]
+ public struct IOChannel
+ {
+ const string GLIB = "glib-2.0";
+
+ public IntPtr Handle;
+
+ [DllImport(GLIB)]
+ static extern IntPtr g_io_channel_unix_new (int fd);
+
+ [DllImport(GLIB)]
+ //static extern int g_io_channel_unix_get_fd (IntPtr channel);
+ static extern int g_io_channel_unix_get_fd (IOChannel channel);
+
+ public IOChannel (int fd)
+ {
+ Handle = g_io_channel_unix_new (fd);
+ }
+
+ public int UnixFd
+ {
+ get {
+ //return g_io_channel_unix_get_fd (Handle);
+ return g_io_channel_unix_get_fd (this);
+ }
+ }
+
+ [DllImport(GLIB)]
+ static extern IOFlags g_io_channel_get_flags (IOChannel channel);
+
+ [DllImport(GLIB)]
+ static extern short g_io_channel_set_flags (IOChannel channel, IOFlags flags, IntPtr error);
+
+ public IOFlags Flags
+ {
+ get {
+ return g_io_channel_get_flags (this);
+ } set {
+ //TODO: fix return and error
+ g_io_channel_set_flags (this, value, IntPtr.Zero);
+ }
+ }
+ }
+
+ public class IO
+ {
+ const string GLIB = "glib-2.0";
+
+ [DllImport(GLIB)]
+ protected static extern uint g_io_add_watch (IntPtr channel, IOCondition condition, IOFunc func, IntPtr user_data);
+
+ [DllImport(GLIB)]
+ protected static extern uint g_io_add_watch (IOChannel channel, IOCondition condition, IOFunc func, IntPtr user_data);
+
+ [DllImport(GLIB)]
+ protected static extern uint g_io_add_watch_full (IOChannel channel, int priority, IOCondition condition, IOFunc func, IntPtr user_data, IntPtr notify);
+
+
+ public static ArrayList objs = new ArrayList ();
+
+ public static void AddWatch (int fd, IOFunc func)
+ {
+ objs.Add (func);
+
+ IOChannel channel = new IOChannel (fd);
+ uint watch = g_io_add_watch (channel, IOCondition.In, func, IntPtr.Zero);
+ }
+
+ }
+ //From Mono.Unix and poll(2)
+ [Flags]
+ enum PollEvents : short {
+ POLLIN = 0x0001, // There is data to read
+ POLLPRI = 0x0002, // There is urgent data to read
+ POLLOUT = 0x0004, // Writing now will not block
+ POLLERR = 0x0008, // Error condition
+ POLLHUP = 0x0010, // Hung up
+ POLLNVAL = 0x0020, // Invalid request; fd not open
+ // XPG4.2 definitions (via _XOPEN_SOURCE)
+ POLLRDNORM = 0x0040, // Normal data may be read
+ POLLRDBAND = 0x0080, // Priority data may be read
+ POLLWRNORM = 0x0100, // Writing now will not block
+ POLLWRBAND = 0x0200, // Priority data may be written
+ }
+
+ public enum IOCondition : short
+ {
+ In = PollEvents.POLLIN,
+ Out = PollEvents.POLLOUT,
+ Pri = PollEvents.POLLPRI,
+ Err = PollEvents.POLLERR,
+ Hup = PollEvents.POLLHUP,
+ Nval = PollEvents.POLLNVAL,
+ }
+
+ [Flags]
+ public enum IOFlags : short
+ {
+ Append = 1 << 0,
+ Nonblock = 1 << 1,
+ //Read only flag
+ IsReadable = 1 << 2,
+ //Read only flag
+ isWriteable = 1 << 3,
+ //Read only flag
+ IsSeekable = 1 << 4,
+ //?
+ Mask = (1 << 5) - 1,
+ GetMask = Mask,
+ SetMask = Append | Nonblock,
+ }
+}
77 glib/TestGlib.cs
@@ -0,0 +1,77 @@
+// Copyright 2006 Alp Toker <alp@atoker.com>
+// This software is made available under the MIT License
+// See COPYING for details
+
+using System;
+using GLib;
+using Gtk;
+using NDesk.DBus;
+using org.freedesktop.DBus;
+
+public class TestGlib
+{
+ public static bool Dispatch (IOChannel source, IOCondition condition, IntPtr data)
+ {
+ Console.WriteLine ("Dispatch " + source.UnixFd + " " + condition);
+ conn.Iterate ();
+ Console.WriteLine ("Dispatch done");
+
+ return true;
+ }
+
+ public static void OnClick (object o, EventArgs args)
+ {
+ Console.WriteLine ("click");
+
+ Console.WriteLine ();
+ foreach (string n in bus.ListNames ())
+ //Console.WriteLine (n);
+ tv.Buffer.Text += n+'\n';
+ }
+
+ static TextView tv;
+
+ static Connection conn;
+ static Bus bus;
+
+ public static void Main ()
+ {
+ Application.Init ();
+
+ conn = new Connection ();
+
+ tv = new TextView ();
+ ScrolledWindow sw = new ScrolledWindow ();
+ sw.Add (tv);
+
+ Button btn = new Button ("Click me");
+ btn.Clicked += OnClick;
+
+ VBox vb = new VBox (false, 2);
+ vb.PackStart (sw, true, true, 0);
+ vb.PackStart (btn, false, true, 0);
+
+ Window win = new Window ("DBus#");
+ win.SetDefaultSize (640, 480);
+ win.Add (vb);
+ win.Destroyed += delegate {Application.Quit ();};
+ win.ShowAll ();
+
+
+ ObjectPath opath = new ObjectPath ("/org/freedesktop/DBus");
+ string name = "org.freedesktop.DBus";
+
+ bus = conn.GetObject<Bus> (name, opath);
+
+ bus.NameAcquired += delegate (string acquired_name) {
+ Console.WriteLine ("NameAcquired: " + acquired_name);
+ };
+
+ string myName = bus.Hello ();
+ Console.WriteLine ("myName: " + myName);
+
+ IO.AddWatch ((int)conn.sock.Handle, Dispatch);
+
+ Application.Run ();
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.