Chromium Code Reviews| 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/plugin_callback.h" | 5 #include "native_client/src/shared/ppapi_proxy/plugin_callback.h" |
| 6 #include <string.h> | |
| 6 #include "srpcgen/ppp_rpc.h" | 7 #include "srpcgen/ppp_rpc.h" |
| 7 | 8 |
| 8 namespace ppapi_proxy { | 9 namespace ppapi_proxy { |
| 9 | 10 |
| 10 CompletionCallbackTable::CompletionCallbackTable() | 11 CompletionCallbackTable::CompletionCallbackTable() |
| 11 : next_id_(1) { | 12 : next_id_(1) { |
| 12 } | 13 } |
| 13 | 14 |
| 14 int32_t CompletionCallbackTable::AddCallback( | 15 int32_t CompletionCallbackTable::AddCallback( |
| 16 const PP_CompletionCallback& callback, | |
| 17 char* read_buffer) { | |
| 18 if (callback.func == NULL) | |
| 19 return 0; | |
| 20 CallbackInfo info = { callback, read_buffer }; | |
| 21 table_[next_id_] = info; | |
| 22 return next_id_++; | |
|
sehr (please use chromium)
2011/01/12 17:49:12
nit: ++next_id_;
polina
2011/01/12 23:44:27
This will return the next id, not the current one,
| |
| 23 } | |
| 24 | |
| 25 int32_t CompletionCallbackTable::AddCallback( | |
| 15 const PP_CompletionCallback& callback) { | 26 const PP_CompletionCallback& callback) { |
| 16 if (callback.func == NULL) | 27 return AddCallback(callback, NULL); |
| 17 return 0; | |
| 18 table_[next_id_] = callback; | |
| 19 return next_id_++; | |
| 20 } | 28 } |
| 21 | 29 |
| 22 PP_CompletionCallback CompletionCallbackTable::RemoveCallback( | 30 PP_CompletionCallback CompletionCallbackTable::RemoveCallback( |
| 23 int32_t callback_id) { | 31 int32_t callback_id, char** read_buffer) { |
| 24 CallbackTable::iterator it = table_.find(callback_id); | 32 CallbackTable::iterator it = table_.find(callback_id); |
| 25 if (table_.end() != it) { | 33 if (table_.end() != it) { |
| 26 PP_CompletionCallback callback = it->second; | 34 CallbackInfo info = it->second; |
| 27 table_.erase(it); | 35 table_.erase(it); |
| 28 return callback; | 36 if (read_buffer != NULL) |
| 37 *read_buffer = info.read_buffer; | |
| 38 return info.callback; | |
| 29 } | 39 } |
| 40 *read_buffer = NULL; | |
| 30 return PP_BlockUntilComplete(); | 41 return PP_BlockUntilComplete(); |
| 31 } | 42 } |
| 32 | 43 |
| 33 } // namespace ppapi_proxy | 44 } // namespace ppapi_proxy |
| 34 | 45 |
| 35 // SRPC-abstraction wrapper around a PP_CompletionCallback. | 46 // SRPC-abstraction wrapper around a PP_CompletionCallback. |
| 36 void CompletionCallbackRpcServer::RunCompletionCallback( | 47 void CompletionCallbackRpcServer::RunCompletionCallback( |
| 37 NaClSrpcRpc* rpc, | 48 NaClSrpcRpc* rpc, |
| 38 NaClSrpcClosure* done, | 49 NaClSrpcClosure* done, |
| 50 // inputs | |
| 39 int32_t callback_id, | 51 int32_t callback_id, |
| 40 int32_t result) { | 52 int32_t result, |
| 53 // TODO(polina): use shm for read buffer | |
| 54 nacl_abi_size_t read_buffer_size, char* read_buffer) { | |
| 41 NaClSrpcClosureRunner runner(done); | 55 NaClSrpcClosureRunner runner(done); |
| 42 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 56 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
| 57 | |
| 58 char* user_buffer; | |
| 43 PP_CompletionCallback callback = | 59 PP_CompletionCallback callback = |
| 44 ppapi_proxy::CompletionCallbackTable::Get()->RemoveCallback(callback_id); | 60 ppapi_proxy::CompletionCallbackTable::Get()->RemoveCallback( |
| 61 callback_id, &user_buffer); | |
| 45 if (callback.func == NULL) | 62 if (callback.func == NULL) |
| 46 return; | 63 return; |
| 64 | |
| 65 if (user_buffer != NULL && read_buffer_size > 0) | |
| 66 memcpy(user_buffer, read_buffer, read_buffer_size); | |
| 47 PP_RunCompletionCallback(&callback, result); | 67 PP_RunCompletionCallback(&callback, result); |
| 68 | |
| 48 rpc->result = NACL_SRPC_RESULT_OK; | 69 rpc->result = NACL_SRPC_RESULT_OK; |
| 49 } | 70 } |
| OLD | NEW |