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;
31 public BluetoothOppServer()
33 _impl = BluetoothOppServerImpl.Instance;
37 /// (event) ConnectionRequested is called when OPP client requests for connection.
39 public event EventHandler<ConnectionRequestedEventArgs> ConnectionRequested
43 _impl.ConnectionRequested += value;
47 _impl.ConnectionRequested -= value;
52 /// (event) TransferProgress is called when the file transfer state is changed.
54 public event EventHandler<TransferProgressEventArgs> TransferProgress
58 _impl.TransferProgress += value;
62 _impl.TransferProgress -= value;
67 /// (event) TransferFinished is called when the file tranfser is completed.
69 public event EventHandler<TransferFinishedEventArgs> TransferFinished
73 _impl.TransferFinished += value;
77 _impl.TransferFinished -= value;
81 /// Register the Opp Server with the Opp service.
84 /// The device must be bonded with remote device by CreateBond().
85 /// If connection request is received from OPP Client, ConnectionRequested event will be invoked.
87 /// <param name="FilePath"> Path to store the files.</param>
88 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
89 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
90 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
91 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
92 public static BluetoothOppServer StartServer(string FilePath)
94 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
96 if (_instance == null)
98 BluetoothOppServer server = new BluetoothOppServer();
102 int ret = _impl.StartServer(FilePath);
103 if (ret != (int)BluetoothError.None)
105 Log.Error(Globals.LogTag, "Failed to Opp Start Server - " + (BluetoothError)ret);
106 BluetoothErrorFactory.ThrowBluetoothException(ret);
112 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
118 /// Stops the Opp Server.
120 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
121 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
122 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
123 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
124 public void StopServer()
126 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
128 int ret = _impl.StopServer();
129 if (ret != (int)BluetoothError.None)
131 Log.Error(Globals.LogTag, "Failed to Stop the Opp Server - " + (BluetoothError)ret);
132 BluetoothErrorFactory.ThrowBluetoothException(ret);
136 if (_instance != null)
142 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
147 /// Accept File Push request.
149 /// <param name="FileName"> File name to accept.</param>
150 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
151 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
152 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
153 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
154 public int AcceptPush(string FileName)
156 int _transitionId = -1;
157 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
159 int ret = _impl.AcceptPush(FileName, out _transitionId);
160 if (ret != (int)BluetoothError.None)
162 Log.Error(Globals.LogTag, "Failed to Accept Push - " + (BluetoothError)ret);
163 BluetoothErrorFactory.ThrowBluetoothException(ret);
168 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
170 return _transitionId;
174 /// Reject File Push request.
176 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
177 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
178 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
179 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
180 public void RejectPush()
182 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
184 int ret = _impl.RejectPush();
185 if (ret != (int)BluetoothError.None)
187 Log.Error(Globals.LogTag, "Failed to Reject Push - " + (BluetoothError)ret);
188 BluetoothErrorFactory.ThrowBluetoothException(ret);
193 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
198 /// Cancel the ongoing transfer session.
200 /// <param name="TransferId"> tranfer ID.</param>
201 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
202 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
203 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
204 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
205 public void CancelTransfer(int TransferId)
207 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
209 int ret = _impl.CancelTransferId(TransferId);
210 if (ret != (int)BluetoothError.None)
212 Log.Error(Globals.LogTag, "Failed to Cancel Transfer - " + (BluetoothError)ret);
213 BluetoothErrorFactory.ThrowBluetoothException(ret);
218 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
223 /// Cancel the ongoing transfer session.
225 /// <param name="FilePath"> Path to store the files.</param>
226 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
227 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
228 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
229 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
230 public void SetDestinationPath(string FilePath)
232 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
234 int ret = _impl.SetDestinationPath(FilePath);
235 if (ret != (int)BluetoothError.None)
237 Log.Error(Globals.LogTag, "Failed to Set Destination Path - " + (BluetoothError)ret);
238 BluetoothErrorFactory.ThrowBluetoothException(ret);
243 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
249 /// A class which is used to handle the connection and send and receive the object over Opp profile.
251 /// <privilege> http://tizen.org/privilege/bluetooth </privilege>
252 public class BluetoothOppClient : BluetoothProfile
254 internal BluetoothOppClient()
259 /// (event) PushResponded is called when remote OPP Server responds to a File push request.
261 public event EventHandler<PushRespondedEventArgs> PushResponded
265 BluetoothOppClientImpl.Instance.PushResponded += value;
269 BluetoothOppClientImpl.Instance.PushResponded -= value;
274 /// (event) PushProgress is called when the file transfer state is changed.
276 public event EventHandler<PushProgressEventArgs> PushProgress
280 BluetoothOppClientImpl.Instance.PushProgress += value;
284 BluetoothOppClientImpl.Instance.PushProgress -= value;
289 /// (event) PushFinished is called when the file tranfser is completed.
291 public event EventHandler<PushFinishedEventArgs> PushFinished
295 BluetoothOppClientImpl.Instance.PushFinished += value;
299 BluetoothOppClientImpl.Instance.PushFinished -= value;
304 /// Add File path to be pushed.
306 /// <param name="FilePath"> file for sending.</param>
307 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
308 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
309 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
310 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
311 public void AddFile(string FilePath)
313 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
315 int ret = BluetoothOppClientImpl.Instance.AddFile(FilePath);
316 if (ret != (int)BluetoothError.None)
318 Log.Error(Globals.LogTag, "Failed to Set File Path - " + (BluetoothError)ret);
319 BluetoothErrorFactory.ThrowBluetoothException(ret);
324 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
329 /// Clears all the File paths.
331 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
332 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
333 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
334 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
335 public void ClearFiles()
337 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
339 int ret = BluetoothOppClientImpl.Instance.ClearFile();
340 if (ret != (int)BluetoothError.None)
342 Log.Error(Globals.LogTag, "Failed to Clear the Files - " + (BluetoothError)ret);
343 BluetoothErrorFactory.ThrowBluetoothException(ret);
348 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
353 /// Cancels the ongoing push session.
355 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
356 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
357 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
358 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
359 public void CancelPush()
361 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
363 int ret = BluetoothOppClientImpl.Instance.CancelPush();
364 if (ret != (int)BluetoothError.None)
366 Log.Error(Globals.LogTag, "Failed to Cancel Push Operation - " + (BluetoothError)ret);
367 BluetoothErrorFactory.ThrowBluetoothException(ret);
372 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);
377 /// Pushes the file set through AddFile.
379 /// <param name="Destination"> destination device address.</param>
380 /// <feature>http://tizen.org/feature/network.bluetooth.opp</feature>
381 /// <exception cref="System.NotSupportedException">Thrown when the required feature is not Supported.</exception>
382 /// <exception cref="System.NotSupportedException">Thrown when the BT/BTLE is not Supported.</exception>
383 /// <exception cref="System.InvalidOperationException">Thrown when the BT/BTLE is not Enabled or Other Bluetooth Errors.</exception>
384 public void PushFile(string Destination)
386 if (BluetoothAdapter.IsBluetoothEnabled && Globals.IsInitialize)
388 int ret = BluetoothOppClientImpl.Instance.PushFile(Destination);
389 if (ret != (int)BluetoothError.None)
391 Log.Error(Globals.LogTag, "Failed to Cancel Push Operation - " + (BluetoothError)ret);
392 BluetoothErrorFactory.ThrowBluetoothException(ret);
397 BluetoothErrorFactory.ThrowBluetoothException((int)BluetoothError.NotEnabled);