@@ -52,34 +52,35 @@ class FutureApiInterface {
52
52
53
53
// / Increment the reference count on handle's asynchronous call.
54
54
// / Called when the Future is copied.
55
- virtual void ReferenceFuture (FutureHandle handle) = 0;
55
+ virtual void ReferenceFuture (const FutureHandle& handle) = 0;
56
56
57
57
// / Decrement the reference count on handle's asynchronous call.
58
58
// / Called when the Future is destroyed or moved.
59
59
// / If the reference count drops to zero, the asynchronous call can be
60
60
// / forgotten.
61
- virtual void ReleaseFuture (FutureHandle handle) = 0;
61
+ virtual void ReleaseFuture (const FutureHandle& handle) = 0;
62
62
63
63
// / Return the status of the asynchronous call.
64
- virtual FutureStatus GetFutureStatus (FutureHandle handle) const = 0;
64
+ virtual FutureStatus GetFutureStatus (const FutureHandle& handle) const = 0;
65
65
66
66
// / Return the API-specific error.
67
67
// / Valid when GetFutureStatus() is kFutureStatusComplete, and undefined
68
68
// / otherwise.
69
- virtual int GetFutureError (FutureHandle handle) const = 0;
69
+ virtual int GetFutureError (const FutureHandle& handle) const = 0;
70
70
71
71
// / Return the API-specific error, in human-readable form, or "" if no message
72
72
// / has been provided.
73
73
// / Valid when GetFutureStatus() is kFutureStatusComplete, and undefined
74
74
// / otherwise.
75
- virtual const char * GetFutureErrorMessage (FutureHandle handle) const = 0;
75
+ virtual const char * GetFutureErrorMessage (
76
+ const FutureHandle& handle) const = 0;
76
77
77
78
// / Return a pointer to the completed asynchronous result, or NULL if
78
79
// / result is still pending.
79
80
// / After an asynchronous call is marked complete, the API should not
80
81
// / modify the result (especially on a callback thread), since the threads
81
82
// / owning the Future can reference the result memory via this function.
82
- virtual const void * GetFutureResult (FutureHandle handle) const = 0;
83
+ virtual const void * GetFutureResult (const FutureHandle& handle) const = 0;
83
84
84
85
// / Register a callback that will be called when this future's status is set
85
86
// / to Complete. If clear_existing_callbacks is true, then the new callback
@@ -92,16 +93,14 @@ class FutureApiInterface {
92
93
// / After the callback has been called, if `user_data_delete_fn_ptr` is
93
94
// / non-null, then `(*user_data_delete_fn_ptr)(user_data)` will be called.
94
95
virtual CompletionCallbackHandle AddCompletionCallback (
95
- FutureHandle handle, FutureBase::CompletionCallback callback,
96
- void * user_data,
97
- void (* user_data_delete_fn)(void *),
96
+ const FutureHandle& handle, FutureBase::CompletionCallback callback,
97
+ void * user_data, void (*user_data_delete_fn)(void *),
98
98
bool clear_existing_callbacks) = 0;
99
99
100
100
// / Unregister a callback that was previously registered with
101
101
// / `AddCompletionCallback`.
102
102
virtual void RemoveCompletionCallback (
103
- FutureHandle handle,
104
- CompletionCallbackHandle callback_handle) = 0;
103
+ const FutureHandle& handle, CompletionCallbackHandle callback_handle) = 0;
105
104
106
105
#if defined(FIREBASE_USE_STD_FUNCTION)
107
106
// / Register a callback that will be called when this future's status is set
@@ -116,7 +115,8 @@ class FutureApiInterface {
116
115
// /
117
116
// / @return A handle that can be passed to `FutureBase::RemoveCompletion`.
118
117
virtual CompletionCallbackHandle AddCompletionCallbackLambda (
119
- FutureHandle handle, std::function<void (const FutureBase&)> callback,
118
+ const FutureHandle& handle,
119
+ std::function<void (const FutureBase&)> callback,
120
120
bool clear_existing_callbacks) = 0;
121
121
#endif // defined(FIREBASE_USE_STD_FUNCTION)
122
122
@@ -143,37 +143,36 @@ class CompletionCallbackHandle {
143
143
public:
144
144
// Construct a null CompletionCallbackHandle.
145
145
CompletionCallbackHandle ()
146
- : callback_(nullptr ), user_data_(nullptr ),
147
- user_data_delete_fn_ (nullptr ) {}
146
+ : callback_(nullptr ),
147
+ user_data_ (nullptr ),
148
+ user_data_delete_fn_(nullptr ) {}
149
+
148
150
private:
149
151
friend class ::FIREBASE_NAMESPACE::FutureBase;
150
152
friend class ::FIREBASE_NAMESPACE::ReferenceCountedFutureImpl;
151
- CompletionCallbackHandle (
152
- FutureBase::CompletionCallback callback,
153
- void * user_data,
154
- void (* user_data_delete_fn)(void *))
155
- : callback_(callback), user_data_(user_data),
156
- user_data_delete_fn_(user_data_delete_fn) {}
153
+ CompletionCallbackHandle (FutureBase::CompletionCallback callback,
154
+ void * user_data, void (*user_data_delete_fn)(void *))
155
+ : callback_(callback),
156
+ user_data_(user_data),
157
+ user_data_delete_fn_(user_data_delete_fn) {}
157
158
158
159
FutureBase::CompletionCallback callback_;
159
160
void * user_data_;
160
- void (* user_data_delete_fn_)(void *);
161
+ void (*user_data_delete_fn_)(void *);
161
162
};
162
163
163
164
} // namespace detail
164
165
165
166
template <class T >
166
- void
167
- Future<T>::OnCompletion(
168
- TypedCompletionCallback callback, void * user_data) const {
169
- FutureBase::OnCompletion (
170
- reinterpret_cast <CompletionCallback>(callback), user_data);
167
+ void Future<T>::OnCompletion(TypedCompletionCallback callback,
168
+ void * user_data) const {
169
+ FutureBase::OnCompletion (reinterpret_cast <CompletionCallback>(callback),
170
+ user_data);
171
171
}
172
172
173
173
#if defined(FIREBASE_USE_STD_FUNCTION)
174
174
template <class ResultType >
175
- inline void
176
- Future<ResultType>::OnCompletion(
175
+ inline void Future<ResultType>::OnCompletion(
177
176
std::function<void (const Future<ResultType>&)> callback) const {
178
177
FutureBase::OnCompletion (
179
178
*reinterpret_cast <std::function<void (const FutureBase&)>*>(&callback));
@@ -182,17 +181,15 @@ Future<ResultType>::OnCompletion(
182
181
183
182
#if defined(INTERNAL_EXPERIMENTAL)
184
183
template <class T >
185
- FutureBase::CompletionCallbackHandle
186
- Future<T>::AddOnCompletion(
184
+ FutureBase::CompletionCallbackHandle Future<T>::AddOnCompletion(
187
185
TypedCompletionCallback callback, void * user_data) const {
188
186
return FutureBase::AddOnCompletion (
189
187
reinterpret_cast <CompletionCallback>(callback), user_data);
190
188
}
191
189
192
190
#if defined(FIREBASE_USE_STD_FUNCTION)
193
191
template <class ResultType >
194
- inline FutureBase::CompletionCallbackHandle
195
- Future<ResultType>::AddOnCompletion(
192
+ inline FutureBase::CompletionCallbackHandle Future<ResultType>::AddOnCompletion(
196
193
std::function<void (const Future<ResultType>&)> callback) const {
197
194
return FutureBase::AddOnCompletion (
198
195
*reinterpret_cast <std::function<void (const FutureBase&)>*>(&callback));
@@ -204,7 +201,7 @@ Future<ResultType>::AddOnCompletion(
204
201
inline FutureBase::FutureBase () : api_(NULL ), handle_(0 ) {} // NOLINT
205
202
206
203
inline FutureBase::FutureBase (detail::FutureApiInterface* api,
207
- FutureHandle handle)
204
+ const FutureHandle& handle)
208
205
: api_(api), handle_(handle) {
209
206
api_->ReferenceFuture (handle_);
210
207
detail::RegisterForCleanup (api_, this );
@@ -280,17 +277,16 @@ inline void FutureBase::OnCompletion(CompletionCallback callback,
280
277
void * user_data) const {
281
278
if (api_ != NULL ) { // NOLINT
282
279
api_->AddCompletionCallback (handle_, callback, user_data, nullptr ,
283
- /* clear_existing_callbacks=*/ true );
280
+ /* clear_existing_callbacks=*/ true );
284
281
}
285
282
}
286
283
287
284
#if defined(INTERNAL_EXPERIMENTAL)
288
- inline FutureBase::CompletionCallbackHandle
289
- FutureBase::AddOnCompletion (CompletionCallback callback,
290
- void * user_data) const {
285
+ inline FutureBase::CompletionCallbackHandle FutureBase::AddOnCompletion (
286
+ CompletionCallback callback, void * user_data) const {
291
287
if (api_ != NULL ) { // NOLINT
292
288
return api_->AddCompletionCallback (handle_, callback, user_data, nullptr ,
293
- /* clear_existing_callbacks=*/ false );
289
+ /* clear_existing_callbacks=*/ false );
294
290
}
295
291
return CompletionCallbackHandle ();
296
292
}
@@ -308,16 +304,17 @@ inline void FutureBase::OnCompletion(
308
304
std::function<void (const FutureBase&)> callback) const {
309
305
if (api_ != NULL ) { // NOLINT
310
306
api_->AddCompletionCallbackLambda (handle_, callback,
311
- /* clear_existing_callbacks=*/ true );
307
+ /* clear_existing_callbacks=*/ true );
312
308
}
313
309
}
314
310
315
311
#if defined(INTERNAL_EXPERIMENTAL)
316
312
inline FutureBase::CompletionCallbackHandle FutureBase::AddOnCompletion (
317
313
std::function<void (const FutureBase&)> callback) const {
318
314
if (api_ != NULL ) { // NOLINT
319
- return api_->AddCompletionCallbackLambda (handle_, callback,
320
- /* clear_existing_callbacks=*/ false );
315
+ return api_->AddCompletionCallbackLambda (
316
+ handle_, callback,
317
+ /* clear_existing_callbacks=*/ false );
321
318
}
322
319
return CompletionCallbackHandle ();
323
320
}
0 commit comments