tizen 2.3.1 release
[framework/web/wearable/wrt-plugins-tizen.git] / src / Bluetooth / JSBluetoothProfileHandler.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <SecurityExceptions.h>
19
20 #include <JSUtil.h>
21 #include <ArgumentValidator.h>
22 #include <GlobalContextManager.h>
23 #include <PlatformException.h>
24
25 #include "plugin_config.h"
26 #include "JSBluetoothProfileHandler.h"
27 #include "JSBluetoothHealthProfileHandler.h"
28
29 #include <TimeTracer.h>
30 #include <Logger.h>
31
32 using namespace WrtDeviceApis::Commons;
33 using namespace DeviceAPI::Common;
34
35 namespace DeviceAPI {
36 namespace Bluetooth {
37
38 JSClassDefinition JSBluetoothProfileHandler::m_classInfo = {
39     0,
40     kJSClassAttributeNone,
41     "BluetoothProfileHandler",
42     NULL, //ParentClass
43     m_property, //StaticValues
44     NULL, //StaticFunctions
45     initialize, //Initialize
46     finalize, //Finalize
47     NULL, //HasProperty,
48     NULL, //GetProperty,
49     NULL, //SetProperty,
50     NULL, //DeleteProperty,
51     NULL, //GetPropertyNames,
52     NULL, //CallAsFunction,
53     NULL, //CallAsConstructor,
54     NULL, //HasInstance,
55     NULL //ConvertToType
56 };
57
58 JSStaticValue JSBluetoothProfileHandler::m_property[] = {
59     {
60         BLUETOOTH_PROFILE_TYPE,
61         getProperty,
62         NULL,
63         kJSPropertyAttributeNone |
64         kJSPropertyAttributeReadOnly |
65         kJSPropertyAttributeDontDelete
66     },
67     { 0, 0, 0, 0 }
68 };
69
70 JSClassRef JSBluetoothProfileHandler::m_jsClassRef =
71     JSClassCreate(JSBluetoothProfileHandler::getClassInfo());
72
73 const JSClassRef JSBluetoothProfileHandler::getClassRef()
74 {
75     if (!m_jsClassRef) {
76         m_jsClassRef = JSClassCreate(&m_classInfo);
77     }
78     return m_jsClassRef;
79 }
80
81 const JSClassDefinition* JSBluetoothProfileHandler::getClassInfo()
82 {
83     return &m_classInfo;
84 }
85
86 void JSBluetoothProfileHandler::initialize(JSContextRef context,
87     JSObjectRef object)
88 {
89     // Do nothing
90 }
91
92 void JSBluetoothProfileHandler::finalize(JSObjectRef object)
93 {
94     // Do nothing
95 }
96
97 JSValueRef JSBluetoothProfileHandler::getProperty(JSContextRef context,
98     JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {
99     LOGD("Enter");
100
101     try {
102         if (JSStringIsEqualToUTF8CString(propertyName, BLUETOOTH_PROFILE_TYPE)) {
103             if(object) {
104                 if(JSValueIsObjectOfClass(context, object,
105                     JSBluetoothHealthProfileHandler::getClassRef())) {
106
107                     std::string profileType("HEALTH");
108                     LOGD("profileType: %s", profileType.c_str());
109                     return JSUtil::toJSValueRef(context, profileType);
110                 }
111             }
112             else {
113                 LOGE("object is NULL");
114             }
115         }
116     } catch (const BasePlatformException &err) {
117         LOGW("Getting property is failed %s", err.getMessage().c_str());
118     }
119
120     return NULL;
121 }
122
123
124
125 } // Bluetooth
126 } // DeviceAPI