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

Side by Side Diff: examples/srpc/duality/duality.cc

Issue 2856050: Adding srpc example to naclports. (Closed) Base URL: http://naclports.googlecode.com/svn/trunk/src/
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 | « examples/srpc/duality/duality.h ('k') | examples/srpc/duality/duality.html » ('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 // 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 }
OLDNEW
« no previous file with comments | « examples/srpc/duality/duality.h ('k') | examples/srpc/duality/duality.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698