sync with tizen_2.0
[platform/framework/native/appfw.git] / src / app / FApp_AppManagerEvent.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         FApp_AppManagerEvent.cpp
20  * @brief       This is the implementation for the _AppManagerEvent.cpp class.
21  */
22
23 #include <FBaseSysLog.h>
24
25 #include "FApp_Types.h"
26 #include "FApp_AppManagerEvent.h"
27 #include "FApp_AppManagerEventArg.h"
28 #include "FApp_IAppManagerEventListener.h"
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Runtime;
32
33
34 namespace Tizen { namespace App
35 {
36
37 _AppManagerEventArg::_AppManagerEventArg(void)
38         : __appType(_APP_TYPE_UI_APP)
39         , __eventType(_AppManagerEvent::_APP_MANAGER_EVENT_INVALID)
40 {
41 }
42
43 _AppManagerEventArg::_AppManagerEventArg(const AppId& appId, _AppType appType, _AppManagerEvent::_Type eventType)
44         : __appId(appId)
45         , __appType(appType)
46         , __eventType(eventType)
47 {
48 }
49
50 _AppManagerEventArg::_AppManagerEventArg(const _AppManagerEventArg& value)
51 {
52 //      *this = value;
53         __appId = value.__appId;
54         __appType = value.__appType;
55         __eventType = value.__eventType;
56 }
57
58 _AppManagerEventArg::~_AppManagerEventArg(void)
59 {
60 }
61
62 const AppId
63 _AppManagerEventArg::GetAppId(void) const
64 {
65         return __appId;
66 }
67
68 _AppType
69 _AppManagerEventArg::GetAppType(void) const
70 {
71         return __appType;
72 }
73
74 _AppManagerEvent::_Type
75 _AppManagerEventArg::GetEventType(void) const
76 {
77         return __eventType;
78 }
79
80 _AppManagerEventArg&
81 _AppManagerEventArg::operator =(const _AppManagerEventArg& source)
82 {
83         if (&source == this)
84         {
85                 return *this;
86         }
87
88         __appId = source.__appId;
89         __appType = source.__appType;
90         __eventType = source.__eventType;
91
92         return *this;
93 }
94
95
96 ///////////////////////////////////////////////////////
97 //_AppManagerEvent
98 ///////////////////////////////////////////////////////
99 result
100 _AppManagerEvent::Construct(void)
101 {
102         return _Event::Initialize();
103 }
104
105 void
106 _AppManagerEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
107 {
108         _IAppManagerEventListener* pListener = dynamic_cast<_IAppManagerEventListener*>(&listener);
109         SysTryReturnVoidResult(NID_APP, pListener != null, E_INVALID_STATE, "Invalid listener : listener(0x%x), arg(0x%x)", &listener, &arg);
110
111         const _AppManagerEventArg* pEventArg = dynamic_cast<const _AppManagerEventArg*>(&arg);
112         SysTryReturnVoidResult(NID_APP, pEventArg != null, E_INVALID_STATE, "Invalid arg : listener(0x%x), arg(0x%x)", &listener, &arg);
113
114         switch (pEventArg->GetEventType())
115         {
116         case _APP_MANAGER_EVENT_LAUNCHED:
117                 pListener->OnApplicationLaunched(pEventArg->GetAppId(), pEventArg->GetAppType());
118                 break;
119
120         case _APP_MANAGER_EVENT_TERMINATED:
121                 pListener->OnApplicationTerminated(pEventArg->GetAppId(), pEventArg->GetAppType());
122                 break;
123
124         default:
125                 SysLog(NID_APP, "Invalid event type(%d)!!", pEventArg->GetEventType());
126                 break;
127         }
128 }
129
130 } } // Tizen::App