Home | History | Annotate | Download | only in dev
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_
      6 #define PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_
      7 
      8 #include "ppapi/c/pp_array_output.h"
      9 #include "ppapi/c/pp_completion_callback.h"
     10 #include "ppapi/c/pp_stdint.h"
     11 #include "ppapi/cpp/resource.h"
     12 
     13 namespace pp {
     14 
     15 class InstanceHandle;
     16 
     17 class ResourceArray_Dev : public Resource {
     18  public:
     19   // Heap-allocated data passed to ArrayOutputCallbackConverter(). Please see
     20   // the comment of ArrayOutputCallbackConverter() for more details.
     21   struct ArrayOutputCallbackData {
     22     ArrayOutputCallbackData(const PP_ArrayOutput& array_output,
     23                             const PP_CompletionCallback& callback)
     24         : resource_array_output(0),
     25           output(array_output),
     26           original_callback(callback) {
     27     }
     28 
     29     PP_Resource resource_array_output;
     30     PP_ArrayOutput output;
     31     PP_CompletionCallback original_callback;
     32   };
     33 
     34   ResourceArray_Dev();
     35 
     36   ResourceArray_Dev(PassRef, PP_Resource resource);
     37 
     38   ResourceArray_Dev(const ResourceArray_Dev& other);
     39 
     40   ResourceArray_Dev(const InstanceHandle& instance,
     41                     const PP_Resource elements[],
     42                     uint32_t size);
     43 
     44   virtual ~ResourceArray_Dev();
     45 
     46   ResourceArray_Dev& operator=(const ResourceArray_Dev& other);
     47 
     48   uint32_t size() const;
     49 
     50   PP_Resource operator[](uint32_t index) const;
     51 
     52   // This is an adapter for backward compatibility. It works with those APIs
     53   // which take a PPB_ResourceArray_Dev resource as output parameter, and
     54   // returns results using PP_ArrayOutput. For example:
     55   //
     56   //   ResourceArray_Dev::ArrayOutputCallbackData* data =
     57   //       new ResourceArray_Dev::ArrayOutputCallbackData(
     58   //           pp_array_output, callback);
     59   //   ppb_foo->Bar(
     60   //       foo_resource, &data->resource_array_output,
     61   //       PP_MakeCompletionCallback(
     62   //           &ResourceArray_Dev::ArrayOutputCallbackConverter, data));
     63   //
     64   // It takes a heap-allocated ArrayOutputCallbackData struct passed as the user
     65   // data, and deletes it when the call completes.
     66   static void ArrayOutputCallbackConverter(void* user_data, int32_t result);
     67 };
     68 
     69 }  // namespace pp
     70 
     71 #endif  // PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_
     72