summaryrefslogtreecommitdiffstats
path: root/ppapi/native_client/src/trusted/plugin/srpc_client.h
blob: 072c263a19cf0b35a02265238b2f49ebf7dae206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 2012 The Chromium Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

// A representation of an SRPC connection.  These can be either to the
// service runtime or to untrusted NaCl threads.

#ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLIENT_H_
#define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLIENT_H_

#include <map>
#include "native_client/src/include/nacl_macros.h"
#include "native_client/src/include/nacl_string.h"
#include "native_client/src/trusted/plugin/utility.h"
#include "native_client/src/shared/srpc/nacl_srpc.h"

namespace nacl {
class DescWrapper;
}  // namespace nacl

namespace plugin {

class ErrorInfo;
class MethodInfo;
class Plugin;
class SrpcParams;

//  SrpcClient represents an SRPC connection to a client.
class SrpcClient {
 public:
  // Factory method for creating SrpcClients.
  static SrpcClient* New(nacl::DescWrapper* wrapper);

  //  Init is passed a DescWrapper.  The SrpcClient performs service
  //  discovery and provides the interface for future rpcs.
  bool Init(nacl::DescWrapper* socket);

  //  The destructor closes the connection to sel_ldr.
  ~SrpcClient();

  bool StartJSObjectProxy(Plugin* plugin, ErrorInfo* error_info);
  //  Test whether the SRPC service has a given method.
  bool HasMethod(const nacl::string& method_name);
  //  Invoke an SRPC method.
  bool Invoke(const nacl::string& method_name, SrpcParams* params);
  // Get the error status from that last method invocation
  NaClSrpcError GetLastError() { return last_error_; }
  bool InitParams(const nacl::string& method_name, SrpcParams* params);

  // Attach a service for reverse-direction (from .nexe) RPCs.
  void AttachService(NaClSrpcService* service, void* instance_data);

 private:
  NACL_DISALLOW_COPY_AND_ASSIGN(SrpcClient);
  SrpcClient();
  void GetMethods();
  typedef std::map<nacl::string, MethodInfo*> Methods;
  Methods methods_;
  NaClSrpcChannel srpc_channel_;
  bool srpc_channel_initialised_;
  NaClSrpcError last_error_;
};

}  // namespace plugin

#endif  // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_CLIENT_H_