OLD | NEW |
(Empty) | |
| 1 // Copyright 2008 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 |
| 6 #include <examples/srpc/duality/duality.h> |
| 7 |
| 8 #include <stdbool.h> |
| 9 #include <stdio.h> |
| 10 #include <stdlib.h> |
| 11 #include <string.h> |
| 12 |
| 13 #include <nacl/nacl_npapi.h> |
| 14 #include <nacl/nacl_srpc.h> |
| 15 |
| 16 Duality::Duality() |
| 17 : Scriptable() { |
| 18 printf("Duality: Duality() was called!\n"); |
| 19 fflush(stdout); |
| 20 } |
| 21 |
| 22 Duality::~Duality() { |
| 23 printf("Duality: ~Duality() was called!\n"); |
| 24 fflush(stdout); |
| 25 } |
| 26 |
| 27 bool Duality::SayHello(Scriptable * instance, |
| 28 const NPVariant* args, |
| 29 uint32_t arg_count, |
| 30 NPVariant* result) { |
| 31 printf("Duality: Duality::SayHello was called via NPAPI!\n"); |
| 32 fflush(stdout); |
| 33 if (result) { |
| 34 const char *msg = "Hello from a specialized Scriptable!"; |
| 35 const int msg_length = strlen(msg) + 1; |
| 36 // Note: |msg_copy| will be freed later on by the browser, so it needs to |
| 37 // be allocated here with NPN_MemAlloc(). |
| 38 char *msg_copy = reinterpret_cast<char*>(NPN_MemAlloc(msg_length)); |
| 39 strncpy(msg_copy, msg, msg_length); |
| 40 STRINGN_TO_NPVARIANT(msg_copy, msg_length - 1, *result); |
| 41 } |
| 42 return true; |
| 43 } |
| 44 |
| 45 void Duality::InitializeMethodTable() { |
| 46 printf("Duality: Duality::InitializeMethodTable was called!\n"); |
| 47 fflush(stdout); |
| 48 NPIdentifier say_hello_id = NPN_GetStringIdentifier("SayHello"); |
| 49 IdentifierToMethodMap::value_type tMethodEntry(say_hello_id, |
| 50 &Duality::SayHello); |
| 51 method_table_->insert(tMethodEntry); |
| 52 } |
OLD | NEW |