modify license, permission and remove ^M char
[platform/framework/native/uifw.git] / src / ui / FUi_ActiveWindowEvent.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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  * @file        FUi_ActiveWindowEvent.cpp
19  * @brief       This is the implementation for the _ActiveWindowEvent class.
20  * @since       2.0
21  */
22 #include <new>
23 #include <FBaseErrors.h>
24 #include <FBaseSysLog.h>
25 #include "FUi_ActiveWindowEvent.h"
26
27 using namespace Tizen::Base;
28 using namespace Tizen::Base::Runtime;
29 using namespace Tizen::App;
30
31 namespace Tizen { namespace Ui
32 {
33
34 class _ActiveWindowEventArg
35         : public Tizen::Base::Runtime::IEventArg
36         , public Tizen::Base::Object
37 {
38 public:
39         _ActiveWindowEventArg(unsigned int xid, int pid, char* pAppName);
40
41         virtual ~_ActiveWindowEventArg(void);
42
43         unsigned int GetWindowId(void) const;
44         int GetProcessId(void) const;
45         char* GetAppName(void) const;
46
47 private:
48         _ActiveWindowEventArg(const _ActiveWindowEventArg& rhs);
49         _ActiveWindowEventArg& operator =(const _ActiveWindowEventArg& rhs);
50
51 private:
52         unsigned int __xid;
53         int __pid;
54         char* __pAppName;
55 }; // _ActiveWindowEventArg
56
57 _ActiveWindowEventArg::_ActiveWindowEventArg(unsigned int xid, int pid, char* pAppName)
58         : __xid(xid)
59         , __pid(pid)
60         , __pAppName(pAppName)
61 {
62 }
63
64 _ActiveWindowEventArg::~_ActiveWindowEventArg(void)
65 {
66 }
67
68 unsigned int
69 _ActiveWindowEventArg::GetWindowId(void) const
70 {
71         return __xid;
72 }
73
74 int
75 _ActiveWindowEventArg::GetProcessId(void) const
76 {
77         return __pid;
78 }
79
80 char*
81 _ActiveWindowEventArg::GetAppName(void) const
82 {
83         return __pAppName;
84 }
85
86 _ActiveWindowEvent*
87 _ActiveWindowEvent::CreateInstanceN(void)
88 {
89         _ActiveWindowEvent* pActiveWindowEvent = new (std::nothrow) _ActiveWindowEvent();
90         SysTryReturn(NID_UI, pActiveWindowEvent, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
91
92         result r = GetLastResult();
93         SysTryCatch(NID_UI, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
94
95         SetLastResult(E_SUCCESS);
96
97         return pActiveWindowEvent;
98
99 CATCH:
100         delete pActiveWindowEvent;
101         return null;
102 }
103
104 IEventArg*
105 _ActiveWindowEvent::CreateActiveWindowEventArgN(unsigned int xid, int pid, char* pAppName)
106 {
107         _ActiveWindowEventArg* pEventArg = new (std::nothrow) _ActiveWindowEventArg(xid, pid, pAppName);
108         SysTryReturn(NID_UI, pEventArg, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
109
110         SetLastResult(E_SUCCESS);
111
112         return pEventArg;
113 }
114
115 _ActiveWindowEvent::~_ActiveWindowEvent(void)
116 {
117 }
118
119 void
120 _ActiveWindowEvent::FireImpl(IEventListener& listener, const IEventArg& arg)
121 {
122         _IActiveWindowEventListener* pEventListener = dynamic_cast <_IActiveWindowEventListener*>(&listener);
123         SysTryReturnVoidResult(NID_UI, pEventListener, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
124
125         const _ActiveWindowEventArg* pArg = dynamic_cast <const _ActiveWindowEventArg*>(&arg);
126         SysTryReturnVoidResult(NID_UI, pArg, E_INVALID_ARG, "[E_INVALID_ARG] A specified input parameter is invalid.");
127
128         pEventListener->OnActiveWindowChanged(pArg->GetWindowId(), pArg->GetProcessId(), pArg->GetAppName());
129
130         SetLastResult(E_SUCCESS);
131 }
132
133 _ActiveWindowEvent::_ActiveWindowEvent(void)
134 {
135         result r = _Event::Initialize();
136         SysTryReturnVoidResult(NID_UI, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
137
138         SetLastResult(E_SUCCESS);
139 }
140
141 }} // Tizen::Ui