session.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef _ISC_SESSION_H
  2. #define _ISC_SESSION_H 1
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. #include <iostream>
  7. #include "data.h"
  8. namespace isc {
  9. namespace cc {
  10. class SessionError : public std::exception {
  11. public:
  12. SessionError(std::string m = "CC Session Error") : msg(m) {}
  13. ~SessionError() throw() {}
  14. const char* what() const throw() { return msg.c_str(); }
  15. private:
  16. std::string msg;
  17. };
  18. class Session {
  19. private:
  20. int sock;
  21. int sequence; // the next sequence number to use
  22. public:
  23. std::string lname;
  24. Session();
  25. // XXX: quick hack to allow the user to watch the socket directly.
  26. int getSocket() const { return (sock); }
  27. void establish();
  28. void disconnect();
  29. void sendmsg(isc::data::ElementPtr& msg);
  30. void sendmsg(isc::data::ElementPtr& env, isc::data::ElementPtr& msg);
  31. bool recvmsg(isc::data::ElementPtr& msg,
  32. bool nonblock = true);
  33. bool recvmsg(isc::data::ElementPtr& env,
  34. isc::data::ElementPtr& msg,
  35. bool nonblock = true);
  36. void subscribe(std::string group,
  37. std::string instance = "*");
  38. void unsubscribe(std::string group,
  39. std::string instance = "*");
  40. unsigned int group_sendmsg(isc::data::ElementPtr msg,
  41. std::string group,
  42. std::string instance = "*",
  43. std::string to = "*");
  44. bool group_recvmsg(isc::data::ElementPtr& envelope,
  45. isc::data::ElementPtr& msg,
  46. bool nonblock = true);
  47. unsigned int reply(isc::data::ElementPtr& envelope,
  48. isc::data::ElementPtr& newmsg);
  49. };
  50. } // namespace cc
  51. } // namespace isc
  52. #endif // _ISC_SESSION_H