/thirdparty/qxt/qxtweb-standalone/qxtweb/qxtabstractwebservice.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 121 lines · 19 code · 9 blank · 93 comment · 0 complexity · 7ff29fb7b9b5b386a92989eb5dce5695 MD5 · raw file

  1. /****************************************************************************
  2. **
  3. ** Copyright (C) Qxt Foundation. Some rights reserved.
  4. **
  5. ** This file is part of the QxtWeb module of the Qxt library.
  6. **
  7. ** This library is free software; you can redistribute it and/or modify it
  8. ** under the terms of the Common Public License, version 1.0, as published
  9. ** by IBM, and/or under the terms of the GNU Lesser General Public License,
  10. ** version 2.1, as published by the Free Software Foundation.
  11. **
  12. ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
  13. ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
  14. ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
  15. ** FITNESS FOR A PARTICULAR PURPOSE.
  16. **
  17. ** You should have received a copy of the CPL and the LGPL along with this
  18. ** file. See the LICENSE file and the cpl1.0.txt/lgpl-2.1.txt files
  19. ** included with the source distribution for more information.
  20. ** If you did not receive a copy of the licenses, contact the Qxt Foundation.
  21. **
  22. ** <http://libqxt.org> <foundation@libqxt.org>
  23. **
  24. ****************************************************************************/
  25. /*!
  26. \class QxtAbstractWebService
  27. \inmodule QxtWeb
  28. \brief The QxtAbstractWebService class is a base interface for web services
  29. QxtAbstractWebService provides a common interface for all web service classes.
  30. It uses an event-driven design instead of the more traditional request-response
  31. design used by many web scripting languages. When the user requests a web
  32. page, the service receives a pageRequestedEvent; after the service assembles
  33. the response, it must post a QxtWebPageEvent (or a subclass, such as
  34. QxtWebRedirectEvent or QxtWebErrorEvent).
  35. Usually, an application providing web services will instantiate one
  36. QxtAbstractWebService object for each session, but this is not a requirement.
  37. For services that do not require session management, such as those that serve
  38. only static content, the session factory may return the same pointer for
  39. every invocation, or it may use some more exotic scheme.
  40. When using one service object per session, each service's data members are
  41. independent and may be used to track state across requests. A service object
  42. shared among multiple sessions will retain state across requests as well but
  43. it must implement its own mechanism for separating non-shared data.
  44. The QxtWeb architecture is not multithreaded; that is, QxtAbstractWebService
  45. does not automatically spawn a process for every session. However,
  46. QxtAbstractWebSessionManager performs thread-safe event dispatching, so
  47. subclasses of QxtAbstractWebService are free to create threads themselves.
  48. A web service object may delete itself (see QObject::deleteLater()) to end
  49. the associated session.
  50. \sa QxtAbstractWebSessionManager::ServiceFactory
  51. */
  52. /*
  53. * TODO:
  54. * The current architecture only allows for two behaviors: creating a new session
  55. * for every connection without a session cookie, or not using sessions at all.
  56. * This needs to be fixed by adding a function to the session manager to explicitly
  57. * create a new session.
  58. */
  59. #include "qxtabstractwebservice.h"
  60. #ifndef QXT_DOXYGEN_RUN
  61. class QxtAbstractWebServicePrivate : public QxtPrivate<QxtAbstractWebService>
  62. {
  63. public:
  64. QXT_DECLARE_PUBLIC(QxtAbstractWebService)
  65. QxtAbstractWebServicePrivate() {}
  66. QxtAbstractWebSessionManager* manager;
  67. };
  68. #endif
  69. /*!
  70. * Creates a QxtAbstractWebService with the specified \a parent and session \a manager.
  71. *
  72. * Often, the session manager will also be the parent, but this is not a requirement.
  73. *
  74. * Note that this is an abstract class and cannot be instantiated directly.
  75. */
  76. QxtAbstractWebService::QxtAbstractWebService(QxtAbstractWebSessionManager* manager, QObject* parent) : QObject(parent)
  77. {
  78. QXT_INIT_PRIVATE(QxtAbstractWebService);
  79. qxt_d().manager = manager;
  80. }
  81. /*!
  82. * Returns the session manager associated with the web service.
  83. */
  84. QxtAbstractWebSessionManager* QxtAbstractWebService::sessionManager() const
  85. {
  86. return qxt_d().manager;
  87. }
  88. /*!
  89. * \fn void QxtAbstractWebService::postEvent(QxtWebEvent* event)
  90. * Posts an \a event to a web browser that has made a request to the service.
  91. */
  92. /*!
  93. * \fn virtual void QxtAbstractWebService::pageRequestedEvent(QxtWebRequestEvent* event)
  94. * This \a event handler must be reimplemented in subclasses to receive page
  95. * request events.
  96. *
  97. * Every page request event received MUST be responded to with a QxtWebPageEvent
  98. * or a QxtWebPageEvent subclass. This response does not have to be posted
  99. * during the execution of this function, to support asynchronous design, but
  100. * failure to post an event will cause the web browser making the request to
  101. * wait until it times out.
  102. *
  103. * \sa QxtWebRequestEvent
  104. */