llcorehttphandler.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * @file llcorehttphandler.h
  3. * @brief Public-facing declarations for the HttpHandler class
  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_HANDLER_H_
  27. #define _LLCORE_HTTP_HANDLER_H_
  28. #include "llcorehttpcommon.h"
  29. namespace LLCore
  30. {
  31. class HttpResponse;
  32. // HttpHandler defines an interface used by the library to notify library
  33. // callers of significant events, currently request completion. Callers must
  34. // derive or mixin this class then provide an implementation of the @see
  35. // onCompleted method to receive such notifications. An instance may be shared
  36. // by any number of requests and across instances of HttpRequest running in the
  37. // same thread.
  38. //
  39. // Threading: HttpHandler itself is interface and is tread-compatible.
  40. // Most derivations, however, will have different constraints.
  41. //
  42. // Allocation: Not refcounted, may be stack allocated though that is rarely a
  43. // good idea. Queued requests and replies keep a naked pointer to the handler
  44. // and this can result in a dangling pointer if lifetimes aren't managed
  45. // correctly.
  46. // *TODO: public std::enable_shared_from_this<HttpHandler>
  47. class HttpHandler
  48. {
  49. public:
  50. typedef std::shared_ptr<HttpHandler> ptr_t;
  51. typedef std::weak_ptr<HttpHandler> wptr_t;
  52. virtual ~HttpHandler()
  53. {
  54. }
  55. // Method invoked during calls to @see update(). Each invocation represents
  56. // the completion of some requested operation. Caller can identify the
  57. // request from the handle and interrogate the response argument for
  58. // success/failure, data and other information.
  59. //
  60. // @param handle Identifier of the request generating the
  61. // notification.
  62. // @param response Supplies detailed information about the request
  63. // including status codes (both programming and
  64. // HTTP), HTTP body data and encodings, headers,
  65. // etc. The response object is refcounted and the
  66. // called code may retain the object by invoking
  67. // @see addRef() on it. The library itself drops
  68. // all references to object on return and never
  69. // touches it again.
  70. virtual void onCompleted(HttpHandle handle, HttpResponse* response) = 0;
  71. }; // end class HttpHandler
  72. } // End namespace LLCore
  73. #endif // _LLCORE_HTTP_HANDLER_H_