OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "native_client/src/trusted/reverse_service/reverse_service.h" | 9 #include "native_client/src/trusted/reverse_service/reverse_service.h" |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 if (NULL == service->reverse_interface()) { | 117 if (NULL == service->reverse_interface()) { |
118 NaClLog(4, "ModuleExitRpc: no reverse_interface. Nothing to do.\n"); | 118 NaClLog(4, "ModuleExitRpc: no reverse_interface. Nothing to do.\n"); |
119 } else { | 119 } else { |
120 NaClLog(4, "ModuleExitRpc: invoking ReportExitStatus\n"); | 120 NaClLog(4, "ModuleExitRpc: invoking ReportExitStatus\n"); |
121 service->reverse_interface()->ReportExitStatus(exit_status); | 121 service->reverse_interface()->ReportExitStatus(exit_status); |
122 } | 122 } |
123 NaClLog(4, "Leaving ModuleExitRpc\n"); | 123 NaClLog(4, "Leaving ModuleExitRpc\n"); |
124 rpc->result = NACL_SRPC_RESULT_OK; | 124 rpc->result = NACL_SRPC_RESULT_OK; |
125 } | 125 } |
126 | 126 |
| 127 void PostMessageRpc(NaClSrpcRpc* rpc, |
| 128 NaClSrpcArg** in_args, |
| 129 NaClSrpcArg** out_args, |
| 130 NaClSrpcClosure* done) { |
| 131 nacl::ReverseService* service = reinterpret_cast<nacl::ReverseService*>( |
| 132 rpc->channel->server_instance_data); |
| 133 char* message = in_args[0]->arrays.carr; |
| 134 nacl_abi_size_t nbytes = in_args[0]->u.count; |
| 135 NaClSrpcClosureRunner on_return(done); |
| 136 |
| 137 NaClLog(4, "Entered PostMessageRpc\n"); |
| 138 if (NULL == service->reverse_interface()) { |
| 139 NaClLog(1, "PostMessage RPC, no reverse_interface. Message: %s\n", |
| 140 message); |
| 141 } else { |
| 142 service->reverse_interface()->PostMessage(std::string(message, nbytes)); |
| 143 } |
| 144 out_args[0]->u.ival = (int32_t) nbytes; |
| 145 NaClLog(4, "Leaving PostMessageRpc\n"); |
| 146 rpc->result = NACL_SRPC_RESULT_OK; |
| 147 } |
| 148 |
127 // Manifest name service, internal APIs. | 149 // Manifest name service, internal APIs. |
128 // | 150 // |
129 // Manifest file lookups result in read-only file descriptors with a | 151 // Manifest file lookups result in read-only file descriptors with a |
130 // handle. When the descriptor is closed, the service runtime must | 152 // handle. When the descriptor is closed, the service runtime must |
131 // inform the plugin of this using the handle, so that the File object | 153 // inform the plugin of this using the handle, so that the File object |
132 // reference can be closed (thereby allowing the browser to delete or | 154 // reference can be closed (thereby allowing the browser to delete or |
133 // otherwise garbage collect the file). Files, being from the | 155 // otherwise garbage collect the file). Files, being from the |
134 // manifest, cannot be deleted. The manifest is also a read-only | 156 // manifest, cannot be deleted. The manifest is also a read-only |
135 // object, so no new entries can be made to it. | 157 // object, so no new entries can be made to it. |
136 // | 158 // |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 // | 287 // |
266 // TODO(bsy): replace with real code. | 288 // TODO(bsy): replace with real code. |
267 out_args[0]->u.ival = 0; // ok | 289 out_args[0]->u.ival = 0; // ok |
268 rpc->result = NACL_SRPC_RESULT_OK; | 290 rpc->result = NACL_SRPC_RESULT_OK; |
269 } | 291 } |
270 | 292 |
271 } // namespace | 293 } // namespace |
272 | 294 |
273 namespace nacl { | 295 namespace nacl { |
274 | 296 |
| 297 // TODO(bsy): this is a temporary cross-repo hack; should be removed |
| 298 // when the interface is made pure virtual again |
| 299 void ReverseInterface::PostMessage(nacl::string message) { |
| 300 NaClLog(0, "ReverseInterface::PostMessage(NACL_OUTPUT_TAG:%s)\n", |
| 301 message.c_str()); |
| 302 } |
| 303 |
275 // need NaClThreadIfFactoryFunction that keeps "this" to do counting | 304 // need NaClThreadIfFactoryFunction that keeps "this" to do counting |
276 | 305 |
277 struct ReverseCountingThreadInterface { | 306 struct ReverseCountingThreadInterface { |
278 struct NaClThreadInterface base NACL_IS_REFCOUNT_SUBCLASS; | 307 struct NaClThreadInterface base NACL_IS_REFCOUNT_SUBCLASS; |
279 nacl::ReverseService* rev; | 308 nacl::ReverseService* rev; |
280 }; | 309 }; |
281 | 310 |
282 /* fwd */ extern NaClThreadInterfaceVtbl const kReverseThreadInterfaceVtbl; | 311 /* fwd */ extern NaClThreadInterfaceVtbl const kReverseThreadInterfaceVtbl; |
283 | 312 |
284 int ReverseThreadIfFactoryFn( | 313 int ReverseThreadIfFactoryFn( |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 ReverseThreadIfLaunchCallback, | 416 ReverseThreadIfLaunchCallback, |
388 ReverseThreadIfExit, | 417 ReverseThreadIfExit, |
389 }; | 418 }; |
390 | 419 |
391 NaClSrpcHandlerDesc const ReverseService::handlers[] = { | 420 NaClSrpcHandlerDesc const ReverseService::handlers[] = { |
392 { NACL_REVERSE_CONTROL_TEST, Test, }, | 421 { NACL_REVERSE_CONTROL_TEST, Test, }, |
393 { NACL_REVERSE_CONTROL_LOG, RevLog, }, | 422 { NACL_REVERSE_CONTROL_LOG, RevLog, }, |
394 { NACL_REVERSE_CONTROL_ADD_CHANNEL, AddChannel, }, | 423 { NACL_REVERSE_CONTROL_ADD_CHANNEL, AddChannel, }, |
395 { NACL_REVERSE_CONTROL_INIT_DONE, ModuleInitDoneRpc, }, | 424 { NACL_REVERSE_CONTROL_INIT_DONE, ModuleInitDoneRpc, }, |
396 { NACL_REVERSE_CONTROL_REPORT_STATUS, ModuleExitRpc, }, | 425 { NACL_REVERSE_CONTROL_REPORT_STATUS, ModuleExitRpc, }, |
| 426 { NACL_REVERSE_CONTROL_POST_MESSAGE, PostMessageRpc, }, |
397 { NACL_MANIFEST_LIST, ManifestListRpc, }, | 427 { NACL_MANIFEST_LIST, ManifestListRpc, }, |
398 { NACL_MANIFEST_LOOKUP, ManifestLookupRpc, }, | 428 { NACL_MANIFEST_LOOKUP, ManifestLookupRpc, }, |
399 { NACL_MANIFEST_UNREF, ManifestUnrefRpc, }, | 429 { NACL_MANIFEST_UNREF, ManifestUnrefRpc, }, |
400 { NULL, NULL, }, | 430 { NULL, NULL, }, |
401 }; | 431 }; |
402 | 432 |
403 ReverseService::ReverseService(nacl::DescWrapper* conn_cap, | 433 ReverseService::ReverseService(nacl::DescWrapper* conn_cap, |
404 ReverseInterface* rif) | 434 ReverseInterface* rif) |
405 : service_socket_(NULL), | 435 : service_socket_(NULL), |
406 reverse_interface_(rif), | 436 reverse_interface_(rif), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 ("ReverseService::DecrThreadCount:" | 508 ("ReverseService::DecrThreadCount:" |
479 " Decrementing thread count when count is zero\n")); | 509 " Decrementing thread count when count is zero\n")); |
480 } | 510 } |
481 if (0 == --thread_count_) { | 511 if (0 == --thread_count_) { |
482 NaClXCondVarBroadcast(&cv_); | 512 NaClXCondVarBroadcast(&cv_); |
483 } | 513 } |
484 NaClXMutexUnlock(&mu_); | 514 NaClXMutexUnlock(&mu_); |
485 } | 515 } |
486 | 516 |
487 } // namespace nacl | 517 } // namespace nacl |
OLD | NEW |