summaryrefslogtreecommitdiff
path: root/csharp/test/Ice/info/TestI.cs
blob: 31ef27ef50520a3550c26f122bb63fda65b3e01d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

using System.Collections.Generic;

namespace Ice
{
    namespace info
    {
        public class TestI : Test.TestIntfDisp_
        {
            private static Ice.IPEndpointInfo getIPEndpointInfo(Ice.EndpointInfo info)
            {
                for(; info != null; info = info.underlying)
                {
                    if(info is Ice.IPEndpointInfo)
                    {
                        return info as Ice.IPEndpointInfo;
                    }
                }
                return null;
            }

            private static Ice.IPConnectionInfo getIPConnectionInfo(Ice.ConnectionInfo info)
            {
                for(; info != null; info = info.underlying)
                {
                    if(info is Ice.IPConnectionInfo)
                    {
                        return info as Ice.IPConnectionInfo;
                    }
                }
                return null;
            }

            override public void shutdown(Ice.Current current)
            {
                current.adapter.getCommunicator().shutdown();
            }

            override public Dictionary<string, string> getEndpointInfoAsContext(Ice.Current c)
            {
                Dictionary<string, string> ctx = new Dictionary<string, string>();
                Ice.EndpointInfo info = c.con.getEndpoint().getInfo();
                ctx["timeout"] = info.timeout.ToString();
                ctx["compress"] = info.compress ? "true" : "false";
                ctx["datagram"] = info.datagram() ? "true" : "false";
                ctx["secure"] = info.datagram() ? "true" : "false";
                ctx["type"] = info.type().ToString();

                Ice.IPEndpointInfo ipinfo = getIPEndpointInfo(info);
                ctx["host"] = ipinfo.host;
                ctx["port"] = ipinfo.port.ToString();

                if(ipinfo is Ice.UDPEndpointInfo)
                {
                    Ice.UDPEndpointInfo udp =(Ice.UDPEndpointInfo)ipinfo;
                    ctx["mcastInterface"] = udp.mcastInterface;
                    ctx["mcastTtl"] = udp.mcastTtl.ToString();
                }

                return ctx;
            }

            override public Dictionary<string, string> getConnectionInfoAsContext(Ice.Current c)
            {
                Dictionary<string, string> ctx = new Dictionary<string, string>();
                Ice.ConnectionInfo info = c.con.getInfo();
                ctx["adapterName"] = info.adapterName;
                ctx["incoming"] = info.incoming ? "true" : "false";

                Ice.IPConnectionInfo ipinfo = getIPConnectionInfo(info);
                ctx["localAddress"] = ipinfo.localAddress;
                ctx["localPort"] = ipinfo.localPort.ToString();
                ctx["remoteAddress"] = ipinfo.remoteAddress;
                ctx["remotePort"] = ipinfo.remotePort.ToString();

                if(info is Ice.WSConnectionInfo)
                {
                    Ice.WSConnectionInfo wsinfo =(Ice.WSConnectionInfo)info;
                    foreach(KeyValuePair<string, string> e in wsinfo.headers)
                    {
                        ctx["ws." + e.Key] = e.Value;
                    }
                }

                return ctx;
            }
        }
    }
}