1// 2// Copyright (c) ZeroC, Inc. All rights reserved. 3// 4 5#import <timeout/TestI.h> 6#import <objc/Ice.h> 7 8#import <Foundation/NSThread.h> 9 10@interface ActivateAdapterThread : NSThread 11{ 12 id<ICEObjectAdapter> adapter_; 13 int timeout_; 14} 15-(id) init:(id<ICEObjectAdapter>)adapter timeout:(int)timeout; 16+(id) activateAdapterThread:(id<ICEObjectAdapter>)adapter timeout:(int)timeout; 17-(void) main; 18#if defined(__clang__) && !__has_feature(objc_arc) 19-(void) dealloc; 20#endif 21@end 22 23@implementation ActivateAdapterThread 24-(id) init:(id<ICEObjectAdapter>)adapter timeout:(int)timeout 25{ 26 self = [super init]; 27 if(!self) 28 { 29 return nil; 30 } 31 adapter_ = ICE_RETAIN(adapter); 32 timeout_ = timeout; 33 return self; 34} 35 36+(id) activateAdapterThread:(id<ICEObjectAdapter>)adapter timeout:(int)timeout 37{ 38 return ICE_AUTORELEASE([[self alloc] init:adapter timeout:timeout]); 39} 40-(void) main 41{ 42 [NSThread sleepForTimeInterval:timeout_ / 1000.0]; 43 [adapter_ activate]; 44} 45 46#if defined(__clang__) && !__has_feature(objc_arc) 47-(void) dealloc 48{ 49 [adapter_ release]; 50 [super dealloc]; 51} 52#endif 53 54@end 55 56@implementation TimeoutI 57-(void) op:(ICECurrent*)__unused current 58{ 59} 60 61-(void) sendData:(TestTimeoutMutableByteSeq*)__unused seq current:(ICECurrent*)__unused current 62{ 63} 64 65-(void) sleep:(ICEInt)to current:(ICECurrent*)__unused current 66{ 67 [NSThread sleepForTimeInterval:to / 1000.0]; 68} 69 70-(void) holdAdapter:(ICEInt)to current:(ICECurrent*)current 71{ 72 [current.adapter hold]; 73 ActivateAdapterThread* thread = [ActivateAdapterThread activateAdapterThread:current.adapter timeout:to]; 74 [thread start]; 75} 76 77-(void) shutdown:(ICECurrent*)current 78{ 79 [[current.adapter getCommunicator] shutdown]; 80} 81@end 82 83@implementation TimeoutControllerI 84-(id) init:(id<ICEObjectAdapter>)adapter 85{ 86 self = [super init]; 87 if(!self) 88 { 89 return nil; 90 } 91 adapter_ = ICE_RETAIN(adapter); 92 return self; 93} 94+(id) controller:(id<ICEObjectAdapter>)adapter 95{ 96 return ICE_AUTORELEASE([[self alloc] init:adapter]); 97} 98 99#if defined(__clang__) && !__has_feature(objc_arc) 100-(void) dealloc 101{ 102 [adapter_ release]; 103 [super dealloc]; 104} 105#endif 106 107-(void) holdAdapter:(ICEInt)to current:(ICECurrent*)__unused current 108{ 109 [adapter_ hold]; 110 if(to >= 0) 111 { 112 ActivateAdapterThread* thread = [ActivateAdapterThread activateAdapterThread:adapter_ timeout:to]; 113 [thread start]; 114 } 115} 116 117-(void) resumeAdapter:(ICECurrent*)__unused current 118{ 119 [adapter_ activate]; 120} 121 122-(void) shutdown:(ICECurrent*)current 123{ 124 [[current.adapter getCommunicator] shutdown]; 125} 126@end 127