2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "resource-bitmap-requester.h"
19 #include <dali/integration-api/resource-cache.h>
21 using namespace Dali::Integration;
28 ResourceBitmapRequester::ResourceBitmapRequester( ResourceLoader& resourceLoader )
29 : ResourceRequesterBase( resourceLoader )
31 mThreadImageLocal = new ResourceThreadImage( resourceLoader, false );
32 mThreadImageRemote = new ResourceThreadImage( resourceLoader, true );
35 ResourceBitmapRequester::~ResourceBitmapRequester()
37 delete mThreadImageLocal;
38 delete mThreadImageRemote;
41 void ResourceBitmapRequester::Pause()
43 mThreadImageLocal->Pause();
44 mThreadImageRemote->Pause();
47 void ResourceBitmapRequester::Resume()
49 mThreadImageLocal->Resume();
50 mThreadImageRemote->Resume();
53 void ResourceBitmapRequester::LoadResource( Integration::ResourceRequest& request )
55 DALI_ASSERT_DEBUG( (0 != dynamic_cast<BitmapResourceType*>(request.GetType())) && "Only requsts for bitmap resources can ever be routed to ResourceBitmapRequester.\n");
56 BitmapResourceType* resType = static_cast<BitmapResourceType*>(request.GetType());
59 // Work out what thread to decode / load the image on:
60 ResourceThreadBase* const localImageThread = mThreadImageLocal;
61 ResourceThreadBase* const remoteImageThread = mThreadImageRemote;
62 ResourceThreadBase* workerThread;
64 // Work out if the resource is in memory, a file, or in a remote server:
65 ResourceThreadBase::RequestType requestType;
66 if( request.GetResource().Get() )
68 requestType = ResourceThreadBase::RequestDecode;
69 workerThread = localImageThread;
73 const std::string& resourcePath = request.GetPath();
74 if( resourcePath.length() > 7 && strncasecmp( resourcePath.c_str(), "http://", 7 ) == 0 )
76 requestType = ResourceThreadBase::RequestDownload;
77 workerThread = remoteImageThread;
81 requestType = ResourceThreadBase::RequestLoad;
82 workerThread = localImageThread;
86 // Dispatch the job to the right thread:
87 workerThread->AddRequest( request, requestType );
91 Integration::LoadStatus ResourceBitmapRequester::LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource )
94 return RESOURCE_COMPLETELY_LOADED;
97 void ResourceBitmapRequester::SaveResource(const Integration::ResourceRequest& request )
102 void ResourceBitmapRequester::CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId)
104 mThreadImageLocal->CancelRequest(id);
105 mThreadImageRemote->CancelRequest(id);