summaryrefslogtreecommitdiff
path: root/matlab/lib/+Ice/ObjectPrx.m
blob: 41d6c7e68bb17031fa916888e55b6604e9367fa9 (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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
classdef ObjectPrx < IceInternal.WrapperObject
    % ObjectPrx   Summary of ObjectPrx
    %
    % Base interface of all object proxies.
    %
    % ObjectPrx Methods:
    %   ice_toString - Returns a stringified version of this proxy.
    %   ice_getCommunicator - Returns the communicator that created this
    %     proxy.
    %   ice_ping - Tests whether the target object of this proxy can
    %     be reached.
    %   ice_pingAsync - Tests whether the target object of this proxy can
    %     be reached.
    %   ice_isA - Tests whether this object supports a specific
    %     Slice interface.
    %   ice_isAAsync - Tests whether this object supports a specific
    %     Slice interface.
    %   ice_id - Returns the Slice type ID of the most-derived interface
    %     supported by the target object of this proxy.
    %   ice_idAsync - Returns the Slice type ID of the most-derived
    %     interface supported by the target object of this proxy.
    %   ice_ids - Returns the Slice type IDs of the interfaces supported
    %     by the target object of this proxy.
    %   ice_idsAsync - Returns the Slice type IDs of the interfaces
    %     supported by the target object of this proxy.
    %   ice_getIdentity - Returns the identity embedded in this proxy.
    %   ice_identity - Returns a proxy that is identical to this proxy,
    %     except for the identity.
    %   ice_getContext - Returns the per-proxy context for this proxy.
    %   ice_context - Returns a proxy that is identical to this proxy,
    %     except for the per-proxy context.
    %   ice_getFacet - Returns the facet for this proxy.
    %   ice_facet - Returns a proxy that is identical to this proxy,
    %     except for the facet.
    %   ice_getAdapter - Returns the adapter ID for this proxy.
    %   ice_adapterId - Returns a proxy that is identical to this proxy,
    %     except for the adapter ID.
    %   ice_getEndpoints - Returns the endpoints used by this proxy.
    %   ice_endpoints - Returns a proxy that is identical to this proxy,
    %     except for the endpoints.
    %   ice_getLocatorCacheTimeout - Returns the locator cache timeout
    %     of this proxy.
    %   ice_locatorCacheTimeout - Returns a proxy that is identical to
    %     this proxy, except for the locator cache timeout.
    %   ice_getInvocationTimeout - Returns the invocation timeout of
    %     this proxy.
    %   ice_invocationTimeout - Returns a proxy that is identical to
    %     this proxy, except for the invocation timeout.
    %   ice_getConnectionId - Returns the connection id of this proxy.
    %   ice_connectionId - Returns a proxy that is identical to this
    %     proxy, except for its connection ID.
    %   ice_isConnectionCached - Returns whether this proxy caches
    %     connections.
    %   ice_connectionCached - Returns a proxy that is identical to this
    %     proxy, except for connection caching.
    %   ice_getEndpointSelection - Returns how this proxy selects
    %     endpoints (randomly or ordered).
    %   ice_endpointSelection - Returns a proxy that is identical to
    %     this proxy, except for the endpoint selection policy.
    %   ice_getEncodingVersion - Returns the encoding version used to
    %     marshal requests parameters.
    %   ice_encodingVersion - Returns a proxy that is identical to this
    %     proxy, except for the encoding used to marshal parameters.
    %   ice_getRouter - Returns the router for this proxy.
    %   ice_router - Returns a proxy that is identical to this proxy,
    %     except for the router.
    %   ice_getLocator - Returns the locator for this proxy.
    %   ice_locator - Returns a proxy that is identical to this proxy,
    %     except for the locator.
    %   ice_isSecure - Returns whether this proxy uses only secure
    %     endpoints.
    %   ice_secure - Returns a proxy that is identical to this proxy,
    %     except for how it selects endpoints.
    %   ice_isPreferSecure - Returns whether this proxy prefers secure
    %     endpoints.
    %   ice_preferSecure - Returns a proxy that is identical to this
    %     proxy, except for its endpoint selection policy.
    %   ice_isTwoway - Returns whether this proxy uses twoway invocations.
    %   ice_twoway - Returns a proxy that is identical to this proxy,
    %     but uses twoway invocations.
    %   ice_isOneway - Returns whether this proxy uses oneway invocations.
    %   ice_oneway - Returns a proxy that is identical to this proxy,
    %     but uses oneway invocations.
    %   ice_isBatchOneway - Returns whether this proxy uses batch oneway
    %     invocations.
    %   ice_batchOneway - Returns a proxy that is identical to this
    %     proxy, but uses batch oneway invocations.
    %   ice_isDatagram - Returns whether this proxy uses datagram
    %     invocations.
    %   ice_datagram - Returns a proxy that is identical to this proxy,
    %     but uses datagram invocations.
    %   ice_isBatchDatagram - Returns whether this proxy uses batch
    %     datagram invocations.
    %   ice_batchDatagram - Returns a proxy that is identical to this
    %     proxy, but uses batch datagram invocations.
    %   ice_compress - Returns a proxy that is identical to this proxy,
    %     except for compression.
    %   ice_getCompress - Obtains the compression override setting of this proxy.
    %   ice_timeout - Returns a proxy that is identical to this proxy,
    %     except for its connection timeout setting.
    %   ice_getTimeout - Obtains the timeout override of this proxy.
    %   ice_fixed - Obtains a proxy that is identical to this proxy, except it's
    %     a fixed proxy bound to the given connection.
    %   ice_getConnection - Returns the Connection for this proxy.
    %   ice_getConnectionAsync - Returns the Connection for this proxy.
    %   ice_getCachedConnection - Returns the cached Connection for this
    %     proxy.
    %   ice_flushBatchRequests - Flushes any pending batched requests for
    %     this communicator.
    %   ice_flushBatchRequestsAsync - Flushes any pending batched
    %     requests for this communicator.

    % Copyright (c) ZeroC, Inc. All rights reserved.

    methods
        function obj = ObjectPrx(communicator, encoding, impl, bytes)
            obj = obj@IceInternal.WrapperObject(impl, 'Ice_ObjectPrx');
            obj.communicator = communicator;
            obj.encoding = encoding;
            if nargin == 4
                obj.bytes = bytes;
            end

            if ~isempty(impl)
                obj.isTwoway = obj.iceCallWithResult('ice_isTwoway');
            end
        end

        function delete(obj)
            if ~isempty(obj.impl_)
                obj.iceCall('unref');
                obj.impl_ = [];
            end
        end

        %
        % Override == operator.
        %
        function r = eq(obj, other)
            if isempty(other) || ~isa(other, 'Ice.ObjectPrx')
                r = false;
            elseif ~isempty(obj.bytes) && ~isempty(other.bytes)
                %
                % Compare the marshaled forms of the two proxies.
                %
                r = isequal(obj.bytes, other.bytes);
            else
                %
                % Call into C++ to compare the two proxies.
                %
                obj.instantiate_();
                other.instantiate_();
                r = obj.iceCallWithResult('equals', other.impl_);
            end
        end

        function r = ice_createOutputStream(obj)
            r = Ice.OutputStream(obj.communicator, obj.encoding);
        end

        function r = ice_toString(obj)
            % ice_toString - Returns a stringified version of this proxy.
            %
            % Returns (char) - A stringified proxy.

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_toString');
        end

        function r = ice_getCommunicator(obj)
            % ice_getCommunicator - Returns the communicator that created this
            %   proxy.
            %
            % Returns (Ice.Communicator) - The communicator that created this
            %   proxy.

            r = obj.communicator;
        end

        function ice_ping(obj, varargin)
            % ice_ping - Tests whether the target object of this proxy can
            %   be reached.
            %
            % Parameters:
            %   context - Optional context map for the invocation.

            obj.iceInvoke('ice_ping', 1, false, [], false, {}, varargin{:});
        end

        function r = ice_pingAsync(obj, varargin)
            % ice_pingAsync - Tests whether the target object of this proxy can
            %   be reached.
            %
            % Parameters:
            %   context - Optional context map for the invocation.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            r = obj.iceInvokeAsync('ice_ping', 1, false, [], 0, [], {}, varargin{:});
        end

        function r = ice_isA(obj, id, varargin)
            % ice_isA - Tests whether this object supports a specific
            %   Slice interface.
            %
            % Parameters:
            %   id - The type ID of the Slice interface to test against.
            %   context - Optional context map for the invocation.
            %
            % Returns (logical) - True if the target object has the interface
            %   specified by id or derives from the interface specified by id.

            os = obj.iceStartWriteParams([]);
            os.writeString(id);
            obj.iceEndWriteParams(os);
            is = obj.iceInvoke('ice_isA', 1, true, os, true, {}, varargin{:});
            is.startEncapsulation();
            r = is.readBool();
            is.endEncapsulation();
        end

        function r = ice_isAAsync(obj, id, varargin)
            % ice_isAAsync - Tests whether this object supports a specific
            %   Slice interface.
            %
            % Parameters:
            %   id - The type ID of the Slice interface to test against.
            %   context - Optional context map for the invocation.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            os = obj.iceStartWriteParams([]);
            os.writeString(id);
            obj.iceEndWriteParams(os);
            function varargout = unmarshal(is)
                is.startEncapsulation();
                varargout{1} = is.readBool();
                is.endEncapsulation();
            end
            r = obj.iceInvokeAsync('ice_isA', 1, true, os, 1, @unmarshal, {}, varargin{:});
        end

        function r = ice_id(obj, varargin)
            % ice_id - Returns the Slice type ID of the most-derived interface
            %   supported by the target object of this proxy.
            %
            % Parameters:
            %   context - Optional context map for the invocation.
            %
            % Returns (char) - The Slice type ID of the most-derived interface.

            is = obj.iceInvoke('ice_id', 1, true, [], true, {}, varargin{:});
            is.startEncapsulation();
            r = is.readString();
            is.endEncapsulation();
        end

        function r = ice_idAsync(obj, varargin)
            % ice_idAsync - Returns the Slice type ID of the most-derived
            %   interface supported by the target object of this proxy.
            %
            % Parameters:
            %   context - Optional context map for the invocation.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            function varargout = unmarshal(is)
                is.startEncapsulation();
                varargout{1} = is.readString();
                is.endEncapsulation();
            end
            r = obj.iceInvokeAsync('ice_id', 1, true, [], 1, @unmarshal, {}, varargin{:});
        end

        function r = ice_ids(obj, varargin)
            % ice_ids - Returns the Slice type IDs of the interfaces supported
            %   by the target object of this proxy.
            %
            % Parameters:
            %   context - Optional context map for the invocation.
            %
            % Returns (cell array of char) - The Slice type IDs of the
            %   interfaces supported by the target object, in base-to-derived
            %   order. The first element of the returned array is always
            %   ::Ice::Object.

            is = obj.iceInvoke('ice_ids', 1, true, [], true, {}, varargin{:});
            is.startEncapsulation();
            r = is.readStringSeq();
            is.endEncapsulation();
        end

        function r = ice_idsAsync(obj, varargin)
            % ice_idsAsync - Returns the Slice type IDs of the interfaces
            %   supported by the target object of this proxy.
            %
            % Parameters:
            %   context - Optional context map for the invocation.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            function varargout = unmarshal(is)
                is.startEncapsulation();
                varargout{1} = is.readStringSeq();
                is.endEncapsulation();
            end
            r = obj.iceInvokeAsync('ice_ids', 1, true, [], 1, @unmarshal, {}, varargin{:});
        end

        function r = ice_getIdentity(obj)
            % ice_getIdentity - Returns the identity embedded in this proxy.
            %
            % Returns (Ice.Identity) - The identity of the target object.

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_getIdentity');
        end

        function r = ice_identity(obj, id)
            % ice_identity - Returns a proxy that is identical to this proxy,
            %   except for the identity.
            %
            % Parameters:
            %   id (Ice.Identity) - The identity for the new proxy.
            %
            % Returns (Ice.ObjectPrx) - The proxy with the new identity.

            r = obj.factory_('ice_identity', false, id);
        end

        function r = ice_getContext(obj)
            % ice_getContext - Returns the per-proxy context for this proxy.
            %
            % Returns (containers.Map) - The per-proxy context. If the proxy
            % does not have a per-proxy (implicit) context, the return value
            % is an empty array.

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_getContext');
        end

        function r = ice_context(obj, ctx)
            % ice_context - Returns a proxy that is identical to this proxy,
            %   except for the per-proxy context.
            %
            % Parameters:
            %   ctx (containers.Map) - The context for the new proxy.
            %
            % Returns - The proxy with the new per-proxy context.

            r = obj.factory_('ice_context', true, ctx);
        end

        function r = ice_getFacet(obj)
            % ice_getFacet - Returns the facet for this proxy.
            %
            % Returns (char) - The facet for this proxy. If the proxy uses the
            %   default facet, the return value is the empty string.

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_getFacet');
        end

        function r = ice_facet(obj, f)
            % ice_facet - Returns a proxy that is identical to this proxy,
            %   except for the facet.
            %
            % Parameters:
            %   f (char) - The facet for the new proxy.
            %
            % Returns (Ice.ObjectPrx) - The proxy with the new facet.

            r = obj.factory_('ice_facet', false, f);
        end

        function r = ice_getAdapterId(obj)
            % ice_getAdapter - Returns the adapter ID for this proxy.
            %
            % Returns (char) - The adapter ID. If the proxy does not have an
            %   adapter ID, the return value is the empty string.

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_getAdapterId');
        end

        function r = ice_adapterId(obj, id)
            % ice_adapterId - Returns a proxy that is identical to this proxy,
            %   except for the adapter ID.
            %
            % Parameters:
            %   id (char) - The adapter ID for the new proxy.
            %
            % Returns - The proxy with the new adapter ID.

            r = obj.factory_('ice_adapterId', true, id);
        end

        function r = ice_getEndpoints(obj)
            % ice_getEndpoints - Returns the endpoints used by this proxy.
            %
            % Returns (cell array of Ice.Endpoint) - The endpoints used by
            %   this proxy.

            obj.instantiate_();
            num = obj.iceCallWithResult('ice_getNumEndpoints');
            r = {};
            for i = 1:num
                impl = libpointer('voidPtr');
                e = obj.iceCallWithResult('ice_getEndpoint', i - 1, impl); % C-style index
                assert(~isNull(impl));
                r{i} = Ice.Endpoint(impl);
            end
        end

        function r = ice_endpoints(obj, endpts)
            % ice_endpoints - Returns a proxy that is identical to this proxy,
            %   except for the endpoints.
            %
            % Parameters:
            %   endpts (cell array of Ice.Endpoint) - The endpoints for the
            %     new proxy.
            %
            % Returns - The proxy with the new endpoints.

            %
            % It's not clear how we can pass a vector of void* to a C function. So we create a temporary C vector
            % and populate it one element at a time.
            %

            for i = 1:length(endpts)
                if ~isa(endpts{i}, 'Ice.Endpoint')
                    throw(MException('Ice:ArgumentException', 'expected an Ice.Endpoint'))
                end
            end
            arr = libpointer('voidPtr');
            obj.iceCall('ice_createEndpointList', length(endpts), arr);
            for i = 1:length(endpts)
                obj.iceCall('ice_setEndpoint', arr, i - 1, endpts{i}.impl_); % C-style index
            end
            r = obj.factory_('ice_endpoints', true, arr); % The C function also destroys the temporary array.
        end

        function r = ice_getLocatorCacheTimeout(obj)
            % ice_getLocatorCacheTimeout - Returns the locator cache timeout
            %   of this proxy.
            %
            % Returns (int32) - The locator cache timeout value (in seconds).

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_getLocatorCacheTimeout');
        end

        function r = ice_locatorCacheTimeout(obj, t)
            % ice_locatorCacheTimeout - Returns a proxy that is identical to
            %   this proxy, except for the locator cache timeout.
            %
            % Parameters:
            %   t (int32) - The new locator cache timeout (in seconds).
            %
            % Returns - The proxy with the new timeout.

            r = obj.factory_('ice_locatorCacheTimeout', true, t);
        end

        function r = ice_getInvocationTimeout(obj)
            % ice_getInvocationTimeout - Returns the invocation timeout of
            %   this proxy.
            %
            % Returns (int32) - The invocation timeout value (in seconds).

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_getInvocationTimeout');
        end

        function r = ice_invocationTimeout(obj, t)
            % ice_invocationTimeout - Returns a proxy that is identical to
            %   this proxy, except for the invocation timeout.
            %
            % Parameters:
            %   t (int32) - The new invocation timeout (in seconds).
            %
            % Returns - The proxy with the new timeout.

            r = obj.factory_('ice_invocationTimeout', true, t);
        end

        function r = ice_getConnectionId(obj)
            % ice_getConnectionId - Returns the connection id of this proxy.
            %
            % Returns (char) - The connection id.

            obj.instantiate_();
            r = obj.iceCallWithResult('ice_getConnectionId');
        end

        function r = ice_connectionId(obj, id)
            % ice_connectionId - Returns a proxy that is identical to this
            %   proxy, except for its connection ID.
            %
            % Parameters:
            %   id (char) - The connection ID for the new proxy. An empty
            %   string removes the connection ID.
            %
            % Returns - A proxy with the specified connection ID.

            r = obj.factory_('ice_connectionId', true, id);
        end

        function r = ice_isConnectionCached(obj)
            % ice_isConnectionCached - Returns whether this proxy caches
            %   connections.
            %
            % Returns (logical) - True if this proxy caches connections;
            %   false otherwise.

            r = obj.iceCallWithResult('ice_isConnectionCached');
        end

        function r = ice_connectionCached(obj, b)
            % ice_connectionCached - Returns a proxy that is identical to this
            %   proxy, except for connection caching.
            %
            % Parameters:
            %   b (logical) - True if the new proxy should cache connections;
            %     false otherwise.
            %
            % Returns - The proxy with the specified caching policy.

            if b
                val = 1;
            else
                val = 0;
            end
            r = obj.factory_('ice_connectionCached', true, val);
        end

        function r = ice_getEndpointSelection(obj)
            % ice_getEndpointSelection - Returns how this proxy selects
            %   endpoints (randomly or ordered).
            %
            % Returns (Ice.EndpointSelectionType) - The endpoint selection
            %   policy.

            obj.instantiate_();
            r = Ice.EndpointSelectionType.ice_getValue(obj.iceCallWithResult('ice_getEndpointSelection'));
        end

        function r = ice_endpointSelection(obj, t)
            % ice_endpointSelection - Returns a proxy that is identical to
            %   this proxy, except for the endpoint selection policy.
            %
            % Parameters:
            %   t (Ice.EndpointSelectionType) - The new endpoint selection policy.
            %
            % Returns - The proxy with the specified endpoint selection policy.

            r = obj.factory_('ice_endpointSelection', true, t);
        end

        function r = ice_getEncodingVersion(obj)
            % ice_getEncodingVersion - Returns the encoding version used to
            %   marshal requests parameters.
            %
            % Returns (Ice.EncodingVersion) - The encoding version.

            r = obj.encoding;
        end

        function r = ice_encodingVersion(obj, ver)
            % ice_encodingVersion - Returns a proxy that is identical to this
            %   proxy, except for the encoding used to marshal parameters.
            %
            % Parameters:
            %   ver (Ice.EncodingVersion) - The encoding version to use to
            %   marshal request parameters.
            %
            % Returns - The proxy with the specified encoding version.

            r = obj.factory_('ice_encodingVersion', true, ver);
            r.encoding = ver;
        end

        function r = ice_getRouter(obj)
            % ice_getRouter - Returns the router for this proxy.
            %
            % Returns (Ice.RouterPrx) - The router for the proxy. If no router
            %   is configured for the proxy, the return value is an empty
            %   array.

            obj.instantiate_();
            v = libpointer('voidPtr');
            obj.iceCall('ice_getRouter', v);
            if isNull(v)
                r = [];
            else
                r = Ice.RouterPrx(obj.communicator, obj.encoding, v, []);
            end
        end

        function r = ice_router(obj, rtr)
            % ice_router - Returns a proxy that is identical to this proxy,
            %   except for the router.
            %
            % Parameters:
            %   rtr (Ice.RouterPrx) - The router for the new proxy.
            %
            % Returns - The proxy with the specified router.

            if isempty(rtr)
                impl = libpointer('voidPtr');
            else
                impl = rtr.impl_;
            end
            r = obj.factory_('ice_router', true, impl);
        end

        function r = ice_getLocator(obj)
            % ice_getLocator - Returns the locator for this proxy.
            %
            % Returns (Ice.LocatorPrx) - The locator for the proxy. If no
            %   locator is configured for the proxy, the return value is
            %   an empty array.

            obj.instantiate_();
            v = libpointer('voidPtr');
            obj.iceCall('ice_getLocator', v);
            if isNull(v)
                r = [];
            else
                r = Ice.LocatorPrx(obj.communicator, obj.encoding, v, []);
            end
        end

        function r = ice_locator(obj, loc)
            % ice_locator - Returns a proxy that is identical to this proxy,
            %   except for the locator.
            %
            % Parameters:
            %   loc (Ice.LocatorPrx) - The locator for the new proxy.
            %
            % Returns - The proxy with the specified locator.

            if isempty(loc)
                impl = libpointer('voidPtr');
            else
                impl = loc.impl_;
            end
            r = obj.factory_('ice_locator', true, impl);
        end

        function r = ice_isSecure(obj)
            % ice_isSecure - Returns whether this proxy uses only secure
            %   endpoints.
            %
            % Returns (logical) - True if this proxy communicates only via
            %   secure endpoints; false otherwise.

            r = obj.iceCallWithResult('ice_isSecure');
        end

        function r = ice_secure(obj, b)
            % ice_secure - Returns a proxy that is identical to this proxy,
            %   except for how it selects endpoints.
            %
            % Parameters:
            %   b (logical) - If b is true, only endpoints that use a secure
            %     transport are used by the new proxy. If b is false, the
            %     returned proxy uses both secure and insecure endpoints.
            %
            % Returns - The proxy with the specified selection policy.

            if b
                val = 1;
            else
                val = 0;
            end
            r = obj.factory_('ice_secure', true, val);
        end

        function r = ice_isPreferSecure(obj)
            % ice_isPreferSecure - Returns whether this proxy prefers secure
            %   endpoints.
            %
            % Returns (logical) - True if the proxy always attempts to invoke
            %   via secure endpoints before it attempts to use insecure
            %   endpoints; false otherwise.

            r = obj.iceCallWithResult('ice_isPreferSecure');
        end

        function r = ice_preferSecure(obj, b)
            % ice_preferSecure - Returns a proxy that is identical to this
            %   proxy, except for its endpoint selection policy.
            %
            % Parameters:
            %   b (logical) - If b is true, the new proxy will use secure
            %     endpoints for invocations and only use insecure endpoints
            %     if an invocation cannot be made via secure endpoints.
            %     If b is false, the proxy prefers insecure endpoints to
            %     secure ones.
            %
            % Returns - The proxy with the specified selection policy.

            if b
                val = 1;
            else
                val = 0;
            end
            r = obj.factory_('ice_preferSecure', true, val);
        end

        function r = ice_isTwoway(obj)
            % ice_isTwoway - Returns whether this proxy uses twoway invocations.
            %
            % Returns (logical) - True if this proxy uses twoway invocations;
            %   false otherwise.

            r = obj.isTwoway;
        end

        function r = ice_twoway(obj)
            % ice_twoway - Returns a proxy that is identical to this proxy,
            %   but uses twoway invocations.
            %
            % Returns - A proxy that uses twoway invocations.

            r = obj.factory_('ice_twoway', true);
        end

        function r = ice_isOneway(obj)
            % ice_isOneway - Returns whether this proxy uses oneway invocations.
            %
            % Returns (logical) - True if this proxy uses oneway invocations;
            %   false otherwise.

            r = obj.iceCallWithResult('ice_isOneway');
        end

        function r = ice_oneway(obj)
            % ice_oneway - Returns a proxy that is identical to this proxy,
            %   but uses oneway invocations.
            %
            % Returns - A proxy that uses oneway invocations.

            r = obj.factory_('ice_oneway', true);
        end

        function r = ice_isBatchOneway(obj)
            % ice_isBatchOneway - Returns whether this proxy uses batch oneway
            %   invocations.
            %
            % Returns (logical) - True if this proxy uses batch oneway
            %   invocations; false otherwise.

            r = obj.iceCallWithResult('ice_isBatchOneway');
        end

        function r = ice_batchOneway(obj)
            % ice_batchOneway - Returns a proxy that is identical to this
            %   proxy, but uses batch oneway invocations.
            %
            % Returns - A new proxy that uses batch oneway invocations.

            r = obj.factory_('ice_batchOneway', true);
        end

        function r = ice_isDatagram(obj)
            % ice_isDatagram - Returns whether this proxy uses datagram
            %   invocations.
            %
            % Returns (logical) - True if this proxy uses datagram invocations;
            %   false otherwise.

            r = obj.iceCallWithResult('ice_isDatagram');
        end

        function r = ice_datagram(obj)
            % ice_datagram - Returns a proxy that is identical to this proxy,
            %   but uses datagram invocations.
            %
            % Returns - A new proxy that uses datagram invocations.

            r = obj.factory_('ice_datagram', true);
        end

        function r = ice_isBatchDatagram(obj)
            % ice_isBatchDatagram - Returns whether this proxy uses batch
            %   datagram invocations.
            %
            % Returns (logical) - True if this proxy uses batch datagram
            %   invocations; false otherwise.

            r = obj.iceCallWithResult('ice_isBatchDatagram');
        end

        function r = ice_batchDatagram(obj)
            % ice_batchDatagram - Returns a proxy that is identical to this
            %   proxy, but uses batch datagram invocations.
            %
            % Returns - A new proxy that uses batch datagram invocations.

            r = obj.factory_('ice_batchDatagram', true);
        end

        function r = ice_compress(obj, b)
            % ice_compress - Returns a proxy that is identical to this proxy,
            %   except for compression.
            %
            % Parameters:
            %   b (logical) - True enables compression for the new proxy;
            %     false disables compression.
            %
            % Returns - A proxy with the specified compression override setting.

            if b
                val = 1;
            else
                val = 0;
            end
            r = obj.factory_('ice_compress', true, val);
        end

        function r = ice_getCompress(obj)
            % ice_getCompress - Obtains the compression override setting of this proxy.
            %
            % Returns (optional bool) - The compression override setting. If Ice.Unset
            %   is returned, no override is set. Otherwise, true if compression is
            %   enabled, false otherwise.

            obj.instantiate_();
            opt = obj.iceCallWithResult('ice_getCompress');
            if opt.hasValue
                r = opt.value;
            else
                r = Ice.Unset;
            end
        end

        function r = ice_timeout(obj, t)
            % ice_timeout - Returns a proxy that is identical to this proxy,
            %   except for its connection timeout setting which overrides the timeout
            %   setting from the proxy endpoints.
            %
            % Parameters:
            %   t (int32) - The connection override timeout for the proxy in
            %     milliseconds.
            %
            % Returns - A proxy with the specified timeout.

            r = obj.factory_('ice_timeout', true, t);
        end

        function r = ice_getTimeout(obj)
            % ice_getTimeout - Obtains the timeout override of this proxy.
            %
            % Returns (optional int32) - The timeout override. If Ice.Unset
            %   is returned, no override is set. Otherwise, returns the
            %   timeout override value.

            obj.instantiate_();
            opt = obj.iceCallWithResult('ice_getTimeout');
            if opt.hasValue
                r = opt.value;
            else
                r = Ice.Unset;
            end
        end

        function r = ice_fixed(obj, connection)
            % ice_fixed - Obtains a proxy that is identical to this proxy, except it's
            %   a fixed proxy bound to the given connection.
            %
            % Parameters:
            %   connection (Ice.Connection) - The fixed proxy connection.
            %
            % Returns (Ice.ObjectPrx) - A fixed proxy bound to the given connection.

            if isempty(connection)
                throw(MException('Ice:ArgumentException', 'invalid null connection passed to ice_fixed'));
            end

            r = obj.factory_('ice_fixed', true, connection.iceGetImpl());
        end

        function r = ice_getConnection(obj)
            % ice_getConnection - Returns the Connection for this proxy. If the
            %   proxy does not yet have an established connection, it first
            %   attempts to create a connection.
            %
            % Returns (Ice.Connection) - The Connection for this proxy.

            obj.instantiate_();
            v = libpointer('voidPtr');
            obj.iceCall('ice_getConnection', v);
            if isNull(v)
                r = [];
            else
                r = Ice.Connection(v, obj.communicator);
            end
        end

        function r = ice_getConnectionAsync(obj)
            % ice_getConnectionAsync - Returns the Connection for this proxy.
            %   If the proxy does not yet have an established connection, it
            %   first attempts to create a connection.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            obj.instantiate_();
            future = libpointer('voidPtr');
            obj.iceCall('ice_getConnectionAsync', future);
            assert(~isNull(future));
            function varargout = fetch(f)
                con = libpointer('voidPtr', 0); % Output param
                f.iceCall('fetch', con);
                assert(~isNull(con));
                varargout{1} = Ice.Connection(con);
            end
            r = Ice.Future(future, 'ice_getConnection', 1, 'Ice_GetConnectionFuture', @fetch);
        end

        function r = ice_getCachedConnection(obj)
            % ice_getCachedConnection - Returns the cached Connection for this
            %   proxy. If the proxy does not yet have an established
            %   connection, it does not attempt to create a connection.
            %
            % Returns (Ice.Connection) - The cached Connection for this proxy,
            %   or an empty array if the proxy does not have an established
            %   connection.

            obj.instantiate_();
            v = libpointer('voidPtr');
            obj.iceCall('ice_getCachedConnection', v);
            if isNull(v)
                r = [];
            else
                r = Ice.Connection(v, obj.communicator);
            end
        end

        function ice_flushBatchRequests(obj)
            % ice_flushBatchRequests - Flushes any pending batched requests for
            %   this communicator. The call blocks until the flush is complete.

            obj.instantiate_();
            obj.iceCall('ice_flushBatchRequests');
        end

        function r = ice_flushBatchRequestsAsync(obj)
            % ice_flushBatchRequestsAsync - Flushes any pending batched
            %   requests for this communicator. The call blocks until the
            %   flush is complete.
            %
            % Returns (Ice.Future) - A future that will be completed when the
            %   invocation completes.

            obj.instantiate_();
            future = libpointer('voidPtr');
            obj.iceCall('ice_flushBatchRequestsAsync', future);
            assert(~isNull(future));
            r = Ice.Future(future, 'ice_flushBatchRequests', 0, 'Ice_SimpleFuture', @(fut) fut.iceCall('check'));
        end
    end

    methods(Hidden=true)
        function iceWrite(obj, os, encoding)
            %
            % If we don't yet have a byte buffer representing the marshaled form of the proxy, then call into
            % C++ to marshal the proxy and then cache the bytes.
            %
            if isempty(obj.bytes)
                obj.bytes = obj.iceCallWithResult('write', obj.communicator.impl_, encoding);
            end
            os.writeBlob(obj.bytes);
        end
        function r = iceGetImpl(obj)
            obj.instantiate_();
            r = obj.impl_;
        end
    end

    methods(Access=protected)
        function os = iceStartWriteParams(obj, format)
            os = obj.ice_createOutputStream();
            os.startEncapsulation(format);
        end

        function iceEndWriteParams(obj, os)
            os.endEncapsulation();
        end

        function is = iceInvoke(obj, op, mode, twowayOnly, os, hasOutParams, exceptions, varargin)
            if isempty(obj.impl_)
                obj.instantiate_();
            end

            try
                % Vararg accepted for optional context argument.
                if length(varargin) > 1
                    throw(MException('Ice:ArgumentException', 'one optional argument is allowed for request context'))
                end

                if twowayOnly && ~obj.isTwoway
                    throw(Ice.TwowayOnlyException('', 'invocation requires twoway proxy', op));
                end

                if isempty(os)
                    buf = [];
                    size = 0;
                else
                    buf = os.buf.buf;
                    size = os.buf.size;
                end

                if length(varargin) == 1
                    %
                    % Avoid the string concatenation
                    %
                    % res = obj.iceCallWithResult('ice_invoke', op, mode, buf, size, varargin{1});
                    %
                    res = IceInternal.Util.callWithResult('Ice_ObjectPrx_ice_invoke', obj.impl_, op, mode, buf, ...
                                                          size, varargin{1});
                else
                    %
                    % Avoid the string concatenation
                    %
                    % res = obj.iceCallWithResult('ice_invokeNC', op, mode, buf, size);
                    %
                    res = IceInternal.Util.callWithResult('Ice_ObjectPrx_ice_invokeNC', obj.impl_, op, mode, buf, size);
                end

                is = [];
                if ~isempty(res.params)
                    if isempty(obj.cachedInputStream)
                        is = Ice.InputStream(obj.communicator, obj.encoding, IceInternal.Buffer(res.params));
                        obj.cachedInputStream = is;
                    else
                        is = obj.cachedInputStream;
                        is.reset(res.params);
                    end
                end

                if obj.isTwoway
                    if ~res.ok
                        obj.iceThrowUserException(is, exceptions{:});
                    elseif ~hasOutParams
                        is.skipEmptyEncapsulation();
                    end
                end
            catch ex
                ex.throwAsCaller();
            end
        end

        function fut = iceInvokeAsync(obj, op, mode, twowayOnly, os, numOutArgs, unmarshalFunc, exceptions, varargin)
            if isempty(obj.impl_)
                obj.instantiate_();
            end

            isTwoway = obj.isTwoway;

            % This nested function is invoked by Future.fetchOutputs()
            function varargout = fetch(f)
                try
                    if isTwoway
                        %
                        % Call 'results' to obtain a boolean indicating whether the request completed successfully
                        % or returned a user exception, and the encoded out parameters. The function can also raise
                        % a local exception if necessary.
                        %
                        % Avoid the string concatenation
                        %
                        % res = f.iceCallWithResult('results');
                        %
                        res = IceInternal.Util.callWithResult('Ice_InvocationFuture_results', f.impl_);
                        is = Ice.InputStream(obj.communicator, obj.encoding, IceInternal.Buffer(res.params));
                        if ~res.ok
                            obj.iceThrowUserException(is, exceptions{:});
                        end
                        if isempty(unmarshalFunc)
                            is.skipEmptyEncapsulation();
                        else
                            [varargout{1:numOutArgs}] = unmarshalFunc(is);
                        end
                    else
                        %
                        % Check for a local exception.
                        %
                        % Avoid the string concatenation
                        %
                        % f.iceCall('check');
                        %
                        IceInternal.Util.call('Ice_InvocationFuture_check', f.impl_);
                    end
                catch ex
                    ex.throwAsCaller();
                end
            end

            try
                % Vararg accepted for optional context argument.
                if length(varargin) > 1
                    throw(MException('Ice:ArgumentException', 'one optional argument is allowed for request context'))
                end
                if twowayOnly && ~isTwoway
                    throw(Ice.TwowayOnlyException('', 'invocation requires twoway proxy', op));
                end
                if isempty(os)
                    buf = [];
                    size = 0;
                else
                    buf = os.buf.buf;
                    size = os.buf.size;
                end
                futPtr = libpointer('voidPtr'); % Output param
                if length(varargin) == 1
                    %
                    % Avoid the string concatenation
                    %
                    % obj.iceCall('ice_invokeAsync', op, mode, buf, size, varargin{1}, futPtr);
                    %
                    IceInternal.Util.call('Ice_ObjectPrx_ice_invokeAsync', obj.impl_, op, mode, buf, size, ...
                                          varargin{1}, futPtr);
                else
                    %
                    % Avoid the string concatenation
                    %
                    % obj.iceCall('ice_invokeAsyncNC', op, mode, buf, size, futPtr);
                    %
                    IceInternal.Util.call('Ice_ObjectPrx_ice_invokeAsyncNC', obj.impl_, op, mode, buf, size, futPtr);
                end
                assert(~isNull(futPtr));
                fut = Ice.Future(futPtr, op, numOutArgs, 'Ice_InvocationFuture', @fetch);
            catch ex
                ex.throwAsCaller();
            end
        end

        function iceThrowUserException(obj, is, varargin) % Varargs are user exception type names
            try
                is.startEncapsulation();
                is.throwException();
            catch ex
                if isa(ex, 'Ice.UserException')
                    is.endEncapsulation();
                    for i = 1:length(varargin)
                        if isa(ex, varargin{i})
                            ex.throwAsCaller();
                        end
                    end
                    uue = Ice.UnknownUserException('', '', ex.ice_id());
                    uue.throwAsCaller();
                else
                    rethrow(ex);
                end
            end
        end
    end

    methods(Static)
        function r = ice_staticId()
            r = '::Ice::Object';
        end

        function r = checkedCast(p, varargin)
            if length(varargin) == 0
                r = p;
            else
                r = Ice.ObjectPrx.iceCheckedCast(p, Ice.ObjectPrx.ice_staticId(), 'Ice.ObjectPrx', varargin{:});
            end
        end

        function r = uncheckedCast(p, varargin)
            if length(varargin) == 0
                r = p;
            elseif length(varargin) == 1
                if ~isempty(p)
                    r = p.ice_facet(varargin{1});
                else
                    r = p;
                end
            else
                throw(MException('Ice:ArgumentException', 'too many arguments to uncheckedCast'));
            end
        end
    end

    methods(Static,Access=protected)
        function r = iceCheckedCast(p, id, cls, varargin)
            try
                hasFacet = false;
                facet = [];
                context = {};
                if length(varargin) == 1
                    if isa(varargin{1}, 'containers.Map')
                        context = { varargin{1} };
                    elseif isempty(varargin{1}) || isa(varargin{1}, 'char')
                        hasFacet = true;
                        facet = varargin{1};
                    else
                        throw(MException('Ice:ArgumentException', 'expecting string or containers.Map'));
                    end
                elseif length(varargin) == 2
                    hasFacet = true;
                    facet = varargin{1};
                    context = { varargin{2} };
                elseif length(varargin) > 2
                    throw(MException('Ice:ArgumentException', 'too many arguments to checkedCast'));
                end
                if ~isempty(p)
                    if hasFacet
                        p = p.ice_facet(facet);
                    end
                    if isa(p, cls)
                        r = p;
                    elseif p.ice_isA(id, context{:})
                        constructor = str2func(cls);
                        r = constructor(p.communicator, p.encoding, p.clone_(), []);
                    else
                        r = [];
                    end
                else
                    r = p;
                end
            catch ex
                ex.throwAsCaller();
            end
        end

        function r = iceUncheckedCast(p, cls, varargin)
            hasFacet = false;
            facet = [];
            if length(varargin) == 1
                hasFacet = true;
                facet = varargin{1};
            elseif length(varargin) > 1
                throw(MException('Ice:ArgumentException', 'too many arguments to uncheckedCast'));
            end
            if ~isempty(p)
                if hasFacet
                    p = p.ice_facet(facet);
                end
                if isa(p, cls)
                    r = p;
                else
                    constructor = str2func(cls);
                    r = constructor(p.communicator, p.encoding, p.clone_(), []);
                end
            else
                r = p;
            end
        end
    end

    methods(Access=private)
        function instantiate_(obj)
            %
            % An unmarshaled proxy delays the creation of its corresponding C++ object until the application
            % needs it. To obtain the C++ object, we unmarshal it (again) by calling into C++ to extract it
            % from the byte buffer that contains the proxy's marshaled form.
            %
            if isempty(obj.impl_)
                assert(~isempty(obj.bytes));
                %
                % Call into C++ to construct a proxy. We pass the data buffer and start position (adjusted for
                % C-style pointers), along with the size of the entire buffer. The C++ implementation reads what
                % it needs and returns the new proxy object as well as number of bytes it consumed.
                %
                impl = libpointer('voidPtr');
                start = 0; % Starting position for a C-style pointer.
                IceInternal.Util.call('Ice_ObjectPrx_read', obj.communicator.impl_, obj.encoding, obj.bytes, ...
                                      start, length(obj.bytes), impl);
                obj.impl_ = impl;

                % Cache the twoway status
                obj.isTwoway = obj.iceCallWithResult('ice_isTwoway');
            end
        end

        function r = factory_(obj, op, keepType, varargin)
            %
            % Call a C++ proxy factory function. The function returns nil if the call results in no change to the
            % proxy, in which case we can return the current object.
            %

            obj.instantiate_();

            newImpl = libpointer('voidPtr');
            obj.iceCall(op, newImpl, varargin{:});
            if isNull(newImpl)
                r = obj;
            elseif keepType
                r = obj.newInstance_(newImpl); % Retain the proxy's current type.
            else
                %
                % We don't retain the proxy's existing type for a couple of factory functions.
                %
                r = Ice.ObjectPrx(obj.communicator, obj.encoding, newImpl);
            end
        end

        function r = newInstance_(obj, impl)
            %
            % Return a new instance of this proxy type.
            %
            constructor = str2func(class(obj)); % Obtain the constructor for this class
            r = constructor(obj.communicator, obj.encoding, impl, []); % Call the constructor
        end

        function r = clone_(obj)
            %
            % Clone the C++ reference for use by a new instance of ObjectPrx.
            %
            obj.instantiate_();
            implPtr = libpointer('voidPtr'); % Output param
            obj.iceCall('clone', implPtr);
            r = implPtr;
        end
    end

    properties(Access=private)
        communicator % The communicator wrapper
        encoding
        isTwoway
        cachedInputStream % Only used for synchronous invocations
        bytes
    end
end