OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Instances of NaCl modules spun up within the plugin as a subprocess. | |
6 // This may represent the "main" nacl module, or it may represent helpers | |
7 // that perform various tasks within the plugin, for example, | |
8 // a NaCl module for a compiler could be loaded to translate LLVM bitcode | |
9 // into native code. | |
10 | |
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ | |
12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ | |
13 | |
14 #include <stdarg.h> | |
15 | |
16 #include "native_client/src/include/nacl_macros.h" | |
17 #include "native_client/src/include/portability.h" | |
18 | |
19 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h" | |
20 #include "ppapi/native_client/src/trusted/plugin/srpc_client.h" | |
21 | |
22 namespace plugin { | |
23 | |
24 class Plugin; | |
25 class ServiceRuntime; | |
26 class SrpcParams; | |
27 | |
28 | |
29 // A class representing an instance of a NaCl module, loaded by the plugin. | |
30 class NaClSubprocess { | |
31 public: | |
32 NaClSubprocess(const std::string& description, | |
33 ServiceRuntime* service_runtime, | |
34 SrpcClient* srpc_client); | |
35 virtual ~NaClSubprocess(); | |
36 | |
37 ServiceRuntime* service_runtime() const { return service_runtime_.get(); } | |
38 void set_service_runtime(ServiceRuntime* service_runtime) { | |
39 service_runtime_.reset(service_runtime); | |
40 } | |
41 | |
42 // The socket used for communicating w/ the NaCl module. | |
43 SrpcClient* srpc_client() const { return srpc_client_.get(); } | |
44 | |
45 // A basic description of the subprocess. | |
46 std::string description() const { return description_; } | |
47 | |
48 // A detailed description of the subprocess that may contain addresses. | |
49 // Only use for debugging, but do not expose this to untrusted webapps. | |
50 std::string detailed_description() const; | |
51 | |
52 // Start up interfaces. | |
53 bool StartSrpcServices(); | |
54 | |
55 // Invoke an Srpc Method. |out_params| must be allocated and cleaned up | |
56 // outside of this function, but it will be initialized by this function, and | |
57 // on success any out-params (if any) will be placed in |out_params|. | |
58 // Input types must be listed in |input_signature|, with the actual | |
59 // arguments passed in as var-args. Returns |true| on success. | |
60 bool InvokeSrpcMethod(const std::string& method_name, | |
61 const std::string& input_signature, | |
62 SrpcParams* out_params, | |
63 ...); | |
64 | |
65 // Fully shut down the subprocess. | |
66 void Shutdown(); | |
67 | |
68 private: | |
69 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess); | |
70 | |
71 bool VInvokeSrpcMethod(const std::string& method_name, | |
72 const std::string& signature, | |
73 SrpcParams* params, | |
74 va_list vl); | |
75 | |
76 std::string description_; | |
77 | |
78 // The service runtime representing the NaCl module instance. | |
79 nacl::scoped_ptr<ServiceRuntime> service_runtime_; | |
80 // Ownership of srpc_client taken from the service runtime. | |
81 nacl::scoped_ptr<SrpcClient> srpc_client_; | |
82 }; | |
83 | |
84 } // namespace plugin | |
85 | |
86 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_ | |
OLD | NEW |