Pepper_42_C++_interfaces
Public Member Functions | Protected Attributes | List of all members
pp::CompletionCallback Class Reference

#include <completion_callback.h>

Inheritance diagram for pp::CompletionCallback:
Inheritance graph
Collaboration diagram for pp::CompletionCallback:
Collaboration graph

Public Member Functions

 CompletionCallback ()
 
 CompletionCallback (PP_CompletionCallback_Func func, void *user_data)
 
 CompletionCallback (PP_CompletionCallback_Func func, void *user_data, int32_t flags)
 
void set_flags (int32_t flags)
 
void Run (int32_t result)
 
void RunAndClear (int32_t result)
 
bool IsOptional () const
 
const PP_CompletionCallback & pp_completion_callback () const
 
int32_t flags () const
 
int32_t MayForce (int32_t result) const
 

Protected Attributes

PP_CompletionCallback cc_
 

Detailed Description

This API enables you to implement and receive callbacks when Pepper operations complete asynchronously.

You can create these objects yourself, but it is most common to use the CompletionCallbackFactory to allow the callbacks to call class member functions.

Definition at line 24 of file completion_callback.h.

Constructor & Destructor Documentation

pp::CompletionCallback::CompletionCallback ( )
inline

The default constructor will create a blocking CompletionCallback that can be passed to a method to indicate that the calling thread should be blocked until the asynchronous operation corresponding to the method completes.

Note: Blocking completion callbacks are only allowed from from background threads.

Definition at line 33 of file completion_callback.h.

References cc_.

pp::CompletionCallback::CompletionCallback ( PP_CompletionCallback_Func  func,
void *  user_data 
)
inline

A constructor for creating a CompletionCallback.

Parameters
[in]funcThe function to be called on completion.
[in]user_dataThe user data to be passed to the callback function. This is optional and is typically used to help track state in case of multiple pending callbacks.

Definition at line 43 of file completion_callback.h.

References cc_.

pp::CompletionCallback::CompletionCallback ( PP_CompletionCallback_Func  func,
void *  user_data,
int32_t  flags 
)
inline

A constructor for creating a CompletionCallback with specified flags.

Parameters
[in]funcThe function to be called on completion.
[in]user_dataThe user data to be passed to the callback function. This is optional and is typically used to help track state in case of multiple pending callbacks.
[in]flagsBit field combination of PP_CompletionCallback_Flag flags used to control how non-NULL callbacks are scheduled by asynchronous methods.

Definition at line 57 of file completion_callback.h.

References cc_, and flags().

Member Function Documentation

int32_t pp::CompletionCallback::flags ( ) const
inline

The flags() function returns flags used to control how non-NULL callbacks are scheduled by asynchronous methods.

Returns
An int32_t containing a bit field combination of PP_CompletionCallback_Flag flags.

Definition at line 129 of file completion_callback.h.

References cc_.

Referenced by CompletionCallback(), and set_flags().

bool pp::CompletionCallback::IsOptional ( ) const
inline

IsOptional() is used to determine the setting of the PP_COMPLETIONCALLBACK_FLAG_OPTIONAL flag. This flag allows any method taking such callback to complete synchronously and not call the callback if the operation would not block. This is useful when performance is an issue, and the operation bandwidth should not be limited to the processing speed of the message loop.

On synchronous method completion, the completion result will be returned by the method itself. Otherwise, the method will return PP_OK_COMPLETIONPENDING, and the callback will be invoked asynchronously on the same thread where the PPB method was invoked.

Returns
true if this callback is optional, otherwise false.

Definition at line 113 of file completion_callback.h.

References cc_.

Referenced by MayForce().

int32_t pp::CompletionCallback::MayForce ( int32_t  result) const
inline

MayForce() is used when implementing functions taking callbacks. If the callback is required and result indicates that it has not been scheduled, it will be forced on the main thread.

Example:

int32_t OpenURL(pp::URLLoader* loader,
pp::URLRequestInfo* url_request_info,
const CompletionCallback& cc) {
if (loader == NULL || url_request_info == NULL)
return cc.MayForce(PP_ERROR_BADRESOURCE);
return loader->Open(*loader, *url_request_info, cc);
}
Parameters
[in]resultPP_OK_COMPLETIONPENDING or the result of the completed operation to be passed to the callback function. PP_OK_COMPLETIONPENDING indicates that the callback has already been scheduled. Other non-positive values correspond to error codes from pp_errors.h. Positive values indicate additional information such as bytes read.
Returns
PP_OK_COMPLETIONPENDING if the callback has been forced, result parameter otherwise.

Definition at line 158 of file completion_callback.h.

References pp::Core::CallOnMainThread(), pp::Module::core(), pp::Module::Get(), and IsOptional().

const PP_CompletionCallback& pp::CompletionCallback::pp_completion_callback ( ) const
inline

The pp_completion_callback() function returns the underlying PP_CompletionCallback

Returns
A PP_CompletionCallback.

Definition at line 122 of file completion_callback.h.

References cc_.

void pp::CompletionCallback::Run ( int32_t  result)
inline

Run() is used to run the CompletionCallback. Normally, the system runs a CompletionCallback after an asynchronous operation completes, but programs may wish to run the CompletionCallback manually in order to reuse the same code paths.

Parameters
[in]resultThe result of the operation to be passed to the callback function. Non-positive values correspond to the error codes from pp_errors.h (excluding PP_OK_COMPLETIONPENDING). Positive values indicate additional information such as bytes read.

Definition at line 82 of file completion_callback.h.

References cc_, and PP_DCHECK.

void pp::CompletionCallback::RunAndClear ( int32_t  result)
inline

RunAndClear() is used to run the CompletionCallback and clear out the callback so that it cannot be run a second time.

Parameters
[in]resultThe result of the operation to be passed to the callback function. Non-positive values correspond to the error codes from pp_errors.h (excluding PP_OK_COMPLETIONPENDING). Positive values indicate additional information such as bytes read.

Definition at line 95 of file completion_callback.h.

References cc_, and PP_DCHECK.

void pp::CompletionCallback::set_flags ( int32_t  flags)
inline

The set_flags() function is used to set the flags used to control how non-NULL callbacks are scheduled by asynchronous methods.

Parameters
[in]flagsBit field combination of PP_CompletionCallback_Flag flags used to control how non-NULL callbacks are scheduled by asynchronous methods.

Definition at line 69 of file completion_callback.h.

References cc_, and flags().

Member Data Documentation

PP_CompletionCallback pp::CompletionCallback::cc_
protected

The documentation for this class was generated from the following file: