1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#import <ProxyI.h>
6#import <Util.h>
7#import <StreamI.h>
8#import <VersionI.h>
9#import <CommunicatorI.h>
10#import <IdentityI.h>
11#import <ConnectionI.h>
12#import <LocalObjectI.h>
13
14#import <objc/Ice/Object.h>
15#import <objc/Ice/LocalException.h>
16#import <objc/Ice/Router.h>
17#import <objc/Ice/Locator.h>
18
19#include <Ice/Initialize.h>
20#include <Ice/Proxy.h>
21#include <Ice/LocalException.h>
22#include <Ice/Router.h>
23#include <Ice/Locator.h>
24
25#import <objc/runtime.h>
26#import <objc/message.h>
27
28#import <Foundation/NSThread.h>
29#import <Foundation/NSInvocation.h>
30
31#include <Block.h>
32
33#define OBJECTPRX ((IceProxy::Ice::Object*)objectPrx_)
34#define ASYNCRESULT ((Ice::AsyncResult*)asyncResult_)
35
36namespace
37{
38
39class BeginInvokeAsyncCallback : public IceUtil::Shared
40{
41public:
42
43BeginInvokeAsyncCallback(const Ice::CommunicatorPtr& communicator,
44                         void (^completed)(id<ICEInputStream>, BOOL),
45                         void (^exception)(ICEException*),
46                         void (^sent)(BOOL),
47                         BOOL returnsData) :
48    _communicator(communicator),
49    _completed(Block_copy(completed)),
50    _exception(Block_copy(exception)),
51    _sent(Block_copy(sent)),
52    _returnsData(returnsData)
53{
54}
55
56virtual ~BeginInvokeAsyncCallback()
57{
58    Block_release(_completed);
59    Block_release(_exception);
60    Block_release(_sent);
61}
62
63void response(bool ok, const std::pair<const Ice::Byte*, const Ice::Byte*>& outParams)
64{
65    id<ICEInputStream> is = [[ICEInputStream alloc] initWithCxxCommunicator:_communicator.get() data:outParams];
66    NSException* exception = nil;
67    @autoreleasepool
68    {
69        @try
70        {
71            if(_returnsData)
72            {
73                _completed(is, ok);
74            }
75            else if(outParams.first != outParams.second)
76            {
77                if(ok)
78                {
79                    [is skipEmptyEncapsulation];
80                }
81                else
82                {
83                    @try
84                    {
85                        [is startEncapsulation];
86                        [is throwException];
87                    }
88                    @catch(ICEUserException *ex)
89                    {
90                        [is endEncapsulation];
91                        @throw [ICEUnknownUserException unknownUserException:__FILE__ line:__LINE__ unknown:[ex ice_id]];
92                    }
93                }
94                _completed(nil, ok);
95            }
96        }
97        @catch(id e)
98        {
99            exception = [e retain];
100        }
101        @finally
102        {
103            [is release];
104        }
105    }
106
107    if(exception != nil)
108    {
109        rethrowCxxException(exception, true); // True = release the exception.
110    }
111}
112
113void exception(const Ice::Exception& ex)
114{
115    NSException* exception = nil;
116    @autoreleasepool
117    {
118        @try
119        {
120            @throw toObjCException(ex);
121        }
122        @catch(ICEException* ex)
123        {
124            if(_exception)
125            {
126                @try
127                {
128                    _exception(ex);
129                }
130                @catch(id e)
131                {
132                    exception = [e retain];
133                }
134            }
135        }
136    }
137    if(exception != nil)
138    {
139        rethrowCxxException(exception, true); // True = release the exception.
140    }
141}
142
143void sent(bool sentSynchronously)
144{
145    if(!_sent)
146    {
147        return;
148    }
149
150    NSException* exception = nil;
151    @autoreleasepool
152    {
153        @try
154        {
155            _sent(sentSynchronously);
156        }
157        @catch(id e)
158        {
159            exception = [e retain];
160        }
161    }
162
163    if(exception != nil)
164    {
165        rethrowCxxException(exception, true); // True = release the exception.
166    }
167}
168
169private:
170
171const Ice::CommunicatorPtr _communicator;
172void (^_completed)(id<ICEInputStream>, BOOL);
173void (^_exception)(ICEException*);
174void (^_sent)(BOOL);
175BOOL _returnsData;
176
177};
178
179};
180
181@implementation ICEAsyncResult
182-(ICEAsyncResult*) initWithAsyncResult:(const Ice::AsyncResultPtr&)arg
183                               operation:(NSString*)op
184                                   proxy:(id<ICEObjectPrx>)p
185{
186    self = [super init];
187    if(!self)
188    {
189        return nil;
190    }
191
192    asyncResult_ = arg.get();
193    ASYNCRESULT->__incRef();
194    operation_ = [op retain];
195    proxy_ = [p retain];
196    return self;
197}
198
199-(Ice::AsyncResult*) asyncResult
200{
201    return ASYNCRESULT;
202}
203
204-(void) dealloc
205{
206    ASYNCRESULT->__decRef();
207    asyncResult_ = 0;
208    [operation_ release];
209    [proxy_ release];
210    [super dealloc];
211}
212
213+(ICEAsyncResult*) asyncResultWithAsyncResult:(const Ice::AsyncResultPtr&)arg
214{
215    return [self asyncResultWithAsyncResult:arg operation:nil proxy:nil];
216}
217+(ICEAsyncResult*) asyncResultWithAsyncResult:(const Ice::AsyncResultPtr&)arg
218                                      operation:(NSString*)op
219                                          proxy:(id<ICEObjectPrx>)p
220{
221    if(!arg)
222    {
223        return nil;
224    }
225    else
226    {
227        return [[[self alloc] initWithAsyncResult:arg operation:op proxy:p] autorelease];
228    }
229}
230-(NSString*) operation
231{
232    return operation_;
233}
234
235-(void) cancel
236{
237    ASYNCRESULT->cancel();
238}
239
240-(id<ICECommunicator>) getCommunicator
241{
242    return [ICECommunicator localObjectWithCxxObject:ASYNCRESULT->getCommunicator().get()];
243}
244
245-(id<ICEConnection>) getConnection
246{
247    return [ICEConnection localObjectWithCxxObject:ASYNCRESULT->getConnection().get()];
248}
249
250-(id<ICEObjectPrx>) getProxy
251{
252    return [[proxy_ retain] autorelease];
253}
254
255-(BOOL) isCompleted
256{
257    return ASYNCRESULT->isCompleted();
258}
259
260-(void) waitForCompleted
261{
262    ASYNCRESULT->waitForCompleted();
263}
264
265-(BOOL) isSent
266{
267    return ASYNCRESULT->isSent();
268}
269
270-(void) waitForSent
271{
272    ASYNCRESULT->waitForSent();
273}
274
275-(BOOL) sentSynchronously
276{
277    return ASYNCRESULT->sentSynchronously();
278}
279
280-(void) throwLocalException
281{
282    NSException* nsex;
283    try
284    {
285        ASYNCRESULT->throwLocalException();
286        return;
287    }
288    catch(const std::exception& ex)
289    {
290        nsex = toObjCException(ex);
291    }
292    @throw nsex;
293}
294
295-(NSString*) getOperation
296{
297    if(operation_ != nil)
298    {
299        return [[operation_ retain] autorelease];
300    }
301    else
302    {
303        return [toNSString(ASYNCRESULT->getOperation()) autorelease];
304    }
305}
306@end
307
308@implementation ICEObjectPrx
309
310-(ICEObjectPrx*) iceInitWithObjectPrx:(const Ice::ObjectPrx&)arg
311{
312    self = [super init];
313    if(!self)
314    {
315        return nil;
316    }
317    communicator_ = [ICECommunicator localObjectWithCxxObjectNoAutoRelease:arg->ice_getCommunicator().get()];
318    objectPrx_ = arg.get();
319    OBJECTPRX->__incRef();
320    return self;
321}
322
323-(IceProxy::Ice::Object*) iceObjectPrx
324{
325    return (IceProxy::Ice::Object*)objectPrx_;
326}
327
328-(void) dealloc
329{
330    OBJECTPRX->__decRef();
331    objectPrx_ = 0;
332    [communicator_ release];
333    [super dealloc];
334}
335
336+(ICEObjectPrx*) iceObjectPrxWithObjectPrx:(const Ice::ObjectPrx&)arg
337{
338    if(!arg)
339    {
340        return nil;
341    }
342    else
343    {
344        return [[[self alloc] iceInitWithObjectPrx:arg] autorelease];
345    }
346}
347
348+(id) uncheckedCast:(id<ICEObjectPrx>)proxy
349{
350    if(proxy != nil)
351    {
352        if([(ICEObjectPrx*)proxy isKindOfClass:self])
353        {
354            return [[proxy retain] autorelease];
355        }
356        else
357        {
358            return [[[self alloc] iceInitWithObjectPrx:[(ICEObjectPrx*)proxy iceObjectPrx]] autorelease];
359        }
360    }
361    return nil;
362}
363+(id) uncheckedCast:(id<ICEObjectPrx>)proxy facet:(NSString*)facet
364{
365    return [self uncheckedCast:[proxy ice_facet:facet]];
366}
367+(id) checkedCast:(id<ICEObjectPrx>)proxy
368{
369    if(proxy != nil)
370    {
371        if([(ICEObjectPrx*)proxy isKindOfClass:self])
372        {
373            return [[proxy retain] autorelease];
374        }
375        else if([(ICEObjectPrx*)proxy conformsToProtocol:[self iceProtocol]] ||
376                [proxy ice_isA:[self ice_staticId]])
377        {
378            return [[[self alloc] iceInitWithObjectPrx:[(ICEObjectPrx*)proxy iceObjectPrx]] autorelease];
379        }
380    }
381    return nil;
382}
383+(id) checkedCast:(id<ICEObjectPrx>)proxy facet:(NSString*)facet
384{
385    @try
386    {
387        return [self checkedCast:[proxy ice_facet:facet]];
388    }
389    @catch(ICEFacetNotExistException* ex)
390    {
391        return nil;
392    }
393}
394+(id) checkedCast:(id<ICEObjectPrx>)proxy context:(ICEContext*)context
395{
396    if(proxy != nil)
397    {
398        if([(ICEObjectPrx*)proxy isKindOfClass:self])
399        {
400            return [[proxy retain] autorelease];
401        }
402        else if([(ICEObjectPrx*)proxy conformsToProtocol:[self iceProtocol]] ||
403                [proxy ice_isA:[self ice_staticId] context:context])
404        {
405            return [[[self alloc] iceInitWithObjectPrx:[(ICEObjectPrx*)proxy iceObjectPrx]] autorelease];
406        }
407    }
408    return nil;
409}
410+(id) checkedCast:(id<ICEObjectPrx>)proxy facet:(NSString*)facet context:(ICEContext*)context
411{
412    @try
413    {
414        return [self checkedCast:[proxy ice_facet:facet] context:context];
415    }
416    @catch(ICEFacetNotExistException* ex)
417    {
418        return nil;
419    }
420}
421+(NSString*) ice_staticId
422{
423    return @"::Ice::Object";
424}
425
426+(Protocol*) iceProtocol
427{
428    return objc_getProtocol(class_getName([self class]));
429}
430
431-(id<ICEOutputStream>) iceCreateOutputStream
432{
433    NSException* nsex = nil;
434    try
435    {
436        return [[ICEOutputStream alloc] initWithCxxCommunicator:OBJECTPRX->ice_getCommunicator().get()];
437    }
438    catch(const std::exception& ex)
439    {
440        nsex = toObjCException(ex);
441    }
442    @throw nsex;
443    return nil; // Keep the compiler happy.
444}
445-(void) iceCheckAsyncTwowayOnly:(NSString*)operation
446{
447    //
448    // No mutex lock necessary, there is nothing mutable in this
449    // operation.
450    //
451
452    if(![self ice_isTwoway])
453    {
454        @throw [NSException exceptionWithName:NSInvalidArgumentException
455                            reason:[NSString stringWithFormat:@"`%@' can only be called with a twoway proxy", operation]
456                            userInfo:nil];
457    }
458}
459
460-(void) iceInvoke:(NSString*)operation
461            mode:(ICEOperationMode)mode
462          format:(ICEFormatType)format
463         marshal:(ICEMarshalCB)marshal
464       unmarshal:(ICEUnmarshalCB)unmarshal
465         context:(ICEContext*)context
466{
467    if(unmarshal && !OBJECTPRX->ice_isTwoway())
468    {
469        @throw [ICETwowayOnlyException twowayOnlyException:__FILE__ line:__LINE__ operation:operation];
470    }
471
472    ICEOutputStream<ICEOutputStream>* os = nil;
473    if(marshal)
474    {
475        os = [self iceCreateOutputStream];
476        try
477        {
478            [os os]->startEncapsulation(IceInternal::getCompatibleEncoding(OBJECTPRX->ice_getEncodingVersion()),
479                                        (Ice::FormatType)format);
480        }
481        catch(const std::exception& ex)
482        {
483            [os release];
484            @throw toObjCException(ex);
485        }
486
487        @try
488        {
489            marshal(os);
490        }
491        @catch(id ex)
492        {
493            [os release];
494            @throw ex;
495        }
496    }
497
498    NSException* nsex = nil;
499    try
500    {
501        std::vector<Ice::Byte> inParams;
502        if(os)
503        {
504            [os os]->endEncapsulation();
505            [os os]->finished(inParams);
506            [os release];
507            os = nil;
508        }
509
510        BOOL ok = YES; // Keep the compiler happy.
511        std::vector<Ice::Byte> outParams;
512        if(context != nil)
513        {
514            Ice::Context ctx;
515            fromNSDictionary(context, ctx);
516            ok = OBJECTPRX->ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inParams, outParams, ctx);
517        }
518        else
519        {
520            ok = OBJECTPRX->ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inParams, outParams);
521        }
522
523        std::pair<const Ice::Byte*, const Ice::Byte*> p(&outParams[0], &outParams[0] + outParams.size());
524        ICEInputStream<ICEInputStream>* is;
525        is = [[ICEInputStream alloc] initWithCxxCommunicator:OBJECTPRX->ice_getCommunicator().get() data:p];
526        @try
527        {
528            if(unmarshal)
529            {
530                unmarshal(is, ok);
531            }
532            else if(!outParams.empty())
533            {
534                if(ok)
535                {
536                    [is skipEmptyEncapsulation];
537                }
538                else
539                {
540                    @try
541                    {
542                        [is startEncapsulation];
543                        [is throwException];
544                    }
545                    @catch(ICEUserException* ex)
546                    {
547                        [is endEncapsulation];
548                        @throw [ICEUnknownUserException unknownUserException:__FILE__ line:__LINE__ unknown:[ex ice_id]];
549                    }
550                }
551            }
552        }
553        @catch(id e)
554        {
555            nsex = e;
556        }
557        [is release];
558    }
559    catch(const std::exception& ex)
560    {
561        if(os != nil)
562        {
563            [os release];
564            os = nil;
565        }
566        nsex = toObjCException(ex);
567    }
568    if(nsex != nil)
569    {
570        @throw nsex;
571    }
572
573    NSAssert(os == nil, @"output stream not cleared");
574}
575
576-(id<ICEAsyncResult>) iceI_begin_invoke:(NSString*)operation
577                                mode:(ICEOperationMode)mode
578                              format:(ICEFormatType)format
579                             marshal:(void(^)(id<ICEOutputStream>))marshal
580                         returnsData:(BOOL)returnsData
581                             context:(ICEContext*)context
582{
583    if(returnsData)
584    {
585        [self iceCheckAsyncTwowayOnly:operation];
586    }
587
588    ICEOutputStream<ICEOutputStream>* os = nil;
589    if(marshal)
590    {
591        os = [self iceCreateOutputStream];
592        try
593        {
594            [os os]->startEncapsulation(IceInternal::getCompatibleEncoding(OBJECTPRX->ice_getEncodingVersion()),
595                                        (Ice::FormatType)format);
596        }
597        catch(const std::exception& ex)
598        {
599            [os release];
600            @throw toObjCException(ex);
601        }
602
603        @try
604        {
605            marshal(os);
606        }
607        @catch(id ex)
608        {
609            [os release];
610            @throw ex;
611        }
612    }
613
614    NSException* nsex = nil;
615    try
616    {
617        std::vector<Ice::Byte> inParams;
618        if(os)
619        {
620            [os os]->endEncapsulation();
621            [os os]->finished(inParams);
622            [os release];
623            os = nil;
624        }
625
626        Ice::AsyncResultPtr r;
627        if(context != nil)
628        {
629            Ice::Context ctx;
630            fromNSDictionary(context, ctx);
631            r = OBJECTPRX->begin_ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inParams, ctx);
632        }
633        else
634        {
635            r = OBJECTPRX->begin_ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inParams);
636        }
637        return [ICEAsyncResult asyncResultWithAsyncResult:r operation:operation proxy:self];
638    }
639    catch(const std::exception& ex)
640    {
641        if(os != nil)
642        {
643            [os release];
644            os = nil;
645        }
646        nsex = toObjCException(ex);
647    }
648    if(nsex != nil)
649    {
650        @throw nsex;
651    }
652    return nil; // Keep the compiler happy.
653}
654
655-(id<ICEAsyncResult>) iceI_begin_invoke:(NSString*)operation
656                                mode:(ICEOperationMode)mode
657                              format:(ICEFormatType)format
658                             marshal:(void(^)(id<ICEOutputStream>))marshal
659                         returnsData:(BOOL)returnsData
660                           completed:(void(^)(id<ICEInputStream>, BOOL))completed
661                            response:(BOOL)response
662                           exception:(void(^)(ICEException*))exception
663                                sent:(void(^)(BOOL))sent
664                             context:(ICEContext*)context
665{
666    if(returnsData)
667    {
668        [self iceCheckAsyncTwowayOnly:operation];
669        if(!response)
670        {
671            @throw [NSException exceptionWithName:NSInvalidArgumentException
672                                reason:@"Response callback is nil"
673                                userInfo:nil];
674        }
675    }
676
677    if(!exception)
678    {
679        @throw [NSException exceptionWithName:NSInvalidArgumentException
680                            reason:@"Exception callback is nil"
681                            userInfo:nil];
682    }
683
684    ICEOutputStream<ICEOutputStream>* os = nil;
685    if(marshal)
686    {
687        os = [self iceCreateOutputStream];
688        try
689        {
690            [os os]->startEncapsulation(IceInternal::getCompatibleEncoding(OBJECTPRX->ice_getEncodingVersion()),
691                                        (Ice::FormatType)format);
692        }
693        catch(const std::exception& ex)
694        {
695            [os release];
696            @throw toObjCException(ex);
697        }
698
699        @try
700        {
701            marshal(os);
702        }
703        @catch(id ex)
704        {
705            [os release];
706            @throw ex;
707        }
708    }
709
710    NSException* nsex = nil;
711    try
712    {
713        std::vector<Ice::Byte> inParams;
714        if(os)
715        {
716            [os os]->endEncapsulation();
717            [os os]->finished(inParams);
718            [os release];
719            os = nil;
720        }
721
722        Ice::Callback_Object_ice_invokePtr cb = Ice::newCallback_Object_ice_invoke(
723            new BeginInvokeAsyncCallback(OBJECTPRX->ice_getCommunicator(), completed, exception, sent, returnsData),
724            &BeginInvokeAsyncCallback::response,
725            &BeginInvokeAsyncCallback::exception,
726            &BeginInvokeAsyncCallback::sent);
727
728        Ice::AsyncResultPtr r;
729        if(context != nil)
730        {
731            Ice::Context ctx;
732            fromNSDictionary(context, ctx);
733            r = OBJECTPRX->begin_ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inParams, ctx, cb);
734        }
735        else
736        {
737            r = OBJECTPRX->begin_ice_invoke(fromNSString(operation), (Ice::OperationMode)mode, inParams, cb);
738        }
739        return [ICEAsyncResult asyncResultWithAsyncResult:r operation:operation proxy:self];
740    }
741    catch(const std::exception& ex)
742    {
743        if(os != nil)
744        {
745            [os release];
746            os = nil;
747        }
748        nsex = toObjCException(ex);
749    }
750    if(nsex != nil)
751    {
752        @throw nsex;
753    }
754    return nil; // Keep the compiler happy.
755}
756-(id<ICEAsyncResult>) iceI_begin_invoke:(NSString*)op
757                                mode:(ICEOperationMode)mode
758                              format:(ICEFormatType)format
759                             marshal:(void(^)(id<ICEOutputStream>))marshal
760                            response:(void(^)())response
761                           exception:(void(^)(ICEException*))exception
762                                sent:(void(^)(BOOL))sent
763                             context:(ICEContext*)ctx
764{
765    void(^completed)(id<ICEInputStream>, BOOL) = ^(id<ICEInputStream>, BOOL) {
766        if(response)
767        {
768            response();
769        }
770    };
771    return [self iceI_begin_invoke:op
772                 mode:mode
773                 format:format
774                 marshal:marshal
775                 returnsData:NO
776                 completed:completed
777                 response:YES
778                 exception:exception
779                 sent:sent
780                 context:ctx];
781}
782
783-(id<ICEAsyncResult>) iceI_begin_invoke:(NSString*)op
784                                mode:(ICEOperationMode)mode
785                              format:(ICEFormatType)format
786                             marshal:(void(^)(id<ICEOutputStream>))marshal
787                           completed:(void(^)(id<ICEInputStream>, BOOL))completed
788                            response:(BOOL)response
789                           exception:(void(^)(ICEException*))exception
790                                sent:(void(^)(BOOL))sent
791                             context:(ICEContext*)ctx
792{
793    return [self iceI_begin_invoke:op
794                 mode:mode
795                 format:format
796                 marshal:marshal
797                 returnsData:YES
798                 completed:completed
799                 response:response
800                 exception:exception
801                 sent:sent context:ctx];
802}
803
804-(void)iceI_end_invoke:(NSString*)operation unmarshal:(ICEUnmarshalCB)unmarshal result:(id<ICEAsyncResult>)r
805{
806    ICEAsyncResult* result = (ICEAsyncResult*)r;
807    if(operation != [result operation])
808    {
809        @throw [NSException exceptionWithName:NSInvalidArgumentException
810                            reason:[NSString stringWithFormat:@"Incorrect operation for end_%@ method: %@",
811                                             operation, [result operation]]
812                            userInfo:nil];
813    }
814    if(result == nil)
815    {
816        @throw [NSException exceptionWithName:NSInvalidArgumentException
817                            reason:@"ICEAsyncResult is nil"
818                            userInfo:nil];
819    }
820
821    NSException* nsex = nil;
822    try
823    {
824        std::pair<const Ice::Byte*, const Ice::Byte*> outParams;
825        BOOL ok = OBJECTPRX->_iceI_end_ice_invoke(outParams, [result asyncResult]);
826
827        ICEInputStream* is;
828        is = [[ICEInputStream alloc] initWithCxxCommunicator:OBJECTPRX->ice_getCommunicator().get() data:outParams];
829        @try
830        {
831            if(unmarshal)
832            {
833                unmarshal(is, ok);
834            }
835            else if(outParams.first != outParams.second)
836            {
837                if(ok)
838                {
839                    [is skipEmptyEncapsulation];
840                }
841                else
842                {
843                    @try
844                    {
845                        [is startEncapsulation];
846                        [is throwException];
847                    }
848                    @catch(ICEUserException* ex)
849                    {
850                        [is endEncapsulation];
851                        @throw [ICEUnknownUserException unknownUserException:__FILE__ line:__LINE__ unknown:[ex ice_id]];
852                    }
853                }
854            }
855        }
856        @catch(id e)
857        {
858            nsex = e;
859        }
860        [is release];
861    }
862    catch(const std::exception& ex)
863    {
864        nsex = toObjCException(ex);
865    }
866
867    if(nsex != nil)
868    {
869        @throw nsex;
870    }
871}
872
873-(id) copyWithZone:(NSZone *)__unused zone
874{
875    return [self retain];
876}
877
878-(NSUInteger) hash
879{
880    return (NSUInteger)OBJECTPRX->_hash();
881}
882-(NSString*) description
883{
884    return [toNSString(OBJECTPRX->ice_toString()) autorelease];
885}
886-(BOOL) isEqual:(id)o_
887{
888    if(self == o_)
889    {
890        return YES;
891    }
892    if(!o_ || ![o_ isKindOfClass:[ICEObjectPrx class]])
893    {
894        return NO;
895    }
896    return *OBJECTPRX == *[o_ iceObjectPrx];
897}
898
899-(NSComparisonResult) compareIdentity:(id<ICEObjectPrx>)aProxy
900{
901    IceProxy::Ice::Object* lhs = OBJECTPRX;
902    IceProxy::Ice::Object* rhs = [(ICEObjectPrx*)aProxy iceObjectPrx];
903    if(Ice::proxyIdentityEqual(lhs, rhs))
904    {
905        return NSOrderedSame;
906    }
907    else if(Ice::proxyIdentityLess(lhs, rhs))
908    {
909        return NSOrderedAscending;
910    }
911    else
912    {
913        return NSOrderedDescending;
914    }
915}
916
917-(NSComparisonResult) compareIdentityAndFacet:(id<ICEObjectPrx>)aProxy
918{
919    IceProxy::Ice::Object* lhs = OBJECTPRX;
920    IceProxy::Ice::Object* rhs = [(ICEObjectPrx*)aProxy iceObjectPrx];
921    if(Ice::proxyIdentityAndFacetEqual(lhs, rhs))
922    {
923        return NSOrderedSame;
924    }
925    else if(Ice::proxyIdentityAndFacetLess(lhs, rhs))
926    {
927        return NSOrderedAscending;
928    }
929    else
930    {
931        return NSOrderedDescending;
932    }
933}
934
935-(id<ICECommunicator>) ice_getCommunicator
936{
937    return [[communicator_ retain] autorelease];
938}
939
940-(NSMutableString*) ice_toString
941{
942    return [toNSMutableString(OBJECTPRX->ice_toString()) autorelease];
943}
944
945-(BOOL) ice_isA:(NSString*)typeId
946{
947    __block BOOL ret;
948    cppCall(^ { ret = OBJECTPRX->ice_isA(fromNSString(typeId)); });
949    return ret;
950}
951-(BOOL) ice_isA:(NSString*)typeId context:(ICEContext*)context
952{
953    __block BOOL ret;
954    cppCall(^(const Ice::Context& ctx) { ret = OBJECTPRX->ice_isA(fromNSString(typeId), ctx); }, context);
955    return ret;
956}
957-(id<ICEAsyncResult>) begin_ice_isA:(NSString*)typeId
958{
959    return beginCppCall(^(Ice::AsyncResultPtr& result)
960                        {
961                            result = OBJECTPRX->begin_ice_isA(fromNSString(typeId));
962                        }, self);
963}
964-(id<ICEAsyncResult>) begin_ice_isA:(NSString*)typeId context:(ICEContext*)context
965{
966    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx)
967                        {
968                            result = OBJECTPRX->begin_ice_isA(fromNSString(typeId), ctx);
969                        }, context, self);
970}
971-(id<ICEAsyncResult>) begin_ice_isA:(NSString*)typeId
972                           response:(void(^)(BOOL))response
973                          exception:(void(^)(ICEException*))exception
974{
975    return [self begin_ice_isA:typeId response:response exception:exception sent:nil];
976}
977-(id<ICEAsyncResult>) begin_ice_isA:(NSString*)typeId
978                            context:(ICEContext*)context
979                           response:(void(^)(BOOL))response
980                          exception:(void(^)(ICEException*))exception
981
982{
983    return [self begin_ice_isA:typeId context:context response:response exception:exception sent:nil];
984}
985-(id<ICEAsyncResult>) begin_ice_isA:(NSString*)typeId
986                           response:(void(^)(BOOL))response
987                          exception:(void(^)(ICEException*))exception
988                               sent:(void(^)(BOOL))sent
989{
990    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::CallbackPtr& cb)
991                        {
992                            result = OBJECTPRX->begin_ice_isA(fromNSString(typeId), cb);
993                        },
994                        ^(const Ice::AsyncResultPtr& result) {
995                            BOOL ret = OBJECTPRX->end_ice_isA(result);
996                            if(response)
997                            {
998                                response(ret);
999                            }
1000                        },
1001                        exception, sent, self);
1002
1003}
1004-(id<ICEAsyncResult>) begin_ice_isA:(NSString*)typeId
1005                            context:(ICEContext*)context
1006                           response:(void(^)(BOOL))response
1007                          exception:(void(^)(ICEException*))exception
1008                               sent:(void(^)(BOOL))sent
1009{
1010    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx, const Ice::CallbackPtr& cb)
1011                        {
1012                            result = OBJECTPRX->begin_ice_isA(fromNSString(typeId), ctx, cb);
1013                        },
1014                        context,
1015                        ^(const Ice::AsyncResultPtr& result) {
1016                            BOOL ret = OBJECTPRX->end_ice_isA(result);
1017                            if(response)
1018                            {
1019                                response(ret);
1020                            }
1021                        },
1022                        exception, sent, self);
1023}
1024-(BOOL) end_ice_isA:(id<ICEAsyncResult>)result
1025{
1026    __block BOOL ret;
1027    endCppCall(^(const Ice::AsyncResultPtr& r) { ret = OBJECTPRX->end_ice_isA(r); }, result);
1028    return ret;
1029}
1030
1031-(void) ice_ping
1032{
1033    cppCall(^ { OBJECTPRX->ice_ping(); });
1034}
1035-(void) ice_ping:(ICEContext*)context
1036{
1037    cppCall(^(const Ice::Context& ctx) { OBJECTPRX->ice_ping(ctx); }, context);
1038}
1039-(id<ICEAsyncResult>) begin_ice_ping
1040{
1041    return beginCppCall(^(Ice::AsyncResultPtr& result) { result = OBJECTPRX->begin_ice_ping(); }, self);
1042}
1043-(id<ICEAsyncResult>) begin_ice_ping:(ICEContext*)context
1044{
1045    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx)
1046                        {
1047                            result = OBJECTPRX->begin_ice_ping(ctx);
1048                        }, context, self);
1049}
1050
1051-(id<ICEAsyncResult>) begin_ice_ping:(void(^)())response exception:(void(^)(ICEException*))exception
1052{
1053    return [self begin_ice_ping:response exception:exception sent:nil];
1054}
1055-(id<ICEAsyncResult>) begin_ice_ping:(ICEContext*)context
1056                            response:(void(^)())response
1057                           exception:(void(^)(ICEException*))exception
1058
1059{
1060    return [self begin_ice_ping:context response:response exception:exception sent:nil];
1061}
1062-(id<ICEAsyncResult>) begin_ice_ping:(void(^)())response
1063                           exception:(void(^)(ICEException*))exception
1064                                sent:(void(^)(BOOL))sent
1065{
1066    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::CallbackPtr& cb)
1067                        {
1068                            result = OBJECTPRX->begin_ice_ping(cb);
1069                        },
1070                        ^(const Ice::AsyncResultPtr& result) {
1071                            OBJECTPRX->end_ice_ping(result);
1072                            if(response)
1073                            {
1074                                response();
1075                            }
1076                        },
1077                        exception, sent, self);
1078}
1079
1080-(id<ICEAsyncResult>) begin_ice_ping:(ICEContext*)context
1081                            response:(void(^)())response
1082                           exception:(void(^)(ICEException*))exception
1083                                sent:(void(^)(BOOL))sent
1084{
1085    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx, const Ice::CallbackPtr& cb)
1086                        {
1087                            result = OBJECTPRX->begin_ice_ping(ctx, cb);
1088                        },
1089                        context,
1090                        ^(const Ice::AsyncResultPtr& result) {
1091                            OBJECTPRX->end_ice_ping(result);
1092                            if(response)
1093                            {
1094                                response();
1095                            }
1096                        },
1097                        exception, sent, self);
1098}
1099-(void) end_ice_ping:(id<ICEAsyncResult>)result
1100{
1101    endCppCall(^(const Ice::AsyncResultPtr& r) { OBJECTPRX->end_ice_ping(r); }, result);
1102}
1103
1104-(NSMutableArray*) ice_ids
1105{
1106    __block NSMutableArray* ret;
1107    cppCall(^ { ret = [toNSArray(OBJECTPRX->ice_ids()) autorelease]; });
1108    return ret;
1109}
1110-(NSMutableArray*) ice_ids:(ICEContext*)context
1111{
1112    __block NSMutableArray* ret;
1113    cppCall(^(const Ice::Context& ctx) { ret = [toNSArray(OBJECTPRX->ice_ids(ctx)) autorelease]; }, context);
1114    return ret;
1115}
1116-(id<ICEAsyncResult>) begin_ice_ids
1117{
1118    return beginCppCall(^(Ice::AsyncResultPtr& result) { result = OBJECTPRX->begin_ice_ids(); } , self);
1119}
1120
1121-(id<ICEAsyncResult>) begin_ice_ids:(ICEContext*)context
1122{
1123    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx)
1124                        {
1125                            result = OBJECTPRX->begin_ice_ids(ctx);
1126                        }, context, self);
1127}
1128-(id<ICEAsyncResult>) begin_ice_ids:(void(^)(NSArray*))response exception:(void(^)(ICEException*))exception
1129{
1130    return [self begin_ice_ids:response exception:exception sent:nil];
1131}
1132-(id<ICEAsyncResult>) begin_ice_ids:(ICEContext*)context
1133                           response:(void(^)(NSArray*))response
1134                          exception:(void(^)(ICEException*))exception
1135{
1136    return [self begin_ice_ids:context response:response exception:exception sent:nil];
1137}
1138-(id<ICEAsyncResult>) begin_ice_ids:(void(^)(NSArray*))response
1139                          exception:(void(^)(ICEException*))exception
1140                               sent:(void(^)(BOOL))sent
1141{
1142    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::CallbackPtr& cb)
1143                        {
1144                            result = OBJECTPRX->begin_ice_ids(cb);
1145                        },
1146                        ^(const Ice::AsyncResultPtr& result) {
1147                            NSMutableArray* ret = [toNSArray(OBJECTPRX->end_ice_ids(result)) autorelease];
1148                            if(response)
1149                            {
1150                                response(ret);
1151                            }
1152                        },
1153                        exception, sent, self);
1154}
1155-(id<ICEAsyncResult>) begin_ice_ids:(ICEContext*)context
1156                           response:(void(^)(NSArray*))response
1157                          exception:(void(^)(ICEException*))exception
1158                               sent:(void(^)(BOOL))sent
1159{
1160    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx, const Ice::CallbackPtr& cb)
1161                        {
1162                            result = OBJECTPRX->begin_ice_ids(ctx, cb);
1163                        },
1164                        context,
1165                        ^(const Ice::AsyncResultPtr& result) {
1166                            NSMutableArray* ret = [toNSArray(OBJECTPRX->end_ice_ids(result)) autorelease];
1167                            if(response)
1168                            {
1169                                response(ret);
1170                            }
1171                        },
1172                        exception, sent, self);
1173}
1174-(NSMutableArray*) end_ice_ids:(id<ICEAsyncResult>)result
1175{
1176    __block NSMutableArray* ret;
1177    endCppCall(^(const Ice::AsyncResultPtr& r) { ret = [toNSArray(OBJECTPRX->end_ice_ids(r)) autorelease]; }, result);
1178    return ret;
1179}
1180
1181-(NSMutableString*) ice_id
1182{
1183    __block NSMutableString* ret;
1184    cppCall(^ { ret = [toNSMutableString(OBJECTPRX->ice_id()) autorelease]; });
1185    return ret;
1186}
1187-(NSMutableString*) ice_id:(ICEContext*)context
1188{
1189    __block NSMutableString* ret;
1190    cppCall(^(const Ice::Context& ctx) { ret = [toNSMutableString(OBJECTPRX->ice_id(ctx)) autorelease]; }, context);
1191    return ret;
1192}
1193-(id<ICEAsyncResult>) begin_ice_id
1194{
1195    return beginCppCall(^(Ice::AsyncResultPtr& result) { result = OBJECTPRX->begin_ice_id(); } , self);
1196}
1197-(id<ICEAsyncResult>) begin_ice_id:(ICEContext*)context
1198{
1199    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx)
1200                        {
1201                            result = OBJECTPRX->begin_ice_id(ctx);
1202                        }, context, self);
1203}
1204-(id<ICEAsyncResult>) begin_ice_id:(void(^)(NSString*))response exception:(void(^)(ICEException*))exception
1205{
1206    return [self begin_ice_id:response exception:exception sent:nil];
1207}
1208-(id<ICEAsyncResult>) begin_ice_id:(ICEContext*)context
1209                          response:(void(^)(NSString*))response
1210                         exception:(void(^)(ICEException*))exception
1211
1212{
1213    return [self begin_ice_id:context response:response exception:exception sent:nil];
1214}
1215-(id<ICEAsyncResult>) begin_ice_id:(void(^)(NSString*))response
1216                         exception:(void(^)(ICEException*))exception
1217                              sent:(void(^)(BOOL))sent
1218{
1219    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::CallbackPtr& cb)
1220                        {
1221                            result = OBJECTPRX->begin_ice_id(cb);
1222                        },
1223                        ^(const Ice::AsyncResultPtr& result) {
1224                            NSString* ret = [toNSString(OBJECTPRX->end_ice_id(result)) autorelease];
1225                            if(response)
1226                            {
1227                                response(ret);
1228                            }
1229                        },
1230                        exception, sent, self);
1231}
1232-(id<ICEAsyncResult>) begin_ice_id:(ICEContext*)context
1233                          response:(void(^)(NSString*))response
1234                         exception:(void(^)(ICEException*))exception
1235                              sent:(void(^)(BOOL))sent
1236{
1237    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx, const Ice::CallbackPtr& cb)
1238                        {
1239                            result = OBJECTPRX->begin_ice_id(ctx, cb);
1240                        },
1241                        context,
1242                        ^(const Ice::AsyncResultPtr& result) {
1243                            NSString* ret = [toNSString(OBJECTPRX->end_ice_id(result)) autorelease];
1244                            if(response)
1245                            {
1246                                response(ret);
1247                            }
1248                        },
1249                        exception, sent, self);
1250}
1251-(NSMutableString*) end_ice_id:(id<ICEAsyncResult>)result
1252{
1253    __block NSMutableString* ret;
1254    endCppCall(^(const Ice::AsyncResultPtr& r) { ret = [toNSMutableString(OBJECTPRX->end_ice_id(r)) autorelease]; },
1255               result);
1256    return ret;
1257}
1258
1259-(BOOL) ice_invoke:(NSString*)operation
1260              mode:(ICEOperationMode)mode
1261          inEncaps:(NSData*)inEncaps
1262         outEncaps:(NSMutableData**)outEncaps
1263{
1264    return [self end_ice_invoke:outEncaps result:[self begin_ice_invoke:operation mode:mode inEncaps:inEncaps]];
1265}
1266
1267-(BOOL) ice_invoke:(NSString*)operation
1268              mode:(ICEOperationMode)mode
1269          inEncaps:(NSData*)inEncaps
1270         outEncaps:(NSMutableData**)outEncaps
1271           context:(ICEContext*)context
1272{
1273    return [self end_ice_invoke:outEncaps
1274        result:[self begin_ice_invoke:operation mode:mode inEncaps:inEncaps context:context]];
1275}
1276
1277-(id<ICEAsyncResult>) begin_ice_invoke:(NSString*)operation mode:(ICEOperationMode)mode inEncaps:(NSData*)inEncaps
1278{
1279    return beginCppCall(^(Ice::AsyncResultPtr& result)
1280                        {
1281                            std::pair<const Ice::Byte*, const Ice::Byte*>
1282                                inP((ICEByte*)[inEncaps bytes], (ICEByte*)[inEncaps bytes] + [inEncaps length]);
1283                            result = OBJECTPRX->begin_ice_invoke(fromNSString(operation),
1284                                                                 (Ice::OperationMode)mode,
1285                                                                 inP);
1286                        }, self);
1287}
1288-(id<ICEAsyncResult>) begin_ice_invoke:(NSString*)operation
1289                                  mode:(ICEOperationMode)mode
1290                              inEncaps:(NSData*)inEncaps
1291                               context:(ICEContext*)context
1292{
1293    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx)
1294                        {
1295                            std::pair<const Ice::Byte*, const Ice::Byte*>
1296                                inP((ICEByte*)[inEncaps bytes], (ICEByte*)[inEncaps bytes] + [inEncaps length]);
1297                            result = OBJECTPRX->begin_ice_invoke(fromNSString(operation),
1298                                                                 (Ice::OperationMode)mode,
1299                                                                 inP,
1300                                                                 ctx);
1301                        }, context, self);
1302}
1303-(id<ICEAsyncResult>) begin_ice_invoke:(NSString*)operation
1304                                  mode:(ICEOperationMode)mode
1305                              inEncaps:(NSData*)inEncaps
1306                              response:(void(^)(BOOL, NSMutableData*))response
1307                             exception:(void(^)(ICEException*))exception
1308{
1309    return [self begin_ice_invoke:operation mode:mode inEncaps:inEncaps response:response exception:exception sent:nil];
1310}
1311-(id<ICEAsyncResult>) begin_ice_invoke:(NSString*)operation
1312                                  mode:(ICEOperationMode)mode
1313                              inEncaps:(NSData*)inEncaps
1314                               context:(ICEContext*)context
1315                              response:(void(^)(BOOL, NSMutableData*))response
1316                             exception:(void(^)(ICEException*))exception
1317{
1318    return [self begin_ice_invoke:operation mode:mode inEncaps:inEncaps context:context response:response
1319                 exception:exception sent:nil];
1320}
1321-(id<ICEAsyncResult>) begin_ice_invoke:(NSString*)operation
1322                                  mode:(ICEOperationMode)mode
1323                              inEncaps:(NSData*)inEncaps
1324                              response:(void(^)(BOOL, NSMutableData*))response
1325                             exception:(void(^)(ICEException*))exception
1326                                  sent:(void(^)(BOOL))sent
1327{
1328    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::CallbackPtr& cb)
1329                        {
1330                            std::pair<const Ice::Byte*, const Ice::Byte*>
1331                                inP((ICEByte*)[inEncaps bytes], (ICEByte*)[inEncaps bytes] + [inEncaps length]);
1332                            result = OBJECTPRX->begin_ice_invoke(fromNSString(operation),
1333                                                                 (Ice::OperationMode)mode,
1334                                                                 inP,
1335                                                                 cb);
1336                        },
1337                        ^(const Ice::AsyncResultPtr& result) {
1338                            std::pair<const ::Ice::Byte*, const ::Ice::Byte*> outP;
1339                            BOOL ret = OBJECTPRX->_iceI_end_ice_invoke(outP, result);
1340                            if(response)
1341                            {
1342                                NSMutableData* outEncaps =
1343                                    [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
1344                                response(ret, outEncaps);
1345                            }
1346                        },
1347                        exception, sent, self);
1348}
1349-(id<ICEAsyncResult>) begin_ice_invoke:(NSString*)operation
1350                                  mode:(ICEOperationMode)mode
1351                              inEncaps:(NSData*)inEncaps
1352                               context:(ICEContext*)context
1353                              response:(void(^)(BOOL, NSMutableData*))response
1354                             exception:(void(^)(ICEException*))exception
1355                                  sent:(void(^)(BOOL))sent
1356{
1357    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::Context& ctx, const Ice::CallbackPtr& cb)
1358                        {
1359                            std::pair<const Ice::Byte*, const Ice::Byte*>
1360                                inP((ICEByte*)[inEncaps bytes], (ICEByte*)[inEncaps bytes] + [inEncaps length]);
1361                            result = OBJECTPRX->begin_ice_invoke(fromNSString(operation),
1362                                                                 (Ice::OperationMode)mode,
1363                                                                 inP,
1364                                                                 ctx,
1365                                                                 cb);
1366                        },
1367                        context,
1368                        ^(const Ice::AsyncResultPtr& result) {
1369                            std::pair<const ::Ice::Byte*, const ::Ice::Byte*> outP;
1370                            BOOL ret = OBJECTPRX->_iceI_end_ice_invoke(outP, result);
1371                            if(response)
1372                            {
1373                                NSMutableData* outEncaps =
1374                                    [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
1375                                response(ret, outEncaps);
1376                            }
1377                        },
1378                        exception, sent, self);
1379}
1380-(BOOL) end_ice_invoke:(NSMutableData**)outEncaps result:(id<ICEAsyncResult>)result
1381
1382{
1383    __block BOOL ret;
1384    endCppCall(^(const Ice::AsyncResultPtr& r)
1385               {
1386                   std::pair<const ::Ice::Byte*, const ::Ice::Byte*> outP;
1387                   ret = OBJECTPRX->_iceI_end_ice_invoke(outP, r);
1388                   *outEncaps = [NSMutableData dataWithBytes:outP.first length:(outP.second - outP.first)];
1389               }, result);
1390    return ret;
1391}
1392
1393-(ICEIdentity*) ice_getIdentity
1394{
1395    return [ICEIdentity identityWithIdentity:OBJECTPRX->ice_getIdentity()];
1396}
1397-(id) ice_identity:(ICEIdentity*)identity
1398{
1399    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_identity([identity identity])];
1400}
1401-(ICEMutableContext*) ice_getContext
1402{
1403    return [toNSDictionary(OBJECTPRX->ice_getContext()) autorelease];
1404}
1405-(id) ice_context:(ICEContext*)context
1406{
1407    Ice::Context ctx;
1408    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_context(fromNSDictionary(context, ctx))];
1409}
1410-(NSMutableString*) ice_getFacet
1411{
1412    return [toNSMutableString(OBJECTPRX->ice_getFacet()) autorelease];
1413}
1414-(id) ice_facet:(NSString*)facet
1415{
1416    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_facet(fromNSString(facet))];
1417}
1418-(NSMutableString*) ice_getAdapterId
1419{
1420    return [toNSMutableString(OBJECTPRX->ice_getAdapterId()) autorelease];
1421}
1422
1423-(ICEMutableEndpointSeq*) ice_getEndpoints
1424{
1425    return [toNSArray(OBJECTPRX->ice_getEndpoints()) autorelease];
1426}
1427
1428-(id) ice_endpoints:(ICEEndpointSeq*)endpoints
1429{
1430    Ice::EndpointSeq cxxEndpoints;
1431    fromNSArray(endpoints, cxxEndpoints);
1432    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_endpoints(cxxEndpoints)];
1433}
1434
1435-(id) ice_adapterId:(NSString*)adapterId
1436{
1437    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_adapterId(fromNSString(adapterId))];
1438}
1439
1440-(ICEInt) ice_getLocatorCacheTimeout
1441{
1442    return OBJECTPRX->ice_getLocatorCacheTimeout();
1443}
1444-(id) ice_locatorCacheTimeout:(ICEInt)timeout
1445{
1446    NSException* nsex;
1447    try
1448    {
1449        return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_locatorCacheTimeout(timeout)];
1450    }
1451    catch(const std::exception& ex)
1452    {
1453        nsex = toObjCException(ex);
1454    }
1455    @throw nsex;
1456}
1457-(BOOL) ice_isConnectionCached
1458{
1459    return OBJECTPRX->ice_isConnectionCached();
1460}
1461-(id) ice_connectionCached:(BOOL)cached
1462{
1463    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_connectionCached(cached)];
1464}
1465-(ICEEndpointSelectionType) ice_getEndpointSelection
1466{
1467    return (ICEEndpointSelectionType)OBJECTPRX->ice_getEndpointSelection();
1468}
1469-(id) ice_endpointSelection:(ICEEndpointSelectionType)type
1470{
1471    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_endpointSelection((Ice::EndpointSelectionType)type)];
1472}
1473-(BOOL) ice_isSecure
1474{
1475    return OBJECTPRX->ice_isSecure();
1476}
1477-(id) ice_secure:(BOOL)secure
1478{
1479    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_secure(secure)];
1480}
1481
1482-(ICEEncodingVersion*) ice_getEncodingVersion
1483{
1484    return [ICEEncodingVersion encodingVersionWithEncodingVersion:OBJECTPRX->ice_getEncodingVersion()];
1485}
1486
1487-(id) ice_encodingVersion:(ICEEncodingVersion*)encoding
1488{
1489    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_encodingVersion([encoding encodingVersion])];
1490}
1491
1492-(BOOL) ice_isPreferSecure
1493{
1494    return OBJECTPRX->ice_isPreferSecure();
1495}
1496-(id) ice_preferSecure:(BOOL)preferSecure
1497{
1498    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_preferSecure(preferSecure)];
1499}
1500-(id<ICERouterPrx>) ice_getRouter
1501{
1502    return (id<ICERouterPrx>)[ICERouterPrx iceObjectPrxWithObjectPrx:OBJECTPRX->ice_getRouter()];
1503}
1504-(id) ice_router:(id<ICERouterPrx>)router
1505{
1506    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_router(
1507            Ice::RouterPrx::uncheckedCast(Ice::ObjectPrx([(ICEObjectPrx*)router iceObjectPrx])))];
1508}
1509-(id<ICELocatorPrx>) ice_getLocator
1510{
1511    return (id<ICELocatorPrx>)[ICELocatorPrx iceObjectPrxWithObjectPrx:OBJECTPRX->ice_getLocator()];
1512}
1513-(id) ice_locator:(id<ICELocatorPrx>)locator
1514{
1515    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_locator(
1516            Ice::LocatorPrx::uncheckedCast(Ice::ObjectPrx([(ICEObjectPrx*)locator iceObjectPrx])))];
1517}
1518-(BOOL) ice_isCollocationOptimized
1519{
1520    return OBJECTPRX->ice_isCollocationOptimized();
1521}
1522-(id) ice_collocationOptimized:(BOOL)collocOptimized
1523{
1524    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_collocationOptimized(collocOptimized)];
1525}
1526-(ICEInt) ice_getInvocationTimeout
1527{
1528    return OBJECTPRX->ice_getInvocationTimeout();
1529}
1530-(id) ice_invocationTimeout:(ICEInt)timeout
1531{
1532    NSException* nsex;
1533    try
1534    {
1535        return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_invocationTimeout(timeout)];
1536    }
1537    catch(const std::exception& ex)
1538    {
1539        nsex = toObjCException(ex);
1540    }
1541    @throw nsex;
1542}
1543-(id) ice_twoway
1544{
1545    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_twoway()];
1546}
1547-(BOOL) ice_isTwoway
1548{
1549    return OBJECTPRX->ice_isTwoway();
1550}
1551-(id) ice_oneway
1552{
1553    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_oneway()];
1554}
1555-(BOOL) ice_isOneway
1556{
1557    return OBJECTPRX->ice_isOneway();
1558}
1559-(id) ice_batchOneway
1560{
1561    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_batchOneway()];
1562}
1563-(BOOL) ice_isBatchOneway
1564{
1565    return OBJECTPRX->ice_isBatchOneway();
1566}
1567-(id) ice_datagram
1568{
1569    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_datagram()];
1570}
1571-(BOOL) ice_isDatagram
1572{
1573    return OBJECTPRX->ice_isDatagram();
1574}
1575-(id) ice_batchDatagram
1576{
1577    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_batchDatagram()];
1578}
1579-(BOOL) ice_isBatchDatagram
1580{
1581    return OBJECTPRX->ice_isBatchDatagram();
1582}
1583-(id) ice_compress:(BOOL)compress
1584{
1585    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_compress(compress)];
1586}
1587-(id) ice_getCompress
1588{
1589    IceUtil::Optional<bool> compress = OBJECTPRX->ice_getCompress();
1590    return compress ? @(*compress) : nil;
1591}
1592-(id) ice_timeout:(int)timeout
1593{
1594    NSException* nsex;
1595    try
1596    {
1597        return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_timeout(timeout)];
1598    }
1599    catch(const std::exception& ex)
1600    {
1601        nsex = toObjCException(ex);
1602    }
1603    @throw nsex;
1604}
1605-(id) ice_getTimeout
1606{
1607    IceUtil::Optional<int> timeout = OBJECTPRX->ice_getTimeout();
1608    return timeout ? @(*timeout) : nil;
1609}
1610-(id) ice_fixed:(id<ICEConnection>)connection
1611{
1612    Ice::ConnectionPtr con =
1613        dynamic_cast<Ice::Connection*>(static_cast<IceUtil::Shared*>([(ICELocalObject*)connection cxxObject]));
1614    if(!con)
1615    {
1616        @throw [NSException exceptionWithName:NSInvalidArgumentException
1617                                       reason:@"invalid connection passed to ice_fixed"
1618                                     userInfo:nil];
1619    }
1620    NSException* nsex = nil;
1621    try
1622    {
1623        return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_fixed(con)];
1624    }
1625    catch(const std::exception& ex)
1626    {
1627        nsex = toObjCException(ex);
1628    }
1629    @throw nsex;
1630    return nil; // Keep the compiler happy.
1631}
1632-(id) ice_connectionId:(NSString*)connectionId
1633{
1634    return [[self class] iceObjectPrxWithObjectPrx:OBJECTPRX->ice_connectionId(fromNSString(connectionId))];
1635}
1636-(id<ICEConnection>) ice_getConnection
1637{
1638    NSException* nsex = nil;
1639    try
1640    {
1641        return [ICEConnection localObjectWithCxxObject:OBJECTPRX->ice_getConnection().get()];
1642    }
1643    catch(const std::exception& ex)
1644    {
1645        nsex = toObjCException(ex);
1646    }
1647    @throw nsex;
1648    return nil; // Keep the compiler happy.
1649}
1650
1651-(id<ICEAsyncResult>) begin_ice_getConnection
1652{
1653    return beginCppCall(^(Ice::AsyncResultPtr& result)
1654                        {
1655                            result = OBJECTPRX->begin_ice_getConnection();
1656                        }, self);
1657}
1658-(id<ICEAsyncResult>) begin_ice_getConnection:(void(^)(id<ICEConnection>))response
1659                                    exception:(void(^)(ICEException*))exception
1660{
1661    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::CallbackPtr& cb)
1662                        {
1663                            result = OBJECTPRX->begin_ice_getConnection(cb);
1664                        },
1665                        ^(const Ice::AsyncResultPtr& result) {
1666                            id<ICEConnection> ret =
1667                                [ICEConnection localObjectWithCxxObject:OBJECTPRX->end_ice_getConnection(result).get()];
1668                            if(response)
1669                            {
1670                                response(ret);
1671                            }
1672                        },
1673                        exception, nil, self);
1674}
1675-(id<ICEConnection>) end_ice_getConnection:(id<ICEAsyncResult>)result
1676{
1677    __block id<ICEConnection> ret;
1678    endCppCall(^(const Ice::AsyncResultPtr& r)
1679               {
1680                   ret = [ICEConnection localObjectWithCxxObject:OBJECTPRX->end_ice_getConnection(r).get()];
1681               }, result);
1682    return ret;
1683}
1684
1685-(id<ICEConnection>) ice_getCachedConnection
1686{
1687    NSException* nsex = nil;
1688    try
1689    {
1690        return [ICEConnection localObjectWithCxxObject:OBJECTPRX->ice_getCachedConnection().get()];
1691    }
1692    catch(const std::exception& ex)
1693    {
1694        nsex = toObjCException(ex);
1695    }
1696    @throw nsex;
1697    return nil; // Keep the compiler happy.
1698}
1699-(void) ice_flushBatchRequests
1700{
1701    NSException* nsex = nil;
1702    try
1703    {
1704        OBJECTPRX->ice_flushBatchRequests();
1705    }
1706    catch(const std::exception& ex)
1707    {
1708        nsex = toObjCException(ex);
1709    }
1710    if(nsex != nil)
1711    {
1712        @throw nsex;
1713    }
1714}
1715
1716-(id<ICEAsyncResult>) begin_ice_flushBatchRequests
1717{
1718    return beginCppCall(^(Ice::AsyncResultPtr& result)
1719                        {
1720                            result = OBJECTPRX->begin_ice_flushBatchRequests();
1721                        }, self);
1722}
1723-(id<ICEAsyncResult>) begin_ice_flushBatchRequests:(void(^)(ICEException*))exception
1724{
1725    return [self begin_ice_flushBatchRequests:exception sent:nil];
1726}
1727-(id<ICEAsyncResult>) begin_ice_flushBatchRequests:(void(^)(ICEException*))exception sent:(void(^)(BOOL))sent
1728{
1729    return beginCppCall(^(Ice::AsyncResultPtr& result, const Ice::CallbackPtr& cb)
1730                        {
1731                            result = OBJECTPRX->begin_ice_flushBatchRequests(cb);
1732                        },
1733                        ^(const Ice::AsyncResultPtr& result) {
1734                            OBJECTPRX->end_ice_flushBatchRequests(result);
1735                        },
1736                        exception, sent, self);
1737}
1738-(void) end_ice_flushBatchRequests:(id<ICEAsyncResult>)result
1739{
1740    endCppCall(^(const Ice::AsyncResultPtr& r)
1741               {
1742                   OBJECTPRX->end_ice_flushBatchRequests(r);
1743               }, result);
1744}
1745@end
1746