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

Side by Side Diff: src/trusted/plugin/srpc/method_map.h

Issue 2981011: Move plugin/srpc contents to the more appropriately named plugin/common.... (Closed) Base URL: http://nativeclient.googlecode.com/svn/trunk/src/native_client/
Patch Set: '' Created 10 years, 5 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
« no previous file with comments | « src/trusted/plugin/srpc/desc_based_handle.cc ('k') | src/trusted/plugin/srpc/method_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2008 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can
4 * be found in the LICENSE file.
5 */
6
7 // Lookup table types for method dispatching.
8
9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_METHOD_MAP_H
10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_METHOD_MAP_H
11
12 #include "native_client/src/include/nacl_macros.h"
13 #include "native_client/src/include/portability_string.h"
14 #include "native_client/src/shared/srpc/nacl_srpc.h"
15
16 #include <limits.h>
17 #include <map>
18
19 namespace plugin {
20
21 class Plugin;
22
23 bool InitSrpcArgArray(NaClSrpcArg* arr, int size);
24 void FreeSrpcArg(NaClSrpcArg* arg);
25
26 // A utility class that builds and deletes parameter vectors used in rpcs.
27 class SrpcParams {
28 public:
29 SrpcParams() : exception_string_(NULL) {
30 memset(ins_, 0, sizeof(ins_));
31 memset(outs_, 0, sizeof(outs_));
32 }
33
34 SrpcParams(const char* in_types, const char* out_types)
35 : exception_string_(NULL) {
36 if (!Init(in_types, out_types)) {
37 FreeAll();
38 }
39 }
40
41 ~SrpcParams() {
42 FreeAll();
43 free(exception_string_);
44 }
45
46 bool Init(const char* in_types, const char* out_types);
47 uint32_t SignatureLength() const;
48 uint32_t OutputLength() const;
49
50 NaClSrpcArg** ins() const { return const_cast<NaClSrpcArg**>(ins_); }
51 NaClSrpcArg** outs() const { return const_cast<NaClSrpcArg**>(outs_); }
52
53 char* exception_string() const { return exception_string_; }
54 void set_exception_string(const char* msg) {
55 exception_string_ = STRDUP(msg);
56 }
57
58 private:
59 NACL_DISALLOW_COPY_AND_ASSIGN(SrpcParams);
60 void FreeAll();
61 bool FillVec(NaClSrpcArg* vec[], const char* types);
62 void FreeArguments(NaClSrpcArg* vec[]);
63 // The ins_ and outs_ arrays contain one more element, to hold a NULL pointer
64 // to indicate the end of the list.
65 NaClSrpcArg* ins_[NACL_SRPC_MAX_ARGS + 1];
66 NaClSrpcArg* outs_[NACL_SRPC_MAX_ARGS + 1];
67 char* exception_string_;
68 };
69
70 typedef bool (*RpcFunction)(void* obj, SrpcParams* params);
71
72 // MethodInfo records the method names and type signatures of an SRPC server.
73 class MethodInfo {
74 public:
75 // statically defined method - called through a pointer
76 MethodInfo(const RpcFunction function_ptr,
77 const char* name,
78 const char* ins,
79 const char* outs,
80 // index is set to UINT_MAX for methods implemented by the plugin,
81 // All methods implemented by nacl modules have indexes
82 // that are lower than UINT_MAX.
83 const uint32_t index = UINT_MAX) :
84 function_ptr_(function_ptr),
85 name_(STRDUP(name)),
86 ins_(STRDUP(ins)),
87 outs_(STRDUP(outs)),
88 index_(index) { }
89 ~MethodInfo();
90
91 RpcFunction function_ptr() const { return function_ptr_; }
92 char* name() const { return name_; }
93 char* ins() const { return ins_; }
94 char* outs() const { return outs_; }
95 uint32_t index() const { return index_; }
96
97 private:
98 NACL_DISALLOW_COPY_AND_ASSIGN(MethodInfo);
99 RpcFunction function_ptr_;
100 char* name_;
101 char* ins_;
102 char* outs_;
103 uint32_t index_;
104 };
105
106 class MethodMap {
107 public:
108 MethodMap() {}
109 ~MethodMap();
110 MethodInfo* GetMethod(uintptr_t method_id);
111 void AddMethod(uintptr_t method_id, MethodInfo* info);
112
113 private:
114 NACL_DISALLOW_COPY_AND_ASSIGN(MethodMap);
115 typedef std::map<uintptr_t, MethodInfo*> MethodMapStorage;
116 MethodMapStorage method_map_;
117 };
118
119 } // namespace plugin
120
121 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_SRPC_METHOD_MAP_H
OLDNEW
« no previous file with comments | « src/trusted/plugin/srpc/desc_based_handle.cc ('k') | src/trusted/plugin/srpc/method_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698