update for beta universally
[profile/ivi/wrt-plugins-tizen.git] / src / standards / Tizen / Account / JSAccountServiceType.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 /*
19  * JSServiceType.cpp
20  *
21  *  Created on: 2012. 1. 30.
22  *      Author: sangtai
23  */
24
25 #include "JSAccountServiceType.h"
26
27 #include <CommonsJavaScript/Converter.h>
28 #include "AccountConverter.h"
29
30 using namespace TizenApis::Api::Account;
31 using namespace WrtDeviceApis::Commons;
32 using namespace WrtDeviceApis::CommonsJavaScript;
33 //using namespace TizenApis::Commons;
34
35 namespace TizenApis {
36         namespace Tizen1_0 {
37                 namespace Account {
38
39                         namespace {
40                                 #define ACCOUNT_SERVICE_TYPE               "AccountServiceType"
41                                 #define ACCOUNT_SERVICE_TYPE_ID            "id"
42                                 #define ACCOUNT_SERVICE_TYPE_DISPLAY_NAME  "displayName"
43                                 #define ACCOUNT_SERVICE_TYPE_ICON_PATH     "icon"
44                                 #define ACCOUNT_SERVICE_TYPE_TAGS          "tags"
45                         }
46
47                         JSClassDefinition JSAccountServiceType::m_classInfo = {
48                                 0,
49                                 kJSClassAttributeNone,
50                                 ACCOUNT_SERVICE_TYPE,
51                                 0,
52                                 m_property,
53                                 NULL, //m_function,
54                                 initialize,
55                                 finalize,
56                                 NULL, //hasProperty,
57                                 NULL, //getProperty,
58                                 NULL, //setProperty,
59                                 NULL, //deleteProperty,
60                                 NULL, //getPropertyNames,
61                                 NULL, //callAsFunction,
62                                 NULL, //callAsConstructor,
63                                 NULL, //hasInstance,
64                                 NULL, //convertToType,
65                         };
66
67                         JSStaticValue JSAccountServiceType::m_property[] = {
68                                 { ACCOUNT_SERVICE_TYPE_ID,           getProperty, NULL, kJSPropertyAttributeNone },
69                                 { ACCOUNT_SERVICE_TYPE_DISPLAY_NAME, getProperty, NULL, kJSPropertyAttributeNone },
70                                 { ACCOUNT_SERVICE_TYPE_ICON_PATH,    getProperty, NULL, kJSPropertyAttributeNone },
71                                 { ACCOUNT_SERVICE_TYPE_TAGS,         getProperty, NULL, kJSPropertyAttributeNone },
72                                 { 0, 0, 0, 0 }
73                         };
74
75
76                         JSClassRef JSAccountServiceType::m_jsClassRef = JSClassCreate(
77                                         JSAccountServiceType::getClassInfo());
78
79                         const JSClassDefinition* JSAccountServiceType::getClassInfo(){
80                                 return &(m_classInfo);
81                         }
82
83                         JSClassRef JSAccountServiceType::getClassRef()                  {
84                                 if (!m_jsClassRef) {
85                                         m_jsClassRef = JSClassCreate(&m_classInfo);
86                                 }
87                                 return m_jsClassRef;
88                         }
89
90                         JSObjectRef JSAccountServiceType::createJSObject(JSContextRef context, AccountServiceTypePropertyPtr account){
91                                 LogDebug("<<<");
92
93                                 AccountServiceTypePrivateObject *priv = new AccountServiceTypePrivateObject(context, account);
94
95                                 JSObjectRef jsValueRef = JSObjectMake(context, getClassRef(), static_cast<void*>(priv));
96                                 LogDebug(">>>");
97                                 return jsValueRef;
98                         }
99
100                         void JSAccountServiceType::initialize(JSContextRef context, JSObjectRef object) {
101                                 LogDebug("<<< ");
102                                 AccountServiceTypePrivateObject *privateObject = static_cast<AccountServiceTypePrivateObject*>(JSObjectGetPrivate(object));
103                                 if (NULL == privateObject) {
104                                         LogDebug("privateObject is NULL");
105                                 }
106                         }
107
108                         void JSAccountServiceType::finalize(JSObjectRef object) {
109                                 LogDebug("<<<");
110                                 AccountServiceTypePrivateObject* priv = static_cast<AccountServiceTypePrivateObject*>(JSObjectGetPrivate(object));
111                                 delete priv;
112                                 JSObjectSetPrivate(object, NULL);
113                         }
114
115                         JSValueRef JSAccountServiceType::getProperty(JSContextRef context,
116                                         JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) {
117                                 LogDebug("<<<");
118                                 AccountConverterFactory::ConverterType converter = AccountConverterFactory::getConverter(context);
119                                 Try{
120                                         AccountServiceTypePrivateObject* priv = static_cast<AccountServiceTypePrivateObject*>(JSObjectGetPrivate(object));
121                                         if (!priv) {
122                                                 Throw(NullPointerException);
123                                         }
124                                         AccountServiceTypePropertyPtr accountServiceTypeProperty = priv->getObject();
125
126                                         if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_ID)) {
127                                                 return converter->toJSValueRef(accountServiceTypeProperty->getId());
128                                         } else if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_DISPLAY_NAME)) {
129                                                 return converter->toJSValueRef(accountServiceTypeProperty->getDisplayName());
130                                         } else if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_ICON_PATH)) {
131                                                 return converter->toJSValueRef(accountServiceTypeProperty->getIconPath());
132                                         } else if (JSStringIsEqualToUTF8CString(propertyName, ACCOUNT_SERVICE_TYPE_TAGS)) {
133                                                         return converter->toJSValueRef(accountServiceTypeProperty->getTags());
134                                         }
135                                 }       Catch(Exception){
136                                         LogError("invalid property");
137                                 }
138
139                                 return JSValueMakeUndefined(context);
140                         }
141
142 JSAccountServiceType::~JSAccountServiceType() {
143         // TODO Auto-generated destructor stub
144 }
145
146                 } //namespace Account
147         } //namespace Tizen1_0
148 } //namespace TizenApis