virtual void on_connect(){ try{ socket_.send(helpers::base64_encode(session_->init())); }catch(themispp::exception_t& e){ error_callback_(e.what()); } }
void send(const std::string& data) { try{ socket_.send(helpers::base64_encode(session_->wrap(std::vector<uint8_t>(data.c_str(), data.c_str()+data.length())))); }catch(themispp::exception_t& e){ error_callback_(e.what()); } }
void open(const std::string& url, const std::vector<uint8_t>& id, const std::vector<uint8_t>& priv_key, connect_callback_t on_connect){ connect_callback_=on_connect; try{ session_ = std::shared_ptr<themispp::secure_session_t>(new themispp::secure_session_t(id, priv_key, &callback_)); socket_.open(url); }catch (themispp::exception_t& e){ error_callback_(e.what()); } }
bool SbigDetector::SendCommand(short command, void* params, void* results) { last_error_ = SBIGUnivDrvCommand(command, params, results); if (last_error_ != CE_NO_ERROR) { GetErrorStringParams err_query{static_cast<uint16_t>(last_error_)}; GetErrorStringResults err_string; SBIGUnivDrvCommand(CC_GET_ERROR_STRING, &err_query, &err_string); cerr << "SBIG Error (" << last_error_ << "): " << err_string.errorString << endl; error_callback_(command, last_error_); return false; } return true; }
virtual void on_receive(const std::string& data){ try{ std::cerr<<data<<std::endl; std::vector<uint8_t> d=session_->unwrap(helpers::base64_decode(data)); if(!(session_->is_established())) socket_.send(helpers::base64_encode(d)); else if(d.size()==0) connect_callback_(); else receive_callback_(std::string((const char*)(&d[0]), d.size())); }catch(themispp::exception_t& e){ error_callback_(e.what()); } }
void Channel::HandleEventWithGuard(Timestamp receive_time) { event_handling_ = true; #if defined(__MACH__) || defined(__ANDROID_API__) LogTrace("%s", REventsToString().c_str()); #else VLOG(1) << REventsToString(); #endif if ((revents_ & POLLHUP) && !(revents_ & POLLIN)) { if (log_hup_) { #if defined(__MACH__) || defined(__ANDROID_API__) LogWarn("Channel::handle_event() POLLHUP"); #else LOG(WARNING) << "Channel::handle_event() POLLHUP"; #endif } if (close_callback_) { close_callback_(); } } if (revents_ & POLLNVAL) { #if defined(__MACH__) || defined(__ANDROID_API__) LogWarn("Channel::handle_event() POLLNVAL"); #else LOG(WARNING) << "Channel::handle_event() POLLNVAL"; #endif } if (revents_ & (POLLERR | POLLNVAL)) { if (error_callback_) error_callback_(); } #ifndef POLLRDHUP const int POLLRDHUP = 0; #endif if (revents_ & (POLLIN | POLLPRI | POLLRDHUP)) { if (read_callback_) read_callback_(receive_time); } if (revents_ & POLLOUT) { if (write_callback_) write_callback_(); } event_handling_ = false; }
virtual void on_error(int32_t code, const std::string& reason){\ error_callback_(reason); }