summaryrefslogtreecommitdiff
path: root/src/FNetBt_BluetoothSppSystemAdapter.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/FNetBt_BluetoothSppSystemAdapter.h')
-rw-r--r--src/FNetBt_BluetoothSppSystemAdapter.h203
1 files changed, 203 insertions, 0 deletions
diff --git a/src/FNetBt_BluetoothSppSystemAdapter.h b/src/FNetBt_BluetoothSppSystemAdapter.h
new file mode 100644
index 0000000..d741a9c
--- /dev/null
+++ b/src/FNetBt_BluetoothSppSystemAdapter.h
@@ -0,0 +1,203 @@
+//
+// 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 FNetBt_BluetoothSppSystemAdapter.h
+ * @brief This is the header file for the _BluetoothSppSystemAdapter class.
+ *
+ * This header file contains the declaration of the _BluetoothSppSystemAdapter class.
+ */
+#ifndef _FNET_BT_INTERNAL_BLUETOOTH_SPP_SYSTEM_ADAPTER_H_
+#define _FNET_BT_INTERNAL_BLUETOOTH_SPP_SYSTEM_ADAPTER_H_
+
+#include <unique_ptr.h>
+#include <bluetooth.h>
+#include <FBaseObject.h>
+#include <FBaseResult.h>
+#include <FNetBtBluetoothTypes.h>
+
+static const int _BT_INVALID_SOCKET_FD = -1;
+
+// forward declarations
+namespace Tizen { namespace Base {
+class ByteBuffer;
+class String;
+class UuId;
+
+namespace Collection {
+class ArrayList;
+template<class keyType, class valueType> class HashMapT;
+}
+} }
+
+namespace Tizen { namespace Net { namespace Bluetooth
+{
+
+// forward declarations
+class BluetoothDevice;
+class _IBluetoothSocketListener;
+
+/**
+ * @class _BluetoothSppSystemAdapter
+ * @brief This class provides functions related to RFCOMM socket (SPP) and have a role of adaptation OSP classes and the
+ * underlying subsystem. This class is a type of singleton, therefore only one instance should be allowed.
+ */
+class _BluetoothSppSystemAdapter
+ : public Tizen::Base::Object
+{
+public:
+ /**
+ * Creates an instance of this class if there is no instance in this application context.
+ * Gets the exist instance because this class is a singleton, otherwise.
+ *
+ * @return the instance of this class
+ */
+ static _BluetoothSppSystemAdapter* GetInstance(void);
+
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Server Socket
+ //-----------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Create and initialize a server socket, and start to listen the socket events. @n
+ * An instance of _IBluetoothSocketListener class is registered internally.
+ *
+ * @return An error code
+ * @param[in] serviceUuid The service UUID
+ * @param[in] listener The instance of _IBluetoothSocketListener to be registered
+ * @param[out] serverSocketFd The server socket FD
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SERVICE_UNAVAILABLE The service is not available.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result OpenServerSocket(const Tizen::Base::UuId& serviceUuid, _IBluetoothSocketListener& listener, int& serverSocketFd);
+
+ /**
+ * Close the specified server socket. @n
+ * All child sockets involved in this server socket will be automatically disconnected.
+ *
+ * @return An error code
+ * @param[in] serverSocketFd The server socket FD
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result CloseServerSocket(int serverSocketFd);
+
+ /**
+ * Accept the connection request received to the specified server socket. @n
+ * A new child socket is created if the accept is successful.
+ *
+ * @return An error code
+ * @param[in] serverSocketFd The server socket FD
+ * @param[out] socketFd The child socket FD for the connection
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result AcceptSocketRequest(int serverSocketFd, int& socketFd);
+
+ /**
+ * Reject the connection request received to the specified server socket.
+ *
+ * @return An error code
+ * @param[in] serverSocketFd The server socket FD
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result RejectSocketRequest(int serverSocketFd);
+
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // socket
+ //-----------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Connect with the specified server. @n
+ * A new socket FD can be acquired on
+ * OnSocketConnected() callback method invoked when the connection is completely established.
+ *
+ * @return An error code
+ * @param[in] serverAddress The address of the server
+ * @param[in] serviceUuid The service UUID
+ * @param[in] listener The socket event listener
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result ConnectSocket(const Tizen::Base::ByteBuffer& serverAddress, const Tizen::Base::UuId& serviceUuid,
+ _IBluetoothSocketListener& listener);
+
+ /**
+ * Close the connection related to the specified socket. @n
+ *
+ * @return An error code
+ * @param[in] socketFd The socket FD
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result DisconnectSocket(int socketFd);
+
+ /**
+ * Send data through the connection related to the specified socket. @n
+ *
+ * @return An error code
+ * @param[in] socketFd The socket FD
+ * @param[in] data The data to be sent
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_SYSTEM A system error has occurred.
+ */
+ result SendSocketData(int socketFd, const Tizen::Base::ByteBuffer& data);
+
+
+ //-----------------------------------------------------------------------------------------------------------------
+ // Callback methods
+ //-----------------------------------------------------------------------------------------------------------------
+
+ /**
+ * Callback called by the underlying system to notify that the RFCOMM server socket is received the connection request.
+ */
+ static void OnSocketConnectionRequested(int serverSocketFd, const char* pRemoteAddress, void* pUserData);
+
+ /**
+ * Callback called by the underlying system to notify that the connection state has changed to connected or disconnected.
+ */
+ static void OnSocketConnectionStateChanged(int status, bt_socket_connection_state_e connectionState,
+ bt_socket_connection_s* pConnectionInfo, void* pUserData);
+
+ /**
+ * Callback used by the underlying system to notify that data is received on the established connection.
+ */
+ static void OnSocketDataReceived(bt_socket_received_data_s* pData, void* pUserData);
+
+private:
+ _BluetoothSppSystemAdapter(void);
+ ~_BluetoothSppSystemAdapter(void);
+
+ _BluetoothSppSystemAdapter(const _BluetoothSppSystemAdapter& value);
+ _BluetoothSppSystemAdapter& operator =(const _BluetoothSppSystemAdapter& value);
+
+ bool Construct(void);
+
+ static void InitSingleton(void);
+
+private:
+ std::unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > __pServerSocketMap;
+ std::unique_ptr< Tizen::Base::Collection::HashMapT<int, _IBluetoothSocketListener*> > __pSocketMap;
+ std::unique_ptr< Tizen::Base::Collection::HashMapT<Tizen::Base::String, _IBluetoothSocketListener*> > __pClientSocketMap;
+ static _BluetoothSppSystemAdapter* __pInstance;
+}; // _BluetoothSppSystemAdapter
+
+} } }
+#endif // _FNET_BT_INTERNAL_BLUETOOTH_SPP_SYSTEM_ADAPTER_H_