void eUSPInstance::HandleMessage(const pp::Var& _m)
{
	if(!_m.is_string())
		return;
	string m = _m.AsString();
	if(m == "run")
	{
		xPlatform::Handler()->OnInit();
		inited = true;
		Update();
		audio.Play();
		PostMessage("ready");
	}
	if(!inited)
		return;
	static const string open("open:");
	static const string joystick("joystick:");
	if(m.length() > open.length() && m.substr(0, open.length()) == open)
	{
		string url = m.substr(open.length());
		new eURLLoader(this, url, this);
	}
	else if(m.length() > joystick.length() && m.substr(0, joystick.length()) == joystick)
	{
		using namespace xOptions;
		string joy = m.substr(joystick.length());
		eOption<int>* op_joy = eOption<int>::Find("joystick");
		SAFE_CALL(op_joy)->Value(joy.c_str());
	}
	else if(m == "reset")
	{
		Handler()->OnAction(A_RESET);
	}
}
Example #2
0
        /* when the browser does paintownModule.postMessage('run') this will
         * get executed.
         */
        virtual void HandleMessage(const pp::Var& var_message){
            if (!var_message.is_string()){
                return;
            }

            std::string message = var_message.AsString();
            if (message == "run"){
                run();
            }
        }
Example #3
0
pp::Var WiScriptableObject::Call(const pp::Var& method,
                                           const std::vector<pp::Var>& args,
                                           pp::Var* exception) {
  if (!method.is_string()) {
    return pp::Var();
  }
  std::string method_name = method.AsString();
  // TODO(sdk_user): 4. Make this function call whatever method has method_name
  // as its method ID.
  return pp::Var();
}
Example #4
0
bool WiScriptableObject::HasMethod(const pp::Var& method,
                                             pp::Var* exception) {
  if (!method.is_string()) {
    return false;
  }
  std::string method_name = method.AsString();
  // TODO(sdk_user): 3. Make this function return true iff method_name is equal
  // to any of your method IDs.
  bool has_method = false;
  return has_method;
}
Example #5
0
void HelloWorldInstance::HandleMessage(const pp::Var& var_message) {
  if (!var_message.is_string()) {
    return;
  }

  // Post the return result back to the browser.  Note that HandleMessage() is
  // always called on the main thread, so it's OK to post the return message
  // directly from here.  The return post is asynhronous: PostMessage returns
  // immediately.

  //PostMessage(return_var);
}
Example #6
0
  /// Handler for messages coming in from the browser via postMessage().  The
  /// @a var_message can contain anything: a JSON string; a string that encodes
  /// method names and arguments; etc.  For example, you could use
  /// JSON.stringify in the browser to create a message that contains a method
  /// name and some parameters, something like this:
  ///   var json_message = JSON.stringify({ "myMethod" : "3.14159" });
  ///   nacl_module.postMessage(json_message);
  /// On receipt of this message in @a var_message, you could parse the JSON to
  /// retrieve the method name, match it to a function call, and then call it
  /// with the parameter.
  /// @param[in] var_message The message posted by the browser.
  virtual void HandleMessage(const pp::Var& var_message) {
    if (!var_message.is_string())
        return;

    std::string message = var_message.AsString();
    pp::Var var_reply;
    if (message == kBenchString) {
      bench();
      var_reply = pp::Var(kReplyString);
      PostMessage(var_reply);
    }
  }
Example #7
0
static Variant to_variant(const pp::Var& p_var) {

	if (p_var.is_undefined() || p_var.is_null())
		return Variant();
	if (p_var.is_bool())
		return Variant(p_var.AsBool());
	if (p_var.is_double())
		return Variant(p_var.AsDouble());
	if (p_var.is_int())
		return Variant((int64_t)p_var.AsInt());
	if (p_var.is_string())
		return Variant(String::utf8(p_var.AsString().c_str()));

	return Variant();
};
Example #8
0
void DiagrammarInterface::HandleMessage(const pp::Var& var_message) {
  // Ignore the message if it is not a string.
  if (!var_message.is_string()) return;

  // Get the string message and compare it to "hello".
  std::string message = var_message.AsString();
  if (message == "hello") {
    // If it matches, send our response back to JavaScript.
    pp::Var var_reply("running");
    PostMessage(var_reply);
  }
  if (message == "status?") {
    pp::Var var_reply(world_.now() - world_.simulation_time());
    PostMessage(var_reply);
  }
}
void PpapiDeviceInfo::gotDeviceId(int32_t result, const pp::Var& deviceId)
{
    assert(isMainThread());
    ScopedMutex scopedMutex(mutex_);
    string rawDeviceIdStr;
    if (result == PP_OK && deviceId.is_string())
        rawDeviceIdStr = deviceId.AsString();
    // Google says the device ID from PPAPI, when supported, will always be 64
    // chars: a string with the text value of the numerical ID. Clamp or extend
    // the actual received value to this length.
    const string::size_type SPEC_SIZE = 64;
    rawDeviceIdStr.resize(SPEC_SIZE, '0');
    // Now convert the text numerical ID to a binary value
    deviceIdBin_ = hexTextToBin(rawDeviceIdStr);
    assert(deviceIdBin_.size() == 32);
    // We are now initialized
    condVar_.signal();
}
Example #10
0
 void GboxInstance::HandleMessage(const pp::Var& var_message) {
   if (!var_message.is_string()) return;
   std::string message = var_message.AsString();
   pp::Var var_reply;
   if (message == kHelloString) {
     theLog.info("message: '%s'", message.c_str());
     Hello();
   } else if (message == kPaintMethodId) {
     Paint();
   } else if (message == kClockMethodId) {
     Clock();
   } else if (message == "quiet") {
     theLog.info("message: '%s'", message.c_str());
     Quiet();
   } else {
     theLog.info("other message: '%s'", message.c_str());
     Other(message);
   }
 }
