@@ -52,34 +52,35 @@ class FutureApiInterface {
5252
5353 // / Increment the reference count on handle's asynchronous call.
5454 // / Called when the Future is copied.
55- virtual void ReferenceFuture (FutureHandle handle) = 0;
55+ virtual void ReferenceFuture (const FutureHandle& handle) = 0;
5656
5757 // / Decrement the reference count on handle's asynchronous call.
5858 // / Called when the Future is destroyed or moved.
5959 // / If the reference count drops to zero, the asynchronous call can be
6060 // / forgotten.
61- virtual void ReleaseFuture (FutureHandle handle) = 0;
61+ virtual void ReleaseFuture (const FutureHandle& handle) = 0;
6262
6363 // / Return the status of the asynchronous call.
64- virtual FutureStatus GetFutureStatus (FutureHandle handle) const = 0;
64+ virtual FutureStatus GetFutureStatus (const FutureHandle& handle) const = 0;
6565
6666 // / Return the API-specific error.
6767 // / Valid when GetFutureStatus() is kFutureStatusComplete, and undefined
6868 // / otherwise.
69- virtual int GetFutureError (FutureHandle handle) const = 0;
69+ virtual int GetFutureError (const FutureHandle& handle) const = 0;
7070
7171 // / Return the API-specific error, in human-readable form, or "" if no message
7272 // / has been provided.
7373 // / Valid when GetFutureStatus() is kFutureStatusComplete, and undefined
7474 // / otherwise.
75- virtual const char * GetFutureErrorMessage (FutureHandle handle) const = 0;
75+ virtual const char * GetFutureErrorMessage (
76+ const FutureHandle& handle) const = 0;
7677
7778 // / Return a pointer to the completed asynchronous result, or NULL if
7879 // / result is still pending.
7980 // / After an asynchronous call is marked complete, the API should not
8081 // / modify the result (especially on a callback thread), since the threads
8182 // / 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;
8384
8485 // / Register a callback that will be called when this future's status is set
8586 // / to Complete. If clear_existing_callbacks is true, then the new callback
@@ -92,16 +93,14 @@ class FutureApiInterface {
9293 // / After the callback has been called, if `user_data_delete_fn_ptr` is
9394 // / non-null, then `(*user_data_delete_fn_ptr)(user_data)` will be called.
9495 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 *),
9898 bool clear_existing_callbacks) = 0;
9999
100100 // / Unregister a callback that was previously registered with
101101 // / `AddCompletionCallback`.
102102 virtual void RemoveCompletionCallback (
103- FutureHandle handle,
104- CompletionCallbackHandle callback_handle) = 0;
103+ const FutureHandle& handle, CompletionCallbackHandle callback_handle) = 0;
105104
106105#if defined(FIREBASE_USE_STD_FUNCTION)
107106 // / Register a callback that will be called when this future's status is set
@@ -116,7 +115,8 @@ class FutureApiInterface {
116115 // /
117116 // / @return A handle that can be passed to `FutureBase::RemoveCompletion`.
118117 virtual CompletionCallbackHandle AddCompletionCallbackLambda (
119- FutureHandle handle, std::function<void (const FutureBase&)> callback,
118+ const FutureHandle& handle,
119+ std::function<void (const FutureBase&)> callback,
120120 bool clear_existing_callbacks) = 0;
121121#endif // defined(FIREBASE_USE_STD_FUNCTION)
122122
@@ -143,37 +143,36 @@ class CompletionCallbackHandle {
143143 public:
144144 // Construct a null CompletionCallbackHandle.
145145 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+
148150 private:
149151 friend class ::FIREBASE_NAMESPACE::FutureBase;
150152 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) {}
157158
158159 FutureBase::CompletionCallback callback_;
159160 void * user_data_;
160- void (* user_data_delete_fn_)(void *);
161+ void (*user_data_delete_fn_)(void *);
161162};
162163
163164} // namespace detail
164165
165166template <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);
171171}
172172
173173#if defined(FIREBASE_USE_STD_FUNCTION)
174174template <class ResultType >
175- inline void
176- Future<ResultType>::OnCompletion(
175+ inline void Future<ResultType>::OnCompletion(
177176 std::function<void (const Future<ResultType>&)> callback) const {
178177 FutureBase::OnCompletion (
179178 *reinterpret_cast <std::function<void (const FutureBase&)>*>(&callback));
@@ -182,17 +181,15 @@ Future<ResultType>::OnCompletion(
182181
183182#if defined(INTERNAL_EXPERIMENTAL)
184183template <class T >
185- FutureBase::CompletionCallbackHandle
186- Future<T>::AddOnCompletion(
184+ FutureBase::CompletionCallbackHandle Future<T>::AddOnCompletion(
187185 TypedCompletionCallback callback, void * user_data) const {
188186 return FutureBase::AddOnCompletion (
189187 reinterpret_cast <CompletionCallback>(callback), user_data);
190188}
191189
192190#if defined(FIREBASE_USE_STD_FUNCTION)
193191template <class ResultType >
194- inline FutureBase::CompletionCallbackHandle
195- Future<ResultType>::AddOnCompletion(
192+ inline FutureBase::CompletionCallbackHandle Future<ResultType>::AddOnCompletion(
196193 std::function<void (const Future<ResultType>&)> callback) const {
197194 return FutureBase::AddOnCompletion (
198195 *reinterpret_cast <std::function<void (const FutureBase&)>*>(&callback));
@@ -204,7 +201,7 @@ Future<ResultType>::AddOnCompletion(
204201inline FutureBase::FutureBase () : api_(NULL ), handle_(0 ) {} // NOLINT
205202
206203inline FutureBase::FutureBase (detail::FutureApiInterface* api,
207- FutureHandle handle)
204+ const FutureHandle& handle)
208205 : api_(api), handle_(handle) {
209206 api_->ReferenceFuture (handle_);
210207 detail::RegisterForCleanup (api_, this );
@@ -280,17 +277,16 @@ inline void FutureBase::OnCompletion(CompletionCallback callback,
280277 void * user_data) const {
281278 if (api_ != NULL ) { // NOLINT
282279 api_->AddCompletionCallback (handle_, callback, user_data, nullptr ,
283- /* clear_existing_callbacks=*/ true );
280+ /* clear_existing_callbacks=*/ true );
284281 }
285282}
286283
287284#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 {
291287 if (api_ != NULL ) { // NOLINT
292288 return api_->AddCompletionCallback (handle_, callback, user_data, nullptr ,
293- /* clear_existing_callbacks=*/ false );
289+ /* clear_existing_callbacks=*/ false );
294290 }
295291 return CompletionCallbackHandle ();
296292}
@@ -308,16 +304,17 @@ inline void FutureBase::OnCompletion(
308304 std::function<void (const FutureBase&)> callback) const {
309305 if (api_ != NULL ) { // NOLINT
310306 api_->AddCompletionCallbackLambda (handle_, callback,
311- /* clear_existing_callbacks=*/ true );
307+ /* clear_existing_callbacks=*/ true );
312308 }
313309}
314310
315311#if defined(INTERNAL_EXPERIMENTAL)
316312inline FutureBase::CompletionCallbackHandle FutureBase::AddOnCompletion (
317313 std::function<void (const FutureBase&)> callback) const {
318314 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 );
321318 }
322319 return CompletionCallbackHandle ();
323320}
0 commit comments