Skip to content

Instantly share code, notes, and snippets.

@fernandoc1
Created October 30, 2014 14:32
Show Gist options
  • Save fernandoc1/8d5c68e5fbdb8e37ca83 to your computer and use it in GitHub Desktop.
Save fernandoc1/8d5c68e5fbdb8e37ca83 to your computer and use it in GitHub Desktop.
Simple PNaCl application
{
"program":
{
"portable":
{
"pnacl-translate":
{
"url": "fingerprint.pexe"
}
}
}
}
<html>
<body>
<embed id="fingerprintModule" width=0 height=0 src="fingerprint.nmf" type="application/x-pnacl"/>
</body>
</html>
#include <iostream>
#include <ppapi/cpp/instance.h>
#include <ppapi/cpp/module.h>
#include <ppapi/cpp/var.h>
class FingerPrintInstance: public pp::Instance
{
public:
explicit FingerPrintInstance(PP_Instance instance)
: pp::Instance(instance)
{}
private:
virtual void HandleMessage(const pp::Var& var_message)
{
if(var_message.is_resource())
{
std::cout << "Resource received" << std::endl;
}
else if(var_message.is_string())
{
std::cout << "Message: " << var_message.AsString() << std::endl;
}
else
{
std::cout << "Unrecognized type" << std::endl;
}
}
};
class FingerPrintModule: public pp::Module
{
public:
FingerPrintModule()
: pp::Module()
{}
virtual ~FingerPrintModule()
{}
virtual pp::Instance* CreateInstance(PP_Instance instance)
{
return new FingerPrintInstance(instance);
}
};
namespace pp
{
Module* CreateModule()
{
std::cout << "Module created" << std::endl;
return new FingerPrintModule();
}
}
PNACL_PATH = /home/fccoelho/Code/nacl_sdk/pepper_37/
CC = $(PNACL_PATH)/toolchain/linux_pnacl/bin/pnacl-clang++
FINALIZE = $(PNACL_PATH)/toolchain/linux_pnacl/bin/pnacl-finalize
STRIP = $(PNACL_PATH)/toolchain/linux_pnacl/bin/pnacl-strip
PNACL_INCLUDE_DIR = $(PNACL_PATH)/include
PNACL_LIBRARY_DIR = $(PNACL_PATH)/lib/pnacl/Release
LINK_LIBRARIES = -lppapi_cpp -lppapi -lpthread
SOURCE_FILES = main.cpp
OUTPUT_NAME = fingerprint
all:
$(CC) -c $(SOURCE_FILES) -o output.o -I$(PNACL_INCLUDE_DIR)
$(CC) output.o -o output_unstripped.bc -L$(PNACL_LIBRARY_DIR) $(LINK_LIBRARIES)
$(FINALIZE) output_unstripped.bc -o output_unstripped.pexe
$(STRIP) output_unstripped.pexe -o $(OUTPUT_NAME).pexe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment