Home | History | Annotate | Download | only in wire
      1 // Copyright 2012 Google Inc. All Rights Reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //     http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 #ifndef POLO_WIRE_POLOWIREINTERFACE_H_
     16 #define POLO_WIRE_POLOWIREINTERFACE_H_
     17 
     18 #include <stddef.h>
     19 #include <vector>
     20 
     21 #include "polo/wire/polowirelistener.h"
     22 #include "polo/util/macros.h"
     23 
     24 namespace polo {
     25 namespace wire {
     26 
     27 // An interface for sending and receiving raw data for a Polo pairing session.
     28 class PoloWireInterface {
     29  public:
     30   PoloWireInterface() {}
     31   virtual ~PoloWireInterface() {}
     32 
     33   // Sets the listener that will receive incoming data and error notifications.
     34   // @param listener the listener to set for this interface
     35   void set_listener(PoloWireListener* listener) { listener_ = listener; }
     36 
     37   // Sends data over the interface.
     38   // @param data the bytes to send
     39   virtual void Send(const std::vector<uint8_t>& data) = 0;
     40 
     41   // Receives the given number of bytes from the interface asynchronously. The
     42   // listener will be notified when the data is received.
     43   // @param num_bytes the number of bytes to receive
     44   virtual void Receive(size_t num_bytes) = 0;
     45 
     46  protected:
     47   // Gets the listener that will receive incoming data and error notifications.
     48   PoloWireListener* listener() const { return listener_; }
     49 
     50  private:
     51   PoloWireListener* listener_;
     52 
     53   DISALLOW_COPY_AND_ASSIGN(PoloWireInterface);
     54 };
     55 
     56 }  // namespace wire
     57 }  // namespace polo
     58 
     59 #endif  // POLO_WIRE_POLOWIREINTERFACE_H_
     60