This source file includes following definitions.
- HandleMessage
- CreateInstance
- CreateModule
#include <algorithm>
#include "ppapi/cpp/instance.h"
#include "ppapi/cpp/module.h"
#include "ppapi/cpp/var.h"
#ifdef PostMessage
#undef PostMessage
#endif
class MyInstance : public pp::Instance {
public:
explicit MyInstance(PP_Instance instance) : pp::Instance(instance) {}
virtual ~MyInstance() {}
virtual void HandleMessage(const pp::Var& message_data);
};
void MyInstance::HandleMessage(const pp::Var& message_data) {
if (message_data.is_string()) {
std::string string_copy(message_data.AsString());
std::reverse(string_copy.begin(), string_copy.end());
bool is_palindrome(message_data.AsString() == string_copy);
PostMessage(pp::Var(is_palindrome));
}
}
class MyModule : public pp::Module {
public:
MyModule() : pp::Module() {}
virtual ~MyModule() {}
virtual pp::Instance* CreateInstance(PP_Instance instance) {
return new MyInstance(instance);
}
};
namespace pp {
Module* CreateModule() {
return new MyModule();
}
}