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