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// From ../test_thunk/simple.idl modified Fri Nov 16 11:26:06 2012.
6
7#include "ppapi/c/../test_thunk/simple.h"
8#include "ppapi/c/pp_errors.h"
9#include "ppapi/shared_impl/tracked_callback.h"
10#include "ppapi/thunk/enter.h"
11#include "ppapi/thunk/ppb_instance_api.h"
12#include "ppapi/thunk/resource_creation_api.h"
13#include "ppapi/thunk/simple_api.h"
14#include "ppapi/thunk/thunk.h"
15
16namespace ppapi {
17namespace thunk {
18
19namespace {
20
21PP_Resource Create(PP_Instance instance) {
22  VLOG(4) << "PPB_Simple::Create()";
23  EnterResourceCreation enter(instance);
24  if (enter.failed())
25    return 0;
26  return enter.functions()->CreateSimple(instance);
27}
28
29PP_Bool IsSimple(PP_Resource resource) {
30  VLOG(4) << "PPB_Simple::IsSimple()";
31  EnterResource<PPB_Simple_API> enter(resource, false);
32  return PP_FromBool(enter.succeeded());
33}
34
35void PostMessage(PP_Instance instance, PP_Var message) {
36  VLOG(4) << "PPB_Simple::PostMessage()";
37  EnterInstance enter(instance);
38  if (enter.failed())
39    return;
40  enter.functions()->PostMessage(instance, message);
41}
42
43uint32_t DoUint32Instance_0_5(PP_Instance instance) {
44  VLOG(4) << "PPB_Simple::DoUint32Instance()";
45  EnterInstance enter(instance);
46  if (enter.failed())
47    return 0;
48  return enter.functions()->DoUint32Instance0_5(instance);
49}
50
51uint32_t DoUint32Instance(PP_Instance instance, PP_Resource resource) {
52  VLOG(4) << "PPB_Simple::DoUint32Instance()";
53  EnterInstance enter(instance);
54  if (enter.failed())
55    return 0;
56  return enter.functions()->DoUint32Instance(instance, resource);
57}
58
59uint32_t DoUint32Resource(PP_Resource instance) {
60  VLOG(4) << "PPB_Simple::DoUint32Resource()";
61  EnterResource<PPB_Simple_API> enter(instance, true);
62  if (enter.failed())
63    return 0;
64  return enter.object()->DoUint32Resource();
65}
66
67uint32_t DoUint32ResourceNoErrors(PP_Resource instance) {
68  VLOG(4) << "PPB_Simple::DoUint32ResourceNoErrors()";
69  EnterResource<PPB_Simple_API> enter(instance, false);
70  if (enter.failed())
71    return 0;
72  return enter.object()->DoUint32ResourceNoErrors();
73}
74
75int32_t OnFailure12(PP_Instance instance) {
76  VLOG(4) << "PPB_Simple::OnFailure12()";
77  EnterInstance enter(instance);
78  if (enter.failed())
79    return 12;
80  return enter.functions()->OnFailure12(instance);
81}
82
83const PPB_Simple_0_5 g_ppb_simple_thunk_0_5 = {
84  &Create,
85  &IsSimple,
86  &PostMessage,
87  &DoUint32Instance_0_5,
88  &DoUint32Resource,
89  &DoUint32ResourceNoErrors
90};
91
92const PPB_Simple_1_0 g_ppb_simple_thunk_1_0 = {
93  &Create,
94  &IsSimple,
95  &DoUint32Instance_0_5,
96  &DoUint32Resource,
97  &DoUint32ResourceNoErrors,
98  &OnFailure12
99};
100
101const PPB_Simple_1_5 g_ppb_simple_thunk_1_5 = {
102  &Create,
103  &IsSimple,
104  &DoUint32Instance,
105  &DoUint32Resource,
106  &DoUint32ResourceNoErrors,
107  &OnFailure12
108};
109
110}  // namespace
111
112const PPB_Simple_0_5* GetPPB_Simple_0_5_Thunk() {
113  return &g_ppb_simple_thunk_0_5;
114}
115
116const PPB_Simple_1_0* GetPPB_Simple_1_0_Thunk() {
117  return &g_ppb_simple_thunk_1_0;
118}
119
120const PPB_Simple_1_5* GetPPB_Simple_1_5_Thunk() {
121  return &g_ppb_simple_thunk_1_5;
122}
123
124}  // namespace thunk
125}  // namespace ppapi
126