Fix the boiler plate codes
[platform/framework/native/appfw.git] / src / base / runtime / FBaseRt_EventDrivenThreadEvent.cpp
1 //
2 // Copyright (c) 2012 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  * @file        FBaseRt_EventDrivenThreadEvent.cpp
19  * @brief       This is the implementation file for the _EventDrivenThreadEvent class.
20  *
21  */
22
23
24 #include <FBaseSysLog.h>
25 #include "FBaseRt_EventDrivenThreadEvent.h"
26 #include "FBaseRt_EventDrivenThreadEventArg.h"
27 #include "FBaseRt_IEventDrivenThreadEventListener.h"
28
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Base::Runtime;
33
34 namespace Tizen { namespace Base { namespace Runtime
35 {
36
37 _EventDrivenThreadEvent::_EventDrivenThreadEvent(void)
38 {
39
40 }
41
42 _EventDrivenThreadEvent::~_EventDrivenThreadEvent(void)
43 {
44
45 }
46
47 result
48 _EventDrivenThreadEvent::Construct(_IEventDrivenThreadEventListener& listener)
49 {
50         result r = E_SUCCESS;
51
52         r = Initialize();
53         SysTryReturn(NID_BASE_RT, !IsFailed(r), r, r, "[%s] Failed to initialize.", GetErrorMessage(r));
54
55         r = AddListener(listener);
56         SysTryReturn(NID_BASE_RT, !IsFailed(r), r, r, "[%s] Failed add listener.", GetErrorMessage(r));
57
58         return r;
59 }
60
61 void
62 _EventDrivenThreadEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
63 {
64         _IEventDrivenThreadEventListener* pEventDrivenThreadEventListener =
65                 dynamic_cast <_IEventDrivenThreadEventListener*>(&listener);
66         const _EventDrivenThreadEventArg* pEventDrivenThreadEventArg = dynamic_cast <const _EventDrivenThreadEventArg*>(&arg);
67         SysTryReturnVoidResult(NID_BASE_RT, pEventDrivenThreadEventListener != null && pEventDrivenThreadEventArg != null, E_INVALID_ARG,
68                                         "[%s] listener or agr is null.",
69                                         GetErrorMessage(E_INVALID_ARG));
70
71         if (pEventDrivenThreadEventArg->GetType() == EVENT_DRIVEN_THREAD_EVENT_TYPE_USER_EVENT)
72         {
73                 pEventDrivenThreadEventListener->OnUserEventReceivedN(
74                         pEventDrivenThreadEventArg->GetRequestId(), pEventDrivenThreadEventArg->GetArgs());
75         }
76         else
77         {
78                 pEventDrivenThreadEventListener->OnStop();
79         }
80 }
81
82 } } } // Tizen::Base::Runtime