#ifndef GATOSOCKET_H #define GATOSOCKET_H #include #include #include #include "gatoaddress.h" #include "gatoconnectionparameters.h" /** This class encapsulates a message-oriented bluetooth L2CAP socket. */ class GatoSocket : public QObject { Q_OBJECT Q_ENUMS(State) public: explicit GatoSocket(QObject *parent); ~GatoSocket(); enum State { StateDisconnected, StateConnecting, StateConnected }; enum Error { TimeoutError, UnknownError }; enum SecurityLevel { SecurityNone, SecurityLow, SecurityMedium, SecurityHigh }; State state() const; bool connectTo(const GatoAddress &addr, unsigned short cid); void close(); /** Dequeues a pending message from the rx queue. * Doesn't block: if there are no pending messages, returns null QByteArray. */ QByteArray receive(); /** Adds a message to the tx queue. */ void send(const QByteArray &pkt); SecurityLevel securityLevel() const; bool setSecurityLevel(SecurityLevel level); GatoConnectionParameters connectionParameters() const; bool setConnectionParameters(const GatoConnectionParameters ¶ms); signals: void connected(); void disconnected(); void error(Error error); void readyRead(); private: bool transmit(const QByteArray &pkt); private slots: void readNotify(); void writeNotify(); private: State s; int fd; SecurityLevel desiredSec; GatoConnectionParameters desiredParams; QSocketNotifier *readNotifier; QQueue readQueue; QSocketNotifier *writeNotifier; QQueue writeQueue; }; #endif // GATOSOCKET_H