merge with master
[framework/osp/net.git] / src / wifi / FNetWifiWifiDirectDeviceManager.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 /**
19  * @file        FNetWifiWifiDirectDeviceManager.cpp
20  * @brief       This is the implementation file for the WifiDirectDeviceManager
21  *              Class.
22  *
23  * This file contains implementation of the WifiDirectDeviceManager Class.
24  */
25
26 #include <FNetWifiWifiDirectDeviceManager.h>
27 #include <FNetWifiWifiDirectDeviceInfo.h>
28 #include <FNetWifiWifiDirectDevice.h>
29 #include <FBaseColArrayList.h>
30 #include <FBaseString.h>
31 #include <FBaseSysLog.h>
32 #include "FSys_SystemInfoImpl.h"
33 #include "FNetWifi_WifiDirectDeviceManagerImpl.h"
34
35 static const wchar_t* _WIFI_DIRECT_FEATURE_INFO_KEY = L"http://tizen.org/feature/network.wifi.direct";
36
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::System;
40
41 namespace Tizen { namespace Net { namespace Wifi {
42
43 WifiDirectDeviceManager::WifiDirectDeviceManager(void)
44     : __pWifiDirectDeviceManagerImpl(null)
45 {
46 }
47
48 WifiDirectDeviceManager::~WifiDirectDeviceManager(void)
49 {
50     if (__pWifiDirectDeviceManagerImpl != null)
51     {
52         delete __pWifiDirectDeviceManagerImpl;
53         __pWifiDirectDeviceManagerImpl = null;
54     }
55 }
56
57 IList*
58 WifiDirectDeviceManager::GetAllDeviceInfoN(void)
59 {
60     bool isWifiDirectSupported = false;
61     IList* pList = null;
62     result r = _SystemInfoImpl::GetSysInfo(_WIFI_DIRECT_FEATURE_INFO_KEY, isWifiDirectSupported);
63
64     SysTryReturn(NID_NET_WIFI, r == E_SUCCESS && isWifiDirectSupported == true, null, E_UNSUPPORTED_OPERATION,
65             "[E_UNSUPPORTED_OPERATION] No WifiDirectDeviceInfo available since the device don't support the Wi-Fi Direct.");
66
67     pList = _WifiDirectDeviceManagerImpl::GetAllDeviceInfoN();
68     r = GetLastResult();
69
70     if (pList == null)
71     {
72         SysLogException(NID_NET_WIFI, r, "[%s] Propagating.", GetErrorMessage(r));
73     }
74
75     return pList;
76 }
77
78 WifiDirectDevice*
79 WifiDirectDeviceManager::GetWifiDirectDeviceN(const WifiDirectDeviceInfo* pLocalDeviceInfo)
80 {
81     bool isWifiDirectSupported = false;
82     WifiDirectDevice* pWifiDirectDevice = null;
83     result r = _SystemInfoImpl::GetSysInfo(_WIFI_DIRECT_FEATURE_INFO_KEY, isWifiDirectSupported);
84
85     SysTryReturn(NID_NET_WIFI, r == E_SUCCESS && isWifiDirectSupported == true, null, E_UNSUPPORTED_OPERATION,
86             "[E_UNSUPPORTED_OPERATION] No WifiDirectDeviceInfo available since the device don't support the Wi-Fi Direct.");
87
88     pWifiDirectDevice = _WifiDirectDeviceManagerImpl::GetWifiDirectDeviceN(pLocalDeviceInfo);
89     r = GetLastResult();
90
91     if (pWifiDirectDevice == null)
92     {
93         SysLogException(NID_NET_WIFI, r, "[%s] Propagating.", GetErrorMessage(r));
94     }
95
96     return pWifiDirectDevice;
97 }
98
99 }}}// Tizen::Net::Wifi