| Index: ppapi/native_client/src/trusted/plugin/srpc_client.cc
|
| ===================================================================
|
| --- ppapi/native_client/src/trusted/plugin/srpc_client.cc (revision 122205)
|
| +++ ppapi/native_client/src/trusted/plugin/srpc_client.cc (working copy)
|
| @@ -4,50 +4,83 @@
|
| * found in the LICENSE file.
|
| */
|
|
|
| +#include "native_client/src/trusted/plugin/srpc_client.h"
|
|
|
| #include <string.h>
|
|
|
| -#include <map>
|
| -
|
| #include "native_client/src/shared/platform/nacl_log.h"
|
| -#include "native_client/src/trusted/plugin/browser_interface.h"
|
| -#include "native_client/src/trusted/plugin/desc_based_handle.h"
|
| #include "native_client/src/trusted/plugin/plugin.h"
|
| -#include "native_client/src/trusted/plugin/scriptable_handle.h"
|
| -#include "native_client/src/trusted/plugin/srpc_client.h"
|
| +#include "native_client/src/trusted/plugin/srpc_params.h"
|
| #include "native_client/src/trusted/plugin/utility.h"
|
|
|
| namespace plugin {
|
|
|
| +typedef bool (*RpcFunction)(void* obj, SrpcParams* params);
|
| +
|
| +// MethodInfo records the method names and type signatures of an SRPC server.
|
| +class MethodInfo {
|
| + public:
|
| + // statically defined method - called through a pointer
|
| + MethodInfo(const RpcFunction function_ptr,
|
| + const char* name,
|
| + const char* ins,
|
| + const char* outs,
|
| + // index is set to UINT_MAX for methods implemented by the plugin,
|
| + // All methods implemented by nacl modules have indexes
|
| + // that are lower than UINT_MAX.
|
| + const uint32_t index = UINT_MAX) :
|
| + function_ptr_(function_ptr),
|
| + name_(STRDUP(name)),
|
| + ins_(STRDUP(ins)),
|
| + outs_(STRDUP(outs)),
|
| + index_(index) { }
|
| +
|
| + ~MethodInfo() {
|
| + free(reinterpret_cast<void*>(name_));
|
| + free(reinterpret_cast<void*>(ins_));
|
| + free(reinterpret_cast<void*>(outs_));
|
| + }
|
| +
|
| + RpcFunction function_ptr() const { return function_ptr_; }
|
| + char* name() const { return name_; }
|
| + char* ins() const { return ins_; }
|
| + char* outs() const { return outs_; }
|
| + uint32_t index() const { return index_; }
|
| +
|
| + private:
|
| + NACL_DISALLOW_COPY_AND_ASSIGN(MethodInfo);
|
| + RpcFunction function_ptr_;
|
| + char* name_;
|
| + char* ins_;
|
| + char* outs_;
|
| + uint32_t index_;
|
| +};
|
| +
|
| SrpcClient::SrpcClient()
|
| - : srpc_channel_initialised_(false),
|
| - browser_interface_(NULL) {
|
| + : srpc_channel_initialised_(false) {
|
| PLUGIN_PRINTF(("SrpcClient::SrpcClient (this=%p)\n",
|
| static_cast<void*>(this)));
|
| NaClSrpcChannelInitialize(&srpc_channel_);
|
| }
|
|
|
| -SrpcClient* SrpcClient::New(Plugin* plugin, nacl::DescWrapper* wrapper) {
|
| +SrpcClient* SrpcClient::New(nacl::DescWrapper* wrapper) {
|
| nacl::scoped_ptr<SrpcClient> srpc_client(new SrpcClient());
|
| - if (!srpc_client->Init(plugin->browser_interface(), wrapper)) {
|
| + if (!srpc_client->Init(wrapper)) {
|
| PLUGIN_PRINTF(("SrpcClient::New (SrpcClient::Init failed)\n"));
|
| return NULL;
|
| }
|
| return srpc_client.release();
|
| }
|
|
|
| -bool SrpcClient::Init(BrowserInterface* browser_interface,
|
| - nacl::DescWrapper* wrapper) {
|
| - PLUGIN_PRINTF(("SrpcClient::Init (this=%p, browser_interface=%p, wrapper=%p)"
|
| - "\n", static_cast<void*>(this),
|
| - static_cast<void*>(browser_interface),
|
| +bool SrpcClient::Init(nacl::DescWrapper* wrapper) {
|
| + PLUGIN_PRINTF(("SrpcClient::Init (this=%p, wrapper=%p)\n",
|
| + static_cast<void*>(this),
|
| static_cast<void*>(wrapper)));
|
| // Open the channel to pass RPC information back and forth
|
| if (!NaClSrpcClientCtor(&srpc_channel_, wrapper->desc())) {
|
| return false;
|
| }
|
| srpc_channel_initialised_ = true;
|
| - browser_interface_ = browser_interface;
|
| PLUGIN_PRINTF(("SrpcClient::Init (Ctor worked)\n"));
|
| // Record the method names in a convenient way for later dispatches.
|
| GetMethods();
|
| @@ -71,8 +104,7 @@
|
| PLUGIN_PRINTF(("SrpcClient::~SrpcClient (return)\n"));
|
| }
|
|
|
| -bool SrpcClient::StartJSObjectProxy(Plugin* plugin,
|
| - ErrorInfo *error_info) {
|
| +bool SrpcClient::StartJSObjectProxy(Plugin* plugin, ErrorInfo *error_info) {
|
| // Start up PPAPI interaction if the plugin determines that the
|
| // requisite methods are exported.
|
| return plugin->StartProxiedExecution(&srpc_channel_, error_info);
|
| @@ -88,62 +120,62 @@
|
| // Intern the methods into a mapping from identifiers to MethodInfo.
|
| for (uint32_t i = 0; i < method_count; ++i) {
|
| int retval;
|
| - const char* name;
|
| + const char* method_name;
|
| const char* input_types;
|
| const char* output_types;
|
|
|
| retval = NaClSrpcServiceMethodNameAndTypes(srpc_channel_.client,
|
| i,
|
| - &name,
|
| + &method_name,
|
| &input_types,
|
| &output_types);
|
| if (!retval) {
|
| return;
|
| }
|
| - if (!IsValidIdentifierString(name, NULL)) {
|
| + if (!IsValidIdentifierString(method_name, NULL)) {
|
| // If name is not an ECMAScript identifier, do not enter it into the
|
| // methods_ table.
|
| continue;
|
| }
|
| - uintptr_t ident = browser_interface_->StringToIdentifier(name);
|
| MethodInfo* method_info =
|
| - new MethodInfo(NULL, name, input_types, output_types, i);
|
| + new MethodInfo(NULL, method_name, input_types, output_types, i);
|
| if (NULL == method_info) {
|
| return;
|
| }
|
| // Install in the map only if successfully read.
|
| - methods_[ident] = method_info;
|
| + methods_[method_name] = method_info;
|
| }
|
| }
|
|
|
| -bool SrpcClient::HasMethod(uintptr_t method_id) {
|
| - bool has_method = (NULL != methods_[method_id]);
|
| - PLUGIN_PRINTF(("SrpcClient::HasMethod (this=%p, return %d)\n",
|
| - static_cast<void*>(this), has_method));
|
| +bool SrpcClient::HasMethod(const nacl::string& method_name) {
|
| + bool has_method = (NULL != methods_[method_name]);
|
| + PLUGIN_PRINTF((
|
| + "SrpcClient::HasMethod (this=%p, method_name='%s', return %d)\n",
|
| + static_cast<void*>(this), method_name.c_str(), has_method));
|
| return has_method;
|
| }
|
|
|
| -bool SrpcClient::InitParams(uintptr_t method_id, SrpcParams* params) {
|
| - MethodInfo* method_info = methods_[method_id];
|
| +bool SrpcClient::InitParams(const nacl::string& method_name,
|
| + SrpcParams* params) {
|
| + MethodInfo* method_info = methods_[method_name];
|
| if (method_info) {
|
| return params->Init(method_info->ins(), method_info->outs());
|
| }
|
| return false;
|
| }
|
|
|
| -bool SrpcClient::Invoke(uintptr_t method_id,
|
| - SrpcParams* params) {
|
| +bool SrpcClient::Invoke(const nacl::string& method_name, SrpcParams* params) {
|
| // It would be better if we could set the exception on each detailed failure
|
| // case. However, there are calls to Invoke from within the plugin itself,
|
| // and these could leave residual exceptions pending. This seems to be
|
| // happening specifically with hard_shutdowns.
|
| PLUGIN_PRINTF(("SrpcClient::Invoke (this=%p, method_name='%s', params=%p)\n",
|
| static_cast<void*>(this),
|
| - browser_interface_->IdentifierToString(method_id).c_str(),
|
| + method_name.c_str(),
|
| static_cast<void*>(params)));
|
|
|
| - // Ensure Invoke was called with an identifier that had a binding.
|
| - if (NULL == methods_[method_id]) {
|
| + // Ensure Invoke was called with a method name that has a binding.
|
| + if (NULL == methods_[method_name]) {
|
| PLUGIN_PRINTF(("SrpcClient::Invoke (ident not in methods_)\n"));
|
| return false;
|
| }
|
| @@ -151,7 +183,7 @@
|
| PLUGIN_PRINTF(("SrpcClient::Invoke (sending the rpc)\n"));
|
| // Call the method
|
| NaClSrpcError err = NaClSrpcInvokeV(&srpc_channel_,
|
| - methods_[method_id]->index(),
|
| + methods_[method_name]->index(),
|
| params->ins(),
|
| params->outs());
|
| PLUGIN_PRINTF(("SrpcClient::Invoke (response=%d)\n", err));
|
|
|