void Pololu::Serial::Interface::transfer(Pololu::Request& request) { Request* serialRequest = dynamic_cast<Request*>(&request); if (serialRequest) transfer(*serialRequest); else throw RequestError(); }
Pololu::Usb::Request* Pololu::Usb::Protocol::createRequest(const std::string& typeName) const { std::map<std::string, Pointer<Pololu::Usb::Request> >::const_iterator it = requests.find(typeName); if (it != requests.end()) return it->second->clone(); else throw RequestError(typeName); }
void Server::loadObject (ObjectRequest const &request, Object *object) const { namespace fs = boost::filesystem; //fs::path path; bool is_url = false; if (request.url.size()) { if (request.content.size()) { throw RequestError("both url and content set"); } if (test_url(request.url)) { is_url = true; } } if (request.raw) { if (request.content.size()) { xtor.extract(request.content, request.type, object); } else if (is_url) { xtor.extract_url(request.url, request.type, object); } else { xtor.extract_path(request.url, request.type, object); } } else { if (request.content.size()) { std::istringstream is(request.content); object->read(is); } else { fs::path path; if (is_url) { // url path = fs::unique_path(); int r = wget(request.url, path.native()); if (r != 0) { throw ExternalError(request.url); } } else { path = fs::path(request.url); } ifstream is(path.native(), ios::binary); object->read(is); if (is_url) { fs::remove(path); } } } }
void Server::loadObject (ObjectRequest const &request, Object *object) const { namespace fs = boost::filesystem; fs::path path; bool is_url = false; if (request.url.size()) { if (request.content.size()) { throw RequestError("both url and content set"); } if (test_url(request.url)) { is_url = true; path = fs::unique_path(); string cmd = (boost::format("wget -O '%s' '%s'") % path.native() % request.url).str(); int r = ::system(cmd.c_str()); if (r != 0) { throw ExternalError(cmd); } } else { path = fs::path(request.url); } } if (request.raw) { if (request.content.size()) { xtor.extract(request.content, request.type, object); } else { // url std::cout<<"Inside Server::loadObject, request.raw = true"<<std::endl; xtor.extract_path(path.native(), request.type, object); } } else { if (request.content.size()) { std::istringstream is(request.content); object->read(is); } else { // url ifstream is(path.native(), ios::binary); object->read(is); } } if (is_url) { fs::remove(path); } }
void CSAuthenticated::handleClientRequestHeaderRead(const boost::system::error_code& error) { if (! error) { //we now have a complete header, read it and figure out what type of message we're dealing with try { //if were here we got a request. Update stats AssetClient::AddRequestToStats(); _isActive = true; _activeSince = pt::second_clock::local_time(); switch (_currentRequest->getType()) { case ClientRequestMsg::RT_GET: this->handleGetRequest(true); break; case ClientRequestMsg::RT_PURGE: this->handlePurgeRequest(); break; case ClientRequestMsg::RT_PUT: this->handlePutRequest(); break; case ClientRequestMsg::RT_TEST: this->handleTestRequest(); break; case ClientRequestMsg::RT_MAINT_PURGELOCALS: this->handlePurgeLocals(); break; case ClientRequestMsg::RT_STATUS_GET: this->handleStatusGet(); break; case ClientRequestMsg::RT_STORED_ASSET_IDS_GET: this->handleStoredAssetIdsGet(); break; case ClientRequestMsg::RT_GET_DONTCACHE: this->handleGetRequest(false); break; default: throw RequestError("Invalid request type sent to server"); } } catch (const std::exception& e) { SAFELOG(AppLog::instance().out() << "handleClientRequestHeaderRead(): Error while processing header: " << e.what() << std::endl); AssetClient::ptr client; if (client = _client.lock()) { client->disconnect(); } } } else { this->handleIoFailure(__FUNCTION__, error); } }