• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef HandleMessage_h
2 #define HandleMessage_h
3 
4 #include "Arguments.h"
5 
6 namespace CoreIPC {
7 
8 // Dispatch functions with no reply arguments.
9 
10 template<typename C, typename MF>
callMemberFunction(const Arguments0 &,C * object,MF function)11 void callMemberFunction(const Arguments0&, C* object, MF function)
12 {
13     (object->*function)();
14 }
15 
16 template<typename C, typename MF, typename P1>
callMemberFunction(const Arguments1<P1> & args,C * object,MF function)17 void callMemberFunction(const Arguments1<P1>& args, C* object, MF function)
18 {
19     (object->*function)(args.argument1);
20 }
21 
22 template<typename C, typename MF, typename P1, typename P2>
callMemberFunction(const Arguments2<P1,P2> & args,C * object,MF function)23 void callMemberFunction(const Arguments2<P1, P2>& args, C* object, MF function)
24 {
25     (object->*function)(args.argument1, args.argument2);
26 }
27 
28 template<typename C, typename MF, typename P1, typename P2, typename P3>
callMemberFunction(const Arguments3<P1,P2,P3> & args,C * object,MF function)29 void callMemberFunction(const Arguments3<P1, P2, P3>& args, C* object, MF function)
30 {
31     (object->*function)(args.argument1, args.argument2, args.argument3);
32 }
33 
34 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4>
callMemberFunction(const Arguments4<P1,P2,P3,P4> & args,C * object,MF function)35 void callMemberFunction(const Arguments4<P1, P2, P3, P4>& args, C* object, MF function)
36 {
37     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4);
38 }
39 
40 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5>
callMemberFunction(const Arguments5<P1,P2,P3,P4,P5> & args,C * object,MF function)41 void callMemberFunction(const Arguments5<P1, P2, P3, P4, P5>& args, C* object, MF function)
42 {
43     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5);
44 }
45 
46 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
callMemberFunction(const Arguments6<P1,P2,P3,P4,P5,P6> & args,C * object,MF function)47 void callMemberFunction(const Arguments6<P1, P2, P3, P4, P5, P6>& args, C* object, MF function)
48 {
49     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6);
50 }
51 
52 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
callMemberFunction(const Arguments7<P1,P2,P3,P4,P5,P6,P7> & args,C * object,MF function)53 void callMemberFunction(const Arguments7<P1, P2, P3, P4, P5, P6, P7>& args, C* object, MF function)
54 {
55     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, args.argument7);
56 }
57 
58 // Dispatch functions with reply arguments.
59 
60 template<typename C, typename MF>
callMemberFunction(const Arguments0 &,Arguments0 &,C * object,MF function)61 void callMemberFunction(const Arguments0&, Arguments0&, C* object, MF function)
62 {
63     (object->*function)();
64 }
65 
66 template<typename C, typename MF, typename R1>
callMemberFunction(const Arguments0 &,Arguments1<R1> & replyArgs,C * object,MF function)67 void callMemberFunction(const Arguments0&, Arguments1<R1>& replyArgs, C* object, MF function)
68 {
69     (object->*function)(replyArgs.argument1);
70 }
71 
72 template<typename C, typename MF, typename R1, typename R2>
callMemberFunction(const Arguments0 &,Arguments2<R1,R2> & replyArgs,C * object,MF function)73 void callMemberFunction(const Arguments0&, Arguments2<R1, R2>& replyArgs, C* object, MF function)
74 {
75     (object->*function)(replyArgs.argument1, replyArgs.argument2);
76 }
77 
78 template<typename C, typename MF, typename P1>
callMemberFunction(const Arguments1<P1> & args,Arguments0 &,C * object,MF function)79 void callMemberFunction(const Arguments1<P1>& args, Arguments0&, C* object, MF function)
80 {
81     (object->*function)(args.argument1);
82 }
83 
84 template<typename C, typename MF, typename P1, typename R1>
callMemberFunction(const Arguments1<P1> & args,Arguments1<R1> & replyArgs,C * object,MF function)85 void callMemberFunction(const Arguments1<P1>& args, Arguments1<R1>& replyArgs, C* object, MF function)
86 {
87     (object->*function)(args.argument1, replyArgs.argument1);
88 }
89 
90 template<typename C, typename MF, typename P1, typename R1, typename R2>
callMemberFunction(const Arguments1<P1> & args,Arguments2<R1,R2> & replyArgs,C * object,MF function)91 void callMemberFunction(const Arguments1<P1>& args, Arguments2<R1, R2>& replyArgs, C* object, MF function)
92 {
93     (object->*function)(args.argument1, replyArgs.argument1, replyArgs.argument2);
94 }
95 
96 template<typename C, typename MF, typename P1, typename R1, typename R2, typename R3>
callMemberFunction(const Arguments1<P1> & args,Arguments3<R1,R2,R3> & replyArgs,C * object,MF function)97 void callMemberFunction(const Arguments1<P1>& args, Arguments3<R1, R2, R3>& replyArgs, C* object, MF function)
98 {
99     (object->*function)(args.argument1, replyArgs.argument1, replyArgs.argument2, replyArgs.argument3);
100 }
101 
102 template<typename C, typename MF, typename P1, typename P2>
callMemberFunction(const Arguments2<P1,P2> & args,Arguments0 &,C * object,MF function)103 void callMemberFunction(const Arguments2<P1, P2>& args, Arguments0&, C* object, MF function)
104 {
105     (object->*function)(args.argument1, args.argument2);
106 }
107 
108 template<typename C, typename MF, typename P1, typename R1, typename R2, typename R3, typename R4>
callMemberFunction(const Arguments1<P1> & args,Arguments4<R1,R2,R3,R4> & replyArgs,C * object,MF function)109 void callMemberFunction(const Arguments1<P1>& args, Arguments4<R1, R2, R3, R4>& replyArgs, C* object, MF function)
110 {
111     (object->*function)(args.argument1, replyArgs.argument1, replyArgs.argument2, replyArgs.argument3, replyArgs.argument4);
112 }
113 
114 template<typename C, typename MF, typename P1, typename P2, typename R1>
callMemberFunction(const Arguments2<P1,P2> & args,Arguments1<R1> & replyArgs,C * object,MF function)115 void callMemberFunction(const Arguments2<P1, P2>& args, Arguments1<R1>& replyArgs, C* object, MF function)
116 {
117     (object->*function)(args.argument1, args.argument2, replyArgs.argument1);
118 }
119 
120 template<typename C, typename MF, typename P1, typename P2, typename R1, typename R2>
callMemberFunction(const Arguments2<P1,P2> & args,Arguments2<R1,R2> & replyArgs,C * object,MF function)121 void callMemberFunction(const Arguments2<P1, P2>& args, Arguments2<R1, R2>& replyArgs, C* object, MF function)
122 {
123     (object->*function)(args.argument1, args.argument2, replyArgs.argument1, replyArgs.argument2);
124 }
125 
126 template<typename C, typename MF, typename P1, typename P2, typename P3, typename R1>
callMemberFunction(const Arguments3<P1,P2,P3> & args,Arguments1<R1> & replyArgs,C * object,MF function)127 void callMemberFunction(const Arguments3<P1, P2, P3>& args, Arguments1<R1>& replyArgs, C* object, MF function)
128 {
129     (object->*function)(args.argument1, args.argument2, args.argument3, replyArgs.argument1);
130 }
131 
132 template<typename C, typename MF, typename P1, typename P2, typename P3, typename R1, typename R2>
callMemberFunction(const Arguments3<P1,P2,P3> & args,Arguments2<R1,R2> & replyArgs,C * object,MF function)133 void callMemberFunction(const Arguments3<P1, P2, P3>& args, Arguments2<R1, R2>& replyArgs, C* object, MF function)
134 {
135     (object->*function)(args.argument1, args.argument2, args.argument3, replyArgs.argument1, replyArgs.argument2);
136 }
137 
138 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename R1>
callMemberFunction(const Arguments4<P1,P2,P3,P4> & args,Arguments1<R1> & replyArgs,C * object,MF function)139 void callMemberFunction(const Arguments4<P1, P2, P3, P4>& args, Arguments1<R1>& replyArgs, C* object, MF function)
140 {
141     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, replyArgs.argument1);
142 }
143 
144 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R1>
callMemberFunction(const Arguments6<P1,P2,P3,P4,P5,P6> & args,Arguments1<R1> & replyArgs,C * object,MF function)145 void callMemberFunction(const Arguments6<P1, P2, P3, P4, P5, P6>& args, Arguments1<R1>& replyArgs, C* object, MF function)
146 {
147     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, replyArgs.argument1);
148 }
149 
150 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename R1>
callMemberFunction(const Arguments7<P1,P2,P3,P4,P5,P6,P7> & args,Arguments1<R1> & replyArgs,C * object,MF function)151 void callMemberFunction(const Arguments7<P1, P2, P3, P4, P5, P6, P7>& args, Arguments1<R1>& replyArgs, C* object, MF function)
152 {
153     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, args.argument7, replyArgs.argument1);
154 }
155 
156 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename R1, typename R2>
callMemberFunction(const Arguments4<P1,P2,P3,P4> & args,Arguments2<R1,R2> & replyArgs,C * object,MF function)157 void callMemberFunction(const Arguments4<P1, P2, P3, P4>& args, Arguments2<R1, R2>& replyArgs, C* object, MF function)
158 {
159     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, replyArgs.argument1, replyArgs.argument2);
160 }
161 
162 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename R1, typename R2>
callMemberFunction(const Arguments5<P1,P2,P3,P4,P5> & args,Arguments2<R1,R2> & replyArgs,C * object,MF function)163 void callMemberFunction(const Arguments5<P1, P2, P3, P4, P5>& args, Arguments2<R1, R2>& replyArgs, C* object, MF function)
164 {
165     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, replyArgs.argument1, replyArgs.argument2);
166 }
167 
168 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R1, typename R2>
callMemberFunction(const Arguments6<P1,P2,P3,P4,P5,P6> & args,Arguments2<R1,R2> & replyArgs,C * object,MF function)169 void callMemberFunction(const Arguments6<P1, P2, P3, P4, P5, P6>& args, Arguments2<R1, R2>& replyArgs, C* object, MF function)
170 {
171     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, replyArgs.argument1, replyArgs.argument2);
172 }
173 
174 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename R1, typename R2, typename R3>
callMemberFunction(const Arguments4<P1,P2,P3,P4> & args,Arguments3<R1,R2,R3> & replyArgs,C * object,MF function)175 void callMemberFunction(const Arguments4<P1, P2, P3, P4>& args, Arguments3<R1, R2, R3>& replyArgs, C* object, MF function)
176 {
177     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, replyArgs.argument1, replyArgs.argument2, replyArgs.argument3);
178 }
179 
180 // Dispatch functions with delayed reply arguments.
181 template<typename C, typename MF, typename P1, typename R>
callMemberFunction(const Arguments1<P1> & args,PassRefPtr<R> delayedReply,C * object,MF function)182 void callMemberFunction(const Arguments1<P1>& args, PassRefPtr<R> delayedReply, C* object, MF function)
183 {
184     (object->*function)(args.argument1, delayedReply);
185 }
186 
187 // Variadic dispatch functions.
188 
189 template<typename C, typename MF>
callMemberFunction(const Arguments0 &,ArgumentDecoder * argumentDecoder,C * object,MF function)190 void callMemberFunction(const Arguments0&, ArgumentDecoder* argumentDecoder, C* object, MF function)
191 {
192     (object->*function)(argumentDecoder);
193 }
194 
195 template<typename C, typename MF, typename P1>
callMemberFunction(const Arguments1<P1> & args,ArgumentDecoder * argumentDecoder,C * object,MF function)196 void callMemberFunction(const Arguments1<P1>& args, ArgumentDecoder* argumentDecoder, C* object, MF function)
197 {
198     (object->*function)(args.argument1, argumentDecoder);
199 }
200 
201 template<typename C, typename MF, typename P1, typename P2>
callMemberFunction(const Arguments2<P1,P2> & args,ArgumentDecoder * argumentDecoder,C * object,MF function)202 void callMemberFunction(const Arguments2<P1, P2>& args, ArgumentDecoder* argumentDecoder, C* object, MF function)
203 {
204     (object->*function)(args.argument1, args.argument2, argumentDecoder);
205 }
206 
207 template<typename C, typename MF, typename P1, typename P2, typename P3>
callMemberFunction(const Arguments3<P1,P2,P3> & args,ArgumentDecoder * argumentDecoder,C * object,MF function)208 void callMemberFunction(const Arguments3<P1, P2, P3>& args, ArgumentDecoder* argumentDecoder, C* object, MF function)
209 {
210     (object->*function)(args.argument1, args.argument2, args.argument3, argumentDecoder);
211 }
212 
213 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4>
callMemberFunction(const Arguments4<P1,P2,P3,P4> & args,ArgumentDecoder * argumentDecoder,C * object,MF function)214 void callMemberFunction(const Arguments4<P1, P2, P3, P4>& args, ArgumentDecoder* argumentDecoder, C* object, MF function)
215 {
216     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, argumentDecoder);
217 }
218 
219 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5>
callMemberFunction(const Arguments5<P1,P2,P3,P4,P5> & args,ArgumentDecoder * argumentDecoder,C * object,MF function)220 void callMemberFunction(const Arguments5<P1, P2, P3, P4, P5>& args, ArgumentDecoder* argumentDecoder, C* object, MF function)
221 {
222     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, argumentDecoder);
223 }
224 
225 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
callMemberFunction(const Arguments6<P1,P2,P3,P4,P5,P6> & args,ArgumentDecoder * argumentDecoder,C * object,MF function)226 void callMemberFunction(const Arguments6<P1, P2, P3, P4, P5, P6>& args, ArgumentDecoder* argumentDecoder, C* object, MF function)
227 {
228     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, argumentDecoder);
229 }
230 
231 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
callMemberFunction(const Arguments7<P1,P2,P3,P4,P5,P6,P7> & args,ArgumentDecoder * argumentDecoder,C * object,MF function)232 void callMemberFunction(const Arguments7<P1, P2, P3, P4, P5, P6, P7>& args, ArgumentDecoder* argumentDecoder, C* object, MF function)
233 {
234     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, args.argument7, argumentDecoder);
235 }
236 
237 // Variadic dispatch functions with non-variadic reply arguments.
238 
239 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename R1, typename R2, typename R3>
callMemberFunction(const Arguments4<P1,P2,P3,P4> & args,ArgumentDecoder * argumentDecoder,Arguments3<R1,R2,R3> & replyArgs,C * object,MF function)240 void callMemberFunction(const Arguments4<P1, P2, P3, P4>& args, ArgumentDecoder* argumentDecoder, Arguments3<R1, R2, R3>& replyArgs, C* object, MF function)
241 {
242     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, argumentDecoder, replyArgs.argument1, replyArgs.argument2, replyArgs.argument3);
243 }
244 
245 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R1, typename R2>
callMemberFunction(const Arguments6<P1,P2,P3,P4,P5,P6> & args,ArgumentDecoder * argumentDecoder,Arguments2<R1,R2> & replyArgs,C * object,MF function)246 void callMemberFunction(const Arguments6<P1, P2, P3, P4, P5, P6>& args, ArgumentDecoder* argumentDecoder, Arguments2<R1, R2>& replyArgs, C* object, MF function)
247 {
248     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, argumentDecoder, replyArgs.argument1, replyArgs.argument2);
249 }
250 
251 template<typename C, typename MF, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename R1, typename R2, typename R3>
callMemberFunction(const Arguments6<P1,P2,P3,P4,P5,P6> & args,ArgumentDecoder * argumentDecoder,Arguments3<R1,R2,R3> & replyArgs,C * object,MF function)252 void callMemberFunction(const Arguments6<P1, P2, P3, P4, P5, P6>& args, ArgumentDecoder* argumentDecoder, Arguments3<R1, R2, R3>& replyArgs, C* object, MF function)
253 {
254     (object->*function)(args.argument1, args.argument2, args.argument3, args.argument4, args.argument5, args.argument6, argumentDecoder, replyArgs.argument1, replyArgs.argument2, replyArgs.argument3);
255 }
256 
257 // Main dispatch functions
258 
259 template<typename T, typename C, typename MF>
handleMessage(ArgumentDecoder * argumentDecoder,C * object,MF function)260 void handleMessage(ArgumentDecoder* argumentDecoder, C* object, MF function)
261 {
262     typename T::DecodeType::ValueType arguments;
263     if (!argumentDecoder->decode(arguments))
264         return;
265     callMemberFunction(arguments, object, function);
266 }
267 
268 template<typename T, typename C, typename MF>
handleMessage(ArgumentDecoder * argumentDecoder,ArgumentEncoder * replyEncoder,C * object,MF function)269 void handleMessage(ArgumentDecoder* argumentDecoder, ArgumentEncoder* replyEncoder, C* object, MF function)
270 {
271     typename T::DecodeType::ValueType arguments;
272     if (!argumentDecoder->decode(arguments))
273         return;
274 
275     typename T::Reply::ValueType replyArguments;
276     callMemberFunction(arguments, replyArguments, object, function);
277     replyEncoder->encode(replyArguments);
278 }
279 
280 template<typename T, typename C, typename MF>
handleMessageVariadic(ArgumentDecoder * argumentDecoder,C * object,MF function)281 void handleMessageVariadic(ArgumentDecoder* argumentDecoder, C* object, MF function)
282 {
283     typename T::DecodeType::ValueType arguments;
284     if (!argumentDecoder->decode(arguments))
285         return;
286     callMemberFunction(arguments, argumentDecoder, object, function);
287 }
288 
289 
290 template<typename T, typename C, typename MF>
handleMessageVariadic(ArgumentDecoder * argumentDecoder,ArgumentEncoder * replyEncoder,C * object,MF function)291 void handleMessageVariadic(ArgumentDecoder* argumentDecoder, ArgumentEncoder* replyEncoder, C* object, MF function)
292 {
293     typename T::DecodeType::ValueType arguments;
294     if (!argumentDecoder->decode(arguments))
295         return;
296 
297     typename T::Reply::ValueType replyArguments;
298     callMemberFunction(arguments, argumentDecoder, replyArguments, object, function);
299     replyEncoder->encode(replyArguments);
300 }
301 
302 template<typename T, typename C, typename MF>
handleMessageDelayed(Connection * connection,ArgumentDecoder * argumentDecoder,ArgumentEncoder * replyEncoder,C * object,MF function)303 void handleMessageDelayed(Connection* connection, ArgumentDecoder* argumentDecoder, ArgumentEncoder* replyEncoder, C* object, MF function)
304 {
305     typename T::DecodeType::ValueType arguments;
306     if (!argumentDecoder->decode(arguments))
307         return;
308 
309     RefPtr<typename T::DelayedReply> delayedReply = adoptRef(new typename T::DelayedReply(connection, replyEncoder));
310     callMemberFunction(arguments, delayedReply.release(), object, function);
311 }
312 
313 } // namespace CoreIPC
314 
315 #endif // HandleMessage_h
316