// When we receive an url response this method is called; 
// The loaded image is removed from the async_queue and added to the
// update queue. The update queue is used to update the texture.
//--------------------------------------------------------------
void ofxThreadedImageLoaderSingleton::urlResponse(ofHttpResponse & response) {
	if(response.status == 200) {
		lock();
		
		// Get the loaded url from the async queue and move it into the update queue.
		entry_iterator it = getEntryFromAsyncQueue(response.request.name);
		if(it != images_async_loading.end()) {
			(*it).image->loadImage(response.data);
			images_to_update.push_back(*it);
			images_async_loading.erase(it);
		}
		
		unlock();
	}else{
		// log error.
		ofLogError()<< "Could not get image from url, response status: " << response.status;
		ofRemoveURLRequest(response.request.getID());
		// remove the entry from the queue
		lock();
		entry_iterator it = getEntryFromAsyncQueue(response.request.name);
		if(it != images_async_loading.end()) {
			images_async_loading.erase(it);
		}
		unlock();
	}
}
示例#2
0
//--------------------------------------------------------------
void ofxTwitter::urlResponse(ofHttpResponse & response){
    
        if(response.status==200){
            ofLogNotice("ofxTwitter::urlResponse") << response.request.name << " loaded ok.";
            for(int i = 0; i < data.size(); i++) {
                
                vector<string> request_info = ofSplitString(response.request.name, "_");
                if(data[i].user.id_str == request_info[1]) {
                    if(request_info[0] == "profile") {
                        data[i].user.profile_image.loadImage(response.data);
                        data[i].user.profile_image_url_loaded = true;
                    }
                    if(request_info[0] == "banner") {
                        data[i].user.profile_banner.loadImage(response.data);
                        data[i].user.profile_banner_url_loaded = true;
                    }
                }
                
            }
        }else{
            ofLogError("ofxTwitter::urlResponse") << response.status << " " << response.error;
            if(response.status == -1 || response.status == 404) ofRemoveURLRequest(response.request.getID());
        }
    
}