39 CompatibilityMode _compatMode;
46 CompatibilityMode mode()
const {
return _compatMode; }
49 const char *getPacketSeparator();
52 inline void setDelegate(
SessionDelegate *delegate) { _delegate = delegate; }
61 bool receive(
bool cooked);
62 bool parse(std::string
const &data);
65 bool send(
char const *data,
bool escaped =
false) {
66 return send(std::string(data), escaped);
69 template <
typename T>
bool send(T
const &data,
bool escaped =
false) {
70 std::ostringstream ss;
71 static std::string
const searchStr =
"$#}*";
81 std::find_first_of(data.begin(), data.end(), searchStr.begin(),
82 searchStr.end()) != data.end()) {
83 std::string encoded = Escape(data);
85 csum = Checksum(encoded);
90 csum = Checksum(data);
93 ss <<
'#' << std::hex << std::setw(2) << std::setfill(
'0')
96 std::string final_data = ss.str();
97 DS2LOG(Packet,
"putpkt(\"%s\", %u)", final_data.c_str(),
98 (
unsigned)final_data.length());
100 return _channel->send(final_data);
106 inline bool sendOK() {
return send(
"OK"); }
107 bool sendError(ErrorCode code);
110 inline bool getAckMode() {
return _ackmode; }
113 inline void setAckMode(
bool enabled) { _ackmode = enabled; }
117 return const_cast<SessionBase *
>(
this)->_interpreter;
122 virtual bool onACK();
123 virtual bool onNAK();
124 virtual bool onCommandReceived(
bool valid);
125 virtual void onInvalidData(std::string
const &data);