PacketHeader* PacketHeader::parse(byte* rawData) {
	PacketHeader *header=new PacketHeader();

	ByteBuffer byteBuffer;
	byteBuffer.Construct(rawData, 0, LENGTH, LENGTH);


	byteBuffer.GetArray(PacketHeader::opCodeBuffer, 0, OPCODE_LENGTH);
	//for(int i=0; i<2; i++) {
	//	AppLog("Array(2) : %d", PacketHeader::opCodeBuffer[i]);
	//}
	header->setOpCode(ByteToInt(PacketHeader::opCodeBuffer, OPCODE_LENGTH));

	//AppLog("OPCODE : %d", header->getOpCode());



	byteBuffer.GetArray(PacketHeader::packetSizeBuffer, 0, PAYLOAD_LENGTH);
	//for(int i=0; i<4; i++) {
	//	AppLog("Array(4) : %d", PacketHeader::packetSizeBuffer[i]);
	//}



	header->setPayloadLength(
			ByteToInt(PacketHeader::packetSizeBuffer, PAYLOAD_LENGTH)	//4
			- PacketHeader::LENGTH);

	//AppLog("OPCODE : %d", header->getPayloadLength());


	return header;
}
void RouteRequestManager::OnTransactionReadyToRead(Osp::Net::Http::HttpSession& httpSession, Osp::Net::Http::HttpTransaction& httpTransaction, int availableBodyLen){
	AppLogDebug("http ready called");
	HttpResponse* resp = httpTransaction.GetResponse();
	//String status = resp->GetStatusText();
	//AppLog("status: %S",status);

	ByteBuffer* buffer = (resp->ReadBodyN());
	char data[buffer->GetLimit()+1];
	buffer->SetPosition(0);
	buffer->GetArray((byte*)data, 0, buffer->GetLimit());
	data[buffer->GetLimit()] ='\0';
	String test(data);
	AppLogDebug("%S",test.GetPointer());
	AppLogDebug("\n\n");

	ArrayListT<Trip*>* trips=null;
	IRailAPI h;
	if(AppData::GetInstance()->getCurrentRequest() != null){
		trips = h.createTripList(buffer);
	}
	if(trips != null){
		if(!addToResults)
			AppData::GetInstance()->getCurrentRequest()->clearTrips();
		AppData::GetInstance()->getCurrentRequest()->getTrips()->AddItems(*trips);
		//AppLog("parsing succesfull");
		Controller::GetInstance()->switchToRoutePlannerResults();
	}
	else{
		//AppLogDebug("parsing failed");
		Controller::GetInstance()->showServerErrorMessage();
	}
	//write to file
	/*
	File f;
	int fileIndex = getRoutePlannerRegistryIndex();
	f.Construct(L"/Home/history/RP"+ Integer::ToString(fileIndex) + ".xml",L"w+",false);
	f.Write(*buffer);
	*/
}
示例#3
0
result
CategoryItemForm::ReadCustomListItems()
{
	result r = E_SUCCESS;
	String dirName(L"/Home/catalog/"+dir);
	Directory* pDir;
	DirEnumerator* pDirEnum;

	pDir = new Directory; // allocate Directory instance

	// Open directory
	r = pDir->Construct(dirName);

	// Read all directory entries
	pDirEnum = pDir->ReadN();

	String contentType;
	int i = 0;
	while(pDirEnum->MoveNext() == E_SUCCESS) {
		DirEntry dirEntry = pDirEnum->GetCurrentDirEntry();
		if(dirEntry.IsNomalFile()) {
			//AppLog("%S", dirEntry.GetName().GetPointer());
			if(!dirEntry.GetName().Equals("category.info", false)) {

				String fileName(dirName+"/"+dirEntry.GetName());

				String title, desc;
				String iTempStr, iTempStr2;

				File file;
				result r = file.Construct(fileName, L"r");
				if( IsFailed(r) )
				{
						AppLog("File::Consturct() is failed by %s", GetErrorMessage(r));
				}

				FileAttributes fileAttrs;
				file.GetAttributes(fileName, fileAttrs);
				long long size = fileAttrs.GetFileSize();


				ByteBuffer readBuffer;
				readBuffer.Construct((int)size + 1);

				r = file.Read(readBuffer);
				if( IsFailed(r) )
				{
						AppLog("File::Read() is failed by %s", GetErrorMessage(r));
				}

				char* data = new char[readBuffer.GetLimit()+1];
				readBuffer.SetPosition(0);
				readBuffer.GetArray((byte*)data, 0, readBuffer.GetLimit());
				data[readBuffer.GetLimit()] ='\0';
				//String str = String(data);

				String str;
				r = StringUtil::Utf8ToString(data, str);
				delete data;
				if(IsFailed(r)) {
					AppLog("File read error. File : %S", fileName.GetPointer());
					continue;
				}

				file.Seek(FILESEEKPOSITION_BEGIN, 0);
				file.Read(title);

				r = TextPic::GetTranslated(title);
				if (IsFailed(r)) {
					continue;
				}

				int linecount = 0;
				while(file.Read(iTempStr) != E_END_OF_FILE) {
					linecount++;
					iTempStr2.Append(iTempStr);
				}

				anciilist.Add(*(new String(iTempStr2)));
				titlelist.Add(*(new String(title)));
				filelist.Add(*(new String(fileName)));

				ItemListForm::AddListItem(*CategoryList, title, iTempStr2, i++, linecount);
				file.Flush();
			}
		}
	}

	delete pDirEnum;
	delete pDir;

	return r;
}