~ubuntu-branches/ubuntu/karmic/ndesk-dbus/karmic

« back to all changes in this revision

Viewing changes to examples/TestExportInterface.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-10-16 11:52:32 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20071016115232-fe3ejbyws97q4rf2
Tags: 0.6.0-1
* New upstream release.
* debian/control:
  + Update build dependencies.
* debian/rules:
  + Update for new upstream build system.
  + Call dh_clifixperms instead of manual find magic.
  + Bump clilibs to >= 0.6.0.
* debian/watch:
  + Update location.
* patches/01_pkg-config-library-path.dpatch:
  + Fix library path in the pkg-config file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
        {
14
14
                Bus bus = Bus.Session;
15
15
 
16
 
                ObjectPath myOpath = new ObjectPath ("/org/ndesk/test");
17
 
                string myNameReq = "org.ndesk.test";
18
 
 
19
 
                IDemoObject demo;
20
 
 
21
 
                if (bus.NameHasOwner (myNameReq)) {
22
 
                        demo = bus.GetObject<IDemoObject> (myNameReq, myOpath);
23
 
                } else {
24
 
                        demo = new DemoObject ();
25
 
                        bus.Register (myNameReq, myOpath, demo);
26
 
 
27
 
                        RequestNameReply nameReply = bus.RequestName (myNameReq);
28
 
                        Console.WriteLine ("RequestNameReply: " + nameReply);
29
 
 
 
16
                string bus_name = "org.ndesk.test";
 
17
                ObjectPath path = new ObjectPath ("/org/ndesk/test");
 
18
 
 
19
                IDemoOne demo;
 
20
 
 
21
                if (bus.RequestName (bus_name) == RequestNameReply.PrimaryOwner) {
 
22
                        //create a new instance of the object to be exported
 
23
                        demo = new Demo ();
 
24
                        bus.Register (path, demo);
 
25
 
 
26
                        //run the main loop
30
27
                        while (true)
31
28
                                bus.Iterate ();
 
29
                } else {
 
30
                        //import a remote to a local proxy
 
31
                        demo = bus.GetObject<IDemo> (bus_name, path);
32
32
                }
33
33
 
34
34
                Console.WriteLine ();
 
35
                demo.SomeEvent += HandleSomeEventA;
 
36
                demo.FireOffSomeEvent ();
 
37
 
 
38
                Console.WriteLine ();
 
39
                demo.SomeEvent -= HandleSomeEventA;
 
40
                demo.FireOffSomeEvent ();
 
41
 
 
42
                Console.WriteLine ();
35
43
                demo.SomeEvent += delegate (string arg1, object arg2, double arg3, MyTuple mt) {Console.WriteLine ("SomeEvent handler: " + arg1 + ", " + arg2 + ", " + arg3 + ", " + mt.A + ", " + mt.B);};
36
44
                demo.SomeEvent += delegate (string arg1, object arg2, double arg3, MyTuple mt) {Console.WriteLine ("SomeEvent handler two: " + arg1 + ", " + arg2 + ", " + arg3 + ", " + mt.A + ", " + mt.B);};
37
45
                demo.FireOffSomeEvent ();
38
 
                //handle the raised signal
39
 
                //bus.Iterate ();
40
 
 
41
 
                Console.WriteLine ();
42
 
                demo.SomeEvent += HandleSomeEventA;
43
 
                demo.FireOffSomeEvent ();
44
 
                //handle the raised signal
45
 
                //bus.Iterate ();
46
 
 
47
 
                Console.WriteLine ();
48
 
                demo.SomeEvent -= HandleSomeEventA;
49
 
                demo.FireOffSomeEvent ();
50
 
                //handle the raised signal
51
 
                //bus.Iterate ();
52
 
 
53
 
                Console.WriteLine ();
 
46
 
 
47
                Console.WriteLine ();
 
48
 
 
49
                Console.WriteLine (demo.GetSomeVariant ());
 
50
 
 
51
                Console.WriteLine ();
 
52
 
 
53
                demo.Say2 ("demo.Say2");
 
54
                ((IDemoTwo)demo).Say2 ("((IDemoTwo)demo).Say2");
 
55
 
 
56
                demo.SayEnum (DemoEnum.Bar, DemoEnum.Foo);
 
57
 
 
58
                /*
 
59
                uint n;
 
60
                string ostr;
 
61
                demo.WithOutParameters (out n, "21", out ostr);
 
62
                Console.WriteLine ("n: " + n);
 
63
                Console.WriteLine ("ostr: " + ostr);
 
64
                */
 
65
 
 
66
                /*
 
67
                IDemoOne[] objs = demo.GetObjArr ();
 
68
                foreach (IDemoOne obj in objs)
 
69
                        obj.Say ("Some obj");
 
70
                */
 
71
 
 
72
                demo.ThrowSomeException ();
54
73
        }
55
74
 
56
75
        public static void HandleSomeEventA (string arg1, object arg2, double arg3, MyTuple mt)
65
84
}
66
85
 
