Tizen 2.0 Release
[framework/osp/bluetooth.git] / src / FNetBtBluetoothOppServer.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 // @file    FNetBtBluetoothOppServer.cpp
18 // @brief   This is the implementation file for the BluetoothOppServer class.
19 //
20
21 #include <FBaseString.h>
22 #include <FNetBtBluetoothOppServer.h>
23 #include <FNetBtIBluetoothOppServerEventListener.h>
24 #include <FBaseSysLog.h>
25 #include <FSec_AccessController.h>
26 #include <FSys_SystemInfoImpl.h>
27 #include "FNetBt_BluetoothOppServerImpl.h"
28
29 using namespace Tizen::Security;
30
31 namespace Tizen { namespace Net { namespace Bluetooth
32 {
33
34 BluetoothOppServer::BluetoothOppServer(void)
35         : __pImpl(null)
36 {
37 }
38
39 BluetoothOppServer::~BluetoothOppServer(void)
40 {
41         delete __pImpl;
42 }
43
44 result
45 BluetoothOppServer::Construct(IBluetoothOppServerEventListener& listener)
46 {
47         result r = E_SUCCESS;
48         bool isBtSupported = false;
49
50         Tizen::System::_SystemInfoImpl::GetSysInfo(L"http://tizen.org/feature/network.bluetooth", isBtSupported);
51         SysTryReturnResult(NID_NET_BT, isBtSupported == true, E_UNSUPPORTED_OPERATION, "Bluetooth is not supported.");
52
53         SysAssertf(__pImpl == null,
54                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
55
56         __pImpl = new (std::nothrow) _BluetoothOppServerImpl;
57         SysTryReturnResult(NID_NET_BT, __pImpl != null, E_OUT_OF_MEMORY, "Creation of a _BluetoothOppServerImpl instance failed.");
58
59         r = __pImpl->Construct(listener);
60
61         if (r != E_SUCCESS)
62         {
63                 delete __pImpl;
64                 __pImpl = null;
65         }
66
67         return r;
68 }
69
70 result
71 BluetoothOppServer::AcceptPush(void)
72 {
73         result r = E_SUCCESS;
74
75         // Privilege check
76         r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
77         SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
78                         "The application does not have the privilege to call this method.");
79
80         // Check Construct
81         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
82
83         return __pImpl->AcceptPush();
84 }
85
86 result
87 BluetoothOppServer::RejectPush(void)
88 {
89         result r = E_SUCCESS;
90
91         // Privilege check
92         r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
93         SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
94                         "The application does not have the privilege to call this method.");
95
96         // Check Construct
97         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
98
99         return __pImpl->RejectPush();
100 }
101
102 result
103 BluetoothOppServer::SetDestinationPath(const Tizen::Base::String& dstPath)
104 {
105         // Check Construct
106         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
107
108         return __pImpl->SetDestinationPath(dstPath);
109 }
110
111 result
112 BluetoothOppServer::SetMinProgressInterval(int percent)
113 {
114         // Check Construct
115         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
116
117         return __pImpl->SetMinProgressInterval(percent);
118 }
119
120 result
121 BluetoothOppServer::StartService(const Tizen::Base::String& dstPath)
122 {
123         result r = E_SUCCESS;
124
125         // Privilege check
126         r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
127         SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
128                         "The application does not have the privilege to call this method.");
129
130         // Check Construct
131         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
132
133         return __pImpl->StartService(dstPath);
134 }
135
136 result
137 BluetoothOppServer::StopService(void)
138 {
139         result r = E_SUCCESS;
140
141         // Privilege check
142         r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
143         SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
144                         "The application does not have the privilege to call this method.");
145
146         // Check Construct
147         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
148
149         return __pImpl->StopService();
150 }
151
152 result
153 BluetoothOppServer::StopTransfer(void)
154 {
155         result r = E_SUCCESS;
156
157         // Privilege check
158         r = _AccessController::CheckUserPrivilege(_PRV_BLUETOOTH_OPP);
159         SysTryReturnResult(NID_NET_BT, r == E_SUCCESS, E_PRIVILEGE_DENIED,
160                         "The application does not have the privilege to call this method.");
161
162         // Check Construct
163         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
164
165         return __pImpl->StopTransfer();
166 }
167
168 } } } // Tizen::Net::Bluetooth