Remove hardcoded path for multiuser support
[platform/framework/web/wrt-plugins-tizen.git] / src / Content / ContentListener.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 <pthread.h>
19 #include <CommonsJavaScript/JSUtils.h>
20 #include <CommonsJavaScript/Validator.h>
21 #include <JSWebAPIErrorFactory.h>
22 #include <JSUtil.h>
23 #include "ContentListener.h"
24 #include "ContentConverter.h"
25 #include <Logger.h>
26
27 using namespace DeviceAPI::Common;
28 using namespace WrtDeviceApis::Commons;
29 using namespace WrtDeviceApis::CommonsJavaScript;
30
31
32 namespace DeviceAPI {
33 namespace Content {
34
35 ContentListener::ContentListener(JSContextRef globalCtx, JSObjectRef object)
36 {
37         m_callback = new MultiCallbackUserData(globalCtx);
38
39     // onstarted
40     JSValueRef oncontentadded = JSUtil::getProperty(globalCtx , object, "oncontentadded");
41     if(!JSValueIsUndefined(globalCtx,oncontentadded)) {
42         m_callback->setCallback("oncontentadded", JSUtil::JSValueToObject(globalCtx, oncontentadded));
43     }
44     JSValueRef oncontentupdated = JSUtil::getProperty(globalCtx , object, "oncontentupdated");
45     if(!JSValueIsUndefined(globalCtx,oncontentupdated)) {
46         m_callback->setCallback("oncontentupdated", JSUtil::JSValueToObject(globalCtx, oncontentupdated));
47     }
48     JSValueRef oncontentremoved = JSUtil::getProperty(globalCtx , object, "oncontentremoved");
49     if(!JSValueIsUndefined(globalCtx,oncontentremoved)) {
50         m_callback->setCallback("oncontentremoved", JSUtil::JSValueToObject(globalCtx, oncontentremoved));
51     }
52
53 }
54
55 ContentListener::~ContentListener() {
56         if(m_callback != NULL){
57                 delete m_callback;
58                 m_callback = NULL;
59         }
60 }
61
62 void ContentListener::oncontentadded(MediacontentMediaPtr content)
63 {
64         JSContextRef context = m_callback->getContext();
65
66         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
67         JSValueRef result = converter->toJSValueRefMedia(content);
68         m_callback->invokeCallback("oncontentadded", result);
69 }
70
71 void ContentListener::oncontentupdated(MediacontentMediaPtr content)
72 {
73         JSContextRef context = m_callback->getContext();
74
75         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
76         JSValueRef result = converter->toJSValueRefMedia(content);
77         m_callback->invokeCallback("oncontentupdated", result);
78
79 }
80
81 void ContentListener::oncontentremoved(std::string id)
82 {
83         JSContextRef context = m_callback->getContext();
84
85         MediaConverterFactory::ConverterType converter = MediaConverterFactory::getConverter(context);
86         m_callback->invokeCallback("oncontentremoved", converter->toJSValueRef(id));
87 }
88
89
90 } // Download
91 } // DeviceAPI