2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __TIZEN_CONTENT_FIND_CALLBACK_H__
19 #define __TIZEN_CONTENT_FIND_CALLBACK_H__
24 #include <AbstractFilter.h>
27 #include <JavaScriptCore/JavaScript.h>
29 #include <JSWebAPIErrorFactory.h>
30 #include "JSContent.h"
31 #include "JSImageContent.h"
32 #include "JSVideoContent.h"
33 #include "JSAudioContent.h"
38 #include "ContentCallback.h"
42 using namespace DeviceAPI::Common;
43 using namespace DeviceAPI::Tizen;
48 class ContentFindCallback : public ContentCallback
51 ContentFindCallback(JSContextRef globalCtx ) : ContentCallback(globalCtx){
56 virtual ~ContentFindCallback(){
61 JSValueRef valueArray[m_contents.size()];
62 for( unsigned int i = 0 ; i < m_contents.size(); i++){
63 if(std::dynamic_pointer_cast<ImageContent>(m_contents[i])){
64 valueArray[i] = JSImageContent::CreateJSObject(m_callback->getContext(), m_contents[i]);
66 else if(std::dynamic_pointer_cast<VideoContent>(m_contents[i])){
67 valueArray[i] = JSVideoContent::CreateJSObject(m_callback->getContext(), m_contents[i]);
69 else if(std::dynamic_pointer_cast<AudioContent>(m_contents[i])){
70 valueArray[i] = JSAudioContent::CreateJSObject(m_callback->getContext(), m_contents[i]);
72 else if(m_contents[i]){
73 valueArray[i] = JSContent::CreateJSObject(m_callback->getContext(), m_contents[i]);
76 JSValueRef exception = NULL;
77 JSObjectRef jsResult = JSObjectMakeArray(m_callback->getContext(), m_contents.size(), valueArray, &exception);
78 if (exception != NULL) {
79 throw DeviceAPI::Common::UnknownException(m_callback->getContext(), exception);
81 m_callback->invokeCallback("onsuccess", jsResult);
82 TIME_TRACER_ITEM_END(CONTENT_TT_FIND_TOTAL, CONTENT_TIME_TRACER_SHOW);
85 std::string getDirectoryId(){
89 void setDirectoryId(std::string& directoryId){
90 m_directoryId = directoryId;
93 AbstractFilterPtr& getFilter(){
97 void setFilter(AbstractFilterPtr& filter){
101 SortModePtr& getSortMode(){
105 void setSortMode(SortModePtr& sortMode){
106 m_sortMode = sortMode;
109 unsigned long getCount(){
113 void setCount(unsigned long count){
117 unsigned long getOffset(){
121 void setOffset(unsigned long offset){
125 ContentLst* getContents(){
130 std::string m_directoryId;
131 AbstractFilterPtr m_filter;
132 SortModePtr m_sortMode;
133 unsigned long m_count;
134 unsigned long m_offset;
136 ContentLst m_contents;
139 typedef std::shared_ptr<ContentFindCallback> ContentFindCallbackPtr;
144 #endif // __TIZEN_CONTENT_FIND_CALLBACK_H__