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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « examples/srpc/duality/duality.h ('k') | examples/srpc/duality/duality.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: examples/srpc/duality/duality.cc
===================================================================
--- examples/srpc/duality/duality.cc (revision 0)
+++ examples/srpc/duality/duality.cc (revision 0)
@@ -0,0 +1,52 @@
+// Copyright 2008 The Native Client SDK Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can
+// be found in the LICENSE file.
+
+
+#include <examples/srpc/duality/duality.h>
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <nacl/nacl_npapi.h>
+#include <nacl/nacl_srpc.h>
+
+Duality::Duality()
+ : Scriptable() {
+ printf("Duality: Duality() was called!\n");
+ fflush(stdout);
+}
+
+Duality::~Duality() {
+ printf("Duality: ~Duality() was called!\n");
+ fflush(stdout);
+}
+
+bool Duality::SayHello(Scriptable * instance,
+ const NPVariant* args,
+ uint32_t arg_count,
+ NPVariant* result) {
+ printf("Duality: Duality::SayHello was called via NPAPI!\n");
+ fflush(stdout);
+ if (result) {
+ const char *msg = "Hello from a specialized Scriptable!";
+ const int msg_length = strlen(msg) + 1;
+ // Note: |msg_copy| will be freed later on by the browser, so it needs to
+ // be allocated here with NPN_MemAlloc().
+ char *msg_copy = reinterpret_cast<char*>(NPN_MemAlloc(msg_length));
+ strncpy(msg_copy, msg, msg_length);
+ STRINGN_TO_NPVARIANT(msg_copy, msg_length - 1, *result);
+ }
+ return true;
+}
+
+void Duality::InitializeMethodTable() {
+ printf("Duality: Duality::InitializeMethodTable was called!\n");
+ fflush(stdout);
+ NPIdentifier say_hello_id = NPN_GetStringIdentifier("SayHello");
+ IdentifierToMethodMap::value_type tMethodEntry(say_hello_id,
+ &Duality::SayHello);
+ method_table_->insert(tMethodEntry);
+}
« 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