fake_session.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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: session.h 1250 2010-03-09 22:52:15Z jinmei $
  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 <cc/data.h>
  21. namespace boost {
  22. namespace asio {
  23. class io_service;
  24. }
  25. }
  26. // global variables so tests can insert
  27. // update and check, before, during and after
  28. // the actual session object was created/destroyed
  29. // if initial_messages contains a list of messages,
  30. // these are sent when recv_msg or group_recvmsg is called
  31. // instead of whatever is in the msg queue
  32. extern isc::data::ElementPtr initial_messages;
  33. extern isc::data::ElementPtr subscriptions;
  34. extern isc::data::ElementPtr msg_queue;
  35. bool haveSubscription(const std::string& group, const std::string& instance);
  36. bool haveSubscription(const isc::data::ElementPtr group, const isc::data::ElementPtr instance);
  37. isc::data::ElementPtr getFirstMessage(std::string& group, std::string& to);
  38. void addMessage(isc::data::ElementPtr, const std::string& group, const std::string& to);
  39. namespace isc {
  40. namespace cc {
  41. class SessionError : public isc::Exception {
  42. public:
  43. SessionError(const char* file, size_t line, const char* what) :
  44. isc::Exception(file, line, what) {}
  45. };
  46. class Session {
  47. private:
  48. Session(const Session& source);
  49. Session& operator=(const Session& source);
  50. public:
  51. // public so tests can inspect them
  52. Session();
  53. Session(boost::asio::io_service& ioservice);
  54. ~Session();
  55. // XXX: quick hack to allow the user to watch the socket directly.
  56. int getSocket() const;
  57. void startRead(boost::function<void()> read_callback);
  58. void establish();
  59. bool connect();
  60. void disconnect();
  61. void sendmsg(isc::data::ElementPtr& msg);
  62. void sendmsg(isc::data::ElementPtr& env,
  63. isc::data::ElementPtr& msg);
  64. bool recvmsg(isc::data::ElementPtr& msg,
  65. bool nonblock = true, int seq = -1);
  66. bool recvmsg(isc::data::ElementPtr& env,
  67. isc::data::ElementPtr& msg,
  68. bool nonblock = true, int seq = -1);
  69. void subscribe(std::string group,
  70. std::string instance = "*");
  71. void unsubscribe(std::string group,
  72. std::string instance = "*");
  73. unsigned int group_sendmsg(isc::data::ElementPtr msg,
  74. std::string group,
  75. std::string instance = "*",
  76. std::string to = "*");
  77. bool group_recvmsg(isc::data::ElementPtr& envelope,
  78. isc::data::ElementPtr& msg,
  79. bool nonblock = true,
  80. int seq = -1);
  81. unsigned int reply(isc::data::ElementPtr& envelope,
  82. isc::data::ElementPtr& newmsg);
  83. bool hasQueuedMsgs();
  84. };
  85. } // namespace cc
  86. } // namespace isc
  87. #endif // _ISC_SESSION_H
  88. // Local Variables:
  89. // mode: c++
  90. // End: