1 #ifndef __DALI_SLP_PLATFORM_RESOURCE_THREAD_BASE_H__
2 #define __DALI_SLP_PLATFORM_RESOURCE_THREAD_BASE_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include "resource-loader.h"
23 #include <boost/thread.hpp>
25 #include <dali/integration-api/platform-abstraction.h>
26 #include <dali/integration-api/resource-cache.h>
35 * Resource loader worker thread
37 class ResourceThreadBase
42 /** Client threads send work to resource threads through Requests, for which
43 * this type identifies the action to be taken on the resource thread. */
46 /** Pull a resource out of the platform's file system. */
48 /** Pull a resource out of a memory buffer. */
50 /** Push a resource's data out to the file system. */
54 typedef std::pair<Integration::ResourceRequest, RequestType> RequestInfo;
55 typedef std::deque<RequestInfo> RequestQueue;
56 typedef RequestQueue::iterator RequestQueueIter;
60 ResourceThreadBase(ResourceLoader& resourceLoader);
61 virtual ~ResourceThreadBase();
64 void TerminateThread();
68 * Add a resource request to the back of the queue
69 * @param[in] request The requested resource/file url and attributes
70 * @param[in] type Load or save flag
72 void AddRequest(const Integration::ResourceRequest& request, const RequestType type);
75 * Cancel a resource request. Removes the request from the queue.
76 * @param[in] resourceId ID of the resource to be canceled
78 void CancelRequest(Integration::ResourceId resourceId);
81 * Pause starting new work in the background, but keep that work queued.
86 * Resume processing tasks on background thread.
93 * Main control loop for the thread.
94 * The thread is terminated when this function exits
99 * Wait for an incoming resource request or termination
101 void WaitForRequests();
104 * Process the resource request at the head of the queue
106 void ProcessNextRequest();
109 * Install a logging function in to core for this thread.
111 void InstallLogging();
114 * Uninstall a logging function.
116 void UninstallLogging();
120 * @param[in] request The requested resource/file url and attributes
122 virtual void Load(const Integration::ResourceRequest& request) = 0;
125 * Decode a resource exactly as if it were being loaded but source its data
126 * from a memory buffer attached directly to the request object.
127 * @param[in] request The requested resource data and attributes
129 virtual void Decode(const Integration::ResourceRequest& request);
133 * @param[in] request The requested resource/file url and attributes
135 virtual void Save(const Integration::ResourceRequest& request) = 0;
138 ResourceLoader& mResourceLoader;
139 boost::thread* mThread; ///< thread instance
140 boost::condition_variable mCondition; ///< condition variable
141 boost::mutex mMutex; ///< used to protect mQueue
142 RequestQueue mQueue; ///< Request queue
143 Integration::ResourceId mCurrentRequestId; ///< Request being processed on thread
144 bool mPaused; ///< Whether to process work in mQueue
146 #if defined(DEBUG_ENABLED)
148 Integration::Log::Filter* mLogFilter;
150 }; // class ResourceThreadBase
152 } // namespace SlpPlatform
156 #endif // __DALI_SLPPLATFORM_RESOURCE_THREAD_BASE_H__