Dali 3D User Interface Engine
feedback-player-impl.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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 
18 // CLASS HEADER
19 #include <feedback-player-impl.h>
20 
21 // EXTERNAL INCLUDES
22 #include <fstream>
24 
25 // INTERNAL INCLUDES
26 #include <singleton-service-impl.h>
27 
28 namespace Dali
29 {
30 
31 namespace Internal
32 {
33 
34 namespace Adaptor
35 {
36 
37 namespace // unnamed namespace
38 {
39 
40 // Type Registration
42 {
43  return FeedbackPlayer::Get();
44 }
45 
46 Dali::TypeRegistration FEEDBACK_PLAYER_TYPE( typeid(Dali::FeedbackPlayer), typeid(Dali::BaseHandle), Create );
47 
48 } // unnamed namespace
49 
50 Dali::FeedbackPlayer FeedbackPlayer::New()
51 {
52  Dali::FeedbackPlayer player = Dali::FeedbackPlayer( new FeedbackPlayer() );
53  return player;
54 }
55 
56 Dali::FeedbackPlayer FeedbackPlayer::Get()
57 {
58  Dali::FeedbackPlayer player;
59 
61  if ( service )
62  {
63  // Check whether the singleton is already created
64  Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::FeedbackPlayer ) );
65  if ( handle )
66  {
67  // If so, downcast the handle
68  player = Dali::FeedbackPlayer( dynamic_cast< FeedbackPlayer* >( handle.GetObjectPtr() ) );
69  }
70  else
71  {
72  player = Dali::FeedbackPlayer( New() );
73  service.Register( typeid( player ), player );
74  }
75  }
76 
77  return player;
78 }
79 
80 void FeedbackPlayer::PlayMonotone( unsigned int duration )
81 {
82  mPlugin.PlayHapticMonotone( duration );
83 }
84 
85 void FeedbackPlayer::PlayFile( const std::string& filePath )
86 {
87  mPlugin.PlayHaptic( filePath );
88 }
89 
91 {
93 }
94 
95 int FeedbackPlayer::PlaySound( const std::string& filename )
96 {
97  return mPlugin.PlaySound(filename);
98 }
99 
100 void FeedbackPlayer::StopSound( int handle )
101 {
102  mPlugin.StopSound(handle);
103 }
104 
105 void FeedbackPlayer::PlayFeedbackPattern( int type, int pattern )
106 {
107  mPlugin.PlayFeedbackPattern(type, pattern);
108 }
109 
110 bool FeedbackPlayer::LoadFile(const std::string& filename, std::string& data)
111 {
112  bool loaded = false;
113 
114  std::ifstream stream(filename.c_str());
115 
116  if( stream.is_open() )
117  {
118  data.assign((std::istreambuf_iterator<char>(stream)),
119  std::istreambuf_iterator<char>());
120  loaded = true;
121  }
122 
123  return loaded;
124 }
125 
127 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
128 {
129 }
130 
132 {
133 }
134 
135 } // namespace Adaptor
136 
137 } // namespace Internal
138 
139 } // namespace Dali
Dali Docs Home
Read more about Dali