1 /**********************************************************\
2 |                                                          |
3 |                          hprose                          |
4 |                                                          |
5 | Official WebSite: http://www.hprose.com/                 |
6 |                   http://www.hprose.org/                 |
7 |                                                          |
8 \**********************************************************/
9 
10 /**********************************************************\
11  *                                                        *
12  * hprose/rpc/common.d                                    *
13  *                                                        *
14  * hprose common library for D.                           *
15  *                                                        *
16  * LastModified: Apr 22, 2016                             *
17  * Author: Ma Bingyao <andot@hprose.com>                  *
18  *                                                        *
19 \**********************************************************/
20 
21 module hprose.rpc.common;
22 
23 import hprose.rpc.context;
24 import std.stdio;
25 import std.variant;
26 import std.traits;
27 import std.typecons;
28 import std.typetuple;
29 
30 alias NextInvokeHandler = Variant delegate(string name, ref Variant[] args, Context context);
31 alias InvokeHandler = Variant delegate(string name, ref Variant[] args, Context context, NextInvokeHandler next);
32 
33 alias NextFilterHandler = ubyte[] delegate(ubyte[] request, Context context);
34 alias FilterHandler = ubyte[] delegate(ubyte[] request, Context context, NextFilterHandler next);
35 
36 struct MethodName {
37     string value;
38 }
39 
40 enum ResultMode {
41     Normal, Serialized, Raw, RawWithEndTag
42 }
43 
44 struct Simple {
45     bool value = true;
46 }
47 
48 template isAbstractMethod(T) if (is(T == interface) || is(T == class)) {
49     template isAbstractMethod(string M) {
50         static if (__traits(hasMember, T, M) && __traits(compiles, __traits(getMember, T, M))) {
51             enum isAbstractMethod = __traits(isAbstractFunction, mixin("T." ~ M));
52             
53         }
54         else {
55             enum isAbstractMethod = false;
56         }
57     }
58 }
59 
60 template getAbstractMethods(T) if (is(T == interface) || is(T == class)) {
61     enum allMembers = __traits(allMembers, T);
62     static if (allMembers.length > 0) {
63         enum getAbstractMethods = tuple(Filter!(isAbstractMethod!T, allMembers));
64     }
65     else {
66         static assert(0, T.stringof ~ " has no virtual methods");
67     }
68 }