Tizen 2.0 Release
[framework/osp/media.git] / src / FMedia_AudioSessionEvent.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <FBaseRtThread.h>
19 #include <FBaseRtIEventListener.h>
20 #include <FBaseSysLog.h>
21 #include <FBaseRtIEventArg.h>
22 #include "FMedia_AudioSessionEvent.h"
23 #include "FMedia_AudioSessionEventArg.h"
24
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Runtime;
27
28 namespace Tizen { namespace Media
29 {
30
31 _AudioSessionEvent::_AudioSessionEvent(void)
32         :__pListener(null)
33 {
34 }
35
36 _AudioSessionEvent::~_AudioSessionEvent(void)
37 {
38 }
39
40 result
41 _AudioSessionEvent::Construct(void)
42 {
43         result r = E_SUCCESS;
44         __pListener = null;
45
46         r = _Event::Initialize();
47         SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
48         return r;
49 }
50
51
52 void
53 _AudioSessionEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
54 {
55         IAudioSessionEventListener *pAudioSessionEventListener = dynamic_cast<IAudioSessionEventListener*> (&listener);
56         SysTryReturn(NID_MEDIA, pAudioSessionEventListener, , E_SYSTEM, "[E_SYSTEM] A system error has been occureed. The value of listener is null.");
57
58         __pListener = pAudioSessionEventListener;
59
60         const Tizen::Base::Runtime::IEventArg* pTempArg = const_cast <const Tizen::Base::Runtime::IEventArg*>(&arg);
61
62         _AudioSessionEventArg *pArg = (_AudioSessionEventArg*) pTempArg;
63
64         switch (pArg->GetEventType())
65         {
66         case _AUDIO_SESSION_EVENT_INTERRUPTED:
67                 pAudioSessionEventListener->OnAudioSessionInterrupted();
68                 break;
69         case _AUDIO_SESSION_EVENT_RELEASED:
70                 pAudioSessionEventListener->OnAudioSessionInterruptReleased();
71                 break;
72         case _AUDIO_SESSION_EVENT_AUDIO_FOCUS_CHANGED:
73                 pAudioSessionEventListener->OnAudioSessionAudioFocusChanged();
74                 break;
75         default:
76                 SysTryLog(NID_MEDIA, false, "The event type is wrong.");
77                 break;
78         }
79 }
80 };
81 };