[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / native_client_sdk / src / getting_started / part2 / hello_tutorial.cc
blob5261a06e46dbd11c042e53dfb9f521492a4bd56e
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/cpp/instance.h"
6 #include "ppapi/cpp/module.h"
7 #include "ppapi/cpp/var.h"
9 namespace {
11 // The expected string sent by the browser.
12 const char* const kHelloString = "hello";
13 // The string sent back to the browser upon receipt of a message
14 // containing "hello".
15 const char* const kReplyString = "hello from NaCl";
17 } // namespace
19 class HelloTutorialInstance : public pp::Instance {
20 public:
21 explicit HelloTutorialInstance(PP_Instance instance)
22 : pp::Instance(instance) {}
23 virtual ~HelloTutorialInstance() {}
25 virtual void HandleMessage(const pp::Var& var_message) {
26 // Ignore the message if it is not a string.
27 if (!var_message.is_string())
28 return;
30 // Get the string message and compare it to "hello".
31 std::string message = var_message.AsString();
32 if (message == kHelloString) {
33 // If it matches, send our response back to JavaScript.
34 pp::Var var_reply(kReplyString);
35 PostMessage(var_reply);
40 class HelloTutorialModule : public pp::Module {
41 public:
42 HelloTutorialModule() : pp::Module() {}
43 virtual ~HelloTutorialModule() {}
45 virtual pp::Instance* CreateInstance(PP_Instance instance) {
46 return new HelloTutorialInstance(instance);
50 namespace pp {
52 Module* CreateModule() {
53 return new HelloTutorialModule();
56 } // namespace pp