2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 namespace Tizen.Network.Bluetooth
23 /// A class which is used to handle the connection and send and receive the object over Opp profile.
25 /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
26 public class BluetoothOppServer
28 private static BluetoothOppServerImpl _impl;
29 private static BluetoothOppServer _instance;
34 public BluetoothOppServer()
36 _impl = BluetoothOppServerImpl.Instance;
40 /// (event) ConnectionRequested is called when OPP client requests for connection.
42 public event EventHandler<ConnectionRequestedEventArgs> ConnectionRequested
46 _impl.ConnectionRequested += value;
50 _impl.ConnectionRequested -= value;
55 /// (event) TransferProgress is called when the file transfer state is changed.
57 public event EventHandler<TransferProgressEventArgs> TransferProgress
61 _impl.TransferProgress += value;
65 _impl.TransferProgress -= value;
70 /// (event) TransferFinished is called when the file tranfser is completed.
72 public event EventHandler<TransferFinishedEventArgs> TransferFinished
76 _impl.TransferFinished += value;
80 _impl.TransferFinished -= value;
84 /// Register the Opp Server with the Opp service.
87 /// The device must be bonded with remote device by CreateBond().
88 /// If connection request is received from OPP Client, ConnectionRequested event will be invoked.
90 /// <param name="FilePath"> Path to store the files.</param>
91 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
92 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
93 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
94 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
95 public static BluetoothOppServer StartServer(string FilePath)
97 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
99 if (_instance == null)
101 BluetoothOppServer server = new BluetoothOppServer();
105 int ret = _impl.StartServer(FilePath);
106 if (ret != (int)BluetoothError.None)
108 Log.Error(Globals.LogTag, "Failed to Opp Start Server - " + (BluetoothError)ret);
109 BluetoothErrorFactory.ThrowBluetoothException(ret);
115 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
121 /// Stops the Opp Server.
123 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
124 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
125 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
126 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
127 public void StopServer()
129 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
131 int ret = _impl.StopServer();
132 if (ret != (int)BluetoothError.None)
134 Log.Error(Globals.LogTag, "Failed to Stop the Opp Server - " + (BluetoothError)ret);
135 BluetoothErrorFactory.ThrowBluetoothException(ret);
139 if (_instance != null)
145 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
150 /// Accept File Push request.
152 /// <param name="FileName"> File name to accept.</param>
153 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
154 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
155 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
156 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
157 public int AcceptPush(string FileName)
159 int _transitionId = -1;
160 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
162 int ret = _impl.AcceptPush(FileName, out _transitionId);
163 if (ret != (int)BluetoothError.None)
165 Log.Error(Globals.LogTag, "Failed to Accept Push - " + (BluetoothError)ret);
166 BluetoothErrorFactory.ThrowBluetoothException(ret);
171 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
173 return _transitionId;
177 /// Reject File Push request.
179 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
180 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
181 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
182 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
183 public void RejectPush()
185 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
187 int ret = _impl.RejectPush();
188 if (ret != (int)BluetoothError.None)
190 Log.Error(Globals.LogTag, "Failed to Reject Push - " + (BluetoothError)ret);
191 BluetoothErrorFactory.ThrowBluetoothException(ret);
196 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
201 /// Cancel the ongoing transfer session.
203 /// <param name="TransferId"> tranfer ID.</param>
204 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
205 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
206 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
207 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
208 public void CancelTransfer(int TransferId)
210 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
212 int ret = _impl.CancelTransferId(TransferId);
213 if (ret != (int)BluetoothError.None)
215 Log.Error(Globals.LogTag, "Failed to Cancel Transfer - " + (BluetoothError)ret);
216 BluetoothErrorFactory.ThrowBluetoothException(ret);
221 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
226 /// Cancel the ongoing transfer session.
228 /// <param name="FilePath"> Path to store the files.</param>
229 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
230 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
231 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
232 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
233 public void SetDestinationPath(string FilePath)
235 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
237 int ret = _impl.SetDestinationPath(FilePath);
238 if (ret != (int)BluetoothError.None)
240 Log.Error(Globals.LogTag, "Failed to Set Destination Path - " + (BluetoothError)ret);
241 BluetoothErrorFactory.ThrowBluetoothException(ret);
246 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
252 /// A class which is used to handle the connection and send and receive the object over Opp profile.
254 /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
255 public class BluetoothOppClient : BluetoothProfile
257 internal BluetoothOppClient()
262 /// (event) PushResponded is called when remote OPP Server responds to a File push request.
264 public event EventHandler<PushRespondedEventArgs> PushResponded
268 BluetoothOppClientImpl.Instance.PushResponded += value;
272 BluetoothOppClientImpl.Instance.PushResponded -= value;
277 /// (event) PushProgress is called when the file transfer state is changed.
279 public event EventHandler<PushProgressEventArgs> PushProgress
283 BluetoothOppClientImpl.Instance.PushProgress += value;
287 BluetoothOppClientImpl.Instance.PushProgress -= value;
292 /// (event) PushFinished is called when the file tranfser is completed.
294 public event EventHandler<PushFinishedEventArgs> PushFinished
298 BluetoothOppClientImpl.Instance.PushFinished += value;
302 BluetoothOppClientImpl.Instance.PushFinished -= value;
307 /// Add File path to be pushed.
309 /// <param name="FilePath"> file for sending.</param>
310 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
311 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
312 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
313 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
314 public void AddFile(string FilePath)
316 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
318 int ret = BluetoothOppClientImpl.Instance.AddFile(FilePath);
319 if (ret != (int)BluetoothError.None)
321 Log.Error(Globals.LogTag, "Failed to Set File Path - " + (BluetoothError)ret);
322 BluetoothErrorFactory.ThrowBluetoothException(ret);
327 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
332 /// Clears all the File paths.
334 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
335 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
336 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
337 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
338 public void ClearFiles()
340 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
342 int ret = BluetoothOppClientImpl.Instance.ClearFile();
343 if (ret != (int)BluetoothError.None)
345 Log.Error(Globals.LogTag, "Failed to Clear the Files - " + (BluetoothError)ret);
346 BluetoothErrorFactory.ThrowBluetoothException(ret);
351 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
356 /// Cancels the ongoing push session.
358 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
359 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
360 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
361 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
362 public void CancelPush()
364 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
366 int ret = BluetoothOppClientImpl.Instance.CancelPush();
367 if (ret != (int)BluetoothError.None)
369 Log.Error(Globals.LogTag, "Failed to Cancel Push Operation - " + (BluetoothError)ret);
370 BluetoothErrorFactory.ThrowBluetoothException(ret);
375 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
380 /// Pushes the file set through AddFile.
382 /// <param name="Destination"> destination device address.</param>
383 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
384 /// <exception cref="NotSupportedException">Thrown when the required feature is not Supported.</exception>
385 /// <exception cref="NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
386 /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
387 public void PushFile(string Destination)
389 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
391 int ret = BluetoothOppClientImpl.Instance.PushFile(Destination);
392 if (ret != (int)BluetoothError.None)
394 Log.Error(Globals.LogTag, "Failed to Cancel Push Operation - " + (BluetoothError)ret);
395 BluetoothErrorFactory.ThrowBluetoothException(ret);
400 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);