summaryrefslogtreecommitdiff
path: root/cpp/include/Ice/AsyncResult.h
blob: 17d57f99273aa0d0af5382ad9cd9b80e67caf7fe (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
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_ASYNC_RESULT_H
#define ICE_ASYNC_RESULT_H

#ifndef ICE_CPP11_MAPPING

#include <IceUtil/Monitor.h>
#include <IceUtil/Mutex.h>
#include <Ice/LocalObject.h>
#include <Ice/CommunicatorF.h>
#include <Ice/ConnectionF.h>
#include <Ice/ProxyF.h>
#include <Ice/AsyncResultF.h>

namespace Ice
{

/**
 * Represents the result of an asynchronous invocation using the C++98 mapping.
 * \headerfile Ice/Ice.h
 */
class ICE_API AsyncResult : private IceUtil::noncopyable, public Ice::LocalObject
{
public:

    virtual ~AsyncResult();

    /**
     * Prevents a queued invocation from being sent or, if the invocation has already been sent,
     * ignores a reply if the server sends one. cancel is a local operation and has no effect
     * on the server. A canceled invocation is considered to be completed, meaning isCompleted
     * returns true, and the result of the invocation is an InvocationCanceledException.
     */
    virtual void cancel() = 0;

    /**
     * Allows you to create ordered or hashed collections of pending asynchronous invocations.
     * @return A unique hash code for this object.
     */
    virtual Int getHash() const = 0;

    /**
     * Obtains the communicator that sent the invocation.
     * @return A reference to the communicator.
     */
    virtual CommunicatorPtr getCommunicator() const = 0;

    /**
     * Obtains the connection that was used for the invocation. Note that, for typical asynchronous
     * proxy invocations, this method returns a nil value because the possibility of automatic retries
     * means the connection that is currently in use could change unexpectedly. The getConnection
     * method only returns a non-nil value when the AsyncResult object is obtained by calling
     * Connection::begin_flushBatchRequests.
     * @return A reference to the connection.
     */
    virtual ConnectionPtr getConnection() const = 0;

    /**
     * Obtains the proxy that was used to call the begin_ method, or nil if the AsyncResult object was
     * not obtained via an asynchronous proxy invocation.
     * @return A reference to the proxy.
     */
    virtual ObjectPrxPtr getProxy() const = 0;

    /**
     * Obtains the completion status of the invocation.
     * @return True if, at the time it is called, the result of an invocation is available, indicating
     * that a call to the end_ method will not block the caller. Otherwise, if the result is not yet
     * available, the method returns false.
     */
    virtual bool isCompleted() const = 0;

    /**
     * Blocks the caller until the result of an invocation becomes available.
     */
    virtual void waitForCompleted() = 0;

    /**
     * Obtains the sent status of the invocation.
     * @return True if, at the time it is called, the request has been written to the local transport
     * (whether it was initially queued or not). Otherwise, if the request is still queued or an
     * exception occurred before the request could be sent, this method returns false.
     */
    virtual bool isSent() const = 0;

    /**
     * Blocks the calling thread until a request has been written to the client-side transport,
     * or an exception occurs.
     */
    virtual void waitForSent() = 0;

    /**
     * Throws the local exception that caused the invocation to fail. If no exception has occurred yet,
     * this method does nothing.
     */
    virtual void throwLocalException() const = 0;

    /**
     * Determines whether the request was sent synchronously.
     * @return True if a request was written to the client-side transport without first being queued.
     * If the request was initially queued, sentSynchronously returns false (independent of whether
     * the request is still in the queue or has since been written to the client-side transport).
     */
    virtual bool sentSynchronously() const = 0;

    /**
     * Obtains the cookie that was passed to the begin_ method.
     * @return The cookie, or nil if you did not pass a cookie to the begin_ method.
     */
    virtual LocalObjectPtr getCookie() const = 0;

    /**
     * Obtains the name of the operation.
     * @return The operation name.
     */
    virtual const std::string& getOperation() const = 0;

    /// \cond INTERNAL
    virtual bool _waitForResponse() = 0;
    virtual Ice::InputStream* _startReadParams() = 0;
    virtual void _endReadParams() = 0;
    virtual void _readEmptyParams() = 0;
    virtual void _readParamEncaps(const ::Ice::Byte*&, ::Ice::Int&) = 0;
    virtual void _throwUserException() = 0;

    static void _check(const AsyncResultPtr&, const ::IceProxy::Ice::Object*, const ::std::string&);
    static void _check(const AsyncResultPtr&, const Connection*, const ::std::string&);
    static void _check(const AsyncResultPtr&, const Communicator*, const ::std::string&);

    class Callback : public IceUtil::Shared
    {
    public:

        virtual void run() = 0;
    };
    typedef IceUtil::Handle<Callback> CallbackPtr;

    virtual void _scheduleCallback(const CallbackPtr&) = 0;
    /// \endcond

protected:

    /// \cond INTERNAL
    static void check(const AsyncResultPtr&, const ::std::string&);
    /// \endcond
};

}

#endif

#endif