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.
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
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_
12 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_
16 #include "native_client/src/include/nacl_macros.h"
17 #include "native_client/src/include/nacl_string.h"
18 #include "native_client/src/include/portability.h"
20 #include "ppapi/native_client/src/trusted/plugin/service_runtime.h"
21 #include "ppapi/native_client/src/trusted/plugin/srpc_client.h"
30 // A class representing an instance of a NaCl module, loaded by the plugin.
31 class NaClSubprocess
{
33 NaClSubprocess(const nacl::string
& description
,
34 ServiceRuntime
* service_runtime
,
35 SrpcClient
* srpc_client
)
36 : description_(description
),
37 service_runtime_(service_runtime
),
38 srpc_client_(srpc_client
) {
40 virtual ~NaClSubprocess();
42 ServiceRuntime
* service_runtime() const { return service_runtime_
.get(); }
43 void set_service_runtime(ServiceRuntime
* service_runtime
) {
44 service_runtime_
.reset(service_runtime
);
47 // The socket used for communicating w/ the NaCl module.
48 SrpcClient
* srpc_client() const { return srpc_client_
.get(); }
50 // A basic description of the subprocess.
51 nacl::string
description() const { return description_
; }
53 // A detailed description of the subprocess that may contain addresses.
54 // Only use for debugging, but do not expose this to untrusted webapps.
55 nacl::string
detailed_description() const;
57 // Start up interfaces.
58 bool StartSrpcServices();
60 // Invoke an Srpc Method. |out_params| must be allocated and cleaned up
61 // outside of this function, but it will be initialized by this function, and
62 // on success any out-params (if any) will be placed in |out_params|.
63 // Input types must be listed in |input_signature|, with the actual
64 // arguments passed in as var-args. Returns |true| on success.
65 bool InvokeSrpcMethod(const nacl::string
& method_name
,
66 const nacl::string
& input_signature
,
67 SrpcParams
* out_params
,
70 // Fully shut down the subprocess.
74 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess
);
76 bool VInvokeSrpcMethod(const nacl::string
& method_name
,
77 const nacl::string
& signature
,
81 nacl::string description_
;
83 // The service runtime representing the NaCl module instance.
84 nacl::scoped_ptr
<ServiceRuntime
> service_runtime_
;
85 // Ownership of srpc_client taken from the service runtime.
86 nacl::scoped_ptr
<SrpcClient
> srpc_client_
;
91 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_NACL_SUBPROCESS_H_