upload tizen1.0 source
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Bluetooth / JSBluetoothDevice.cpp
index ac0de97..a54f08d 100644 (file)
@@ -165,7 +165,7 @@ JSValueRef JSBluetoothDevice::getName(JSContextRef context,
        {
                if (priv == NULL)
                {
-                       Throw(UnknownException);
+                       Throw(ConversionException);
                }
 
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
@@ -184,7 +184,7 @@ JSValueRef JSBluetoothDevice::getName(JSContextRef context,
        {
                LogError("InvalidArgumentException");
                return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
        }
        Catch(WrtDeviceApis::Commons::UnsupportedException)
        {
@@ -215,7 +215,7 @@ JSValueRef JSBluetoothDevice::getAddress(JSContextRef context,
        {
                if (priv == NULL)
                {
-                       Throw(UnknownException);
+                       Throw(ConversionException);
                }
 
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
@@ -235,7 +235,7 @@ JSValueRef JSBluetoothDevice::getAddress(JSContextRef context,
        {
                LogError("InvalidArgumentException");
                return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
        }
        Catch(WrtDeviceApis::Commons::UnsupportedException)
        {
@@ -264,7 +264,7 @@ JSValueRef JSBluetoothDevice::getDeviceClass(JSContextRef context,
        {
                if (priv == NULL)
                {
-                       Throw(UnknownException);
+                       Throw(ConversionException);
                }
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
                BluetoothDeviceDataClass devClass = BluetoothDeviceManager->getClass();
@@ -285,7 +285,7 @@ JSValueRef JSBluetoothDevice::getDeviceClass(JSContextRef context,
        {
                LogError("InvalidArgumentException");
                return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
        }
        Catch(WrtDeviceApis::Commons::UnsupportedException)
        {
@@ -316,7 +316,7 @@ JSValueRef JSBluetoothDevice::getBondProperty(JSContextRef context,
        {
                if (priv == NULL)
                {
-                       Throw(UnknownException);
+                       Throw(ConversionException);
                }
 
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
@@ -337,7 +337,7 @@ JSValueRef JSBluetoothDevice::getBondProperty(JSContextRef context,
        {
                LogError("InvalidArgumentException");
                return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
        }
        Catch(WrtDeviceApis::Commons::UnsupportedException)
        {
@@ -367,7 +367,7 @@ JSValueRef JSBluetoothDevice::getTrustProperty(JSContextRef context,
        {
                if (priv == NULL)
                {
-                       Throw(UnknownException);
+                       Throw(ConversionException);
                }
 
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
@@ -387,7 +387,7 @@ JSValueRef JSBluetoothDevice::getTrustProperty(JSContextRef context,
        {
                LogError("InvalidArgumentException");
                return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
        }
        Catch(WrtDeviceApis::Commons::UnsupportedException)
        {
@@ -417,7 +417,7 @@ JSValueRef JSBluetoothDevice::getConnectProperty(JSContextRef context,
        {
                if (priv == NULL)
                {
-                       Throw(UnknownException);
+                       Throw(ConversionException);
                }
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
                bool isConnected = BluetoothDeviceManager->getConnectProperty();
@@ -436,7 +436,7 @@ JSValueRef JSBluetoothDevice::getConnectProperty(JSContextRef context,
        {
                LogError("InvalidArgumentException");
                return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
        }
        Catch(WrtDeviceApis::Commons::UnsupportedException)
        {
@@ -468,7 +468,7 @@ JSValueRef JSBluetoothDevice::getUuids(JSContextRef context,
        {
                if (priv == NULL)
                {
-                       Throw(UnknownException);
+                       Throw(ConversionException);
                }
                
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
@@ -504,7 +504,7 @@ JSValueRef JSBluetoothDevice::getUuids(JSContextRef context,
        {
                LogError("InvalidArgumentException");
                return JSTizenExceptionFactory::postException(context, exception,
-                               JSTizenException::TYPE_MISMATCH_ERROR, "invalid value error");
+                               JSTizenException::INVALID_VALUES_ERROR, "invalid value error");
        }
        Catch(WrtDeviceApis::Commons::UnsupportedException)
        {
@@ -534,48 +534,39 @@ JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, JSObj
        JSBluetoothDevicePriv *priv = static_cast<JSBluetoothDevicePriv*>(JSObjectGetPrivate(thisObject));
        JSValueRef successCallback = NULL;
        JSValueRef errorCallBack = NULL;
-
+       size_t index = 0;
+       JSValueRef reserveArguments[4];
+       JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
 
        Try     {
 
+               for (index = 0; index < 4; index++)
+               {
+                       if (index < argumentCount)
+                               reserveArguments[index] = arguments[index];
+                       else 
+                               reserveArguments[index] = JSValueMakeNull(context);
+                       
+               }
 
                if (priv == NULL)
                {
                        LogError("priv null");
-                       Throw(UnknownException);        
+                       Throw(ConversionException);     
                }
 
                LogDebug(bluetoothExportedNames[BLUETOOTH_FUNCTION_API_DEVICE_CONNECT_TO_SERVICE]);
 
                AceSecurityStatus status = BLUETOOTH_CHECK_ACCESS(
-                       priv->getContext(),
                        bluetoothExportedNames[BLUETOOTH_FUNCTION_API_DEVICE_CONNECT_TO_SERVICE]);
 
                TIZEN_SYNC_ACCESS_HANDLER(status, context, exception);
 
-               if (argumentCount < 2 || argumentCount > 4)
-               {
-                       LogError("InvalidArgumentException");
-                       return JSTizenExceptionFactory::postException(context, 
-                               exception, JSTizenException::INVALID_VALUES_ERROR, "invalid parameter error");
-
-               }
-               if (JSValueIsNull(context, arguments[0]) == true || JSValueIsString(context, arguments[0]) == false)
-               {
-                       LogError("hasInstance TypeMismatchException");
-                       return JSTizenExceptionFactory::postException(context, 
-                               exception, JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-               }
                
                BluetoothConverter converter(context);
-               successCallback = converter.toFunction(arguments[1]);
+               successCallback = converter.toFunction(reserveArguments[1]);
+               errorCallBack = converter.toFunctionOrNull(reserveArguments[2]);
                
-               if (argumentCount >= 3)
-               {
-                       errorCallBack = converter.toFunctionOrNull(arguments[2]);
-               }
-               
-               JSCallbackManagerPtr cbm = JSCallbackManager::createObject(priv->getContext(), NULL, NULL);
 
                if (cbm == NULL)
                {
@@ -587,39 +578,12 @@ JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, JSObj
                IBluetoothDeviceManagerPtr BluetoothDeviceManager(priv->getObject());
                EventBTConnectToServiceByUUIDPtr event(new EventBTConnectToServiceByUUID);
                BluetoothSocketData socketData;
-               socketData.uuid = converter.toString(arguments[0]);
+               socketData.uuid = converter.toBluetoothUUIDString(reserveArguments[0]);
                socketData.protocol  = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
 
                if (argumentCount >= 4)
                {
-                       if (JSValueIsNull(context, arguments[3]) == true)
-                       {
-                               socketData.protocol  = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-                       }
-                       else 
-                       {
-                               if (JSValueIsString(context, arguments[3]) == false)
-                               {
-                                       
-                                       LogError("InvalidArgumentException");
-                                       return JSTizenExceptionFactory::postException(context, 
-                                               exception, JSTizenException::TYPE_MISMATCH_ERROR, "type mismatch error");
-                               }
-
-                               std::string protocol = converter.toString(arguments[3]);
-                               LogDebug(protocol.c_str());
-
-                               if (strcmp(protocol.c_str(), PROTOCOL_TYPE_RFCOMM_VALUE) == 0)
-                               {
-                                       socketData.protocol  = PROTOCOL_TYPE_RFCOMM_VALUE_INT;
-                               }
-                               else                    
-                               {
-                                       LogError("BluetoothDeviceManager or event or listener NULL");
-                                       Throw(WrtDeviceApis::Commons::UnsupportedException);    
-                               }
-
-                       }
+                       socketData.protocol = converter.toBluetoothProtocolInt(reserveArguments[3]);
                }
                
                if (BluetoothDeviceManager == NULL || event == NULL)
@@ -633,8 +597,6 @@ JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, JSObj
                event->setForAsynchronousCall(&BluetoothDeviceManagerListener::getInstance());
                event->setSocketData(socketData);
                BluetoothDeviceManager->connectToServiceByUUID(event);
-
-               return JSValueMakeNull(context);
        }
        Catch (WrtDeviceApis::Commons::ConversionException)
        {
@@ -664,8 +626,6 @@ JSValueRef JSBluetoothDevice::connectToServiceByUUID(JSContextRef context, JSObj
 
        return JSValueMakeUndefined(context);
 }
-
-
 }
 }