Home · All Namespaces · All Classes · Grouped Classes · Modules · Functions codeless banner

QObexPushService Class Reference
[QtBaseModule]

The QObexPushService class provides an OBEX Push service. More...

    #include <QObexPushService>

Inherits QObject.

Inherited by DefaultObexPushService.

Public Types

Public Functions

Public Slots

Signals

Protected Functions

Additional Inherited Members


Detailed Description

The QObexPushService class provides an OBEX Push service.

The QObexPushService class can be used to provide OBEX Push services over Bluetooth, Infrared or any other OBEX capable transport. This class implements the Bluetooth Object Push Profile, and can also be used to implement the Infrared IrXfer service.

If you want to control whether an incoming file should be accepted, subclass QObexPushService and override the acceptFile() function. Subclasses can also override businessCard() to provide the default business card object that may be requested by an OBEX Push client.

When an OBEX client sends a file to the service, the acceptFile() function is called to determine whether the file transfer should be allowed. If the transfer is accepted, the putRequested() signal is emitted with the details of the incoming file, and the dataTransferProgress() signal will be emitted at intervals to show the progress of the file transfer operation. The requestFinished() signal is emitted when the transfer is complete.

Similarly, when an OBEX client requests the default business card, the businessCardRequested() signal is emitted, and the dataTransferProgress() signal will be emitted at intervals. The requestFinished() signal is emitted when the transfer is complete.

Finally, the done() signal is emitted when the OBEX client disconnects or if the connection is terminated.

Handling socket disconnections

You should ensure that the QIODevice provided in the constructor emits QIODevice::aboutToClose() or QObject::destroyed() when the associated transport connection is disconnected. If one of these signals are emitted, QObexPushService will know the transport connection has been lost, and will emit done() (and also requestFinished() if a Put or Get request is in progress) with error set to true, and error() will return ConnectionError.

This is particularly an issue for socket classes such as QTcpSocket that do not emit QIODevice::aboutToClose() when a disconnected() signal is emitted. In these cases, QObexPushService will not know that the transport has been disconnected. To avoid this, you can make the socket emit QIODevice::aboutToClose() when it is disconnected:

    // make the socket emit aboutToClose() when disconnected() is emitted
    QObject::connect(socket, SIGNAL(disconnected()), socket, SIGNAL(aboutToClose()));

Or, if the socket can be discarded as soon as it is disconnected:

    // delete the socket when the transport is disconnected
    QObject::connect(socket, SIGNAL(disconnected()), socket, SLOT(deleteLater()));

Member Type Documentation

enum QObexPushService::Error

Defines the possible errors for a push service.

ConstantValueDescription
QObexPushService::NoError0No error has occurred.
QObexPushService::ConnectionError1The client is unable to send data, or the client-server communication process is otherwise disrupted. If this happens, the state will change to QObexPushService::Closed.
QObexPushService::Aborted2The request was aborted (either by the client, or by a call to abort()).
QObexPushService::UnknownError100An error other than those specified above occurred.

enum QObexPushService::State

Defines the possible states for a push service.

ConstantValueDescription
QObexPushService::Ready0The service is ready to receive requests from an OBEX client. This is the default state.
QObexPushService::Connecting1A client is connecting.
QObexPushService::Disconnecting2A client is disconnecting.
QObexPushService::Streaming3A file transfer operation is in progress.
QObexPushService::Closed100The service has been closed and cannot process any more requests. The service will change to this state if a client sends a Disconnect command, or a ConnectionError occurs.


Member Function Documentation

QObexPushService::QObexPushService ( QIODevice * device, QObject * parent = 0 )

Constructs an OBEX Push service that uses device for the transport connection. The parent is the QObject parent.

The device must be opened, or else the service will be unable to receive any client requests.

QObexPushService::~QObexPushService ()

Destroys the service.

void QObexPushService::abort ()   [slot]

Aborts the current client request if a Put or Get request is in progress. If the request was successfully aborted, requestFinished() will be emitted with error set to true and error() will return QObexPushService::Aborted.

