OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2008 The Native Client Authors. All rights reserved. | |
3 * Use of this source code is governed by a BSD-style license that can | |
4 * be found in the LICENSE file. | |
5 */ | |
6 | |
7 | |
8 #include <setjmp.h> | |
9 #include <stdio.h> | |
10 #include <string.h> | |
11 | |
12 #include <map> | |
13 | |
14 #include "native_client/src/trusted/plugin/srpc/browser_interface.h" | |
15 #include "native_client/src/trusted/plugin/srpc/desc_based_handle.h" | |
16 #include "native_client/src/trusted/plugin/srpc/portable_handle.h" | |
17 #include "native_client/src/trusted/plugin/srpc/shared_memory.h" | |
18 #include "native_client/src/trusted/plugin/srpc/plugin.h" | |
19 | |
20 #include "native_client/src/trusted/plugin/srpc/scriptable_handle.h" | |
21 | |
22 namespace { | |
23 | |
24 bool Map(void* obj, plugin::SrpcParams* params) { | |
25 plugin::DescBasedHandle *ptr = | |
26 reinterpret_cast<plugin::DescBasedHandle*>(obj); | |
27 // Create a copy of the wrapper to go on the SharedMemory object. | |
28 nacl::DescWrapper* shm_wrapper = | |
29 ptr->plugin()->wrapper_factory()->MakeGeneric(ptr->wrapper()->desc()); | |
30 // Increment the ref count of the contained object. | |
31 NaClDescRef(shm_wrapper->desc()); | |
32 | |
33 plugin::SharedMemory* portable_shared_memory = | |
34 plugin::SharedMemory::New(ptr->plugin(), shm_wrapper); | |
35 plugin::ScriptableHandle* shared_memory = | |
36 ptr->browser_interface()->NewScriptableHandle(portable_shared_memory); | |
37 if (NULL == shared_memory) { | |
38 return false; | |
39 } | |
40 PLUGIN_PRINTF(("ScriptableHandle::Invoke: new returned %p\n", | |
41 static_cast<void*>(shared_memory))); | |
42 params->outs()[0]->tag = NACL_SRPC_ARG_TYPE_OBJECT; | |
43 params->outs()[0]->u.oval = shared_memory; | |
44 return true; | |
45 } | |
46 | |
47 } // namespace | |
48 | |
49 namespace plugin { | |
50 | |
51 DescBasedHandle::DescBasedHandle(): plugin_(NULL), | |
52 wrapper_(NULL) { | |
53 PLUGIN_PRINTF(("DescBasedHandle::DescBasedHandle(%p)\n", | |
54 static_cast<void*>(this))); | |
55 } | |
56 | |
57 DescBasedHandle::~DescBasedHandle() { | |
58 PLUGIN_PRINTF(("DescBasedHandle::~DescBasedHandle(%p)\n", | |
59 static_cast<void*>(this))); | |
60 if (NULL != wrapper_) { | |
61 wrapper_->Delete(); | |
62 wrapper_ = NULL; | |
63 } | |
64 } | |
65 | |
66 DescBasedHandle* DescBasedHandle::New(Plugin* plugin, | |
67 nacl::DescWrapper* wrapper) { | |
68 PLUGIN_PRINTF(("DescBasedHandle::New()\n")); | |
69 | |
70 DescBasedHandle* desc_based_handle = new(std::nothrow) DescBasedHandle(); | |
71 | |
72 if (desc_based_handle == NULL || !desc_based_handle->Init(plugin, wrapper)) { | |
73 return NULL; | |
74 } | |
75 | |
76 return desc_based_handle; | |
77 } | |
78 | |
79 bool DescBasedHandle::Init(Plugin* plugin, nacl::DescWrapper* wrapper) { | |
80 plugin_ = plugin; | |
81 wrapper_ = wrapper; | |
82 LoadMethods(); | |
83 return true; | |
84 } | |
85 | |
86 BrowserInterface* DescBasedHandle::browser_interface() const { | |
87 return plugin_->browser_interface(); | |
88 } | |
89 | |
90 void DescBasedHandle::LoadMethods() { | |
91 // Methods supported by DescBasedHandle. | |
92 AddMethodCall(Map, "map", "", "h"); | |
93 } | |
94 | |
95 } // namespace plugin | |
OLD | NEW |