summaryrefslogtreecommitdiff
path: root/python/test/Ice/info/TestI.py
blob: 1bd913e36303cbdb9979bc681bb9b9ba1eb005d8 (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
#
# Copyright (c) ZeroC, Inc. All rights reserved.
#

import Ice, Test
import time

def getIPEndpointInfo(info):
    while(info):
        if isinstance(info, Ice.IPEndpointInfo):
            return info
        info = info.underlying

def getIPConnectionInfo(info):
    while(info):
        if isinstance(info, Ice.IPConnectionInfo):
            return info
        info = info.underlying

class MyDerivedClassI(Test.TestIntf):
    def __init__(self):
        self.ctx = None

    def shutdown(self, current=None):
        current.adapter.getCommunicator().shutdown()

    def getEndpointInfoAsContext(self, current):
        ctx = {}
        info = getIPEndpointInfo(current.con.getEndpoint().getInfo())
        ctx["timeout"] = str(info.timeout)
        if info.compress:
            ctx["compress"] = "true"
        else:
            ctx["compress"] ="false"
        if info.datagram():
            ctx["datagram"] = "true"
        else:
            ctx["datagram"] ="false"
        if info.secure():
            ctx["secure"] = "true"
        else:
            ctx["secure"] ="false"
        ctx["type"] = str(info.type())

        ctx["host"] = info.host
        ctx["port"] = str(info.port)

        if isinstance(info, Ice.UDPEndpointInfo):
            ctx["protocolMajor"] = str(info.protocolMajor)
            ctx["protocolMinor"] = str(info.protocolMinor)
            ctx["encodingMajor"] = str(info.encodingMajor)
            ctx["encodingMinor"] = str(info.encodingMinor)
            ctx["mcastInterface"] = info.mcastInterface
            ctx["mcastTtl"] = str(info.mcastTtl)

        return ctx

    def getConnectionInfoAsContext(self, current):
        ctx = {}
        info = current.con.getInfo()
        ipinfo = getIPConnectionInfo(info)
        ctx["adapterName"] = info.adapterName
        if info.incoming:
            ctx["incoming"] = "true"
        else:
            ctx["incoming"] ="false"

        ctx["localAddress"] = ipinfo.localAddress
        ctx["localPort"] = str(ipinfo.localPort)
        ctx["remoteAddress"] = ipinfo.remoteAddress
        ctx["remotePort"] = str(ipinfo.remotePort)

        if isinstance(info, Ice.WSConnectionInfo):
            for key, value in info.headers.items():
                ctx["ws." + key] = value

        return ctx