6690c64519ea7d6c587b5bfc1046110b84b6e8f9
[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       type = rhs.type->Clone();
127       path = rhs.path;
128       resource = rhs.resource;
129       priority = rhs.priority;
130     }
131
132     return *this;
133   }
134
135   /**
136    * Non-virtual destructor; not intended as a base class
137    */
138   ~ResourceRequest()
139   {
140     delete type;
141   }
142
143   /**
144    * Retrieve the resource ID
145    * @return The ID
146    */
147   ResourceId GetId() const
148   {
149     return id;
150   }
151
152   /**
153    * Retrieve the resource type
154    * @return The type
155    */
156   ResourceType* GetType() const
157   {
158     return type;
159   }
160
161   /**
162    * Retrieve the resource path
163    * @return The path
164    */
165   const std::string& GetPath() const
166   {
167     return path;
168   }
169
170   /**
171    * Retrieve the resource (for save and decode requests)
172    * @return The resource
173    */
174   ResourcePointer GetResource() const
175   {
176     return resource;
177   }
178
179   /**
180    * Retrieve the load priority
181    * @return The priority
182    */
183   LoadResourcePriority GetPriority() const
184   {
185     return priority;
186   }
187
188 private:
189
190   ResourceId           id;
191   ResourceType*        type;
192   std::string          path;
193   /** When saving resources or decoding them, the resource data will be passed
194    *  through in a reference counted object here. When Loading, it will be null. */
195   ResourcePointer      resource;
196   LoadResourcePriority priority;
197 };
198
199 } // namespace Integration
200
201 } // namespace Dali
202
203 #endif // __DALI_INTEGRATION_RESOURCE_REQUEST_H__