QBtObjectExchangeServer.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * QBtObjectExchangeServer.h
  3. *
  4. *
  5. * Author: Ftylitakis Nikolaos
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. #ifndef QBTOBJECTEXCHANGESERVER_H_
  20. #define QBTOBJECTEXCHANGESERVER_H_
  21. #include <QBtGlobal.h>
  22. #include <QBtTypes.h>
  23. #include <QBtServiceAdvertiser.h>
  24. #include <QtCore/QObject>
  25. QBT_NAMESPACE_BEGIN
  26. //Forward declaration
  27. class QBtObjectExchangeServerPrivate;
  28. // suggestion: (LV)
  29. //
  30. // use smart pointers for the service advertiser and reset it when
  31. // 'startServer' is called
  32. /**
  33. * This class is used to create an OBEX server.
  34. * After instantiation user can call startServer(const QString&)
  35. * to start the server. From the serviceName argument user can
  36. * specify the name of the OBEX service which is how the service will
  37. * be identified by other devices. By default the name is MyOBEX.
  38. *
  39. * If sever started successfully and is ready to use then serverStarted() signal is emitted.
  40. * At destruction time or if user calls stopServer(),terminates the service transmittion
  41. * and disconnects from any device connected and serverStopped() signal is emitted.
  42. *
  43. * All the remaining signals are only for feedback in case any action that is done.
  44. */
  45. class DLL_EXPORT QBtObjectExchangeServer : public QObject
  46. {
  47. Q_OBJECT
  48. public:
  49. enum ErrorCode{
  50. QObexServerUndefined,
  51. QObexServerFailedToInitialize,
  52. QObexServerInUse,
  53. QObexServerClientAbortedTransfer,
  54. QObexServerAbortedTransmission,
  55. QObexServerSessionError,
  56. QObexServerSessionPutRequestProblem,
  57. QObexServerSessionCopyFileError
  58. };
  59. public:
  60. QBtObjectExchangeServer(QObject* parent);
  61. ~QBtObjectExchangeServer();
  62. /**
  63. * Returns true if the server is connected.
  64. */
  65. bool isConnected();
  66. /**
  67. * If startServer() function is already called then using this function
  68. * the user can acquire the information of the transmitting service that
  69. * represents this server to the outside world.
  70. */
  71. QBtService& getTransmittingServiceInfo();
  72. protected:
  73. void setTransmittingService(const QBtService& service);
  74. /**
  75. * Initializes a new advertiser and starts the transmitting of the
  76. * service passed as argument.
  77. */
  78. void startAdvertisingService(const QBtService& service);
  79. /**
  80. * Stops the transmittion of the service (if any)
  81. */
  82. void stopAdvertisingService();
  83. public slots:
  84. /**
  85. *
  86. * Starts OBEX server by initializing the components needed
  87. * and by advertising the service by which the server will
  88. * be identified by other devices.
  89. */
  90. void startServer (const QBtUuid & serviceId, const QString& serviceName = "My OBEX Service");
  91. /**
  92. * Stops the server, terminates the service transmittion and disconnects
  93. * from any device connected
  94. */
  95. void stopServer();
  96. signals:
  97. /**
  98. * Emitted when server is successfully started and ready to use.
  99. */
  100. void serverStarted();
  101. /**
  102. * Emitted when server is disconnected and stopped
  103. */
  104. void serverStopped();
  105. /**
  106. * Emitted in case of error
  107. */
  108. void error(ErrorCode code);
  109. /**
  110. * Emitted as a feedback of the running receive status of
  111. * any data (file or byte buffer)
  112. */
  113. void receivingObjectInfo(int overalDataSize, int bytesSent);
  114. /**
  115. * Emitted when the transmittion of a file or byte buffer is started from a remote client
  116. * to the local device.
  117. */
  118. void receivingStarted();
  119. /**
  120. * Emitted when a receiving of a file or byte buffer is stopped,
  121. * being successfull or not.
  122. *
  123. * @param receivedFileName
  124. */
  125. void receivingStopped (const QString & receivedFileName);
  126. /**
  127. * If the server (local device) sends a request to start a transmittion to the remote client
  128. * connected, the client reserves the right to deny the transmittion before it begins.
  129. * In that case transmittingRejected() is emitted.
  130. */
  131. void transmittingRejected();
  132. /**
  133. * Emitted as a feedback of the running transmittion status of
  134. * any data (file or byte buffer) *
  135. */
  136. void transmittingObjectInfo(int overalDataSize, int byteSent);
  137. /**
  138. * Emitted when a transmittion is started from the local device to a remote device.
  139. */
  140. void transmittingStarted (const QString & transmittingfileName);
  141. /**
  142. * Emitted upon successfull or not end of transmittion from
  143. * the local device to a remote client.
  144. */
  145. void transmittingStopped (const QString & transmittingfileName);
  146. /**
  147. * Emitted if during a transmittion the client aborts it.
  148. */
  149. void clientAbortedTransmittion();
  150. private:
  151. QBtServiceAdvertiser* _advertiser;
  152. QBtService* _service;
  153. QBtObjectExchangeServerPrivate* _implPtr;
  154. bool _isConnected;
  155. friend class QBtObjectExchangeServerPrivate;
  156. };
  157. QBT_NAMESPACE_END
  158. //Q_DECLARE_METATYPE(QBT_PREPEND_NAMESPACE(QBtObjectExchangeServer))
  159. #endif /* QBTOBJECTEXCHANGESERVER_H_ */