Home | History | Annotate | Download | only in bluetooth
      1 // Copyright 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
      6 #define DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
      7 
      8 #include <string>
      9 
     10 #include "base/memory/ref_counted.h"
     11 #include "device/bluetooth/bluetooth_socket.h"
     12 
     13 #ifdef __OBJC__
     14 @class BluetoothRFCOMMChannelDelegate;
     15 @class IOBluetoothRFCOMMChannel;
     16 @class IOBluetoothSDPServiceRecord;
     17 #else
     18 class BluetoothRFCOMMChannelDelegate;
     19 class IOBluetoothRFCOMMChannel;
     20 class IOBluetoothSDPServiceRecord;
     21 #endif
     22 
     23 namespace net {
     24 
     25 class DrainableIOBuffer;
     26 class GrowableIOBuffer;
     27 
     28 }  // namespace net
     29 
     30 namespace device {
     31 
     32 class BluetoothServiceRecord;
     33 
     34 // This class is an implementation of BluetoothSocket class for OSX platform.
     35 class BluetoothSocketMac : public BluetoothSocket {
     36  public:
     37   // TODO(youngki): This method is deprecated; remove this method when
     38   // BluetoothServiceRecord is removed.
     39   static scoped_refptr<BluetoothSocket> CreateBluetoothSocket(
     40       const BluetoothServiceRecord& service_record);
     41 
     42   static scoped_refptr<BluetoothSocket> CreateBluetoothSocket(
     43       IOBluetoothSDPServiceRecord* record);
     44 
     45   // BluetoothSocket override
     46   virtual bool Receive(net::GrowableIOBuffer* buffer) OVERRIDE;
     47   virtual bool Send(net::DrainableIOBuffer* buffer) OVERRIDE;
     48   virtual std::string GetLastErrorMessage() const OVERRIDE;
     49 
     50   // called by BluetoothRFCOMMChannelDelegate.
     51   void OnDataReceived(IOBluetoothRFCOMMChannel* rfcomm_channel,
     52                       void* data,
     53                       size_t length);
     54 
     55  protected:
     56   virtual ~BluetoothSocketMac();
     57 
     58  private:
     59   explicit BluetoothSocketMac(IOBluetoothRFCOMMChannel* rfcomm_channel);
     60 
     61   void ResetIncomingDataBuffer();
     62 
     63   IOBluetoothRFCOMMChannel* rfcomm_channel_;
     64   BluetoothRFCOMMChannelDelegate* delegate_;
     65   scoped_refptr<net::GrowableIOBuffer> incoming_data_buffer_;
     66   std::string error_message_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(BluetoothSocketMac);
     69 };
     70 
     71 }  // namespace device
     72 
     73 #endif  // DEVICE_BLUETOOTH_BLUETOOTH_SOCKET_MAC_H_
     74