1 #ifndef __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__
2 #define __DALI_INTERNAL_IMAGE_FACTORY_CACHE_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.
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>
35 namespace ImageFactoryCache
39 * Request contains information about requests made when loading image resources.
43 typedef unsigned int RequestId;
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;
50 typedef IntrusivePtr<Request> RequestPtr;
53 * The RequestLifetimeObserver observes the lifetime of image requests.
55 class RequestLifetimeObserver
60 * Called when an image request is discarded.
61 * This occurs during the ImageFactoryCache::Request destructor.
62 * @param[in] request The discarded request.
64 virtual void RequestDiscarded( const Request& request ) = 0;
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.
71 struct Request : public RefObject
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.
82 Request( RequestLifetimeObserver& observer, RequestId reqId, ResourceId resId, const std::string& path, const ImageAttributes *attr );
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
90 * Retrieve the unique ID of this request.
91 * @return The unique ID for this request.
93 RequestId GetId() const;
96 * Called when the RequestLifetimeObserver is being destroyed.
97 * This method should only be called during destruction of the Dali core.
99 void StopLifetimeObservation();
105 Request(); ///< not defined
106 Request(const Request& rhs); ///< not defined
107 Request& operator=(const Request& rhs); ///< not defined
110 RequestId mId; ///< Request id assigned by ImageFactory
111 RequestLifetimeObserver* mLifetimeObserver; ///< reference to the lifetime-observer; not owned
114 typedef std::pair<RequestPathHashMap::iterator, RequestPathHashMap::iterator> RequestPathHashRange;
116 } // namespace ImageFactoryCache
118 } // namespace Internal
122 #endif // __DALI_INTERNAL_IMAGE_FACTORY_CACHE_H__