llcorehttprequestqueue.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * @file llcorehttprequestqueue.h
  3. * @brief Internal declaration for the operation request queue
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2012, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef _LLCORE_HTTP_REQUEST_QUEUE_H_
  27. #define _LLCORE_HTTP_REQUEST_QUEUE_H_
  28. #include <vector>
  29. #include "llcorehttpcommon.h"
  30. #include "llcoremutex.h"
  31. #include "llcorerefcounted.h"
  32. #include "llerror.h"
  33. namespace LLCore
  34. {
  35. class HttpOperation;
  36. // Thread-safe queue of HttpOperation objects. Just a simple queue that handles
  37. // the transfer of operation requests from all HttpRequest instances into the
  38. // singleton HttpService instance.
  39. class HttpRequestQueue : public LLCoreInt::RefCounted
  40. {
  41. protected:
  42. LOG_CLASS(HttpRequestQueue);
  43. HttpRequestQueue(); // Caller acquires a Refcount on construction
  44. virtual ~HttpRequestQueue(); // Use release()
  45. public:
  46. HttpRequestQueue(const HttpRequestQueue&) = delete;
  47. void operator=(const HttpRequestQueue&) = delete;
  48. typedef std::shared_ptr<HttpOperation> opPtr_t;
  49. static void init();
  50. static void term();
  51. // Threading: callable by any thread once inited.
  52. LL_INLINE static HttpRequestQueue* instanceOf() { return sInstance; }
  53. typedef std::vector<opPtr_t> OpContainer;
  54. // Inserts an object at the back of the request queue.
  55. //
  56. // Caller must provide one refcount to the queue which takes possession of
  57. // the count on success.
  58. //
  59. // @return Standard status. On failure, caller must dispose of the
  60. // operation with an explicit release() call.
  61. //
  62. // Threading: callable by any thread.
  63. HttpStatus addOp(const opPtr_t& op);
  64. // Returns the operation on the front of the queue. If the queue is empty
  65. // and @wait is false, call returns immediately with a NULL pointer. If
  66. // true, caller will sleep until explicitly woken. Wake-ups can be spurious
  67. // and callers must expect NULL pointers even if waiting is indicated.
  68. //
  69. // Caller acquires reference count any returned operation
  70. //
  71. // Threading: callable by any thread.
  72. opPtr_t fetchOp(bool wait);
  73. // Returns all queued requests to caller. The @ops argument should be empty
  74. // when called and will be swap()'d with current contents. Handling of the
  75. // @wait argument is identical to @fetchOp.
  76. //
  77. // Caller acquires reference count on each returned operation
  78. //
  79. // Threading: callable by any thread.
  80. void fetchAll(bool wait, OpContainer& ops);
  81. // Wakes any sleeping threads. Normal queuing operations won't require this
  82. // but it may be necessary for termination requests.
  83. //
  84. // Threading: callable by any thread.
  85. void wakeAll();
  86. // Disallows further request queuing. Callers to @addOp will get a failure
  87. // status (LLCORE, HE_SHUTTING_DOWN). Callers to @fetchAll or @fetchOp will
  88. // get requests that are on the queue but the calls will no longer wait.
  89. // Instead they will return immediately. Also wakes up all sleepers to send
  90. // them on their way.
  91. //
  92. // Threading: callable by any thread.
  93. bool stopQueue();
  94. protected:
  95. OpContainer mQueue;
  96. LLCoreInt::HttpMutex mQueueMutex;
  97. LLCoreInt::HttpConditionVariable mQueueCV;
  98. bool mQueueStopped;
  99. static HttpRequestQueue* sInstance;
  100. }; // End class HttpRequestQueue
  101. } // End namespace LLCore
  102. #endif // _LLCORE_HTTP_REQUEST_QUEUE_H_