License conversion from Flora to Apache 2.0
[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/public-api/images/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 typedef unsigned int RequestId;
44
45 typedef std::multimap<size_t, RequestId>           RequestPathHashMap;
46 typedef std::pair<size_t, RequestId>               RequestPathHashPair;
47 typedef std::map<RequestId, Request*>  RequestIdMap;
48 typedef std::pair<RequestId, Request*> RequestIdPair;
49
50 typedef IntrusivePtr<Request> RequestPtr;
51
52 /**
53  * The RequestLifetimeObserver observes the lifetime of image requests.
54  */
55 class RequestLifetimeObserver
56 {
57 public:
58
59   /**
60    * Called when an image request is discarded.
61    * This occurs during the ImageFactoryCache::Request destructor.
62    * @param[in] request The discarded request.
63    */
64   virtual void RequestDiscarded( const Request& request ) = 0;
65 };
66
67 /**
68 * Request is a reference counted object to control the lifetime of elements in ImageFactory's cache.
69 * When no more Image objects reference a request, it gets removed from ImageFactory cache.
70 */
71 struct Request : public RefObject
72 {
73   /**
74    * Image request.
75    * These requests are stored in ImageFactory's cache.
76    * @param [in] observer The object which observes request lifetime.
77    * @param [in] reqId A unique ID for this request.
78    * @param [ib] resId A unique ticket ID.
79    * @param [in] path  Url of request.
80    * @param [in] attr  Requested ImageAttributes.
81    */
82   Request( RequestLifetimeObserver& observer, RequestId reqId, ResourceId resId, const std::string& path, const ImageAttributes *attr );
83
84   ResourceId resourceId;        ///< The Ticket ID. This can be used to acquire details of the loaded resource from ResourceClient.
85   const std::string url;        ///< Path to the image resource
86   ImageAttributes* attributes;  ///< ImageAttributes that were used
87
88 public:
89   /**
90    * Retrieve the unique ID of this request.
91    * @return The unique ID for this request.
92    */
93   RequestId GetId() const;
94
95   /**
96    * Called when the RequestLifetimeObserver is being destroyed.
97    * This method should only be called during destruction of the Dali core.
98    */
99   void StopLifetimeObservation();
100
101 protected:
102   ~Request();
103
104 private:
105   Request(); ///< not defined
106   Request(const Request& rhs); ///< not defined
107   Request& operator=(const Request& rhs); ///< not defined
108
109 private:
110   RequestId mId; ///< Request id assigned by ImageFactory
111   RequestLifetimeObserver* mLifetimeObserver; ///< reference to the lifetime-observer; not owned
112 };
113
114 typedef std::pair<RequestPathHashMap::iterator, RequestPathHashMap::iterator> RequestPathHashRange;
115
116 } // namespace ImageFactoryCache
117
118 } // namespace Internal
119
120 } // namespace Dali
121
122 #endif // __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__
123