예제 #1
0
INT	NETWORK_TF_CLASS::readBinary(BYTE *buffer_ptr, UINT length)

//  DESCRIPTION     : Read data from underlying Data Transfer PDUs.
//  PRECONDITIONS   : 
//  POSTCONDITIONS  : 
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	UINT totalLength = length;
	UINT lengthRead = 0;

	// loop reading required amount of data - if possible
	while (lengthRead < totalLength)
	{
		// get the current PDU
		DATA_TF_PDU_CLASS *dataTfPdu_ptr = getDataTransferPdu(dataTransferIndexM);
		if (dataTfPdu_ptr == NULL) return -1;

		// get maximum length remaining in current PDV
		UINT32 remainingPdvLength = dataTfPdu_ptr->getCurrentPdvLength() - dataTransferOffsetM;

		// check if sufficient data in the current PDV to satisfy the read request
		if (length <= remainingPdvLength)
		{
			// sufficient data - copy amount requested
			byteCopy(buffer_ptr + lengthRead, dataTfPdu_ptr->getCurrentPdvData() + dataTransferOffsetM, length);

			// update offset by amount requested
			dataTransferOffsetM += length;

			// return length read
			lengthRead += length;
		}
		else
		{
			// read remaining PDV data
			byteCopy(buffer_ptr + lengthRead, dataTfPdu_ptr->getCurrentPdvData() + dataTransferOffsetM, remainingPdvLength);

			// update offset by amount requested
			dataTransferOffsetM += remainingPdvLength;

			// update lengths
			lengthRead += remainingPdvLength;
			length -= remainingPdvLength;

			// try to get more PDV data to read
			if (!getMorePdvDataToRead()) 
			{
				// failed to get more data - return the length read so far
				break;
			}
		}
	}

	// return length read
	return lengthRead;
}
예제 #2
0
bool NETWORK_TF_CLASS::writeBinary(const BYTE *buffer_ptr, UINT length)

//  DESCRIPTION     : Write data to underlying Data Transfer PDUs.
//  PRECONDITIONS   : 
//  POSTCONDITIONS  : 
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	UINT totalLength = length;
	UINT lengthWritten = 0;

	// loop reading required amount of data - if possible
	while (lengthWritten < totalLength)
	{
		// get the current PDU
		DATA_TF_PDU_CLASS *dataTfPdu_ptr = getDataTransferPdu(dataTransferIndexM);
		if (dataTfPdu_ptr == NULL) return false;

		// get maximum length remaining in current PDV
		UINT32 remainingPdvLength = dataTfPdu_ptr->getCurrentPdvLength() - dataTransferOffsetM;

		// check if sufficient space in the current PDV to satisfy the write request
		if (length <= remainingPdvLength)
		{
			// sufficient data - copy amount requested
			byteCopy(dataTfPdu_ptr->getCurrentPdvData() + dataTransferOffsetM, (BYTE*) buffer_ptr + lengthWritten, length);

			// update offset by amount requested
			dataTransferOffsetM += length;

			// write complete
			return true;
		}
		else
		{
			// write remaining PDV data
			byteCopy(dataTfPdu_ptr->getCurrentPdvData() + dataTransferOffsetM, (BYTE*) buffer_ptr + lengthWritten, remainingPdvLength);

			// update offset by amount requested
			dataTransferOffsetM += remainingPdvLength;

			// update lengths
			lengthWritten += remainingPdvLength;
			length -= remainingPdvLength;

			// try to get more PDV space to write
			if (!getMorePdvSpaceToWrite()) 
			{
				// failed to get more space - return failure
				break;
			}
		}
	}

	// return failure
	return false;
}
예제 #3
0
bool UID_CLASS::operator = (UID_CLASS& uid)

//  DESCRIPTION     : Operator assignment.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	bool result = false;

	// first free old UID
	cleanup();

	// allocate new storage
	valueM_ptr = new BYTE [uid.getLength() + 1];

	// copy UID
	if (valueM_ptr)
	{
		// save the length
		lengthM = uid.getLength();

		// copy value and null terminate it for convenience
		byteCopy(valueM_ptr, uid.get(), lengthM);
		valueM_ptr[lengthM] = NULLCHAR;

		result = true;
	}

	return result;
}
예제 #4
0
bool AE_TITLE_CLASS::operator = (AE_TITLE_CLASS& aeTitle)

//  DESCRIPTION     : Operator assignment.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	bool result = false;

	// first free old string
	cleanup();

	// copy empty aet
	if (!aeTitle.get()) return true;

	// allocate new storage
	valueM_ptr = new BYTE [aeTitle.getLength() + 1];

	// copy string
	if (valueM_ptr)
	{
		// save the length
		lengthM = aeTitle.getLength();

		// copy value and null terminate it for convenience
		byteCopy(valueM_ptr, aeTitle.get(), lengthM);
		valueM_ptr[lengthM] = NULLCHAR;

		result = true;
	}

	return result;
}
예제 #5
0
void AE_TITLE_CLASS::set(BYTE* aet_ptr, UINT32 length)

//  DESCRIPTION     : Set AET value.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	// first free old AET
	cleanup();

	// check for valid aet
	if ((!aet_ptr) || (!length)) return;

	// compute length to allocate
	UINT32 valueLength = (length < AE_LENGTH) ? AE_LENGTH : length;

	// allocate new storage
	valueM_ptr = new BYTE [valueLength + 1];

	// copy UID
	if (valueM_ptr)
	{
		// save the length
		lengthM = valueLength;

		// ensure that value is max filled with SPACES
		byteFill(valueM_ptr, SPACECHAR, valueLength);

		// copy value and null terminate it for convenience
		byteCopy(valueM_ptr, aet_ptr, length);
		valueM_ptr[lengthM] = NULLCHAR;
	}
}
예제 #6
0
void BYTE_STRING_CLASS::set(char* value_ptr)

