| 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 "native_client/src/trusted/plugin/srpc/portable_handle.h" | |
| 9 #include <stdio.h> | |
| 10 #include <string.h> | |
| 11 #include <map> | |
| 12 | |
| 13 #include "native_client/src/trusted/plugin/srpc/browser_interface.h" | |
| 14 | |
| 15 namespace plugin { | |
| 16 | |
| 17 PortableHandle::PortableHandle() { | |
| 18 PLUGIN_PRINTF(("PortableHandle::PortableHandle(%p)\n", | |
| 19 static_cast<void*>(this))); | |
| 20 } | |
| 21 | |
| 22 PortableHandle::~PortableHandle() { | |
| 23 PLUGIN_PRINTF(("PortableHandle::~PortableHandle(%p)\n", | |
| 24 static_cast<void*>(this))); | |
| 25 } | |
| 26 | |
| 27 void PortableHandle::AddPropertyGet(RpcFunction function_ptr, | |
| 28 const char* name, | |
| 29 const char* outs) { | |
| 30 PLUGIN_PRINTF(("PortableHandle::AddPropertyGet\n")); | |
| 31 uintptr_t method_id = browser_interface()->StringToIdentifier(name); | |
| 32 MethodInfo* new_method = | |
| 33 new(std::nothrow) MethodInfo(function_ptr, name, "", outs); | |
| 34 if (NULL == new_method) { | |
| 35 return; | |
| 36 } | |
| 37 property_get_methods_.AddMethod(method_id, new_method); | |
| 38 } | |
| 39 | |
| 40 void PortableHandle::AddPropertySet(RpcFunction function_ptr, | |
| 41 const char* name, | |
| 42 const char* ins) { | |
| 43 PLUGIN_PRINTF(("PortableHandle::AddPropertySet\n")); | |
| 44 uintptr_t method_id = browser_interface()->StringToIdentifier(name); | |
| 45 MethodInfo* new_method = | |
| 46 new(std::nothrow) MethodInfo(function_ptr, name, ins, ""); | |
| 47 if (NULL == new_method) { | |
| 48 return; | |
| 49 } | |
| 50 property_set_methods_.AddMethod(method_id, new_method); | |
| 51 } | |
| 52 | |
| 53 void PortableHandle::AddMethodCall(RpcFunction function_ptr, | |
| 54 const char* name, | |
| 55 const char* ins, | |
| 56 const char* outs) { | |
| 57 PLUGIN_PRINTF(("PortableHandle::AddMethodCall\n")); | |
| 58 uintptr_t method_id = browser_interface()->StringToIdentifier(name); | |
| 59 MethodInfo* new_method = | |
| 60 new(std::nothrow) MethodInfo(function_ptr, name, ins, outs); | |
| 61 if (NULL == new_method) { | |
| 62 return; | |
| 63 } | |
| 64 methods_.AddMethod(method_id, new_method); | |
| 65 } | |
| 66 | |
| 67 bool PortableHandle::InitParams(uintptr_t method_id, | |
| 68 CallType call_type, | |
| 69 SrpcParams* params) { | |
| 70 MethodInfo* method_info = GetMethodInfo(method_id, call_type); | |
| 71 if (NULL == method_info) { | |
| 72 return InitParamsEx(method_id, call_type, params); | |
| 73 } else { | |
| 74 return params->Init(method_info->ins(), method_info->outs()); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 MethodInfo* PortableHandle::GetMethodInfo(uintptr_t method_id, | |
| 79 CallType call_type) { | |
| 80 MethodInfo* method_info = NULL; | |
| 81 switch (call_type) { | |
| 82 case METHOD_CALL: | |
| 83 method_info = methods_.GetMethod(method_id); | |
| 84 break; | |
| 85 case PROPERTY_GET: | |
| 86 method_info = property_get_methods_.GetMethod(method_id); | |
| 87 break; | |
| 88 case PROPERTY_SET: | |
| 89 method_info = property_set_methods_.GetMethod(method_id); | |
| 90 break; | |
| 91 } | |
| 92 | |
| 93 return method_info; | |
| 94 } | |
| 95 | |
| 96 bool PortableHandle::HasMethod(uintptr_t method_id, CallType call_type) { | |
| 97 if (GetMethodInfo(method_id, call_type)) { | |
| 98 return true; | |
| 99 } | |
| 100 // Call class-specific implementation - see ConnectedSocket and Plugin | |
| 101 // classes for examples. | |
| 102 return HasMethodEx(method_id, call_type); | |
| 103 } | |
| 104 | |
| 105 // TODO(gregoryd) - consider adding a function that will first initialize | |
| 106 // params and then call Invoke | |
| 107 bool PortableHandle::Invoke(uintptr_t method_id, | |
| 108 CallType call_type, | |
| 109 SrpcParams* params) { | |
| 110 MethodInfo* method_info = GetMethodInfo(method_id, call_type); | |
| 111 | |
| 112 if (NULL != method_info && NULL != method_info->function_ptr()) { | |
| 113 return method_info->function_ptr()(reinterpret_cast<void*>(this), params); | |
| 114 } else { | |
| 115 // This should be handled by the class-specific handler | |
| 116 return InvokeEx(method_id, call_type, params); | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 bool PortableHandle::InitParamsEx(uintptr_t method_id, | |
| 121 CallType call_type, | |
| 122 SrpcParams* params) { | |
| 123 UNREFERENCED_PARAMETER(method_id); | |
| 124 UNREFERENCED_PARAMETER(call_type); | |
| 125 UNREFERENCED_PARAMETER(params); | |
| 126 return false; | |
| 127 } | |
| 128 | |
| 129 bool PortableHandle::InvokeEx(uintptr_t method_id, | |
| 130 CallType call_type, | |
| 131 SrpcParams* params) { | |
| 132 UNREFERENCED_PARAMETER(method_id); | |
| 133 UNREFERENCED_PARAMETER(call_type); | |
| 134 UNREFERENCED_PARAMETER(params); | |
| 135 return false; | |
| 136 } | |
| 137 | |
| 138 bool PortableHandle::HasMethodEx(uintptr_t method_id, CallType call_type) { | |
| 139 UNREFERENCED_PARAMETER(method_id); | |
| 140 UNREFERENCED_PARAMETER(call_type); | |
| 141 return false; | |
| 142 } | |
| 143 | |
| 144 } // namespace plugin | |
| OLD | NEW |