Fix memory leak
[platform/core/uifw/dali-adaptor.git] / dali / internal / legacy / common / tizen-platform-abstraction.h
1 #ifndef DALI_TIZEN_PLATFORM_ABSTRACTION_H
2 #define DALI_TIZEN_PLATFORM_ABSTRACTION_H
3
4 /*
5  * Copyright (c) 2019 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/public-api/adaptor-framework/timer.h>
23 #include <dali/public-api/dali-adaptor-common.h>
24
25
26 // EXTERNAL INCLUDES
27 #include <cstdint>
28 #include <string>
29 #include <memory>
30 #include <dali/integration-api/platform-abstraction.h>
31
32 namespace Dali
33 {
34
35 class CallbackBase;
36
37 namespace TizenPlatform
38 {
39 class ResourceLoader;
40
41 /**
42  * Concrete implementation of the platform abstraction class.
43  */
44 class TizenPlatformAbstraction : public Integration::PlatformAbstraction
45 {
46
47 public: // Construction & Destruction
48
49   /**
50    * Constructor
51    */
52   TizenPlatformAbstraction();
53
54   /**
55    * Destructor
56    */
57   virtual ~TizenPlatformAbstraction();
58
59 public: // PlatformAbstraction overrides
60
61   /**
62    * @copydoc PlatformAbstraction::GetClosestImageSize()
63    */
64   virtual ImageDimensions GetClosestImageSize( const std::string& filename,
65                                                ImageDimensions size,
66                                                FittingMode::Type fittingMode,
67                                                SamplingMode::Type samplingMode,
68                                                bool orientationCorrection );
69
70   /**
71    * @copydoc PlatformAbstraction::GetClosestImageSize()
72    */
73   virtual ImageDimensions GetClosestImageSize( Integration::ResourcePointer resourceBuffer,
74                                                ImageDimensions size,
75                                                FittingMode::Type fittingMode,
76                                                SamplingMode::Type samplingMode,
77                                                bool orientationCorrection );
78
79   /**
80    * @copydoc PlatformAbstraction::LoadImageSynchronously()
81    */
82   virtual Integration::ResourcePointer LoadImageSynchronously(const Integration::BitmapResourceType& resource, const std::string& resourcePath);
83
84   /**
85    * @copydoc PlatformAbstraction::DecodeBuffer()
86    */
87   virtual Integration::BitmapPtr DecodeBuffer( const Integration::BitmapResourceType& resource, uint8_t * buffer, size_t size );
88
89   /**
90    * @copydoc PlatformAbstraction::LoadShaderBinaryFile()
91    */
92   virtual bool LoadShaderBinaryFile( const std::string& filename, Dali::Vector< unsigned char >& buffer ) const;
93
94   /**
95    * @copydoc PlatformAbstraction::SaveShaderBinaryFile()
96    */
97   virtual bool SaveShaderBinaryFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes ) const;
98
99   /**
100    * @copydoc PlatformAbstraction::StartTimer()
101    */
102   virtual uint32_t StartTimer( uint32_t milliseconds, CallbackBase* callback );
103
104   /**
105    * @copydoc PlatformAbstraction::CancelTimer()
106    */
107   virtual void CancelTimer ( uint32_t timerId );
108
109   /**
110    * Sets path for data/resource storage.
111    * @param[in] path data/resource storage path
112    */
113   void SetDataStoragePath( const std::string& path );
114
115   /**
116    * Clears the timers that have completed
117    */
118   void CleanupTimers();
119
120 private:
121
122   struct TimerCallback;
123
124   /*
125    * Executes callback function and cleans up timer
126    */
127   void RunTimerFunction(TimerCallback& timerPtr);
128
129   TizenPlatformAbstraction( const TizenPlatformAbstraction& ); ///< Undefined
130   TizenPlatformAbstraction& operator=( const TizenPlatformAbstraction& ); ///< Undefined
131
132   std::string mDataStoragePath;
133
134   std::vector< std::unique_ptr< TimerCallback > > mTimerPairsWaiting;
135   std::vector< std::unique_ptr< TimerCallback > > mTimerPairsSpent;
136 };
137
138 /**
139  * Construct a platform abstraction and return it.
140  * @return TizenPlatformAbstraction instance
141  */
142 TizenPlatformAbstraction* CreatePlatformAbstraction();
143
144 /**
145  * Save a file to disk
146  * @param filename to create
147  * @param buffer to store
148  * @param numBytes to store
149  * @return true if successful, false otherwise
150  */
151 bool SaveFile( const std::string& filename, const unsigned char * buffer, unsigned int numBytes );
152
153 }  // namespace TizenPlatform
154
155 }  // namespace Dali
156
157 #endif // DALI_TIZEN_PLATFORM_ABSTRACTION_H