From f9a7a34abb8e2d069a44e07e70a22b9bc79efb72 Mon Sep 17 00:00:00 2001
From: "noelallen@google.com"
Date: Sat, 15 Dec 2012 02:35:26 +0000
Subject: Support a simple "main" view of PPAPI
Add ppapi_main and hello_world_stdio
Automatically call 'main' after initialization
Mount /dev/console /dev/tty to support STDIN,STDOUT,STDERR
R=binji@chromium.org
BUG=165626
Review URL: https://codereview.chromium.org/11519028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173260 0039d316-1c4b-4281-b951-d872f2087c98
---
native_client_sdk/src/build_tools/build_sdk.py | 5 +-
.../src/build_tools/generate_index.py | 12 +-
native_client_sdk/src/build_tools/generate_make.py | 6 +-
.../src/examples/hello_world/example.js | 24 ++
.../src/examples/hello_world/hello_world.c | 29 ++-
.../src/examples/hello_world/index.html | 15 ++
.../src/examples/hello_world_stdio/Makefile | 61 ++++++
.../src/examples/hello_world_stdio/example.dsc | 35 +++
.../src/examples/hello_world_stdio/example.js | 24 ++
.../src/examples/hello_world_stdio/hello_world.c | 78 +++++++
.../src/examples/hello_world_stdio/index.html | 37 ++++
.../src/libraries/ppapi_main/library.dsc | 27 +++
.../src/libraries/ppapi_main/ppapi_instance.cc | 169 ++++++++++++++
.../src/libraries/ppapi_main/ppapi_instance.h | 50 +++++
.../src/libraries/ppapi_main/ppapi_main.cc | 58 +++++
.../src/libraries/ppapi_main/ppapi_main.h | 53 +++++
native_client_sdk/src/tools/common.mk | 242 +++++++++++++++++++++
17 files changed, 916 insertions(+), 9 deletions(-)
create mode 100644 native_client_sdk/src/examples/hello_world/example.js
create mode 100644 native_client_sdk/src/examples/hello_world_stdio/Makefile
create mode 100644 native_client_sdk/src/examples/hello_world_stdio/example.dsc
create mode 100644 native_client_sdk/src/examples/hello_world_stdio/example.js
create mode 100644 native_client_sdk/src/examples/hello_world_stdio/hello_world.c
create mode 100644 native_client_sdk/src/examples/hello_world_stdio/index.html
create mode 100644 native_client_sdk/src/libraries/ppapi_main/library.dsc
create mode 100644 native_client_sdk/src/libraries/ppapi_main/ppapi_instance.cc
create mode 100644 native_client_sdk/src/libraries/ppapi_main/ppapi_instance.h
create mode 100644 native_client_sdk/src/libraries/ppapi_main/ppapi_main.cc
create mode 100644 native_client_sdk/src/libraries/ppapi_main/ppapi_main.h
create mode 100644 native_client_sdk/src/tools/common.mk
(limited to 'native_client_sdk')
diff --git a/native_client_sdk/src/build_tools/build_sdk.py b/native_client_sdk/src/build_tools/build_sdk.py
index 283396930..a577475 100755
--- a/native_client_sdk/src/build_tools/build_sdk.py
+++ b/native_client_sdk/src/build_tools/build_sdk.py
@@ -602,6 +602,7 @@ EXAMPLE_LIST = [
'gamepad',
'geturl',
'hello_nacl_mounts',
+ 'hello_world_stdio',
'hello_world',
'hello_world_gles',
'hello_world_interactive',
@@ -619,6 +620,7 @@ LIBRARY_LIST = [
'ppapi',
'ppapi_cpp',
'ppapi_gles2',
+ 'ppapi_main',
'pthread',
'zlib',
]
@@ -666,7 +668,8 @@ def BuildStepCopyExamples(pepperdir, toolchains, build_experimental, clobber):
# Copy individual files
files = ['favicon.ico', 'httpd.cmd']
for filename in files:
- oshelpers.Copy(['-v', os.path.join(SDK_EXAMPLE_DIR, filename), exampledir])
+ oshelpers.Copy(['-v', os.path.join(SDK_EXAMPLE_DIR, filename),
+ exampledir])
args = ['--dstroot=%s' % pepperdir, '--master']
for toolchain in toolchains:
diff --git a/native_client_sdk/src/build_tools/generate_index.py b/native_client_sdk/src/build_tools/generate_index.py
index d733162..5bfe23a 100644
--- a/native_client_sdk/src/build_tools/generate_index.py
+++ b/native_client_sdk/src/build_tools/generate_index.py
@@ -57,10 +57,14 @@ mulithreading...
""",
'Tools': """
Using the Tools
-The following "hello_world" examples, show the basic outline of a Native
-Client application. The make files in each of the examples below show a
-simple way to build a NaCl application using
-GNU Make.
+
The following "hello_world" examples, show the basic outline of a
+several types of Native Client applications. The simplest, "Hello World Stdio"
+uses several provided libraries to simplify startup and provides a
+simplified make showing a single build configuration. The other examples in
+this SDK however, are designed to build and run with multiple toolsets, build
+configurations, etc...
+making the build much more complex. In all cases we are using GNU Make.
See the link for further information.
""",
diff --git a/native_client_sdk/src/build_tools/generate_make.py b/native_client_sdk/src/build_tools/generate_make.py
index 786a1e7..af3f839 100755
--- a/native_client_sdk/src/build_tools/generate_make.py
+++ b/native_client_sdk/src/build_tools/generate_make.py
@@ -217,7 +217,8 @@ DSC_FORMAT = {
'DEFINES': (list, '', False),
'LDFLAGS': (list, '', False),
'INCLUDES': (list, '', False),
- 'LIBS' : (list, '', False)
+ 'LIBS' : (list, '', False),
+ 'DEPS' : (list, '', False)
}, True),
'HEADERS': (list, {
'FILES': (list, '', True),
@@ -500,7 +501,8 @@ def ProcessProject(srcroot, dstroot, desc, toolchains):
# Add Makefile and make.bat
repdict = GenerateReplacements(desc, tools)
- WriteReplaced(template, make_path, repdict)
+ if not 'Makefile' in desc.get('DATA', []):
+ WriteReplaced(template, make_path, repdict)
outdir = os.path.dirname(os.path.abspath(make_path))
pepperdir = os.path.dirname(os.path.dirname(outdir))
diff --git a/native_client_sdk/src/examples/hello_world/example.js b/native_client_sdk/src/examples/hello_world/example.js
new file mode 100644
index 0000000..13a9997
--- /dev/null
+++ b/native_client_sdk/src/examples/hello_world/example.js
@@ -0,0 +1,24 @@
+// 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.
+
+var kMaxArraySize = 20;
+var messageArray = new Array();
+
+// Once we load, hide the plugin
+function moduleDidLoad() {
+ common.hideModule();
+}
+
+// Called by the common.js module.
+function handleMessage(message) {
+ // Show last |kMaxArraySize| events in html.
+ messageArray.push(message.data);
+ if (messageArray.length > kMaxArraySize) {
+ messageArray.shift();
+ }
+ var newData = messageArray.join('
');
+ document.getElementById('outputString').innerHTML = newData;
+ // Print event to console.
+ console.log(message.data);
+}
diff --git a/native_client_sdk/src/examples/hello_world/hello_world.c b/native_client_sdk/src/examples/hello_world/hello_world.c
index bbd0693..2d1666e 100644
--- a/native_client_sdk/src/examples/hello_world/hello_world.c
+++ b/native_client_sdk/src/examples/hello_world/hello_world.c
@@ -15,6 +15,7 @@
#include "ppapi/c/pp_module.h"
#include "ppapi/c/pp_var.h"
#include "ppapi/c/ppb.h"
+#include "ppapi/c/ppb_console.h"
#include "ppapi/c/ppb_instance.h"
#include "ppapi/c/ppb_messaging.h"
#include "ppapi/c/ppb_var.h"
@@ -34,6 +35,7 @@
#define TCNAME "host"
#endif
+static PPB_Console* ppb_console_interface = NULL;
static PPB_Messaging* ppb_messaging_interface = NULL;
static PPB_Var* ppb_var_interface = NULL;
@@ -54,6 +56,23 @@ static struct PP_Var CStrToVar(const char* str) {
/**
+ * Post a message back to our JavaScript
+ */
+static void SendMessage(PP_Instance instance, const char *str) {
+ if (ppb_messaging_interface)
+ ppb_messaging_interface->PostMessage(instance, CStrToVar(str));
+}
+
+/**
+ * Send a message to the JavaScript Console
+ */
+static void LogMessage(PP_Instance instance, const char *str) {
+ if (ppb_console_interface)
+ ppb_console_interface->Log(instance, PP_LOGLEVEL_ERROR,
+ CStrToVar(str));
+}
+
+/**
* Called when the NaCl module is instantiated on the web page. The identifier
* of the new instance will be passed in as the first argument (this value is
* generated by the browser and is an opaque handle). This is called for each
@@ -80,8 +99,12 @@ static PP_Bool Instance_DidCreate(PP_Instance instance,
const char* argn[],
const char* argv[]) {
- const char* message = "alert:Hello World (" TCNAME ")!";
- ppb_messaging_interface->PostMessage(instance, CStrToVar(message));
+ const char* post_msg = "Hello World (" TCNAME ")!";
+ const char* console_msg = "Hello World (JavsScript Console)!";
+
+ SendMessage(instance, post_msg);
+ LogMessage(instance, console_msg);
+
return PP_TRUE;
}
@@ -160,6 +183,8 @@ static PP_Bool Instance_HandleDocumentLoad(PP_Instance instance,
*/
PP_EXPORT int32_t PPP_InitializeModule(PP_Module a_module_id,
PPB_GetInterface get_browser) {
+ ppb_console_interface =
+ (PPB_Console*)(get_browser(PPB_CONSOLE_INTERFACE));
ppb_messaging_interface =
(PPB_Messaging*)(get_browser(PPB_MESSAGING_INTERFACE));
ppb_var_interface = (PPB_Var*)(get_browser(PPB_VAR_INTERFACE));
diff --git a/native_client_sdk/src/examples/hello_world/index.html b/native_client_sdk/src/examples/hello_world/index.html
index 5b20825..3fc523d 100644
--- a/native_client_sdk/src/examples/hello_world/index.html
+++ b/native_client_sdk/src/examples/hello_world/index.html
@@ -10,12 +10,27 @@ found in the LICENSE file.
+
Status: NO-STATUS
+ This example demonstrates a complete NaCl PPAPI application. In
+source file hello_world.c contains the three required PPAPI functions
+ PPP_InitializeModule, PPP_GetInterface, PPP_ShutdownModule which initialize
+the application, provide a string name to callback interface mapping, and
+cleanup on shutdown respectively.
+ The example will query for the Console, PostMessage and Var interfaces to
+send a message to JavaScript which will be added to the output box. In
+addition, it will send another message to the JavaScript Console to simulate
+logging for development.
+
+ OUTPUT
+
+
+