1classdef ObjectPrx < IceInternal.WrapperObject
2    % ObjectPrx   Summary of ObjectPrx
3    %
4    % Base interface of all object proxies.
5    %
6    % ObjectPrx Methods:
7    %   ice_toString - Returns a stringified version of this proxy.
8    %   ice_getCommunicator - Returns the communicator that created this
9    %     proxy.
10    %   ice_ping - Tests whether the target object of this proxy can
11    %     be reached.
12    %   ice_pingAsync - Tests whether the target object of this proxy can
13    %     be reached.
14    %   ice_isA - Tests whether this object supports a specific
15    %     Slice interface.
16    %   ice_isAAsync - Tests whether this object supports a specific
17    %     Slice interface.
18    %   ice_id - Returns the Slice type ID of the most-derived interface
19    %     supported by the target object of this proxy.
20    %   ice_idAsync - Returns the Slice type ID of the most-derived
21    %     interface supported by the target object of this proxy.
22    %   ice_ids - Returns the Slice type IDs of the interfaces supported
23    %     by the target object of this proxy.
24    %   ice_idsAsync - Returns the Slice type IDs of the interfaces
25    %     supported by the target object of this proxy.
26    %   ice_getIdentity - Returns the identity embedded in this proxy.
27    %   ice_identity - Returns a proxy that is identical to this proxy,
28    %     except for the identity.
29    %   ice_getContext - Returns the per-proxy context for this proxy.
30    %   ice_context - Returns a proxy that is identical to this proxy,
31    %     except for the per-proxy context.
32    %   ice_getFacet - Returns the facet for this proxy.
33    %   ice_facet - Returns a proxy that is identical to this proxy,
34    %     except for the facet.
35    %   ice_getAdapter - Returns the adapter ID for this proxy.
36    %   ice_adapterId - Returns a proxy that is identical to this proxy,
37    %     except for the adapter ID.
38    %   ice_getEndpoints - Returns the endpoints used by this proxy.
39    %   ice_endpoints - Returns a proxy that is identical to this proxy,
40    %     except for the endpoints.
41    %   ice_getLocatorCacheTimeout - Returns the locator cache timeout
42    %     of this proxy.
43    %   ice_locatorCacheTimeout - Returns a proxy that is identical to
44    %     this proxy, except for the locator cache timeout.
45    %   ice_getInvocationTimeout - Returns the invocation timeout of
46    %     this proxy.
47    %   ice_invocationTimeout - Returns a proxy that is identical to
48    %     this proxy, except for the invocation timeout.
49    %   ice_getConnectionId - Returns the connection id of this proxy.
50    %   ice_connectionId - Returns a proxy that is identical to this
51    %     proxy, except for its connection ID.
52    %   ice_isConnectionCached - Returns whether this proxy caches
53    %     connections.
54    %   ice_connectionCached - Returns a proxy that is identical to this
55    %     proxy, except for connection caching.
56    %   ice_getEndpointSelection - Returns how this proxy selects
57    %     endpoints (randomly or ordered).
58    %   ice_endpointSelection - Returns a proxy that is identical to
59    %     this proxy, except for the endpoint selection policy.
60    %   ice_getEncodingVersion - Returns the encoding version used to
61    %     marshal requests parameters.
62    %   ice_encodingVersion - Returns a proxy that is identical to this
63    %     proxy, except for the encoding used to marshal parameters.
64    %   ice_getRouter - Returns the router for this proxy.
65    %   ice_router - Returns a proxy that is identical to this proxy,
66    %     except for the router.
67    %   ice_getLocator - Returns the locator for this proxy.
68    %   ice_locator - Returns a proxy that is identical to this proxy,
69    %     except for the locator.
70    %   ice_isSecure - Returns whether this proxy uses only secure
71    %     endpoints.
72    %   ice_secure - Returns a proxy that is identical to this proxy,
73    %     except for how it selects endpoints.
74    %   ice_isPreferSecure - Returns whether this proxy prefers secure
75    %     endpoints.
76    %   ice_preferSecure - Returns a proxy that is identical to this
77    %     proxy, except for its endpoint selection policy.
78    %   ice_isTwoway - Returns whether this proxy uses twoway invocations.
79    %   ice_twoway - Returns a proxy that is identical to this proxy,
80    %     but uses twoway invocations.
81    %   ice_isOneway - Returns whether this proxy uses oneway invocations.
82    %   ice_oneway - Returns a proxy that is identical to this proxy,
83    %     but uses oneway invocations.
84    %   ice_isBatchOneway - Returns whether this proxy uses batch oneway
85    %     invocations.
86    %   ice_batchOneway - Returns a proxy that is identical to this
87    %     proxy, but uses batch oneway invocations.
88    %   ice_isDatagram - Returns whether this proxy uses datagram
89    %     invocations.
90    %   ice_datagram - Returns a proxy that is identical to this proxy,
91    %     but uses datagram invocations.
92    %   ice_isBatchDatagram - Returns whether this proxy uses batch
93    %     datagram invocations.
94    %   ice_batchDatagram - Returns a proxy that is identical to this
95    %     proxy, but uses batch datagram invocations.
96    %   ice_compress - Returns a proxy that is identical to this proxy,
97    %     except for compression.
98    %   ice_getCompress - Obtains the compression override setting of this proxy.
99    %   ice_timeout - Returns a proxy that is identical to this proxy,
100    %     except for its connection timeout setting.
101    %   ice_getTimeout - Obtains the timeout override of this proxy.
102    %   ice_fixed - Obtains a proxy that is identical to this proxy, except it's
103    %     a fixed proxy bound to the given connection.
104    %   ice_getConnection - Returns the Connection for this proxy.
105    %   ice_getConnectionAsync - Returns the Connection for this proxy.
106    %   ice_getCachedConnection - Returns the cached Connection for this
107    %     proxy.
108    %   ice_flushBatchRequests - Flushes any pending batched requests for
109    %     this communicator.
110    %   ice_flushBatchRequestsAsync - Flushes any pending batched
111    %     requests for this communicator.
112
113    % Copyright (c) ZeroC, Inc. All rights reserved.
114
115    methods
116        function obj = ObjectPrx(communicator, encoding, impl, bytes)
117            obj = obj@IceInternal.WrapperObject(impl, 'Ice_ObjectPrx');
118            obj.communicator = communicator;
119            obj.encoding = encoding;
120            if nargin == 4
121                obj.bytes = bytes;
122            end
123
124            if ~isempty(impl)
125                obj.isTwoway = obj.iceCallWithResult('ice_isTwoway');
126            end
127        end
128
129        function delete(obj)
130            if ~isempty(obj.impl_)
131                obj.iceCall('unref');
132                obj.impl_ = [];
133            end
134        end
135
136        %
137        % Override == operator.
138        %
139        function r = eq(obj, other)
140            if isempty(other) || ~isa(other, 'Ice.ObjectPrx')
141                r = false;
142            elseif ~isempty(obj.bytes) && ~isempty(other.bytes)
143                %
144                % Compare the marshaled forms of the two proxies.
145                %
146                r = isequal(obj.bytes, other.bytes);
147            else
148                %
149                % Call into C++ to compare the two proxies.
150                %
151                obj.instantiate_();
152                other.instantiate_();
153                r = obj.iceCallWithResult('equals', other.impl_);
154            end
155        end
156
157        function r = ice_createOutputStream(obj)
158            r = Ice.OutputStream(obj.communicator, obj.encoding);
159        end
160
161        function r = ice_toString(obj)
162            % ice_toString - Returns a stringified version of this proxy.
163            %
164            % Returns (char) - A stringified proxy.
165
166            obj.instantiate_();
167            r = obj.iceCallWithResult('ice_toString');
168        end
169
170        function r = ice_getCommunicator(obj)
171            % ice_getCommunicator - Returns the communicator that created this
172            %   proxy.
173            %
174            % Returns (Ice.Communicator) - The communicator that created this
175            %   proxy.
176
177            r = obj.communicator;
178        end
179
180        function ice_ping(obj, varargin)
181            % ice_ping - Tests whether the target object of this proxy can
182            %   be reached.
183            %
184            % Parameters:
185            %   context - Optional context map for the invocation.
186
187            obj.iceInvoke('ice_ping', 1, false, [], false, {}, varargin{:});
188        end
189
190        function r = ice_pingAsync(obj, varargin)
191            % ice_pingAsync - Tests whether the target object of this proxy can
192            %   be reached.
193            %
194            % Parameters:
195            %   context - Optional context map for the invocation.
196            %
197            % Returns (Ice.Future) - A future that will be completed when the
198            %   invocation completes.
199
200            r = obj.iceInvokeAsync('ice_ping', 1, false, [], 0, [], {}, varargin{:});
201        end
202
203        function r = ice_isA(obj, id, varargin)
204            % ice_isA - Tests whether this object supports a specific
205            %   Slice interface.
206            %
207            % Parameters:
208            %   id - The type ID of the Slice interface to test against.
209            %   context - Optional context map for the invocation.
210            %
211            % Returns (logical) - True if the target object has the interface
212            %   specified by id or derives from the interface specified by id.
213
214            os = obj.iceStartWriteParams([]);
215            os.writeString(id);
216            obj.iceEndWriteParams(os);
217            is = obj.iceInvoke('ice_isA', 1, true, os, true, {}, varargin{:});
218            is.startEncapsulation();
219            r = is.readBool();
220            is.endEncapsulation();
221        end
222
223        function r = ice_isAAsync(obj, id, varargin)
224            % ice_isAAsync - Tests whether this object supports a specific
225            %   Slice interface.
226            %
227            % Parameters:
228            %   id - The type ID of the Slice interface to test against.
229            %   context - Optional context map for the invocation.
230            %
231            % Returns (Ice.Future) - A future that will be completed when the
232            %   invocation completes.
233
234            os = obj.iceStartWriteParams([]);
235            os.writeString(id);
236            obj.iceEndWriteParams(os);
237            function varargout = unmarshal(is)
238                is.startEncapsulation();
239                varargout{1} = is.readBool();
240                is.endEncapsulation();
241            end
242            r = obj.iceInvokeAsync('ice_isA', 1, true, os, 1, @unmarshal, {}, varargin{:});
243        end
244
245        function r = ice_id(obj, varargin)
246            % ice_id - Returns the Slice type ID of the most-derived interface
247            %   supported by the target object of this proxy.
248            %
249            % Parameters:
250            %   context - Optional context map for the invocation.
251            %
252            % Returns (char) - The Slice type ID of the most-derived interface.
253
254            is = obj.iceInvoke('ice_id', 1, true, [], true, {}, varargin{:});
255            is.startEncapsulation();
256            r = is.readString();
257            is.endEncapsulation();
258        end
259
260        function r = ice_idAsync(obj, varargin)
261            % ice_idAsync - Returns the Slice type ID of the most-derived
262            %   interface supported by the target object of this proxy.
263            %
264            % Parameters:
265            %   context - Optional context map for the invocation.
266            %
267            % Returns (Ice.Future) - A future that will be completed when the
268            %   invocation completes.
269
270            function varargout = unmarshal(is)
271                is.startEncapsulation();
272                varargout{1} = is.readString();
273                is.endEncapsulation();
274            end
275            r = obj.iceInvokeAsync('ice_id', 1, true, [], 1, @unmarshal, {}, varargin{:});
276        end
277
278        function r = ice_ids(obj, varargin)
279            % ice_ids - Returns the Slice type IDs of the interfaces supported
280            %   by the target object of this proxy.
281            %
282            % Parameters:
283            %   context - Optional context map for the invocation.
284            %
285            % Returns (cell array of char) - The Slice type IDs of the
286            %   interfaces supported by the target object, in base-to-derived
287            %   order. The first element of the returned array is always
288            %   ::Ice::Object.
289
290            is = obj.iceInvoke('ice_ids', 1, true, [], true, {}, varargin{:});
291            is.startEncapsulation();
292            r = is.readStringSeq();
293            is.endEncapsulation();
294        end
295
296        function r = ice_idsAsync(obj, varargin)
297            % ice_idsAsync - Returns the Slice type IDs of the interfaces
298            %   supported by the target object of this proxy.
299            %
300            % Parameters:
301            %   context - Optional context map for the invocation.
302            %
303            % Returns (Ice.Future) - A future that will be completed when the
304            %   invocation completes.
305
306            function varargout = unmarshal(is)
307                is.startEncapsulation();
308                varargout{1} = is.readStringSeq();
309                is.endEncapsulation();
310            end
311            r = obj.iceInvokeAsync('ice_ids', 1, true, [], 1, @unmarshal, {}, varargin{:});
312        end
313
314        function r = ice_getIdentity(obj)
315            % ice_getIdentity - Returns the identity embedded in this proxy.
316            %
317            % Returns (Ice.Identity) - The identity of the target object.
318
319            obj.instantiate_();
320            r = obj.iceCallWithResult('ice_getIdentity');
321        end
322
323        function r = ice_identity(obj, id)
324            % ice_identity - Returns a proxy that is identical to this proxy,
325            %   except for the identity.
326            %
327            % Parameters:
328            %   id (Ice.Identity) - The identity for the new proxy.
329            %
330            % Returns (Ice.ObjectPrx) - The proxy with the new identity.
331
332            r = obj.factory_('ice_identity', false, id);
333        end
334
335        function r = ice_getContext(obj)
336            % ice_getContext - Returns the per-proxy context for this proxy.
337            %
338            % Returns (containers.Map) - The per-proxy context. If the proxy
339            % does not have a per-proxy (implicit) context, the return value
340            % is an empty array.
341
342            obj.instantiate_();
343            r = obj.iceCallWithResult('ice_getContext');
344        end
345
346        function r = ice_context(obj, ctx)
347            % ice_context - Returns a proxy that is identical to this proxy,
348            %   except for the per-proxy context.
349            %
350            % Parameters:
351            %   ctx (containers.Map) - The context for the new proxy.
352            %
353            % Returns - The proxy with the new per-proxy context.
354
355            r = obj.factory_('ice_context', true, ctx);
356        end
357
358        function r = ice_getFacet(obj)
359            % ice_getFacet - Returns the facet for this proxy.
360            %
361            % Returns (char) - The facet for this proxy. If the proxy uses the
362            %   default facet, the return value is the empty string.
363
364            obj.instantiate_();
365            r = obj.iceCallWithResult('ice_getFacet');
366        end
367
368        function r = ice_facet(obj, f)
369            % ice_facet - Returns a proxy that is identical to this proxy,
370            %   except for the facet.
371            %
372            % Parameters:
373            %   f (char) - The facet for the new proxy.
374            %
375            % Returns (Ice.ObjectPrx) - The proxy with the new facet.
376
377            r = obj.factory_('ice_facet', false, f);
378        end
379
380        function r = ice_getAdapterId(obj)
381            % ice_getAdapter - Returns the adapter ID for this proxy.
382            %
383            % Returns (char) - The adapter ID. If the proxy does not have an
384            %   adapter ID, the return value is the empty string.
385
386            obj.instantiate_();
387            r = obj.iceCallWithResult('ice_getAdapterId');
388        end
389
390        function r = ice_adapterId(obj, id)
391            % ice_adapterId - Returns a proxy that is identical to this proxy,
392            %   except for the adapter ID.
393            %
394            % Parameters:
395            %   id (char) - The adapter ID for the new proxy.
396            %
397            % Returns - The proxy with the new adapter ID.
398
399            r = obj.factory_('ice_adapterId', true, id);
400        end
401
402        function r = ice_getEndpoints(obj)
403            % ice_getEndpoints - Returns the endpoints used by this proxy.
404            %
405            % Returns (cell array of Ice.Endpoint) - The endpoints used by
406            %   this proxy.
407
408            obj.instantiate_();
409            num = obj.iceCallWithResult('ice_getNumEndpoints');
410            r = {};
411            for i = 1:num
412                impl = libpointer('voidPtr');
413                e = obj.iceCallWithResult('ice_getEndpoint', i - 1, impl); % C-style index
414                assert(~isNull(impl));
415                r{i} = Ice.Endpoint(impl);
416            end
417        end
418
419        function r = ice_endpoints(obj, endpts)
420            % ice_endpoints - Returns a proxy that is identical to this proxy,
421            %   except for the endpoints.
422            %
423            % Parameters:
424            %   endpts (cell array of Ice.Endpoint) - The endpoints for the
425            %     new proxy.
426            %
427            % Returns - The proxy with the new endpoints.
428
429            %
430            % It's not clear how we can pass a vector of void* to a C function. So we create a temporary C vector
431            % and populate it one element at a time.
432            %
433
434            for i = 1:length(endpts)
435                if ~isa(endpts{i}, 'Ice.Endpoint')
436                    throw(MException('Ice:ArgumentException', 'expected an Ice.Endpoint'))
437                end
438            end
439            arr = libpointer('voidPtr');
440            obj.iceCall('ice_createEndpointList', length(endpts), arr);
441            for i = 1:length(endpts)
442                obj.iceCall('ice_setEndpoint', arr, i - 1, endpts{i}.impl_); % C-style index
443            end
444            r = obj.factory_('ice_endpoints', true, arr); % The C function also destroys the temporary array.
445        end
446
447        function r = ice_getLocatorCacheTimeout(obj)
448            % ice_getLocatorCacheTimeout - Returns the locator cache timeout
449            %   of this proxy.
450            %
451            % Returns (int32) - The locator cache timeout value (in seconds).
452
453            obj.instantiate_();
454            r = obj.iceCallWithResult('ice_getLocatorCacheTimeout');
455        end
456
457        function r = ice_locatorCacheTimeout(obj, t)
458            % ice_locatorCacheTimeout - Returns a proxy that is identical to
459            %   this proxy, except for the locator cache timeout.
460            %
461            % Parameters:
462            %   t (int32) - The new locator cache timeout (in seconds).
463            %
464            % Returns - The proxy with the new timeout.
465
466            r = obj.factory_('ice_locatorCacheTimeout', true, t);
467        end
468
469        function r = ice_getInvocationTimeout(obj)
470            % ice_getInvocationTimeout - Returns the invocation timeout of
471            %   this proxy.
472            %
473            % Returns (int32) - The invocation timeout value (in seconds).
474
475            obj.instantiate_();
476            r = obj.iceCallWithResult('ice_getInvocationTimeout');
477        end
478
479        function r = ice_invocationTimeout(obj, t)
480            % ice_invocationTimeout - Returns a proxy that is identical to
481            %   this proxy, except for the invocation timeout.
482            %
483            % Parameters:
484            %   t (int32) - The new invocation timeout (in seconds).
485            %
486            % Returns - The proxy with the new timeout.
487
488            r = obj.factory_('ice_invocationTimeout', true, t);
489        end
490
491        function r = ice_getConnectionId(obj)
492            % ice_getConnectionId - Returns the connection id of this proxy.
493            %
494            % Returns (char) - The connection id.
495
496            obj.instantiate_();
497            r = obj.iceCallWithResult('ice_getConnectionId');
498        end
499
500        function r = ice_connectionId(obj, id)
501            % ice_connectionId - Returns a proxy that is identical to this
502            %   proxy, except for its connection ID.
503            %
504            % Parameters:
505            %   id (char) - The connection ID for the new proxy. An empty
506            %   string removes the connection ID.
507            %
508            % Returns - A proxy with the specified connection ID.
509
510            r = obj.factory_('ice_connectionId', true, id);
511        end
512
513        function r = ice_isConnectionCached(obj)
514            % ice_isConnectionCached - Returns whether this proxy caches
515            %   connections.
516            %
517            % Returns (logical) - True if this proxy caches connections;
518            %   false otherwise.
519
520            r = obj.iceCallWithResult('ice_isConnectionCached');
521        end
522
523        function r = ice_connectionCached(obj, b)
524            % ice_connectionCached - Returns a proxy that is identical to this
525            %   proxy, except for connection caching.
526            %
527            % Parameters:
528            %   b (logical) - True if the new proxy should cache connections;
529            %     false otherwise.
530            %
531            % Returns - The proxy with the specified caching policy.
532
533            if b
534                val = 1;
535            else
536                val = 0;
537            end
538            r = obj.factory_('ice_connectionCached', true, val);
539        end
540
541        function r = ice_getEndpointSelection(obj)
542            % ice_getEndpointSelection - Returns how this proxy selects
543            %   endpoints (randomly or ordered).
544            %
545            % Returns (Ice.EndpointSelectionType) - The endpoint selection
546            %   policy.
547
548            obj.instantiate_();
549            r = Ice.EndpointSelectionType.ice_getValue(obj.iceCallWithResult('ice_getEndpointSelection'));
550        end
551
552        function r = ice_endpointSelection(obj, t)
553            % ice_endpointSelection - Returns a proxy that is identical to
554            %   this proxy, except for the endpoint selection policy.
555            %
556            % Parameters:
557            %   t (Ice.EndpointSelectionType) - The new endpoint selection policy.
558            %
559            % Returns - The proxy with the specified endpoint selection policy.
560
561            r = obj.factory_('ice_endpointSelection', true, t);
562        end
563
564        function r = ice_getEncodingVersion(obj)
565            % ice_getEncodingVersion - Returns the encoding version used to
566            %   marshal requests parameters.
567            %
568            % Returns (Ice.EncodingVersion) - The encoding version.
569
570            r = obj.encoding;
571        end
572
573        function r = ice_encodingVersion(obj, ver)
574            % ice_encodingVersion - Returns a proxy that is identical to this
575            %   proxy, except for the encoding used to marshal parameters.
576            %
577            % Parameters:
578            %   ver (Ice.EncodingVersion) - The encoding version to use to
579            %   marshal request parameters.
580            %
581            % Returns - The proxy with the specified encoding version.
582
583            r = obj.factory_('ice_encodingVersion', true, ver);
584            r.encoding = ver;
585        end
586
587        function r = ice_getRouter(obj)
588            % ice_getRouter - Returns the router for this proxy.
589            %
590            % Returns (Ice.RouterPrx) - The router for the proxy. If no router
591            %   is configured for the proxy, the return value is an empty
592            %   array.
593
594            obj.instantiate_();
595            v = libpointer('voidPtr');
596            obj.iceCall('ice_getRouter', v);
597            if isNull(v)
598                r = [];
599            else
600                r = Ice.RouterPrx(obj.communicator, obj.encoding, v, []);
601            end
602        end
603
604        function r = ice_router(obj, rtr)
605            % ice_router - Returns a proxy that is identical to this proxy,
606            %   except for the router.
607            %
608            % Parameters:
609            %   rtr (Ice.RouterPrx) - The router for the new proxy.
610            %
611            % Returns - The proxy with the specified router.
612
613            if isempty(rtr)
614                impl = libpointer('voidPtr');
615            else
616                impl = rtr.impl_;
617            end
618            r = obj.factory_('ice_router', true, impl);
619        end
620
621        function r = ice_getLocator(obj)
622            % ice_getLocator - Returns the locator for this proxy.
623            %
624            % Returns (Ice.LocatorPrx) - The locator for the proxy. If no
625            %   locator is configured for the proxy, the return value is
626            %   an empty array.
627
628            obj.instantiate_();
629            v = libpointer('voidPtr');
630            obj.iceCall('ice_getLocator', v);
631            if isNull(v)
632                r = [];
633            else
634                r = Ice.LocatorPrx(obj.communicator, obj.encoding, v, []);
635            end
636        end
637
638        function r = ice_locator(obj, loc)
639            % ice_locator - Returns a proxy that is identical to this proxy,
640            %   except for the locator.
641            %
642            % Parameters:
643            %   loc (Ice.LocatorPrx) - The locator for the new proxy.
644            %
645            % Returns - The proxy with the specified locator.
646
647            if isempty(loc)
648                impl = libpointer('voidPtr');
649            else
650                impl = loc.impl_;
651            end
652            r = obj.factory_('ice_locator', true, impl);
653        end
654
655        function r = ice_isSecure(obj)
656            % ice_isSecure - Returns whether this proxy uses only secure
657            %   endpoints.
658            %
659            % Returns (logical) - True if this proxy communicates only via
660            %   secure endpoints; false otherwise.
661
662            r = obj.iceCallWithResult('ice_isSecure');
663        end
664
665        function r = ice_secure(obj, b)
666            % ice_secure - Returns a proxy that is identical to this proxy,
667            %   except for how it selects endpoints.
668            %
669            % Parameters:
670            %   b (logical) - If b is true, only endpoints that use a secure
671            %     transport are used by the new proxy. If b is false, the
672            %     returned proxy uses both secure and insecure endpoints.
673            %
674            % Returns - The proxy with the specified selection policy.
675
676            if b
677                val = 1;
678            else
679                val = 0;
680            end
681            r = obj.factory_('ice_secure', true, val);
682        end
683
684        function r = ice_isPreferSecure(obj)
685            % ice_isPreferSecure - Returns whether this proxy prefers secure
686            %   endpoints.
687            %
688            % Returns (logical) - True if the proxy always attempts to invoke
689            %   via secure endpoints before it attempts to use insecure
690            %   endpoints; false otherwise.
691
692            r = obj.iceCallWithResult('ice_isPreferSecure');
693        end
694
695        function r = ice_preferSecure(obj, b)
696            % ice_preferSecure - Returns a proxy that is identical to this
697            %   proxy, except for its endpoint selection policy.
698            %
699            % Parameters:
700            %   b (logical) - If b is true, the new proxy will use secure
701            %     endpoints for invocations and only use insecure endpoints
702            %     if an invocation cannot be made via secure endpoints.
703            %     If b is false, the proxy prefers insecure endpoints to
704            %     secure ones.
705            %
706            % Returns - The proxy with the specified selection policy.
707
708            if b
709                val = 1;
710            else
711                val = 0;
712            end
713            r = obj.factory_('ice_preferSecure', true, val);
714        end
715
716        function r = ice_isTwoway(obj)
717            % ice_isTwoway - Returns whether this proxy uses twoway invocations.
718            %
719            % Returns (logical) - True if this proxy uses twoway invocations;
720            %   false otherwise.
721
722            r = obj.isTwoway;
723        end
724
725        function r = ice_twoway(obj)
726            % ice_twoway - Returns a proxy that is identical to this proxy,
727            %   but uses twoway invocations.
728            %
729            % Returns - A proxy that uses twoway invocations.
730
731            r = obj.factory_('ice_twoway', true);
732        end
733
734        function r = ice_isOneway(obj)
735            % ice_isOneway - Returns whether this proxy uses oneway invocations.
736            %
737            % Returns (logical) - True if this proxy uses oneway invocations;
738            %   false otherwise.
739
740            r = obj.iceCallWithResult('ice_isOneway');
741        end
742
743        function r = ice_oneway(obj)
744            % ice_oneway - Returns a proxy that is identical to this proxy,
745            %   but uses oneway invocations.
746            %
747            % Returns - A proxy that uses oneway invocations.
748
749            r = obj.factory_('ice_oneway', true);
750        end
751
752        function r = ice_isBatchOneway(obj)
753            % ice_isBatchOneway - Returns whether this proxy uses batch oneway
754            %   invocations.
755            %
756            % Returns (logical) - True if this proxy uses batch oneway
757            %   invocations; false otherwise.
758
759            r = obj.iceCallWithResult('ice_isBatchOneway');
760        end
761
762        function r = ice_batchOneway(obj)
763            % ice_batchOneway - Returns a proxy that is identical to this
764            %   proxy, but uses batch oneway invocations.
765            %
766            % Returns - A new proxy that uses batch oneway invocations.
767
768            r = obj.factory_('ice_batchOneway', true);
769        end
770
771        function r = ice_isDatagram(obj)
772            % ice_isDatagram - Returns whether this proxy uses datagram
773            %   invocations.
774            %
775            % Returns (logical) - True if this proxy uses datagram invocations;
776            %   false otherwise.
777
778            r = obj.iceCallWithResult('ice_isDatagram');
779        end
780
781        function r = ice_datagram(obj)
782            % ice_datagram - Returns a proxy that is identical to this proxy,
783            %   but uses datagram invocations.
784            %
785            % Returns - A new proxy that uses datagram invocations.
786
787            r = obj.factory_('ice_datagram', true);
788        end
789
790        function r = ice_isBatchDatagram(obj)
791            % ice_isBatchDatagram - Returns whether this proxy uses batch
792            %   datagram invocations.
793            %
794            % Returns (logical) - True if this proxy uses batch datagram
795            %   invocations; false otherwise.
796
797            r = obj.iceCallWithResult('ice_isBatchDatagram');
798        end
799
800        function r = ice_batchDatagram(obj)
801            % ice_batchDatagram - Returns a proxy that is identical to this
802            %   proxy, but uses batch datagram invocations.
803            %
804            % Returns - A new proxy that uses batch datagram invocations.
805
806            r = obj.factory_('ice_batchDatagram', true);
807        end
808
809        function r = ice_compress(obj, b)
810            % ice_compress - Returns a proxy that is identical to this proxy,
811            %   except for compression.
812            %
813            % Parameters:
814            %   b (logical) - True enables compression for the new proxy;
815            %     false disables compression.
816            %
817            % Returns - A proxy with the specified compression override setting.
818
819            if b
820                val = 1;
821            else
822                val = 0;
823            end
824            r = obj.factory_('ice_compress', true, val);
825        end
826
827        function r = ice_getCompress(obj)
828            % ice_getCompress - Obtains the compression override setting of this proxy.
829            %
830            % Returns (optional bool) - The compression override setting. If Ice.Unset
831            %   is returned, no override is set. Otherwise, true if compression is
832            %   enabled, false otherwise.
833
834            obj.instantiate_();
835            opt = obj.iceCallWithResult('ice_getCompress');
836            if opt.hasValue
837                r = opt.value;
838            else
839                r = Ice.Unset;
840            end
841        end
842
843        function r = ice_timeout(obj, t)
844            % ice_timeout - Returns a proxy that is identical to this proxy,
845            %   except for its connection timeout setting which overrides the timeout
846            %   setting from the proxy endpoints.
847            %
848            % Parameters:
849            %   t (int32) - The connection override timeout for the proxy in
850            %     milliseconds.
851            %
852            % Returns - A proxy with the specified timeout.
853
854            r = obj.factory_('ice_timeout', true, t);
855        end
856
857        function r = ice_getTimeout(obj)
858            % ice_getTimeout - Obtains the timeout override of this proxy.
859            %
860            % Returns (optional int32) - The timeout override. If Ice.Unset
861            %   is returned, no override is set. Otherwise, returns the
862            %   timeout override value.
863
864            obj.instantiate_();
865            opt = obj.iceCallWithResult('ice_getTimeout');
866            if opt.hasValue
867                r = opt.value;
868            else
869                r = Ice.Unset;
870            end
871        end
872
873        function r = ice_fixed(obj, connection)
874            % ice_fixed - Obtains a proxy that is identical to this proxy, except it's
875            %   a fixed proxy bound to the given connection.
876            %
877            % Parameters:
878            %   connection (Ice.Connection) - The fixed proxy connection.
879            %
880            % Returns (Ice.ObjectPrx) - A fixed proxy bound to the given connection.
881
882            if isempty(connection)
883                throw(MException('Ice:ArgumentException', 'invalid null connection passed to ice_fixed'));
884            end
885
886            r = obj.factory_('ice_fixed', true, connection.iceGetImpl());
887        end
888
889        function r = ice_getConnection(obj)
890            % ice_getConnection - Returns the Connection for this proxy. If the
891            %   proxy does not yet have an established connection, it first
892            %   attempts to create a connection.
893            %
894            % Returns (Ice.Connection) - The Connection for this proxy.
895
896            obj.instantiate_();
897            v = libpointer('voidPtr');
898            obj.iceCall('ice_getConnection', v);
899            if isNull(v)
900                r = [];
901            else
902                r = Ice.Connection(v, obj.communicator);
903            end
904        end
905
906        function r = ice_getConnectionAsync(obj)
907            % ice_getConnectionAsync - Returns the Connection for this proxy.
908            %   If the proxy does not yet have an established connection, it
909            %   first attempts to create a connection.
910            %
911            % Returns (Ice.Future) - A future that will be completed when the
912            %   invocation completes.
913
914            obj.instantiate_();
915            future = libpointer('voidPtr');
916            obj.iceCall('ice_getConnectionAsync', future);
917            assert(~isNull(future));
918            function varargout = fetch(f)
919                con = libpointer('voidPtr', 0); % Output param
920                f.iceCall('fetch', con);
921                assert(~isNull(con));
922                varargout{1} = Ice.Connection(con);
923            end
924            r = Ice.Future(future, 'ice_getConnection', 1, 'Ice_GetConnectionFuture', @fetch);
925        end
926
927        function r = ice_getCachedConnection(obj)
928            % ice_getCachedConnection - Returns the cached Connection for this
929            %   proxy. If the proxy does not yet have an established
930            %   connection, it does not attempt to create a connection.
931            %
932            % Returns (Ice.Connection) - The cached Connection for this proxy,
933            %   or an empty array if the proxy does not have an established
934            %   connection.
935
936            obj.instantiate_();
937            v = libpointer('voidPtr');
938            obj.iceCall('ice_getCachedConnection', v);
939            if isNull(v)
940                r = [];
941            else
942                r = Ice.Connection(v, obj.communicator);
943            end
944        end
945
946        function ice_flushBatchRequests(obj)
947            % ice_flushBatchRequests - Flushes any pending batched requests for
948            %   this communicator. The call blocks until the flush is complete.
949
950            obj.instantiate_();
951            obj.iceCall('ice_flushBatchRequests');
952        end
953
954        function r = ice_flushBatchRequestsAsync(obj)
955            % ice_flushBatchRequestsAsync - Flushes any pending batched
956            %   requests for this communicator. The call blocks until the
957            %   flush is complete.
958            %
959            % Returns (Ice.Future) - A future that will be completed when the
960            %   invocation completes.
961
962            obj.instantiate_();
963            future = libpointer('voidPtr');
964            obj.iceCall('ice_flushBatchRequestsAsync', future);
965            assert(~isNull(future));
966            r = Ice.Future(future, 'ice_flushBatchRequests', 0, 'Ice_SimpleFuture', @(fut) fut.iceCall('check'));
967        end
968    end
969
970    methods(Hidden=true)
971        function iceWrite(obj, os, encoding)
972            %
973            % If we don't yet have a byte buffer representing the marshaled form of the proxy, then call into
974            % C++ to marshal the proxy and then cache the bytes.
975            %
976            if isempty(obj.bytes)
977                obj.bytes = obj.iceCallWithResult('write', obj.communicator.impl_, encoding);
978            end
979            os.writeBlob(obj.bytes);
980        end
981        function r = iceGetImpl(obj)
982            obj.instantiate_();
983            r = obj.impl_;
984        end
985    end
986
987    methods(Access=protected)
988        function os = iceStartWriteParams(obj, format)
989            os = obj.ice_createOutputStream();
990            os.startEncapsulation(format);
991        end
992
993        function iceEndWriteParams(obj, os)
994            os.endEncapsulation();
995        end
996
997        function is = iceInvoke(obj, op, mode, twowayOnly, os, hasOutParams, exceptions, varargin)
998            if isempty(obj.impl_)
999                obj.instantiate_();
1000            end
1001
1002            try
1003                % Vararg accepted for optional context argument.
1004                if length(varargin) > 1
1005                    throw(MException('Ice:ArgumentException', 'one optional argument is allowed for request context'))
1006                end
1007
1008                if twowayOnly && ~obj.isTwoway
1009                    throw(Ice.TwowayOnlyException('', 'invocation requires twoway proxy', op));
1010                end
1011
1012                if isempty(os)
1013                    buf = [];
1014                    size = 0;
1015                else
1016                    buf = os.buf.buf;
1017                    size = os.buf.size;
1018                end
1019
1020                if length(varargin) == 1
1021                    %
1022                    % Avoid the string concatenation
1023                    %
1024                    % res = obj.iceCallWithResult('ice_invoke', op, mode, buf, size, varargin{1});
1025                    %
1026                    res = IceInternal.Util.callWithResult('Ice_ObjectPrx_ice_invoke', obj.impl_, op, mode, buf, ...
1027                                                          size, varargin{1});
1028                else
1029                    %
1030                    % Avoid the string concatenation
1031                    %
1032                    % res = obj.iceCallWithResult('ice_invokeNC', op, mode, buf, size);
1033                    %
1034                    res = IceInternal.Util.callWithResult('Ice_ObjectPrx_ice_invokeNC', obj.impl_, op, mode, buf, size);
1035                end
1036
1037                is = [];
1038                if ~isempty(res.params)
1039                    if isempty(obj.cachedInputStream)
1040                        is = Ice.InputStream(obj.communicator, obj.encoding, IceInternal.Buffer(res.params));
1041                        obj.cachedInputStream = is;
1042                    else
1043                        is = obj.cachedInputStream;
1044                        is.reset(res.params);
1045                    end
1046                end
1047
1048                if obj.isTwoway
1049                    if ~res.ok
1050                        obj.iceThrowUserException(is, exceptions{:});
1051                    elseif ~hasOutParams
1052                        is.skipEmptyEncapsulation();
1053                    end
1054                end
1055            catch ex
1056                ex.throwAsCaller();
1057            end
1058        end
1059
1060        function fut = iceInvokeAsync(obj, op, mode, twowayOnly, os, numOutArgs, unmarshalFunc, exceptions, varargin)
1061            if isempty(obj.impl_)
1062                obj.instantiate_();
1063            end
1064
1065            isTwoway = obj.isTwoway;
1066
1067            % This nested function is invoked by Future.fetchOutputs()
1068            function varargout = fetch(f)
1069                try
1070                    if isTwoway
1071                        %
1072                        % Call 'results' to obtain a boolean indicating whether the request completed successfully
1073                        % or returned a user exception, and the encoded out parameters. The function can also raise
1074                        % a local exception if necessary.
1075                        %
1076                        % Avoid the string concatenation
1077                        %
1078                        % res = f.iceCallWithResult('results');
1079                        %
1080                        res = IceInternal.Util.callWithResult('Ice_InvocationFuture_results', f.impl_);
1081                        is = Ice.InputStream(obj.communicator, obj.encoding, IceInternal.Buffer(res.params));
1082                        if ~res.ok
1083                            obj.iceThrowUserException(is, exceptions{:});
1084                        end
1085                        if isempty(unmarshalFunc)
1086                            is.skipEmptyEncapsulation();
1087                        else
1088                            [varargout{1:numOutArgs}] = unmarshalFunc(is);
1089                        end
1090                    else
1091                        %
1092                        % Check for a local exception.
1093                        %
1094                        % Avoid the string concatenation
1095                        %
1096                        % f.iceCall('check');
1097                        %
1098                        IceInternal.Util.call('Ice_InvocationFuture_check', f.impl_);
1099                    end
1100                catch ex
1101                    ex.throwAsCaller();
1102                end
1103            end
1104
1105            try
1106                % Vararg accepted for optional context argument.
1107                if length(varargin) > 1
1108                    throw(MException('Ice:ArgumentException', 'one optional argument is allowed for request context'))
1109                end
1110                if twowayOnly && ~isTwoway
1111                    throw(Ice.TwowayOnlyException('', 'invocation requires twoway proxy', op));
1112                end
1113                if isempty(os)
1114                    buf = [];
1115                    size = 0;
1116                else
1117                    buf = os.buf.buf;
1118                    size = os.buf.size;
1119                end
1120                futPtr = libpointer('voidPtr'); % Output param
1121                if length(varargin) == 1
1122                    %
1123                    % Avoid the string concatenation
1124                    %
1125                    % obj.iceCall('ice_invokeAsync', op, mode, buf, size, varargin{1}, futPtr);
1126                    %
1127                    IceInternal.Util.call('Ice_ObjectPrx_ice_invokeAsync', obj.impl_, op, mode, buf, size, ...
1128                                          varargin{1}, futPtr);
1129                else
1130                    %
1131                    % Avoid the string concatenation
1132                    %
1133                    % obj.iceCall('ice_invokeAsyncNC', op, mode, buf, size, futPtr);
1134                    %
1135                    IceInternal.Util.call('Ice_ObjectPrx_ice_invokeAsyncNC', obj.impl_, op, mode, buf, size, futPtr);
1136                end
1137                assert(~isNull(futPtr));
1138                fut = Ice.Future(futPtr, op, numOutArgs, 'Ice_InvocationFuture', @fetch);
1139            catch ex
1140                ex.throwAsCaller();
1141            end
1142        end
1143
1144        function iceThrowUserException(obj, is, varargin) % Varargs are user exception type names
1145            try
1146                is.startEncapsulation();
1147                is.throwException();
1148            catch ex
1149                if isa(ex, 'Ice.UserException')
1150                    is.endEncapsulation();
1151                    for i = 1:length(varargin)
1152                        if isa(ex, varargin{i})
1153                            ex.throwAsCaller();
1154                        end
1155                    end
1156                    uue = Ice.UnknownUserException('', '', ex.ice_id());
1157                    uue.throwAsCaller();
1158                else
1159                    rethrow(ex);
1160                end
1161            end
1162        end
1163    end
1164
1165    methods(Static)
1166        function r = ice_staticId()
1167            r = '::Ice::Object';
1168        end
1169
1170        function r = checkedCast(p, varargin)
1171            if length(varargin) == 0
1172                r = p;
1173            else
1174                r = Ice.ObjectPrx.iceCheckedCast(p, Ice.ObjectPrx.ice_staticId(), 'Ice.ObjectPrx', varargin{:});
1175            end
1176        end
1177
1178        function r = uncheckedCast(p, varargin)
1179            if length(varargin) == 0
1180                r = p;
1181            elseif length(varargin) == 1
1182                if ~isempty(p)
1183                    r = p.ice_facet(varargin{1});
1184                else
1185                    r = p;
1186                end
1187            else
1188                throw(MException('Ice:ArgumentException', 'too many arguments to uncheckedCast'));
1189            end
1190        end
1191    end
1192
1193    methods(Static,Access=protected)
1194        function r = iceCheckedCast(p, id, cls, varargin)
1195            try
1196                hasFacet = false;
1197                facet = [];
1198                context = {};
1199                if length(varargin) == 1
1200                    if isa(varargin{1}, 'containers.Map')
1201                        context = { varargin{1} };
1202                    elseif isempty(varargin{1}) || isa(varargin{1}, 'char')
1203                        hasFacet = true;
1204                        facet = varargin{1};
1205                    else
1206                        throw(MException('Ice:ArgumentException', 'expecting string or containers.Map'));
1207                    end
1208                elseif length(varargin) == 2
1209                    hasFacet = true;
1210                    facet = varargin{1};
1211                    context = { varargin{2} };
1212                elseif length(varargin) > 2
1213                    throw(MException('Ice:ArgumentException', 'too many arguments to checkedCast'));
1214                end
1215                if ~isempty(p)
1216                    if hasFacet
1217                        p = p.ice_facet(facet);
1218                    end
1219                    if isa(p, cls)
1220                        r = p;
1221                    elseif p.ice_isA(id, context{:})
1222                        constructor = str2func(cls);
1223                        r = constructor(p.communicator, p.encoding, p.clone_(), []);
1224                    else
1225                        r = [];
1226                    end
1227                else
1228                    r = p;
1229                end
1230            catch ex
1231                ex.throwAsCaller();
1232            end
1233        end
1234
1235        function r = iceUncheckedCast(p, cls, varargin)
1236            hasFacet = false;
1237            facet = [];
1238            if length(varargin) == 1
1239                hasFacet = true;
1240                facet = varargin{1};
1241            elseif length(varargin) > 1
1242                throw(MException('Ice:ArgumentException', 'too many arguments to uncheckedCast'));
1243            end
1244            if ~isempty(p)
1245                if hasFacet
1246                    p = p.ice_facet(facet);
1247                end
1248                if isa(p, cls)
1249                    r = p;
1250                else
1251                    constructor = str2func(cls);
1252                    r = constructor(p.communicator, p.encoding, p.clone_(), []);
1253                end
1254            else
1255                r = p;
1256            end
1257        end
1258    end
1259
1260    methods(Access=private)
1261        function instantiate_(obj)
1262            %
1263            % An unmarshaled proxy delays the creation of its corresponding C++ object until the application
1264            % needs it. To obtain the C++ object, we unmarshal it (again) by calling into C++ to extract it
1265            % from the byte buffer that contains the proxy's marshaled form.
1266            %
1267            if isempty(obj.impl_)
1268                assert(~isempty(obj.bytes));
1269                %
1270                % Call into C++ to construct a proxy. We pass the data buffer and start position (adjusted for
1271                % C-style pointers), along with the size of the entire buffer. The C++ implementation reads what
1272                % it needs and returns the new proxy object as well as number of bytes it consumed.
1273                %
1274                impl = libpointer('voidPtr');
1275                start = 0; % Starting position for a C-style pointer.
1276                IceInternal.Util.call('Ice_ObjectPrx_read', obj.communicator.impl_, obj.encoding, obj.bytes, ...
1277                                      start, length(obj.bytes), impl);
1278                obj.impl_ = impl;
1279
1280                % Cache the twoway status
1281                obj.isTwoway = obj.iceCallWithResult('ice_isTwoway');
1282            end
1283        end
1284
1285        function r = factory_(obj, op, keepType, varargin)
1286            %
1287            % Call a C++ proxy factory function. The function returns nil if the call results in no change to the
1288            % proxy, in which case we can return the current object.
1289            %
1290
1291            obj.instantiate_();
1292
1293            newImpl = libpointer('voidPtr');
1294            obj.iceCall(op, newImpl, varargin{:});
1295            if isNull(newImpl)
1296                r = obj;
1297            elseif keepType
1298                r = obj.newInstance_(newImpl); % Retain the proxy's current type.
1299            else
1300                %
1301                % We don't retain the proxy's existing type for a couple of factory functions.
1302                %
1303                r = Ice.ObjectPrx(obj.communicator, obj.encoding, newImpl);
1304            end
1305        end
1306
1307        function r = newInstance_(obj, impl)
1308            %
1309            % Return a new instance of this proxy type.
1310            %
1311            constructor = str2func(class(obj)); % Obtain the constructor for this class
1312            r = constructor(obj.communicator, obj.encoding, impl, []); % Call the constructor
1313        end
1314
1315        function r = clone_(obj)
1316            %
1317            % Clone the C++ reference for use by a new instance of ObjectPrx.
1318            %
1319            obj.instantiate_();
1320            implPtr = libpointer('voidPtr'); % Output param
1321            obj.iceCall('clone', implPtr);
1322            r = implPtr;
1323        end
1324    end
1325
1326    properties(Access=private)
1327        communicator % The communicator wrapper
1328        encoding
1329        isTwoway
1330        cachedInputStream % Only used for synchronous invocations
1331        bytes
1332    end
1333end
1334