session.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
  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. // $Id$
  15. #ifndef _ISC_SESSION_H
  16. #define _ISC_SESSION_H 1
  17. #include <string>
  18. #include <boost/function.hpp>
  19. #include <exceptions/exceptions.h>
  20. #include "data.h"
  21. #include "session_config.h"
  22. namespace asio {
  23. class io_service;
  24. }
  25. namespace isc {
  26. namespace cc {
  27. class SessionImpl;
  28. class SessionError : public isc::Exception {
  29. public:
  30. SessionError(const char* file, size_t line, const char* what) :
  31. isc::Exception(file, line, what) {}
  32. };
  33. class Session {
  34. private:
  35. SessionImpl* impl_;
  36. private:
  37. Session(const Session& source);
  38. Session& operator=(const Session& source);
  39. public:
  40. Session();
  41. Session(asio::io_service& ioservice);
  42. ~Session();
  43. // XXX: quick hack to allow the user to watch the socket directly.
  44. int getSocket() const;
  45. void startRead(boost::function<void()> read_callback);
  46. void establish(const char* socket_file = NULL);
  47. void disconnect();
  48. void sendmsg(isc::data::ElementPtr& msg);
  49. void sendmsg(isc::data::ElementPtr& env,
  50. isc::data::ElementPtr& msg);
  51. bool recvmsg(isc::data::ElementPtr& msg,
  52. bool nonblock = true,
  53. int seq = -1);
  54. bool recvmsg(isc::data::ElementPtr& env,
  55. isc::data::ElementPtr& msg,
  56. bool nonblock = true,
  57. int seq = -1);
  58. void subscribe(std::string group,
  59. std::string instance = "*");
  60. void unsubscribe(std::string group,
  61. std::string instance = "*");
  62. int group_sendmsg(isc::data::ElementPtr msg,
  63. std::string group,
  64. std::string instance = "*",
  65. std::string to = "*");
  66. bool group_recvmsg(isc::data::ElementPtr& envelope,
  67. isc::data::ElementPtr& msg,
  68. bool nonblock = true,
  69. int seq = -1);
  70. int reply(isc::data::ElementPtr& envelope,
  71. isc::data::ElementPtr& newmsg);
  72. bool hasQueuedMsgs();
  73. };
  74. } // namespace cc
  75. } // namespace isc
  76. #endif // _ISC_SESSION_H
  77. // Local Variables:
  78. // mode: c++
  79. // End: