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

Unified Diff: native_client_sdk/src/examples/hello_world_stdio/hello_world.c

Issue 11592003: Add support for simple run of "main" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Replace missing stdio Created 8 years 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
Index: native_client_sdk/src/examples/hello_world_stdio/hello_world.c
diff --git a/native_client_sdk/src/examples/hello_world_stdio/hello_world.c b/native_client_sdk/src/examples/hello_world_stdio/hello_world.c
index 2771be0ae8c6c86f401d5117ddc98cd8874372e6..0d2faf14b5de91858d687f128bf742e387c2628d 100644
--- a/native_client_sdk/src/examples/hello_world_stdio/hello_world.c
+++ b/native_client_sdk/src/examples/hello_world_stdio/hello_world.c
@@ -1,7 +1,11 @@
+/* Copyright (c) 2012 The Chromium 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 <stdio.h>
#include <string.h>
-
#include "ppapi/c/ppb_var.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/c/ppb_console.h"
@@ -10,49 +14,12 @@
// Have the Module object provided by ppapi_main create a basic
-// PPAPI instance with default arguments to setting up
-// stdio file handles, processing keyboard, etc...
-// PPAPI Instance with default arguments.
+// PPAPI instance with default arguments which mounts the dev
+// file system providing /dev/null, /dev/tty, and /devl/console3
+// for null STDIN, STDOUT directed to PostMessage and STDERR
+// directed to the JavaScript Console with LogLevel 'ERROR'
PPAPI_MAIN_WITH_DEFAULT_ARGS
-static PPB_Messaging* ppb_messaging_interface = NULL;
-static PPB_Var* ppb_var_interface = NULL;
-static PPB_Console* ppb_console_interface = NULL;
-
-
-/**
- * Creates new string PP_Var from C string. The resulting object will be a
- * refcounted string object. It will be AddRef()ed for the caller. When the
- * caller is done with it, it should be Release()d.
- * @param[in] str C string to be converted to PP_Var
- * @return PP_Var containing string.
- */
-static struct PP_Var CStrToVar(const char* str) {
- if (ppb_var_interface != NULL) {
- return ppb_var_interface->VarFromUtf8(str, strlen(str));
- }
- return PP_MakeUndefined();
-}
-
-//
-// Post a message back to JavaScript
-//
-static void SendMessage(const char *str) {
- PP_Instance instance = PPAPI_GetInstanceId();
- if (ppb_messaging_interface)
- ppb_messaging_interface->PostMessage(instance, CStrToVar(str));
-}
-
-//
-// Send a message to the JavaScript Console
-//
-static void LogMessage(const char *str) {
- PP_Instance instance = PPAPI_GetInstanceId();
- if (ppb_console_interface)
- ppb_console_interface->Log(instance, PP_LOGLEVEL_LOG,
- CStrToVar(str));
-}
-
//
// The "main" entry point called by PPAPIInstance once initialization
// takes place. This is called off the main thread, which is hidden
@@ -64,15 +31,20 @@ static void LogMessage(const char *str) {
// Where the embed tag for this module uses KEY=VALUE
//
int ppapi_main(int argc, const char *argv[]) {
- ppb_messaging_interface =
- (PPB_Messaging*) PPAPI_GetInterface(PPB_MESSAGING_INTERFACE);
- ppb_var_interface =
- (PPB_Var*) PPAPI_GetInterface(PPB_VAR_INTERFACE);
- ppb_console_interface =
- (PPB_Console*) PPAPI_GetInterface(PPB_CONSOLE_INTERFACE);
+ int index = 1;
- SendMessage("Hello World STDIO.\n");
- LogMessage("Hello World STDERR.\n");
+ // Use PostMessage to send "Hello World" to JavaScript.
+ printf("Hello World STDIO.\n");
+ // Use PPAPI Console interface to send "Hello World" to the
+ // JavaScript Console.
+ fprintf(stderr, "Hello World STDERR.\n");
+
+ // Print the arguments we received from the web page
+ printf("NAME: %s\n", argv[0]);
+ while (index + 2 < argc) {
+ printf(" ARGS: %s=%s\n", argv[index+0], argv[index+1]);
+ index += 2;
+ }
return 0;
}
« no previous file with comments | « native_client_sdk/src/examples/hello_world_stdio/Makefile ('k') | native_client_sdk/src/libraries/nacl_mounts/kernel_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698