Example #11
0
void GodotInstance::HandleMessage(const pp::Var& var_message) {

	switch (state) {

		case STATE_METHOD: {

			ERR_FAIL_COND(!var_message.is_string());
			sd->method = var_message.AsString().c_str();
			state = STATE_PARAM_COUNT;
		} break;
		case STATE_PARAM_COUNT: {

			ERR_FAIL_COND(!var_message.is_number());
			sd->arg_count = var_message.AsInt();
			state = sd->arg_count>0?STATE_PARAMS:STATE_CALL;

		} break;
		case STATE_PARAMS: {

			Variant p = to_variant(var_message);
			sd->args.push_back(p);
			if (sd->args.size() >= sd->arg_count)
				state = STATE_CALL;
		} break;
		default:
			break;
	};

	if (state == STATE_CALL) {

		// call
		state = STATE_METHOD;


		if (sd->method == "package_finished") {

			GetURLHandler::Status status = package_pending->get_status();
			printf("status is %i, %i, %i\n", status, GetURLHandler::STATUS_ERROR, GetURLHandler::STATUS_COMPLETED);
			if (status == GetURLHandler::STATUS_ERROR) {
				printf("Error fetching package!\n");
			};
            if (status == GetURLHandler::STATUS_COMPLETED) {

				OSNacl* os = (OSNacl*)OS::get_singleton();
				os->add_package(pkg_url, package_pending->get_data());
			};
            memdelete(package_pending);
			package_pending = NULL;

            package_loaded = true;

            opengl_context_->MakeContextCurrent(this);
            nacl_main(init_argc, (const char**)init_argn, (const char**)init_argv);
            for (uint32_t i=0; i<init_argc; i++) {
				memfree(init_argn[i]);
				memfree(init_argv[i]);
			};
		};

		if (sd->method == "get_package_status") {

			if (package_loaded) {
				// post "loaded"
				PostMessage("loaded");
			} else if (package_pending == NULL) {
				// post "none"
				PostMessage("none");
			} else {
				// post package_pending->get_bytes_read();
				PostMessage(package_pending->get_bytes_read());
			};
		};
	};
}
Example #12
0
    virtual void HandleMessage(const pp::Var& var_message) {
        // Receive a message from javascript.
        if (var_message.is_string()) {
            SkString msg(var_message.AsString().c_str());
            if (msg.startsWith("init")) {
            } else if (msg.startsWith("LoadSKP")) {
                size_t startIndex = strlen("LoadSKP");
                size_t dataSize = msg.size()/sizeof(char) - startIndex;
                SkBase64 decodedData;
                decodedData.decode(msg.c_str() + startIndex, dataSize);
                size_t decodedSize = 3 * (dataSize / 4);
                SkDebugf("Got size: %d\n", decodedSize);
                if (!decodedData.getData()) {
                    SkDebugf("Failed to decode SKP\n");
                    return;
                }
                SkMemoryStream pictureStream(decodedData.getData(), decodedSize);
                SkPicture* picture = SkPicture::CreateFromStream(&pictureStream);
                if (NULL == picture) {
                    SkDebugf("Failed to create SKP.\n");
                    return;
                }
                fDebugger.loadPicture(picture);
                picture->unref();

                // Set up the command list.
                SkTArray<SkString>* commands = fDebugger.getDrawCommandsAsStrings();
                PostMessage("ClearCommands");
                for (int i = 0; i < commands->count(); ++i) {
                    SkString addCommand("AddCommand:");
                    addCommand.append((*commands)[i]);
                    PostMessage(addCommand.c_str());
                }
                PostMessage("UpdateCommands");

                // Set the overview text.
                SkString overviewText;
                fDebugger.getOverviewText(NULL, 0.0, &overviewText, 1);
                overviewText.prepend("SetOverview:");
                PostMessage(overviewText.c_str());

                // Draw the SKP.
                if (!fFlushLoopRunning) {
                    Paint();
                }
            } else if (msg.startsWith("CommandSelected:")) {
                size_t startIndex = strlen("CommandSelected:");
                int index = atoi(msg.c_str() + startIndex);
                fDebugger.setIndex(index);
                if (!fFlushLoopRunning) {
                    Paint();
                }
            } else if (msg.startsWith("Rewind")) {
                fCanvas->clear(SK_ColorWHITE);
                fDebugger.setIndex(0);
                if (!fFlushLoopRunning) {
                    Paint();
                }
            } else if (msg.startsWith("StepBack")) {
                fCanvas->clear(SK_ColorWHITE);
                int currentIndex = fDebugger.index();
                if (currentIndex > 1) {
                    fDebugger.setIndex(currentIndex - 1);
                    if (!fFlushLoopRunning) {
                        Paint();
                    }
                }
            } else if (msg.startsWith("Pause")) {
                // TODO(borenet)
            } else if (msg.startsWith("StepForward")) {
                int currentIndex = fDebugger.index();
                if (currentIndex < fDebugger.getSize() -1) {
                    fDebugger.setIndex(currentIndex + 1);
                    if (!fFlushLoopRunning) {
                        Paint();
                    }
                }
            } else if (msg.startsWith("Play")) {
                fDebugger.setIndex(fDebugger.getSize() - 1);
                if (!fFlushLoopRunning) {
                    Paint();
                }
            }
        }
    }