//  DESCRIPTION     : Set string value.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	// first free old string
	cleanup();

	// check for valid string
	if (!value_ptr) return;

	// get length of string
	UINT32 length = strlen(value_ptr);
	if (!length) return;	

	// allocate new storage
	valueM_ptr = new BYTE [length + 1];

	// copy string
	if (valueM_ptr)
	{
		// save the length
		lengthM = length;

		// copy value and null terminate it for convenience
		byteCopy(valueM_ptr, (BYTE*) value_ptr, lengthM);
		valueM_ptr[lengthM] = NULLCHAR;
	}	
}
예제 #7
0
파일: highscore.c 프로젝트: endrift/scrum
void registerHighScore(int gameMode, const Score* score) {
	if (gameMode >= NUM_GAME_MODES) {
		return;
	}
	if (!scoreDB) {
		scoreDB = scoreBase();
	}
	PaddedScore* scores = scoreDB[gameMode].scores;
	int i, j;
	for (i = 0; i < NUM_HIGH_SCORES; ++i) {
		byteCopy(&bufferScore, &scores[i], sizeof(bufferScore));
		if (score->score > bufferScore.score.score) {
			for (j = NUM_HIGH_SCORES - 1; j > i; --j) {
				byteCopy(&scores[j], &scores[j - 1], sizeof(PaddedScore));
			}
			bufferScore.score = *score;
			byteCopy(&scores[i], &bufferScore, sizeof(bufferScore));
			break;
		}
	}
}
예제 #8
0
파일: highscore.c 프로젝트: endrift/scrum
int isHighScore(int gameMode, const Score* score) {
	if (gameMode >= NUM_GAME_MODES) {
		return 0;
	}
	if (!scoreDB) {
		scoreDB = scoreBase();
	}
	byteCopy(&bufferScore, &scoreDB[gameMode].scores[NUM_HIGH_SCORES - 1], sizeof(bufferScore));
	if (bufferScore.score.name[0]) {
		return score->score > bufferScore.score.score;
	} else {
		return 1;
	}
}
예제 #9
0
파일: highscore.c 프로젝트: endrift/scrum
const Score* getHighScore(int gameMode, int place) {
	if (place >= 10 || gameMode >= NUM_GAME_MODES) {
		return 0;
	}

	if (!scoreDB) {
		scoreDB = scoreBase();
	}
	byteCopy(&bufferScore, &scoreDB[gameMode].scores[place], sizeof(bufferScore));
	if (bufferScore.score.name[0]) {
		return &bufferScore.score;
	}
	return 0;
}
예제 #10
0
void FILEHEAD_CLASS::setPrefix(char *prefix_ptr)

//  DESCRIPTION     : Method to set the Dicom Prefix.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           : 
//<<===========================================================================
{
	// set up the Dicom prefix
	byteZero(prefixM, sizeof(prefixM));
	UINT length = byteStrLen((BYTE*) prefix_ptr);
	length = (length > FMI_PREFIX_LENGTH) ? FMI_PREFIX_LENGTH : length;
	byteCopy(prefixM, (BYTE*) prefix_ptr, length);
}
예제 #11
0
void FILEHEAD_CLASS::setPreambleValue(char* preamble_ptr)

//  DESCRIPTION     : Method to set the Preamble.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           : 
//<<===========================================================================
{
	// set up the preamble
	//preambleValueM = value;
	//byteFill(preambleM, preambleValueM, FMI_PREAMBLE_LENGTH);
	byteZero(preambleM, sizeof(preambleM));
	UINT length = byteStrLen((BYTE*) preamble_ptr);
	length = (length > FMI_PREAMBLE_LENGTH) ? FMI_PREAMBLE_LENGTH : length;
	byteCopy(preambleM, (BYTE*) preamble_ptr, length);
}
예제 #12
0
FILEHEAD_CLASS::FILEHEAD_CLASS()

//  DESCRIPTION     : Constructor.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           : 
//<<===========================================================================
{
	// constructor activities
	widTypeM = WID_FILEHEAD;

	// set up file preamble and prefix
	preambleValueM = FMI_PREAMBLE_VALUE;
	byteFill(preambleM, preambleValueM, FMI_PREAMBLE_LENGTH);
	byteZero(prefixM, sizeof(prefixM));
	byteCopy(prefixM, (BYTE*) FMI_PREFIX_VALUE, FMI_PREFIX_LENGTH);
	transferSyntaxUidM.set(EXPLICIT_VR_LITTLE_ENDIAN);
	filenameM = "";
	loggerM_ptr = NULL;
}
예제 #13
0
bool FILEHEAD_CLASS::updateWid(BASE_WAREHOUSE_ITEM_DATA_CLASS *wid_ptr)

//  DESCRIPTION     : Update this file head with the contents of the file head given.
//  PRECONDITIONS   :
//  POSTCONDITIONS  :
//  EXCEPTIONS      : 
//  NOTES           :
//<<===========================================================================
{
	bool result = true;

	FILEHEAD_CLASS *updateFilehead_ptr = static_cast<FILEHEAD_CLASS*>(wid_ptr);

	// copy all fields - assume update of all values
	preambleValueM = updateFilehead_ptr->preambleValueM;
	byteFill(preambleM, preambleValueM, FMI_PREAMBLE_LENGTH);
	byteZero(prefixM, sizeof(prefixM));
	byteCopy(prefixM, updateFilehead_ptr->prefixM, FMI_PREFIX_LENGTH);
	transferSyntaxUidM = updateFilehead_ptr->transferSyntaxUidM;

	// return result
	return result;
}