diff options
Diffstat (limited to 'src/standards/Tizen/Call/JSCallApi.cpp')
-rwxr-xr-x | src/standards/Tizen/Call/JSCallApi.cpp | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/standards/Tizen/Call/JSCallApi.cpp b/src/standards/Tizen/Call/JSCallApi.cpp new file mode 100755 index 0000000..fe11429 --- /dev/null +++ b/src/standards/Tizen/Call/JSCallApi.cpp @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 <dpl/log.h> +#include <dpl/shared_ptr.h> + +#include <CommonsJavaScript/Validator.h> +#include <CommonsJavaScript/JSUtils.h> +#include <CommonsJavaScript/JSCallbackManager.h> +#include <CommonsJavaScript/Utils.h> +#include <CommonsJavaScript/JSDOMExceptionFactory.h> + +#include "JSCallApi.h" +#include "JSCallHistory.h" +#include "Converter.h" + +using namespace std; +using namespace DPL; +using namespace WrtDeviceApis; +using namespace WrtDeviceApis::Commons; +using namespace WrtDeviceApis::CommonsJavaScript; + +namespace TizenApis { +namespace Tizen1_0 { + +JSClassRef JSCallApi::m_jsClassRef = NULL; + +JSClassDefinition JSCallApi::m_classInfo = +{ + 0, + kJSClassAttributeNone, + "call", + NULL, + m_property, + NULL, + initialize, + finalize, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + hasInstance, + NULL +}; + +JSStaticValue JSCallApi::m_property[] = { + { "history", getProperty, NULL, kJSPropertyAttributeReadOnly }, + { 0, 0, 0, 0 } +}; + +const JSClassRef JSCallApi::getClassRef() { + if (!m_jsClassRef) { + m_jsClassRef = JSClassCreate(&m_classInfo); + } + return m_jsClassRef; +} + +const JSClassDefinition* JSCallApi::getClassInfo(){ + return &m_classInfo; +} + +void JSCallApi::initialize(JSContextRef context, JSObjectRef object) { + JSCallApiPriv *priv = static_cast<JSCallApiPriv*>(JSObjectGetPrivate(object)); + + if (priv == NULL) { + priv = new JSCallApiPriv(context); + + if(!JSObjectSetPrivate(object, static_cast<void*>(priv))) { + LogError("Object can't store private data."); + delete priv; + } + } +} + +void JSCallApi::finalize(JSObjectRef object) { + JSCallApiPriv* priv = static_cast<JSCallApiPriv*>(JSObjectGetPrivate(object)); + + if (priv != NULL) { + JSObjectSetPrivate(object, NULL); + delete priv; + } +} + +JSValueRef JSCallApi::getProperty(JSContextRef context, + JSObjectRef object, + JSStringRef propertyName, + JSValueRef* exception) +{ + JSCallApiPriv *priv = static_cast<JSCallApiPriv*>(JSObjectGetPrivate(object)); + if (!priv) { + return JSValueMakeUndefined(context); + } + + JSContextRef globalContext = priv->getContext(); + + try { + Converter convert(context); + if(JSStringIsEqualToUTF8CString(propertyName, "history")) { + return TizenApis::Tizen1_0::JSCallHistory::createJSObject(globalContext, object); + } + } catch(Commons::Exception) { + LogWarning("trying to get incorrect value"); + } + return JSValueMakeUndefined(context); +} + +bool JSCallApi::hasInstance(JSContextRef context, JSObjectRef constructor, + JSValueRef possibleInstance, JSValueRef* exception) { + return JSValueIsObjectOfClass(context, possibleInstance, getClassRef()); +} + +} +} + |