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 <unique_ptr.h>
26 #include <FBaseRtIEventListener.h>
27 #include <FNetWifiIWifiDirectDeviceListener.h>
28 #include <FBaseColIList.h>
29 #include <FBaseString.h>
30 #include <FNetWifiWifiDirectGroupMember.h>
31 #include <FNetWifiWifiDirectDeviceInfo.h>
32 #include <FNetWifiWifiDirectGroupInfo.h>
33 #include <FBaseSysLog.h>
34 #include "FNetWifi_WifiDirectDeviceImpl.h"
35 #include "FNetWifi_WifiDirectDeviceEvent.h"
36 #include "FNetWifi_WifiDirectEventArg.h"
39 using namespace Tizen::Base::Collection;
40 using namespace Tizen::Base;
42 namespace Tizen { namespace Net { namespace Wifi
45 _WifiDirectDeviceEvent::_WifiDirectDeviceEvent(_WifiDirectDeviceImpl* pWifiDirectDeviceImpl)
47 __pWifiDirectDeviceImpl = pWifiDirectDeviceImpl;
50 _WifiDirectDeviceEvent::~_WifiDirectDeviceEvent(void)
55 _WifiDirectDeviceEvent::_WifiDirectDeviceEvent(void)
56 : __pWifiDirectDeviceImpl(null)
62 _WifiDirectDeviceEvent::Construct(void)
64 return _Event::Initialize();
68 _WifiDirectDeviceEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
70 const _WifiDirectEventArg* pArg = dynamic_cast< const _WifiDirectEventArg* >(&arg);
71 SysTryReturnVoidResult(NID_NET_WIFI, pArg != null, E_INVALID_ARG, "[E_INVALID_ARG] The argument is a null pointer.");
73 IWifiDirectDeviceListener* pDeviceListener = dynamic_cast< IWifiDirectDeviceListener* >(&listener);
74 SysTryReturnVoidResult(NID_NET_WIFI, pDeviceListener != null, E_INVALID_ARG,
75 "[E_INVALID_ARG] The result of a dynamic_cast operation is null for external Device listener.");
77 _WifiDirectEventType eventType = pArg->GetEventType();
78 WifiDirectDeviceId localDeviceId = pArg->GetDeviceId();
79 result r = pArg->GetError();
83 case WIFI_DIRECT_DEVICE_EVENT_ACTIVATED:
84 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_ACTIVATED) : %s", GetErrorMessage(r));
85 pDeviceListener->OnWifiDirectDeviceActivated(localDeviceId, r);
88 case WIFI_DIRECT_DEVICE_EVENT_DEACTIVATED:
89 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_DEACTIVATED) : %s", GetErrorMessage(r));
90 pDeviceListener->OnWifiDirectDeviceDeactivated(localDeviceId, r);
93 case WIFI_DIRECT_DEVICE_EVENT_GROUP_CREATED:
94 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_GROUP_CREATED) : %s", GetErrorMessage(r));
96 WifiDirectGroupInfo* pGroupInfo = pArg->GetGroupInfo();
97 WifiDirectDeviceInfo* pGroupOwnerInfo = pArg->GetDeviceInfo();
98 WifiDirectGroupMember* pGroupMember = pArg->GetGroupMember();
99 pDeviceListener->OnWifiDirectGroupCreatedN(localDeviceId, *pGroupInfo, *pGroupOwnerInfo, pGroupMember, r);
102 case WIFI_DIRECT_DEVICE_EVENT_SCAN_FOUND:
103 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_SCAN_FOUND)");
105 WifiDirectDeviceInfo* pDeviceInfo = pArg->GetDeviceInfo();
106 pDeviceListener->OnWifiDirectRemoteDeviceFound(localDeviceId, *pDeviceInfo);
109 case WIFI_DIRECT_DEVICE_EVENT_SCAN_COMPLETED:
110 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_SCAN_COMPLETED) : %s", GetErrorMessage(r));
114 unique_ptr<ArrayList> pDeviceInfoList(new (std::nothrow) ArrayList(SingleObjectDeleter));
116 if (pDeviceInfoList == null)
118 SysLogException(NID_NET_WIFI, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
119 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, null, E_SYSTEM);
123 for (int i = 0 ; i < pArg->GetDeviceInfoList()->GetCount() ; i++)
125 WifiDirectDeviceInfo* pDeviceInfo = new (std::nothrow) WifiDirectDeviceInfo(*static_cast<WifiDirectDeviceInfo*>(pArg->GetDeviceInfoList()->GetAt(i)));
126 if (pDeviceInfo == null)
128 SysLogException(NID_NET_WIFI, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
129 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, null, E_SYSTEM);
132 result res = pDeviceInfoList->Add(*pDeviceInfo);
136 SysLogException(NID_NET_WIFI, E_SYSTEM, "[E_SYSTEM] Failed to create list of scan result.");
137 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, null, E_SYSTEM);
142 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, pDeviceInfoList.release(), r);
147 pDeviceListener->OnWifiDirectScanCompletedN(localDeviceId, null, r);
152 case WIFI_DIRECT_DEVICE_EVENT_ASSOCIATED:
153 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_ASSOCIATED) : %s", GetErrorMessage(r));
155 WifiDirectDeviceInfo* pGroupOwnerInfo = pArg->GetDeviceInfo();
156 if (pGroupOwnerInfo == null)
158 pDeviceListener->OnWifiDirectAssociationCompleted(localDeviceId, WifiDirectDeviceInfo(), r);
162 pDeviceListener->OnWifiDirectAssociationCompleted(localDeviceId, *pGroupOwnerInfo, r);
167 case WIFI_DIRECT_DEVICE_EVENT_CONNECTED:
168 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_CONNECTED) : %s", GetErrorMessage(r));
170 WifiDirectDeviceInfo* pDeviceInfo = pArg->GetDeviceInfo();
171 if (pDeviceInfo == null)
173 pDeviceListener->OnWifiDirectConnected(localDeviceId, WifiDirectDeviceInfo(), r);
177 pDeviceListener->OnWifiDirectConnected(localDeviceId, *pDeviceInfo, r);
182 case WIFI_DIRECT_DEVICE_EVENT_DISCONNECTED:
184 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_DISCONNECTED) : %s", GetErrorMessage(r));
185 String macAddress = pArg->GetMacAddress();
186 pDeviceListener->OnWifiDirectDisconnected(localDeviceId, macAddress, r);
190 case WIFI_DIRECT_DEVICE_EVENT_AUTONOMOS_GROUP_CREATED:
191 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_AUTONOMOS_GROUP_CREATED) : %s", GetErrorMessage(r));
192 pDeviceListener->OnWifiDirectAutonomousGroupCreated(localDeviceId, r);
195 case WIFI_DIRECT_DEVICE_EVENT_GROUP_LEFT:
196 SysLog(NID_NET_WIFI, "Firing External Event (Type: WIFI_DIRECT_DEVICE_EVENT_GROUP_LEFT) : %s", GetErrorMessage(r));
197 pDeviceListener->OnWifiDirectGroupLeft(localDeviceId, r);
201 SysLog(NID_NET_WIFI, "An undefined external WifiDirectDevice event occurs. (Type: %d)", eventType);
207 } } } // Tizen::Net::Wifi