(GCC 6.2) Remove unused functions from automated tests
[platform/core/uifw/dali-core.git] / dali / internal / event / images / image-factory-cache.h
1 #ifndef __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__
2 #define __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/common/dali-common.h>
23 #include <dali/internal/event/resources/resource-client.h>
24 #include <dali/internal/common/image-attributes.h>
25
26 // EXTERNAL INCLUDES
27
28
29 namespace Dali
30 {
31
32 namespace Internal
33 {
34
35 namespace ImageFactoryCache
36 {
37
38 /**
39  * Request contains information about requests made when loading image resources.
40  */
41 struct Request;
42
43 /**
44  * @brief Unique ID for image resource requests.
45  *
46  * Images are loaded from a string locator (typically a file path) using a set
47  * of ImageAttributes. Each unique pair of string and attributes is mapped to a
48  * unique RequestId value. This ensures multiple Image objects loading the same
49  * image file with the same attributes only generate one resource request and
50  * Core only issues one IO operation to Adaptor to do the load.
51  *
52  * @sa Dali::Integration::ResourceId
53  */
54 typedef unsigned int RequestId;
55
56 typedef std::multimap<size_t, RequestId>           RequestPathHashMap;
57 typedef std::pair<size_t, RequestId>               RequestPathHashPair;
58 typedef std::map<RequestId, Request*>  RequestIdMap;
59 typedef std::pair<RequestId, Request*> RequestIdPair;
60
61 typedef IntrusivePtr<Request> RequestPtr;
62
63 /**
64  * The RequestLifetimeObserver observes the lifetime of image requests.
65  */
66 class RequestLifetimeObserver
67 {
68 public:
69
70   /**
71    * Called when an image request is discarded.
72    * This occurs during the ImageFactoryCache::Request destructor.
73    * @param[in] request The discarded request.
74    */
75   virtual void RequestDiscarded( const Request& request ) = 0;
76 };
77
78 /**
79 * Request is a reference counted object to control the lifetime of elements in ImageFactory's cache.
80 * When no more Image objects reference a request, it gets removed from ImageFactory cache.
81 */
82 struct Request : public RefObject
83 {
84   /**
85    * Image request.
86    * These requests are stored in ImageFactory's cache.
87    * @param [in] observer The object which observes request lifetime.
88    * @param [in] reqId A unique ID for this request.
89    * @param [ib] resId A unique ticket ID.
90    * @param [in] path  Url of request.
91    * @param [in] attr  Requested ImageAttributes.
92    */
93   Request( RequestLifetimeObserver& observer, RequestId reqId, ResourceId resId, const std::string& path, const ImageAttributes *attr );
94
95   ResourceId resourceId;        ///< The Ticket ID. This can be used to acquire details of the loaded resource from ResourceClient.
96   const std::string url;        ///< Path to the image resource
97   ImageAttributes* attributes;  ///< ImageAttributes that were used
98
99 public:
100   /**
101    * Retrieve the unique ID of this request.
102    * @return The unique ID for this request.
103    */
104   RequestId GetId() const;
105
106   /**
107    * Called when the RequestLifetimeObserver is being destroyed.
108    * This method should only be called during destruction of the Dali core.
109    */
110   void StopLifetimeObservation();
111
112 protected:
113   virtual ~Request();
114
115 private:
116   Request(); ///< not defined
117   Request(const Request& rhs); ///< not defined
118   Request& operator=(const Request& rhs); ///< not defined
119
120 private:
121   RequestId mId; ///< Request id assigned by ImageFactory
122   RequestLifetimeObserver* mLifetimeObserver; ///< reference to the lifetime-observer; not owned
123 };
124
125 typedef std::pair<RequestPathHashMap::iterator, RequestPathHashMap::iterator> RequestPathHashRange;
126
127 } // namespace ImageFactoryCache
128
129 } // namespace Internal
130
131 } // namespace Dali
132
133 #endif // __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__
134