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 COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_
12 #define COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_
16 #include "components/nacl/renderer/plugin/service_runtime.h"
17 #include "components/nacl/renderer/plugin/srpc_client.h"
18 #include "native_client/src/include/nacl_macros.h"
19 #include "native_client/src/include/portability.h"
28 // A class representing an instance of a NaCl module, loaded by the plugin.
29 class NaClSubprocess
{
31 NaClSubprocess(const std::string
& description
,
32 ServiceRuntime
* service_runtime
,
33 SrpcClient
* srpc_client
);
34 virtual ~NaClSubprocess();
36 ServiceRuntime
* service_runtime() const { return service_runtime_
.get(); }
37 void set_service_runtime(ServiceRuntime
* service_runtime
) {
38 service_runtime_
.reset(service_runtime
);
41 // The socket used for communicating w/ the NaCl module.
42 SrpcClient
* srpc_client() const { return srpc_client_
.get(); }
44 // A basic description of the subprocess.
45 std::string
description() const { return description_
; }
47 // A detailed description of the subprocess that may contain addresses.
48 // Only use for debugging, but do not expose this to untrusted webapps.
49 std::string
detailed_description() const;
51 // Start up interfaces.
52 bool StartSrpcServices();
54 // Invoke an Srpc Method. |out_params| must be allocated and cleaned up
55 // outside of this function, but it will be initialized by this function, and
56 // on success any out-params (if any) will be placed in |out_params|.
57 // Input types must be listed in |input_signature|, with the actual
58 // arguments passed in as var-args. Returns |true| on success.
59 bool InvokeSrpcMethod(const std::string
& method_name
,
60 const std::string
& input_signature
,
61 SrpcParams
* out_params
,
64 // Fully shut down the subprocess.
68 NACL_DISALLOW_COPY_AND_ASSIGN(NaClSubprocess
);
70 bool VInvokeSrpcMethod(const std::string
& method_name
,
71 const std::string
& signature
,
75 std::string description_
;
77 // The service runtime representing the NaCl module instance.
78 nacl::scoped_ptr
<ServiceRuntime
> service_runtime_
;
79 // Ownership of srpc_client taken from the service runtime.
80 nacl::scoped_ptr
<SrpcClient
> srpc_client_
;
85 #endif // COMPONENTS_NACL_RENDERER_PLUGIN_NACL_SUBPROCESS_H_