QBluetoothZero  2.0
QBtSerialPortServer.h
Go to the documentation of this file.
00001 /*
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *      http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00016 #ifndef QBTSERIALPORTSERVER_H
00017 #define QBTSERIALPORTSERVER_H
00018 
00019 #include <QBtGlobal.h>
00020 #include <QBtTypes.h>
00021 #include <QBtServiceAdvertiser.h>
00022 #include <QtCore/QObject>
00023 #include <QtCore/QByteArray>
00024 
00025 #include <QBtUuid.h>
00026 
00027 QBT_NAMESPACE_BEGIN
00028 
00029 //forward declaration
00030 class QBtSerialPortServerPrivate;
00031 
00062 class DLL_EXPORT QBtSerialPortServer : public QObject
00063 {
00064     Q_OBJECT
00065 
00066 public:
00067     
00068     enum ErrorCode
00069     {
00070         ErrorAlreadyInUse,
00071         ErrorNotSupported,
00072         ErrorUnavailable,
00073         ErrorUndefinedError
00074     };
00075 
00076 public:
00077     QBtSerialPortServer(QObject* parent);
00078     ~QBtSerialPortServer();
00079 
00084     bool isConnected();
00085 
00091     const QBtService & getTransmittingServiceInfo() const;
00092 
00093 protected:
00094     void setTransmittingService (const QBtService& service);
00095 
00101     void setConnectionStatus(bool connected);
00102 
00109     void startAdvertisingService(const QBtService& service);
00110 
00116     void stopAdvertisingService();
00117 
00118 public slots:
00119     /*
00120      * When server is started, a custom bluetooth service is advertised
00121      * through QBtServiceAdvertiser. This service can be retrieved using
00122      * getTransmittingServiceInfo(). If needed, the user can set the name
00123      * of the transmitting service when calling this function.
00124      */
00125     void startServer (const QBtUuid & serviceId, const QString& serviceName = "My RFCOMM service");
00126 
00133     void stopServer();
00134 
00143     void sendData (const QString & data);
00144 
00145 signals:
00149     void serverStarted();
00150 
00155     void serverStopped();
00156 
00160     void clientConnected (const QBtAddress & clientAddress);
00161 
00166     void clientDisconnected();
00167 
00171     void dataSent();
00172 
00176     void dataReceived (const QString & data);
00177 
00181     void error (QBtSerialPortServer::ErrorCode code);
00182 
00183 private:
00184     // Service Advertiser
00185     QBtServiceAdvertiser* _advertiser;
00186     
00187     //transmitting service
00188     QBtService _service;
00189 
00190     //pointer to implementation
00191     QBtSerialPortServerPrivate *_implPtr;
00192 
00193     // status
00194     bool _isConnected;
00195     
00196     
00197     friend class QBtSerialPortServerPrivate;
00198     
00199 };
00200 
00201 QBT_NAMESPACE_END
00202 
00203 //Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtSerialPortServer))
00204 
00205 #endif // QBTSERIALPORTSERVER_H