41b28be4e61152cf3c47b59898dd59bc4196dbc0
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / tizen / resource-loader / resource-loader.h
1 #ifndef __DALI_TIZEN_PLATFORM_RESOURCE_LOADER_H__
2 #define __DALI_TIZEN_PLATFORM_RESOURCE_LOADER_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 #include <dali/integration-api/platform-abstraction.h>
22 #include <dali/public-api/common/dali-vector.h>
23
24 #include <string>
25
26 namespace Dali
27 {
28
29 namespace Integration
30 {
31 namespace Log
32 {
33 class Filter;
34 }
35 }
36
37 namespace TizenPlatform
38 {
39
40 /**
41  * Contains information about a successfully loaded resource
42  */
43 struct LoadedResource
44 {
45   /**
46    * Constructor
47    * @param[in] loadedId        The ID of the resource
48    * @param[in] loadedType      The resource type
49    * @param[in] loadedResource  A pointer to the loaded resource data
50    */
51   LoadedResource(Integration::ResourceId      loadedId,
52                  Integration::ResourceTypeId  loadedType,
53                  Integration::ResourcePointer loadedResource)
54   : id(loadedId),
55     type(loadedType),
56     resource(loadedResource)
57   {
58   }
59
60   /// Copy constructor
61   LoadedResource(const LoadedResource& loaded)
62   : id(loaded.id),
63     type(loaded.type),
64     resource(loaded.resource)
65   {
66   }
67
68   /// Assignment operator
69   LoadedResource& operator=(const LoadedResource& rhs)
70   {
71     if( this != &rhs )
72     {
73       id = rhs.id;
74       type = rhs.type;
75       resource = rhs.resource;
76     }
77     return *this;
78   }
79
80   Integration::ResourceId      id;         ///< Integer ID
81   Integration::ResourceTypeId  type;       ///< Type enum (bitmap, ...)
82   Integration::ResourcePointer resource;   ///< Reference counting pointer to the loaded / decoded representation  of the resource.
83 };
84
85 /**
86  * Contains information about a failed resource load/save request
87  */
88 struct FailedResource
89 {
90 };
91
92 /**
93  * This implements the resource loading part of the PlatformAbstraction API.
94  * The requests for a specific resource type are farmed-out to a resource
95  * requester for that type which handles them in their own dedicated loading
96  * threads.
97  */
98 class ResourceLoader
99 {
100 public:
101
102   /**
103    * Create a resource loader.
104    * There should exactly one of these objects per Dali Core.
105    */
106   ResourceLoader();
107
108   /**
109    * Non-virtual destructor.
110    * ResourceLoader is NOT intended as a base class.
111    */
112   ~ResourceLoader();
113
114   /**
115    * Check if the ResourceLoader is terminating
116    * @return true if terminating else false
117    */
118   bool IsTerminating();
119
120   /**
121    * Add a completely loaded resource to the LoadedResource queue
122    * @param[in] resource The resource's information and data
123    */
124   void AddLoadedResource(LoadedResource& resource);
125
126   /**
127    * Add information about a failed resource load to the FailedLoads queue
128    * @param[in] resource The failed resource's information
129    */
130   void AddFailedLoad(FailedResource& resource);
131
132   // From PlatformAbstraction
133
134   /**
135    * @copydoc SlpPlatformAbstraction::LoadFile()
136    */
137   bool LoadFile( const std::string& filename, std::vector< unsigned char >& buffer ) const;
138   bool LoadFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
139
140   /**
141    * @copydoc TizenPlatformAbstraction::LoadFile()
142    */
143   std::string LoadFile(const std::string& filename) const;
144
145   /**
146    * @copydoc TizenPlatformAbstraction::SaveFile()
147    */
148   static bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes );
149
150 private:
151
152   // Undefined
153   ResourceLoader( const ResourceLoader& resourceLoader );
154
155   // Undefined
156   ResourceLoader& operator=( const ResourceLoader& resourceLoader );
157
158 private:
159   struct ResourceLoaderImpl;
160   ResourceLoaderImpl* mImpl;
161
162   volatile int mTerminateThread;        ///< Set to <> 0 in destructor, signals threads to exit their controlling loops
163
164 };
165
166 } // namespace TizenPlatform
167
168 } // namespace Dali
169
170 #endif // __DALI_TIZEN_PLATFORM_RESOURCE_LOADER_H_