Merge "CMake - Option added to define the default toolkit resource path." into devel...
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-feedback-player.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <dali/devel-api/adaptor-framework/feedback-player.h>
18 #include <dali/devel-api/common/singleton-service.h>
19 #include <dali/public-api/object/base-object.h>
20
21 using namespace Dali;
22
23 namespace Dali
24 {
25 class Adaptor;
26
27 namespace Internal
28 {
29 namespace Adaptor
30 {
31
32 class FeedbackPlayer : public Dali::BaseObject
33 {
34 public:
35   static Dali::FeedbackPlayer New()
36   {
37     Dali::FeedbackPlayer player = Dali::FeedbackPlayer( new FeedbackPlayer() );
38     return player;
39   }
40
41   static Dali::FeedbackPlayer Get()
42   {
43     Dali::FeedbackPlayer player;
44     Dali::SingletonService service( Dali::SingletonService::Get() );
45     if( service )
46     {
47       // Check whether the singleton is already created
48       Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::FeedbackPlayer ) );
49       if( handle )
50       {
51         player = Dali::FeedbackPlayer( dynamic_cast< FeedbackPlayer* >( handle.GetObjectPtr() ) );
52       }
53       else
54       {
55         player = Dali::FeedbackPlayer( New() );
56         service.Register( typeid( player ), player );
57       }
58     }
59     return player;
60   }
61   void PlayMonotone(unsigned int duration)
62   {
63   }
64
65   void PlayFile( const std::string& filePath )
66   {
67   }
68
69   void Stop()
70   {
71   }
72
73   int PlaySound( const std::string& fileName )
74   {
75     return 0;
76   }
77
78   void StopSound( int handle )
79   {
80   }
81
82   void PlayFeedbackPattern( int type, int pattern )
83   {
84   }
85
86   bool LoadFile(const std::string& filename, std::string& data)
87   {
88     return mLoadFileReturn;
89   }
90
91   void SetLoadFileReturnValue(bool value)
92   {
93     mLoadFileReturn = value;
94   }
95
96 private:
97   FeedbackPlayer()
98   : mLoadFileReturn{true}
99   {
100   }
101
102   virtual ~FeedbackPlayer()
103   {
104   }
105
106   FeedbackPlayer(const FeedbackPlayer&)
107   {
108   }
109
110   FeedbackPlayer& operator=(FeedbackPlayer&)
111   {
112     return *this;
113   }
114
115   bool mLoadFileReturn;
116 };
117
118 } // Adaptor
119 } // Internal
120
121 inline Internal::Adaptor::FeedbackPlayer& GetImplementation(Dali::FeedbackPlayer& player)
122 {
123   DALI_ASSERT_ALWAYS( player && "FeedbackPlayer handle is empty" );
124   BaseObject& handle = player.GetBaseObject();
125   return static_cast<Internal::Adaptor::FeedbackPlayer&>(handle);
126 }
127
128 inline const Internal::Adaptor::FeedbackPlayer& GetImplementation(const Dali::FeedbackPlayer& player)
129 {
130   DALI_ASSERT_ALWAYS( player && "FeedbackPlayer handle is empty" );
131   const BaseObject& handle = player.GetBaseObject();
132   return static_cast<const Internal::Adaptor::FeedbackPlayer&>(handle);
133 }
134
135 FeedbackPlayer::FeedbackPlayer()
136 {
137 }
138
139 FeedbackPlayer FeedbackPlayer::Get()
140 {
141   return Internal::Adaptor::FeedbackPlayer::Get();
142 }
143
144 FeedbackPlayer::~FeedbackPlayer()
145 {
146 }
147
148 void FeedbackPlayer::PlayMonotone(unsigned int duration)
149 {
150   GetImplementation(*this).PlayMonotone(duration);
151 }
152
153 void FeedbackPlayer::PlayFile(const std::string filePath)
154 {
155   GetImplementation(*this).PlayFile(filePath);
156 }
157
158 void FeedbackPlayer::Stop()
159 {
160   GetImplementation(*this).Stop();
161 }
162
163 int FeedbackPlayer::PlaySound( const std::string& fileName )
164 {
165   return GetImplementation(*this).PlaySound(fileName);
166 }
167
168 void FeedbackPlayer::StopSound( int handle )
169 {
170   GetImplementation(*this).StopSound(handle);
171 }
172
173 void FeedbackPlayer::PlayFeedbackPattern( int type, int pattern )
174 {
175   GetImplementation(*this).PlayFeedbackPattern(type, pattern);
176 }
177
178 bool FeedbackPlayer::LoadFile(const std::string& filename, std::string& data)
179 {
180   return GetImplementation(*this).LoadFile(filename, data);
181 }
182
183 FeedbackPlayer::FeedbackPlayer( Internal::Adaptor::FeedbackPlayer* player )
184 : BaseHandle( player )
185 {
186 }
187
188 namespace Internal
189 {
190 namespace Adaptor
191 {
192
193 void SetLoadFileReturnValue(Dali::FeedbackPlayer feedbackPlayer, bool returnValue)
194 {
195   GetImplementation(feedbackPlayer).SetLoadFileReturnValue( returnValue );
196 }
197
198 } // Adaptor
199 } // Internal
200
201 } // Dali