1//
2// Copyright (c) ZeroC, Inc. All rights reserved.
3//
4
5#import <objc/Ice.h>
6
7#import <ami/TestI.h>
8#import <TestCommon.h>
9
10@implementation TestAMITestIntfI
11-(id) init
12{
13    self = [super init];
14    if(!self)
15    {
16        return nil;
17    }
18    _cond = [[NSCondition alloc] init];
19    return self;
20}
21
22#if defined(__clang__) && !__has_feature(objc_arc)
23-(void) dealloc
24{
25    [_cond release];
26    [super dealloc];
27}
28#endif
29
30-(void) op:(ICECurrent*)__unused current
31{
32}
33-(void) opWithPayload:(ICEMutableByteSeq*)__unused data current:(ICECurrent*)__unused current
34{
35}
36-(int) opWithResult:(ICECurrent*)__unused current
37{
38    return 15;
39}
40-(void) opWithUE:(ICECurrent*)__unused current
41{
42    @throw [TestAMITestIntfException testIntfException];
43}
44
45-(void) shutdown:(ICECurrent*)current
46{
47    [[current.adapter getCommunicator] shutdown];
48}
49-(void) opBatch:(ICECurrent *)__unused current
50{
51    [_cond lock];
52    ++_batchCount;
53    [_cond signal];
54    [_cond unlock];
55}
56-(ICEInt) opBatchCount:(ICECurrent *)__unused current
57{
58    [_cond lock];
59    @try
60    {
61        return _batchCount;
62    }
63    @finally
64    {
65        [_cond unlock];
66    }
67    return 0;
68}
69-(BOOL) waitForBatch:(ICEInt)count current:(ICECurrent *)__unused current
70{
71    [_cond lock];
72    @try
73    {
74        while(_batchCount < count)
75        {
76            [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:500]];
77        }
78        BOOL result = count == _batchCount;
79        _batchCount = 0;
80        return result;
81    }
82    @finally
83    {
84        [_cond unlock];
85    }
86    return NO;
87}
88-(void) close:(TestAMICloseMode)mode current:(ICECurrent *)current
89{
90    [current.con close:(ICEConnectionClose)mode];
91}
92-(void) sleep:(ICEInt)delay current:(ICECurrent *)__unused current
93{
94    [_cond lock];
95    @try
96    {
97        [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:delay / 1000.0]];
98    }
99    @finally
100    {
101        [_cond unlock];
102    }
103}
104-(void) startDispatch:(ICECurrent*)__unused current
105{
106    [_cond lock];
107    _dispatching = YES;
108    @try
109    {
110        while(_dispatching)
111        {
112            [_cond waitUntilDate:[NSDate dateWithTimeIntervalSinceNow:30.0]];
113        }
114    }
115    @finally
116    {
117        [_cond unlock];
118    }
119}
120-(void) finishDispatch:(ICECurrent*)__unused current
121{
122    [_cond lock];
123    _dispatching = NO;
124    [_cond signal];
125    [_cond unlock];
126}
127-(BOOL) supportsAMD:(ICECurrent *)__unused current
128{
129    return NO;
130}
131-(BOOL) supportsFunctionalTests:(ICECurrent *)__unused current
132{
133    return NO;
134}
135
136-(void) pingBiDir:(id<TestAMIPingReplyPrx>)reply current:(ICECurrent *)current
137{
138    reply = [reply ice_fixed:current.con];
139    id<ICEAsyncResult> result = [reply begin_reply];
140    [reply end_reply:result];
141}
142@end
143
144@implementation TestAMITestOuterInnerTestIntfI
145-(int) op:(ICEInt)i j:(ICEInt*)j current:(ICECurrent*)__unused current
146{
147    *j = i;
148    return i;
149}
150@end
151
152@implementation TestAMITestIntfControllerI
153-(id) initWithAdapter:(id<ICEObjectAdapter>)adapter
154{
155    self = [super init];
156    if(!self)
157    {
158        return nil;
159    }
160    _adapter = adapter;
161    return self;
162}
163-(void) holdAdapter:(ICECurrent*)__unused current
164{
165    [_adapter hold];
166}
167-(void) resumeAdapter:(ICECurrent*)__unused current
168{
169    [_adapter activate];
170}
171@end
172