+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-/**
-* @file FNet_NetAccountDatabase.cpp
-* @brief This is the implementation file for the %_NetAccountDatabase class.
-*
-* This file contains the implementation of the %_NetAccountDatabase class.
-*/
-
-#include <unique_ptr.h>
-#include <FBaseString.h>
-#include <FBaseColIList.h>
-#include <FBaseColIListT.h>
-#include <FIoDatabase.h>
-#include <FIoDbStatement.h>
-#include <FIoDbEnumerator.h>
-#include <FIoDirectory.h>
-#include <FAppApp.h>
-#include <FBaseSysLog.h>
-#include <FApp_AppInfo.h>
-#include "FNet_NetTypes.h"
-#include "FNet_NetUtility.h"
-#include "FNet_NetAccountDatabase.h"
-
-using namespace std;
-using namespace Tizen::App;
-using namespace Tizen::Base;
-using namespace Tizen::Base::Collection;
-using namespace Tizen::Io;
-
-namespace Tizen { namespace Net {
-
-result
-_NetAccountDatabase::InitializeRepository(void)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_CREATE_TABLE_STATEMENT[] =
- L"CREATE TABLE IF NOT EXISTS NetAccountTable (accountId INTEGER UNIQUE, accountName TEXT(256) UNIQUE, profileName TEXT(256) UNIQUE, isReadOnly INTEGER)";
-
- result r = E_SUCCESS;
- Database accountDb;
-
- if (!Database::Exists(_NetAccountDatabase::GetDbPath()))
- {
- SysLog(NID_NET, "NetAccount database is NOT found, so create it now.");
- }
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), true);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = accountDb.ExecuteSql(String(_NET_ACCOUNT_DATABASE_CREATE_TABLE_STATEMENT), true);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- return r;
-}
-
-result
-_NetAccountDatabase::AddAccount(const String& accountName, const String& profileName, _NetAccountOwner owner, NetAccountId& accountId)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_MAX_ACCOUNT_ID_STATEMENT[] =
- L"SELECT MAX(accountId) FROM NetAccountTable";
- static const wchar_t _NET_ACCOUNT_DATABASE_ADD_ACCOUNT_STATEMENT[] =
- L"INSERT INTO NetAccountTable (accountId, accountName, profileName, isReadOnly) VALUES(?, ?, ?, ?)";
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
- bool isReadOnly = true;
- NetAccountId netAccountId = INVALID_HANDLE;
-
- SysSecureLog(NID_NET, "AddAccount() has been called with accountName:%ls, profileName:%ls, owner:%d",
- accountName.GetPointer(), profileName.GetPointer(), owner);
-
- accountId = INVALID_HANDLE;
-
- SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
- SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- if (owner == _NET_ACCOUNT_OWNER_THIS)
- {
- isReadOnly = false;
- }
- else
- {
- isReadOnly = true;
- }
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_MAX_ACCOUNT_ID_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetIntAt(0, netAccountId);
- break;
- }
- }
-
- if (netAccountId >= _PS_ACCOUNT_ID_START)
- {
- netAccountId++;
- }
- else
- {
- netAccountId = _PS_ACCOUNT_ID_START;
- }
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_ADD_ACCOUNT_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindInt(0, netAccountId);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = pStmt->BindString(1, accountName);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = pStmt->BindString(2, profileName);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = pStmt->BindInt(3, (int)isReadOnly);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- accountId = netAccountId;
-
- return r;
-}
-
-result
-_NetAccountDatabase::RemoveAccountByAccountId(NetAccountId accountId)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_ACCOUNT_ID_STATEMENT[] =
- L"DELETE FROM NetAccountTable WHERE accountId=?";
-
- SysSecureLog(NID_NET, "RemoveAccountByAccountId() has been called with accountId:%d", accountId);
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
-
- SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_ACCOUNT_ID_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindInt(0, accountId);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
-
- return r;
-}
-
-result
-_NetAccountDatabase::RemoveAccountByProfileName(const String& profileName)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_PROFILE_NAME_STATEMENT[] =
- L"DELETE FROM NetAccountTable WHERE profileName=?";
-
- SysLog(NID_NET, "RemoveAccountByProfileName() has been called with profileName:%ls", profileName.GetPointer());
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
-
- SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_REMOVE_ACCOUNT_BY_PROFILE_NAME_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindString(0, profileName);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
-
- return r;
-}
-
-result
-_NetAccountDatabase::UpdateAccountName(NetAccountId accountId, const String& accountName)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_UPDATE_ACCOUNT_NAME_STATEMENT[] =
- L"UPDATE NetAccountTable SET accountName=? WHERE accountId=?";
-
- SysSecureLog(NID_NET, "UpdateAccountName() has been called with accountId:%d, accountName:%ls", accountId, accountName.GetPointer());
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
-
- SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "AccountId[%d] is invalid.", accountId);
- SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_UPDATE_ACCOUNT_NAME_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindString(0, accountName);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = pStmt->BindInt(1, accountId);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
-
- return r;
-}
-
-IListT<NetAccountId>*
-_NetAccountDatabase::GetAccountIdsN(void)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_IDS_STATEMENT[] =
- L"SELECT accountId FROM NetAccountTable";
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
- unique_ptr< ArrayListT<NetAccountId> > pList;
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_IDS_STATEMENT)));
- r = GetLastResult();
- SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pList.reset(new (std::nothrow) ArrayListT<NetAccountId>());
- r = GetLastResult();
- SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Construct();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- NetAccountId accountId = INVALID_HANDLE;
-
- r = pEnum->GetIntAt(0, accountId);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Add(accountId);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
- }
- }
-
- ClearLastResult(); // To suppress E_OUT_OF_RANGE
-
- return pList.release();
-}
-
-IList*
-_NetAccountDatabase::GetAccountNamesN(void)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAMES_STATEMENT[] =
- L"SELECT accountName FROM NetAccountTable";
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
- unique_ptr<ArrayList, _CollectionDeleter> pList;
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAMES_STATEMENT)));
- r = GetLastResult();
- SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pList.reset(new (std::nothrow) ArrayList());
- r = GetLastResult();
- SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Construct();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- unique_ptr<String> pAccountName(new (std::nothrow) String());
- SysTryReturn(NID_NET, pAccountName != null, null, E_OUT_OF_MEMORY,
- "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
- r = pEnum->GetStringAt(0, *pAccountName);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Add(*pAccountName);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pAccountName.release();
- }
- }
-
- ClearLastResult(); // To suppress E_OUT_OF_RANGE
-
- return pList.release();
-}
-
-IList*
-_NetAccountDatabase::GetProfileNamesN(void)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT[] =
- L"SELECT profileName FROM NetAccountTable";
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
- unique_ptr<ArrayList, _CollectionDeleter> pList;
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_PROFILE_NAMES_STATEMENT)));
- r = GetLastResult();
- SysTryReturn(NID_NET, pStmt != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pList.reset(new (std::nothrow) ArrayList());
- r = GetLastResult();
- SysTryReturn(NID_NET, pList != null, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Construct();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- r = GetLastResult();
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- unique_ptr<String> pProfileName(new (std::nothrow) String());
- SysTryReturn(NID_NET, pProfileName != null, null, E_OUT_OF_MEMORY,
- "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
- r = pEnum->GetStringAt(0, *pProfileName);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pList->Add(*pProfileName);
- SysTryReturn(NID_NET, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pProfileName.release();
- }
- }
-
- ClearLastResult(); // To suppress E_OUT_OF_RANGE
-
- return pList.release();
-}
-
-result
-_NetAccountDatabase::GetAccountName(NetAccountId accountId, String& accountName)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAME_STATEMENT[] =
- L"SELECT accountName FROM NetAccountTable WHERE accountId=?";
-
- SysSecureLog(NID_NET, "GetAccountName() has been called with accountId:%d", accountId);
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
-
- SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_NAME_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindInt(0, accountId);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = E_OBJ_NOT_FOUND;
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetStringAt(0, accountName);
- r = E_SUCCESS;
- break;
- }
- }
-
- return r;
-}
-
-result
-_NetAccountDatabase::GetProfileName(NetAccountId accountId, String& profileName)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_PROFILE_NAME_STATEMENT[] =
- L"SELECT profileName FROM NetAccountTable WHERE accountId=?";
-
- SysSecureLog(NID_NET, "GetProfileName() has been called with accountId:%d", accountId);
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
-
- SysTryReturnResult(NID_NET, accountId > 0, E_INVALID_ARG, "Invalid argument is used. accountId=%d", accountId);
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_PROFILE_NAME_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindInt(0, accountId);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = E_OBJ_NOT_FOUND;
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetStringAt(0, profileName);
- r = E_SUCCESS;
- break;
- }
- }
-
- return r;
-}
-
-result
-_NetAccountDatabase::GetAccountIdByAccountName(const String& accountName, NetAccountId& accountId)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_ACCOUNT_NAME_STATEMENT[] =
- L"SELECT accountId FROM NetAccountTable WHERE accountName=?";
-
- SysSecureLog(NID_NET, "GetAccountIdByAccountName() has been called with accountName:%ls", accountName.GetPointer());
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
-
- SysTryReturnResult(NID_NET, !accountName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. accountName is an empty string.");
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_ACCOUNT_NAME_STATEMENT)));
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindString(0, accountName);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = E_OBJ_NOT_FOUND;
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetIntAt(0, accountId);
- r = E_SUCCESS;
- break;
- }
- }
-
- return r;
-}
-
-result
-_NetAccountDatabase::GetAccountIdByProfileName(const String& profileName, NetAccountId& accountId)
-{
- static const wchar_t _NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_PROFILE_NAME_STATEMENT[] =
- L"SELECT accountId FROM NetAccountTable WHERE profileName=?";
-
- SysLog(NID_NET, "GetAccountIdByProfileName() has been called with profileName:%ls", profileName.GetPointer());
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
-
- SysTryReturnResult(NID_NET, !profileName.IsEmpty(), E_INVALID_ARG, "Invalid argument is used. profileName is an empty string.");
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pStmt.reset(accountDb.CreateStatementN(String(_NET_ACCOUNT_DATABASE_GET_ACCOUNT_ID_BY_PROFILE_NAME_STATEMENT)));
- r = GetLastResult();
- SysTryReturnResult(NID_NET, pStmt != null, r, "Propagating.");
-
- r = pStmt->BindString(0, profileName);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- r = E_OBJ_NOT_FOUND;
-
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetIntAt(0, accountId);
- r = E_SUCCESS;
- break;
- }
- }
-
- return r;
-}
-
-bool
-_NetAccountDatabase::IsReadOnly(NetAccountId accountId)
-{
- static const wchar_t NET_ACCOUNT_DATABASE_GET_IS_READ_ONLY_STATEMENT[] =
- L"SELECT isReadOnly FROM NetAccountTable WHERE accountId=?";
-
- SysSecureLog(NID_NET, "IsReadOnly() has been called with accountId:%d", accountId);
-
- result r = E_SUCCESS;
- Database accountDb;
- unique_ptr<DbStatement> pStmt;
- unique_ptr<DbEnumerator> pEnum;
- int isReadOnly = 1;
-
- SysTryReturn(NID_NET, accountId > 0, true, E_INVALID_ARG,
- "[%s] Invalid argument is used. accountId=%d", GetErrorMessage(E_INVALID_ARG), accountId);
-
- r = accountDb.Construct(_NetAccountDatabase::GetDbPath(), false);
- SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
-
- pStmt.reset(accountDb.CreateStatementN(String(NET_ACCOUNT_DATABASE_GET_IS_READ_ONLY_STATEMENT)));
- r = GetLastResult();
- SysTryReturn(NID_NET, pStmt != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = pStmt->BindInt(0, accountId);
- SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
-
- r = E_OBJ_NOT_FOUND;
- pEnum.reset(accountDb.ExecuteStatementN(*pStmt));
- if (pEnum != null)
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetIntAt(0, isReadOnly);
- r = E_SUCCESS;
- break;
- }
- }
- SysTryReturn(NID_NET, r == E_SUCCESS, true, r, "[%s] Propagating.", GetErrorMessage(r));
-
- ClearLastResult();
-
- return (bool)isReadOnly;
-}
-
-String
-_NetAccountDatabase::GetDbPath(void)
-{
- static const wchar_t _OLD_DATA_PATH[] = L"/Home/";
- static const wchar_t _NET_ACCOUNT_DATABASE_FILE_NAME[] = L".tizen_netaccount.db";
-
- String dbPath;
- _ApiVersion apiVersion = _AppInfo::GetApiVersion();
-
- if (apiVersion == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
- {
- dbPath = String(_OLD_DATA_PATH);
- }
- else
- {
- dbPath = Tizen::App::App::GetInstance()->GetAppDataPath();
- }
-
- dbPath += String(_NET_ACCOUNT_DATABASE_FILE_NAME);
-
- SysLog(NID_NET, "GetDbPath() has been succeeded with the path:%ls", dbPath.GetPointer());
-
- return dbPath;
-}
-
-}} // Tizen::Net
+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-/**
- * @file FNet_NetAccountDatabase.h
- * @brief This is the header file for the %_NetAccountDatabase class.
- *
- * This header file contains the declarations of the %_NetAccountDatabase class.
- */
-
-#ifndef _FNET_INTERNAL_NET_ACCOUNT_DATABASE_H_
-#define _FNET_INTERNAL_NET_ACCOUNT_DATABASE_H_
-
-#include <FBaseDataType.h>
-#include <FNetNetTypes.h>
-
-namespace Tizen { namespace Base
-{
-class String;
-} } // Tizen::Base
-
-namespace Tizen { namespace Base { namespace Collection
-{
-template<class Type> class IListT;
-class IList;
-} } } // Tizen::Base::Collection
-
-namespace Tizen { namespace Net {
-
-enum _NetAccountOwner
-{
- _NET_ACCOUNT_OWNER_OTHER,
- _NET_ACCOUNT_OWNER_THIS
-};
-
-/**
- * @class _NetAccountDatabase
- * @brief This class represents a database for the network account.
- * @since 2.1
- *
- * This class represents a database for the network account.
- */
-class _NetAccountDatabase
-{
-public:
- static result InitializeRepository(void);
- static result AddAccount(const Tizen::Base::String& accountName, const Tizen::Base::String& profileName, _NetAccountOwner owner, NetAccountId& accountId);
- static result RemoveAccountByAccountId(NetAccountId accountId);
- static result RemoveAccountByProfileName(const Tizen::Base::String& profileName);
- static result UpdateAccountName(NetAccountId accountId, const Tizen::Base::String& accountName);
- static Tizen::Base::Collection::IListT<NetAccountId>* GetAccountIdsN(void);
- static Tizen::Base::Collection::IList* GetAccountNamesN(void);
- static Tizen::Base::Collection::IList* GetProfileNamesN(void);
- static result GetAccountName(NetAccountId accountId, Tizen::Base::String& accountName);
- static result GetProfileName(NetAccountId accountId, Tizen::Base::String& profileName);
- static result GetAccountIdByAccountName(const Tizen::Base::String& accountName, NetAccountId& accountId);
- static result GetAccountIdByProfileName(const Tizen::Base::String& profileName, NetAccountId& accountId);
- static bool IsReadOnly(NetAccountId accountId);
-
-private:
- static Tizen::Base::String GetDbPath(void);
-
-private:
- _NetAccountDatabase(void);
- virtual ~_NetAccountDatabase(void);
-
- _NetAccountDatabase(const _NetAccountDatabase& rhs);
- _NetAccountDatabase& operator =(const _NetAccountDatabase& rhs);
-}; // _NetAccountDatabase
-
-} } // Tizen::Net
-#endif // _FNET_INTERNAL_NET_ACCOUNT_DATABASE_H_
-
+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-/**
- * @file FNet_NetAccountInfoImpl.h
- * @brief This is the header file for the _NetAccountInfoImpl class.
- */
-
-#ifndef _FNET_INTERNAL_NET_ACCOUNT_INFO_IMPL_H_
-#define _FNET_INTERNAL_NET_ACCOUNT_INFO_IMPL_H_
-
-#include <unique_ptr.h>
-#include <FBaseDataType.h>
-#include <FBaseObject.h>
-#include <FBaseString.h>
-#include <FNetNetTypes.h>
-
-namespace Tizen { namespace Net
-{
-class IpAddress;
-class NetEndPoint;
-class NetAccountInfo;
-class _NetAccountManagerImpl;
-
-class _NetAccountInfoImpl
- : public Tizen::Base::Object
-{
-
-public:
- /**
- * This is the default constructor for this class.
- *
- * @since 2.1
- * @remarks After creating an instance of this class, the Construct() method must be called explicitly to initialize this instance.
- * @see Construct()
- */
- _NetAccountInfoImpl(void);
-
- /**
- * This is the destructor for this class.
- *
- * @since 2.1
- */
- virtual ~_NetAccountInfoImpl(void);
-
- /**
- * @see NetAccountInfo::Construct()
- */
- result Construct(const _NetAccountInfoImpl& netAccountInfo);
-
- /**
- * @see NetAccountInfo::Construct()
- */
- result Construct(void);
-
- /**
- * Initializes this instance of %_NetAccountInfoImpl with the specified profile instance. @n
- *
- * @since 2.1
- * @return An error code
- * @param[in] pAccountInfo A %NetAccountInfo instance
- * @param[in] pProfileHandle A profile handle
- * @exception E_SUCCESS The method is successful.
- * @exception E_INVALID_STATE This instance has already been constructed.
- * @exception E_INVALID_ARG The specified @c pAccountInfo or @c pProfileInfo is invalid.
- */
- result Construct(NetAccountInfo* pAccountInfo, void* pProfileHandle);
-
-public:
- /**
- * @see NetAccountInfo::GetAccountId()
- */
- NetAccountId GetAccountId(void) const;
-
- /**
- * @see NetAccountInfo::GetAccountName()
- */
- Tizen::Base::String GetAccountName(void) const;
-
- /**
- * @see NetAccountInfo::SetAccountName()
- */
- result SetAccountName(const Tizen::Base::String& accountName);
-
- /**
- * @see NetAccountInfo::GetProtocolType()
- */
- NetProtocolType GetProtocolType(void) const;
-
- /**
- * @see NetAccountInfo::SetProtocolType()
- */
- result SetProtocolType(NetProtocolType netProtocolType);
-
- /**
- * @see NetAccountInfo::GetAccessPointName()
- */
- Tizen::Base::String GetAccessPointName(void) const;
-
- /**
- * @see NetAccountInfo::SetAccessPointName()
- */
- result SetAccessPointName(const Tizen::Base::String& accessPointName);
-
- /**
- * @see NetAccountInfo::GetLocalAddressScheme()
- */
- NetAddressScheme GetLocalAddressScheme(void) const;
-
- /**
- * @see NetAccountInfo::GetLocalAddress()
- */
- const IpAddress* GetLocalAddress(void) const;
-
- /**
- * @see NetAccountInfo::SetLocalAddress()
- */
- result SetLocalAddress(NetAddressScheme localAddrScheme, const IpAddress* pLocalAddress);
-
- /**
- * @see NetAccountInfo::GetDnsAddressScheme()
- */
- NetAddressScheme GetDnsAddressScheme(void) const;
-
- /**
- * @see NetAccountInfo::GetPrimaryDnsAddress()
- */
- const IpAddress* GetPrimaryDnsAddress(void) const;
-
- /**
- * @see NetAccountInfo::GetSecondaryDnsAddress()
- */
- const IpAddress* GetSecondaryDnsAddress(void) const;
-
- /**
- * @see NetAccountInfo::SetDnsAddress()
- */
- result SetDnsAddress(NetAddressScheme dnsAddrScheme, const IpAddress* pPrimaryDnsAddress, const IpAddress* pSecondaryDnsAddress);
-
- /**
- * @see NetAccountInfo::GetProxyAddress()
- */
- const NetEndPoint* GetProxyAddress(void) const;
-
- /**
- * @see NetAccountInfo::SetProxyAddress()
- */
- result SetProxyAddress(const NetEndPoint* pProxyEndPoint);
-
- /**
- * @see NetAccountInfo::GetAuthenticationInfo()
- */
- result GetAuthenticationInfo(NetNapAuthType& authenticationType, Tizen::Base::String& id, Tizen::Base::String& password) const;
-
- /**
- * @see NetAccountInfo::SetAuthenticationInfo()
- */
- result SetAuthenticationInfo(NetNapAuthType authenticationType, const Tizen::Base::String& id, const Tizen::Base::String& password);
-
- /**
- * @see NetAccountInfo::GetBearerType()
- */
- NetBearerType GetBearerType(void) const;
-
- /**
- * @see NetAccountInfo::GetHomeUrl()
- */
- Tizen::Base::String GetHomeUrl(void) const;
-
- /**
- * @see NetAccountInfo::SetHomeUrl()
- */
- void SetHomeUrl(const Tizen::Base::String& homeUrl);
-
- /**
- * @see NetAccountInfo::GetMaximumLengthOfId()
- */
- int GetMaximumLengthOfId(void) const;
-
- /**
- * @see NetAccountInfo::GetMaximumLengthOfPassword()
- */
- int GetMaximumLengthOfPassword(void) const;
-
- /**
- * @see NetAccountInfo::GetMaximumLengthOfAccountName()
- */
- int GetMaximumLengthOfAccountName(void) const;
-
- /**
- * @see NetAccountInfo::IsReadOnly()
- */
- bool IsReadOnly(void) const;
-
- result ConvertToProfileInfo(void* pProfileHandle) const;
-
- /**
- * @see NetAccountInfo::Equals()
- */
- virtual bool Equals(const Tizen::Base::Object& rhs) const;
-
- /**
- * @see NetAccountInfo::GetHashCode()
- */
- virtual int GetHashCode(void) const;
-
-public:
- static NetAccountInfo* CreateNetAccountInfoN(void* pProfileHandle);
-
-public:
- /**
- * Gets the Impl instance.
- *
- * @since 2.1
- * @return The pointer to _NetAccountInfoImpl
- * @param[in] netAccountInfo An instance of NetAccountInfo
- */
- static _NetAccountInfoImpl* GetInstance(NetAccountInfo& netAccountInfo);
-
- /**
- * Gets the Impl instance.
- *
- * @since 2.1
- * @return The pointer to _NetAccountInfoImpl
- * @param[in] netAccountInfo An instance of NetAccountInfo
- */
- static const _NetAccountInfoImpl* GetInstance(const NetAccountInfo& netAccountInfo);
-
-private:
- /**
- * Sets the bearer type.
- *
- * @since 2.1
- *
- * @return An error code
- * @param[in] bearerType The type of the bearer
- * @exception E_SUCCESS The method is successful.
- * @exception E_INVALID_STATE This instance has not been constructed as yet.
- * @remarks If this method fails, the state of this instance does not change.
- * @see GetBearerType()
- */
- result SetBearerType(NetBearerType bearerType);
-
- /**
- * Sets the account Id.
- *
- * @since 2.1
- *
- * @return An error code
- * @param[in] accountId The account id
- * @exception E_SUCCESS The method is successful.
- * @exception E_INVALID_STATE This instance has not been constructed as yet.
- * @remarks If this method fails, the state of this instance does not change.
- * @see GetAccountId()
- */
- result SetAccountId(NetAccountId accountId);
-
-private:
- /**
- * This is the copy constructor for this class. @n
- * Do @b not use directly.
- *
- * @param[in] rhs An instance of _NetAccountInfoImpl
- */
- _NetAccountInfoImpl(const _NetAccountInfoImpl& rhs);
-
- /**
- * This is the assignment operator for this class. @n
- * Do @b not use directly.
- *
- * @param[in] rhs An instance of _NetAccountInfoImpl
- */
- _NetAccountInfoImpl& operator =(const _NetAccountInfoImpl& rhs);
-
-private:
- NetAccountId __accountId;
- Tizen::Base::String __accountName;
- Tizen::Base::String __accessPointName;
- NetNapAuthType __authType;
- Tizen::Base::String __authId;
- Tizen::Base::String __authPassword;
- Tizen::Base::String __homeUrl;
- NetBearerType __bearerType;
- NetProtocolType __protocolType;
- NetAddressScheme __localAddressScheme;
- NetAddressScheme __dnsAddressScheme;
- std::unique_ptr<IpAddress> __pLocalAddress;
- std::unique_ptr<IpAddress> __pPrimaryDnsAddress;
- std::unique_ptr<IpAddress> __pSecondaryDnsAddress;
- std::unique_ptr<NetEndPoint> __pProxyAddress;
- bool __isReadOnly;
-
- friend class _NetAccountManagerImpl;
-}; // _NetAccountInfoImpl
-
-} } //Tizen::Net
-
-#endif // _FNET_INTERNAL_NET_ACCOUNT_INFO_IMPL_H_
+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-/**
- * @file FNet_NetExporter.cpp
- * @brief This is the implementation for the %_NetExporter class.
- */
-
-#include <unique_ptr.h>
-#include <FNetNetAccountInfo.h>
-#include <FBaseSysLog.h>
-#include "FNet_NetAccountInfoImpl.h"
-#include "FNet_NetExporter.h"
-
-using namespace std;
-using namespace Tizen::Base;
-
-namespace Tizen { namespace Net
-{
-
-_NetExporter::_NetExporter(void)
-{
-}
-
-_NetExporter::~_NetExporter(void)
-{
-}
-
-result
-_NetExporter::InitializeNetAccountInfo(NetAccountInfo* pAccountInfo, void* pProfileInfo)
-{
- result r = E_SUCCESS;
-
- SysTryReturnResult(NID_NET, pAccountInfo != null, E_INVALID_ARG, "Invalid argument is used. AccountInfo is null.");
- SysTryReturnResult(NID_NET, pProfileInfo != null, E_INVALID_ARG, "Invalid argument is used. ProfileInfo is null.");
-
- unique_ptr<_NetAccountInfoImpl> pNetAccountInfoImpl(new (std::nothrow) _NetAccountInfoImpl());
- SysTryReturnResult(NID_NET, pNetAccountInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
-
- r = pNetAccountInfoImpl->Construct(pAccountInfo, pProfileInfo);
- SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
-
- pNetAccountInfoImpl.release();
-
- return r;
-}
-
-} } // Tizen::Net
+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file FNetWifi_IWifiManagerEventListener.h
- * @brief This is the header file for the _IWifiManagerEventListener interface.
- *
- * This is the header file for the internal interface of wifi events.
- *
- */
-
-#ifndef _FNET_WIFI_INTERNAL_IWIFI_MANAGER_EVENT_LISTENER_H_
-#define _FNET_WIFI_INTERNAL_IWIFI_MANAGER_EVENT_LISTENER_H_
-
-#include <FBaseRtIEventListener.h>
-#include <FOspConfig.h>
-
-namespace Tizen { namespace Net { namespace Wifi
-{
-
-/**
- * @interface _IWifiManagerEventListener
- * @brief This interface implements listeners for WifiManager internal events.
- * @since 1.0
- */
-
-class _OSP_EXPORT_ _IWifiManagerEventListener
- : public Tizen::Base::Runtime::IEventListener
-{
-
-public:
- /**
- * This polymorphic destructor should be overridden if required. This way,
- * the destructors of the derived classes are called when the destructor of this interface is called.
- *
- */
- virtual ~_IWifiManagerEventListener(void) {}
-
- /**
- * @see IWifiManagerEventListener::OnWifiActivated()
- */
- virtual void OnWifiActivated(result r) = 0;
-
- /**
- * @see IWifiManagerEventListener::OnWifiDeactivated()
- */
- virtual void OnWifiDeactivated(result r) = 0;
-
- /**
- * @see IWifiManagerEventListener::OnWifiConnected()
- */
- virtual void OnWifiConnected(const Tizen::Base::String& ssid, result r) = 0;
-
- /**
- * @see IWifiManagerEventListener::OnWifiDisconnected()
- */
- virtual void OnWifiDisconnected(void) = 0;
-
- /**
- * @see IWifiManagerEventListener::OnWifiRssiChanged()
- */
- virtual void OnWifiRssiChanged(long rssi) = 0;
-
- /**
- * @see IWifiManagerEventListener::OnWifiScanCompletedN()
- */
- virtual void OnWifiScanCompleted(Tizen::Base::Collection::IList* pWifiBssInfoList, result r) = 0;
-
- /**
- * @see IWifiSystemMonitoringEventListener::OnWifiConnectionStateChanged()
- */
- virtual void OnWifiConnectionStateChanged(WifiConnectionState state) = 0;
-
- /**
- * @see IWifiSystemMonitoringEventListener::OnWifiSystemScanResultUpdated()
- */
- virtual void OnWifiSystemScanResultUpdated(void) = 0;
-
-}; // _IWifiManagerEventListener
-
-} } } // Tizen::Net::Wifi
-
-#endif // _FNET_WIFI_INTERNAL_IWIFI_MANAGER_EVENT_LISTENER_H_
+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-/**
- * @file FNetWifi_WifiSystemAdapter.h
- * @brief This is the header file for the _WifiSystemAdapter class.
- * @version 2.1
- *
- * This header file contains declarations of the _WifiSystemAdapter class.
- */
-#ifndef _FNET_WIFI_INTERNAL_WIFI_SYSTEM_ADAPTER_H_
-#define _FNET_WIFI_INTERNAL_WIFI_SYSTEM_ADAPTER_H_
-
-#include <unique_ptr.h>
-#include <wifi.h>
-#include <FOspConfig.h>
-#include <FBaseObject.h>
-#include <FNetWifiWifiTypes.h>
-
-namespace Tizen { namespace Net { namespace Wifi
-{
-
-class WifiBssInfo;
-class _WifiManagerImpl;
-class _IWifiManagerEventListener;
-
-class _OSP_EXPORT_ _WifiSystemAdapter :
- public Tizen::Base::Object
-{
-
-public:
- /**
- * Register an instance of _IWifiManagerEventListener interface.
- *
- * @return An error code
- * @param[in] listener The instance of _IWifiManagerEventListener to be registered
- * @param[in] isHighPriority Set to @c true to register with the high priority, @n
- * else @c false
- * @exception E_SUCCESS The method is successful.
- * @exception E_OUT_OF_MEMORY The memory is insufficient.
- */
- result RegisterManagerEventListener(_IWifiManagerEventListener& listener);
-
- /**
- * Unregister an instance of _IBluetoothManagerEventListener interface.
- *
- * @return An error code
- * @param[in] listener The instance of _IWifiManagerEventListener to be unregistered
- * @exception E_SUCCESS The method is successful.
- * @exception E_OBJ_NOT_FOUND The input instance is not registered.
- */
- result UnregisterManagerEventListener(_IWifiManagerEventListener& listener);
-
- /**
- * Activates the local Wifi device.
- *
- * @return An error code
- * @exception E_SUCCESS The activation was successful.
- * @exception E_FAILURE Failed to activate.
- * @exception E_SYSTEM A system error occurred.
- */
- result Activate(void);
-
- /**
- * Deactivates the local Wifi device.
- *
- * @return An error code
- * @exception E_SUCCESS The deactivation was successful.
- * @exception E_FAILURE Failed to deactivate.
- * @exception E_SYSTEM A system error occurred.
- */
- result Deactivate(void);
-
- /**
- * Gets the MAC address of the Wifi device.
- * @return The MAC address in the form '00-00-00-00-00-00'
- */
- Tizen::Base::String GetMacAddress(void) const;
-
- /**
- * Checks whether the local device is activated.
- * @return @c true, if the local device is activated @n
- * @c false, otherwise
- */
- bool IsActivated(void) const;
-
- /**
- * Checks whether the local device is connected with a remote STA.
- * @return @c true, if the local device is connected with a remote STA @n
- * @c false, otherwise
- */
- bool IsConnected(void) const;
-
- /**
- * Checks whether the local device is already connected with a specific remote STA.
- *
- * @return @c true, if the local device is already connected with a specific remote STA @n
- * @c false, otherwise
- * @param[in] pApHandle a handle of access point
- *
- */
- bool IsConnected(wifi_ap_h pApHandle) const;
-
- /**
- * Requests a scan for nearby BSS with both infrastructure and independent mode.
- *
- * @return An error code
- * @exception E_SUCCESS The method was successful.
- * @exception E_FAILURE The method failed.
- * @remarks Only active scan - i.e. probing for APs in the range - is supported.
- * @see IWifiManagerEventListener::OnWifiScanCompleted()
- */
- result Scan(void);
-
- /**
- * Establishes a connection to a specific access point - only BSS with infrastructure mode.
- *
- * @return An error code
- * @param[in] targetApInfo A BSS information that represents target access point.
- * @exception E_SUCCESS The method was successful.
- * @exception E_FAILURE The method failed.
- * @exception E_INVALID_ARG A specified input parameter is invalid. E.g. BSS type is independent mode.
- * @remarks If a connection to other access point is already established, it will be disconnected and the new connection
- * of this method will be established.
- * @see IWifiManagerEventListener::OnWifiConnected()
- */
- result Connect(const WifiBssInfo& targetApInfo);
-
- /**
- * Gets the state of current Wi-Fi connection.
- *
- * @return The state of the current Wi-Fi connection
- */
- WifiConnectionState GetConnectionState(void) const;
-
- /**
- * Gets the information of current Wi-Fi connection target which the local device is connecting or connected with.
- *
- * @return A pointer to the WifiBssInfo instance representing the information of current Wi-Fi connection target
- * else @c null if GetConnectionState() is WIFI_CONNECTION_STATE_NOT_CONNECTED
- */
- WifiBssInfo* GetConnectionTargetInfoN(void) const;
-
- /**
- * Gets a list of the latest search results which the underlying Wi-Fi system scan periodically on background.
- *
- * @return An IList containing WifiBssInfo of existing Wi-Fi connections if successful, @n
- * else @c null
- */
- Tizen::Base::Collection::IList* GetSystemScanResultN(void) const;
-
- /**
- * Called when the device state is changed.
- *
- * @param[in] state Device status
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData);
-
- /**
- * Called when the connection state is changed.
- *
- * @param[in] state Connection status
- * @param[in] pApHandle A handle of access point
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h pApHandle, void* pUserData);
-
- /**
- * Called when each access point is found.
- *
- * @param[in] pApHandle A handle of access point
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static bool OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserData);
-
- /**
- * Called when each access point is checked.
- *
- * @param[in] pApHandle A handle of access point
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static bool OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUserData);
-
- /**
- * Called when Wifi is activated.
- *
- * @param[in] errorCode Error code
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiActivated(wifi_error_e errorCode, void* pUserData);
-
- /**
- * Called when Wifi is dectivated.
- *
- * @param[in] errorCode Error code
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiDeactivated(wifi_error_e errorCode, void* pUserData);
-
- /**
- * Called when the local device is connected with Wifi access point.
- *
- * @param[in] errorCode Error code
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiConnected(wifi_error_e errorCode, void* pUserData);
-
- /**
- * Called when the scan process is completed.
- *
- * @param[in] errorCode Error code
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiScanCompleted(wifi_error_e errorCode, void* pUserData);
-
- /**
- * Called when the rssi value is changed.
- *
- * @param[in] rssiLevel Rssi level
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiRssiLevelChanged(wifi_rssi_level_e rssiLevel, void* pUserData);
-
- /**
- * Called when the background scan result is updated.
- *
- * @param[in] errorCode Error code
- * @param[in] pUserData The user data passed from the callback registration function
- */
- static void OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, void* pUserData);
-
- /**
- * Get the singleton insatnce of _WifiSystemAdapter.
- *
- * @return The pointer to _WifiSystemAdapter
- */
- static _WifiSystemAdapter* GetInstance(void);
-
-private:
- /**
- * This default constructor is intentionally declared as private to implement the Singleton semantic.
- *
- * @remarks After creating an instance of this class, you must explicitly call
- * the construction method to initialize the instance.
- * @see Construct()
- */
- _WifiSystemAdapter(void);
-
- /**
- * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
- *
- * @param[in] rhs An instance of %_WifiSystemAdapter
- */
- _WifiSystemAdapter(const _WifiSystemAdapter& rhs);
-
- /**
- * This destructor is intentionally declared as private to implement the Singleton semantic.
- *
- */
- virtual ~_WifiSystemAdapter(void);
-
- /**
- * Initializes the _WifiSystemAdapter instance and adds the listener instance.
- *
- * @return An error code
- * @exception E_SUCCESS The initialization was successful.
- * @exception E_SYSTEM A system error occurred.
- */
- result Construct();
-
- /**
- * Initializes the _WifiSystemAdapter singletone instance.
- *
- * @exception E_SUCCESS The initialization was successful.
- * @exception E_SYSTEM A system error occurred.
- * @exception E_OUT_OF_MEMORY The memory is insufficient.
- */
- static void InitSingleton(void);
-
- /**
- * Destorys instance of singleton class.
- *
- */
- static void DestroySingleton(void);
-
- /**
- * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
- *
- * @param[in] rhs An instance of %_WifiSystemAdapter
- */
- _WifiSystemAdapter& operator=(const _WifiSystemAdapter& rhs);
-
- static const char* GetStringOfConnectionState(wifi_connection_state_e state);
-
-private:
- Tizen::Base::Collection::LinkedListT<_IWifiManagerEventListener*> __mgrEvtListenerList;
- wifi_connection_state_e __prevconnState;
-
-friend class std::default_delete<_WifiSystemAdapter>;
-
-}; // _WifiSystemAdapter
-
-} } } // Tizen::Net::Wifi
-
-#endif // _FNET_WIFI_INTERNAL_WIFI_SYSTEM_ADAPTER_H_
+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-/**
- * @file FNet_NetExporter.h
- * @brief This is the header file for the %_NetExporter class.
- */
-
-#ifndef _FNET_INTERNAL_NET_EXPORTER_H_
-#define _FNET_INTERNAL_NET_EXPORTER_H_
-
-#include <FBaseDataType.h>
-#include <FOspConfig.h>
-
-namespace Tizen { namespace Net
-{
-class NetAccountInfo;
-
-class _OSP_EXPORT_ _NetExporter
-{
-public:
- static result InitializeNetAccountInfo(NetAccountInfo* pAccountInfo, void* pProfileInfo);
-
-private:
- /**
- * This default constructor is intentionally declared as private because this class is not constructible.
- */
- _NetExporter(void);
-
- /**
- * This destructor is intentionally declared as private because this class is not constructible.
- */
- virtual ~_NetExporter(void);
-
- /**
- * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
- *
- * @param[in] rhs An instance of %_NetExporter
- */
- _NetExporter(const _NetExporter& rhs);
-
- /**
- * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
- *
- * @param[in] rhs An instance of %_NetExporter
- */
- _NetExporter& operator =(const _NetExporter& rhs);
-}; // _NetExporter
-
-} } // Tizen::Net
-
-#endif // _FNET_INTERNAL_NET_EXPORTER_H_
+++ /dev/null
-//
-// Open Service Platform
-// Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Apache License, Version 2.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
-
-/**
- * @file FNetWifi_WifiSystemAdapter.cpp
- * @brief This is the implementation file for the _WifiSystemAdapter Class.
- */
-#include <pthread.h>
-#include <FBaseUtilStringUtil.h>
-#include <FBaseSysLog.h>
-#include <FNetWifiWifiBssInfo.h>
-#include <FBase_StringConverter.h>
-#include "FNetWifi_WifiBssInfoImpl.h"
-#include "FNetWifi_IWifiManagerEventListener.h"
-#include "FNetWifi_WifiManagerImpl.h"
-#include "FNetWifi_WifiSystemAdapter.h"
-#include "FNetWifi_WifiSecurityInfoImpl.h"
-#include "FNetWifi_WifiUtility.h"
-
-#ifdef _WifiConvertErrorResult
-#undef _WifiConvertErrorResult
-#endif
-#define _WifiConvertErrorResult(condition, r, value) \
- do \
- { \
- if (condition) { \
- r = value; \
- } \
- } while (0);
-
-using namespace std;
-using namespace Tizen::Base;
-using namespace Tizen::Base::Runtime;
-using namespace Tizen::Base::Collection;
-
-namespace Tizen { namespace Net { namespace Wifi {
-
-static _WifiSystemAdapter* pInstance = null;
-
-_WifiSystemAdapter::_WifiSystemAdapter(void)
- : __mgrEvtListenerList()
- , __prevconnState(WIFI_CONNECTION_STATE_DISCONNECTED)
-{
-}
-
-_WifiSystemAdapter::~_WifiSystemAdapter(void)
-{
-}
-
-result
-_WifiSystemAdapter::Construct(void)
-{
- int err = WIFI_ERROR_NONE;
-
- err = wifi_initialize();
- SysTryReturnResult(NID_NET_WIFI, ((err == WIFI_ERROR_NONE) || (err == WIFI_ERROR_INVALID_OPERATION)), E_SYSTEM, "Failed to wifi_initialize()");
-
- err = wifi_set_device_state_changed_cb(OnWifiDeviceStateChanged, null);
- SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_device_state_changed_cb()");
-
- err = wifi_set_connection_state_changed_cb(OnWifiConnectionStateChanged, null);
- SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_connection_state_changed_cb()");
-
- err = wifi_set_rssi_level_changed_cb(OnWifiRssiLevelChanged, null);
- SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_rssi_level_changed_cb()");
-
- err = wifi_set_background_scan_cb(OnWifiBackgroundScanResultUpdated, null);
- SysTryReturnResult(NID_NET_WIFI, err == WIFI_ERROR_NONE, E_SYSTEM, "Failed to wifi_set_background_scan_cb()");
-
- wifi_get_connection_state(&__prevconnState);
-
- return E_SUCCESS;
-}
-
-void
-_WifiSystemAdapter::InitSingleton(void)
-{
- result r = E_SUCCESS;
- unique_ptr<_WifiSystemAdapter> pInst(new (std::nothrow) _WifiSystemAdapter());
-
- SysTryReturnVoidResult(NID_NET_WIFI, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
-
- r = pInst->Construct();
- SysTryReturnVoidResult(NID_NET_WIFI, r == E_SUCCESS, r, "[%s] Error occurred in construct.", GetErrorMessage(r));
-
- pInstance = pInst.release();
-
- std::atexit(DestroySingleton);
-}
-
-void
-_WifiSystemAdapter::DestroySingleton(void)
-{
- wifi_unset_connection_state_changed_cb();
- wifi_unset_device_state_changed_cb();
- wifi_unset_rssi_level_changed_cb();
- wifi_unset_background_scan_cb();
- wifi_deinitialize();
-}
-
-_WifiSystemAdapter*
-_WifiSystemAdapter::GetInstance(void)
-{
- static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
-
- if (!pInstance)
- {
- ClearLastResult();
- pthread_once(&onceBlock, InitSingleton);
-
- result r = GetLastResult();
- if (IsFailed(r))
- {
- onceBlock = PTHREAD_ONCE_INIT;
- }
- }
-
- return pInstance;
-}
-
-result
-_WifiSystemAdapter::RegisterManagerEventListener(_IWifiManagerEventListener& listener)
-{
- return __mgrEvtListenerList.Add(&listener);
-}
-
-result
-_WifiSystemAdapter::UnregisterManagerEventListener(_IWifiManagerEventListener& listener)
-{
- return __mgrEvtListenerList.Remove(&listener);
-}
-
-result
-_WifiSystemAdapter::Activate(void)
-{
- result r = E_SYSTEM;
- int err = WIFI_ERROR_NONE;
-
- err = wifi_activate(OnWifiActivated, null);
- _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE);
- _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION);
- _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to activate Wi-Fi. [0x%08X]", err);
-
- return E_SUCCESS;
-}
-
-result
-_WifiSystemAdapter::Deactivate(void)
-{
- result r = E_SYSTEM;
- int err = WIFI_ERROR_NONE;
-
- err = wifi_deactivate(OnWifiDeactivated, null);
- _WifiConvertErrorResult(err == WIFI_ERROR_OPERATION_FAILED, r, E_FAILURE);
- _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_OPERATION, r, E_INVALID_OPERATION);
- _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to deactivate Wi-Fi. [0x%08X]", err);
-
- return E_SUCCESS;
-}
-
-String
-_WifiSystemAdapter::GetMacAddress(void) const
-{
- int err = 0;
- char *pMacAddress;
- err = wifi_get_mac_address(&pMacAddress);
- String macAddress(_WifiUtility::ConvertMacAddress(pMacAddress));
- free(pMacAddress);
-
- return macAddress;
-}
-
-bool
-_WifiSystemAdapter::IsActivated(void) const
-{
- bool val = false;
- wifi_is_activated(&val);
-
- return val;
-}
-
-bool
-_WifiSystemAdapter::IsConnected(void) const
-{
- wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED;
-
- wifi_get_connection_state(&connectionState);
-
- switch (connectionState)
- {
- case WIFI_CONNECTION_STATE_CONNECTED:
- return true;
- default:
- return false;
- }
-}
-
-
-bool
-_WifiSystemAdapter::IsConnected(wifi_ap_h pApHandle) const
-{
- int err = WIFI_ERROR_NONE;
- bool isSame = false;
-
- if (IsConnected())
- {
- wifi_ap_h pConnectedApHandle = null;
- err = wifi_get_connected_ap(&pConnectedApHandle);
-
- if (err != WIFI_ERROR_NONE && pConnectedApHandle == null)
- {
- SysLog(NID_NET_WIFI, "Failed result from wifi_get_connected_ap() is 0x%x", err);
- return false;
- }
-
- String connectedBssId(_WifiUtility::GetBssIdFromApHandle(pConnectedApHandle));
- String targetBssId(_WifiUtility::GetBssIdFromApHandle(pApHandle));
-
- if (connectedBssId.CompareTo(targetBssId) == 0)
- {
- isSame = true;
- }
-
- (void)wifi_ap_destroy(pConnectedApHandle);
- }
-
- return isSame;
-}
-
-
-result
-_WifiSystemAdapter::Scan(void)
-{
- result r = E_FAILURE;
- int err = WIFI_ERROR_NONE;
-
- err = wifi_scan(OnWifiScanCompleted, null);
- _WifiConvertErrorResult(err == WIFI_ERROR_NONE, r, E_SUCCESS);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to scan for a nearby BSS. [0x%08X]", err);
-
- return E_SUCCESS;
-}
-
-WifiConnectionState
-_WifiSystemAdapter::GetConnectionState(void) const
-{
- WifiConnectionState currentState = WIFI_CONN_STATE_NOT_CONNECTED;
-
- wifi_foreach_found_aps(OnWifiEachAccessPointChecked, ¤tState);
-
- return currentState;
-}
-
-WifiBssInfo*
-_WifiSystemAdapter::GetConnectionTargetInfoN(void) const
-{
- WifiBssInfo* pBssInfo = null;
- int apRes = WIFI_ERROR_NONE;
- wifi_ap_h pApHandle = null;
-
- apRes = wifi_get_connected_ap(&pApHandle);
- SysTryReturn(NID_NET_WIFI, apRes != WIFI_ERROR_OUT_OF_MEMORY, null, E_OUT_OF_MEMORY,
- "[E_OUT_OF_MEMORY] Memory allocation failed.");
- SysTryReturn(NID_NET_WIFI, apRes == WIFI_ERROR_NONE, null, E_SYSTEM, "[E_SYSTEM] Failed to get the connected AP handle.");
-
- pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandle);
- (void)wifi_ap_destroy(pApHandle);
- SysTryReturn(NID_NET_WIFI, pBssInfo != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
-
- return pBssInfo;
-}
-
-Tizen::Base::Collection::IList*
-_WifiSystemAdapter::GetSystemScanResultN(void) const
-{
- LinkedList* pBssInfoList = null;
-
- pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter);
- SysTryReturn(NID_NET_WIFI, pBssInfoList != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
-
- wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList);
-
- return pBssInfoList;
-}
-
-void
-_WifiSystemAdapter::OnWifiDeviceStateChanged(wifi_device_state_e state, void* pUserData)
-{
- result r = E_SUCCESS;
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- if(state == WIFI_DEVICE_STATE_ACTIVATED)
- {
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r));
- pMgrEvtListener->OnWifiActivated(r);
- }
- else
- {
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r));
- pMgrEvtListener->OnWifiDeactivated(r);
- }
- }
-
- delete pEnum;
-}
-
-void
-_WifiSystemAdapter::OnWifiActivated(wifi_error_e errorCode, void* pUserData)
-{
- result r = E_FAILURE;
- _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS);
-
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_ACTIVATED],[result:%s]", GetErrorMessage(r));
- pMgrEvtListener->OnWifiActivated(r);
- }
-
- delete pEnum;
-}
-
-void
-_WifiSystemAdapter::OnWifiDeactivated(wifi_error_e errorCode, void* pUserData)
-{
- result r = E_FAILURE;
- _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS);
-
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DEACTIVATED],[result:%s]", GetErrorMessage(r));
- pMgrEvtListener->OnWifiDeactivated(r);
- }
-
- delete pEnum;
-}
-
-void
-_WifiSystemAdapter::OnWifiConnected(wifi_error_e errorCode, void* pUserData)
-{
- result r = E_SUCCESS;
- _WifiConvertErrorResult(errorCode != WIFI_ERROR_NONE, r, E_FAILURE);
- _WifiConvertErrorResult(errorCode == WIFI_ERROR_ALREADY_EXISTS, r, E_SUCCESS);
- _WifiConvertErrorResult(errorCode == WIFI_ERROR_INVALID_KEY, r, E_AUTHENTICATION);
- _WifiConvertErrorResult(errorCode == WIFI_ERROR_NO_REPLY, r, E_NOT_RESPONDING);
- _WifiConvertErrorResult(errorCode == WIFI_ERROR_DHCP_FAILED, r, E_DHCP);
- SysTryLog(NID_NET_WIFI, r == E_SUCCESS, "Failed result from OnWifiConnected() is 0x%x.", errorCode);
-
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- if(r == E_SUCCESS)
- {
- char* pEssid = null;
- wifi_ap_h apHandler;
- int err = wifi_get_connected_ap(&apHandler);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_get_connected_ap() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY);
-
- err = wifi_ap_get_essid(apHandler, &pEssid);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err);
- String ssid(pEssid);
- free(pEssid);
-
- (void)wifi_ap_destroy(apHandler);
-
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r));
- pMgrEvtListener->OnWifiConnected(ssid, r);
- }
- else
- {
- String ssid(L"");
-
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:%s]", GetErrorMessage(r));
- pMgrEvtListener->OnWifiConnected(ssid, r);
- }
- }
-
- delete pEnum;
-}
-
-void
-_WifiSystemAdapter::OnWifiConnectionStateChanged(wifi_connection_state_e state, wifi_ap_h pApHandle, void *pUserData)
-{
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
-
- char* pEssid = null;
- int err = wifi_ap_get_essid(pApHandle, &pEssid);
- unique_ptr<char, _CharDeleter> pSsid(pEssid);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_essid() is 0x%x.", err);
- SysLog(NID_NET_WIFI, "The connection state is %s, ssid : %s", GetStringOfConnectionState(state), pSsid.get());
-
- if (pAdapter->__prevconnState == state)
- {
- SysLog(NID_NET_WIFI, "The connection state is same as the previous state.[%d]", state);
- return;
- }
-
- pAdapter->__prevconnState = state;
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- switch(state)
- {
- case WIFI_CONNECTION_STATE_CONNECTED:
- {
- String ssid(pSsid.release());
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- // Fire a CONNECTED event for notifying that the connection is established not by this system adapter.
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTED],[result:E_SUCCESS]");
- pMgrEvtListener->OnWifiConnected(ssid, E_SUCCESS);
-
- // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to 'CONNECTED' state.
- // This seems a little redundant but the purpose of it is quite different from CONNECTED event.
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONNECTION_STATE_CONNECTED]");
- pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONNECTED);
- }
- }
- break;
-
- case WIFI_CONNECTION_STATE_DISCONNECTED:
- {
- wifi_connection_state_e connectionState = WIFI_CONNECTION_STATE_DISCONNECTED;
- wifi_get_connection_state(&connectionState);
-
- // Ignore if wifi state is connected.
- if (connectionState == WIFI_CONNECTION_STATE_CONNECTED)
- break;
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- // Fire a DISCONNECTED event for notifying that the connection is broken off not by this system adapter.
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_DISCONNECTED]");
- pMgrEvtListener->OnWifiDisconnected();
-
- // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "IDLE' state.
- // This seems a little redundant but the purpose of it is quite different from DISCONNECTED event.
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_NOT_CONNECTED]");
- pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_NOT_CONNECTED);
- }
- }
- break;
-
- case WIFI_CONNECTION_STATE_ASSOCIATION:
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "ASSOCIATING" state.
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_ASSOCIATING]");
- pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_ASSOCIATING);
- }
- }
- break;
-
- case WIFI_CONNECTION_STATE_CONFIGURATION:
- {
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- // Fire a CONNECTION_CHANGED event for notifying that the connection state is changed to "CONFIGURING" state.
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_CONNECTION_STATE_CHANGED],[State:WIFI_CONN_STATE_CONFIGURING]");
- pMgrEvtListener->OnWifiConnectionStateChanged(WIFI_CONN_STATE_CONFIGURING);
- }
- }
- break;
-
- default:
- break;
- }
-
- delete pEnum;
-}
-
-bool
-_WifiSystemAdapter::OnWifiEachAccessPointFound(wifi_ap_h pApHandle, void* pUserData)
-{
- WifiBssInfo* pBssInfo = null;
- LinkedList* pBssInfoList = static_cast<LinkedList*>(pUserData);
- wifi_ap_h pApHandleClone = null;
-
- int err = wifi_ap_clone(&pApHandleClone, pApHandle);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_clone() is 0x%x.", err);
- pBssInfo = _WifiUtility::CreateWifiBssInfoInstanceN(pApHandleClone);
- // keep gonig even though creating one WifiBssInfo instance.
- SysTryReturn(NID_NET_WIFI, pBssInfo != null, true, GetLastResult(),
- "[%s] Propagating because of creating a new WifiBssInfo fails.", GetErrorMessage(GetLastResult()));
-
- pBssInfoList->Add(*pBssInfo);
-
- return true;
-}
-
-bool
-_WifiSystemAdapter::OnWifiEachAccessPointChecked(wifi_ap_h pApHandle, void* pUserData)
-{
- wifi_connection_state_e apState = WIFI_CONNECTION_STATE_DISCONNECTED;
- WifiConnectionState* pLocalState = static_cast<WifiConnectionState*>(pUserData);
- bool isContinued = true;
-
- int err = wifi_ap_get_connection_state(pApHandle, &apState);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_get_connection_state() is 0x%x.", err);
-
- switch (apState)
- {
- case WIFI_CONNECTION_STATE_ASSOCIATION:
- *pLocalState = WIFI_CONN_STATE_ASSOCIATING;
- isContinued = false;
- break;
- case WIFI_CONNECTION_STATE_CONFIGURATION:
- *pLocalState = WIFI_CONN_STATE_CONFIGURING;
- isContinued = false;
- break;
- case WIFI_CONNECTION_STATE_CONNECTED:
- *pLocalState = WIFI_CONN_STATE_CONNECTED;
- isContinued = false;
- break;
- case WIFI_CONNECTION_STATE_DISCONNECTED:
- default:
- *pLocalState = WIFI_CONN_STATE_NOT_CONNECTED;
- break;
- }
-
- return isContinued;
-}
-
-void
-_WifiSystemAdapter::OnWifiScanCompleted(wifi_error_e errorCode, void *pUserData)
-{
- LinkedList* pBssInfoList = null;
- result r = E_FAILURE;
- _WifiConvertErrorResult(errorCode == WIFI_ERROR_NONE, r, E_SUCCESS);
-
- pBssInfoList = new (std::nothrow) LinkedList(SingleObjectDeleter);
- SysTryReturnVoidResult(NID_NET_WIFI, pBssInfoList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
-
- int err = wifi_foreach_found_aps(OnWifiEachAccessPointFound, pBssInfoList);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_foreach_found_aps() is 0x%x.", err);
-
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED],[result:%s]", GetErrorMessage(r));
- pMgrEvtListener->OnWifiScanCompleted(pBssInfoList, r);
- }
-
- delete pBssInfoList;
- delete pEnum;
-}
-
-void
-_WifiSystemAdapter::OnWifiBackgroundScanResultUpdated(wifi_error_e errorCode, void* pUserData)
-{
- if (errorCode == WIFI_ERROR_NONE)
- {
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_SCAN_COMPLETED]");
- pMgrEvtListener->OnWifiSystemScanResultUpdated();
- }
-
- delete pEnum;
- }
-}
-
-result
-_WifiSystemAdapter::Connect(const WifiBssInfo& targetApInfo)
-{
- result r = E_SUCCESS;
- int err = WIFI_ERROR_NONE;
-
- wifi_ap_h pApHandle;
- wifi_security_type_e securityType;
- const _WifiBssInfoImpl* pBssInfoImpl = _WifiBssInfoImpl::GetInstance(targetApInfo);
- const WifiSecurityInfo* pSecurityInfo = targetApInfo.GetSecurityInfo();
- const _WifiSecurityInfoImpl* pSecurityInfoImpl = _WifiSecurityInfoImpl::GetInstance(*pSecurityInfo);
-
- pApHandle = static_cast <wifi_ap_h> (pBssInfoImpl->GetBssHandle());
-
- if(pApHandle == null)
- {
- SysLog(NID_NET_WIFI, "It's Hidden AP");
-
- // Sets SSID
- unique_ptr<char[]> pSsidTemp(_StringConverter::CopyToCharArrayN(targetApInfo.GetSsid()));
- SysTryReturnResult(NID_NET_WIFI, pSsidTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
- err = wifi_ap_create(pSsidTemp.get(), &pApHandle);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_create() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- _WifiConvertErrorResult(err == WIFI_ERROR_OUT_OF_MEMORY, r, E_OUT_OF_MEMORY);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to create handle of ap.");
-
- // Sets Authentication Type
- securityType = _WifiUtility::ConvertSecurityType(pSecurityInfo->GetAuthenticationType());
- err = wifi_ap_set_security_type(pApHandle, securityType);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_security_type() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set authenticatino type.");
-
- // Sets Network Key
- unique_ptr<char[]> pKeyTemp(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetNetworkKey()));
- SysTryReturnResult(NID_NET_WIFI, pKeyTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
- err = wifi_ap_set_passphrase(pApHandle,pKeyTemp.get());
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_passphrase() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set network key.");
- }
- else
- {
- SysTryReturnResult(NID_NET_WIFI, !IsConnected(pApHandle), E_INVALID_STATE,
- "There is already connected to the same access point.");
-
- unique_ptr<char[]> pKeyTemp;
- const char* pSecurityKey = null;
- if (pSecurityInfoImpl->GetNetworkKey().IsEmpty())
- {
- switch (targetApInfo.GetSecurityInfo()->GetEncryptionType())
- {
- case WIFI_ENCRYPTION_NONE:
- break;
-
- case WIFI_ENCRYPTION_WEP:
- pSecurityKey = reinterpret_cast <const char*>(pSecurityInfoImpl->GetNetworkKeyWep());
- break;
-
- case WIFI_ENCRYPTION_TKIP:
- pSecurityKey = reinterpret_cast <const char*>(pSecurityInfoImpl->GetNetworkKeyTkip());
- break;
-
- case WIFI_ENCRYPTION_AES:
- pSecurityKey = reinterpret_cast <const char*>(pSecurityInfoImpl->GetNetworkKeyAes());
- break;
-
- case WIFI_ENCRYPTION_TKIP_AES_MIXED:
- pSecurityKey = reinterpret_cast <const char*>(pSecurityInfoImpl->GetNetworkKeyTkip());
-
- if (strlen(pSecurityKey) == 0)
- {
- pSecurityKey = reinterpret_cast <const char*>(pSecurityInfoImpl->GetNetworkKeyAes());
- }
- break;
- default:
- break;
- }
- }
- else
- {
- if (targetApInfo.GetSecurityInfo()->GetEncryptionType() != WIFI_ENCRYPTION_NONE)
- {
- pKeyTemp.reset(_StringConverter::CopyToCharArrayN(pSecurityInfoImpl->GetNetworkKey()));
- SysTryReturnResult(NID_NET_WIFI, pKeyTemp != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
- pSecurityKey = pKeyTemp.get();
- }
- }
-
- err = wifi_ap_set_passphrase(pApHandle, pSecurityKey);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_passphrase() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set network key.");
- }
-
- if (pSecurityInfoImpl->GetAuthenticationType() == WIFI_AUTHENTICATION_WPA ||
- pSecurityInfoImpl->GetAuthenticationType() == WIFI_AUTHENTICATION_WPA2)
- {
- wifi_eap_type_e eapType = _WifiUtility::ConvertEapType(pSecurityInfoImpl->GetEapType());
- err = wifi_ap_set_eap_type(pApHandle, eapType);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_type() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap type.");
-
- wifi_eap_auth_type_e eapAuthType = _WifiUtility::ConvertEapAuthType(pSecurityInfoImpl->GetEapType());
- err = wifi_ap_set_eap_auth_type(pApHandle, eapAuthType);
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_auth_type() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap authentication type.");
-
- err = wifi_ap_set_eap_passphrase(pApHandle, pSecurityInfoImpl->GetEapUserId(), pSecurityInfoImpl->GetEapPassword());
- SysTryLog(NID_NET_WIFI, err == WIFI_ERROR_NONE, "Failed result from wifi_ap_set_eap_passphrase() is 0x%x.", err);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
- _WifiConvertErrorResult(err == WIFI_ERROR_INVALID_PARAMETER, r, E_INVALID_ARG);
- SysTryReturnResult(NID_NET_WIFI, r == E_SUCCESS, r, "Failed to set eap authentication type.");
- }
-
- err = wifi_connect(pApHandle, OnWifiConnected, null);
- _WifiConvertErrorResult(err != WIFI_ERROR_NONE, r, E_FAILURE);
-
- return E_SUCCESS;
-}
-
-void
-_WifiSystemAdapter::OnWifiRssiLevelChanged(wifi_rssi_level_e rssiLevel, void *pUserData)
-{
- long rssi = _WifiUtility::ConvertLeveltoRssiValue(rssiLevel);
- _IWifiManagerEventListener* pMgrEvtListener = null;
- IEnumeratorT<_IWifiManagerEventListener*>* pEnum = null;
- _WifiSystemAdapter* pAdapter = _WifiSystemAdapter::GetInstance();
- pEnum = pAdapter->__mgrEvtListenerList.GetEnumeratorN();
-
- while (pEnum->MoveNext() == E_SUCCESS)
- {
- pEnum->GetCurrent(pMgrEvtListener);
-
- SysLog(NID_NET_WIFI, "Fire event [WIFI_EVENT_RSSI_LEVEL_CHANGED]");
- pMgrEvtListener->OnWifiRssiChanged(rssi);
- }
-
- delete pEnum;
-}
-
-const char*
-_WifiSystemAdapter::GetStringOfConnectionState(wifi_connection_state_e state)
-{
- const char* pStateStr[] =
- {
- "DISCONNECTED",
- "ASSOCIATION",
- "CONFIGURATION",
- "CONNECTED",
- };
-
- return pStateStr[state];
-}
-
-} } } // Tizen::Net::Wifi