Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/method_map.h

Issue 9390028: Remove browser support for non-PPAPI nexes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 // Lookup table types for method dispatching.
6
7 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_METHOD_MAP_H
8 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_METHOD_MAP_H
9
10 #include <limits.h>
11 #include <map>
12 #include <vector>
13
14 #include "native_client/src/include/nacl_macros.h"
15 #include "native_client/src/include/portability_string.h"
16 #include "native_client/src/shared/srpc/nacl_srpc.h"
17
18 namespace plugin {
19
20 bool InitSrpcArgArray(NaClSrpcArg* arr, int size);
21 void FreeSrpcArg(NaClSrpcArg* arg);
22
23 // A utility class that builds and deletes parameter vectors used in rpcs.
24 class SrpcParams {
25 public:
26 SrpcParams() : exception_string_(NULL) {
27 memset(ins_, 0, sizeof(ins_));
28 memset(outs_, 0, sizeof(outs_));
29 }
30
31 SrpcParams(const char* in_types, const char* out_types)
32 : exception_string_(NULL) {
33 if (!Init(in_types, out_types)) {
34 FreeAll();
35 }
36 }
37
38 ~SrpcParams() {
39 FreeAll();
40 free(exception_string_);
41 }
42
43 bool Init(const char* in_types, const char* out_types);
44 uint32_t SignatureLength() const;
45 uint32_t InputLength() const;
46 uint32_t OutputLength() const;
47
48 NaClSrpcArg** ins() const { return const_cast<NaClSrpcArg**>(ins_); }
49 NaClSrpcArg** outs() const { return const_cast<NaClSrpcArg**>(outs_); }
50
51 char* exception_string() const { return exception_string_; }
52 void set_exception_string(const char* msg) {
53 exception_string_ = STRDUP(msg);
54 }
55
56 private:
57 NACL_DISALLOW_COPY_AND_ASSIGN(SrpcParams);
58 void FreeAll();
59 bool FillVec(NaClSrpcArg* vec[], const char* types);
60 void FreeArguments(NaClSrpcArg* vec[]);
61 // The ins_ and outs_ arrays contain one more element, to hold a NULL pointer
62 // to indicate the end of the list.
63 NaClSrpcArg* ins_[NACL_SRPC_MAX_ARGS + 1];
64 NaClSrpcArg* outs_[NACL_SRPC_MAX_ARGS + 1];
65 char* exception_string_;
66 };
67
68 typedef bool (*RpcFunction)(void* obj, SrpcParams* params);
69
70 // MethodInfo records the method names and type signatures of an SRPC server.
71 class MethodInfo {
72 public:
73 // statically defined method - called through a pointer
74 MethodInfo(const RpcFunction function_ptr,
75 const char* name,
76 const char* ins,
77 const char* outs,
78 // index is set to UINT_MAX for methods implemented by the plugin,
79 // All methods implemented by nacl modules have indexes
80 // that are lower than UINT_MAX.
81 const uint32_t index = UINT_MAX) :
82 function_ptr_(function_ptr),
83 name_(STRDUP(name)),
84 ins_(STRDUP(ins)),
85 outs_(STRDUP(outs)),
86 index_(index) { }
87 ~MethodInfo();
88
89 RpcFunction function_ptr() const { return function_ptr_; }
90 char* name() const { return name_; }
91 char* ins() const { return ins_; }
92 char* outs() const { return outs_; }
93 uint32_t index() const { return index_; }
94
95 private:
96 NACL_DISALLOW_COPY_AND_ASSIGN(MethodInfo);
97 RpcFunction function_ptr_;
98 char* name_;
99 char* ins_;
100 char* outs_;
101 uint32_t index_;
102 };
103
104 class MethodMap {
105 public:
106 MethodMap() {}
107 ~MethodMap();
108 MethodInfo* GetMethod(uintptr_t method_id);
109 void AddMethod(uintptr_t method_id, MethodInfo* info);
110
111 typedef std::vector<uintptr_t> MethodMapKeys;
112 MethodMapKeys* Keys() { return &method_map_keys_; }
113
114 private:
115 NACL_DISALLOW_COPY_AND_ASSIGN(MethodMap);
116 typedef std::map<uintptr_t, MethodInfo*> MethodMapStorage;
117 MethodMapStorage method_map_;
118 MethodMapKeys method_map_keys_;
119 };
120
121 } // namespace plugin
122
123 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_METHOD_MAP_H
OLDNEW
« no previous file with comments | « ppapi/native_client/src/trusted/plugin/desc_based_handle.cc ('k') | ppapi/native_client/src/trusted/plugin/method_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698