Added object sizes to platform abstraction in profiling section
[platform/core/uifw/dali-core.git] / dali / integration-api / resource-request.h
1 #ifndef __DALI_INTEGRATION_RESOURCE_REQUEST_H__
2 #define __DALI_INTEGRATION_RESOURCE_REQUEST_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 // INTERNAL INCLUDES
21 #include <dali/integration-api/resource-types.h>
22
23 namespace Dali
24 {
25
26 class RefObject;
27
28 namespace Integration
29 {
30
31 // Resource Requests
32
33 /**
34  * Used to return loaded resources for rendering etc.
35  */
36 typedef IntrusivePtr<Dali::RefObject> ResourcePointer;
37
38 /**
39  * Used to prioritize between loading operations.
40  */
41 enum LoadResourcePriority
42 {
43   LoadPriorityLowest,
44   LoadPriorityLow,
45   LoadPriorityNormal,
46   LoadPriorityHigh,
47   LoadPriorityHighest,
48 };
49
50 /**
51  * Used to request a resource from the native filesystem.
52  */
53 class DALI_IMPORT_API ResourceRequest
54 {
55 public:
56
57   /**
58    * Used to request a resource be accessed from the native filesystem.
59    * @param[in] newId         A unique ID for this request.
60    * @param[in] resourceType  The type of resource requested. The implementation of
61    *                          PlatformAbstraction::LoadResource() is responsible for
62    *                          converting the native file(s) to this type
63    *                          e.g. decoding a jpeg to a bitmap.
64    * @param[in] resourcePath  The path of the resource; typically a filename.
65    * @param[in] loadPriority  The priority of the request.
66    */
67   ResourceRequest(ResourceId newId,
68                   const ResourceType& resourceType,
69                   const std::string& resourcePath,
70                   LoadResourcePriority loadPriority = LoadPriorityNormal)
71   : id(newId),
72     type(NULL),
73     path(resourcePath),
74     priority(loadPriority)
75   {
76     type = resourceType.Clone();
77   }
78
79   /**
80    * Used to request or save a resource from/to the native filesystem.
81    * @param[in] newId         A unique ID for this request.
82    * @param[in] resourceType  The type of resource.
83    * @param[in] resourcePath  The location of the resource / where the resource should be saved.
84    * @param[in] resourcePtr   The resource to decode / save.
85    * @param[in] savePriority  The priority of the request.
86    */
87   ResourceRequest(ResourceId newId,
88                   const ResourceType& resourceType,
89                   const std::string& resourcePath,
90                   ResourcePointer resourcePtr,
91                   LoadResourcePriority savePriority = LoadPriorityNormal)
92   : id(newId),
93     type(NULL),
94     path(resourcePath),
95     resource(resourcePtr),
96     priority(savePriority)
97   {
98     type = resourceType.Clone();
99   }
100
101   /**
102    * Copy constructor.
103    * @param[in] request The resource request to copy.
104    */
105   ResourceRequest(const ResourceRequest& request)
106   : id(request.id),
107     type(NULL),
108     path(request.path),
109     resource(request.resource),
110     priority(request.priority)
111   {
112     type = request.type->Clone();
113   }
114
115   /**
116    * Assignment operator.
117    * @param[in] rhs The resource request to copy.
118    */
119   ResourceRequest& operator=(const ResourceRequest& rhs)
120   {
121     if( this != &rhs )
122     {
123       id = rhs.id;
124       type = rhs.type->Clone();
125       path = rhs.path;
126       resource = rhs.resource;
127       priority = rhs.priority;
128     }
129
130     return *this;
131   }
132
133   /**
134    * Non-virtual destructor; not intended as a base class
135    */
136   ~ResourceRequest()
137   {
138     delete type;
139   }
140
141   /**
142    * Retrieve the resource ID
143    * @return The ID
144    */
145   ResourceId GetId() const
146   {
147     return id;
148   }
149
150   /**
151    * Retrieve the resource type
152    * @return The type
153    */
154   ResourceType* GetType() const
155   {
156     return type;
157   }
158
159   /**
160    * Retrieve the resource path
161    * @return The path
162    */
163   const std::string& GetPath() const
164   {
165     return path;
166   }
167
168   /**
169    * Retrieve the resource (for save and decode requests)
170    * @return The resource
171    */
172   ResourcePointer GetResource() const
173   {
174     return resource;
175   }
176
177   /**
178    * Retrieve the load priority
179    * @return The priority
180    */
181   LoadResourcePriority GetPriority() const
182   {
183     return priority;
184   }
185
186 private:
187
188   ResourceId           id;
189   ResourceType*        type;
190   std::string          path;
191   /** When saving resources or decoding them, the resource data will be passed
192    *  through in a reference counted object here. When Loading, it will be null. */
193   ResourcePointer      resource;
194   LoadResourcePriority priority;
195 };
196
197 } // namespace Integration
198
199 } // namespace Dali
200
201 #endif // __DALI_INTEGRATION_RESOURCE_REQUEST_H__