Update common test util
[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/adaptor-framework/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 true;
89   }
90
91 private:
92   FeedbackPlayer()
93   {
94   }
95
96   virtual ~FeedbackPlayer()
97   {
98   }
99
100   FeedbackPlayer(const FeedbackPlayer&)
101   {
102   }
103
104   FeedbackPlayer& operator=(FeedbackPlayer&)
105   {
106     return *this;
107   }
108 };
109
110 } // Adaptor
111 } // Internal
112
113 inline Internal::Adaptor::FeedbackPlayer& GetImplementation(Dali::FeedbackPlayer& player)
114 {
115   DALI_ASSERT_ALWAYS( player && "FeedbackPlayer handle is empty" );
116   BaseObject& handle = player.GetBaseObject();
117   return static_cast<Internal::Adaptor::FeedbackPlayer&>(handle);
118 }
119
120 inline const Internal::Adaptor::FeedbackPlayer& GetImplementation(const Dali::FeedbackPlayer& player)
121 {
122   DALI_ASSERT_ALWAYS( player && "FeedbackPlayer handle is empty" );
123   const BaseObject& handle = player.GetBaseObject();
124   return static_cast<const Internal::Adaptor::FeedbackPlayer&>(handle);
125 }
126
127 FeedbackPlayer::FeedbackPlayer()
128 {
129 }
130
131 FeedbackPlayer FeedbackPlayer::Get()
132 {
133   return Internal::Adaptor::FeedbackPlayer::Get();
134 }
135
136 FeedbackPlayer::~FeedbackPlayer()
137 {
138 }
139
140 void FeedbackPlayer::PlayMonotone(unsigned int duration)
141 {
142   GetImplementation(*this).PlayMonotone(duration);
143 }
144
145 void FeedbackPlayer::PlayFile(const std::string filePath)
146 {
147   GetImplementation(*this).PlayFile(filePath);
148 }
149
150 void FeedbackPlayer::Stop()
151 {
152   GetImplementation(*this).Stop();
153 }
154
155 int FeedbackPlayer::PlaySound( const std::string& fileName )
156 {
157   return GetImplementation(*this).PlaySound(fileName);
158 }
159
160 void FeedbackPlayer::StopSound( int handle )
161 {
162   GetImplementation(*this).StopSound(handle);
163 }
164
165 void FeedbackPlayer::PlayFeedbackPattern( int type, int pattern )
166 {
167   GetImplementation(*this).PlayFeedbackPattern(type, pattern);
168 }
169
170 bool FeedbackPlayer::LoadFile(const std::string& filename, std::string& data)
171 {
172   return GetImplementation(*this).LoadFile(filename, data);
173 }
174
175 FeedbackPlayer::FeedbackPlayer( Internal::Adaptor::FeedbackPlayer* player )
176 : BaseHandle( player )
177 {
178 }
179
180 } // Dali