Adding the Speech web api plugin 12/8412/1
authorBrian Jones <brian.j.jones@intel.com>
Sun, 18 Aug 2013 05:14:13 +0000 (22:14 -0700)
committerBrian Jones <brian.j.jones@intel.com>
Sun, 18 Aug 2013 05:14:13 +0000 (22:14 -0700)
Signed-off-by: Brian Jones <brian.j.jones@intel.com>
src/CMakeLists.txt
src/Speech/CMakeLists.txt [new file with mode: 0644]
src/Speech/JSSpeech.cpp [new file with mode: 0644]
src/Speech/JSSpeech.h [new file with mode: 0644]
src/Speech/Speech.cpp [new file with mode: 0644]
src/Speech/Speech.h [new file with mode: 0644]
src/Speech/Speech.idl [new file with mode: 0644]
src/Speech/SpeechListener.cpp [new file with mode: 0644]
src/Speech/SpeechListener.h [new file with mode: 0644]
src/Speech/config.xml [new file with mode: 0644]
src/Speech/plugin_initializer.cpp [new file with mode: 0644]

index ba21fae..ced59cc 100644 (file)
@@ -20,5 +20,6 @@ SET(LIBS_TEST
 add_plugin(
        Vehicle
        MediaServer
+       Speech
 )
 
diff --git a/src/Speech/CMakeLists.txt b/src/Speech/CMakeLists.txt
new file mode 100644 (file)
index 0000000..34b8fee
--- /dev/null
@@ -0,0 +1,67 @@
+SET(TARGET_NAME ${speech_target})
+SET(DESTINATION_NAME ${speech_dest})
+SET(TARGET_IMPL_NAME ${speech_impl})
+
+cmake_minimum_required(VERSION 2.8)
+
+add_definitions(-std=c++11)
+
+include(FindPkgConfig)
+
+PKG_CHECK_MODULES(REQUIRED gio-2.0 wrt-plugins-tizen-common json-glib-1.0)
+
+find_library(uuid_LIBRARY uuid DOC "Uuid libraries")
+find_path(uuid_INCLUDE_DIR uuid/uuid.h DOC "Libtool headers")
+
+if(uuid_LIBRARY)
+        message(STATUS "uuid found")
+else(uuid_LIBRARY)
+        message(FATAL_ERROR "uuid missing.  please install uuid-dev")
+endif(uuid_LIBRARY)
+
+
+
+INCLUDE_DIRECTORIES(
+       ${INCLUDE_COMMON}
+       ${amb_INCLUDE_DIRS}
+       ${uuid_INCLUDE_DIR}
+)
+
+SET(CMAKE_INSTALL_RPATH
+       ${CMAKE_INSTALL_RPATH}
+       ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${tizen_dest}
+       ${CMAKE_INSTALL_PREFIX}/${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME}
+)
+
+SET(SRCS_IMPL
+       SpeechListener.cpp
+       Speech.cpp
+       JSSpeech.cpp
+)
+
+ADD_LIBRARY(${TARGET_IMPL_NAME} SHARED ${SRCS_IMPL})
+
+TARGET_LINK_LIBRARIES(${TARGET_IMPL_NAME}
+       ${LIBS_COMMON}
+       ${uuid_LIBRARY}
+       -L/usr/lib/wrt-plugins/tizen-tizen/
+)
+
+SET(SRCS
+       plugin_initializer.cpp
+)
+
+ADD_LIBRARY(${TARGET_NAME} SHARED ${SRCS})
+
+TARGET_LINK_LIBRARIES(${TARGET_NAME}
+       ${TARGET_IMPL_NAME}
+)
+
+INSTALL(TARGETS ${TARGET_NAME} ${TARGET_IMPL_NAME} LIBRARY DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/config.xml DESTINATION ${DESTINATION_LIB_PREFIX}/${DESTINATION_NAME})
+INSTALL(
+       DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ DESTINATION ${DESTINATION_HEADER_PREFIX}/speech
+       FILES_MATCHING PATTERN "*.h" PATTERN "CMakeFiles" EXCLUDE
+)
+
+
diff --git a/src/Speech/JSSpeech.cpp b/src/Speech/JSSpeech.cpp
new file mode 100644 (file)
index 0000000..6ee9c25
--- /dev/null
@@ -0,0 +1,261 @@
+//
+// Tizen Speech Web API
+// Copyright (c) 2013, Intel Corporation.
+//
+// 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 "JSSpeech.h"
+
+namespace DeviceAPI {
+namespace Speech {
+
+using namespace DPL;
+using namespace DeviceAPI::Common;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+JSClassDefinition JSSpeech::m_classInfo = {
+        0,
+        kJSClassAttributeNone,
+        "Speech",
+        0,
+        m_property,
+        m_function,
+        initialize,
+        finalize,
+        NULL, //HasProperty,
+        NULL, //GetProperty,
+        NULL, //SetProperty,
+        NULL, //DeleteProperty,
+        NULL, //GetPropertyNames,
+        NULL, //CallAsFunction,
+        NULL, //CallAsConstructor,
+        hasInstance,
+        NULL, //ConvertToType
+};
+
+JSStaticValue JSSpeech::m_property[] = {
+        { "language", getLang, setLang, kJSPropertyAttributeNone },
+        { "continuous", getContinuous, setContinuous, kJSPropertyAttributeNone },
+        { "intermResults", getInterimResults, NULL, kJSPropertyAttributeReadOnly },
+        { "maxAlternatives", getMaxAlternatives, setMaxAlternatives, kJSPropertyAttributeNone },
+        { "serviceURI", getServiceURI, NULL, kJSPropertyAttributeReadOnly },
+        { 0, 0, 0, 0 }
+};
+
+JSStaticFunction JSSpeech::m_function[] = {
+               { "start", JSSpeech::start, kJSPropertyAttributeNone },
+               { "stop", JSSpeech::stop, kJSPropertyAttributeNone },
+        { "abort", JSSpeech::abort, kJSPropertyAttributeNone },
+        { "setCBListener", JSSpeech::setCBListener, kJSPropertyAttributeNone },
+        { 0, 0, 0 }
+};
+
+const JSClassRef JSSpeech::getClassRef()
+{
+        if (!m_jsClassRef)
+        {
+                m_jsClassRef = JSClassCreate(&m_classInfo);
+        }
+        return m_jsClassRef;
+}
+
+const JSClassDefinition* JSSpeech::getClassInfo()
+{
+        return &m_classInfo;
+}
+
+JSClassRef JSSpeech::m_jsClassRef = JSClassCreate(JSSpeech::getClassInfo());
+
+void JSSpeech::initialize(JSContextRef context, JSObjectRef object)
+{
+        SpeechPrivObject* priv = static_cast<SpeechPrivObject*>(JSObjectGetPrivate(object));
+        if (!priv)
+        {
+                SpeechPtr speech(new SpeechMaster());
+                priv = new SpeechPrivObject( context, speech);
+                if(!JSObjectSetPrivate(object, static_cast<void*>(priv)))
+                {
+                        LoggerE("Object can't store private data.");
+                        delete priv;
+                }
+        }
+
+        LoggerD("JSSpeech::initialize ");
+}
+
+void JSSpeech::finalize(JSObjectRef object)
+{
+        SpeechPrivObject* priv = static_cast<SpeechPrivObject*>(JSObjectGetPrivate(object));
+        JSObjectSetPrivate(object, NULL);
+        LoggerD("Deleting timeutil");
+        delete priv;
+}
+
+bool JSSpeech::hasInstance(JSContextRef context,
+                JSObjectRef constructor,
+                JSValueRef possibleInstance,
+                JSValueRef* exception)
+{
+        return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
+}
+
+JSValueRef JSSpeech::setCBListener(JSContextRef context,
+                               JSObjectRef object,
+                               JSObjectRef thisObject,
+                               size_t argumentCount,
+                               const JSValueRef arguments[],
+                               JSValueRef* exception)
+{
+       LoggerD("setCBListener called for JSSpeech");
+
+       SpeechPrivObject* privateObject = static_cast<SpeechPrivObject*>(JSObjectGetPrivate(thisObject));
+
+       LoggerD("setCBListener break 1");
+
+       if (NULL == privateObject)
+       {
+               LoggerE("private object is null");
+       }
+
+       LoggerD("setCBListener break 2");
+
+       SpeechPtr speechPtr(privateObject->getObject());                        //get the private object
+
+       LoggerD("setCBListener break 3");
+
+       JSContextRef gContext = privateObject->getContext();                    // get the private context
+
+       ArgumentValidator validator(context, argumentCount, arguments);         //set up argument validator
+       JSObjectRef callbackObj = validator.toCallbackObject(0,false,"onaudiostart","onsoundstart","onspeechstart", "onspeechend", "onsoundend", "onresult", "onnomatch", "onerror", "onstart", "onend", "NULL");
+       JSValueProtect(context, callbackObj);
+       speechPtr->setCBListener(callbackObj, gContext);
+
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSpeech::getLang(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception)
+{
+       LoggerD("getLang called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+bool JSSpeech::setLang(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef value,
+                                JSValueRef* exception)
+{
+       LoggerD("setLang called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSpeech::getContinuous(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception)
+{
+       LoggerD("getContinuous called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+bool JSSpeech::setContinuous(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef value,
+                                JSValueRef* exception)
+{
+       LoggerD("setContinuous called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSpeech::getInterimResults(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception)
+{
+       LoggerD("getInterimResults called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSpeech::getMaxAlternatives(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception)
+{
+       LoggerD("getMaxAlternatives called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+bool JSSpeech::setMaxAlternatives(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef value,
+                                JSValueRef* exception)
+{
+       LoggerD("setMaxAlternatives called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSpeech::getServiceURI(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception)
+{
+       LoggerD("getServiceURI called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+       // Method calls
+
+
+JSValueRef JSSpeech::start(JSContextRef context,
+                                JSObjectRef object,
+                                JSObjectRef thisObject,
+                                size_t argumentCount,
+                                const JSValueRef arguments[],
+                                JSValueRef* exception)
+{
+       LoggerD("start called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSpeech::stop(JSContextRef context,
+                                JSObjectRef object,
+                                JSObjectRef thisObject,
+                                size_t argumentCount,
+                                const JSValueRef arguments[],
+                                JSValueRef* exception)
+{
+       LoggerD("stop called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+JSValueRef JSSpeech::abort(JSContextRef context,
+                                JSObjectRef object,
+                                JSObjectRef thisObject,
+                                size_t argumentCount,
+                                const JSValueRef arguments[],
+                                JSValueRef* exception)
+{
+       LoggerD("abort called for JSSpeech: Sorry this method is not implemented yet");
+       return JSValueMakeUndefined(context);
+}
+
+
+}
+}
diff --git a/src/Speech/JSSpeech.h b/src/Speech/JSSpeech.h
new file mode 100644 (file)
index 0000000..1235497
--- /dev/null
@@ -0,0 +1,168 @@
+//
+// Tizen Speech Web API
+// Copyright (c) 2013, Intel Corporation.
+//
+// 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 JSSPEECH_H
+#define JSSPEECH_H
+
+#include "Speech.h"
+#include <dpl/shared_ptr.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <CommonsJavaScript/JSPendingOperationPrivateObject.h>
+#include <CommonsJavaScript/PrivateObject.h>
+#include <Logger.h>
+#include <Commons/Exception.h>
+#include <CommonsJavaScript/Utils.h>
+#include <CommonsJavaScript/JSCallbackManager.h>
+#include <JSWebAPIErrorFactory.h>
+#include <ArgumentValidator.h>
+#include <CommonsJavaScript/Converter.h>
+#include <sstream>
+
+#include <json-glib/json-gvariant.h>
+
+namespace DeviceAPI {
+namespace Speech {
+
+typedef WrtDeviceApis::CommonsJavaScript::PrivateObject<SpeechPtr, WrtDeviceApis::CommonsJavaScript::NoOwnership> SpeechPrivObject;
+
+class JSSpeech
+{
+public:
+       static const JSClassDefinition* getClassInfo();
+       static const JSClassRef getClassRef();
+
+private:
+       /**
+               * The callback invoked when an object is first created.
+               */
+       static void initialize(JSContextRef context,
+                                                  JSObjectRef object);
+
+       /**
+               * The callback invoked when an object is finalized.
+               */
+       static void finalize(JSObjectRef object);
+
+       /**
+               * The callback invoked when an object is used as the target of an 'instanceof' expression.
+               */
+       static bool hasInstance(JSContextRef ctx,
+                                                       JSObjectRef constructor,
+                                                       JSValueRef possibleInstance,
+                                                       JSValueRef* exception);
+
+       //  Get & set parameters for speech recognition
+
+       static JSValueRef getLang(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception);
+
+
+       static bool setLang(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef value,
+                                JSValueRef* exception);
+
+       static JSValueRef getContinuous(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception);
+
+       static bool setContinuous(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef value,
+                                JSValueRef* exception);
+
+       static JSValueRef getInterimResults(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception);
+
+       static JSValueRef getMaxAlternatives(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception);
+
+       static bool setMaxAlternatives(JSContextRef context,
+                                JSObjectRef object,
+                                JSStringRef propertyName,
+                                JSValueRef value,
+                                JSValueRef* exception);
+
+       static JSValueRef getServiceURI(JSContextRef context,
+                              JSObjectRef object,
+                              JSStringRef propertyName,
+                              JSValueRef* exception);
+
+       // Method calls
+
+
+       static JSValueRef start(JSContextRef context,
+                                JSObjectRef object,
+                                JSObjectRef thisObject,
+                                size_t argumentCount,
+                                const JSValueRef arguments[],
+                                JSValueRef* exception);
+
+       static JSValueRef stop(JSContextRef context,
+                                JSObjectRef object,
+                                JSObjectRef thisObject,
+                                size_t argumentCount,
+                                const JSValueRef arguments[],
+                                JSValueRef* exception);
+
+       static JSValueRef abort(JSContextRef context,
+                                JSObjectRef object,
+                                JSObjectRef thisObject,
+                                size_t argumentCount,
+                                const JSValueRef arguments[],
+                                JSValueRef* exception);
+
+       static JSValueRef setCBListener(JSContextRef context,
+                                                               JSObjectRef object,
+                                                               JSObjectRef thisObject,
+                                                               size_t argumentCount,
+                                                               const JSValueRef arguments[],
+                                                               JSValueRef* exception);
+
+       /**
+                * This structure contains properties and callbacks that define a type of object.
+                */
+       static JSClassDefinition m_classInfo;
+
+    /**
+     * This member variable contains the initialization values for the
+     * properties of this class. The values are given according to
+     * the data structure JSPropertySpec
+     */
+    static JSStaticValue m_property[];
+
+       /**
+                * This structure describes a statically declared function.
+                */
+       static JSStaticFunction m_function[];
+
+       static JSClassRef m_jsClassRef;
+};
+
+}
+}
+
+#endif // JSSPEECH_H
diff --git a/src/Speech/Speech.cpp b/src/Speech/Speech.cpp
new file mode 100644 (file)
index 0000000..33c68d5
--- /dev/null
@@ -0,0 +1,198 @@
+//
+// Tizen Speech Web API
+// Copyright (c) 2013, Intel Corporation.
+//
+// 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 "Speech.h"
+#include <gio/gio.h>
+#include <stdexcept>
+#include <list>
+#include <Logger.h>
+
+#include <Commons/ThreadPool.h>
+#include <CommonsJavaScript/Converter.h>
+#include <json-glib/json-gvariant.h>
+
+namespace DeviceAPI
+{
+namespace Speech
+{
+
+using namespace WrtDeviceApis::Commons;
+
+SpeechMaster::SpeechMaster()
+{
+
+}
+
+static void signalCallback( GDBusConnection *connection,
+                               const gchar *sender_name,
+                               const gchar *object_path,
+                               const gchar *interface_name,
+                               const gchar *signal_name,
+                               GVariant *parameters,
+                               gpointer user_data)
+{
+       //TODO: add the other signal types
+       //If the signal name is Result
+       if (0 == g_strcmp0(signal_name, "Result"))
+       {
+               LoggerD("SpeechMaster::signalCallback called");
+               LoggerD("SpeechMaster::signalCallback signal name is " << signal_name);
+
+               SpeechMaster* master = static_cast<SpeechMaster*>(user_data);
+
+               LoggerD("signalCallback break 1");
+
+               if(!master)
+               {
+                       LoggerE("Failed to cast Speech object");
+                       return;
+               }
+
+               LoggerD("signalCallback break 2");
+
+               GVariantIter *resultIter;
+               std::vector<std::string> speechCommands;
+
+               if (parameters != NULL && signal_name != NULL)
+               {
+
+                       g_variant_get (parameters,
+                                                "(as)",
+                                                &resultIter);
+
+                       LoggerD("signalCallback break 3");
+
+                       GVariantIter *resultIter;
+                       gchar* result;
+                       std::string strResult;
+
+                       if (resultIter != NULL)
+                       {
+                               while (g_variant_iter_loop (resultIter, "s", &result))
+                               {
+                                       strResult.assign(result);
+                                       speechCommands.push_back(strResult);
+                                       LoggerD("signalCallback got speech command : " << result);
+                               }
+                       }
+                       else
+                               LoggerD("signalCallback resultIter is NULL! Possibly just a signal");
+
+                       LoggerD("signalCallback break 4");
+
+               }
+               else
+                       LoggerD("signalCallback parameters were NULL, signal only!");
+
+               LoggerD("signalCallback break 5");
+
+               master->onSignalReceived(RESULT, speechCommands);
+
+
+               if(resultIter != NULL)
+                        g_variant_iter_free(resultIter);
+       }
+}
+
+void SpeechMaster::onSignalReceived(SpeechEventType eventType, std::vector<std::string> speechCommands)
+{
+       LoggerD("SpeechMaster::onSignalReceived called");
+
+       switch(eventType)
+       {
+               case RESULT :
+                       listener->onresult(speechCommands);
+                       break;
+               default:
+                       break;
+       }
+}
+
+void SpeechMaster::setCBListener(JSObjectRef cbObject, JSContextRef context)
+{
+       LoggerD("SpeechMaster::setCBListener called");
+
+       if(cbObject == NULL)
+       {
+               LoggerE("Error SpeechMaster::setCBListener failed:  NULL object");
+
+               return;
+       }
+
+       listener = new SpeechListener(context, cbObject);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "AudioStart", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "SoundStart", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "SpeechStart", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "SpeechEnd", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "SoundEnd", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "AudioEnd", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "Result", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "NoMatch", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "Error", NULL, NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "Start", "/srs", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  "End", "/srs", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", "org.tizen.srs",
+                                                                                  NULL, "/srs", NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), "org.tizen.srs", NULL,
+                                                                                  NULL, NULL , NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+       g_dbus_connection_signal_subscribe(g_bus_get_sync(G_BUS_TYPE_SESSION, NULL,NULL), NULL, NULL,
+                                                                                  NULL, NULL , NULL, G_DBUS_SIGNAL_FLAGS_NONE,
+                                                                                  signalCallback, this, NULL);
+
+}
+
+
+}      //namespace DeviceAPI
+}      //namespace Speech
diff --git a/src/Speech/Speech.h b/src/Speech/Speech.h
new file mode 100644 (file)
index 0000000..c81607d
--- /dev/null
@@ -0,0 +1,61 @@
+//
+// Tizen Speech Web API
+// Copyright (c) 2013, Intel Corporation.
+//
+// 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 SPEECH_H
+#define SPEECH_H
+
+#include <list>
+#include <string>
+#include <dpl/mutex.h>
+#include <dpl/shared_ptr.h>
+#include <JavaScriptCore/JavaScript.h>
+#include <gio/gio.h>
+#include "SpeechListener.h"
+
+
+namespace DeviceAPI {
+namespace Speech {
+
+enum SpeechEventType
+{
+       RESULT
+};
+
+class SpeechMaster
+{
+
+public:
+
+        SpeechMaster();
+        void setCBListener(JSObjectRef cbObject, JSContextRef context);
+               void onSignalReceived(SpeechEventType eventType, std::vector<std::string> speechCommands);
+        void start();
+               void stop();
+               void abort();
+
+               private:
+               SpeechListener *listener;
+};
+
+
+typedef DPL::SharedPtr<SpeechMaster> SpeechPtr;
+
+}      //namespace DeviceAPI
+}      //namespace Speech
+
+#endif // SPEECH_H
+
diff --git a/src/Speech/Speech.idl b/src/Speech/Speech.idl
new file mode 100644 (file)
index 0000000..36adb74
--- /dev/null
@@ -0,0 +1,90 @@
+   [Constructor]
+    interface SpeechRecognition : EventTarget {
+        // recognition parameters
+        attribute SpeechGrammarList grammars;
+        attribute DOMString lang;
+        attribute boolean continuous;
+        attribute boolean interimResults;
+        attribute unsigned long maxAlternatives;
+        attribute DOMString serviceURI;
+
+        // methods to drive the speech interaction
+        void start();
+        void stop();
+        void abort();
+
+        // event methods
+        attribute EventHandler onaudiostart;
+        attribute EventHandler onsoundstart;
+        attribute EventHandler onspeechstart;
+        attribute EventHandler onspeechend;
+        attribute EventHandler onsoundend;
+        attribute EventHandler onaudioend;
+        attribute EventHandler onresult;
+        attribute EventHandler onnomatch;
+        attribute EventHandler onerror;
+        attribute EventHandler onstart;
+        attribute EventHandler onend;
+    };
+
+    interface SpeechRecognitionError : Event {
+        enum ErrorCode {
+          "no-speech",
+          "aborted",
+          "audio-capture",
+          "network",
+          "not-allowed",
+          "service-not-allowed",
+          "bad-grammar",
+          "language-not-supported"
+        };
+
+        readonly attribute ErrorCode error;
+        readonly attribute DOMString message;
+    };
+
+    // Item in N-best list
+    interface SpeechRecognitionAlternative {
+        readonly attribute DOMString transcript;
+        readonly attribute float confidence;
+    };
+
+    // A complete one-shot simple response
+    interface SpeechRecognitionResult {
+        readonly attribute unsigned long length;
+        getter SpeechRecognitionAlternative item(in unsigned long index);
+        readonly attribute boolean final;
+    };
+
+    // A collection of responses (used in continuous mode)
+    interface SpeechRecognitionResultList {
+        readonly attribute unsigned long length;
+        getter SpeechRecognitionResult item(in unsigned long index);
+    };
+
+    // A full response, which could be interim or final, part of a continuous response or not
+    interface SpeechRecognitionEvent : Event {
+        readonly attribute unsigned long resultIndex;
+        readonly attribute SpeechRecognitionResultList results;
+        readonly attribute any interpretation;
+        readonly attribute Document emma;
+    };
+
+    // The object representing a speech grammar
+    [Constructor]
+    interface SpeechGrammar {
+        attribute DOMString src;
+        attribute float weight;
+    };
+
+    // The object representing a speech grammar collection
+    [Constructor]
+    interface SpeechGrammarList {
+        readonly attribute unsigned long length;
+        getter SpeechGrammar item(in unsigned long index);
+        void addFromURI(in DOMString src,
+                        optional float weight);
+        void addFromString(in DOMString string,
+                        optional float weight);
+    };
+
diff --git a/src/Speech/SpeechListener.cpp b/src/Speech/SpeechListener.cpp
new file mode 100644 (file)
index 0000000..690fbee
--- /dev/null
@@ -0,0 +1,183 @@
+//
+// Tizen Speech Web API
+// Copyright (c) 2013, Intel Corporation.
+//
+// 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 "SpeechListener.h"
+
+using namespace DeviceAPI::Common;
+using namespace WrtDeviceApis::Commons;
+using namespace WrtDeviceApis::CommonsJavaScript;
+
+
+namespace DeviceAPI {
+namespace Speech {
+
+SpeechListener::SpeechListener(JSContextRef globalCtx, JSObjectRef cbObject)
+{
+       m_callback = new MultiCallbackUserData(globalCtx);
+
+    JSValueRef onaudiostart = JSUtil::getProperty(globalCtx , cbObject, "onaudiostart");
+
+    if (!JSValueIsUndefined(globalCtx,onaudiostart))
+    {
+        m_callback->setCallback("onaudiostart", JSUtil::JSValueToObject(globalCtx, onaudiostart));
+    }
+
+    JSValueRef onsoundstart = JSUtil::getProperty(globalCtx , cbObject, "onsoundstart");
+
+    if (!JSValueIsUndefined(globalCtx,onsoundstart))
+    {
+        m_callback->setCallback("onsoundstart", JSUtil::JSValueToObject(globalCtx, onsoundstart));
+    }
+
+    JSValueRef onspeechstart = JSUtil::getProperty(globalCtx , cbObject, "onspeechstart");
+
+    if (!JSValueIsUndefined(globalCtx,onspeechstart))
+    {
+        m_callback->setCallback("onspeechstart", JSUtil::JSValueToObject(globalCtx, onspeechstart));
+    }
+
+    JSValueRef onspeechend = JSUtil::getProperty(globalCtx , cbObject, "onspeechend");
+
+    if (!JSValueIsUndefined(globalCtx,onspeechend))
+    {
+        m_callback->setCallback("onspeechend", JSUtil::JSValueToObject(globalCtx, onspeechend));
+    }
+
+    JSValueRef onsoundend = JSUtil::getProperty(globalCtx , cbObject, "onsoundend");
+
+    if (!JSValueIsUndefined(globalCtx,onsoundend))
+    {
+        m_callback->setCallback("onsoundend", JSUtil::JSValueToObject(globalCtx, onsoundend));
+    }
+
+    JSValueRef onaudioend = JSUtil::getProperty(globalCtx , cbObject, "onaudioend");
+
+    if (!JSValueIsUndefined(globalCtx,onaudioend))
+    {
+        m_callback->setCallback("onaudioend", JSUtil::JSValueToObject(globalCtx, onaudioend));
+    }
+
+    JSValueRef onresult = JSUtil::getProperty(globalCtx , cbObject, "onresult");
+
+    if (!JSValueIsUndefined(globalCtx,onresult))
+    {
+        m_callback->setCallback("onresult", JSUtil::JSValueToObject(globalCtx, onresult));
+    }
+
+    JSValueRef onnomatch = JSUtil::getProperty(globalCtx , cbObject, "onnomatch");
+
+    if (!JSValueIsUndefined(globalCtx,onnomatch))
+    {
+        m_callback->setCallback("onnomatch", JSUtil::JSValueToObject(globalCtx, onnomatch));
+    }
+
+    JSValueRef onerror = JSUtil::getProperty(globalCtx , cbObject, "onerror");
+
+    if (!JSValueIsUndefined(globalCtx,onerror))
+    {
+        m_callback->setCallback("onerror", JSUtil::JSValueToObject(globalCtx, onerror));
+    }
+
+       JSValueRef onstart = JSUtil::getProperty(globalCtx , cbObject, "onstart");
+
+    if (!JSValueIsUndefined(globalCtx,onstart))
+    {
+        m_callback->setCallback("onstart", JSUtil::JSValueToObject(globalCtx, onstart));
+    }
+
+    JSValueRef onend = JSUtil::getProperty(globalCtx , cbObject, "onend");
+
+    if (!JSValueIsUndefined(globalCtx,onend))
+    {
+        m_callback->setCallback("onend", JSUtil::JSValueToObject(globalCtx, onend));
+    }
+
+}
+
+SpeechListener::~SpeechListener()
+{
+       if (m_callback != NULL)
+       {
+               delete m_callback;
+               m_callback = NULL;
+       }
+}
+
+void SpeechListener::onaudiostart()
+{
+       m_callback->invokeCallback("onaudiostart");
+}
+
+void SpeechListener::onsoundstart()
+{
+       m_callback->invokeCallback("onsoundstart");
+}
+
+void SpeechListener::onspeechstart()
+{
+       m_callback->invokeCallback("onspeechstart");
+}
+
+void SpeechListener::onspeechend()
+{
+       m_callback->invokeCallback("onspeechend");
+}
+
+void SpeechListener::onsoundend()
+{
+       m_callback->invokeCallback("onsoundend");
+}
+
+void SpeechListener::onaudioend()
+{
+       m_callback->invokeCallback("onaudioend");
+}
+
+void SpeechListener::onresult(std::vector<std::string> speechCommands)
+{
+       LoggerD("SpeechListener::onresult called, we have -  " << speechCommands[0]);
+
+       JSContextRef context = m_callback->getContext();
+       Converter converter(context);
+       JSValueRef result = converter.toJSValueRef(speechCommands);
+
+       m_callback->invokeCallback("onresult", result);
+}
+
+void SpeechListener::onnomatch(std::string event)
+{
+
+}
+
+void SpeechListener::onerror(std::string error)
+{
+
+}
+
+void SpeechListener::onstart()
+{
+       m_callback->invokeCallback("onstart");
+}
+
+void SpeechListener::onend()
+{
+       m_callback->invokeCallback("onend");
+}
+
+} // DeviceAPI
+} // Speech
diff --git a/src/Speech/SpeechListener.h b/src/Speech/SpeechListener.h
new file mode 100644 (file)
index 0000000..d521901
--- /dev/null
@@ -0,0 +1,69 @@
+//
+// Tizen Speech Web API
+// Copyright (c) 2013, Intel Corporation.
+//
+// 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 SPEECH_LISTENER_H
+#define SPEECH_LISTENER_H
+
+#include <JavaScriptCore/JavaScript.h>
+#include <MultiCallbackUserData.h>
+#include <gio/gio.h>
+#include <stdexcept>
+#include <Logger.h>
+#include <CommonsJavaScript/JSUtils.h>
+#include <JSUtil.h>
+#include <CommonsJavaScript/Converter.h>
+
+
+using namespace DeviceAPI::Common;
+
+namespace DeviceAPI {
+namespace Speech {
+
+enum SpeechRecognitionError
+{
+       UNKNONWN_SPEECH_ERROR
+};
+
+class SpeechListener {
+public:
+       SpeechListener(JSContextRef globalCtx, JSObjectRef object);
+       virtual ~SpeechListener();
+
+       void onaudiostart();
+       void onsoundstart();
+       void onspeechstart();
+       void onspeechend();
+       void onsoundend();
+       void onaudioend();
+       //void onresult(SpeechRecognitionEvent event);
+       //void onnomatch(SpeechRecognitionEvent event);
+       //void onerror(SpeechRecognitionError error);
+       void onresult(std::vector<std::string> speechCommands);
+       void onnomatch(std::string event);
+       void onerror(std::string error);
+       void onstart();
+       void onend();
+
+private:
+       MultiCallbackUserData *m_callback;
+};
+
+}
+}
+
+
+#endif // SPEECH_LISTENER_H
diff --git a/src/Speech/config.xml b/src/Speech/config.xml
new file mode 100644 (file)
index 0000000..8b40d6e
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" ?>
+<!DOCTYPE plugin-properties SYSTEM "/usr/etc/tizen-apis/config.dtd">
+<plugin-properties>
+    <library-name>libwrt-plugins-tizen-speech.so</library-name>
+    <feature-install-uri>speech.install.uri</feature-install-uri>
+    <feature-key-cn>INTEL plugin group</feature-key-cn>
+    <feature-root-cn>INTEL certificate authority</feature-root-cn>
+    <feature-root-fingerprint>AAAABBBBCCCCDDDEEEE0000</feature-root-fingerprint>
+
+    <api-feature>
+        <name>http://tizen.org/privilege/speech</name>
+        <device-capability>speech</device-capability>
+    </api-feature>
+
+
+</plugin-properties>
diff --git a/src/Speech/plugin_initializer.cpp b/src/Speech/plugin_initializer.cpp
new file mode 100644 (file)
index 0000000..a21598a
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// Tizen Speech Web API
+// Copyright (c) 2013, Intel Corporation.
+//
+// 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 <Commons/plugin_initializer_def.h>
+#include <Commons/WrtAccess/WrtAccess.h>
+#include "JSSpeech.h"
+#include <Logger.h>
+
+namespace DeviceAPI {
+namespace Speech {
+
+using namespace WrtDeviceApis;
+using namespace WrtDeviceApis::Commons;
+
+class_definition_options_t ConstructorClassOptions =
+{
+       JS_INTERFACE,
+       CREATE_INSTANCE,
+       NONE_NOTICE,
+       USE_OVERLAYED, //ignored
+       NULL,
+       NULL,
+       NULL
+};
+
+void on_widget_start_callback(int widgetId) {
+       LoggerD("[TIZEN\\Speech] on_widget_start_callback ("<<widgetId<<")");
+       Try
+       {
+               WrtAccessSingleton::Instance().initialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LoggerE("WrtAccess initialization failed");
+       }
+}
+
+void on_widget_stop_callback(int widgetId) {
+       LoggerD("[TIZEN\\Speech] on_widget_stop_callback ("<<widgetId<<")");
+       Try
+       {
+               WrtAccessSingleton::Instance().deinitialize(widgetId);
+       }
+       Catch(Commons::Exception)
+       {
+               LoggerE("WrtAccess deinitialization failed");
+       }
+}
+
+PLUGIN_ON_WIDGET_START(on_widget_start_callback)
+PLUGIN_ON_WIDGET_STOP(on_widget_stop_callback)
+
+PLUGIN_CLASS_MAP_BEGIN
+PLUGIN_CLASS_MAP_ADD_CLASS(WRT_JS_EXTENSION_OBJECT_TIZEN,
+               "speech",
+               (js_class_template_getter)JSSpeech::getClassRef,
+               NULL)
+
+PLUGIN_CLASS_MAP_END
+
+} // Time
+} // DeviceAPI