nfcconnection.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
  3. * All rights reserved.
  4. * This component and the accompanying materials are made available
  5. * under the terms of "Eclipse Public License v1.0"
  6. * which accompanies this distribution, and is available
  7. * at the URL "http://www.eclipse.org/legal/epl-v10.html".
  8. *
  9. * Initial Contributors:
  10. * Nokia Corporation - initial contribution.
  11. *
  12. * Contributors:
  13. *
  14. * Description: Implements NFC connection functionality.
  15. */
  16. #ifndef NFCCONNECTION_H
  17. #define NFCCONNECTION_H
  18. /*!
  19. * \file
  20. * \brief Implements NFC LLCP connection functionality.
  21. */
  22. #include <QObject>
  23. #include <qmobilityglobal.h>
  24. // Forward declarations.
  25. QTM_BEGIN_NAMESPACE
  26. class QLlcpServer;
  27. class QLlcpSocket;
  28. class QNearFieldManager;
  29. class QNearFieldTarget;
  30. QTM_END_NAMESPACE
  31. class P2PEngine;
  32. // Qt Mobility namespace.
  33. QTM_USE_NAMESPACE
  34. //! Implements NFC LLCP connection functionality.
  35. /*!
  36. This class creates a connection between two NFC devices using the NFC LLCP communication
  37. protocol. The class establishes peer-to-peer communication between two NFC-enabled devices
  38. and makes it possible to accept incoming LLCP socket connections.
  39. LLCP server takes care of listening for NFC targets and starts an LLCP connection to the client.
  40. The LLCP server is listening for incoming connections at a specified URI and then
  41. sends data to the client.
  42. */
  43. class NfcConnection : public QObject
  44. {
  45. Q_OBJECT
  46. public:
  47. //! Class Constructor.
  48. /*!
  49. * \param parent Parent for the object.
  50. * \param engine Reference to P2PEngine, ownership is not transferred.
  51. */
  52. explicit NfcConnection(QObject *parent, P2PEngine *engine);
  53. //! Destructor.
  54. virtual ~NfcConnection();
  55. //! Reads all available data from the device.
  56. /*!
  57. \return QString data read as a string.
  58. */
  59. Q_INVOKABLE QString readText();
  60. //! Writes the content of byteArray to the device.
  61. /*!
  62. \return Returns true on success; otherwise returns false.
  63. */
  64. bool sendText();
  65. private slots:
  66. //! Connects to the target at a specified URI.
  67. /*!
  68. \param target The near field target that was detected.
  69. */
  70. void targetDetected(QNearFieldTarget *target);
  71. //! Disconnects the socket.
  72. /*!
  73. \param target The near field target that was lost.
  74. */
  75. void targetLost(QNearFieldTarget *target);
  76. //! Creates the next pending connection as a connected QLlcpSocket object.
  77. void handleNewConnection();
  78. //! Slot called when socket has been disconnected.
  79. void clientSocketDisconnected();
  80. private:
  81. P2PEngine *m_engine; //! Reference to P2PEngine, not owned.
  82. QLlcpSocket *m_nfcServerSocket; //! NFC LLCP server socket.
  83. QNearFieldManager *m_nfcManager; //! Sets the target access modes to NFC devices.
  84. QLlcpServer *m_nfcServer; //! Provides an NFC LLCP socket based server.
  85. QLlcpSocket *m_nfcClientSocket; //! NFC LLCP client socket.
  86. };
  87. #endif // NFCCONNECTION_H