| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "native_client/src/trusted/plugin/nacl_subprocess.h" | 5 #include "native_client/src/trusted/plugin/nacl_subprocess.h" |
| 6 | 6 |
| 7 #include <stdarg.h> | 7 #include <stdarg.h> |
| 8 | 8 |
| 9 #include "native_client/src/trusted/plugin/browser_interface.h" | 9 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 10 #include "native_client/src/trusted/plugin/method_map.h" | |
| 11 #include "native_client/src/trusted/plugin/plugin_error.h" | 10 #include "native_client/src/trusted/plugin/plugin_error.h" |
| 12 #include "native_client/src/trusted/plugin/scriptable_handle.h" | 11 #include "native_client/src/trusted/plugin/srpc_params.h" |
| 13 #include "native_client/src/trusted/plugin/service_runtime.h" | |
| 14 | 12 |
| 15 namespace plugin { | 13 namespace plugin { |
| 16 | 14 |
| 17 nacl::string NaClSubprocess::description() const { | |
| 18 return description_; | |
| 19 } | |
| 20 | |
| 21 nacl::string NaClSubprocess::detailed_description() const { | 15 nacl::string NaClSubprocess::detailed_description() const { |
| 22 nacl::stringstream ss; | 16 nacl::stringstream ss; |
| 23 ss << description() | 17 ss << description() |
| 24 << "={ this=" << static_cast<const void*>(this) | 18 << "={ this=" << static_cast<const void*>(this) |
| 25 << ", srpc_client=" << static_cast<void*>(srpc_client_.get()) | 19 << ", srpc_client=" << static_cast<void*>(srpc_client_.get()) |
| 26 << ", service_runtime=" << static_cast<void*>(service_runtime_.get()) | 20 << ", service_runtime=" << static_cast<void*>(service_runtime_.get()) |
| 27 << " }"; | 21 << " }"; |
| 28 return ss.str(); | 22 return ss.str(); |
| 29 } | 23 } |
| 30 | 24 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 43 | 37 |
| 44 bool NaClSubprocess::StartSrpcServices() { | 38 bool NaClSubprocess::StartSrpcServices() { |
| 45 srpc_client_.reset(service_runtime_->SetupAppChannel()); | 39 srpc_client_.reset(service_runtime_->SetupAppChannel()); |
| 46 return NULL != srpc_client_.get(); | 40 return NULL != srpc_client_.get(); |
| 47 } | 41 } |
| 48 | 42 |
| 49 bool NaClSubprocess::StartJSObjectProxy(Plugin* plugin, ErrorInfo* error_info) { | 43 bool NaClSubprocess::StartJSObjectProxy(Plugin* plugin, ErrorInfo* error_info) { |
| 50 return srpc_client_->StartJSObjectProxy(plugin, error_info); | 44 return srpc_client_->StartJSObjectProxy(plugin, error_info); |
| 51 } | 45 } |
| 52 | 46 |
| 53 bool NaClSubprocess::HasMethod(uintptr_t method_id) const { | |
| 54 if (NULL == srpc_client_.get()) { | |
| 55 return false; | |
| 56 } | |
| 57 return srpc_client_->HasMethod(method_id); | |
| 58 } | |
| 59 | |
| 60 bool NaClSubprocess::InitParams(uintptr_t method_id, SrpcParams* params) const { | |
| 61 if (NULL == srpc_client_.get()) { | |
| 62 return false; | |
| 63 } | |
| 64 return srpc_client_->InitParams(method_id, params); | |
| 65 } | |
| 66 | |
| 67 bool NaClSubprocess::Invoke(uintptr_t method_id, SrpcParams* params) const { | |
| 68 if (NULL == srpc_client_.get()) { | |
| 69 return false; | |
| 70 } | |
| 71 return srpc_client_->Invoke(method_id, params); | |
| 72 } | |
| 73 | |
| 74 bool NaClSubprocess::InvokeSrpcMethod(const nacl::string& method_name, | 47 bool NaClSubprocess::InvokeSrpcMethod(const nacl::string& method_name, |
| 75 const nacl::string& input_signature, | 48 const nacl::string& input_signature, |
| 76 SrpcParams* params, | 49 SrpcParams* params, |
| 77 ...) { | 50 ...) { |
| 78 va_list vl; | 51 va_list vl; |
| 79 va_start(vl, params); | 52 va_start(vl, params); |
| 80 bool result = VInvokeSrpcMethod(method_name, input_signature, params, vl); | 53 bool result = VInvokeSrpcMethod(method_name, input_signature, params, vl); |
| 81 va_end(vl); | 54 va_end(vl); |
| 82 return result; | 55 return result; |
| 83 } | 56 } |
| 84 | 57 |
| 85 bool NaClSubprocess::VInvokeSrpcMethod(const nacl::string& method_name, | 58 bool NaClSubprocess::VInvokeSrpcMethod(const nacl::string& method_name, |
| 86 const nacl::string& input_signature, | 59 const nacl::string& input_signature, |
| 87 SrpcParams* params, | 60 SrpcParams* params, |
| 88 va_list vl) { | 61 va_list vl) { |
| 89 uintptr_t method_ident; | 62 if (NULL == srpc_client_.get()) { |
| 90 if (!SetupSrpcInvocation(method_name, params, &method_ident)) { | 63 PLUGIN_PRINTF(("VInvokeSrpcMethod (no srpc_client_)\n")); |
| 91 return false; | 64 return false; |
| 92 } | 65 } |
| 93 | 66 if (!srpc_client_->HasMethod(method_name)) { |
| 94 // Set up inputs. | 67 PLUGIN_PRINTF(("VInvokeSrpcMethod (no %s method found)\n", |
| 68 method_name.c_str())); |
| 69 return false; |
| 70 } |
| 71 if (!srpc_client_->InitParams(method_name, params)) { |
| 72 PLUGIN_PRINTF(("VInvokeSrpcMethod (InitParams failed)\n")); |
| 73 return false; |
| 74 } |
| 75 // Marshall inputs. |
| 95 for (size_t i = 0; i < input_signature.length(); ++i) { | 76 for (size_t i = 0; i < input_signature.length(); ++i) { |
| 96 char c = input_signature[i]; | 77 char c = input_signature[i]; |
| 97 // Only handle the limited number of SRPC types used for PNaCl. | 78 // Only handle the limited number of SRPC types used for PNaCl. |
| 98 // Add more as needed. | 79 // Add more as needed. |
| 99 switch (c) { | 80 switch (c) { |
| 100 default: | 81 default: |
| 101 PLUGIN_PRINTF(("PnaclSrpcLib::InvokeSrpcMethod unhandled type: %c\n", | 82 PLUGIN_PRINTF(("PnaclSrpcLib::InvokeSrpcMethod unhandled type: %c\n", |
| 102 c)); | 83 c)); |
| 103 return false; | 84 return false; |
| 104 case NACL_SRPC_ARG_TYPE_BOOL: { | 85 case NACL_SRPC_ARG_TYPE_BOOL: { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 params->ins()[i]->u.ival = input; | 109 params->ins()[i]->u.ival = input; |
| 129 break; | 110 break; |
| 130 } | 111 } |
| 131 case NACL_SRPC_ARG_TYPE_LONG: { | 112 case NACL_SRPC_ARG_TYPE_LONG: { |
| 132 int64_t input = va_arg(vl, int64_t); | 113 int64_t input = va_arg(vl, int64_t); |
| 133 params->ins()[i]->u.lval = input; | 114 params->ins()[i]->u.lval = input; |
| 134 break; | 115 break; |
| 135 } | 116 } |
| 136 } | 117 } |
| 137 } | 118 } |
| 138 | 119 return srpc_client_->Invoke(method_name, params); |
| 139 return Invoke(method_ident, params); | |
| 140 } | |
| 141 | |
| 142 bool NaClSubprocess::SetupSrpcInvocation(const nacl::string& method_name, | |
| 143 SrpcParams* params, | |
| 144 uintptr_t* method_ident) { | |
| 145 *method_ident = browser_interface_->StringToIdentifier(method_name); | |
| 146 if (!HasMethod(*method_ident)) { | |
| 147 PLUGIN_PRINTF(("SetupSrpcInvocation (no %s method found)\n", | |
| 148 method_name.c_str())); | |
| 149 return false; | |
| 150 } | |
| 151 return InitParams(*method_ident, params); | |
| 152 } | 120 } |
| 153 | 121 |
| 154 } // namespace plugin | 122 } // namespace plugin |
| OLD | NEW |