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