2 * Copyright (c) 2016 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.
17 #include <dali/public-api/object/base-object.h>
18 #include <dali/devel-api/common/singleton-service.h>
19 #include <dali/devel-api/adaptor-framework/sound-player.h>
33 class SoundPlayer : public Dali::BaseObject
36 static Dali::SoundPlayer New()
38 Dali::SoundPlayer player = Dali::SoundPlayer( new SoundPlayer() );
42 static Dali::SoundPlayer Get()
44 Dali::SoundPlayer player;
46 Dali::SingletonService service( Dali::SingletonService::Get() );
49 // Check whether the singleton is already created
50 Dali::BaseHandle handle = service.GetSingleton( typeid( Dali::SoundPlayer ) );
53 // If so, downcast the handle
54 player = Dali::SoundPlayer( dynamic_cast< SoundPlayer* >( handle.GetObjectPtr() ) );
58 player = Dali::SoundPlayer( New() );
59 service.Register( typeid( player ), player );
65 int PlaySound(const std::string fileName)
79 virtual ~SoundPlayer()
83 SoundPlayer(const SoundPlayer&);
84 SoundPlayer& operator=(SoundPlayer&);
87 } // Adaptor namespace
88 } // Internal namespace
90 inline Internal::Adaptor::SoundPlayer& GetImplementation(Dali::SoundPlayer& player)
92 DALI_ASSERT_ALWAYS( player && "SoundPlayer handle is empty" );
93 BaseObject& handle = player.GetBaseObject();
94 return static_cast<Internal::Adaptor::SoundPlayer&>(handle);
97 inline const Internal::Adaptor::SoundPlayer& GetImplementation(const Dali::SoundPlayer& player)
99 DALI_ASSERT_ALWAYS( player && "SoundPlayer handle is empty" );
100 const BaseObject& handle = player.GetBaseObject();
101 return static_cast<const Internal::Adaptor::SoundPlayer&>(handle);
104 SoundPlayer SoundPlayer::Get()
106 return Internal::Adaptor::SoundPlayer::Get();
109 SoundPlayer::SoundPlayer()
113 SoundPlayer::SoundPlayer(Internal::Adaptor::SoundPlayer*player)
118 SoundPlayer::~SoundPlayer()
122 int SoundPlayer::PlaySound(const std::string fileName)
124 return GetImplementation(*this).PlaySound(fileName);