Merge "Boost removal from performance server" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / common / haptic-player-impl.cpp
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 <haptic-player-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/type-registry.h>
23
24 // INTERNAL INCLUDES
25 #include <singleton-service-impl.h>
26
27 namespace Dali
28 {
29
30 namespace Internal
31 {
32
33 namespace Adaptor
34 {
35
36 namespace // unnamed namespace
37 {
38
39 // Type Registration
40 Dali::BaseHandle Create()
41 {
42   return HapticPlayer::Get();
43 }
44
45 Dali::TypeRegistration HAPTIC_PLAYER_TYPE( typeid(Dali::HapticPlayer), typeid(Dali::BaseHandle), Create );
46
47 } // unnamed namespace
48
49 Dali::HapticPlayer HapticPlayer::New()
50 {
51   Dali::HapticPlayer player = Dali::HapticPlayer( new HapticPlayer() );
52   return player;
53 }
54
55 Dali::HapticPlayer HapticPlayer::Get()
56 {
57   Dali::HapticPlayer player;
58
59   Dali::SingletonService service( SingletonService::Get() );
60   if ( service )
61   {
62     // Check whether the singleton is already created
63     Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::HapticPlayer ) );
64     if ( handle )
65     {
66       // If so, downcast the handle
67       player = Dali::HapticPlayer( dynamic_cast< HapticPlayer* >( handle.GetObjectPtr() ) );
68     }
69     else
70     {
71       player = Dali::HapticPlayer( New() );
72       service.Register( typeid( player ), player );
73     }
74   }
75
76   return player;
77 }
78
79 void HapticPlayer::PlayMonotone( unsigned int duration )
80 {
81   mPlugin.PlayHapticMonotone( duration );
82 }
83
84 void HapticPlayer::PlayFile( const std::string& filePath )
85 {
86   mPlugin.PlayHaptic( filePath );
87 }
88
89 void HapticPlayer::Stop()
90 {
91   mPlugin.StopHaptic();
92 }
93
94 HapticPlayer::HapticPlayer()
95 : mPlugin( FeedbackPluginProxy::DEFAULT_OBJECT_NAME )
96 {
97 }
98
99 HapticPlayer::~HapticPlayer()
100 {
101 }
102
103 } // namespace Adaptor
104
105 } // namespace Internal
106
107 } // namespace Dali