session.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. bool recvmsg(ISC::Data::ElementPtr& msg,
  31. bool nonblock = true);
  32. void subscribe(std::string group,
  33. std::string instance = "*",
  34. std::string subtype = "normal");
  35. void unsubscribe(std::string group,
  36. std::string instance = "*");
  37. unsigned int group_sendmsg(ISC::Data::ElementPtr& msg,
  38. std::string group,
  39. std::string instance = "*",
  40. std::string to = "*");
  41. bool group_recvmsg(ISC::Data::ElementPtr& envelope,
  42. ISC::Data::ElementPtr& msg,
  43. bool nonblock = true);
  44. unsigned int reply(ISC::Data::ElementPtr& envelope,
  45. ISC::Data::ElementPtr& newmsg);
  46. };
  47. } // namespace CC
  48. } // namespace ISC
  49. #endif // _ISC_SESSION_H