blob: adbe732bdf7913d22808f32ec2cea5da49ab6206 (
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
// **********************************************************************
//
// Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in
// the ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#import <EndpointI.h>
#import <Util.h>
#import <VersionI.h>
#import <LocalObjectI.h>
#import <objc/Ice/BuiltinSequences.h>
#import <Ice/Endpoint.h>
#include <objc/runtime.h>
#define ENDPOINT dynamic_cast<Ice::Endpoint*>(static_cast<IceUtil::Shared*>(cxxObject_))
#define ENDPOINTINFO dynamic_cast<Ice::EndpointInfo*>(static_cast<IceUtil::Shared*>(cxxObject_))
@implementation ICEEndpoint
-(Ice::Endpoint*) endpoint
{
return ENDPOINT;
}
-(ICEEndpointInfo*) getInfo
{
NSException* nsex = nil;
try
{
Ice::EndpointInfoPtr info = ENDPOINT->getInfo();
if(!info)
{
return nil;
}
Ice::UDPEndpointInfoPtr udpInfo = Ice::UDPEndpointInfoPtr::dynamicCast(info);
if(udpInfo)
{
return [[[ICEUDPEndpointInfo alloc] initWithUDPEndpointInfo:udpInfo.get()] autorelease];
}
Ice::WSEndpointInfoPtr wsInfo = Ice::WSEndpointInfoPtr::dynamicCast(info);
if(wsInfo)
{
return [[[ICEWSEndpointInfo alloc] initWithWSEndpointInfo:wsInfo.get()] autorelease];
}
Ice::TCPEndpointInfoPtr tcpInfo = Ice::TCPEndpointInfoPtr::dynamicCast(info);
if(tcpInfo)
{
return [[[ICETCPEndpointInfo alloc] initWithTCPEndpointInfo:tcpInfo.get()] autorelease];
}
Ice::OpaqueEndpointInfoPtr opaqueInfo = Ice::OpaqueEndpointInfoPtr::dynamicCast(info);
if(opaqueInfo)
{
return [[[ICEOpaqueEndpointInfo alloc] initWithOpaqueEndpointInfo:opaqueInfo.get()] autorelease];
}
std::ostringstream os;
os << "endpointInfoWithType_" << info->type() << ":";
SEL selector = sel_registerName(os.str().c_str());
if([ICEEndpointInfo respondsToSelector:selector])
{
IceUtil::Shared* shared = info.get();
return [ICEEndpointInfo performSelector:selector withObject:[NSValue valueWithPointer:shared]];
}
Ice::IPEndpointInfoPtr ipInfo = Ice::IPEndpointInfoPtr::dynamicCast(info);
if(ipInfo)
{
return [[[ICEIPEndpointInfo alloc] initWithIPEndpointInfo:ipInfo.get()] autorelease];
}
return [[[ICEEndpointInfo alloc] initWithEndpointInfo:info.get()] autorelease];
}
catch(const std::exception& ex)
{
nsex = toObjCException(ex);
}
if(nsex != nil)
{
@throw nsex;
}
return nil;
}
-(NSMutableString*) toString
{
return [toNSMutableString(ENDPOINT->toString()) autorelease];
}
@end
@implementation ICEEndpointInfo(ICEInternal)
-(id) initWithEndpointInfo:(Ice::EndpointInfo*)endpointInfo;
{
self = [super initWithCxxObject:endpointInfo];
if(self)
{
self->timeout = endpointInfo->timeout;
self->compress = endpointInfo->compress;
}
return self;
}
-(ICEShort) type
{
return ENDPOINTINFO->type();
}
-(BOOL) datagram;
{
return ENDPOINTINFO->datagram();
}
-(BOOL) secure;
{
return ENDPOINTINFO->secure();
}
@end
@implementation ICEIPEndpointInfo(ICEInternal)
-(id) initWithIPEndpointInfo:(Ice::IPEndpointInfo*)ipEndpointInfo;
{
self = [super initWithEndpointInfo:ipEndpointInfo];
if(self)
{
self->host = [[NSString alloc] initWithUTF8String:ipEndpointInfo->host.c_str()];
self->port = ipEndpointInfo->port;
self->sourceAddress = [[NSString alloc] initWithUTF8String:ipEndpointInfo->sourceAddress.c_str()];
}
return self;
}
@end
@implementation ICETCPEndpointInfo(ICEInternal)
-(id) initWithTCPEndpointInfo:(Ice::TCPEndpointInfo*)tcpEndpointInfo
{
self = [super initWithIPEndpointInfo:tcpEndpointInfo];
return self;
}
@end
@implementation ICEUDPEndpointInfo(ICEInternal)
-(id) initWithUDPEndpointInfo:(Ice::UDPEndpointInfo*)udpEndpointInfo
{
self = [super initWithIPEndpointInfo:udpEndpointInfo];
if(self)
{
self->mcastInterface = [[NSString alloc] initWithUTF8String:udpEndpointInfo->mcastInterface.c_str()];
self->mcastTtl = udpEndpointInfo->mcastTtl;
}
return self;
}
@end
@implementation ICEWSEndpointInfo(ICEInternal)
-(id) initWithWSEndpointInfo:(Ice::WSEndpointInfo*)wsEndpointInfo
{
self = [super initWithIPEndpointInfo:wsEndpointInfo];
if(self)
{
self->resource = [[NSString alloc] initWithUTF8String:wsEndpointInfo->resource.c_str()];
}
return self;
}
@end
@implementation ICEOpaqueEndpointInfo(ICEInternal)
-(id) initWithOpaqueEndpointInfo:(Ice::OpaqueEndpointInfo*)opaqueEndpointInfo
{
self = [super init];
if(self)
{
self->rawEncoding = [[ICEEncodingVersion alloc] initWithEncodingVersion:opaqueEndpointInfo->rawEncoding];
self->rawBytes = toNSData(opaqueEndpointInfo->rawBytes);
}
return self;
}
@end
|