Tizen 2.0 Release
[framework/osp/media.git] / src / FMedia_AudioRecorderEvent.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 /**
19  * @file                        FMedia_AudioRecorderEvent.cpp
20  * @brief                       This file contains the event processing for AudioRecorder
21  */
22
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"
29
30 using namespace Tizen::Base;
31
32 namespace Tizen { namespace Media
33 {
34
35 _AudioRecorderEvent::_AudioRecorderEvent(void)
36         : __pAudioRecorderImpl(null)
37 {
38
39 }
40
41 _AudioRecorderEvent::~_AudioRecorderEvent(void)
42 {
43
44 }
45
46 result
47 _AudioRecorderEvent::Construct(_AudioRecorderImpl& audioRecorderImpl)
48 {
49         result r = E_SUCCESS;
50
51         __pAudioRecorderImpl = &audioRecorderImpl;
52         r = _Event::Initialize();
53         return r;
54 }
55
56 result
57 _AudioRecorderEvent::SendEvent(_RecorderEventType event, RecorderErrorReason err, result res)
58 {
59         result r = E_SUCCESS;
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.");
62
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));
68
69         // In case of success, event argument should be released for Base::Event to use the argument continuously.
70         pRecorderEventArg.release();
71         return r;
72 }
73
74 void
75 _AudioRecorderEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
76 {
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.");
79
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.");
83
84         switch (pArg->GetEventType())
85         {
86         case _RECORDER_EVENT_ERROR:
87         {
88                 __pAudioRecorderImpl->SetState(RECORDER_STATE_ERROR);
89                 pAudioRecorderEventListener->OnAudioRecorderErrorOccurred(pArg->GetError());
90         }
91         break;
92
93         case _RECORDER_EVENT_RECORDING_STARTED:
94         {
95                 __pAudioRecorderImpl->SetState(RECORDER_STATE_RECORDING);
96                 pAudioRecorderEventListener->OnAudioRecorderStarted(pArg->GetResult());
97         }
98         break;
99
100         case _RECORDER_EVENT_STOPPED:
101         {
102                 __pAudioRecorderImpl->SetState(RECORDER_STATE_STOPPED);
103                 pAudioRecorderEventListener->OnAudioRecorderStopped(pArg->GetResult());
104         }
105         break;
106
107         case _RECORDER_EVENT_CANCELED:
108         {
109                 __pAudioRecorderImpl->SetState(RECORDER_STATE_STOPPED);
110                 pAudioRecorderEventListener->OnAudioRecorderCanceled(pArg->GetResult());
111         }
112         break;
113
114         case _RECORDER_EVENT_ENDOF_FILESIZE:
115         {
116                 __pAudioRecorderImpl->SetState(RECORDER_STATE_ENDOF_FILE);
117                 pAudioRecorderEventListener->OnAudioRecorderEndReached(RECORDING_ENDOF_MAX_TIME);
118         }
119         break;
120
121         case _RECORDER_EVENT_ENDOF_RECTIME:
122         {
123                 __pAudioRecorderImpl->SetState(RECORDER_STATE_ENDOF_FILE);
124                 pAudioRecorderEventListener->OnAudioRecorderEndReached(RECORDING_ENDOF_MAX_TIME);
125         }
126         break;
127
128         case _RECORDER_EVENT_PAUSED:
129         {
130                 __pAudioRecorderImpl->SetState(RECORDER_STATE_PAUSED);
131                 pAudioRecorderEventListener->OnAudioRecorderPaused(pArg->GetResult());
132         }
133         break;
134
135         case _RECORDER_EVENT_CLOSED:
136         {
137                 __pAudioRecorderImpl->SetState(RECORDER_STATE_CLOSED);
138                 pAudioRecorderEventListener->OnAudioRecorderClosed(pArg->GetResult());
139         }
140         break;
141
142         default:
143                 break;
144
145         }
146 }
147
148 }}
149