resolver_interface.h 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (C) 2010 CZ NIC
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __RESOLVER_INTERFACE_H
  15. #define __RESOLVER_INTERFACE_H
  16. #include <dns/message.h>
  17. ///
  18. /// \file resolver_interface.h
  19. /// \short Interface to resolver.
  20. ///
  21. /// This file contains an interface for the resolver. By subclassing
  22. /// this abstract interface, other parts of the system can ask the
  23. /// resolver to do some resolving too.
  24. ///
  25. /// This is done by creating a subclass of ResolverInterface::Callback,
  26. /// which defines what to do with the result, and then calling resolve()
  27. /// on the ResolverInterface implementation.
  28. ///
  29. /// One default Callback subclass is provided right now, in
  30. /// resolver_callback.[h|cc], which calls resumse() on a given DNSServer
  31. ///
  32. namespace isc {
  33. namespace resolve {
  34. ///
  35. /// \short Abstract interface to the resolver.
  36. ///
  37. /// Abstract interface to the resolver. The NameserverAddressStore uses this
  38. /// to ask for addresses. It is here because resolver does not yet exist.
  39. ///
  40. /// It is abstract to allow tests pass dummy resolvers.
  41. ///
  42. class ResolverInterface {
  43. public:
  44. /// \short An abstract callback for when the resolver is done.
  45. ///
  46. /// You can pass an instance of a subclass of this (as a
  47. /// CallbackPtr) to RecursiveQuery::sendQuery(), and when it
  48. /// is done, it will either call success() if there is an
  49. /// answer MessagePtr, or failure(), if the resolver was not
  50. /// able to find anything.
  51. ///
  52. /// Note that a result Message does not necessarily contain
  53. /// the actual answer (it could be a noerror/nodata response).
  54. class Callback {
  55. public:
  56. /// \short Some data arrived.
  57. virtual void success(const isc::dns::MessagePtr response) = 0;
  58. ///
  59. ///\short No data available.
  60. ///
  61. ///\todo Provide error reason (result of the
  62. /// classification call, for instance? We'd also
  63. /// need some way to say 'everything times out')
  64. ///
  65. virtual void failure() = 0;
  66. /// \short Virtual destructor, so descendants are cleaned up
  67. virtual ~Callback() {};
  68. };
  69. typedef boost::shared_ptr<Callback> CallbackPtr;
  70. ///
  71. ///\short Ask a question.
  72. ///
  73. /// Asks the resolver a question. Once the answer is ready
  74. /// the callback is called.
  75. ///
  76. /// \param question What to ask. The resolver will decide who.
  77. /// \param callback What should happen when the answer is ready.
  78. ///
  79. virtual void resolve(const isc::dns::QuestionPtr& question,
  80. const CallbackPtr& callback) = 0;
  81. /// \short Virtual destructor, so descendants are properly cleaned up
  82. virtual ~ ResolverInterface() {}
  83. };
  84. } // namespace nsas
  85. } // namespace isc
  86. #endif //__RESOLVER_INTERFACE_H