2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FMedia_AudioRecorderEvent.cpp
20 * @brief This file contains the event processing for AudioRecorder
23 #include <unique_ptr.h>
24 #include <FMediaIAudioRecorderEventListener.h>
25 #include <FBaseSysLog.h>
26 #include "FMedia_AudioRecorderEvent.h"
27 #include "FMedia_RecorderEventArg.h"
28 #include "FMedia_AudioRecorderImpl.h"
30 using namespace Tizen::Base;
32 namespace Tizen { namespace Media
35 _AudioRecorderEvent::_AudioRecorderEvent(void)
36 : __pAudioRecorderImpl(null)
41 _AudioRecorderEvent::~_AudioRecorderEvent(void)
47 _AudioRecorderEvent::Construct(_AudioRecorderImpl& audioRecorderImpl)
51 __pAudioRecorderImpl = &audioRecorderImpl;
52 r = _Event::Initialize();
57 _AudioRecorderEvent::SendEvent(_RecorderEventType event, RecorderErrorReason err, result res)
60 std::unique_ptr <_RecorderEventArg> pRecorderEventArg (new (std::nothrow) _RecorderEventArg());
61 SysTryReturn(NID_MEDIA, pRecorderEventArg.get() != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
63 pRecorderEventArg->SetEventType(event);
64 pRecorderEventArg->SetResult(res);
65 pRecorderEventArg->SetError(err);
66 r = FireAsync(*(pRecorderEventArg.get()));
67 SysTryReturn(NID_MEDIA, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
69 // In case of success, event argument should be released for Base::Event to use the argument continuously.
70 pRecorderEventArg.release();
75 _AudioRecorderEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
77 IAudioRecorderEventListener* pAudioRecorderEventListener = dynamic_cast <IAudioRecorderEventListener*>(&listener);
78 SysTryReturn(NID_MEDIA, pAudioRecorderEventListener != null, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. Listener is null.");
80 Tizen::Base::Runtime::IEventArg* pTtempArg = const_cast <Tizen::Base::Runtime::IEventArg*>(&arg);
81 _RecorderEventArg* pArg = dynamic_cast <_RecorderEventArg*>(pTtempArg);
82 SysTryReturn(NID_MEDIA, pArg != null, , E_SYSTEM, "[E_SYSTEM] A system error has been occurred. EventArg is null.");
84 switch (pArg->GetEventType())
86 case _RECORDER_EVENT_ERROR:
88 __pAudioRecorderImpl->SetState(RECORDER_STATE_ERROR);
89 pAudioRecorderEventListener->OnAudioRecorderErrorOccurred(pArg->GetError());
93 case _RECORDER_EVENT_RECORDING_STARTED:
95 __pAudioRecorderImpl->SetState(RECORDER_STATE_RECORDING);
96 pAudioRecorderEventListener->OnAudioRecorderStarted(pArg->GetResult());
100 case _RECORDER_EVENT_STOPPED:
102 __pAudioRecorderImpl->SetState(RECORDER_STATE_STOPPED);
103 pAudioRecorderEventListener->OnAudioRecorderStopped(pArg->GetResult());
107 case _RECORDER_EVENT_CANCELED:
109 __pAudioRecorderImpl->SetState(RECORDER_STATE_STOPPED);
110 pAudioRecorderEventListener->OnAudioRecorderCanceled(pArg->GetResult());
114 case _RECORDER_EVENT_ENDOF_FILESIZE:
116 __pAudioRecorderImpl->SetState(RECORDER_STATE_ENDOF_FILE);
117 pAudioRecorderEventListener->OnAudioRecorderEndReached(RECORDING_ENDOF_MAX_TIME);
121 case _RECORDER_EVENT_ENDOF_RECTIME:
123 __pAudioRecorderImpl->SetState(RECORDER_STATE_ENDOF_FILE);
124 pAudioRecorderEventListener->OnAudioRecorderEndReached(RECORDING_ENDOF_MAX_TIME);
128 case _RECORDER_EVENT_PAUSED:
130 __pAudioRecorderImpl->SetState(RECORDER_STATE_PAUSED);
131 pAudioRecorderEventListener->OnAudioRecorderPaused(pArg->GetResult());
135 case _RECORDER_EVENT_CLOSED:
137 __pAudioRecorderImpl->SetState(RECORDER_STATE_CLOSED);
138 pAudioRecorderEventListener->OnAudioRecorderClosed(pArg->GetResult());