llcorehttpreplyqueue.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @file llcorehttpreplyqueue.h
  3. * @brief Internal declarations for the operation reply 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_REPLY_QUEUE_H_
  27. #define _LLCORE_HTTP_REPLY_QUEUE_H_
  28. #include <vector>
  29. #include "llcoremutex.h"
  30. #include "llerror.h"
  31. namespace LLCore
  32. {
  33. class HttpOperation;
  34. class HttpRequest;
  35. // Almost identical to the HttpRequestQueue class but whereas that class is a
  36. // singleton and is known to the HttpService object, this queue is 1:1 with
  37. // HttpRequest instances and is not explicitly referenced by the service
  38. // object. Instead, HttpOperation objects that want to generate replies back to
  39. // their creators also keep references to the corresponding HttpReplyQueue. The
  40. // HttpService plumbing then simply delivers replies to the requested reply
  41. // queue.
  42. //
  43. // One result of that is that the fetch operations do not have a wait forever
  44. // option. The service object doesn't keep handles on everything it would need
  45. // to notify so it can't wake up sleepers should it need to shutdown. So only
  46. // non-blocking or timed-blocking modes are anticipated. These are how most
  47. // application consumers will be coded anyway so it should not be too much of a
  48. // burden.
  49. class HttpReplyQueue
  50. {
  51. protected:
  52. LOG_CLASS(HttpReplyQueue);
  53. public:
  54. typedef std::shared_ptr<HttpOperation> opPtr_t;
  55. typedef std::shared_ptr<HttpReplyQueue> ptr_t;
  56. HttpReplyQueue();
  57. ~HttpReplyQueue();
  58. // Non-copyable
  59. HttpReplyQueue(const HttpReplyQueue&) = delete;
  60. HttpReplyQueue& operator=(const HttpReplyQueue&) = delete;
  61. typedef std::vector<opPtr_t> OpContainer;
  62. // Insert an object at the back of the reply queue. Library also takes
  63. // possession of one reference count to pass through the queue.
  64. // Threading: callable by any thread.
  65. void addOp(const opPtr_t& op);
  66. // Fetch an operation from the head of the queue. Returns NULL if none
  67. // exists. Caller acquires reference count on returned operation.
  68. // Threading: callable by any thread.
  69. opPtr_t fetchOp();
  70. // Caller acquires reference count on each returned operation.
  71. // Threading: callable by any thread.
  72. void fetchAll(OpContainer& ops);
  73. protected:
  74. OpContainer mQueue;
  75. LLCoreInt::HttpMutex mQueueMutex;
  76. };
  77. } // End namespace LLCore
  78. #endif // _LLCORE_HTTP_REPLY_QUEUE_H_