2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FNetWifi_WifiDirectDeviceEvent.cpp
20 * @brief This is the implementation file for the _WifiDirectDeviceEvent Class.
22 * This header file contains implementation of the _WifiDirectDeviceEvent Class.
25 #include <FBaseRtIEventListener.h>
26 #include <FNetWifiIWifiDirectDeviceListener.h>
27 #include <FBaseColIList.h>
28 #include <FBaseString.h>
29 #include <FNetWifiWifiDirectGroupMember.h>
30 #include <FNetWifiWifiDirectDeviceInfo.h>
31 #include <FNetWifiWifiDirectGroupInfo.h>
32 #include <FBaseSysLog.h>
33 #include "FNetWifi_WifiDirectDeviceImpl.h"
34 #include "FNetWifi_WifiDirectDeviceEvent.h"
35 #include "FNetWifi_WifiDirectEventArg.h"
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Base;
40 namespace Tizen { namespace Net { namespace Wifi
43 ////////////////////////////////////////////////////////////////////////////
44 _WifiDirectDeviceEvent::_WifiDirectDeviceEvent(_WifiDirectDeviceImpl* pWifiDirectDeviceImpl)
46 __pWifiDirectDeviceImpl = pWifiDirectDeviceImpl;
49 _WifiDirectDeviceEvent::~_WifiDirectDeviceEvent(void)
54 _WifiDirectDeviceEvent::_WifiDirectDeviceEvent(void)
55 : __pWifiDirectDeviceImpl(null)
61 _WifiDirectDeviceEvent::Construct(void)
63 return _Event::Initialize();
66 ////////////////////////////////////////////////////////////////////////////////
67 /// Operation : Protected
70 _WifiDirectDeviceEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
72 const _WifiDirectEventArg* pArg = dynamic_cast< const _WifiDirectEventArg* >(&arg);
73 SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is a null pointer.");
75 IWifiDirectDeviceListener* pDeviceListener = dynamic_cast< IWifiDirectDeviceListener* >(&listener);
76 SysTryReturnVoidResult(NID_NET_WIFI, pDeviceListener != null, E_INVALID_ARG,
77 "[E_INVALID_ARG] The result of a dynamic_cast operation is null for external Device listener.");
79 _WifiDirectEventType eventType = pArg->GetEventType();
80 WifiDirectDeviceId localDeviceId = pArg->GetDeviceId();
81 result r = pArg->GetError();
85 case WIFI_DIRECT_DEVICE_EVENT_ACTIVATED:
86 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_ACTIVATED) : %s", GetErrorMessage(r));
87 pDeviceListener->OnWifiDirectDeviceActivated(localDeviceId, r);
90 case WIFI_DIRECT_DEVICE_EVENT_DEACTIVATED:
91 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_DEACTIVATED) : %s", GetErrorMessage(r));
92 pDeviceListener->OnWifiDirectDeviceDeactivated(localDeviceId, r);
95 case WIFI_DIRECT_DEVICE_EVENT_GROUP_CREATED:
96 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_GROUP_CREATED) : %s", GetErrorMessage(r));
98 WifiDirectGroupInfo* pGroupInfo = pArg->GetGroupInfo();
99 WifiDirectDeviceInfo* pGroupOwnerInfo = pArg->GetDeviceInfo();
100 WifiDirectGroupMember* pGroupMember = pArg->GetGroupMember();
101 pDeviceListener->OnWifiDirectGroupCreatedN(localDeviceId, *pGroupInfo, *pGroupOwnerInfo, pGroupMember, r);
104 case WIFI_DIRECT_DEVICE_EVENT_SCAN_FOUND:
105 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_SCAN_FOUND)");
107 WifiDirectDeviceInfo* pDeviceInfo = pArg->GetDeviceInfo();
108 pDeviceListener->OnWifiDirectRemoteDeviceFound(localDeviceId, *pDeviceInfo);
111 case WIFI_DIRECT_DEVICE_EVENT_SCAN_COMPLETED:
112 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_SCAN_COMPLETED) : %s", GetErrorMessage(r));
116 ArrayList* pSrcDeviceInfoList = dynamic_cast< ArrayList* >(pArg->GetDeviceInfoList());
117 if (pSrcDeviceInfoList == null)
119 SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] Failed to dynamic casting DeviceInfo list.");
120 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, null, E_SYSTEM);
124 ArrayList* pDescDeviceInfoList = new (std::nothrow) ArrayList();
125 if (pSrcDeviceInfoList == null)
127 SysLogException(NID_NET_WIFI, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
128 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, null, E_SYSTEM);
132 result res = pDescDeviceInfoList->Construct(*pSrcDeviceInfoList);
136 delete pDescDeviceInfoList;
137 pDescDeviceInfoList = null;
142 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, pDescDeviceInfoList, r);
146 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, null, r);
151 case WIFI_DIRECT_DEVICE_EVENT_ASSOCIATED:
152 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_ASSOCIATED) : %s", GetErrorMessage(r));
154 WifiDirectDeviceInfo* pGroupOwnerInfo = pArg->GetDeviceInfo();
155 if (pGroupOwnerInfo == null)
157 pDeviceListener->OnWifiDirectAssociationCompleted(localDeviceId, WifiDirectDeviceInfo(), r);
161 pDeviceListener->OnWifiDirectAssociationCompleted(localDeviceId, *pGroupOwnerInfo, r);
166 case WIFI_DIRECT_DEVICE_EVENT_CONNECTED:
167 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_CONNECTED) : %s", GetErrorMessage(r));
169 WifiDirectDeviceInfo* pDeviceInfo = pArg->GetDeviceInfo();
170 if (pDeviceInfo == null)
172 pDeviceListener->OnWifiDirectConnected(localDeviceId, WifiDirectDeviceInfo(), r);
176 pDeviceListener->OnWifiDirectConnected(localDeviceId, *pDeviceInfo, r);
181 case WIFI_DIRECT_DEVICE_EVENT_DISCONNECTED:
183 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_DISCONNECTED) : %s", GetErrorMessage(r));
184 String macAddress = pArg->GetMacAddress();
185 pDeviceListener->OnWifiDirectDisconnected(localDeviceId, macAddress, r);
189 case WIFI_DIRECT_DEVICE_EVENT_AUTONOMOS_GROUP_CREATED:
190 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_AUTONOMOS_GROUP_CREATED) : %s", GetErrorMessage(r));
191 pDeviceListener->OnWifiDirectAutonomousGroupCreated(localDeviceId, r);
194 case WIFI_DIRECT_DEVICE_EVENT_GROUP_LEFT:
195 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_GROUP_LEFT) : %s", GetErrorMessage(r));
196 pDeviceListener->OnWifiDirectGroupLeft(localDeviceId, r);
200 SysLog(NID_NET_WIFI, "An undefined external WifiDirectDevice event occurs. (Type: %d)", eventType);
206 } } } // Tizen::Net::Wifi