Due to timing issues, the request may finish before it can be aborted, in which case requestFinished() is emitted normally.

QIODevice * QObexPushService::acceptFile ( const QString & name, const QString & type, qint64 size, const QString & description )   [virtual protected]

Called when a client makes a Put request to send a file to this service. The name, type, size and description parameters respectively hold the name, MIME type, size and description of the file, as sent by the client. The size will be 0 if the client did not send any information about the size of the file.

This function can be overridden to intercept the request and determine whether the request should be allowed to continue (for example, by asking the end user, or by checking some file threshold) and where the file data should be saved. To allow the request, return a QIODevice pointer, and the received file data will be written to this QIODevice. To refuse the request, return 0.

If the request is allowed to continue, the putRequested() signal is emitted, and the requestFinished() signal will be emitted when the the request has finished. The returned QIODevice pointer is accessible from currentDevice().

The default implementation attempts to save the incoming file into QDir::homePath(), using name as the name of the file. (If name contains a path, only the filename at the end of the path will be used, and if name is an empty string, the file will be saved as "received_file".) If the file is successfully created, the Put request will be accepted; otherwise, the request will be refused.

See also putRequested(), currentDevice(), dataTransferProgress(), and requestFinished().

QByteArray QObexPushService::businessCard () const   [virtual]

Returns the business card that will be sent to OBEX clients who request it, as per the Business Card exchange feature of the Bluetooth Object Push Profile.

See also setBusinessCard().

void QObexPushService::businessCardRequested ()   [signal]

This signal is emitted when an OBEX client has requested the business card from the service, and businessCard() returns a non-empty QByteArray. (If businessCard() returns an empty QByteArray, the signal is not emitted.)

The requestFinished() signal is emitted when the request is completed.

See also setBusinessCard() and businessCard().

QIODevice * QObexPushService::currentDevice () const

If a Put request is in progress, this function returns the QIODevice pointer that is used to store the data from the request. If there is no Put request in progress, this function returns 0.

This function can be used to delete the QIODevice in the slot connected to the requestFinished() signal.

See also acceptFile().

void QObexPushService::dataTransferProgress ( qint64 done, qint64 total )   [signal]

This signal is emitted during file transfer operations to indicate the progress of the transfer. The done value is the number of bytes that have been sent or received so far, and total is the total number of bytes to be sent or received.

If the total number of bytes is not known, total will be 0.

void QObexPushService::done ( bool error )   [signal]

This signal is emitted when the OBEX client has disconnected from the service or if the connection has been terminated. The error value is true if an error occurred during the processing; otherwise error is false.

Error QObexPushService::error () const

Returns the error for the last completed request.

void QObexPushService::putRequested ( const QString & name, const QString & type, qint64 size, const QString & description )   [signal]

This signal is emitted when an OBEX client has made a Put request to the service and acceptFile() has accepted the request. The name, type, size and description parameters respectively hold the name, MIME type, size and description of the file, as sent by the client. The size will be 0 if the client did not send any information about the size of the file.

The requestFinished() signal is emitted when the Put request is completed.

See also currentDevice().

void QObexPushService::requestFinished ( bool error )   [signal]

This signal is emitted when a client Put or Get request is completed. The error value is true if an error occurred during the request; otherwise error is false.

QIODevice * QObexPushService::sessionDevice () const

Returns the device used by this OBEX Push server session, as provided in the constructor.

void QObexPushService::setBusinessCard ( const QByteArray & vCard )

Sets vCard to be the business card (in vCard format) that will be sent to OBEX clients who request it, as per the Business Card exchange feature of the Bluetooth Object Push Profile.

If no business card is set, this service will refuse all client requests for business cards.

See also businessCard().

State QObexPushService::state () const

Returns the current state of the service.

void QObexPushService::stateChanged ( QObexPushService::State state )   [signal]

This signal is emitted when the state of the service changes. The state is the new state of the client.


Copyright © 2009 Trolltech Trademarks
Qt Extended 4.4.3