You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/07 17:13:53 UTC

[06/50] [abbrv] Add JPPS and Utils plugins to project template.

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.cpp
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.cpp b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.cpp
new file mode 100644
index 0000000..83616b8
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.cpp
@@ -0,0 +1,355 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+#include "PPSInterfaceGlue.h"
+
+#include <json/value.h>
+#include <json/writer.h>
+#include <json/reader.h>
+
+#include <vector>
+#include <sstream>
+
+#include <ppsparse.h>
+
+#include "../core/PPSEvent.h"
+
+namespace jpps {
+
+const std::string PPSInterfaceGlue::EVENT_OPEN = "ppsOpened";
+const std::string PPSInterfaceGlue::EVENT_OPEN_FAILED = "ppsOpenFailed";
+const std::string PPSInterfaceGlue::EVENT_FIRST_READ = "ppsFirstRead";
+const std::string PPSInterfaceGlue::EVENT_NEW_DATA = "OnChange";//"ppsNewData";
+const std::string PPSInterfaceGlue::EVENT_CLOSE = "ppsClosed";
+const std::string PPSInterfaceGlue::EVENT_WRITE_FAILED = "ppsWriteFailed";
+const std::string PPSInterfaceGlue::EVENT_READ_FAILED = "ppsReadFailed";
+
+const std::string PPSInterfaceGlue::ENCODING_N = "n";
+const std::string PPSInterfaceGlue::ENCODING_B = "b";
+const std::string PPSInterfaceGlue::ENCODING_JSON = "json";
+
+const Json::StaticString PPSInterfaceGlue::JSON_REMOVE("remove");
+const Json::StaticString PPSInterfaceGlue::JSON_CHANGED("changed");
+const Json::StaticString PPSInterfaceGlue::JSON_DATA("data");
+const Json::StaticString PPSInterfaceGlue::JSON_OBJNAME("objName");
+const Json::StaticString PPSInterfaceGlue::JSON_CHANGE_DATA("changeData");
+const Json::StaticString PPSInterfaceGlue::JSON_ALL_DATA("allData");
+
+
+PPSInterfaceGlue::PPSInterfaceGlue()
+: m_interface()
+, m_pArg(NULL)
+, m_handleOpen(NULL)
+, m_handleFirstRead(NULL)
+, m_handleNewData(NULL)
+, m_handleClose(NULL)
+, m_handleOpenFailed(NULL)
+, m_handleWriteFailed(NULL)
+, m_handleReadFailed(NULL)
+{
+	m_interface.setEventFunc(onEvent, this);
+}
+
+PPSInterfaceGlue::~PPSInterfaceGlue()
+{
+	m_interface.setEventFunc(NULL);
+}
+
+void PPSInterfaceGlue::callbackInit(void* pArg,
+								    callback* handleOpen,
+								    callback* handleFirstRead,
+								    callback* handleNewData,
+								    callback* handleClose,
+								    callback* handleOpenFailed,
+								    callback* handleWriteFailed,
+								    callback* handleReadFailed)
+{
+	m_pArg = pArg;
+	m_handleOpen = handleOpen;
+	m_handleFirstRead = handleFirstRead;
+	m_handleNewData = handleNewData;
+	m_handleClose = handleClose;
+	m_handleOpenFailed = handleOpenFailed;
+	m_handleWriteFailed = handleWriteFailed;
+	m_handleReadFailed = handleReadFailed;
+}
+
+void PPSInterfaceGlue::setVerbose(unsigned short v)
+{
+	m_interface.setVerbose(v);
+}
+
+bool PPSInterfaceGlue::open(const std::string& path, int oflags)
+{
+	// We don't expose the "mode" to the JS layer - always create in 0666 mode
+	return m_interface.open(path, oflags, 0666, false);
+}
+
+void PPSInterfaceGlue::close()
+{
+	m_interface.close();
+}
+
+void PPSInterfaceGlue::sync()
+{
+	m_interface.sync();
+}
+
+void PPSInterfaceGlue::onEvent(void* pArg, const PPSEvent& event)
+{
+	PPSInterfaceGlue* pGlue = static_cast<PPSInterfaceGlue*>(pArg);
+
+	if (pGlue != NULL)
+		pGlue->onEvent(event);
+}
+
+void PPSInterfaceGlue::onEvent(const PPSEvent& event)
+{
+	callback* pFunc = NULL;
+	std::string sArg;
+
+	switch (event.getEventType()) {
+
+	case PPSEvent::PPS_EVENT_OPENED:
+		pFunc = m_handleOpen;
+		sArg = EVENT_OPEN;
+		break;
+
+	case PPSEvent::PPS_EVENT_FIRST_READ_COMPLETE:
+		pFunc = m_handleFirstRead;
+		sArg = EVENT_FIRST_READ + " " + handleNewData(event.getNewData());
+		break;
+
+	case PPSEvent::PPS_EVENT_NEW_DATA:
+		pFunc = m_handleNewData;
+		sArg = EVENT_NEW_DATA + " " + handleNewData(event.getNewData());
+		break;
+
+	case PPSEvent::PPS_EVENT_CLOSED:
+		pFunc = m_handleClose;
+		sArg = EVENT_CLOSE;
+		break;
+
+	case PPSEvent::PPS_EVENT_OPEN_FAILED:
+		pFunc = m_handleOpenFailed;
+		sArg = EVENT_OPEN_FAILED + " " + event.getMessage();
+		break;
+
+	case PPSEvent::PPS_EVENT_WRITE_FAILED:
+		pFunc = m_handleWriteFailed;
+		sArg = EVENT_WRITE_FAILED + " " + event.getMessage();
+		break;
+
+	case PPSEvent::PPS_EVENT_READ_FAILED:
+		pFunc = m_handleReadFailed;
+		sArg = EVENT_READ_FAILED + " " + event.getMessage();
+		break;
+	}
+
+	if (pFunc != NULL)
+		pFunc(m_pArg, sArg);
+}
+
+std::string PPSInterfaceGlue::handleNewData(const ppsObject& newData)
+{
+	Json::Value data(Json::nullValue);
+	data[JSON_CHANGE_DATA] = JSONEncodeNewData(newData);
+	data[JSON_ALL_DATA] = JSONEncodeRead(m_interface.read());
+
+	Json::FastWriter writer;
+	return writer.write(data);
+}
+
+std::string PPSInterfaceGlue::read() const
+{
+	Json::Value data = JSONEncodeRead(m_interface.read());
+	Json::FastWriter writer;
+	return writer.write(data);
+}
+
+Json::Value PPSInterfaceGlue::JSONEncodeRead(const ppsObject& ppsObj) const
+{
+	// If the ppsObj is empty, we can't encode it
+	if (ppsObj.name.empty())
+		return "";
+
+	Json::Value readData(Json::nullValue);
+
+	for (const_ppsAttrIter it = ppsObj.attributes.begin(); it != ppsObj.attributes.end(); it++) {
+
+		ppsAttribute ppsAttrib = (*it).second;
+
+		// An attribute was deleted: update the JSON data structure and the event data
+		if (ppsAttrib.flags & PPS_DELETED) {
+
+			readData.removeMember(ppsAttrib.name);
+		}
+		else {
+
+			// The value is a number
+			if (ppsAttrib.encoding == ENCODING_N) {
+
+				// Convert the value to floating point
+				// istringstream is locale aware - we shouldn't need to perform any special
+				// processing in order to properly convert the data to a floating point
+				// TODO: test that the istringstream conversion works with a locale
+				//       that uses alternate floating point number encoding
+				std::istringstream stream(ppsAttrib.value);
+				double doubleValue;
+
+				// Try to convert the value to a floating point
+				if (!(stream >> doubleValue)) {
+
+					std::string err = EVENT_READ_FAILED + " Failed to convert the string \"" + ppsAttrib.value + "\" to a real number.";
+					m_handleReadFailed(m_pArg, err);
+					return "";
+				}
+
+				readData[ppsAttrib.name] = doubleValue;
+			}
+			// The value is a boolean
+			else if (ppsAttrib.encoding == ENCODING_B) {
+
+				readData[ppsAttrib.name] = (ppsAttrib.value == "true");
+			}
+			// The value is JSON data
+			else if (ppsAttrib.encoding == ENCODING_JSON) {
+
+				Json::Reader reader;
+				reader.parse(ppsAttrib.value, readData[ppsAttrib.name]);
+			}
+			// Just pass the value through as a straight string
+			else {
+
+				readData[ppsAttrib.name] = ppsAttrib.value;
+			}
+		}
+	}
+
+	return readData;
+}
+
+Json::Value PPSInterfaceGlue::JSONEncodeNewData(const ppsObject& ppsObj) const
+{
+	// If the ppsObj is empty, we can't encode it
+	if (ppsObj.name.empty())
+		return "";
+
+	Json::Value eventData(Json::nullValue);
+
+	// Set the PPS object name
+	eventData[JSON_OBJNAME] = ppsObj.name.substr(1); // PR 159829 : Remove the pre-pending '@' symbol
+
+	for (const_ppsAttrIter it = ppsObj.attributes.begin(); it != ppsObj.attributes.end(); it++) {
+
+		ppsAttribute ppsAttrib = (*it).second;
+
+		// An attribute was deleted: update the JSON data structure and the event data
+		if (ppsAttrib.flags & PPS_DELETED) {
+
+			eventData[JSON_REMOVE][ppsAttrib.name] = true;
+		}
+		else {
+
+			eventData[JSON_CHANGED][ppsAttrib.name] = true;
+
+			// The value is a number
+			if (ppsAttrib.encoding == ENCODING_N) {
+
+				// Convert the value to floating point
+				// istringstream is locale aware - we shouldn't need to perform any special
+				// processing in order to properly convert the data to a floating point
+				// TODO: test that the istringstream conversion works with a locale
+				//       that uses alternate floating point number encoding
+				std::istringstream stream(ppsAttrib.value);
+				double doubleValue;
+
+				// Try to convert the value to a floating point
+				if (!(stream >> doubleValue)) {
+
+					std::string err = EVENT_READ_FAILED + " Failed to convert the string \"" + ppsAttrib.value + "\" to a real number.";
+					m_handleReadFailed(m_pArg, err);
+					return "";
+				}
+
+				eventData[JSON_DATA][ppsAttrib.name] = doubleValue;
+			}
+			// The value is a boolean
+			else if (ppsAttrib.encoding == ENCODING_B) {
+
+				eventData[JSON_DATA][ppsAttrib.name] = (ppsAttrib.value == "true");
+			}
+			// The value is JSON data
+			else if (ppsAttrib.encoding == ENCODING_JSON) {
+
+				Json::Reader reader;
+				reader.parse(ppsAttrib.value, eventData[JSON_DATA][ppsAttrib.name]);
+			}
+			// Just pass the value through as a straight string
+			else {
+
+				eventData[JSON_DATA][ppsAttrib.name] = ppsAttrib.value;
+			}
+		}
+	}
+
+	return eventData;
+}
+
+void PPSInterfaceGlue::write(const std::string& data)
+{
+    Json::Reader reader;
+    Json::Value root;
+
+	bool parsingSuccessful = reader.parse(data, root);
+
+    // If parsing the JSON string fails, return a write error
+    if (!parsingSuccessful) {
+
+    	std::string err = EVENT_WRITE_FAILED + " JSON failed to parse the string (\"" + data + "\") to be written. (" + reader.getFormatedErrorMessages() + ")";
+        m_handleWriteFailed(m_pArg, err);
+        return;
+    }
+
+	Json::Value::Members memberNames = root.getMemberNames();
+
+	std::ostringstream output;
+	output.precision(15);
+
+	Json::Value member;
+
+	for (unsigned int i = 0; i < memberNames.size(); i++) {
+
+		output << memberNames[i] << ":";
+		member = root[memberNames[i]];
+
+		if (member.isObject() || member.isArray()) {
+
+			Json::FastWriter writer;
+			output << ENCODING_JSON << ":" << writer.write(member); // write() adds an \n
+		}
+		else if (member.isBool()) {
+
+			output << ENCODING_B << ":" << member.asString() << std::endl;
+		}
+		else if (member.isNumeric()) {
+
+			output << ENCODING_N << ":" << member.asDouble() << std::endl;
+		}
+		else if (member.isString()) {
+
+			output << ":" << member.asString() << std::endl;
+		}
+		else {
+
+			std::string err = EVENT_WRITE_FAILED + " The string passed in (\"" + data + "\") contains an invalid JSON type.";
+			m_handleWriteFailed(m_pArg, err);
+			return;
+		}
+	}
+
+	m_interface.write(output.str());
+}
+
+} /* namespace jpps */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.h
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.h b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.h
new file mode 100644
index 0000000..fafbacd
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSInterfaceGlue.h
@@ -0,0 +1,177 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+/*
+ * $QNXLicenseC:
+ * Copyright 2009, QNX Software Systems. All Rights Reserved.
+ *
+ * You must obtain a written license from and pay applicable license fees to QNX
+ * Software Systems before you may reproduce, modify or distribute this software,
+ * or any work that includes all or part of this software.   Free development
+ * licenses are available for evaluation and non-commercial purposes.  For more
+ * information visit http://licensing.qnx.com or email licensing@qnx.com.
+ *
+ * This file may contain contributions from others.  Please review this entire
+ * file for other proprietary rights or license notices, as well as the QNX
+ * Development Suite License Guide at http://licensing.qnx.com/license-guide/
+ * for other information.
+ * $
+ */
+
+#ifndef PPSINTERFACEGLUE_H_
+#define PPSINTERFACEGLUE_H_
+
+#include "../core/PPSInterface.h"
+#include "PluginTypes.h"
+
+#include <json/value.h>
+
+#include <string>
+
+namespace jpps {
+class PPSEvent;
+struct ppsObject;
+}
+
+namespace jpps {
+
+/**
+ * This class bridges JavaScript and the native PPSInterface code.
+ */
+class PPSInterfaceGlue {
+
+public:
+
+	/**
+	 * Constructor.
+	 */
+	PPSInterfaceGlue();
+
+	/**
+	 * Destructor.
+	 */
+	virtual ~PPSInterfaceGlue();
+
+	/**
+	 * The browser plugin should set these handlers.
+	 *
+	 * @param pArg pArg will be passed back to each callback function when it is called.
+	 */
+	void callbackInit(void* pArg,
+					  callback* handleOpen,
+					  callback* handleFirstRead,
+					  callback* handleNewData,
+					  callback* handleClose,
+					  callback* handleOpenFailed,
+					  callback* handleWriteFailed,
+					  callback* handleReadFailed);
+
+	/**
+	 * Set the verbosity of logging to the slog.
+	 */
+	void setVerbose(unsigned short v);
+
+	/**
+	 * Open a PPS object.
+	 */
+	bool open(const std::string& path, int oflags);
+
+	/**
+	 * Write to a PPS object.
+	 */
+	void write(const std::string& data);
+
+	/**
+	 * Read from the PPS object. This actually returns the cached value of the last
+	 * onNewData event from PPSInteraface, then encodes it as JSON.
+	 */
+	std::string read() const;
+
+	/**
+	 * Close this PPS object.
+	 */
+	void close();
+
+	/**
+	 * Forces all queued I/O operations for this object to finish, synchronizing the file's state.
+	 * The function blocks until this is finished.
+	 */
+	void sync();
+
+	/**
+	 * The function that the PPSInterface will call when an event happens.
+	 * This is the static function that is used as a function pointer for
+	 * PPSInterface::setEventFunc().
+	 *
+	 * @param event The event PPSInterface is sending.
+	 * @param pArg A pointer to a PPSInterfaceGlue object, passed in during
+	 * object construction.
+	 */
+	static void onEvent(void* pArg, const PPSEvent& event);
+
+private:
+
+	/**
+	 * The static PPSInterfaceGlue::onEvent() calls this onEvent to do the actual work.
+	 */
+	void onEvent(const PPSEvent& event);
+
+	/**
+	 * Handle a new data event.
+	 */
+	std::string handleNewData(const ppsObject& newData);
+
+	/**
+	 * Take a ppsObject and turn it into a JSON string to send back to the JavaScript
+	 * with a new data event. This structures the JSON with changed properties and the
+	 * data that has changed.
+	 */
+	Json::Value JSONEncodeNewData(const ppsObject& ppsObj) const;
+
+	/**
+	 * Take a ppsObject and turn it into a JSON string to send back to the JavaScript
+	 * when a call to read() is made.
+	 */
+	Json::Value JSONEncodeRead(const ppsObject& ppsObj) const;
+
+	// String names for the various events
+	static const std::string EVENT_OPEN;
+	static const std::string EVENT_OPEN_FAILED;
+	static const std::string EVENT_FIRST_READ;
+	static const std::string EVENT_NEW_DATA;
+	static const std::string EVENT_CLOSE;
+	static const std::string EVENT_READ_FAILED;
+	static const std::string EVENT_WRITE_FAILED;
+
+	/** Custom PPS encoding value: an "n" means a real number. */
+	static const std::string ENCODING_N;
+	/** Custom PPS encoding value: a "b" means a boolean value. */
+	static const std::string ENCODING_B;
+	/** Custom PPS encoding value: the data is encoded using JSON. */
+	static const std::string ENCODING_JSON;
+
+	// JSON constants
+	static const Json::StaticString JSON_REMOVE;
+	static const Json::StaticString JSON_CHANGED;
+	static const Json::StaticString JSON_DATA;
+	static const Json::StaticString JSON_OBJNAME;
+	static const Json::StaticString JSON_CHANGE_DATA;
+	static const Json::StaticString JSON_ALL_DATA;
+
+	/** The interface this object wraps. */
+	PPSInterface m_interface;
+
+	// Handlers for various events
+	void* m_pArg;
+	callback* m_handleOpen;
+	callback* m_handleFirstRead;
+	callback* m_handleNewData;
+	callback* m_handleClose;
+	callback* m_handleOpenFailed;
+	callback* m_handleWriteFailed;
+	callback* m_handleReadFailed;
+};
+
+} /* namespace jpps */
+#endif /* PPSINTERFACEGLUE_H_ */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.cpp
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.cpp b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.cpp
new file mode 100644
index 0000000..2eb4552
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.cpp
@@ -0,0 +1,300 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+#include "PPSServerGlue.h"
+
+#include <json/value.h>
+#include <json/writer.h>
+#include <json/reader.h>
+
+#include <sstream>
+
+#include <ppsparse.h>
+#include <fcntl.h>
+
+namespace jpps {
+
+const std::string PPSServerGlue::EVENT_OPEN = "onOpen";
+const std::string PPSServerGlue::EVENT_CLOSE = "onClose";
+const std::string PPSServerGlue::EVENT_CLIENT_CONNECT = "onClientConnect";
+const std::string PPSServerGlue::EVENT_CLIENT_DISCONNECT = "onClientDisconnect";
+const std::string PPSServerGlue::EVENT_MESSAGE = "onMessage";
+const std::string PPSServerGlue::EVENT_OPEN_FAILED = "onOpenFailed";
+const std::string PPSServerGlue::EVENT_SEND_MESSAGE_FAILED = "onSendMessageFailed";
+const std::string PPSServerGlue::EVENT_RECEIVE_MESSAGE_FAILED = "onReceiveMessageFailed";
+
+const std::string PPSServerGlue::ENCODING_N = "n";
+const std::string PPSServerGlue::ENCODING_B = "b";
+const std::string PPSServerGlue::ENCODING_JSON = "json";
+
+const Json::StaticString PPSServerGlue::JSON_DATA("data");
+const Json::StaticString PPSServerGlue::JSON_CONNECTION_ID("clientId");
+
+PPSServerGlue::PPSServerGlue()
+: m_interface()
+, m_pArg(NULL)
+, m_handleOpen(NULL)
+, m_handleClose(NULL)
+, m_handleClientConnect(NULL)
+, m_handleClientDisconnect(NULL)
+, m_handleMessage(NULL)
+, m_handleOpenFailed(NULL)
+, m_handleSendMessageFailed(NULL)
+, m_handleReceiveMessageFailed(NULL)
+{
+	m_interface.setEventFunc(onEvent, this);
+}
+
+PPSServerGlue::~PPSServerGlue()
+{
+	m_interface.setEventFunc(NULL);
+}
+
+void PPSServerGlue::callbackInit(void* pArg,
+					  callback* handleOpen,
+					  callback* handleClose,
+					  callback* handleClientConnect,
+					  callback* handleClientDisconnect,
+					  callback* handleMessage,
+					  callback* handleOpenFailed,
+					  callback* handleSendMessageFailed,
+					  callback* handleReceiveMessageFailed)
+{
+	m_pArg = pArg;
+	m_handleOpen = handleOpen;
+	m_handleClose = handleClose;
+	m_handleClientConnect = handleClientConnect;
+	m_handleClientDisconnect = handleClientDisconnect;
+	m_handleMessage = handleMessage;
+	m_handleOpenFailed = handleOpenFailed;
+	m_handleSendMessageFailed = handleSendMessageFailed;
+	m_handleReceiveMessageFailed = handleReceiveMessageFailed;
+}
+
+
+void PPSServerGlue::setVerbose(unsigned short v)
+{
+	m_interface.setVerbose(v);
+}
+
+bool PPSServerGlue::open(const std::string& path, int oflags)
+{
+	// Make sure we're creating the server, if it doesn't exist
+	if (!(oflags & O_CREAT))
+		oflags &= O_CREAT;
+
+	// We don't expose the "mode" to the JS layer - always create in 0666 mode
+	return m_interface.open(path, oflags, 0666, true);
+}
+
+void PPSServerGlue::close()
+{
+	m_interface.close();
+}
+
+void PPSServerGlue::sendMessage(const std::string& clientID, const std::string& msg)
+{
+	std::string decodedMsg = JSONDecodeData(msg);
+	std::string message(clientID + "\n" + decodedMsg);
+	m_interface.write(message);
+}
+
+void PPSServerGlue::broadcastMessage(const std::string& msg)
+{
+	m_interface.write(JSONDecodeData(msg));
+}
+
+void PPSServerGlue::onEvent(void* pArg, const PPSEvent& event)
+{
+	PPSServerGlue* pGlue = static_cast<PPSServerGlue*>(pArg);
+
+	if (pGlue != NULL)
+		pGlue->onEvent(event);
+}
+
+void PPSServerGlue::onEvent(const PPSEvent& event)
+{
+	callback* pFunc = NULL;
+	std::string sArg;
+
+	switch (event.getEventType()) {
+
+	case PPSEvent::PPS_EVENT_OPENED:
+		pFunc = m_handleOpen;
+		sArg = EVENT_OPEN;
+		break;
+
+	// The server doesn't do anything with this event
+	case PPSEvent::PPS_EVENT_FIRST_READ_COMPLETE:
+		break;
+
+	case PPSEvent::PPS_EVENT_NEW_DATA:
+	{
+		ppsObject data(event.getNewData());
+
+		// This means a new connection
+		if (data.flags & PPS_CREATED) {
+			sArg = EVENT_CLIENT_CONNECT;
+			pFunc = m_handleClientConnect;
+		}
+		// This means a connection is closed
+		else if (data.flags & PPS_DELETED) {
+			sArg = EVENT_CLIENT_DISCONNECT;
+			pFunc = m_handleClientDisconnect;
+		}
+		// We're getting data from the connection
+		else {
+			sArg = EVENT_MESSAGE;
+			pFunc = m_handleMessage;
+		}
+
+		sArg += " " + JSONEncodeData(data);
+
+		break;
+	}
+
+	case PPSEvent::PPS_EVENT_CLOSED:
+		pFunc = m_handleClose;
+		sArg = EVENT_CLOSE;
+		break;
+
+	case PPSEvent::PPS_EVENT_OPEN_FAILED:
+		pFunc = m_handleOpenFailed;
+		sArg = EVENT_OPEN_FAILED + " " + event.getMessage();
+		break;
+
+	case PPSEvent::PPS_EVENT_WRITE_FAILED:
+		pFunc = m_handleSendMessageFailed;
+		sArg = EVENT_SEND_MESSAGE_FAILED + " " + event.getMessage();
+		break;
+
+	case PPSEvent::PPS_EVENT_READ_FAILED:
+		pFunc = m_handleReceiveMessageFailed;
+		sArg = EVENT_RECEIVE_MESSAGE_FAILED + event.getMessage();
+		break;
+	}
+
+	if (pFunc != NULL)
+		pFunc(m_pArg, sArg);
+
+}
+
+std::string PPSServerGlue::JSONEncodeData(const ppsObject& ppsObj) const
+{
+	// If the ppsObj is empty, we can't encode it
+	if (ppsObj.name.empty())
+		return "";
+
+	Json::Value eventData(Json::nullValue);
+
+	// Set the client id
+	// Chop off the '+' or '-' if it's there
+	eventData[JSON_CONNECTION_ID] = ppsObj.name;
+
+	for (const_ppsAttrIter it = ppsObj.attributes.begin(); it != ppsObj.attributes.end(); it++) {
+
+		ppsAttribute ppsAttrib = (*it).second;
+
+		// The value is a number
+		if (ppsAttrib.encoding == ENCODING_N) {
+
+			// Convert the value to floating point
+			// istringstream is locale aware - we shouldn't need to perform any special
+			// processing in order to properly convert the data to a floating point
+			// TODO: test that the istringstream conversion works with a locale
+			//       that uses alternate floating point number encoding
+			std::istringstream stream(ppsAttrib.value);
+			double doubleValue;
+
+			// Try to convert the value to a floating point
+			if (!(stream >> doubleValue)) {
+
+				std::string err = EVENT_RECEIVE_MESSAGE_FAILED + " Failed to convert the string \"" + ppsAttrib.value + "\" to a real number.";
+				m_handleReceiveMessageFailed(m_pArg, err);
+				return "";
+			}
+
+			eventData[JSON_DATA][ppsAttrib.name] = doubleValue;
+		}
+		// The value is a boolean
+		else if (ppsAttrib.encoding == ENCODING_B) {
+
+			eventData[JSON_DATA][ppsAttrib.name] = (ppsAttrib.value == "true");
+		}
+		// The value is JSON data
+		else if (ppsAttrib.encoding == ENCODING_JSON) {
+
+			Json::Reader reader;
+			reader.parse(ppsAttrib.value, eventData[JSON_DATA][ppsAttrib.name]);
+		}
+		// Just pass the value through as a straight string
+		else {
+
+			eventData[JSON_DATA][ppsAttrib.name] = ppsAttrib.value;
+		}
+	}
+
+	Json::FastWriter writer;
+	return writer.write(eventData);
+}
+
+std::string PPSServerGlue::JSONDecodeData(const std::string& data) const
+{
+	 Json::Reader reader;
+	Json::Value root;
+
+	bool parsingSuccessful = reader.parse(data, root);
+
+	// If parsing the JSON string fails, return a write error
+	if (!parsingSuccessful) {
+
+		std::string err = EVENT_SEND_MESSAGE_FAILED + " JSON failed to parse the string (\"" + data + "\") to be written. (" + reader.getFormatedErrorMessages() + ")";
+		m_handleSendMessageFailed(m_pArg, err);
+		return "";
+	}
+
+	Json::Value::Members memberNames = root.getMemberNames();
+
+	std::ostringstream output;
+	output.precision(15);
+
+	Json::Value member;
+
+	for (unsigned int i = 0; i < memberNames.size(); i++) {
+
+		output << memberNames[i] << ":";
+		member = root[memberNames[i]];
+
+		if (member.isObject() || member.isArray()) {
+
+			Json::FastWriter writer;
+			output << ENCODING_JSON << ":" << writer.write(member);
+		}
+		else if (member.isBool()) {
+
+			output << ENCODING_B << ":" << member.asString();
+		}
+		else if (member.isNumeric()) {
+
+			output << ENCODING_N << ":" << member.asDouble();
+		}
+		else if (member.isString()) {
+
+			output << ":" << member.asString();
+		}
+		else {
+
+			std::string err = EVENT_SEND_MESSAGE_FAILED + " The string passed in (\"" + data + "\") contains an invalid JSON type.";
+			m_handleSendMessageFailed(m_pArg, err);
+			return "";
+		}
+
+		// Make sure we terminate the line
+		output << std::endl;
+	}
+
+	return output.str();
+}
+
+} /* namespace jpps */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.h
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.h b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.h
new file mode 100644
index 0000000..8891829
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PPSServerGlue.h
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+/*
+ * $QNXLicenseC:
+ * Copyright 2009, QNX Software Systems. All Rights Reserved.
+ *
+ * You must obtain a written license from and pay applicable license fees to QNX
+ * Software Systems before you may reproduce, modify or distribute this software,
+ * or any work that includes all or part of this software.   Free development
+ * licenses are available for evaluation and non-commercial purposes.  For more
+ * information visit http://licensing.qnx.com or email licensing@qnx.com.
+ *
+ * This file may contain contributions from others.  Please review this entire
+ * file for other proprietary rights or license notices, as well as the QNX
+ * Development Suite License Guide at http://licensing.qnx.com/license-guide/
+ * for other information.
+ * $
+ */
+
+#ifndef PPSSERVERGLUE_H_
+#define PPSSERVERGLUE_H_
+
+#include "../core/PPSInterface.h"
+#include "PluginTypes.h"
+
+// Forward declaration
+namespace Json {
+class StaticString;
+}
+namespace jpps {
+class PPSEvent;
+struct ppsObject;
+}
+
+namespace jpps {
+
+/**
+ * Act as glue between jpps Server class an the PPSInterface.
+ * This class encapsulates a PPS object as a PPS server.
+ * TODO: write a better comment
+ */
+class PPSServerGlue {
+
+public:
+
+	/**
+	 * Constructor.
+	 */
+	PPSServerGlue();
+
+	/**
+	 * Destructor.
+	 */
+	virtual ~PPSServerGlue();
+
+	/**
+	 * The browser plugin should set these handlers.
+	 *
+	 * @param pArg pArg will be passed back to each callback function when it is called.
+	 */
+	void callbackInit(void* pArg,
+					  callback* handleOpen,
+					  callback* handleClose,
+					  callback* handleClientConnect,
+					  callback* handleClientDisconnect,
+					  callback* handleMessage,
+					  callback* handleOpenFailed,
+					  callback* handleSendMessageFailed,
+					  callback* handleReceiveMessageFailed);
+
+	/**
+	 * Set the verbosity of logging to the slog.
+	 */
+	void setVerbose(unsigned short v);
+
+	/**
+	 * Open a PPS server object.
+	 */
+	bool open(const std::string& path, int oflags);
+
+	/**
+	 * Close this PPS server object.
+	 */
+	void close();
+
+	/**
+	 * Send a message to a particular client.
+	 */
+	void sendMessage(const std::string& clientID, const std::string& msg);
+
+	/**
+	 * Send a message to all clients.
+	 */
+	void broadcastMessage(const std::string& msg);
+
+	/**
+	 * The function that the PPSInterface will call when an event happens.
+	 * This is the static function that is used as a function pointer for
+	 * PPSInterface::setEventFunc().
+	 *
+	 * @param event The event PPSInterface is sending.
+	 * @param pArg A pointer to a PPSInterfaceGlue object, passed in during
+	 * object construction.
+	 */
+	static void onEvent(void* pArg, const PPSEvent& event);
+
+private:
+
+	/**
+	 * The static PPSInterfaceGlue::onEvent() calls this onEvent to do the actual work.
+	 */
+	void onEvent(const PPSEvent& event);
+
+	/**
+	 * Take a ppsObject and turn it into a JSON string to send back to the JavaScript
+	 * with a onMessage event.
+	 */
+	std::string JSONEncodeData(const ppsObject& ppsObj) const;
+
+	/**
+	 * Take a JSON string and change it into a PPS consumable string.
+	 */
+	std::string JSONDecodeData(const std::string& data) const;
+
+	// String names for the various events
+	static const std::string EVENT_OPEN;
+	static const std::string EVENT_CLOSE;
+	static const std::string EVENT_CLIENT_CONNECT;
+	static const std::string EVENT_CLIENT_DISCONNECT;
+	static const std::string EVENT_MESSAGE;
+	static const std::string EVENT_OPEN_FAILED;
+	static const std::string EVENT_SEND_MESSAGE_FAILED;
+	static const std::string EVENT_RECEIVE_MESSAGE_FAILED;
+
+	/** Custom PPS encoding value: an "n" means a real number. */
+	static const std::string ENCODING_N;
+	/** Custom PPS encoding value: a "b" means a boolean value. */
+	static const std::string ENCODING_B;
+	/** Custom PPS encoding value: the data is encoded using JSON. */
+	static const std::string ENCODING_JSON;
+
+	// JSON constants
+	static const Json::StaticString JSON_DATA;
+	static const Json::StaticString JSON_CONNECTION_ID;
+
+	/** The interface this object wraps. */
+	PPSInterface m_interface;
+
+	// Handlers for various events
+	void* m_pArg;
+	callback* m_handleOpen;
+	callback* m_handleClose;
+	callback* m_handleClientConnect;
+	callback* m_handleClientDisconnect;
+	callback* m_handleMessage;
+	callback* m_handleOpenFailed;
+	callback* m_handleSendMessageFailed;
+	callback* m_handleReceiveMessageFailed;
+
+};
+
+} /* namespace jpps */
+#endif /* PPSSERVERGLUE_H_ */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PluginTypes.h
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PluginTypes.h b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PluginTypes.h
new file mode 100644
index 0000000..9ce6b32
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/PluginTypes.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+/*
+ * $QNXLicenseC:
+ * Copyright 2009, QNX Software Systems. All Rights Reserved.
+ *
+ * You must obtain a written license from and pay applicable license fees to QNX
+ * Software Systems before you may reproduce, modify or distribute this software,
+ * or any work that includes all or part of this software.   Free development
+ * licenses are available for evaluation and non-commercial purposes.  For more
+ * information visit http://licensing.qnx.com or email licensing@qnx.com.
+ *
+ * This file may contain contributions from others.  Please review this entire
+ * file for other proprietary rights or license notices, as well as the QNX
+ * Development Suite License Guide at http://licensing.qnx.com/license-guide/
+ * for other information.
+ * $
+ */
+
+#ifndef PLUGINTYPES_H_
+#define PLUGINTYPES_H_
+
+namespace jpps {
+
+/**
+ * Function type for setting handles between JNext plug-in and glue classes.
+ */
+typedef void (callback)(void* pArg, const std::string&);
+
+}
+
+
+#endif /* PLUGINTYPES_H_ */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/pluginManifest.cpp
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/pluginManifest.cpp b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/pluginManifest.cpp
new file mode 100644
index 0000000..e06ad4c
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/plugin/pluginManifest.cpp
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+/*
+ * $QNXLicenseC:
+ * Copyright 2009, QNX Software Systems. All Rights Reserved.
+ *
+ * You must obtain a written license from and pay applicable license fees to QNX
+ * Software Systems before you may reproduce, modify or distribute this software,
+ * or any work that includes all or part of this software.   Free development
+ * licenses are available for evaluation and non-commercial purposes.  For more
+ * information visit http://licensing.qnx.com or email licensing@qnx.com.
+ *
+ * This file may contain contributions from others.  Please review this entire
+ * file for other proprietary rights or license notices, as well as the QNX
+ * Development Suite License Guide at http://licensing.qnx.com/license-guide/
+ * for other information.
+ * $
+ */
+
+#include "JPPSPlugin.h"
+#include "JPPSServerPlugin.h"
+
+#include <string>
+
+/**
+ * This callback must be implemented by all JSExt objects. It is invoked from
+ * plugin.cpp.
+ *
+ * @return A comma separated list of classes supported by this JNEXT extension
+ */
+char* onGetObjList(void)
+{
+	static char* ppsclasses = NULL;
+
+	if (ppsclasses == NULL) {
+
+		// Get the length of all the strings, +1 for the ',' +1 for the \0
+		int size = std::strlen(jpps::JPPSPlugin::CLASS_NAME) + std::strlen(jpps::JPPSServerPlugin::CLASS_NAME) + 1 + 1;
+		ppsclasses = new char[size];
+		std::strcpy(ppsclasses, jpps::JPPSPlugin::CLASS_NAME);
+		std::strcat(ppsclasses, ",");
+		std::strcat(ppsclasses, jpps::JPPSServerPlugin::CLASS_NAME);
+		ppsclasses[size] = '\0';
+	}
+    // Return a comma separated list of classes known to this plugin
+    return ppsclasses;
+}
+
+/**
+ * This callback must be implemented by all JSExt objects. It is invoked from
+ * plugin.cpp.
+ *
+ * @param strClassName Name of the class requested to be created Valid named are those
+ * that are returned in onGetObjList
+ *
+ * @param strObjId The unique object id for the class
+ *
+ * @return A pointer to the created extension object
+ */
+JSExt* onCreateObject(const std::string& strClassName, const std::string& strObjId)
+{
+    // Given a class name and identifier, create the relevant object.
+    if (strClassName == jpps::JPPSPlugin::CLASS_NAME) {
+        return new jpps::JPPSPlugin(strObjId);;
+    }
+    else if (strClassName == jpps::JPPSServerPlugin::CLASS_NAME) {
+    	return new jpps::JPPSServerPlugin(strObjId);
+    }
+
+    // Any other name is invalid
+    return NULL;
+}
+
+

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Logger.h
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Logger.h b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Logger.h
new file mode 100644
index 0000000..37a9d17
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Logger.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+/*
+ * $QNXLicenseC:
+ * Copyright 2009, QNX Software Systems. All Rights Reserved.
+ *
+ * You must obtain a written license from and pay applicable license fees to QNX
+ * Software Systems before you may reproduce, modify or distribute this software,
+ * or any work that includes all or part of this software.   Free development
+ * licenses are available for evaluation and non-commercial purposes.  For more
+ * information visit http://licensing.qnx.com or email licensing@qnx.com.
+ *
+ * This file may contain contributions from others.  Please review this entire
+ * file for other proprietary rights or license notices, as well as the QNX
+ * Development Suite License Guide at http://licensing.qnx.com/license-guide/
+ * for other information.
+ * $
+ */
+
+#ifndef LOGGER_H_
+#define LOGGER_H_
+
+#include <string>
+
+#include <sys/slog.h>
+#include <sys/slogcodes.h>
+
+namespace jpps {
+
+/**
+ * The Logger class writes messages to the system log. It has a verbosity setting
+ * in order to prevent cluttering the slog during normal operation.
+ */
+class Logger {
+
+public:
+
+	enum slogType {
+		info = _SLOG_INFO,
+		warning = _SLOG_WARNING,
+		error = _SLOG_ERROR,
+		critical = _SLOG_CRITICAL,
+		debug = _SLOG_DEBUG1
+	};
+
+	/**
+	 * Default constructor. Sets the verbosity to 0;
+	 */
+	Logger() : m_verbosity(0) {}
+
+	/**
+	 * Destructor.
+	 */
+	~Logger() {}
+
+	/**
+	 * Set the desired level of verbosity. A value of 0 means that only warning,
+	 * error and critical messages will appear in the slog. A verbosity of 1 adds
+	 * info messages. A verbosity of 2 adds debug messages.
+	 */
+	inline void setVerbosity(unsigned short value) { m_verbosity = value; }
+
+	/**
+	 * Get the current level of verbosity.
+	 */
+	inline unsigned short getVerbosity() const { return m_verbosity; }
+
+	/**
+	 * Used to send messages to the system log (slog).
+	 *
+	 * @param type The type of slog message.
+	 * @param message The message to put in the slog.
+	 */
+	void slog(const slogType& type, const std::string& message) const {
+
+		// Don't display info or debug when verbosity is set to 0
+		if (m_verbosity == 0 && (type == info || type == debug)) return;
+		// Don't display debug when verbosity is set to 1
+		if (m_verbosity == 1 && type == debug) return;
+
+		::slogf(_SLOG_SETCODE(_SLOGC_GRAPHICS, 300), type, "%s", message.c_str());
+	}
+
+private:
+
+	/** The verbosity level.  */
+	unsigned short m_verbosity;
+};
+
+}
+
+#endif /* LOGGER_H_ */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.cpp
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.cpp b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.cpp
new file mode 100644
index 0000000..82ab5d1
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+#include "Thread.h"
+#include <pthread.h>
+#include "Logger.h"
+#include <sstream>
+#include <string.h>
+#include <errno.h>
+
+namespace jpps {
+
+Thread::Thread()
+: m_threadID(-1)
+{
+	// Init the thread with all defaults
+	pthread_attr_init(&m_attrib);
+}
+
+Thread::~Thread()
+{
+	// Dispose of the thread attributes
+	pthread_attr_destroy(&m_attrib);
+}
+
+void Thread::start(void* (*start_routine)(void*), void* arg, const std::string& thread_name)
+{
+	// If this thread is already started, you can't start a new one
+	if (m_threadID != -1) {
+		return;
+	}
+
+	// Create a new thread
+	if (pthread_create(&m_threadID, &m_attrib, start_routine, arg) != 0) {
+
+		std::ostringstream ostream;
+		ostream << "Thread::start() Failed - Failed to create a new thread. "
+				<< " (" << errno << ": " << strerror(errno) << ")";
+
+		Logger logger;
+		logger.slog(Logger::warning, ostream.str());
+	}
+
+	if (!thread_name.empty())
+		pthread_setname_np(m_threadID, thread_name.c_str());
+}
+
+void Thread::stop()
+{
+	// If the thread wasn't running, we can't stop it
+	if (m_threadID == -1) {
+		return;
+	}
+
+	// Cancel the thread
+	if (pthread_cancel(m_threadID) != 0) {
+
+		std::ostringstream ostream;
+		ostream << "Thread::stop() Failed - Failed to cancel thread " << m_threadID << "."
+				<< " (" << errno << ": " << strerror(errno) << ")";
+
+		Logger logger;
+		logger.slog(Logger::warning, ostream.str());
+	}
+
+	// Reset the thread ID
+	m_threadID = -1;
+}
+
+} /* namespace jpps */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.h
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.h b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.h
new file mode 100644
index 0000000..79cc62a
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/JPPS/src/blackberry10/native/src/utils/Thread.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2012 Research In Motion Limited. All rights reserved.
+ */
+
+/*
+ * $QNXLicenseC:
+ * Copyright 2009, QNX Software Systems. All Rights Reserved.
+ *
+ * You must obtain a written license from and pay applicable license fees to QNX
+ * Software Systems before you may reproduce, modify or distribute this software,
+ * or any work that includes all or part of this software.   Free development
+ * licenses are available for evaluation and non-commercial purposes.  For more
+ * information visit http://licensing.qnx.com or email licensing@qnx.com.
+ *
+ * This file may contain contributions from others.  Please review this entire
+ * file for other proprietary rights or license notices, as well as the QNX
+ * Development Suite License Guide at http://licensing.qnx.com/license-guide/
+ * for other information.
+ * $
+ */
+
+#ifndef THREAD_H_
+#define THREAD_H_
+
+#include <sys/types.h>
+#include <string>
+
+namespace jpps {
+
+/**
+ * Simple wrapper to simplify thread management.
+ */
+class Thread {
+
+public:
+
+	/**
+	 * Constructor.
+	 */
+	Thread();
+
+	/**
+	 * Destructor.
+	 */
+	virtual ~Thread();
+
+	/**
+	 * Start a thread with the given function. If the thread is already running and has not
+	 * been stopped, this does nothing.
+	 */
+	void start(void* (*start_routine)(void*), void* arg, const std::string& thread_name = "");
+
+	/**
+	 * Stop the thread. If the thread isn't running, this does nothing.
+	 */
+	void stop();
+
+	/**
+	 * Is the thread running?
+	 */
+	inline bool isRunning() const { return (m_threadID >= 0); }
+
+private:
+
+	/** The id of this thread. */
+	pthread_t m_threadID;
+
+	/** The attributes of this thread. */
+	pthread_attr_t m_attrib;
+};
+
+} /* namespace jpps */
+#endif /* THREAD_H_ */

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/Makefile
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/Makefile b/blackberry10/bin/templates/project/plugins/Utils/Makefile
new file mode 100644
index 0000000..0e22650
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Utils/Makefile
@@ -0,0 +1,8 @@
+LIST=VARIANT
+ifndef QRECURSE
+QRECURSE=recurse.mk
+ifdef QCONFIG
+QRDIR=$(dir $(QCONFIG))
+endif
+endif
+include $(QRDIR)$(QRECURSE)

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/Makefile
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/Makefile b/blackberry10/bin/templates/project/plugins/Utils/src/Makefile
new file mode 100644
index 0000000..0e22650
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Utils/src/Makefile
@@ -0,0 +1,8 @@
+LIST=VARIANT
+ifndef QRECURSE
+QRECURSE=recurse.mk
+ifdef QCONFIG
+QRDIR=$(dir $(QCONFIG))
+endif
+endif
+include $(QRDIR)$(QRECURSE)

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/Makefile
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/Makefile b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/Makefile
new file mode 100644
index 0000000..0e22650
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/Makefile
@@ -0,0 +1,8 @@
+LIST=VARIANT
+ifndef QRECURSE
+QRECURSE=recurse.mk
+ifdef QCONFIG
+QRDIR=$(dir $(QCONFIG))
+endif
+endif
+include $(QRDIR)$(QRECURSE)

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/Makefile
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/Makefile b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/Makefile
new file mode 100644
index 0000000..0cc5eae
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/Makefile
@@ -0,0 +1,8 @@
+LIST=CPU
+ifndef QRECURSE
+QRECURSE=recurse.mk
+ifdef QCONFIG
+QRDIR=$(dir $(QCONFIG))
+endif
+endif
+include $(QRDIR)$(QRECURSE)

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/common.mk
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/common.mk b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/common.mk
new file mode 100644
index 0000000..90a43db
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/common.mk
@@ -0,0 +1,18 @@
+ifndef QCONFIG
+QCONFIG=qconfig.mk
+endif
+include $(QCONFIG)
+
+NAME=utils
+LDFLAGS+=-Wl,-h,libutils.so
+
+include ../../../../../../meta.mk
+
+SRCS+=$(WEBWORKS_DIR)/dependencies/JsonCpp/jsoncpp-src-0.6.0-rc2/src/lib_json/json_reader.cpp \
+      $(WEBWORKS_DIR)/dependencies/JsonCpp/jsoncpp-src-0.6.0-rc2/src/lib_json/json_value.cpp \
+      $(WEBWORKS_DIR)/dependencies/JsonCpp/jsoncpp-src-0.6.0-rc2/src/lib_json/json_writer.cpp \
+      webworks_utils.cpp
+
+include $(MKFILES_ROOT)/qtargets.mk
+
+LIBS += socket

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/device/libutils.so
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/device/libutils.so b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/device/libutils.so
new file mode 100644
index 0000000..126d02c
Binary files /dev/null and b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/device/libutils.so differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/simulator/libutils.so
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/simulator/libutils.so b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/simulator/libutils.so
new file mode 100644
index 0000000..392ad33
Binary files /dev/null and b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/simulator/libutils.so differ

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.cpp
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.cpp b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.cpp
new file mode 100644
index 0000000..68397a1
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <resolv.h>
+#include <sstream>
+#include <string>
+
+#include "webworks_utils.hpp"
+
+namespace webworks {
+
+std::string Utils::intToStr(const int val)
+{
+    std::string s;
+    std::stringstream out;
+    out << val;
+    return out.str();
+}
+
+int Utils::strToInt(const std::string& val) {
+    int number;
+
+    if (!(std::istringstream(val) >> number)) {
+        return -1;
+    }
+    return number;
+}
+
+std::string Utils::toBase64(const unsigned char *input, const size_t size)
+{
+    size_t outputSize = size * 4;
+    char *output = new char[outputSize];
+    outputSize = b64_ntop(input, size, output, outputSize);
+    output[outputSize] = 0;
+
+    std::string outputString(output);
+    delete output;
+
+    return outputString;
+}
+
+} // namespace webworks

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/92134ef7/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.hpp
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.hpp b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.hpp
new file mode 100644
index 0000000..4ab2ca7
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Utils/src/blackberry10/native/webworks_utils.hpp
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2012 Research In Motion Limited.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef WW_UTILS_HPP_
+#define WW_UTILS_HPP_
+
+#include <string.h>
+#include <string>
+
+namespace webworks {
+
+class Utils {
+public:
+    static std::string intToStr(const int val);
+    static int strToInt(const std::string& val);
+    static std::string toBase64(const unsigned char *input, const size_t size);
+};
+
+} // namespace webworks
+
+#endif // WW_UTILS_HPP_