Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

remove led from master branch

  • Loading branch information...
commit c27a22c475b88f57db64927a41efe551864c321e 1 parent e74a1fb
@andywu89 authored
View
52 BB10/LED/README.md
@@ -1,52 +0,0 @@
-# LED API
-
-The LED API allows you to control the LED.
-
-**Tested On**
-
-* BlackBerry 10.0.9.388
-
-**Author(s)**
-
-* [Andy Wu](https://github.com/andywu89)
-
-**To contribute code to this repository you must be [signed up as an official contributor](http://blackberry.github.com/howToContribute.html).**
-
-## How To Install The Extension
-
-1. Clone the repo to your local machine
-2. Locate your BlackBerry WebWorks SDK **C:\Program Files\Research In Motion\BlackBerry 10 WebWorks SDK <version>\Framework\ext** (Windows) or **~/SDKs/BlackBerry 10 WebWorks SDK <version>/Framework/ext** (Mac)
-3. Create a new directory **webworks.bbalert.led** in the **ext** directory.
-4. Copy **output/webworks.bbalert.led/ledJnext.so** to **/path/to/sdk/ext/webworks.bbalert.led/device/ledJnext.so**
-5. Copy everything in **javascript_src** to **/path/to/sdk/ext/webworks.bbalert.led/**
-
-## Required Feature ID
-Whenever you use the below feature id in any of your WebWorks applications this extension will be loaded for use.
-
- <feature id="webworks.bbalert.led" required="true" version="1.0.0.0" />
-
-## Summary
-
-var id = webworks.bbalert.led.startLed([String: color], [String: blinkCount])
-
-Parameters:
-color: hex string with with format "RRGGBB", default: "FF0000"
-blinkCount: String Integer >=0, default: "0" (0 means Blink indefinitely until stopLed command is issued)
-
-Return:
-request id - used to reference the LED request
-
-webworks.bbalert.led.stopLed([String:id])
-Parameter:
-id: request id - given when startLed command was issued.
-
-Example:
-
- <script type="text/javascript" >
- var id = webworks.bbalert.led.startLed("FFFF00", "10");
- webworks.bbalert.led.stopLed(id)
- </script>
-
-## Disclaimer
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
3  BB10/LED/TestApplication/README.md
@@ -1,3 +0,0 @@
-# Where to find the missing file webworks-1.0.2.9.js
-
-You will find it under Framework/clientFiles/webworks-1.0.2.9.js in your WebWorks SDK installation folder and copy it to this folder.
View
13 BB10/LED/TestApplication/config.xml
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<widget xmlns="http://www.w3.org/ns/widgets"
- xmlns:rim="http://www.blackberry.com/ns/widgets"
- version="1.0.0.5" id="helloworld" xml:lang="en">
- <author href="http://www.example.com/"
- rim:copyright="Copyright 1998-2012 My Corp">My Corp</author>
- <name>helloWorld</name>
- <content src="index.html"/>
- <rim:permissions>
- <rim:permit>access_led_control</rim:permit>
- </rim:permissions>
- <feature id="webworks.bbalert.led" required="true" version="1.0.0.0"/>
-</widget>
View
65 BB10/LED/TestApplication/index.html
@@ -1,65 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Hello World</title>
- <style>
- button{
- width: 100%;
- border:none;
- height:50px;
- margin-top:10px;
- }
- #stop-buttons{
- width:100%;
- }
- </style>
-</head>
-<body>
- <div id="color-selection">
- <label>Colors</label>
- <br>
- <input type="checkbox" name="color" value="FF0000">Red<br>
- <input type="checkbox" name="color" value="00FF00">Green<br>
- <input type="checkbox" name="color" value="0000FF">Blue<br>
-
- </div>
- <label>Blink Count</label>
- <input type="text" value="1" name="blinkCount" id="blinkCount" />
- <button id="start" onclick="startLed()">start led</button>
- <div id="stop-buttons">
- </div>
- <script src="webworks-1.0.2.9.js"></script>
- <script>
- var stopButtons = document.getElementById('stop-buttons');
- function startLed(){
-
- var colors = document.getElementsByName("color");
- var currColor = 0;
-
- for(var i = 0; i < colors.length; i++){
- if(colors[i].checked){
- currColor = parseInt(colors[i].value, 16) | currColor;
- }
- }
- var id = webworks.bbalert.led.startLed(currColor.toString(16), document.getElementById("blinkCount").value);
-
- var button = document.createElement("button")
- var buttonContent = document.createTextNode("Stop Led - " + id);
- button.appendChild(buttonContent);
- button.setAttribute("id", id);
- button.onclick = function (){
- webworks.bbalert.led.stopLed(this.id);
- stopButtons.removeChild(this);
-
- };
- stopButtons.appendChild(button);
- }
-
-
- window.addEventListener("load", function(e) {
- document.addEventListener("webworksready", ready);
- }, false);
- </script>
-</body>
-</html>
View
28 BB10/LED/javascript_src/client.js
@@ -1,28 +0,0 @@
-/*
-* 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.
-*/
-
-var _self = {},
- _ID = require("./manifest.json").namespace;
-
-_self.startLed = function (color, blinkCount) {
- var args = {"color": color || {}, "blinkCount": blinkCount || {}};
- return window.webworks.execSync(_ID, "flashLedStart", args);
-};
-_self.stopLed = function (id) {
- var args = {"id": id};
- return window.webworks.execSync(_ID, "flashLedStop", args);
-};
-module.exports = _self;
View
89 BB10/LED/javascript_src/index.js
@@ -1,89 +0,0 @@
-/*
- * 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.
- */
-var ledJNext,
- _event = require("../../lib/event");
-
-module.exports = {
- flashLedStart: function (success, fail, args, env) {
- try {
- var stringArgs = "";
- for (key in args) {
- stringArgs += " " + JSON.parse(decodeURIComponent(args[key]));
- }
- success(ledJNext.flashLedStartJNext(stringArgs));
- } catch (e) {
- fail(-1, e);
- }
- },
- flashLedStop: function (success, fail, args, env) {
- try {
- var stringArgs = "";
- for (key in args) {
- stringArgs += " " + JSON.parse(decodeURIComponent(args[key]));
- }
- success(ledJNext.flashLedStopJNext(stringArgs));
- } catch (e) {
- fail(-1, e);
- }
- }
-};
-
-///////////////////////////////////////////////////////////////////
-// JavaScript wrapper for JNEXT plugin
-///////////////////////////////////////////////////////////////////
-
-JNEXT.LedJNext = function ()
-{
- var _self = this;
-
- _self.flashLedStartJNext = function (args) {
- return JNEXT.invoke(_self._id, "flashLedStartNative" + args);
- };
-
- _self.flashLedStopJNext = function (args) {
- return JNEXT.invoke(_self._id, "flashLedStopNative" + args);
- };
-
- _self.getId = function () {
- return _self._id;
- };
-
- _self.init = function () {
- if (!JNEXT.require("ledJnext")) {
- return false;
- }
-
- _self._id = JNEXT.createObject("ledJnext.FlashLed");
-
- if (!_self._id || _self._id === "") {
- return false;
- }
-
- JNEXT.registerEvents(_self);
- };
-
- _self.onEvent = function (strData) {
- var arData = strData.split(" "),
- strEventId = arData[0],
- arg = arData[1];
- };
-
- _self._id = "";
-
- _self.init();
-};
-
-ledJNext = new JNEXT.LedJNext();
View
5 BB10/LED/javascript_src/manifest.json
@@ -1,5 +0,0 @@
-{
- "global": false,
- "namespace": "webworks.bbalert.led",
- "dependencies": []
-}
View
320 BB10/LED/native_src/public/plugin.cpp
@@ -1,320 +0,0 @@
-#include "plugin.h"
-#include "tokenizer.h"
-
-#ifdef _WINDOWS
-#include <windows.h>
-BOOL APIENTRY DllMain( HANDLE hModule,
- DWORD ul_reason_for_call,
- LPVOID lpReserved )
-{
- return TRUE;
-}
-#else
-#include <errno.h>
-#include <string.h>
-
-extern int errno;
-#endif
-
-SendPluginEv SendPluginEvent;
-
-string g_GetSysErrMsg( void )
-{
- string strError = "Unknown";
- // Problem loading
-#ifdef _WINDOWS
- int nErrorCode = GetLastError();
- LPTSTR s;
- if ( ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL, nErrorCode, 0, ( LPTSTR ) &s, 0, NULL ) )
- {
- strError = s;
- }
- else
- {
- char szBuf[ 20 ];
- _snprintf_s( szBuf, _countof(szBuf), 19, "%d", nErrorCode );
- strError = szBuf;
- }
-#else
- char szError[80];
- if ( strerror_r( errno, szError, sizeof(szError) ) )
- {
- strError = "no description found";
- }
- else
- {
- strError = szError;
- }
-#endif
- return strError;
-}
-
-void g_sleep( unsigned int mseconds )
-{
-#ifdef _WINDOWS
- Sleep( mseconds );
-#else
- usleep( mseconds * 1000 );
-#endif
-}
-
-string& g_trim( string& str )
-{
- // Whitespace characters
- char whspc[] = " \t\r\n\v\f";
-
- // Whack off first part
- size_t pos = str.find_first_not_of( whspc );
-
- if ( pos != string::npos )
- str.replace( 0, pos, "" );
-
- // Whack off trailing stuff
- pos = str.find_last_not_of( whspc );
-
- if ( pos != string::npos )
- str.replace( pos + 1, str.length() - pos, "" );
-
- return str;
-}
-
-void g_tokenize( const string& str, const string& delimiters, vector<string>& tokens )
-{
- tokenize( str, tokens, delimiters );
-}
-
-char* SetEventFunc( SendPluginEv funcPtr )
-{
- static char * szObjList = onGetObjList();
- SendPluginEvent = funcPtr;
- return szObjList;
-}
-
-
-const int nMAXSIZE = 512;
-char* g_pszRetVal = NULL;
-
-//-----------------------------------------------------------
-// Map from an object Id to an object instance
-//-----------------------------------------------------------
-typedef std::map<string, JSExt*> StringToJExt_T;
-
-//-----------------------------------------------------------
-// Map from a browser context to an id mapping
-//-----------------------------------------------------------
-typedef std::map<void*, StringToJExt_T*> VoidToMap_T;
-
-VoidToMap_T g_context2Map;
-
-class GlobalSharedModule
-{
-
-public:
- GlobalSharedModule( void )
- {
- g_pszRetVal = new char[ nMAXSIZE ];
- }
-
- ~GlobalSharedModule()
- {
- delete [] g_pszRetVal;
-
- VoidToMap_T::iterator posMaps;
-
- for ( posMaps = g_context2Map.begin(); posMaps != g_context2Map.end(); ++posMaps )
- {
- StringToJExt_T& id2Obj = *posMaps->second;
- StringToJExt_T::iterator posMap;
-
- for ( posMap = id2Obj.begin(); posMap != id2Obj.end(); ++posMap )
- {
- JSExt* pJSExt = posMap->second;
-
- if ( pJSExt->CanDelete() )
- {
- delete pJSExt;
- }
- }
-
- id2Obj.erase( id2Obj.begin(), id2Obj.end() );
- }
-
- g_context2Map.erase( g_context2Map.begin(), g_context2Map.end() );
- }
-};
-
-GlobalSharedModule g_sharedModule;
-
-char* g_str2global( const string& strRetVal )
-{
- int nLen = strRetVal.size();
-
- if ( nLen >= nMAXSIZE )
- {
- delete [] g_pszRetVal;
- g_pszRetVal = new char[ nLen + 1 ];
- }
-
- else
- {
- // To minimaize the number of memory reallocations, the assumption
- // is that in most times this will be the case
- delete [] g_pszRetVal;
- g_pszRetVal = new char[ nMAXSIZE ];
- }
-
- strcpy( g_pszRetVal, strRetVal.c_str() );
- return g_pszRetVal;
-}
-
-bool g_unregisterObject( const string& strObjId, void* pContext )
-{
- // Called by the plugin extension implementation
- // if the extension handles the deletion of its object
-
- StringToJExt_T * pID2Obj = NULL;
-
- VoidToMap_T::iterator iter = g_context2Map.find( pContext );
-
- if ( iter != g_context2Map.end() )
- {
- pID2Obj = iter->second;
- }
- else
- {
- return false;
- }
-
- StringToJExt_T& mapID2Obj = *pID2Obj;
-
- StringToJExt_T::iterator r = mapID2Obj.find( strObjId );
-
- if ( r == mapID2Obj.end() )
- {
- return false;
- }
-
- mapID2Obj.erase( strObjId );
- return true;
-}
-
-char* InvokeFunction( const char* szCommand, void* pContext )
-{
- StringToJExt_T * pID2Obj = NULL;
-
- VoidToMap_T::iterator iter = g_context2Map.find( pContext );
-
- if ( iter != g_context2Map.end() )
- {
- pID2Obj = iter->second;
- }
- else
- {
- pID2Obj = new StringToJExt_T;
- g_context2Map[ pContext ] = pID2Obj;
- }
-
- StringToJExt_T& mapID2Obj = *pID2Obj;
-
- string strFullCommand = szCommand;
- vector<string> arParams;
- g_tokenize( strFullCommand, " ", arParams );
- string strCommand = arParams[ 0 ];
- string strRetVal = szERROR;
-
- if ( strCommand == szCREATE )
- {
- string strClassName = arParams[ 1 ];
- string strObjId = arParams[ 2 ];
-
- StringToJExt_T::iterator r = mapID2Obj.find( strObjId );
-
- if ( r != mapID2Obj.end() )
- {
- strRetVal += strObjId;
- strRetVal += " :Object already exists.";
- return g_str2global( strRetVal );
- }
-
- JSExt* pJSExt = onCreateObject( strClassName, strObjId );
-
- if ( pJSExt == NULL )
- {
- strRetVal += strObjId;
- strRetVal += " :Unknown object type ";
- strRetVal += strClassName;
- return g_str2global( strRetVal );
- }
-
- pJSExt->m_pContext = pContext;
- mapID2Obj[ strObjId ] = pJSExt;
-
- strRetVal = szOK;
- strRetVal += strObjId;
- return g_str2global( strRetVal );
- }
- else
- if ( strCommand == szINVOKE )
- {
- string strObjId = arParams[ 1 ];
- string strMethod = arParams[ 2 ];
-
- StringToJExt_T::iterator r = mapID2Obj.find( strObjId );
-
- if ( r == mapID2Obj.end() )
- {
- strRetVal += strObjId;
- strRetVal += " :No object found for id.";
- return g_str2global( strRetVal );
- }
-
- JSExt* pJSExt = r->second;
-
- size_t nLoc = strFullCommand.find( strObjId );
-
- if ( nLoc == string::npos )
- {
- strRetVal += strObjId;
- strRetVal += " :Internal InvokeMethod error.";
- return g_str2global( strRetVal );
- }
-
- if ( strMethod == szDISPOSE )
- {
- StringToJExt_T::iterator r = mapID2Obj.find( strObjId );
-
- if ( r == mapID2Obj.end() )
- {
- strRetVal = szERROR;
- strRetVal += strObjId;
- return g_str2global( strRetVal );
- }
-
- JSExt * pJSExt = mapID2Obj[ strObjId ];
-
- if ( pJSExt->CanDelete() )
- {
- delete pJSExt;
- }
-
- mapID2Obj.erase( strObjId );
- strRetVal = szOK;
- strRetVal += strObjId;
- return g_str2global( strRetVal );
- }
-
- size_t nSuffixLoc = nLoc + strObjId.size();
- string strInvoke = strFullCommand.substr( nSuffixLoc );
- strInvoke = g_trim( strInvoke );
- strRetVal = pJSExt->InvokeMethod( strInvoke );
- return g_str2global( strRetVal );
- }
-
- strRetVal += " :Unknown command ";
- strRetVal += strCommand;
- return g_str2global( strRetVal );
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
View
70 BB10/LED/native_src/public/plugin.h
@@ -1,70 +0,0 @@
-#ifndef _PLUGIN_H
-#define _PLUGIN_H
-
-#include <map>
-#include <string>
-#include <vector>
-#include <unistd.h>
-//#include "tokenizer.h"
-
-using namespace std;
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-//%% Functions exported by this DLL
-//%% Should always be only SetEventFunc and InvokeFunction
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-// g++ requires extern "C" otherwise the names of SetEventFunc and InvokeFunction
-// are mangled C++ style. MS Visual Studio doesn't seem to care though.
-extern "C"
-{
- typedef void (*SendPluginEv)( const char* szEvent, void* pContext );
- char* SetEventFunc(SendPluginEv funcPtr);
- char* InvokeFunction( const char* szCommand, void* pContext );
-}
-
-// JNEXT Framework function of the form:
-// typedef void (*SendPluginEv)( const char* szEvent );
-// used to notify JavaScript of an asynchronous event
-extern SendPluginEv SendPluginEvent;
-
-/////////////////////////////////////////////////////////////////////////
-// Constants and methods common to all JNEXT extensions types
-/////////////////////////////////////////////////////////////////////////
-#define szERROR "Error "
-#define szOK "Ok "
-
-#define szDISPOSE "Dispose"
-#define szINVOKE "InvokeMethod"
-#define szCREATE "CreateObj"
-
-/////////////////////////////////////////////////////////////////////////
-// Utility functions
-/////////////////////////////////////////////////////////////////////////
-string& g_trim( string& str );
-void g_tokenize(const string& str,const string& delimiters, vector<string>& tokens);
-char* g_str2static( const string& strRetVal );
-void g_sleep( unsigned int mseconds );
-bool g_unregisterObject( const string& strObjId, void* pContext );
-
-
-/////////////////////////////////////////////////////////////////////////
-// Abstract extension object
-/////////////////////////////////////////////////////////////////////////
-class JSExt
-{
-public:
- virtual ~JSExt() {};
- virtual string InvokeMethod( const string& strCommand ) = 0;
- virtual bool CanDelete( void ) = 0;
- virtual void TryDelete( void ) {}
-public:
- void* m_pContext;
-};
-
-/////////////////////////////////////////////////////////////////////////
-// Callback functions to be implemented by the plugin implementation
-/////////////////////////////////////////////////////////////////////////
-extern char* onGetObjList( void );
-extern JSExt* onCreateObject( const string& strClassName, const string& strObjId );
-
-#endif
View
222 BB10/LED/native_src/public/tokenizer.cpp
@@ -1,222 +0,0 @@
-/************************************************************************
-The zlib/libpng License
-
-Copyright (c) 2006 Joerg Wiedenmann
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from
-the use of this software.
-
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely, subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented;
-you must not claim that you wrote the original software.
-If you use this software in a product, an acknowledgment
-in the product documentation would be appreciated but is
-not required.
-
-2. Altered source versions must be plainly marked as such,
-and must not be misrepresented as being the original software.
-
-3. This notice may not be removed or altered from any source distribution.
-
-***********************************************************************/
-
-/********************************************************************
- created: 2006-01-28
- filename: tokenizer.cpp
- author: Jörg Wiedenmann
-
- purpose: A tokenizer function which provides a very
- customizable way of breaking up strings.
-
- history: 2006-01-28, Original version
- 2006-03-04, Fixed a small parsing bug, thanks Elias.
-*********************************************************************/
-
-#include "tokenizer.h"
-
-using namespace std;
-
-void tokenize ( const string& str, vector<string>& result,
- const string& delimiters, const string& delimiters_preserve,
- const string& quote, const string& esc )
-{
- // clear the vector
- if ( false == result.empty() )
- {
- result.clear();
- }
-
- string::size_type pos = 0; // the current position (char) in the string
- char ch = 0; // buffer for the current character
- char delimiter = 0; // the buffer for the delimiter char which
- // will be added to the tokens if the delimiter
- // is preserved
- char current_quote = 0; // the char of the current open quote
- bool quoted = false; // indicator if there is an open quote
- string token; // string buffer for the token
- bool token_complete = false; // indicates if the current token is
- // read to be added to the result vector
- string::size_type len = str.length(); // length of the input-string
-
- // for every char in the input-string
- while ( len > pos )
- {
- // get the character of the string and reset the delimiter buffer
- ch = str.at(pos);
- delimiter = 0;
-
- // assume ch isn't a delimiter
- bool add_char = true;
-
- // check ...
-
- // ... if the delimiter is an escaped character
- bool escaped = false; // indicates if the next char is protected
- if ( false == esc.empty() ) // check if esc-chars are provided
- {
- if ( string::npos != esc.find_first_of(ch) )
- {
- // get the escaped char
- ++pos;
- if ( pos < len ) // if there are more chars left
- {
- // get the next one
- ch = str.at(pos);
-
- // add the escaped character to the token
- add_char = true;
- }
- else // cannot get any more characters
- {
- // don't add the esc-char
- add_char = false;
- }
-
- // ignore the remaining delimiter checks
- escaped = true;
- }
- }
-
- // ... if the delimiter is a quote
- if ( false == quote.empty() && false == escaped )
- {
- // if quote chars are provided and the char isn't protected
- if ( string::npos != quote.find_first_of(ch) )
- {
- // if not quoted, set state to open quote and set
- // the quote character
- if ( false == quoted )
- {
- quoted = true;
- current_quote = ch;
-
- // don't add the quote-char to the token
- add_char = false;
- }
- else // if quote is open already
- {
- // check if it is the matching character to close it
- if ( current_quote == ch )
- {
- // close quote and reset the quote character
- quoted = false;
- current_quote = 0;
-
- // don't add the quote-char to the token
- add_char = false;
- }
- } // else
- }
- }
-
- // ... if the delimiter isn't preserved
- if ( false == delimiters.empty() && false == escaped &&
- false == quoted )
- {
- // if a delimiter is provided and the char isn't protected by
- // quote or escape char
- if ( string::npos != delimiters.find_first_of(ch) )
- {
- // if ch is a delimiter and the token string isn't empty
- // the token is complete
- if ( false == token.empty() ) // BUGFIX: 2006-03-04
- {
- token_complete = true;
- }
-
- // don't add the delimiter to the token
- add_char = false;
- }
- }
-
- // ... if the delimiter is preserved - add it as a token
- bool add_delimiter = false;
- if ( false == delimiters_preserve.empty() && false == escaped &&
- false == quoted )
- {
- // if a delimiter which will be preserved is provided and the
- // char isn't protected by quote or escape char
- if ( string::npos != delimiters_preserve.find_first_of(ch) )
- {
- // if ch is a delimiter and the token string isn't empty
- // the token is complete
- if ( false == token.empty() ) // BUGFIX: 2006-03-04
- {
- token_complete = true;
- }
-
- // don't add the delimiter to the token
- add_char = false;
-
- // add the delimiter
- delimiter = ch;
- add_delimiter = true;
- }
- }
-
-
- // add the character to the token
- if ( true == add_char )
- {
- // add the current char
- token.push_back( ch );
- }
-
- // add the token if it is complete
- if ( true == token_complete && false == token.empty() )
- {
- // add the token string
- result.push_back( token );
-
- // clear the contents
- token.clear();
-
- // build the next token
- token_complete = false;
- }
-
- // add the delimiter
- if ( true == add_delimiter )
- {
- // the next token is the delimiter
- string delim_token;
- delim_token.push_back( delimiter );
- result.push_back( delim_token );
-
- // REMOVED: 2006-03-04, Bugfix
- }
-
- // repeat for the next character
- ++pos;
- } // while
-
- // add the final token
- if ( false == token.empty() )
- {
- result.push_back( token );
- }
-}
View
55 BB10/LED/native_src/public/tokenizer.h
@@ -1,55 +0,0 @@
-/************************************************************************
-The zlib/libpng License
-
-Copyright (c) 2006 Joerg Wiedenmann
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from
-the use of this software.
-
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely, subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented;
- you must not claim that you wrote the original software.
- If you use this software in a product, an acknowledgment
- in the product documentation would be appreciated but is
- not required.
-
-2. Altered source versions must be plainly marked as such,
- and must not be misrepresented as being the original software.
-
-3. This notice may not be removed or altered from any source distribution.
-
-***********************************************************************/
-
-/********************************************************************
- created: 2006-01-28
- filename: tokenizer.cpp
- author: Jörg Wiedenmann
-
- purpose: A tokenizer function which provides a very
- customizable way of breaking up strings.
-*********************************************************************/
-
-#include <vector>
-#include <string>
-using namespace std;
-
-// Function to break up a string into tokens
-//
-// Parameters:
-//-----------
-// str = the input string that will be tokenized
-// result = the tokens for str
-// delimiters = the delimiter characters
-// delimiters preserve = same as above, but the delimiter characters
-// will be put into the result as a token
-// quote = characters to protect the enclosed characters
-// esc = characters to protect a single character
-//
-
-void tokenize ( const string& str, vector<string>& result,
- const string& delimiters, const string& delimiters_preserve = "",
- const string& quote = "\"", const string& esc = "\\" );
View
122 BB10/LED/native_src/src/led_js.cpp
@@ -1,122 +0,0 @@
-/*
- * 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 <string>
-#include <sstream>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include "led_js.hpp"
-#include <errno.h>
-using namespace std;
-
-FlashLed::FlashLed(const std::string& id) :
- m_id(id) {
-
-}
-
-FlashLed::~FlashLed() {
-}
-
-char* onGetObjList() {
- static char name[] = "FlashLed";
- return name;
-}
-
-JSExt* onCreateObject(const string& className, const string& id) {
- if (className == "FlashLed") {
- return new FlashLed(id);
- }
-
- return NULL;
-}
-
-
-bool FlashLed::CanDelete() {
- return true;
-}
-
-/**
- * Usage from javascript:
- * var id = flashLED('color', 'blink_count')
- * stopLed(id);
- */
-string FlashLed::InvokeMethod(const string& command) {
-
- bps_initialize();
-
- // Determine which function should be executed
- size_t index = command.find_first_of(" ");
- string strCommand = command.substr(0, index);
-
- if (strCommand == "flashLedStartNative") {
- int colorCode = LED_COLOR_RED;
- int blinkCount = 0;
- if (command.length() > index) {
- string params = command.substr(index + 1, command.length());
-
- size_t indexColor = params.find_first_of(" ");
- string color = params.substr(0, indexColor);
-
- // attempt to convert hex string passed in from JavaScript to integer
- char * p;
- long n = strtoul(color.c_str(), &p, 16);
- if (*p != 0) {
- fprintf(stderr, "Invalid color");
-
- } else {
- colorCode = (int) n;
- }
-
- if (params.length() > indexColor) {
- string blink = params.substr(indexColor + 1, params.length());
- blinkCount = atoi(blink.c_str());
- }
-
- }
- return this->startLed(colorCode, blinkCount);
- } else if (strCommand == "flashLedStopNative") {
- string id = command.substr(index + 1, command.length());
- return this->stopLed(id.c_str());
- }
- return "Unsupported Method";
-
-}
-
-string FlashLed::startLed(int color, int blinkCount) {
-
- //creates a reference id for user
- string id = convertLongToString(clock());
- int status = led_request_rgb(id.c_str(), color, blinkCount);
-
- return id;
-}
-string FlashLed::stopLed(string id) {
- int status = led_cancel(id.c_str());
- if (status == BPS_SUCCESS) {
- return "BPS_SUCCESS";
- } else {
- return strerror(errno);
- }
-
-}
-string FlashLed::convertLongToString(long l) {
- stringstream ss;
- ss << l;
- return ss.str();
-}
-
View
43 BB10/LED/native_src/src/led_js.hpp
@@ -1,43 +0,0 @@
-/*
-* 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 MEMORY_JS_HPP_
-#define MEMORY_JS_HPP_
-
-#include <string>
-#include <pthread.h>
-#include "../public/plugin.h"
-#include <bps/led.h>
-#include <bps/bps.h>
-class FlashLed: public JSExt {
-
-public:
- explicit FlashLed(const std::string& id);
- virtual ~FlashLed();
-
-// Interfaces of JSExt
- virtual bool CanDelete();
- virtual std::string InvokeMethod(const std::string& command);
-
-private:
- string startLed(int color, int blinkCount);
- string stopLed(string id);
- std::string m_id;
- string convertLongToString(long l);
-};
-
-
-
-#endif /* LED_JS_HPP_ */
View
BIN  BB10/LED/output/webworks.bbalert.led/ledJnext.so
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.