OLD | NEW |
(Empty) | |
| 1 // Copyright 2010 The Native Client SDK Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can |
| 3 // be found in the LICENSE file. |
| 4 |
| 5 #ifndef EXAMPLES_SRPC_DUALITY_SCRIPTABLE_H_ |
| 6 #define EXAMPLES_SRPC_DUALITY_SCRIPTABLE_H_ |
| 7 |
| 8 |
| 9 #include <string.h> |
| 10 |
| 11 #include <nacl/nacl_npapi.h> |
| 12 |
| 13 #include <map> |
| 14 |
| 15 // Extend this class and add object-specific functions and properties to the |
| 16 // method table and property table. |
| 17 class Scriptable { |
| 18 public: |
| 19 Scriptable(); |
| 20 virtual ~Scriptable(); |
| 21 |
| 22 // Ensures that members are initialized. |
| 23 virtual void Init(); |
| 24 |
| 25 bool GetProperty(NPIdentifier name, NPVariant *result); |
| 26 |
| 27 bool HasMethod(NPIdentifier name) const; |
| 28 |
| 29 bool HasProperty(NPIdentifier name) const; |
| 30 |
| 31 bool Invoke(NPIdentifier method_name, |
| 32 const NPVariant* args, |
| 33 uint32_t arg_count, |
| 34 NPVariant* result); |
| 35 |
| 36 bool InvokeDefault(const NPVariant* args, |
| 37 uint32_t arg_count, |
| 38 NPVariant* result); |
| 39 |
| 40 bool RemoveProperty(NPIdentifier name); |
| 41 |
| 42 bool SetProperty(NPIdentifier name, const NPVariant* value); |
| 43 |
| 44 protected: |
| 45 // These can't be scriptable::functions because that would make this |
| 46 // uninheritable. |
| 47 typedef bool (*Method)(Scriptable* instance, |
| 48 const NPVariant* args, |
| 49 uint32_t arg_count, |
| 50 NPVariant* result); |
| 51 typedef bool (*Property)(Scriptable* instance, |
| 52 NPVariant* result); |
| 53 |
| 54 typedef std::map<NPIdentifier, Method> IdentifierToMethodMap; |
| 55 typedef std::map<NPIdentifier, Property> IdentifierToPropertyMap; |
| 56 |
| 57 // Implemented by the final class. |
| 58 virtual void InitializeMethodTable() = 0; |
| 59 // Implemented by the final class. |
| 60 virtual void InitializePropertyTable() = 0; |
| 61 |
| 62 IdentifierToMethodMap * method_table_; |
| 63 IdentifierToPropertyMap * property_table_; |
| 64 }; |
| 65 |
| 66 #endif // EXAMPLES_SRPC_DUALITY_SCRIPTABLE_H_ |
OLD | NEW |