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 Flora License, Version 1.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://floralicense.org/license/
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.
20 #include "resource-loader.h"
22 #include <boost/thread.hpp>
24 #include <dali/integration-api/platform-abstraction.h>
25 #include <dali/integration-api/resource-cache.h>
34 * Resource loader worker thread
36 class ResourceThreadBase
41 /** Client threads send work to resource threads through Requests, for which
42 * this type identifies the action to be taken on the resource thread. */
45 /** Pull a resource out of the platform's file system. */
47 /** Pull a resource out of a memory buffer. */
49 /** Push a resource's data out to the file system. */
53 typedef std::pair<Integration::ResourceRequest, RequestType> RequestInfo;
54 typedef std::deque<RequestInfo> RequestQueue;
55 typedef RequestQueue::iterator RequestQueueIter;
59 ResourceThreadBase(ResourceLoader& resourceLoader);
60 virtual ~ResourceThreadBase();
63 void TerminateThread();
67 * Add a resource request to the back of the queue
68 * @param[in] request The requested resource/file url and attributes
69 * @param[in] type Load or save flag
71 void AddRequest(const Integration::ResourceRequest& request, const RequestType type);
74 * Cancel a resource request. Removes the request from the queue.
75 * @param[in] resourceId ID of the resource to be canceled
77 void CancelRequest(Integration::ResourceId resourceId);
80 * Pause starting new work in the background, but keep that work queued.
85 * Resume processing tasks on background thread.
92 * Main control loop for the thread.
93 * The thread is terminated when this function exits
98 * Wait for an incoming resource request or termination
100 void WaitForRequests();
103 * Process the resource request at the head of the queue
105 void ProcessNextRequest();
108 * Install a logging function in to core for this thread.
110 void InstallLogging();
113 * Uninstall a logging function.
115 void UninstallLogging();
119 * @param[in] request The requested resource/file url and attributes
121 virtual void Load(const Integration::ResourceRequest& request) = 0;
124 * Decode a resource exactly as if it were being loaded but source its data
125 * from a memory buffer attached directly to the request object.
126 * @param[in] request The requested resource data and attributes
128 virtual void Decode(const Integration::ResourceRequest& request);
132 * @param[in] request The requested resource/file url and attributes
134 virtual void Save(const Integration::ResourceRequest& request) = 0;
137 ResourceLoader& mResourceLoader;
138 boost::thread* mThread; ///< thread instance
139 boost::condition_variable mCondition; ///< condition variable
140 boost::mutex mMutex; ///< used to protect mQueue
141 RequestQueue mQueue; ///< Request queue
142 bool mPaused; ///< Whether to process work in mQueue
144 #if defined(DEBUG_ENABLED)
146 Integration::Log::Filter* mLogFilter;
148 }; // class ResourceThreadBase
150 } // namespace SlpPlatform
154 #endif // __DALI_SLPPLATFORM_RESOURCE_THREAD_BASE_H__