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