1 #ifndef __DALI_INTERNAL_RESOURCE_TICKET_H__
2 #define __DALI_INTERNAL_RESOURCE_TICKET_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/vector-wrapper.h>
23 #include <dali/devel-api/common/map-wrapper.h>
24 #include <dali/public-api/common/loading-state.h>
25 #include <dali/public-api/object/ref-object.h>
26 #include <dali/internal/event/resources/resource-type-path.h>
27 #include <dali/integration-api/resource-cache.h>
36 typedef IntrusivePtr<ResourceTicket> ResourceTicketPtr;
37 typedef std::vector<ResourceTicketPtr> ResourceTicketContainer;
39 class ResourceTicketObserver;
40 class ResourceTicketLifetimeObserver;
43 * @brief ResourceTicket records the lifetime of a resource loading request.
45 * When a resource is requested from ResourceClient, you get a ticket.
46 * The state of the loading operation, can be observed using the ticket.
47 * After the ticket is destroyed, the resource will be discarded.
49 * Multi-threading note: this class should be used in the main thread only
50 * i.e. not from within Dali::Integration::Core::Render().
52 class ResourceTicket : public RefObject
57 * Create a resource request.
58 * This should only be done by the ResourceTicketRegistry.
59 * @param [in] observer The object which observes ticket lifetimes.
60 * @param [in] id A unique ID for this ticket (loading request).
61 * @param [in] typePath The resource Type & Path pair.
63 ResourceTicket( ResourceTicketLifetimeObserver& observer, unsigned int id, ResourceTypePath& typePath );
66 * Retrieve the unique ID of the resource request.
67 * This can be shared with Nodes etc. which will require the resource when rendering.
68 * @return The unique ID for this request.
70 unsigned int GetId() const { return mId; }
73 * Retrieve the type and path of the resource request.
74 * @return The type and path.
76 const ResourceTypePath& GetTypePath() const { return mTypePath; }
79 * Query the state of the resource loading request.
82 Dali::LoadingState GetLoadingState() const { return mLoadingState; }
86 * @param[in] observer The observer.
88 void AddObserver(ResourceTicketObserver& observer);
91 * Removes an observer.
92 * @param[in] observer The observer.
94 void RemoveObserver(ResourceTicketObserver& observer);
96 public: // Used by the ResourceClient
99 * Called when a resource loads successfully.
100 * The ResourceTicketObservers will be notified.
102 void LoadingSucceeded();
105 * Called when a resource fails to load.
106 * The ResourceTicketObservers will be notified.
108 void LoadingFailed();
111 * Reset state to ResourceLoading.
116 * Notification when a resource has been uploaded to GL.
117 * The ResourceTicketObservers will be notified.
122 * Called when the ResourceTicketLifetimeObserver is being destroyed.
123 * This method should only be called during destruction of the Dali core.
125 void StopLifetimeObservation();
130 * A reference counted object may only be deleted by calling Unreference()
132 virtual ~ResourceTicket();
137 * Undefined copy constructor.
139 ResourceTicket(const ResourceTicket&);
142 * Undefined assignment operator.
144 ResourceTicket& operator=(const ResourceTicket& rhs);
148 ResourceTicketLifetimeObserver* mLifetimeObserver; ///< reference to the lifetime-observer; not owned
151 ResourceTypePath mTypePath;
153 Dali::LoadingState mLoadingState;
155 // These ticket observers are not owned by the ticket.
156 // Observers must remove themselves by calling RemoveObserver e.g. during destruction.
157 typedef std::vector<ResourceTicketObserver*> ObserverContainer;
158 typedef ObserverContainer::iterator ObserverIter;
160 ObserverContainer mObservers;
163 } // namespace Internal
167 #endif // __DALI_INTERNAL_RESOURCE_MANAGER_H__