Esempio n. 1
0
File: Job.cpp Progetto: sijp/NASH
		/*
		 * downloads the image from the manager' from the urlDownload
		 */
		bool Job::download(Employee &employee, HttpLineInterperter *resConfiguration)
		{
			cout<<"Resource is:"<<resConfiguration->getResource()<<endl;
			string downloadRequest = "GET /photos/" +
									resConfiguration->getResource() +
									"?rep=" + this->repDownload +
									" HTTP/1.1";
			employee.send(downloadRequest);
			employee.send("Host: "+employee.getHost()+"\n");
			
			HttpLineInterperter downResponsetInterperter;
			string s;
			while(employee.getFrameAscii(s) && s.size()>1)
			{
				downResponsetInterperter.insertLine(s);
				s.clear();
			}
			//if we succeded in downloading the image
			if(downResponsetInterperter.getStatus() == "200 OK")
			{
				//init a new byte array in the size of the content length
				int byteLength = downResponsetInterperter.getContentLength();
				uchar* dataByte = new uchar[byteLength];
				employee.getBytes(dataByte , byteLength);
				//dataBytes holds the bytes for the image
				this->mimeType = downResponsetInterperter.getContentType();
				//cout<<dataByte<<endl;
				vector<uchar> vecByte(dataByte , dataByte + byteLength/sizeof(uchar));
				//-1 as a flag means we get the image as is.
				this->image=imdecode(Mat(vecByte) , -1);
				
				cout<<"BLJKADSLVGJASDLFAS"<<endl;

				this->gP.setImage(&(this->image));
				delete [] dataByte;
				return true;
			}
			return false;
		}