Pepper_47_C++_interfaces
resource_array_dev.cc
Go to the documentation of this file.
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 
6 
7 #include "ppapi/c/dev/ppb_resource_array_dev.h"
8 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/cpp/logging.h"
11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/module_impl.h"
13 
14 namespace pp {
15 
16 namespace {
17 
18 template <> const char* interface_name<PPB_ResourceArray_Dev>() {
19  return PPB_RESOURCEARRAY_DEV_INTERFACE;
20 }
21 
22 } // namespace
23 
25 }
26 
28  : Resource(PASS_REF, resource) {
29 }
30 
32  : Resource(other) {
33 }
34 
36  const PP_Resource elements[],
37  uint32_t size) {
38  if (has_interface<PPB_ResourceArray_Dev>()) {
39  PassRefFromConstructor(get_interface<PPB_ResourceArray_Dev>()->Create(
40  instance.pp_instance(), elements, size));
41  }
42 }
43 
45 }
46 
48  const ResourceArray_Dev& other) {
49  Resource::operator=(other);
50  return *this;
51 }
52 
53 uint32_t ResourceArray_Dev::size() const {
54  if (!has_interface<PPB_ResourceArray_Dev>())
55  return 0;
56  return get_interface<PPB_ResourceArray_Dev>()->GetSize(pp_resource());
57 }
58 
60  if (!has_interface<PPB_ResourceArray_Dev>())
61  return 0;
62  return get_interface<PPB_ResourceArray_Dev>()->GetAt(pp_resource(), index);
63 }
64 
65 // static
67  int32_t result) {
69  static_cast<ArrayOutputCallbackData*>(user_data);
70 
71  // data->resource_array_output should remain 0 if the call failed.
73  PP_DCHECK(resources.is_null() || result == PP_OK);
74 
75  // Need to issue the "GetDataBuffer" even for error cases and when the number
76  // of items is 0.
77  PP_Resource* output_buf = static_cast<PP_Resource*>(
78  data->output.GetDataBuffer(
79  data->output.user_data, resources.is_null() ? 0 : resources.size(),
80  sizeof(PP_Resource)));
81  if (output_buf) {
82  for (uint32_t index = 0; index < resources.size(); ++index) {
83  output_buf[index] = resources[index];
84  Module::Get()->core()->AddRefResource(output_buf[index]);
85  }
86  }
87 
88  PP_RunCompletionCallback(&data->original_callback, result);
89  delete data;
90 }
91 
92 } // namespace pp
void PassRefFromConstructor(PP_Resource resource)
Definition: resource.cc:50
void AddRefResource(PP_Resource resource)
Definition: core.h:31
PP_Resource operator[](uint32_t index) const
Core * core()
Definition: module.h:74
#define PP_DCHECK(a)
Definition: logging.h:16
PassRef
Definition: pass_ref.h:17
static void ArrayOutputCallbackConverter(void *user_data, int32_t result)
ResourceArray_Dev & operator=(const ResourceArray_Dev &other)
PP_Resource pp_resource() const
Definition: resource.h:47
bool is_null() const
Definition: resource.h:45
uint32_t size() const
PP_Instance pp_instance() const
A reference counted module resource.
Definition: resource.h:20
static Module * Get()
Resource & operator=(const Resource &other)
Definition: resource.cc:27