67
86
[Interface ("org.ndesk.test")]
68
 
public interface IDemoObject
 
87
public interface IDemoOne
69
88
{
70
89
        event SomeEventHandler SomeEvent;
71
90
        void FireOffSomeEvent ();
72
91
        void Say (object var);
 
92
        void SayEnum (DemoEnum a, DemoEnum b);
 
93
        void Say2 (string str);
 
94
        object GetSomeVariant ();
 
95
        void ThrowSomeException ();
 
96
        void WithOutParameters (out uint n, string str, out string ostr);
 
97
        IDemoOne[] GetEmptyObjArr ();
 
98
        IDemoOne[] GetObjArr ();
73
99
}
74
100
 
75
101
[Interface ("org.ndesk.test2")]
76
 
public interface IDemoObjectTwo
 
102
public interface IDemoTwo
77
103
{
78
104
        int Say (string str);
79
 
}
80
 
 
81
 
public class DemoObject : IDemoObject, IDemoObjectTwo
 
105
        void Say2 (string str);
 
106
}
 
107
 
 
108
public interface IDemo : IDemoOne, IDemoTwo
 
109
{
 
110
}
 
111
 
 
112
public class Demo : DemoBase
 
113
{
 
114
        public override void Say2 (string str)
 
115
        {
 
116
                Console.WriteLine ("Subclassed IDemoOne.Say2: " + str);
 
117
        }
 
118
}
 
119
 
 
120
public class DemoBase : IDemo
82
121
{
83
122
        public event SomeEventHandler SomeEvent;
84
123
 
93
132
                return str.Length;
94
133
        }
95
134
 
 
135
        public void SayEnum (DemoEnum a, DemoEnum b)
 
136
        {
 
137
                Console.WriteLine ("IDemoOne.Say2: " + a + ", " + b);
 
138
        }
 
139
 
 
140
        public virtual void Say2 (string str)
 
141
        {
 
142
                Console.WriteLine ("IDemoOne.Say2: " + str);
 
143
        }
 
144
 
 
145
        void IDemoTwo.Say2 (string str)
 
146
        {
 
147
                Console.WriteLine ("IDemoTwo.Say2: " + str);
 
148
        }
 
149
 
96
150
        public void FireOffSomeEvent ()
97
151
        {
98
152
                Console.WriteLine ("Asked to fire off SomeEvent");
106
160
                        Console.WriteLine ("Fired off SomeEvent");
107
161
                }
108
162
        }
 
163
 
 
164
        public object GetSomeVariant ()
 
165
        {
 
166
                Console.WriteLine ("GetSomeVariant()");
 
167
 
 
168
                return new byte[0];
 
169
        }
 
170
 
 
171
        public void ThrowSomeException ()
 
172
        {
 
173
                throw new Exception ("Some exception");
 
174
        }
 
175
 
 
176
        public void WithOutParameters (out uint n, string str, out string ostr)
 
177
        {
 
178
                n = UInt32.Parse (str);
 
179
                ostr = "." + str + ".";
 
180
        }
 
181
 
 
182
        public IDemoOne[] GetEmptyObjArr ()
 
183
        {
 
184
                return new Demo[] {};
 
185
        }
 
186
 
 
187
        public IDemoOne[] GetObjArr ()
 
188
        {
 
189
                return new IDemoOne[] {this};
 
190
        }
109
191
}
110
192
 
111
 
public enum DemoEnum
 
193
public enum DemoEnum : byte
112
194
{
113
195
        Foo,
114
196
        Bar,