bool SimpleCache::GetFileForIndex(int index, ByteBuffer & data) {

	String filePath;
	BuildPathForFileInCache(index, filePath);

	if (!File::IsFileExist(filePath)) {
		return false;
	}

	AppLog("Reading data from cached file at %S", filePath.GetPointer());

	File cachedFile;
	cachedFile.Construct(filePath, L"r+");
	if (IsFailed(GetLastResult())) {
		AppLog("Error opening destination file in cache");
		return false;
	}

	FileAttributes fAttributes;
	File::GetAttributes(filePath, fAttributes);

	data.Construct(fAttributes.GetFileSize());
	cachedFile.Read(data);
	AppLog("Read cache: %d bytes", data.GetCapacity());
	if (IsFailed(GetLastResult())) {
		AppLog("Error reading from cached file");
		return false;
	}

	return true;

}
Esempio n. 2
0
bool BadaFileStream::seek(int32 offs, int whence) {
	bool result = false;
	switch (whence) {
	case SEEK_SET:
		// set from start of file
		SetLastResult(file->Seek(FILESEEKPOSITION_BEGIN, offs));
		result = (E_SUCCESS == GetLastResult());
		break;

	case SEEK_CUR:
		// set relative to offs
		if (bufferIndex < bufferLength && bufferIndex > (uint32)-offs) {
			// re-position within the buffer
			SetLastResult(E_SUCCESS);
			bufferIndex += offs;
			return true;
		} else {
			offs -= (bufferLength - bufferIndex);
			if (offs < 0 && file->Tell() + offs < 0) {
				// avoid negative positioning
				offs = 0;
			}
			if (offs != 0) {
				SetLastResult(file->Seek(FILESEEKPOSITION_CURRENT, offs));
				result = (E_SUCCESS == GetLastResult());
			} else {
				result = true;
			}
		}
		break;

	case SEEK_END:
		// set relative to end - positive will increase the file size
		SetLastResult(file->Seek(FILESEEKPOSITION_END, offs));
		result = (E_SUCCESS == GetLastResult());
		break;

	default:
		AppLog("Invalid whence %d", whence);
		return false;
	}

	if (!result) {
		AppLog("seek failed");
	}

	bufferIndex = bufferLength = 0;
	return result;
}
void
GDBPlot2DCommand::HandleSuccess
	(
	const JString& data
	)
{
	JArray<JFloat>* x = GetX();
	JArray<JFloat>* y = GetY();

	if ((GetLastResult()).BeginsWith("error,msg=\"No symbol"))
		{
		x->RemoveAll();
		y->RemoveAll();
		return;
		}

	const JIndex count = x->GetElementCount();

	JIndex i;
	JIndexRange r;
	JArray<JIndexRange> matchRange1, matchRange2;
	JString v1, v2;
	for (i=1; i<=count; i++)
		{
		if (!prefixPattern.MatchAfter(data, r, &matchRange1))
			{
			break;
			}
		r = matchRange1.GetElement(1);

		if (!prefixPattern.MatchAfter(data, r, &matchRange2))
			{
			break;
			}
		r = matchRange2.GetElement(1);

		v1 = data.GetSubstring(matchRange1.GetElement(2));
		v1.TrimWhitespace();

		v2 = data.GetSubstring(matchRange2.GetElement(2));
		v2.TrimWhitespace();

		JFloat x1, y1;
		if (!v1.ConvertToFloat(&x1) ||
			!v2.ConvertToFloat(&y1))
			{
			break;
			}

		x->SetElement(i, x1);
		y->SetElement(i, y1);
		}

	if (i <= count)
		{
		const JSize delta = count - (i-1);
		x->RemoveNextElements(count - delta + 1, delta);
		y->RemoveNextElements(count - delta + 1, delta);
		}
}
CMLocation
GDBGetStopLocation::GetLocation()
	const
{
	const JString& data = GetLastResult();

	CMLocation loc;
	JIndexRange r;
	if (locationPattern.Match(data, &r))
		{
		std::istringstream stream(data.GetCString());
		stream.seekg(r.last);

		JStringPtrMap<JString> map(JPtrArrayT::kDeleteAll);
		JString *s, *s1, *fullName;
		JIndex lineIndex;
		const JBoolean parsed = GDBLink::ParseMap(stream, &map);
		if (!parsed)
			{
			(CMGetLink())->Log("invalid data map");
			}
		else if (!map.GetElement("fullname", &fullName))
			{
			(CMGetLink())->Log("missing file name");
			}
		else if (!map.GetElement("line", &s))
			{
			(CMGetLink())->Log("missing line index");
			}
		else if (!s->ConvertToUInt(&lineIndex))
			{
			(CMGetLink())->Log("line index is not integer");
			}
		else
			{
			loc.SetFileName(*fullName);
			loc.SetLineNumber(lineIndex);
			}

		if (parsed && map.GetElement("func", &s) && map.GetElement("addr", &s1))
			{
			loc.SetFunctionName(*s);
			loc.SetMemoryAddress(*s1);
			}
		}
	else
		{
		(CMGetLink())->Log("GDBGetStopLocation failed to match");
		}

	return loc;
}
bool SimpleCache::StoreFile(ByteBuffer & data, int position) {

	String filePath;
	BuildPathForFileInCache(position, filePath);

	AppLog("Storing data object in file at %S", filePath.GetPointer());

	File cachedFile;
	cachedFile.Construct(filePath, L"w+");
	if (IsFailed(GetLastResult())) {
		AppLog("Error opening destination file in cache");
		return false;
	}

	cachedFile.Write(data);
	if (IsFailed(GetLastResult())) {
		AppLog("Error writing data to destination file in cache");
		return false;
	}

	return true;

}
Esempio n. 6
0
uint64_t FileData::Pos() const
{
#ifdef OMIM_OS_TIZEN
  int const pos = m_File->Tell();
  result const error = GetLastResult();
  if (IsFailed(error))
    MYTHROW(Writer::PosException, (m_FileName, m_Op, error, pos));
  return pos;
#else
  int64_t const pos = ftell64(m_File);
  if (pos == INVALID_POS)
    MYTHROW(Writer::PosException, (GetErrorProlog(), pos));

  ASSERT_GREATER_OR_EQUAL(pos, 0, ());
  return static_cast<uint64_t>(pos);
#endif
}
Esempio n. 7
0
void FileData::Read(uint64_t pos, void * p, size_t size)
{
#ifdef OMIM_OS_TIZEN
  result error = m_File->Seek(Tizen::Io::FILESEEKPOSITION_BEGIN, pos);
  if (IsFailed(error))
    MYTHROW(Reader::ReadException, (error, pos));
  int const bytesRead = m_File->Read(p, size);
  error = GetLastResult();
  if (static_cast<size_t>(bytesRead) != size || IsFailed(error))
    MYTHROW(Reader::ReadException, (m_FileName, m_Op, error, bytesRead, pos, size));
#else
  if (fseek64(m_File, pos, SEEK_SET))
    MYTHROW(Reader::ReadException, (GetErrorProlog(), pos));

  size_t const bytesRead = fread(p, 1, size, m_File);
  if (bytesRead != size || ferror(m_File))
    MYTHROW(Reader::ReadException, (GetErrorProlog(), bytesRead, pos, size));
#endif
}
void
GDBGetFrame::HandleSuccess
	(
	const JString& cmdData
	)
{
	const JString& data = GetLastResult();

	JIndexRange r;
	if (framePattern.Match(data, &r))
		{
		std::istringstream stream(data.GetCString());
		stream.seekg(r.last);

		JStringPtrMap<JString> map(JPtrArrayT::kDeleteAll);
		JString* s;
		JIndex frameIndex;
		if (!GDBLink::ParseMap(stream, &map))
			{
			(CMGetLink())->Log("invalid data map");
			}
		else if (!map.GetElement("level", &s))
			{
			(CMGetLink())->Log("missing frame index");
			}
		else if (!s->ConvertToUInt(&frameIndex))
			{
			(CMGetLink())->Log("frame index is not integer");
			}
		else
			{
			itsWidget->SelectFrame(frameIndex);
			}
		}
	else
		{
		(CMGetLink())->Log("GDBGetFrame failed to match");
		}
}
void
GDBGetStack::HandleSuccess
	(
	const JString& cmdData
	)
{
	JTreeNode* root       = (GetTree())->GetRoot();
	JIndex initFrameIndex = 0;

	const JString& data = GetLastResult();
	std::istringstream stream(data.GetCString());

	JIndexRange origRange, newRange;
	JStringPtrMap<JString> map(JPtrArrayT::kDeleteAll);
	JString frameName, fileName;
	while (framePattern.MatchAfter(data, origRange, &newRange))
		{
		stream.seekg(newRange.last);
		if (!GDBLink::ParseMap(stream, &map))
			{
			(CMGetLink())->Log("invalid data map");
			break;
			}
		origRange.first = origRange.last = ((std::streamoff) stream.tellg()) + 1;

		JString* s;
		JIndex frameIndex;
		if (!map.GetElement("level", &s))
			{
			(CMGetLink())->Log("missing frame index");
			continue;
			}
		if (!s->ConvertToUInt(&frameIndex))
			{
			(CMGetLink())->Log("frame index is not integer");
			continue;
			}

		frameName = *s;
		while (frameName.GetLength() < kFrameIndexWidth)
			{
			frameName.PrependCharacter('0');
			}
		frameName += ":  ";

		JString* fnName;
		if (!map.GetElement("func", &fnName))
			{
			(CMGetLink())->Log("missing function name");
			continue;
			}
		frameName += *fnName;

		if (map.GetElement("file", &s))
			{
			fileName = *s;
			}

		JIndex lineIndex = 0;
		if (map.GetElement("line", &s) &&
			!s->ConvertToUInt(&lineIndex))
			{
			(CMGetLink())->Log("line number is not integer");
			continue;
			}

		CMStackFrameNode* node =
			new CMStackFrameNode(root, frameIndex, frameName,
								 fileName, lineIndex);
		assert( node != NULL );
		root->Prepend(node);

		if (assertPattern.Match(*fnName))
			{
			initFrameIndex = frameIndex + 1;
			}
		}

	itsArgsCmd->Send();

	(GetWidget())->FinishedLoading(initFrameIndex);
}
Esempio n. 10
0
bool BadaFileStream::eos() const {
	return (bufferLength - bufferIndex == 0) && (GetLastResult() == E_END_OF_FILE);
}
Esempio n. 11
0
bool BadaFileStream::err() const {
	result r = GetLastResult();
	return (r != E_SUCCESS && r != E_END_OF_FILE);
}
Esempio n. 12
0
bool BadaFileStream::flush() {
	logEntered();
	SetLastResult(file->Flush());
	return (E_SUCCESS == GetLastResult());
}