Add features to download images over http protocol.
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / slp / resource-loader / resource-thread-base.h
index 8636e54..ae5aadd 100644 (file)
  *
  */
 
+// INTERNAL INCLUDES
 #include "resource-loader.h"
-#include <deque>
-#include <boost/thread.hpp>
-
+#include "resource-loading-client.h"
 #include <dali/integration-api/platform-abstraction.h>
 #include <dali/integration-api/resource-cache.h>
 
+// EXTERNAL INCLUDES
+#include <deque>
+#include <boost/thread.hpp>
+
 namespace Dali
 {
 
@@ -34,7 +37,7 @@ namespace SlpPlatform
 /**
  * Resource loader worker thread
  */
-class ResourceThreadBase
+class ResourceThreadBase : public ResourceLoadingClient
 {
 public:
   // typedefs and enums
@@ -45,6 +48,8 @@ public:
   {
     /** Pull a resource out of the platform's file system. */
     RequestLoad,
+    /** Pull a resource over http protocol. */
+    RequestDownload,
     /** Pull a resource out of a memory buffer. */
     RequestDecode,
     /** Push a resource's data out to the file system. */
@@ -56,8 +61,10 @@ public:
   typedef RequestQueue::iterator                                RequestQueueIter;
 
 public:
-  // C'tors and D'tors
+  // Constructor
   ResourceThreadBase(ResourceLoader& resourceLoader);
+
+  // Destructor
   virtual ~ResourceThreadBase();
 
 protected:
@@ -122,6 +129,12 @@ protected:
   virtual void Load(const Integration::ResourceRequest& request) = 0;
 
   /**
+   * Download a resource
+   * @param[in] request  The requested resource/file url and attributes
+   */
+  virtual void Download(const Integration::ResourceRequest& request);
+
+  /**
    * Decode a resource exactly as if it were being loaded but source its data
    * from a memory buffer attached directly to the request object.
    * @param[in] request  The requested resource data and attributes
@@ -134,13 +147,23 @@ protected:
    */
   virtual void Save(const Integration::ResourceRequest& request) = 0;
 
+  /**
+   * @brief Cancels current resource request if it matches the one latched to be cancelled.
+   *
+   * @copydoc ResourceLoadingClient::InterruptionPoint
+   */
+  virtual void InterruptionPoint() const;
+
 protected:
   ResourceLoader& mResourceLoader;
   boost::thread* mThread;                       ///< thread instance
   boost::condition_variable mCondition;         ///< condition variable
   boost::mutex mMutex;                          ///< used to protect mQueue
   RequestQueue mQueue;                          ///< Request queue
-  bool mPaused;                                 ///< Whether to process work in mQueue
+private:
+  Integration::ResourceId mCurrentRequestId;    ///< Current request, set by worker thread
+  volatile Integration::ResourceId mCancelRequestId; ///< Request to be cancelled on thread: written by external thread and read by worker.
+  bool mPaused;                                ///< Whether to process work in mQueue
 
 #if defined(DEBUG_ENABLED)
 public: