code:
/*
 * QBtObjectExchangeClient.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTOBJECTEXCHANGECLIENT_H_
#define QBTOBJECTEXCHANGECLIENT_H_

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QBtServiceAdvertiser.h>
#include <QtCore/QObject>

QBT_NAMESPACE_BEGIN

//forward declaration
class QBtObjectExchangeClientPrivate;

/**
 * Class that provides the mechanism to connect to a remote
 * OBEX server and send or recieve files or raw data.
 *
 * After instantiation user can call connectToServer(QBtDevice&, QBtService&)
 * to connect to the remote server specified by the remoteDevice argument
 * to its service provide by remoteService argument.
 *
 *  P.S. At the remote service, one of the supported protocols must be
 * QBtConstants::OBEX. Suggestion, use a service whose class is equal to
 * QBtConstants::OBEXObjectPush or QBtConstants::OBEXFileTransfer.
 * Again, it is suggested to use QBtConstants::OBEXObjectPush.
 * Both options will work fine if the user wants to send a file to
 * the server, but at present further operations can be done using
 * QBtConstants::OBEXObjectPush.
 *
 * Signal connectedToServer() is emitted upon successfull connection to the OBEX server.
 *
 * After the successfull connection to the server, user can call putFile(const QString&)
 * to send to the remote server the file specified by the string passed as argument.
 * If successfull then objectSent() signal is emitted.
 *
 * Also user is able to send a request to get a file from the remote server specifing
 * the absolute path of the file to be fetched at the remote device's file system.
 * Also a local path must be set which is where the file will be stored after the
 * successfull transfer.
 * getFile(const QString& localPath, const QString& remoteFileNameFull)
 * If successfull then fileReceived(const QString) is emitted.
 *
 * getByteBuffer() and putByteBuffer() are implemented but not tested.
 * If successfull they emit dataReceived(const QByteArray) and objectSent() respectively.
 *
 * If connected to an OBEX FTP bluetooth service then setPath() can be called
 * to set the remote working directory. If successfull then remotePathSet(const QString)
 * will be emitted.
 *
 * User can abort any transmittion in progress by calling abort().
 *
 * User can disconnect from the server at any time or the disconnection will take place at
 * destruction time. Any transmittion in progress will be terminated instantly.
 * A successfull disconnection emits disconnectedFromServer() signal.
 */
class DLL_EXPORT QBtObjectExchangeClient : public QObject
{
    Q_OBJECT

public:
    enum ErrorCode{
        OBEXClientConnectionError,
        OBEXClientSendError,
        OBEXClientReceiveError,
        OBEXClientDisconnected,
        OBEXClientInUse,
        OBEXClientInternalError,
        OBEXClientNoSelectedDevice,
        OBEXClientNoSelectedService,
        OBEXClientUnableToSetPath,
		OBEXFeatureNotSupported,
		OBEXClientBrowseError
    };

public:
    QBtObjectExchangeClient(QObject* parent);
    ~QBtObjectExchangeClient();

    /**
     * connectToServer()
     *
     * Connect to a remote server defined by parameter 1 to its service
     * defined by parameter 2.
     *
     * P.S. At the remote service, one of the supported protocols must be
     * QBtConstants::OBEX. Suggestion, use a service whose class is equal to
     * QBtConstants::OBEXObjectPush or QBtConstants::OBEXFileTransfer.
     * Again, it is suggested to use QBtConstants::OBEXObjectPush.
     * Both options will work fine if the user wants to send a file to
     * the server, but at present further operations can be done using
     * QBtConstants::OBEXObjectPush.
     *
     * @param remoteDevice
     * @param remoteService
     */
    void connectToServer(const QBtDevice& remoteDevice, const QBtService& remoteService);

    /**
     * getFile()
     * Get a file from the remote Server
     *
     * @param localPath the path where the file will be saved
     * @param remoteFileNameFull the name of the file to be transfered
     *							containing the full path of its remote location
     */
    void getFile(const QString& remoteFileAbsolutePath, const QString& destinationFolder);

    /**
     * getByteBuffer(const QString& dataName)
     * Request from the server to GET the data buffer defined in the argument
     *
     * @param dataName The name of the buffer.
     */
    void getByteBuffer(const QString& dataName);

    /**
     * Send a specified file from the local file system to the remote
     * OBEX server.
     *
     * @param fileName The file name of the file to be sent. The absolute
     *                 path of the file is required.
     */
    void putFile(const QString& fileName);

    /**
     * putByteBuffer()
     *
     * send the server a byte sequence.
     * @param data,  the data of the buffer
     * @param bufferName, the name of the buffer (used for convenience on the data
     * 		processing of the server)
     */
    void putByteBuffer(const QByteArray& data, const QString& bufferName);

    /**
     * abort()
     *
     * abort any panding or running transmittion.
     */
    void abort();

    /**
     * setPath(const QString path)
     *
     * Set the current path of the remote device OBEX session.
     * @param path The remote folder to be set as current
     */
    void setPath(const QString & path);

	/**
	 * getWorkingPath
	 *
	 *	ONLY FOR WINDOWS
	 *
	 * Return as QString holding the absolute path of the current working directory
	 */
        QString getWorkingPath();

	/**
	 *	initiateFolderBrowsing()
	 *
	 *	ONLY FOR WINDOWS
	 *
	 *	Browse the files of a selected folder.
	 *
	 *  @param folder The folder path must either be absolute (e.g. \E:\Images), or it must be the name of the folder
	 *  you are going to browse as long as the folder is inside the current working directory of yours.
	 *
	 *  @return QList<QBtRemoteFileInfo*> a list of the files/folders found and their attributes
	 */
	QList<QBtRemoteFileInfo*> initiateFolderBrowsing(const QString& folderPath = "");

	/**
	 *	locateFiles
	 *
	 *	ONLY FOR WINDOWS
	 *
	 *	Locate files/folders that comply to the regex passed as arguments. For example can be used to isolate
	 *	files of specific type.
	 *
	 *	@param regex The regex that describes the files that are needed to be selected. If this parameter is not set, the default
	 *	operation is to select all the files in the specified folder.
	 *
	 *	@param folder The folder path must either be absolute (e.g. \E:\Images), or it must be the name of the folder
	 *  you are going to browse as long as the folder is inside the current working directory of yours. If this parameter is not set,
	 *	the default operation is to search in the current working directory.
	 */
	QList<QBtRemoteFileInfo*> locateFiles(QRegExp* regex=0, QString folder="");

	/**
	 *	batchFileRetrieval
	 *
	 *	ONLY FOR WINDOWS
	 *
	 *	Convenient method to retrieve multiple files in the row.
	 *
	 *	@param files The list of files to retrieve
	 *	@param destinationFolder The folder in the local file system where the files will be stored. The files are placed all
	 *	in that directory same directory so the structure in the remote file system is not preserved.
	 *	@param retrieveOnlyNewFiles If set true, then it first check if the file defined already exists in the
	 *	destination folder. If it does then it skips it. By default it is set to copy every file it founds.
	 */
	void batchFileRetrieval(const QList<QBtRemoteFileInfo*>& files,
		const QString destinationFolder,
		bool retrieveOnlyNewFiles = false);

    /**
     * Get info about the service connected to.
     * @return An object containing the service info
     */
    QBtService& getTransmittingService();

    /**
     * Get info about the server connected to.
     * @return An object containing the remote server device info.
     */
    QBtDevice& getServerDevice();

    /**
     * Checks if the client is performing some operation.
     */
    bool isBusy() const;

    /**
     * Checks if the client got a connection (it does not check *now* if the client is still connected).
     */
    bool isConnected() const;

public slots:
    void disconnect();

signals:

    /**
     * Emitted in case of error
     */
    void error(QBtObjectExchangeClient::ErrorCode code);

    /**
     * Emitted upon successfull connection to the OBEX server.
     */
    void connectedToServer();

    /**
     * Emitted upon disconnection from the server.
     */
    void disconnectedFromServer();

    /**
     * Emitted upon successfull transmittion of an object
     */
    void objectSent();

    /**
     * Emitted when a file is received from the server
     */

    void fileReceived (const QString & fileName);

    /**
     * Emitted when a byte buffer is received from the server
     */
    void dataReceived (const QByteArray & data);

    /**
     * Emitted upon successfull set of the remote current working directory.
     */
    void remotePathSet (const QString & pathName);

	/**
	 *	Emitted after calling initiateFolderBrowsing function for every result
	 *	found from browsing.
	 *
	 *	@param file The file info. See QBtRemoteFileInfo class for the info provided.
	 */
	void folderBrowsingResultElement(const QBtRemoteFileInfo& file);

private:
    friend class QBtObjectExchangeClientPrivate;
    QBtObjectExchangeClientPrivate* _implPtr;
};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtObjectExchangeClient))

#endif /* QBTOBJECTEXCHANGECLIENT_H_ */


code:
/*
 * QBtObjectExchangeServer.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTOBJECTEXCHANGESERVER_H_
#define QBTOBJECTEXCHANGESERVER_H_

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QBtServiceAdvertiser.h>
#include <QtCore/QObject>

QBT_NAMESPACE_BEGIN

//Forward declaration
class QBtObjectExchangeServerPrivate;

// suggestion: (LV)
//
// use smart pointers for the service advertiser and reset it when
// 'startServer' is called

/**
 * This class is used to create an OBEX server.
 * After instantiation user can call startServer(const QString&)
 * to start the server. From the serviceName argument user can
 * specify the name of the OBEX service which is how the service will
 * be identified by other devices. By default the name is MyOBEX.
 *
 * If sever started successfully and is ready to use then serverStarted() signal is emitted.
 * At destruction time or if user calls stopServer(),terminates the service transmittion
 * and disconnects from any device connected and serverStopped() signal is emitted.
 *
 * All the remaining signals are only for feedback in case any action that is done.
 */
class DLL_EXPORT QBtObjectExchangeServer : public QObject
{
    Q_OBJECT

public:
    enum ErrorCode{
        QObexServerUndefined,
        QObexServerFailedToInitialize,
        QObexServerInUse,
        QObexServerClientAbortedTransfer,
        QObexServerAbortedTransmission,
        QObexServerSessionError,
        QObexServerSessionPutRequestProblem,
        QObexServerSessionCopyFileError
    };

public:
    QBtObjectExchangeServer(QObject* parent);
    ~QBtObjectExchangeServer();

    /**
     * Returns true if the server is connected.
     */
    bool isConnected();

    /**
     * If startServer() function is already called then using this function
     * the user can acquire the information of the transmitting service that
     * represents this server to the outside world.
     */
    QBtService& getTransmittingServiceInfo();

protected:
    void setTransmittingService(const QBtService& service);

    /**
     * Initializes a new advertiser and starts the transmitting of the
     * service passed as argument.
     */
    void startAdvertisingService(const QBtService& service);

    /**
     * Stops the transmittion of the service (if any)
     */
    void stopAdvertisingService();

public slots:
    /**
     *
     * Starts OBEX server by initializing the components needed
     * and by advertising the service by which the server will
     * be identified by other devices.
     */
    void startServer (const QBtUuid & serviceId, const QString& serviceName = "My OBEX Service");

    /**
     * Stops the server, terminates the service transmittion and disconnects
     * from any device connected
     */
    void stopServer();

signals:

    /**
     * Emitted when server is successfully started and ready to use.
     */
    void serverStarted();

    /**
     * Emitted when server is disconnected and stopped
     */
    void serverStopped();

    /**
     * Emitted in case of error
     */
    void error(ErrorCode code);

    /**
     * Emitted as a feedback of the running receive status of
     * any data (file or byte buffer)
     */
    void receivingObjectInfo(int overalDataSize, int bytesSent);

    /**
     * Emitted when the transmittion of a file or byte buffer is started from a remote client
     * to the local device.
     */
    void receivingStarted();

    /**
     * Emitted when a receiving of a file or byte buffer is stopped,
     * being successfull or not.
     *
     * @param receivedFileName
     */
    void receivingStopped (const QString & receivedFileName);

    /**
     * If the server (local device) sends a request to start a transmittion to the remote client
     * connected, the client reserves the right to deny the transmittion before it begins.
     * In that case transmittingRejected() is emitted.
     */
    void transmittingRejected();

    /**
     * Emitted as a feedback of the running transmittion status of
     * any data (file or byte buffer)	 *
     */
    void transmittingObjectInfo(int overalDataSize, int byteSent);

    /**
     * Emitted when a transmittion is started from the local device to a remote device.
     */
    void transmittingStarted (const QString & transmittingfileName);

    /**
     * Emitted upon successfull or not end of transmittion from
     * the local device to a remote client.
     */
    void transmittingStopped (const QString & transmittingfileName);

    /**
     * Emitted if during a transmittion the client aborts it.
     */
    void clientAbortedTransmittion();

private:
    QBtServiceAdvertiser* 			_advertiser;
    QBtService* 					_service;
    QBtObjectExchangeServerPrivate* _implPtr;
    bool 							_isConnected;

    friend class QBtObjectExchangeServerPrivate;
};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtObjectExchangeServer))

#endif /* QBTOBJECTEXCHANGESERVER_H_ */

repo_name: snapshot/qbluetooth

license: unknown


code:
#ifndef QBTREMOTEFILEINFO_H
#define QBTREMOTEFILEINFO_H

#include <QString>
#include <QObject>
#include <QBtGlobal.h>
#include <QDate>

QBT_NAMESPACE_BEGIN

class DLL_EXPORT QBtRemoteFileInfo : public QObject{
	Q_OBJECT
public:
	QBtRemoteFileInfo(QObject* parent=0);
	QBtRemoteFileInfo(const QBtRemoteFileInfo& fileInfo);
	QString toString();
	QBtRemoteFileInfo& operator=(const QBtRemoteFileInfo& fileInfo);

public:
	QString absolutePath;
	QString fileName;
	QString path;
	bool isDir;
	int type;
	int size;

	QDate creationTime;
	QDate lastAccessTime;
	QDate lastWriteTime;
};

QBT_NAMESPACE_END

Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtRemoteFileInfo))

#endif // QBTREMOTEFILEINFO_H


code:
/*
 * QBtSerialPortClient.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTSERIALPORTCLIENT_H_
#define QBTSERIALPORTCLIENT_H_

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QtCore/QObject>
#include <QtCore/QByteArray>

QBT_NAMESPACE_BEGIN

//forward declaration
class QBtSerialPortClientPrivate;

/**
 * Class that provides the mechanism to connect to a bluetooth serial port
 * server and communicate.
 *
 * Calling connect(const QBtDevice&, const QBtService&) user specifies
 * on which device to connect(on which serial port server) and on which
 * bluetooth service. The QBtDevice instance of the server can be
 * aquired using QBtDeviceDiscoverer or user can create his own instance
 * and set at least the QBtAddress field. Also the QBtService can be
 * aquired using QBtServiceDiscoverer targeting the beforementioned device.
 *
 * On successfull connection, connectedToServer() singal is emitted and
 * user is able to sendData(const QString&) to the server. If successfull
 * then dataSend() signal is emitted.
 *
 * If data is recieved from the server, dataReceived(const QString) signal is
 * emitted containing the bytes recieved. At this point user must be carefull
 * to read the data recieved using the same encoding as the sender (in this
 * case serial port server). QString contains all the necessary functions for
 * character encoding that is why is QString is used instead of QByteArray.
 *
 * When connection is no longer needed, disconnect() can be called.
 * disconnectedFromServer() is then emitted.
 *
 * In case of error error(QBtSerialPortClient::ErrorCode) signal is emitted.
 */
class DLL_EXPORT QBtSerialPortClient : public QObject
{
    Q_OBJECT

public:
    enum ErrorCode
    {
        ErrorAlreadyInUse,
        ErrorNotSupported,
        ErrorUnavailable,
        ErrorOpeningConnection,
        ErrorAlreadyConnected,
        ErrorUndefinedError,
        ErrorUnableToInitializePort,
        ErrorNoDeviceSelected,
        ErrorNoServiceSelected,
        ErrorConnectionError,
        ErrorConnectionTimeout,
        ErrorOnDisconnecting
    };

public:
    /**
     * A Serial port client.
     * According to the bluetooth specification, up to 7 instances of this class
     * can be connected simultaneously to other servers.
     */
    QBtSerialPortClient(QObject* parent);

    /**
     * Destructor.
     *
     * If isConnected() then disconnect() is called.
     */
    ~QBtSerialPortClient();

    /**
     * isConnected()
     *
     * Returns whether or not the client is connected to a remote server.
     */
    bool isConnected();

public slots:
    /**
     * connect()
     * RemoteDevice must contain at least the device address.
     * and remoteService at least a class ID (in case of SerialPort port field is also needed).
     * The remoteService info can be acquired by QBtServiceDiscoverer.
     */
    void connect(const QBtDevice& remoteDevice, const QBtService& remoteService);

    /**
     * disconnect()
     * Disconnects from the remote server if previously succusfully connected.
     */
    void disconnect();

    /**
     * sendData()
     * Send a string to the server.
     * If text is transmitted, it is up to the user to decide which text encoding to use.
     * Upon succesfull transmittion, dataSent() signal is emitted.
     */
    void sendData(const QString& data);

    /**
     * Send a array of bytes to the server, as is.
     * Upon succesfull transmittion, dataSent() signal is emitted.
     */
    void sendData (const QByteArray & data);

signals:
    /**
     * Emitted when successfully disconnected from the remote server (initiated from client).
     */
    void disconnectedFromServer();

    /**
     * Emitted when the server initiated a disconnection.
     */
    void connectionResetByPeer ();

    /**
     * Emitted when successfully connected to the remote server.
     */
    void connectedToServer();

    /**
     * Emitted when after sendData(QString) is called, if the data is send
     * successfully.
     */
    void dataSent();

    /**
     * Emitted as feedback when data are received successfully.
     */
    void dataReceived(const QString & data);

    /**
     * Emitted the instance the dataReceived(const QString&) signal is emitted. User
     * decides which format wants to read.
     */
    void dataReceived(const QByteArray & data);

    /**
     * Emitted in case of error.
     */
    void error(QBtSerialPortClient::ErrorCode error);

private:
    friend class QBtSerialPortClientPrivate;
    QBtSerialPortClientPrivate* _implPtr;
};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtSerialPortClient))

#endif /* QBTSERIALPORTCLIENT_H_ */


code:
/*
 *
 * 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.
 */

#ifndef QBTSERIALPORTSERVER_H
#define QBTSERIALPORTSERVER_H

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QBtServiceAdvertiser.h>
#include <QtCore/QObject>
#include <QtCore/QByteArray>

#include <QBtUuid.h>

QBT_NAMESPACE_BEGIN

//forward declaration
class QBtSerialPortServerPrivate;

/**
 * This class creates a Serial Port Server.
 *
 * After instantiation user can call startServer(const QString&)
 * to start the server and wait for a client to connect. From the
 * serviceName argument user can specify the name of the RFCOMM service
 * which is how the service will be identified by other devices. By default
 * the name is MyRFCOMM.
 *
 * If server is started successfully then serverStarted() signal is emitted.
 *
 * When a remote client is connected to the local running server
 * clientConnected(const QBtAddress &) is emitted and from that point and
 * on the data transmittion can start.
 *
 * To send data to the client use sendData(const QString &). If successfull
 * dataSent() signal is emitted.
 *
 * When data are received successfully from the remote client dataReceived(const QString &)
 * signal is emitted.
 *
 * If client disconnects,  clientDisconnected() will be emitted and user must
 * call startServer(const QString &) to initialize server again to be ready to
 * accept new connection.
 *
 * The connection to a client (if any) is closed when stopServer() is called along
 * with the termination of advertising of the SPP service.
 *
 * In case of an error error(QBtSerialPortServer::ErrorCode) is called.
 */
class DLL_EXPORT QBtSerialPortServer : public QObject
{
    Q_OBJECT

public:

    enum ErrorCode
    {
        ErrorAlreadyInUse,
        ErrorNotSupported,
        ErrorUnavailable,
        ErrorUndefinedError
    };

public:
    QBtSerialPortServer(QObject* parent);
    ~QBtSerialPortServer();

    /**
     * Get the status of the connection.
     * @return true if connected.
     */
    bool isConnected();

    /**
     * If startServer() function is already called then using this function
     * the user can acquire the information of the transmitting service that
     * represents this server to the outside world.
     */
    const QBtService & getTransmittingServiceInfo() const;

protected:
    void setTransmittingService (const QBtService& service);

    /**
     * Set the flag inside this object which represents the connection status.
     * NOTE: This flag is updated automatically whenever the connection status
     * changes.
     */
    void setConnectionStatus(bool connected);

    /**
     * startAdvertisingService()
     *
     * Initializes a new advertiser and starts the transmitting of the
     * service passed as argument.
     */
    void startAdvertisingService(const QBtService& service);

    /**
     * stopAdvertisingService()
     *
     * Stops the transmittion of the service (if any)
     */
    void stopAdvertisingService();

public slots:
    /*
     * When server is started, a custom bluetooth service is advertised
     * through QBtServiceAdvertiser. This service can be retrieved using
     * getTransmittingServiceInfo(). If needed, the user can set the name
     * of the transmitting service when calling this function.
     */
    void startServer (const QBtUuid & serviceId, const QString& serviceName = "My RFCOMM service");

    /**
     * stopServer()
     *
     * Stops the server, terminates the service transmittion and disconnects
     * from any device connected
     */
    void stopServer();

    /**
     * sendData()
     *
     * If connected to a remote client, sends the data passed as argument
     * to the client. If successfull, dataSent() signal is emitted.
     *
     * @param data The data to be send.
     */
    void sendData (const QString & data);

signals:
    /**
    * Emitted when server is successfully started and ready to use.
    */
    void serverStarted();

    /**
     * Emitted when service advertising is terminated. If any client is connected the
     * a clientDisconnected() signal will be emitted as well.
     */
    void serverStopped();

    /**
     * Emitted when a remote client is connected to the local running server.
     */
    void clientConnected (const QBtAddress & clientAddress);

    /**
     * Emitted when a remote client is disconnected either by a normal disconnection
     * or by a problem to the connection (ex. loss of signal, power off bluetooth hardware device)
     */
    void clientDisconnected();

    /**
     * Emitted after calling sendData() function if data are send successfully to the remote client.
     */
    void dataSent();

    /**
     * Emitted when data are received successfully from the remote client.
     */
    void dataReceived (const QString & data);

    /**
     * Emitted in case of error.
     */
    void error (QBtSerialPortServer::ErrorCode code);

private:
    // Service Advertiser
    QBtServiceAdvertiser* _advertiser;

    //transmitting service
    QBtService _service;

    //pointer to implementation
    QBtSerialPortServerPrivate *_implPtr;

    // status
    bool _isConnected;

    friend class QBtSerialPortServerPrivate;

};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtSerialPortServer))

#endif // QBTSERIALPORTSERVER_H


code:
/*
 *
 * 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.
 */

#ifndef QBTSERVICE_H
#define QBTSERVICE_H

#include <QtCore/QString>
#include <QtCore/QList>
#include <QBtGlobal.h>
#include <QBtConstants.h>
#include <QBtUuid.h>

QBT_NAMESPACE_BEGIN

/**
 * Class containing all the necessary information about a bluetooth service
 * of a remote device.
 */
class DLL_EXPORT QBtService : public QObject
{
	Q_OBJECT

   public:
      typedef QList<QBtService> List;

      /**
       * This list will be populates either by the Service Discovery or
       * by the user.
       *
       * The index of every protocol contained corresponds to the level of
       * hierarchy that it belongs.
       *
       * example: to create a service using RFCOMM then the list will be:
       * [0]: L2CAP
       * [1]: RFCOMM
       *
       * So ProtocolList::last() returns the highest protocol.
       */
      typedef QList<QBtUuid> ProtocolList;

      /**
       * Constructs an empty instance.
       */
      QBtService(QObject* parent = 0);

	  /**
	   *  Copy constructor
	   */
	  QBtService(const QBtService& service, QObject* parent = 0);

      /**
       * Gets the protocol list used by this service.
       */
      ProtocolList getProtocols() const;

      /**
       * Gets the service id of this service.
       */
      QBtUuid getClass () const;

      /**
       * Gets the service name.
       */
      QString getName() const;

      /**
       * Gets the service description.
       */
      QString getDescription() const;

      /**
       * Gets the service port.
       */
      uint getPort() const;

      /**
       * Gets the native (?) service handle.
       */
      uint getHandle() const;

      /**
       * Adds a protocol to the service protocol list.
       */
      void addProtocol(const QBtUuid & uuid);

      bool removeProtocol (const QBtUuid & uuid);

      void setProtocols(const ProtocolList & newUUIDs);

      void setClass(const QBtUuid & newClass);

      void setName(const QString& newName);

      void setDescription(const QString& newDescription);

      void setPort(uint newPort);

      void setHandle (uint newHandle);

	  QBtService& operator=(const QBtService& service);

   private:

      // protocol list is mainly used on symbian
      // on windows the connections are done using classUUID
      QBtUuid       _serviceUuid;
      ProtocolList  _protocolList;
      QString       _name;
      QString       _description;
      uint          _handle;

      // used on RFCOMM service as channel number to be used for connection
      // to remote device
      uint          _port;

};

QBT_NAMESPACE_END

Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtService))

#endif // QBTSERVICE_H


code:
/*
 * QBtServiceAdvertiser.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTSERVICEADVERTISER_H_
#define QBTSERVICEADVERTISER_H_

#include <QBtGlobal.h>
#include <QtCore/QObject>
#include <QBtTypes.h>

QBT_NAMESPACE_BEGIN

//forward declaration
class QBtServiceAdvertiserPrivate;

/**
 * Class responsible to advertise a given bluetooth service.
 *
 * After the instantiation of the class, startAdvertising(const QBtService&) can be callled
 * to start advertising the given bluetooth service. If successfull then
 * advertisingStarted(const QBtService&) signal is emitted.
 *
 * At any time stopAdvertising() can be called to stop the advertising and remove the
 * registered service from the SDP database. If successfull then advertisingStopped()
 * is emitted.
 *
 * If user wants to temporarily deactive the service advertisement then he can call
 * updateAvailability(bool) (instead of the stopAdvertising() that stops the advertising
 * permanently).
 *
 * In case of error, error(ErrorCodes) signal is emitted.
 *
 * For integrity reasons, at destruction stops the advertising
 * causing the service to be deleted from the SDP database.
 *
 * NOTE: Currently there is no implementation on the Windows platform so
 * after the intatiation of this object, any call to any function will
 * emit an error(QBtServiceAdvertiser::FeatureNotSupported) signal.
 */
class DLL_EXPORT QBtServiceAdvertiser : public QObject
{
    Q_OBJECT

public:
    enum ErrorCodes
    {
        FeatureNotSupported
    };

public:
    QBtServiceAdvertiser(QObject* parent);
    ~QBtServiceAdvertiser();

    /**
     * Starts the service advertiser.
     *
     * @param service the service class that contains all the necessery
     * information for transmitting the service
     */
    void startAdvertising(const QBtService& service);

    /**
     * Stops the transmittion of the service running (if any)
     */
    void stopAdvertising();

    /**
     * Change the availability of the service.
     * @param aAvailable If true, the service is transmitted.
     */
    void updateAvailability(bool aAvailable);

signals:
    /**
     * The signal is emitted if the transmittion of the service is started
     * @param service A reference to an object containing all the info of the service being transmitted.
     */
    void advertisingStarted(const QBtService& service);

    /**
     * The signal is emitted when the transmittion of the service ends.
     */
    void advertisingStopped();

    /**
     *
     * Emitted in case of error (not implemented).
     */
    void error (QBtServiceAdvertiser::ErrorCodes code);

private:
    // The service to advertise
    QBtService* _localService;

    //pointer to implementation
    QBtServiceAdvertiserPrivate *_implPtr;

    friend class QBtServiceAdvertiserPrivate;

};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtServiceAdvertiser))

#endif /* QBTSERVICEADVERTISER_H_ */


code:
/*
 * QBtServiceDiscoverer.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTSERVICEDISCOVERER_H_
#define QBTSERVICEDISCOVERER_H_

#include <QBtGlobal.h>
#include <QtCore/QObject>
#include <QBtTypes.h>
#include <QtCore/QList>

QBT_NAMESPACE_BEGIN

//forward declaration
class QBtServiceDiscovererPrivate;

/**
 * This class provides the mechanism to inquire a given device for the bluetooth
 * services it supports.
 *
 * If startDiscovery (const QBtDevice &) is called, then the device is inquired for all
 * the bluetooth services it supports.
 *
 * If user is searching for a specific service then
 * startDiscovery (const QBtDevice &, const QBtUuid &) or
 * startDiscovery (const QBtDevice &, QBtConstants::ServiceProtocol)
 * can be called, according to the information the user already has
 * about the inquired service.
 * After the successful call of these functions, discoveryStarted()
 * signal is emitted.
 *
 * At any of the above cases, a found service is reported through
 * newServiceFound (const QBtDevice &, const QBtService &) signal.
 *
 * If service inquiring stops (either by the user calling stopDiscovery() or by normal termination
 * of the inquiring) then discoveryStopped() signal is emitted.
 *
 * At any time the user can access the found services through
 * getInquiredServices().
 */
class DLL_EXPORT QBtServiceDiscoverer : public QObject
{
    Q_OBJECT

public:
    enum ServiceDiscoveryError
    {
        ServiceDiscoveryNotAbleToComplete,
        UnableToRetrieveServiceAttributes,
        ProblemRequestingNextServiceRecord,
        ProblemAcquiringNextServiceAttributes,
        NotSupported,
        NoDeviceSelected,
        UnknownError
    };

public:
    QBtServiceDiscoverer(QObject* parent = 0);
    virtual ~QBtServiceDiscoverer();

    /**
     *  getInquiredServices()
     *
     *  Returns a service list containing the inquired services (if any)
     */
    QBtService::List getInquiredServices();

    /**
     *  getTargetDevice()
     *
     *  Returns the remote device selected for service discovery.
     *  If "startDiscovery" function (both overloads) was already called
     *  then returns "targetDevice" which was passed as argument
     *  else returns NULL
     */
    const QBtDevice & getTargetDevice() const;

    /**
     * Returns true if a discovery operation is in progress.
     */
    bool isBusy () const;

public slots:

   /**
    * Starts service discovery for OBEX and RFCOMM services.
    * New services found are reported through signal "newServiceFound" or can
    * be acquired through "getInquiredServices" function
    *
    */
   void startDiscovery (const QBtDevice & targetDevice);

   /**
    * Starts service discovery for OBEX services only.
    * New services found are reported through signal "newServiceFound" or can
    * be aquired through "getInquiredServices" function
    *
    */
   void startObexDiscovery (const QBtDevice & targetDevice);

   /**
    * Starts service discovery for RFCOMM services only.
    * New services found are reported through signal "newServiceFound" or can
    * be acquired through "getInquiredServices" function.
    *
    */
   void startRfcommDiscovery (const QBtDevice & targetDevice);

   /**
    * Starts service discovery for the service (or protocol) identified by
    * the uuid parameter.
    * New services found are reported through signal "newServiceFound" or can
    * be acquired through "getInquiredServices" function.
    *
    */
   void startDiscovery (const QBtDevice & targetDevice, const QBtUuid & uuid);

   /**
    *
    * Starts service discovery for UUIDs provided in the list.
    * New services found are reported through signal "newServiceFound" or can
    * be acquired through "getInquiredServices" function.
    *
    */
   void startDiscovery (const QBtDevice& targetDevice, const QList <QBtUuid> & uuids);

   /**
    * Stops service discovery.
    * Services found so far can be acquired using "getInquiredServices" function.
    */
   void stopDiscovery();

signals:

    /**
     * Signal to report that discovery has started. Alternative is error.
     */
    void discoveryStarted();

    /**
     * Signal to report that discovery has stopped (either cancelled or no new devices to detect)
     */
    void discoveryStopped ();

    /**
     * Signaled for every service detected
     * The targetDevice's field "supportedServices" is updated every time
     * this signal is emitted.
     *
     * @param targetDevice The remote device where the service was found
     * @param service	The remote service found
     */
    void newServiceFound (const QBtDevice& targetDevice, const QBtService & service);

    /**
     * Signal to be emitted when error occurs.
     * @param error error code.
     */
    void error (QBtServiceDiscoverer::ServiceDiscoveryError error);

private:
    QBtDevice 					_remoteDevice;
    QBtServiceDiscovererPrivate *_implPtr;

    friend class QBtServiceDiscovererPrivate;
};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtServiceDiscoverer))

#endif /* QBTSERVICEDISCOVERER_H_ */


code:
/*
 * QBtServiceDiscoverer.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTSERVICEPROBER_H_
#define QBTSERVICEPROBER_H_

#include <QBtGlobal.h>
#include <QtCore/QObject>
#include <QBtTypes.h>
#include <QBtDeviceDiscoverer.h>
#include <QBtServiceDiscoverer.h>

QBT_NAMESPACE_BEGIN

/**
 * This class provides the mechanism to inquire services available on all devices
 * in the vicinity.
 *
 * when startDiscovery() is called (or its variations), it searches for all devices
 * according to the query criteria (the service uuids).
 *
 * When the discovery starts, the discoveryStarted() signal is emitted. Likewise,
 * the signal discoveryEnded() is emitted when the discovery ends. This happens when
 * the inquiry ends normally or through interruption (by calling stopDiscovery() ).
 *
 * After each device is filled with all services, the signal newDeviceFound (const QBtDevice &)
 * is emitted.
 *
 * After the discovery ends, the found device list is accessible through getDeviceList(). If no
 * devices were found, this list is empty.
 */
class DLL_EXPORT QBtServiceDiscovererForAll : public QObject
{
    Q_OBJECT

public:
    QBtServiceDiscovererForAll(QObject* parent = 0);
    virtual ~QBtServiceDiscovererForAll();

    /**
     * Returns the list of found devices. The list is empty if no
     * devices were found.
     */
    const QBtDevice::List & getDeviceList() const;

    /**
     * Returns true if a discovery operation is in progress.
     */
    bool isBusy () const;

    /**
     * Returns the number of total devices found.
     */
    int getNumberOfFoundDevices () const;

   /**
    * Returns true if any device was found.
    */
    bool foundDevices() const;

public slots:

   /**
    * Starts service discovery for OBEX and RFCOMM services.
    * New devices with their services are reported through signal "newDeviceFound".
    */
   void startDiscovery ();

   /**
    * Starts service discovery for OBEX services only.
    * New devices with their services are reported through signal "newDeviceFound".
    *
    */
   void startObexDiscovery ();

   /**
    * Starts service discovery for RFCOMM services only.
    * New devices with their services are reported through signal "newDeviceFound".
    */
   void startRfcommDiscovery ();

   /**
    * Starts service discovery for the service (or protocol) identified by
    * the uuid parameter.
    * New devices with their services are reported through signal "newDeviceFound".
    */
   void startDiscovery (const QBtUuid & uuid);

   /**
    *
    * Starts service discovery for UUIDs provided in the list.
    * New devices with their services are reported through signal "newDeviceFound".
    */
   void startDiscovery (const QList <QBtUuid> & uuids);

   /**
    * Stops service discovery.
    * Services found so far can be acquired using "getInquiredServices" function.
    */
   void stopDiscovery();

signals:

   /**
    * Signal to report that discovery has started.
    */
   void discoveryStarted();

   /**
    * Signal to report that discovery has ended (either cancelled or no new devices to detect)
    */
   void discoveryEnded ();

   /**
   * Signal to report that the class finished searching for services
   * in the specified device.
   */
   void newDeviceFound (const QBtDevice & device);

   /**
    * Signal emitted when service discovery error occurs when searching for services in the
    * specified device.
    */
   void serviceDiscoveyError (const QBtDevice & device, QBtServiceDiscoverer::ServiceDiscoveryError error);

   /**
    * Signal emitted when device discovery error occurs.
    */
   void deviceDiscoveryError (QBtDeviceDiscoverer::DeviceDiscoveryErrors error);

private slots:

   void sd_newServiceFound (const QBtDevice &targetDevice, const QBtService & service);
   void sd_serviceDiscoveryStarted ();
   void sd_serviceDiscoveryEnded ();
   void sd_error (QBtServiceDiscoverer::ServiceDiscoveryError error);

   //
   void dd_discoveryEnded ();
   void dd_discoveryStarted ();
   void dd_newDeviceFound (const QBtDevice & remoteDevice);
   void dd_error (QBtDeviceDiscoverer::DeviceDiscoveryErrors error );

private:

   void _startDiscovery ();

private:

    QBtDeviceDiscoverer    _deviceDiscoverer;
    QBtServiceDiscoverer   _serviceDiscoverer;
    QList<QBtUuid>         _targetServices;

    QList <QBtDevice>      _deviceList;

    int                    _deviceIndex;
    bool                   _aborted;

};

QBT_NAMESPACE_END

#endif /* QBTSERVICEDISCOVERER_H_ */


code:
/*
 * QBtSingleDeviceSelectorUI.h
 *
 *
 *      Author: ftylitak
 *
 * 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.
 */

#ifndef QBTSINGLEDEVICESELECTORUI_H_
#define QBTSINGLEDEVICESELECTORUI_H_

#include <QtCore/QObject>
#include <QtGui/QWidget>
#include <QBtGlobal.h>
#include <QBtDevice.h>

QBT_NAMESPACE_BEGIN

class QBtSingleDeviceSelectorUIPrivate;

/**
 * This class provides UI for searching remote bluetooth
 * devices, displaying them and selecting one device.
 *
 * When a device is selected, the UI is closed and the
 * device instance is returned through discoveryCompleted()
 * signal.
 * (NOTE: when closed it is not destroyed, just hiden)
 *
 * To use, create an instance of the class and call
 * show(). When shown, discovery starts as well.
 *
 * To get the selected remote device, the discoveryCompleted()
 * signal must be handled.
 */
class DLL_EXPORT QBtSingleDeviceSelectorUI : public QObject
{
    Q_OBJECT

public:
    /**
     * If parent == 0, the list will be showed as an independent
     * widget on the screen, thus it's not necessary for the client application
     * to have a GUI interface.
     *
     * For Symbian, it uses the native bluetooth search dialog. In this case, the "parent"
     * parameter has no effect.
     */
    QBtSingleDeviceSelectorUI (QWidget* parent = 0);

    /**
     * Destructor.
     */
    ~QBtSingleDeviceSelectorUI();

public slots:

    /**
     * On show, the device discovery starts.
     */
    void show();

signals:
    /**
     * Emitted after device discovery stops and user selects the desired device.
     */
    void discoveryCompleted (const QBtDevice & selectedDevice);

    /**
     * Emitted after calling show() if and only if the device discovery starts successfully
     */
    void discoveryStarted();

    /**
     * Emitted when the user closes the UI without choosing any device.
     */
    void userCanceled ();

private:
    QBtSingleDeviceSelectorUIPrivate* _impl;
    friend class QBtSingleDeviceSelectorUIPrivate;

};

QBT_NAMESPACE_END

#endif /* QBTSINGLEDEVICESELECTORUI_H_ */


code:
/*
 * QBtTypes.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTTYPES_H_
#define QBTTYPES_H_

#include <QBtAddress.h>
#include <QBtService.h>
#include <QBtDevice.h>
#include <QBtConstants.h>
#include <QBtUuid.h>
#include <QBtRemoteFileInfo.h>

#endif /* QBTTYPES_H_ */


code:
#ifndef QBTUUID_H
#define QBTUUID_H

#include <QBtGlobal.h>
#include <QtCore/QString>

QBT_NAMESPACE_BEGIN

/**
 * This class represents a UUID for Bluetooth, either in short format (16 or 32-bits) or full (128-bit).
 *
 */
class DLL_EXPORT QBtUuid : public QObject
{
	Q_OBJECT

   public:

      /**
       * Constructs an empty instance.
       */
      QBtUuid (QObject* parent=NULL);

      /**
       * Constructs an instance from a string representation.
       *
       * Valid formats:
       * XXXX
       * XXXXXXXX
       * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
       */
      QBtUuid (const QString & uuid);

      /**
       * Constructs an instance from a short uuid representation, a 16-bit or 32-bit value.
       */
      explicit QBtUuid (uint uuid);

	  /**
	   * Copy constructor
	   */
	  QBtUuid(const QBtUuid& uuid);
   public:

      /**
       * Sets as short UUID based on the supplied value. Assumed to be a 16-bit or 32-bit hexadecimal number.
       */
      void set (uint uuid);

      /**
       * Sets the uuid from a string representation.
       *
       * Valid formats:
       * XXXX
       * XXXXXXXX
       * XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
       * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
       */
      void set (const QString & uuid);

      /**
       * If short uuid, returns the equivalent uint. If full uuid, returns 0.
       *
       */
      uint get() const;

      /**
       * If this is a full uuid, splits it four 32-bit values. If this is a short
       * uuid, all values are set to zero.
       *
       */
      void get (uint & highWord1, uint & highWord2, uint & lowWord1, uint & lowWord2) const;

      /**
       * If short format, returns the equivalent uint. If full uuid, returns 0.
       *
       */
      bool isFull () const;

      /**
       * Returns true if this is an empty instance.
       *
       */
      bool isNull () const;
      /**
       * Returns a string representation.
       *
       */
      QString toString() const;

      /**
       * Resets to a null UUID.
       */
      void clear();

      /**
       *
       */
      bool operator == (const QBtUuid & obj) const;

	  /**
       *
       */
      bool operator != (const QBtUuid & obj) const;

	  /**
	   *
	   */
	  QBtUuid& operator=(class QBtUuid const &uuid);

   private:

      QString _uuid;

};

#ifdef Q_OS_SYMBIAN
#include <bttypes.h>

/**
 * A simple utility function to convert to the symbian native type.
 *
 */
inline TUUID QBtUuidToSymbianUuid (const QBtUuid & value)
{
   if (value.isFull() == false)
   {
      return TUUID (value.get() );
    }
    else
    {
      uint highWord1, highWord2, lowWord1, lowWord2;
      value.get (highWord1, highWord2, lowWord1, lowWord2);

      return TUUID (highWord1, highWord2, lowWord1, lowWord2);
    }
}

#endif

QBT_NAMESPACE_END

Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtUuid))

#endif // QBTUUID_H


code:
/*
 *
 * 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.
 */

#ifndef QBLUETOOTH_H
#define QBLUETOOTH_H

#include <QBtAuxFunctions.h>
#include <QBtGlobal.h>

#include <QBtTypes.h>
#include <QBtDeviceDiscoverer.h>
#include <QBtSingleDeviceSelectorUI.h>
#include <QBtServiceDiscoverer.h>
#include <QBtServiceDiscovererForAll.h>
#include <QBtServiceAdvertiser.h>
#include <QBtSerialPortServer.h>
#include <QBtSerialPortClient.h>
#include <QBtObjectExchangeClient.h>
#include <QBtObjectExchangeServer.h>
#include <QBtLocalDevice.h>

//using namespace QBluetooth;

namespace QBluetooth
{
    static void registerTypes()
    {
        qRegisterMetaType<QBT_PREPEND_NAMESPACE(QBtDevice)>("QBtDevice");
        qRegisterMetaType<QBT_PREPEND_NAMESPACE(QBtService)>("QBtService");
        qRegisterMetaType<QBT_PREPEND_NAMESPACE(QBtAddress)>("QBtAddress");
        qRegisterMetaType<QBT_PREPEND_NAMESPACE(QBtUuid)>("QBtUuid");
        qRegisterMetaType<QBT_PREPEND_NAMESPACE(QBtRemoteFileInfo)>("QBtRemoteFileInfo");
    }

    static void registerQMLTypes()
    {
       /* #if QT_VERSION > 0x040700
        qmlRegisterType<QBT_PREPEND_NAMESPACE(QBtConstants)>(QML_LIBRARY_NAME, 1, 0, "QBtConstants");
        qmlRegisterType<QBT_PREPEND_NAMESPACE(QBtUuid)>(QML_LIBRARY_NAME, 1, 0, "QBtUuid");
        qmlRegisterType<QBT_PREPEND_NAMESPACE(QBtAddress)>(QML_LIBRARY_NAME, 1, 0, "QBtAddress");
        qmlRegisterType<QBT_PREPEND_NAMESPACE(QBtDevice)>(QML_LIBRARY_NAME, 1, 0, "QBtDevice");
        qmlRegisterType<QBT_PREPEND_NAMESPACE(QBtService)>(QML_LIBRARY_NAME, 1, 0, "QBtService");
        qmlRegisterType<QBT_PREPEND_NAMESPACE(QBtDeviceDiscoverer)>(QML_LIBRARY_NAME, 1, 0, "QBtDeviceDiscoverer");
        qmlRegisterType<QBT_PREPEND_NAMESPACE(QBtRemoteFileInfo)>(QML_LIBRARY_NAME, 1, 0, "QBtRemoteFileInfo");
        //qmlRegisterType<QBtServiceDiscoverer>("QBtServiceDiscoverer", 1, 0, "QBtServiceDiscoverer");
        //qmlRegisterType<QBtServiceAdvertiser>("QBtServiceAdvertiser", 1, 0, "QBtServiceAdvertiser");
        //qmlRegisterType<QBtLocalDevice>("QBtLocalDevice", 1, 0, "QBtLocalDevice");
        //qmlRegisterType<QBtSingleDeviceSelectorUI>("QBtSingleDeviceSelectorUI", 1, 0, "QBtSingleDeviceSelectorUI");
        //qmlRegisterType<QBtSerialPortServer>("QBtSerialPortServer", 1, 0, "QBtSerialPortServer");
        //qmlRegisterType<QBtSerialPortClient>("QBtSerialPortClient", 1, 0, "QBtSerialPortClient");
        //qmlRegisterType<QBtObjectExchangeServer>("QBtObjectExchangeServer", 1, 0, "QBtObjectExchangeServer");
        //qmlRegisterType<QBtObjectExchangeClient>("QBtObjectExchangeClient", 1, 0, "QBtObjectExchangeClient");
        #endif*/
    }

}

#endif // QBLUETOOTH_H


code:
/*
 *
 * 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.
 */

#ifndef QBTADDRESS_H
#define QBTADDRESS_H

#include <QtCore/QString.h>
#include <QtCore/QByteArray.h>
#include <QBtGlobal.h>

#ifdef Q_OS_SYMBIAN
#include <bttypes.h>
#endif

QBT_NAMESPACE_BEGIN

/**
 * Class that represents the device's bluetooth _address.
 * It is one of the main fields of QBtDevice.
 */
class DLL_EXPORT QBtAddress : public QObject
{
	Q_OBJECT
	Q_PROPERTY(QString _address READ toString)// WRITE setName)

public:

    /**
     * QBtAddress()
     * Default constructor.
     */
    QBtAddress();

    /**
     * QBtAddress()
     * Copy constructor
     */
    QBtAddress (const QBtAddress& other);

    QBtAddress (const QByteArray& byteArray);
    QBtAddress (const QString& addr);

#ifdef Q_OS_SYMBIAN
    QBtAddress (const TBTDevAddr& addr);
#endif
    /**
     * Mainly created because on windows bluesoleil sdk, bluetooth _address
     * byte array is reversed so it is usefull to provide this functionality
     * here
     *
     * @param reversedArray
     */
    static QBtAddress& getAddressFromReversedArray (const QByteArray & reversedArray);

    ~QBtAddress ();

    /**
     * @return true if the _address contained in this instance is
     * a valid bluetooth _address
     */
    bool isValid () const;

    /**
     * Returns a string representation of this bluetooth _address
     */
    QString toString() const;

    /**
     * Returns a 6-byte array representation of the bluetooth _address
     */
    QByteArray toByteArray() const; // Symbian representation

    /**
     * Returns a 6-byte array representation of the bluetooth _address
     * in reversed order. Mainly created for convenience when using
     * windows bluesoleil SDK.
     */
    QByteArray toReversedByteArray() const; // windows representation

    QBtAddress& operator= (const QBtAddress & other );
    bool operator!= (const QBtAddress & other );
    bool operator== (const QBtAddress & other );
    bool operator< (const QBtAddress & other );

#ifdef Q_OS_SYMBIAN
    TBTDevAddr convertToSymbianBtDevAddr() const;
#endif

private:
    QString _address;
    bool _valid;
};

QBT_NAMESPACE_END

Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtAddress))

#endif // QBTADDRESS_H


code:
/*
 * auxFunctions_symbian.h
 *
 *      Author: Ftylitakis Nikolaos, Luis Valente
 *
 * 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.
 */

#ifndef AUXFUNCTIONS_SYMBIAN_H_
#define AUXFUNCTIONS_SYMBIAN_H_

#include <QBtGlobal.h>

QBT_NAMESPACE_BEGIN

template <class T> inline void SafeDelete(T* &ptr)
{
	if(ptr)
	{
		delete ptr;
		ptr = 0;
	}
}

//#ifdef Q_OS_SYMBIAN
#include <QtCore/QString>
#include <QtGui/QMessageBox>
#include <QtCore/QDir>
#include <QtCore/QDebug.h>

inline void _Debug_Msg (const QString & m, const QString & file, int line)
{
    qDebug() << "file: " << file << " line: " << line << " " << m;
}

inline void _Assert_Msg (const QString msg, const QString & file, int line)
{
    // strip directory info
    int index = file.lastIndexOf("/");
    QString f = file.mid (index+1);
    QString m = QString ("file: %1 line: %2\n%3").arg (f).arg(line).arg(msg);

    //
    _Debug_Msg (m, file, line);

    //
    QMessageBox::information(0, "assert failed", m);
    Q_ASSERT (false);
}

inline void _Assert_Msg2 (const QString & msg1, const QString & msg2, const QString & file, int line)
{
   _Assert_Msg (QString("%1 : %2").arg(msg1).arg(msg2), file, line);
}

inline void _Break_Here (const QString & file, int line)
{
    // strip directory info
    int index = file.lastIndexOf("/");
    QString f = file.mid (index+1);
    QString m = QString ("file: %1 line: %2").arg (f).arg (line);

    //
    _Debug_Msg (m, file, line);

    //
    QMessageBox::information(0, "code break", m);
    Q_ASSERT (false);
}

inline void _Break_Here (const QString & file, const QString & line)
{
	// strip directory info
	int index = file.lastIndexOf("/");
	QString f = file.mid (index+1);
	QString m = QString ("file: %1 line: %2").arg (f, line);

	QMessageBox::information(0, "code break", m);
	Q_ASSERT (false);
}

#ifdef QT_DEBUG
    #define BT_DEBUG_MSG(msg) (_Debug_Msg((msg),__FILE__,__LINE__) )
    #define BT_BREAK_HERE() (_Break_Here(__FILE__, QString::number(__LINE__)) )
    #define BT_ASSERT_MSG(test, msg) ((!(test)) ? _Assert_Msg((msg), __FILE__, __LINE__) : qt_noop() )
    #define BT_ASSERT_MSG2(test, msg1, msg2) ((!(test)) ? _Assert_Msg2((msg1), (msg2), __FILE__, __LINE__) : qt_noop() )

#else

    #define BT_DEBUG_MSG(msg) {}
    #define BT_ASSERT_MSG_X(test, where, msg) {}
    #define BT_ASSERT_MSG(test, msg) {}
    #define BT_ASSERT_MSG2(test, msg1, msg2) {}
    #define BT_BREAK_HERE() {}

//#endif

#endif

#ifdef Q_OS_WIN32

#include <windows.h>
#include <conio.h>
#include <QBtAddress.h>

using namespace std;

// used to have the number of the classes that use the Bluesoleil SDK.
// if the number reaches zero the sdk is deinitialized.
static size_t sdkInitializationCounter = 0;

//forward declaration

#ifdef BLUETOOTH_LIB
extern "C"{
#include "./BlueSoleil_SDK_2.0.5/include/Btsdk_ui.h"
}
#else
class BTDEVHDL;
#endif

class DLL_EXPORT QBtAuxFunctions
{
public:
    static bool InitBthSdk();
    static void DeinitBthSdk();
    static BTDEVHDL GetDeviceHandle(const QBtAddress& address);
};

#endif // Q_OS_WIN32

QBT_NAMESPACE_END
#endif /* AUXFUNCTIONS_SYMBIAN_H_ */


code:
/*
 *
 * 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.
 */

#ifndef QBTCONSTANTS_H
#define QBTCONSTANTS_H

#include <QBtGlobal.h>

QBT_NAMESPACE_BEGIN

/**
 * Basic enumerations of bluetooth UUIDs
 */
class DLL_EXPORT QBtConstants : public QObject
{
	Q_OBJECT
	Q_ENUMS(ServiceClass)
	Q_ENUMS(ServiceProtocol)
public:

    /**
     * Short UUIDs for standard services, as unsigned integers.
     */
    enum ServiceClass
    {
            UndefinedClass = 0x0000,
            SerialPort = 0x1101,
            LANAccessUsingPPP,
            DialupNetworking,
            IrMCSync,
            OBEXObjectPush,
            OBEXFileTransfer,
            IrMCSyncCommand,
            Headset,
            CordlessTelephony,
            AudioSource,
            AudioSink,
            RemoteControlTarget,
            AdvancedAudioDistribution,
            AV_RemoteControl,
            VideoConferencing,
            Intercom,
            Fax,
            HeadsetAudioGateway,
            WAP,
            WAP_CLIENT,
            PANU,
            NAP,
            GN,
            DirectPrinting,
            ReferencePrinting,
            Imaging,
            ImagingResponder,
            ImagingAutomaticArchive,
            ImagingReferencedObjects,
            Handsfree,
            HandsfreeAudioGateway,
            DirectPrintingReferenceObjectsService,
            ReflectedUI,
            BasicPrinting,
            PrintingStatus,
            HumanInterfaceDeviceService,
            HardcopyCableReplacement,
            HCR_Print,
            HCR_Scan,
            Common_ISDN_Access,
            VideoConferencingGW,
            UDI_MT,
            UDI_TA,
            Audio_Video,
            SIM_Access,
            PnPInformation,
            GenericNetworking,
            GenericFileTransfer,
            GenericAudio,
            GenericTelephony,
            UPNP_Service,
            UPNP_IP_Service,
            ESDP_UPNP_IP_PAN,
            ESDP_UPNP_IP_LAP,
            ESDP_UPNP_L2CAP,

            MY_CUSTOM = 0x10ff
        };

    /**
     * Short UUIDs for standard protocols.
     */
    enum ServiceProtocol
    {
            UndefinedProtocol 	= 0x0000,
            SDP,
            UDP,
            RFCOMM,
            TCP,
            TCS_BIN,
            TCS_AT,
            OBEX 		= 0x0008,
            IP,
            FTP,
            HTTP		= 0x000C,
            WSP			= 0x000E,
            BNEP,
            UPNP,
            HIDP,
            HardcopyControlChannel,
            HardcopyDataChannel = 0x0014,
            HardcopyNotification = 0x0016,
            AVCTP,
            AVDTP = 0x0019,
            CMPT = 0x001B,
            UDI_C_Plane = 0x001D,
            L2CAP = 0x0100
        };
};

QBT_NAMESPACE_END

Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtConstants::ServiceClass))
Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtConstants::ServiceProtocol))

#endif // QBTCONSTANTS_H


code:
/*
 *
 * 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.
 */

#ifndef QBTDEVICE_H
#define QBTDEVICE_H

#include <QtCore/QList>
#include <QtCore/QString>
#include <QBtGlobal.h>
#include <QBtService.h>
#include <QBtAddress.h>

//#include <QtDeclarative/QtDeclarative.h>

QBT_NAMESPACE_BEGIN

/**
 * The class that contains all the information needed about any bluetooth device.
 * Its main fields are 4.
 *
 * a) QBtAddress address: It is the device's bluetooth address.
 *                  Any communication between remote devices is made using this field
 *                  so it is an essential information. No communication can be done
 *                  without this.
 *
 * b) QString name: The name of the device. By default this field is equal to QBtAddress.toString().
 *                  The actual name is retrieved from the device discovery
 *                  and is set by the remote device as an identification string ID.
 *
 * c) DeviceMajor type: an enumeration field characterizing the device type.
 *
 * d) QBtService::List supportedServices: this field is updated after calling
 *                  QBtServiceDiscoverer::startDiscovery(QBtDevice*)
 *                  (if any services are found through SDP)
 */
class DLL_EXPORT QBtDevice : public QObject
{
	Q_OBJECT
	Q_ENUMS(DeviceMajor)
	Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
	Q_PROPERTY(QBtAddress address READ getAddress WRITE setAddress)
	Q_PROPERTY(DeviceMajor type READ getType WRITE setType)

public:
    typedef QList<QBtDevice> List;

    enum DeviceMajor
    {
        Uncategorized, 	//Uncategorized device
        Computer,		//Computer device
        Phone,			//Phone device
        LANAccess,		//Some form of a local area network router
        AudioVideo,		//Audio / Video device
        Peripheral,		//Mouse, Joystick, Keyboard
        Imaging,		//Camera or Scanner device
        Wearable,		//Wearable Device
        Toy,			//Toy device
        Miscellaneous	//Miscellaneous device
    };

public:
    QBtDevice(QObject* parent=0);

	/**
	 *  Copy constructor is needed by the QMetaType to register this custom class
	 */
    QBtDevice(const QBtDevice& dev, QObject* parent=0);
    QBtDevice (const QString & devName, const QBtAddress & devAddress, DeviceMajor devType, QObject* parent=0);
    ~QBtDevice();

    void addNewService (const QBtService& newService);
    //void setName (const QString & newName);
	void setName (const QString & newName);
    void setAddress (const QBtAddress& newAddress);
    void setType(DeviceMajor newType);
    void setSupportedServices (const QBtService::List& newSupportedServices);

    bool serviceListUpdated() const;

	Q_INVOKABLE QString name() const;
    Q_INVOKABLE QString getName() const;
    const QBtAddress& getAddress() const;
    DeviceMajor getType() const;
    QString getTypeAsString() const;
    const QBtService::List & getSupportedServices() const;

    // really needed? does not require special processing to copy the members
	//	->	It is required as it turns out when inheriting from QObject. If not implemented
	//		then i get linker error (at least when compiling for Windows)
    QBtDevice& operator= (const QBtDevice& dev);

signals:
	void nameChanged(QString newName);

private:
    QString _name;
    QBtAddress _address;
    DeviceMajor _type;
    QBtService::List _supportedServices;

    bool _serviceListUpdated;
};

#if QT_VERSION >= 0x040700
//QML_DECLARE_TYPE (QBtDevice)
#endif

//Q_DECLARE_METATYPE(QBtDevice)
//Q_DECLARE_METATYPE(QBtDevice::DeviceMajor)
QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtDevice))

#endif // QBTDEVICE_H

//QML_DECLARE_TYPE(type)


code:
/*
 * QBtDeviceDiscoverer.h
 *
 *      Author: Ftylitakis Nikolaos, Luis Valente
 *
 * 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.
 */

#ifndef QBTDEVICEDISCOVERER_H_
#define QBTDEVICEDISCOVERER_H_

#include <QBtGlobal.h>
#include <QtCore/QObject>
#include <QBtTypes.h>

QBT_NAMESPACE_BEGIN

//Forward declaration
class QBtDeviceDiscovererPrivate;

/**
 * Class that contains the mechanism of the device discovery.
 * After instantiation, user can call startDiscovery() to begin the discovery.
 * If calling startDiscovery() is successfull then discoveryStarted() signal is emitted.
 * Any found device is reported through newDeviceFound(QBtDevice) signal or can be retrieved
 * calling GetInquiredDevices() which returns a list of all the found devices till now.
 * When discovery stops, discoveryStopped() signal is emitted.
 *
 * Incase of any errors, the are reported through
 * error(QBtDeviceDiscoverer::DeviceDiscoveryErrors) signal.
 */
class DLL_EXPORT QBtDeviceDiscoverer : public QObject
{
Q_OBJECT

public: //enums
    enum DeviceDiscoveryErrors
        { BluetoothNotSupported, BluetoothInUse, BluetoothAlreadyStopped, BluetoothNotReady,
        DiscoveryCancelled, UnknownError };

public:
    QBtDeviceDiscoverer(QObject* parent = 0);
    virtual ~QBtDeviceDiscoverer();

    /**
     * GetInquiredDevices()
     *
     * returns a reference to the list of devices found (if any)
     */
    Q_INVOKABLE const QBtDevice::List& getInquiredDevices() const;

    /**
     * Returns true if the class if performing a device discovery.
     */
    bool isBusy () const;

	Q_INVOKABLE void emitDummySignalTest();

public slots:
    /**
     * startDiscovery()
     *
     * Start a device discovery.
     * The start and completion of device discovery are reported through
     * discoveryStarted() and discoveryStopped() signals respectively.
     */
    void startDiscovery();

    /**
     * stopDiscovery()
     *
     * Stops device discovery.
     * Signal discoveryStopped() is emitted.
     */
    void stopDiscovery();

signals:
    /**
     * Signaled for every device detected
     * @param remoteDevice The remote device
     */
	void newDeviceFound (QBtDevice remoteDevice);

	//changed to the above because @ emit the classes already written, pass as argument
	// a local variable QBtDevice so i am not sure if the reference will continue to make senses
	// (may be the variable will be destroyed). Alternative we could return a *(new QBtDevice())
	//  but that would lead to memory leak.
	//void newDeviceFound (const QBtDevice & remoteDevice);

    /**
     * Signal to report that discovery has stopped (either canceled or no new devices to detect)
     */
    void discoveryStopped();

    /**
     * Signal to report that discovery has started. Alternative is error.
     */
    void discoveryStarted();

    /**
    * error
    * Signal to be emitted when error occurs.
    * @param error error code.
    */
    void error(QBtDeviceDiscoverer::DeviceDiscoveryErrors error);

private:

    QBtDeviceDiscovererPrivate *_implPtr;
    friend class QBtDeviceDiscovererPrivate;

};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtDeviceDiscoverer))

#endif /* QBTDEVICEDISCOVERER_H_ */


code:
/*
 *
 * 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.
 */

#ifndef QBTGLOBAL_H
#define QBTGLOBAL_H

#include <QtCore/qglobal.h>
#include <QtCore/QMetaType>

#ifdef BLUETOOTH_LIB
#define DLL_EXPORT Q_DECL_EXPORT
#else
#define DLL_EXPORT Q_DECL_IMPORT
#endif

#if QT_VERSION >= 0x040700
//#include <QtDeclarative>
#endif
/*
#define ENABLE_QBLUETOOTH_NAMESPACE
*/
#define QML_LIBRARY_NAME "QBluetooth"

#ifdef ENABLE_QBLUETOOTH_NAMESPACE
#define QBT_PREPEND_NAMESPACE(name)	::QBluetooth::name
#define QBT_NAMESPACE_NAME QBluetooth
#define QBT_NAMESPACE_BEGIN	namespace QBT_NAMESPACE_NAME{
#define QBT_NAMESPACE_END	}
#define QBT_USE_NAMESPACE	using namespace QBT_NAMESPACE_NAME;
#else
#define QBT_PREPEND_NAMESPACE(name)	name
#define QBT_NAMESPACE_NAME
#define QBT_NAMESPACE_BEGIN
#define QBT_NAMESPACE_END
#define QBT_USE_NAMESPACE
#endif

#endif // QBTGLOBAL_H


code:
/*
 *
 * 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.
 */

#ifndef QBTLOCALDEVICE_H
#define QBTLOCALDEVICE_H

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QtCore/QObject>

QBT_NAMESPACE_BEGIN

//This class contains only static functions. How can it be used through QML
// TYPE == Q_STATIC

class DLL_EXPORT QBtLocalDevice //: public QObject
{
    //Q_OBJECT
public:

    ///////////////////////////////////////
    ///	 Bluetooth local properties		///
    ///////////////////////////////////////
    /**
     * Returns if possible the local device address
     */
    static QBtAddress getLocalDeviceAddress();

    /**
     * Returns true if local device is visible to other devices.
     */
    static bool isVisible ();

    /**
     * Sets the device visibility to other devices.
     * @param value true -> visible, false -> invisible
     */
    static void setVisible (bool value);

    static QBtDevice::DeviceMajor getDeviceClass();

    /**
     * Sets the UUID of the device that characterizes the device's type.
     * The possible enumeration values passed as argument are defined in
     * QBtDevice::DeviceMajor.
     */
    static void setDeviceClass(QBtDevice::DeviceMajor classId);

    /**
     * Sets the name of the device throught which it will be identified by other
     * devices during SDP discovery.
     */
    static void setLocalDeviceName (const QString & deviceName);

    /**
     * Get local device name.
     * @return device name
     */
    static QString getLocalDeviceName();

    /**
     * Returns true if bluetooth hardware exists and is plugged in.
     */
    static bool isBluetoothSupported();

    /**
     * Symbian specific function.
     * Used if bluetooth is powered off, showing a dialog that asks permission
     * from the user to power on bluetooth.
     */
    static void askUserTurnOnBtPower();

    /**
     * Symbian specific function.
     * Turns on/off bluetooth. Returns true is operation was sucessful.
     */
    static bool setBluetoothPowerState (bool value);

    /**
     * Returns true/false if bluetooth hardware is powered on/off respectively.
     */
    static bool getBluetoothPowerState();

    /**
     * Add a new device in the bluetooth registry.
     * @param device the device to be added
     * @return true upon success, else false
     */
    static bool addNewDevice(const QBtDevice& device);

    /**
     * Delete a device from the bluetooth registry.
     * @param device the device to be deleted
     * @return true upon success, else false. If device doesn't exists in the registry the also false
     */
    static bool deleteDevice(const QBtDevice& device);

    /**
     * Delete a device from the bluetooth registry using the bluetooth address.
     * @param address the device address of the device to be delete
     * @return true upon success, else false. If device doesn't exists in the registry the also false
     */
    static bool deleteDevice(const QBtAddress& address);

    /**
     * Breaks the pairing between the local device and the device passed as argument.
     *
     * @param device the device class containing the information of the device to be unpaired.
     */
    static bool unpairDevice(const QBtDevice& device);

    /**
     * Breaks the pairing between the local device and the remote device identified by
     * the bluetooth address passed as argument.
     *
     * @param address the bluetooth address of the remote device.
     */
    static bool unpairDevice(const QBtAddress& address);
};

QBT_NAMESPACE_END

Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtLocalDevice))

#if QT_VERSION >= 0x040700
//QML_DECLARE_TYPEINFO(QBT_PREPEND_NAMESPACE(QBtLocalDevice))
#endif

#endif // QBTLOCALDEVICE_H


code:
/*
 * QBtObjectExchangeClient.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTOBJECTEXCHANGECLIENT_H_
#define QBTOBJECTEXCHANGECLIENT_H_

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QBtServiceAdvertiser.h>
#include <QtCore/QObject>

QBT_NAMESPACE_BEGIN

//forward declaration
class QBtObjectExchangeClientPrivate;

/**
 * Class that provides the mechanism to connect to a remote
 * OBEX server and send or recieve files or raw data.
 *
 * After instantiation user can call connectToServer(QBtDevice&, QBtService&)
 * to connect to the remote server specified by the remoteDevice argument
 * to its service provide by remoteService argument.
 *
 *  P.S. At the remote service, one of the supported protocols must be
 * QBtConstants::OBEX. Suggestion, use a service whose class is equal to
 * QBtConstants::OBEXObjectPush or QBtConstants::OBEXFileTransfer.
 * Again, it is suggested to use QBtConstants::OBEXObjectPush.
 * Both options will work fine if the user wants to send a file to
 * the server, but at present further operations can be done using
 * QBtConstants::OBEXObjectPush.
 *
 * Signal connectedToServer() is emitted upon successfull connection to the OBEX server.
 *
 * After the successfull connection to the server, user can call putFile(const QString&)
 * to send to the remote server the file specified by the string passed as argument.
 * If successfull then objectSent() signal is emitted.
 *
 * Also user is able to send a request to get a file from the remote server specifing
 * the absolute path of the file to be fetched at the remote device's file system.
 * Also a local path must be set which is where the file will be stored after the
 * successfull transfer.
 * getFile(const QString& localPath, const QString& remoteFileNameFull)
 * If successfull then fileReceived(const QString) is emitted.
 *
 * getByteBuffer() and putByteBuffer() are implemented but not tested.
 * If successfull they emit dataReceived(const QByteArray) and objectSent() respectively.
 *
 * If connected to an OBEX FTP bluetooth service then setPath() can be called
 * to set the remote working directory. If successfull then remotePathSet(const QString)
 * will be emitted.
 *
 * User can abort any transmittion in progress by calling abort().
 *
 * User can disconnect from the server at any time or the disconnection will take place at
 * destruction time. Any transmittion in progress will be terminated instantly.
 * A successfull disconnection emits disconnectedFromServer() signal.
 */
class DLL_EXPORT QBtObjectExchangeClient : public QObject
{
    Q_OBJECT

public:
    enum ErrorCode{
        OBEXClientConnectionError,
        OBEXClientSendError,
        OBEXClientReceiveError,
        OBEXClientDisconnected,
        OBEXClientInUse,
        OBEXClientInternalError,
        OBEXClientNoSelectedDevice,
        OBEXClientNoSelectedService,
        OBEXClientUnableToSetPath,
		OBEXFeatureNotSupported,
		OBEXClientBrowseError
    };

public:
    QBtObjectExchangeClient(QObject* parent);
    ~QBtObjectExchangeClient();

    /**
     * connectToServer()
     *
     * Connect to a remote server defined by parameter 1 to its service
     * defined by parameter 2.
     *
     * P.S. At the remote service, one of the supported protocols must be
     * QBtConstants::OBEX. Suggestion, use a service whose class is equal to
     * QBtConstants::OBEXObjectPush or QBtConstants::OBEXFileTransfer.
     * Again, it is suggested to use QBtConstants::OBEXObjectPush.
     * Both options will work fine if the user wants to send a file to
     * the server, but at present further operations can be done using
     * QBtConstants::OBEXObjectPush.
     *
     * @param remoteDevice
     * @param remoteService
     */
    void connectToServer(const QBtDevice& remoteDevice, const QBtService& remoteService);

    /**
     * getFile()
     * Get a file from the remote Server
     *
     * @param localPath the path where the file will be saved
     * @param remoteFileNameFull the name of the file to be transfered
     *							containing the full path of its remote location
     */
    void getFile(const QString& remoteFileAbsolutePath, const QString& destinationFolder);

    /**
     * getByteBuffer(const QString& dataName)
     * Request from the server to GET the data buffer defined in the argument
     *
     * @param dataName The name of the buffer.
     */
    void getByteBuffer(const QString& dataName);

    /**
     * Send a specified file from the local file system to the remote
     * OBEX server.
     *
     * @param fileName The file name of the file to be sent. The absolute
     *                 path of the file is required.
     */
    void putFile(const QString& fileName);

    /**
     * putByteBuffer()
     *
     * send the server a byte sequence.
     * @param data,  the data of the buffer
     * @param bufferName, the name of the buffer (used for convenience on the data
     * 		processing of the server)
     */
    void putByteBuffer(const QByteArray& data, const QString& bufferName);

    /**
     * abort()
     *
     * abort any panding or running transmittion.
     */
    void abort();

    /**
     * setPath(const QString path)
     *
     * Set the current path of the remote device OBEX session.
     * @param path The remote folder to be set as current
     */
    void setPath(const QString & path);

	/**
	 * getWorkingPath
	 *
	 *	ONLY FOR WINDOWS
	 *
	 * Return as QString holding the absolute path of the current working directory
	 */
        QString getWorkingPath();

	/**
	 *	initiateFolderBrowsing()
	 *
	 *	ONLY FOR WINDOWS
	 *
	 *	Browse the files of a selected folder.
	 *
	 *  @param folder The folder path must either be absolute (e.g. \E:\Images), or it must be the name of the folder
	 *  you are going to browse as long as the folder is inside the current working directory of yours.
	 *
	 *  @return QList<QBtRemoteFileInfo*> a list of the files/folders found and their attributes
	 */
	QList<QBtRemoteFileInfo*> initiateFolderBrowsing(const QString& folderPath = "");

	/**
	 *	locateFiles
	 *
	 *	ONLY FOR WINDOWS
	 *
	 *	Locate files/folders that comply to the regex passed as arguments. For example can be used to isolate
	 *	files of specific type.
	 *
	 *	@param regex The regex that describes the files that are needed to be selected. If this parameter is not set, the default
	 *	operation is to select all the files in the specified folder.
	 *
	 *	@param folder The folder path must either be absolute (e.g. \E:\Images), or it must be the name of the folder
	 *  you are going to browse as long as the folder is inside the current working directory of yours. If this parameter is not set,
	 *	the default operation is to search in the current working directory.
	 */
	QList<QBtRemoteFileInfo*> locateFiles(QRegExp* regex=0, QString folder="");

	/**
	 *	batchFileRetrieval
	 *
	 *	ONLY FOR WINDOWS
	 *
	 *	Convenient method to retrieve multiple files in the row.
	 *
	 *	@param files The list of files to retrieve
	 *	@param destinationFolder The folder in the local file system where the files will be stored. The files are placed all
	 *	in that directory same directory so the structure in the remote file system is not preserved.
	 *	@param retrieveOnlyNewFiles If set true, then it first check if the file defined already exists in the
	 *	destination folder. If it does then it skips it. By default it is set to copy every file it founds.
	 */
	void batchFileRetrieval(const QList<QBtRemoteFileInfo*>& files,
		const QString destinationFolder,
		bool retrieveOnlyNewFiles = false);

    /**
     * Get info about the service connected to.
     * @return An object containing the service info
     */
    QBtService& getTransmittingService();

    /**
     * Get info about the server connected to.
     * @return An object containing the remote server device info.
     */
    QBtDevice& getServerDevice();

    /**
     * Checks if the client is performing some operation.
     */
    bool isBusy() const;

    /**
     * Checks if the client got a connection (it does not check *now* if the client is still connected).
     */
    bool isConnected() const;

public slots:
    void disconnect();

signals:

    /**
     * Emitted in case of error
     */
    void error(QBtObjectExchangeClient::ErrorCode code);

    /**
     * Emitted upon successfull connection to the OBEX server.
     */
    void connectedToServer();

    /**
     * Emitted upon disconnection from the server.
     */
    void disconnectedFromServer();

    /**
     * Emitted upon successfull transmittion of an object
     */
    void objectSent();

    /**
     * Emitted when a file is received from the server
     */

    void fileReceived (const QString & fileName);

    /**
     * Emitted when a byte buffer is received from the server
     */
    void dataReceived (const QByteArray & data);

    /**
     * Emitted upon successfull set of the remote current working directory.
     */
    void remotePathSet (const QString & pathName);

	/**
	 *	Emitted after calling initiateFolderBrowsing function for every result
	 *	found from browsing.
	 *
	 *	@param file The file info. See QBtRemoteFileInfo class for the info provided.
	 */
	void folderBrowsingResultElement(const QBtRemoteFileInfo& file);

private:
    friend class QBtObjectExchangeClientPrivate;
    QBtObjectExchangeClientPrivate* _implPtr;
};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtObjectExchangeClient))

#endif /* QBTOBJECTEXCHANGECLIENT_H_ */


code:
/*
 * QBtObjectExchangeServer.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTOBJECTEXCHANGESERVER_H_
#define QBTOBJECTEXCHANGESERVER_H_

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QBtServiceAdvertiser.h>
#include <QtCore/QObject>

QBT_NAMESPACE_BEGIN

//Forward declaration
class QBtObjectExchangeServerPrivate;

// suggestion: (LV)
//
// use smart pointers for the service advertiser and reset it when
// 'startServer' is called

/**
 * This class is used to create an OBEX server.
 * After instantiation user can call startServer(const QString&)
 * to start the server. From the serviceName argument user can
 * specify the name of the OBEX service which is how the service will
 * be identified by other devices. By default the name is MyOBEX.
 *
 * If sever started successfully and is ready to use then serverStarted() signal is emitted.
 * At destruction time or if user calls stopServer(),terminates the service transmittion
 * and disconnects from any device connected and serverStopped() signal is emitted.
 *
 * All the remaining signals are only for feedback in case any action that is done.
 */
class DLL_EXPORT QBtObjectExchangeServer : public QObject
{
    Q_OBJECT

public:
    enum ErrorCode{
        QObexServerUndefined,
        QObexServerFailedToInitialize,
        QObexServerInUse,
        QObexServerClientAbortedTransfer,
        QObexServerAbortedTransmission,
        QObexServerSessionError,
        QObexServerSessionPutRequestProblem,
        QObexServerSessionCopyFileError
    };

public:
    QBtObjectExchangeServer(QObject* parent);
    ~QBtObjectExchangeServer();

    /**
     * Returns true if the server is connected.
     */
    bool isConnected();

    /**
     * If startServer() function is already called then using this function
     * the user can acquire the information of the transmitting service that
     * represents this server to the outside world.
     */
    QBtService& getTransmittingServiceInfo();

protected:
    void setTransmittingService(const QBtService& service);

    /**
     * Initializes a new advertiser and starts the transmitting of the
     * service passed as argument.
     */
    void startAdvertisingService(const QBtService& service);

    /**
     * Stops the transmittion of the service (if any)
     */
    void stopAdvertisingService();

public slots:
    /**
     *
     * Starts OBEX server by initializing the components needed
     * and by advertising the service by which the server will
     * be identified by other devices.
     */
    void startServer (const QBtUuid & serviceId, const QString& serviceName = "My OBEX Service");

    /**
     * Stops the server, terminates the service transmittion and disconnects
     * from any device connected
     */
    void stopServer();

signals:

    /**
     * Emitted when server is successfully started and ready to use.
     */
    void serverStarted();

    /**
     * Emitted when server is disconnected and stopped
     */
    void serverStopped();

    /**
     * Emitted in case of error
     */
    void error(ErrorCode code);

    /**
     * Emitted as a feedback of the running receive status of
     * any data (file or byte buffer)
     */
    void receivingObjectInfo(int overalDataSize, int bytesSent);

    /**
     * Emitted when the transmittion of a file or byte buffer is started from a remote client
     * to the local device.
     */
    void receivingStarted();

    /**
     * Emitted when a receiving of a file or byte buffer is stopped,
     * being successfull or not.
     *
     * @param receivedFileName
     */
    void receivingStopped (const QString & receivedFileName);

    /**
     * If the server (local device) sends a request to start a transmittion to the remote client
     * connected, the client reserves the right to deny the transmittion before it begins.
     * In that case transmittingRejected() is emitted.
     */
    void transmittingRejected();

    /**
     * Emitted as a feedback of the running transmittion status of
     * any data (file or byte buffer)	 *
     */
    void transmittingObjectInfo(int overalDataSize, int byteSent);

    /**
     * Emitted when a transmittion is started from the local device to a remote device.
     */
    void transmittingStarted (const QString & transmittingfileName);

    /**
     * Emitted upon successfull or not end of transmittion from
     * the local device to a remote client.
     */
    void transmittingStopped (const QString & transmittingfileName);

    /**
     * Emitted if during a transmittion the client aborts it.
     */
    void clientAbortedTransmittion();

private:
    QBtServiceAdvertiser* 			_advertiser;
    QBtService* 					_service;
    QBtObjectExchangeServerPrivate* _implPtr;
    bool 							_isConnected;

    friend class QBtObjectExchangeServerPrivate;
};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtObjectExchangeServer))

#endif /* QBTOBJECTEXCHANGESERVER_H_ */


code:
#ifndef QBTREMOTEFILEINFO_H
#define QBTREMOTEFILEINFO_H

#include <QString>
#include <QObject>
#include <QBtGlobal.h>
#include <QDate>

QBT_NAMESPACE_BEGIN

class DLL_EXPORT QBtRemoteFileInfo : public QObject{
	Q_OBJECT
public:
	QBtRemoteFileInfo(QObject* parent=0);
	QBtRemoteFileInfo(const QBtRemoteFileInfo& fileInfo);
	QString toString();
	QBtRemoteFileInfo& operator=(const QBtRemoteFileInfo& fileInfo);

public:
	QString absolutePath;
	QString fileName;
	QString path;
	bool isDir;
	int type;
	int size;

	QDate creationTime;
	QDate lastAccessTime;
	QDate lastWriteTime;
};

QBT_NAMESPACE_END

Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtRemoteFileInfo))

#endif // QBTREMOTEFILEINFO_H


code:
/*
 * QBtSerialPortClient.h
 *
 *
 *      Author: Ftylitakis Nikolaos
 *
 * 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.
 */

#ifndef QBTSERIALPORTCLIENT_H_
#define QBTSERIALPORTCLIENT_H_

#include <QBtGlobal.h>
#include <QBtTypes.h>
#include <QtCore/QObject>
#include <QtCore/QByteArray>

QBT_NAMESPACE_BEGIN

//forward declaration
class QBtSerialPortClientPrivate;

/**
 * Class that provides the mechanism to connect to a bluetooth serial port
 * server and communicate.
 *
 * Calling connect(const QBtDevice&, const QBtService&) user specifies
 * on which device to connect(on which serial port server) and on which
 * bluetooth service. The QBtDevice instance of the server can be
 * aquired using QBtDeviceDiscoverer or user can create his own instance
 * and set at least the QBtAddress field. Also the QBtService can be
 * aquired using QBtServiceDiscoverer targeting the beforementioned device.
 *
 * On successfull connection, connectedToServer() singal is emitted and
 * user is able to sendData(const QString&) to the server. If successfull
 * then dataSend() signal is emitted.
 *
 * If data is recieved from the server, dataReceived(const QString) signal is
 * emitted containing the bytes recieved. At this point user must be carefull
 * to read the data recieved using the same encoding as the sender (in this
 * case serial port server). QString contains all the necessary functions for
 * character encoding that is why is QString is used instead of QByteArray.
 *
 * When connection is no longer needed, disconnect() can be called.
 * disconnectedFromServer() is then emitted.
 *
 * In case of error error(QBtSerialPortClient::ErrorCode) signal is emitted.
 */
class DLL_EXPORT QBtSerialPortClient : public QObject
{
    Q_OBJECT

public:
    enum ErrorCode
    {
        ErrorAlreadyInUse,
        ErrorNotSupported,
        ErrorUnavailable,
        ErrorOpeningConnection,
        ErrorAlreadyConnected,
        ErrorUndefinedError,
        ErrorUnableToInitializePort,
        ErrorNoDeviceSelected,
        ErrorNoServiceSelected,
        ErrorConnectionError,
        ErrorConnectionTimeout,
        ErrorOnDisconnecting
    };

public:
    /**
     * A Serial port client.
     * According to the bluetooth specification, up to 7 instances of this class
     * can be connected simultaneously to other servers.
     */
    QBtSerialPortClient(QObject* parent);

    /**
     * Destructor.
     *
     * If isConnected() then disconnect() is called.
     */
    ~QBtSerialPortClient();

    /**
     * isConnected()
     *
     * Returns whether or not the client is connected to a remote server.
     */
    bool isConnected();

public slots:
    /**
     * connect()
     * RemoteDevice must contain at least the device address.
     * and remoteService at least a class ID (in case of SerialPort port field is also needed).
     * The remoteService info can be acquired by QBtServiceDiscoverer.
     */
    void connect(const QBtDevice& remoteDevice, const QBtService& remoteService);

    /**
     * disconnect()
     * Disconnects from the remote server if previously succusfully connected.
     */
    void disconnect();

    /**
     * sendData()
     * Send a string to the server.
     * If text is transmitted, it is up to the user to decide which text encoding to use.
     * Upon succesfull transmittion, dataSent() signal is emitted.
     */
    void sendData(const QString& data);

    /**
     * Send a array of bytes to the server, as is.
     * Upon succesfull transmittion, dataSent() signal is emitted.
     */
    void sendData (const QByteArray & data);

signals:
    /**
     * Emitted when successfully disconnected from the remote server (initiated from client).
     */
    void disconnectedFromServer();

    /**
     * Emitted when the server initiated a disconnection.
     */
    void connectionResetByPeer ();

    /**
     * Emitted when successfully connected to the remote server.
     */
    void connectedToServer();

    /**
     * Emitted when after sendData(QString) is called, if the data is send
     * successfully.
     */
    void dataSent();

    /**
     * Emitted as feedback when data are received successfully.
     */
    void dataReceived(const QString & data);

    /**
     * Emitted the instance the dataReceived(const QString&) signal is emitted. User
     * decides which format wants to read.
     */
    void dataReceived(const QByteArray & data);

    /**
     * Emitted in case of error.
     */
    void error(QBtSerialPortClient::ErrorCode error);

private:
    friend class QBtSerialPortClientPrivate;
    QBtSerialPortClientPrivate* _implPtr;
};

QBT_NAMESPACE_END

//Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtSerialPortClient))

#endif /* QBTSERIALPORTCLIENT_H_ */