2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <feedback-player-impl.h>
23 #include <dali/public-api/object/type-registry.h>
26 #include <singleton-service-impl.h>
37 namespace // unnamed namespace
41 Dali::BaseHandle Create()
43 return FeedbackPlayer::Get();
46 Dali::TypeRegistration FEEDBACK_PLAYER_TYPE( typeid(Dali::FeedbackPlayer), typeid(Dali::BaseHandle), Create );
48 } // unnamed namespace
50 Dali::FeedbackPlayer FeedbackPlayer::New()
52 Dali::FeedbackPlayer player = Dali::FeedbackPlayer( new FeedbackPlayer() );
56 Dali::FeedbackPlayer FeedbackPlayer::Get()
58 Dali::FeedbackPlayer player;
60 Dali::SingletonService service( SingletonService::Get() );
63 // Check whether the singleton is already created
64 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::FeedbackPlayer ) );
67 // If so, downcast the handle
68 player = Dali::FeedbackPlayer( dynamic_cast< FeedbackPlayer* >( handle.GetObjectPtr() ) );
72 player = Dali::FeedbackPlayer( New() );
73 service.Register( typeid( player ), player );
80 void FeedbackPlayer::PlayMonotone( unsigned int duration )
82 mPlugin.PlayHapticMonotone( duration );
85 void FeedbackPlayer::PlayFile( const std::string& filePath )
87 mPlugin.PlayHaptic( filePath );
90 void FeedbackPlayer::Stop()
95 int FeedbackPlayer::PlaySound( const std::string& filename )
97 return mPlugin.PlaySound(filename);
100 void FeedbackPlayer::StopSound( int handle )
102 mPlugin.StopSound(handle);
105 void FeedbackPlayer::PlayFeedbackPattern( int type, int pattern )
107 mPlugin.PlayFeedbackPattern(type, pattern);
110 bool FeedbackPlayer::LoadFile(const std::string& filename, std::string& data)
114 std::ifstream stream(filename.c_str());
116 if( stream.is_open() )
118 data.assign((std::istreambuf_iterator<char>(stream)),
119 std::istreambuf_iterator<char>());
126 FeedbackPlayer::FeedbackPlayer()
127 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
131 FeedbackPlayer::~FeedbackPlayer()
135 } // namespace Adaptor
137 } // namespace Internal