Modification about event handling for guaranteed caller thread
[platform/framework/native/net.git] / src / FNetNetAccountManagerPartner.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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                        FNetNetAccountManagerPartner.cpp
20  * @brief               This is the implementation for the %NetAccountManager class. (only partner visibility)
21  */
22
23 #include <net_connection.h>
24 #include <FNetNetAccountManager.h>
25 #include <FBaseSysLog.h>
26 #include <FSec_AccessController.h>
27 #include "FNet_NetTypes.h"
28 #include "FNet_NetAccountDatabase.h"
29 #include "FNet_NetAccountInfoImpl.h"
30 #include "FNet_NetAccountManagerImpl.h"
31 #include "FNet_NetConnectionManagerImpl.h"
32 #include "FNet_NetIpcProxy.h"
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Security;
36
37 namespace Tizen { namespace Net
38 {
39
40 result
41 NetAccountManager::UpdateSystemNetAccount(const NetAccountInfo& netAccountInfo)
42 {
43         result r = E_SUCCESS;
44         String profileName;
45         NetBearerType bearerType = netAccountInfo.GetBearerType();
46
47         SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
48
49         SysTryReturnResult(NID_NET, netAccountInfo.GetAccountId() > 0, E_INVALID_ARG,
50                         "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
51         SysTryReturnResult(NID_NET, !netAccountInfo.GetAccountName().IsEmpty(), E_INVALID_ARG,
52                         "Invalid argument is used. accountName is an empty string.");
53
54         r =  _NetAccountDatabase::GetProfileName(netAccountInfo.GetAccountId(), profileName);
55         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
56         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_INVALID_ARG,
57                         "Invalid argument is used. accountId=%d", netAccountInfo.GetAccountId());
58
59         _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
60         SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
61                         "A system error has been occurred. Failed to get an IPC proxy.");
62
63         r = pProxy->UpdateSystemNetAccount(profileName, netAccountInfo, bearerType);
64         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
65
66         r = _NetAccountDatabase::UpdateAccountName(netAccountInfo.GetAccountId(), netAccountInfo.GetAccountName());
67         SysTryReturnResult(NID_NET, r != E_OUT_OF_MEMORY, r, "Propagating.");
68         SysTryReturnResult(NID_NET, r == E_SUCCESS, E_SYSTEM,
69                         "A system error has been occurred. Failed to update account name.");
70
71         return r;
72 }
73
74 NetAccountId
75 NetAccountManager::GetAppNetAccountId(const String& netProfileName) const
76 {
77         result r = E_SUCCESS;
78         NetAccountId netAccountId = INVALID_HANDLE;
79
80         SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
81
82         _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
83         SysTryReturn(NID_NET, pProxy != null, INVALID_HANDLE, E_SYSTEM,
84                         "[%s] A system error has been occurred. Failed to get an IPC proxy.", GetErrorMessage(E_SYSTEM));
85
86         r = pProxy->GetAppNetAccountId(netProfileName, netAccountId);
87         SysTryReturn(NID_NET, r == E_SUCCESS, INVALID_HANDLE, r, "[%s] Propagating.", GetErrorMessage(r));
88
89         return netAccountId;
90 }
91
92 result
93 NetAccountManager::SetNetAccountId(NetAccountId netAccountId)
94 {
95         result r = E_SUCCESS;
96         NetAccountId netAccountId2 = INVALID_HANDLE;
97
98         SysAssertf(__pNetAccountManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
99
100         SysTryReturnResult(NID_NET, netAccountId > 0, E_INVALID_ARG,
101                         "Invalid argument is used. accountId=%d", netAccountId);
102
103         _NetConnectionManagerImpl* pConnectionManager = _NetConnectionManagerImpl::GetInstance();
104         SysTryReturnResult(NID_NET, pConnectionManager != null, E_SYSTEM,
105                         "A system error has been occurred. Failed to get NetConnectionManager instance.");
106
107         _NetIpcProxy* pProxy = _NetIpcProxy::GetInstance();
108         SysTryReturnResult(NID_NET, pProxy != null, E_SYSTEM,
109                         "A system error has been occurred. Failed to get an IPC proxy.");
110
111         r = pProxy->SetNetAccountId(netAccountId, netAccountId2);
112         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
113
114         r = pConnectionManager->SetManagedNetAccountId(netAccountId2);
115         SysTryReturnResult(NID_NET, r == E_SUCCESS, r, "Propagating.");
116
117         return r;
118 }
119
120 }} // Tizen::Net