OLD | NEW |
1 // Copyright (c) 2010 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2010 The Native Client 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/shared/ppapi_proxy/browser_ppp.h" | 5 #include "native_client/src/shared/ppapi_proxy/browser_ppp.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "native_client/src/include/nacl_scoped_ptr.h" | 9 #include "native_client/src/include/nacl_scoped_ptr.h" |
10 #include "native_client/src/include/portability.h" | 10 #include "native_client/src/include/portability.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 return PP_ERROR_FAILED; | 48 return PP_ERROR_FAILED; |
49 } | 49 } |
50 if (!NaClSrpcServiceHandlerCtor(service, PpbRpcs::srpc_methods)) { | 50 if (!NaClSrpcServiceHandlerCtor(service, PpbRpcs::srpc_methods)) { |
51 DebugPrintf("Couldn't construct callback services.\n"); | 51 DebugPrintf("Couldn't construct callback services.\n"); |
52 free(service); | 52 free(service); |
53 return PP_ERROR_FAILED; | 53 return PP_ERROR_FAILED; |
54 } | 54 } |
55 // Export the service on the channel. | 55 // Export the service on the channel. |
56 channel_->server = service; | 56 channel_->server = service; |
57 char* service_string = const_cast<char*>(service->service_string); | 57 char* service_string = const_cast<char*>(service->service_string); |
| 58 // Remember the module_id associated with channel_; |
| 59 SetModuleIdForSrpcChannel(channel_, module_id); |
58 // Do the RPC. | 60 // Do the RPC. |
59 int32_t browser_pid = static_cast<int32_t>(GETPID()); | 61 int32_t browser_pid = static_cast<int32_t>(GETPID()); |
60 int32_t success; | 62 int32_t success; |
61 NaClSrpcError retval = | 63 NaClSrpcError retval = |
62 PppRpcClient::PPP_InitializeModule(channel_, | 64 PppRpcClient::PPP_InitializeModule(channel_, |
63 browser_pid, | 65 browser_pid, |
64 module_id, | 66 module_id, |
65 wrapper->desc(), | 67 wrapper->desc(), |
66 service_string, | 68 service_string, |
67 &plugin_pid_, | 69 &plugin_pid_, |
68 &success); | 70 &success); |
69 if (retval != NACL_SRPC_RESULT_OK) { | 71 if (retval != NACL_SRPC_RESULT_OK) { |
70 DebugPrintf("InitializeModule failed %02x\n", retval); | 72 DebugPrintf("InitializeModule failed %02x\n", retval); |
71 return PP_ERROR_FAILED; | 73 return PP_ERROR_FAILED; |
72 } | 74 } |
73 DebugPrintf("InitializeModule succeeded %02x\n", success); | 75 DebugPrintf("InitializeModule succeeded %02x\n", success); |
74 return success; | 76 return success; |
75 } | 77 } |
76 | 78 |
77 void BrowserPpp::ShutdownModule() { | 79 void BrowserPpp::ShutdownModule() { |
78 DebugPrintf("BrowserPpp::ShutdownModule\n"); | 80 DebugPrintf("BrowserPpp::ShutdownModule\n"); |
79 PppRpcClient::PPP_ShutdownModule(channel_); | 81 PppRpcClient::PPP_ShutdownModule(channel_); |
80 // Clean up the upcall thread for the module. | 82 // Clean up the upcall thread for the module. |
81 NaClThreadJoin(&upcall_thread_); | 83 NaClThreadJoin(&upcall_thread_); |
| 84 // Remove the association between the channel and module id. |
| 85 UnsetModuleIdForSrpcChannel(channel_); |
82 } | 86 } |
83 | 87 |
84 const void* BrowserPpp::GetInterface(const char* interface_name) { | 88 const void* BrowserPpp::GetInterface(const char* interface_name) { |
85 DebugPrintf("BrowserPpp::GetInterface('%s')\n", interface_name); | 89 DebugPrintf("BrowserPpp::GetInterface('%s')\n", interface_name); |
86 int32_t exports_interface_name; | 90 int32_t exports_interface_name; |
87 NaClSrpcError retval = | 91 NaClSrpcError retval = |
88 PppRpcClient::PPP_GetInterface(channel_, | 92 PppRpcClient::PPP_GetInterface(channel_, |
89 const_cast<char*>(interface_name), | 93 const_cast<char*>(interface_name), |
90 &exports_interface_name); | 94 &exports_interface_name); |
91 if (retval != NACL_SRPC_RESULT_OK || !exports_interface_name) { | 95 if (retval != NACL_SRPC_RESULT_OK || !exports_interface_name) { |
92 DebugPrintf(" Interface '%s' not supported\n", interface_name); | 96 DebugPrintf(" Interface '%s' not supported\n", interface_name); |
93 return NULL; | 97 return NULL; |
94 } | 98 } |
95 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) { | 99 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE) == 0) { |
96 DebugPrintf(" Interface '%s' proxied\n", interface_name); | 100 DebugPrintf(" Interface '%s' proxied\n", interface_name); |
97 return reinterpret_cast<const void*>(BrowserInstance::GetInterface()); | 101 return reinterpret_cast<const void*>(BrowserInstance::GetInterface()); |
98 } | 102 } |
99 // TODO(sehr): other interfaces go here. | 103 // TODO(sehr): other interfaces go here. |
100 return NULL; | 104 return NULL; |
101 } | 105 } |
102 | 106 |
103 } // namespace ppapi_proxy | 107 } // namespace ppapi_proxy |
OLD | NEW |