Mono.Zeroconf – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | // Copyright 2006 Alp Toker <alp@atoker.com> |
2 | // This software is made available under the MIT License |
||
3 | // See COPYING for details |
||
4 | |||
5 | using System; |
||
6 | using System.Collections.Generic; |
||
7 | using System.IO; |
||
8 | |||
9 | namespace NDesk.DBus |
||
10 | { |
||
11 | //TODO: complete and use these wrapper classes |
||
12 | //not sure exactly what I'm thinking but there seems to be sense here |
||
13 | |||
14 | //FIXME: signature sending/receiving is currently ambiguous in this code |
||
15 | //FIXME: in fact, these classes are totally broken and end up doing no-op, do not use without understanding the problem |
||
16 | class MethodCall |
||
17 | { |
||
18 | public Message message = new Message (); |
||
19 | |||
20 | public MethodCall (ObjectPath path, string @interface, string member, string destination, Signature signature) |
||
21 | { |
||
22 | message.Header.MessageType = MessageType.MethodCall; |
||
23 | message.ReplyExpected = true; |
||
24 | message.Header.Fields[FieldCode.Path] = path; |
||
25 | if (@interface != null) |
||
26 | message.Header.Fields[FieldCode.Interface] = @interface; |
||
27 | message.Header.Fields[FieldCode.Member] = member; |
||
28 | message.Header.Fields[FieldCode.Destination] = destination; |
||
29 | //TODO: consider setting Sender here for p2p situations |
||
30 | //this will allow us to remove the p2p hacks in MethodCall and Message |
||
31 | #if PROTO_REPLY_SIGNATURE |
||
32 | //TODO |
||
33 | #endif |
||
34 | //message.Header.Fields[FieldCode.Signature] = signature; |
||
35 | //use the wrapper in Message because it checks for emptiness |
||
36 | message.Signature = signature; |
||
37 | } |
||
38 | |||
39 | public MethodCall (Message message) |
||
40 | { |
||
41 | this.message = message; |
||
42 | Path = (ObjectPath)message.Header.Fields[FieldCode.Path]; |
||
43 | if (message.Header.Fields.ContainsKey (FieldCode.Interface)) |
||
44 | Interface = (string)message.Header.Fields[FieldCode.Interface]; |
||
45 | Member = (string)message.Header.Fields[FieldCode.Member]; |
||
46 | Destination = (string)message.Header.Fields[FieldCode.Destination]; |
||
47 | //TODO: filled by the bus so reliable, but not the case for p2p |
||
48 | //so we make it optional here, but this needs some more thought |
||
49 | if (message.Header.Fields.ContainsKey (FieldCode.Sender)) |
||
50 | Sender = (string)message.Header.Fields[FieldCode.Sender]; |
||
51 | #if PROTO_REPLY_SIGNATURE |
||
52 | //TODO: note that an empty ReplySignature should really be treated differently to the field not existing! |
||
53 | if (message.Header.Fields.ContainsKey (FieldCode.ReplySignature)) |
||
54 | ReplySignature = (Signature)message.Header.Fields[FieldCode.ReplySignature]; |
||
55 | else |
||
56 | ReplySignature = Signature.Empty; |
||
57 | #endif |
||
58 | //Signature = (Signature)message.Header.Fields[FieldCode.Signature]; |
||
59 | //use the wrapper in Message because it checks for emptiness |
||
60 | Signature = message.Signature; |
||
61 | } |
||
62 | |||
63 | public ObjectPath Path; |
||
64 | public string Interface; |
||
65 | public string Member; |
||
66 | public string Destination; |
||
67 | public string Sender; |
||
68 | #if PROTO_REPLY_SIGNATURE |
||
69 | public Signature ReplySignature; |
||
70 | #endif |
||
71 | public Signature Signature; |
||
72 | } |
||
73 | |||
74 | class MethodReturn |
||
75 | { |
||
76 | public Message message = new Message (); |
||
77 | |||
78 | public MethodReturn (uint reply_serial) |
||
79 | { |
||
80 | message.Header.MessageType = MessageType.MethodReturn; |
||
81 | message.Header.Flags = HeaderFlag.NoReplyExpected | HeaderFlag.NoAutoStart; |
||
82 | message.Header.Fields[FieldCode.ReplySerial] = reply_serial; |
||
83 | //signature optional? |
||
84 | //message.Header.Fields[FieldCode.Signature] = signature; |
||
85 | } |
||
86 | |||
87 | public MethodReturn (Message message) |
||
88 | { |
||
89 | this.message = message; |
||
90 | ReplySerial = (uint)message.Header.Fields[FieldCode.ReplySerial]; |
||
91 | } |
||
92 | |||
93 | public uint ReplySerial; |
||
94 | } |
||
95 | |||
96 | class Error |
||
97 | { |
||
98 | public Message message = new Message (); |
||
99 | |||
100 | public Error (string error_name, uint reply_serial) |
||
101 | { |
||
102 | message.Header.MessageType = MessageType.Error; |
||
103 | message.Header.Flags = HeaderFlag.NoReplyExpected | HeaderFlag.NoAutoStart; |
||
104 | message.Header.Fields[FieldCode.ErrorName] = error_name; |
||
105 | message.Header.Fields[FieldCode.ReplySerial] = reply_serial; |
||
106 | } |
||
107 | |||
108 | public Error (Message message) |
||
109 | { |
||
110 | this.message = message; |
||
111 | ErrorName = (string)message.Header.Fields[FieldCode.ErrorName]; |
||
112 | ReplySerial = (uint)message.Header.Fields[FieldCode.ReplySerial]; |
||
113 | //Signature = (Signature)message.Header.Fields[FieldCode.Signature]; |
||
114 | } |
||
115 | |||
116 | public string ErrorName; |
||
117 | public uint ReplySerial; |
||
118 | //public Signature Signature; |
||
119 | } |
||
120 | |||
121 | class Signal |
||
122 | { |
||
123 | public Message message = new Message (); |
||
124 | |||
125 | public Signal (ObjectPath path, string @interface, string member) |
||
126 | { |
||
127 | message.Header.MessageType = MessageType.Signal; |
||
128 | message.Header.Flags = HeaderFlag.NoReplyExpected | HeaderFlag.NoAutoStart; |
||
129 | message.Header.Fields[FieldCode.Path] = path; |
||
130 | message.Header.Fields[FieldCode.Interface] = @interface; |
||
131 | message.Header.Fields[FieldCode.Member] = member; |
||
132 | } |
||
133 | |||
134 | public Signal (Message message) |
||
135 | { |
||
136 | this.message = message; |
||
137 | Path = (ObjectPath)message.Header.Fields[FieldCode.Path]; |
||
138 | Interface = (string)message.Header.Fields[FieldCode.Interface]; |
||
139 | Member = (string)message.Header.Fields[FieldCode.Member]; |
||
140 | if (message.Header.Fields.ContainsKey (FieldCode.Sender)) |
||
141 | Sender = (string)message.Header.Fields[FieldCode.Sender]; |
||
142 | } |
||
143 | |||
144 | public ObjectPath Path; |
||
145 | public string Interface; |
||
146 | public string Member; |
||
147 | public string Sender; |
||
148 | } |
||
149 | } |