Modified to support char type.
[platform/upstream/dbus.git] / mono / Test.cs
1 using System;
2 using System.Threading;
3 using DBus;
4 using Gtk;
5
6 namespace DBus.Test
7 {
8   public class Test
9   {
10     public static Service service = null;
11     public static Connection connection = null;
12     
13     public static int Main(string [] args)
14     {
15       TestServer testServer = new TestServer();
16       Thread serverThread = new Thread(new ThreadStart(testServer.StartServer));
17       serverThread.Start();
18
19       connection = Bus.GetSessionBus();
20       service = Service.Get(connection, "org.freedesktop.Test");      
21
22       TestObject testObject = (TestObject) service.GetObject(typeof(TestObject), "/org/freedesktop/Test/TestObject");
23       
24       System.Console.WriteLine(testObject.Test1("Hello"));
25
26       //RunTests(testObject);
27
28       return 0;
29     }
30
31     public static void RunTests(TestObject testObject) 
32     {
33       System.Console.WriteLine(testObject.Test1("Hello"));
34     }
35   }
36
37   public class TestServer
38   {
39     public Connection connection;
40     public Service service;
41
42     public TestServer()
43     {
44       Application.Init();
45       
46       System.Console.WriteLine("Starting server...");
47
48       connection = Bus.GetSessionBus();
49       service = new Service(connection, "org.freedesktop.Test");
50       TestObject testObject = new TestObject();
51       service.RegisterObject(testObject, "/org/freedesktop/Test/TestObject");
52     }
53     
54     public void StartServer()
55     {
56       Application.Run();
57     }
58   }
59
60   [Interface("org.freedesktop.Test.TestObject")]
61   public class TestObject
62   {
63     [Method]
64     public virtual int Test1(string x)
65     {
66       System.Console.WriteLine("Called: " + x);
67       return 5;
68     }
69   }    
70 }