예제 #1
0
파일: zfs.c 프로젝트: jamesyan84/zbase
static int ProcessVideoFile(const char *filePath)
{
	ZInfo4(DBG_MISC, "video: %s", filePath);

	ZDB_METAVIDEO *metadata = NULL;
	char filename[MAX_PATH_SIZE] = {0};
	char dstPath[MAX_PATH_SIZE] = {0};
	int isDir;

	if((metadata = GetVideoMetadata((char *)filePath)) == NULL) {
		ZError(DBG_MISC, "Get video metadata failed!");
		return -1;
	}
	getFileName(filePath, &filename[0]);
	sprintf(dstPath, "%s/%s", VIDEO_SORT_FOLDER, filename);
	if(ZUtilIsFilePresent(dstPath, &isDir)) {
		getNewFileName(pzfs, filename);
		sprintf(dstPath, "%s/%s", VIDEO_SORT_FOLDER, filename);
		ZInfo3(DBG_MISC, "File exist, will use new filename [%s]", filename);
	}
	if(metadata->res)
		free(metadata->res);
	metadata->res = strdup(dstPath);
	if(ZDBInsertVideo(zfs.zVDBHandle, metadata)) {
		ZError(DBG_MISC, "Insert Video to DB failed!");
		free(metadata);
		return -2;
	}
	if (rename (filePath, dstPath) != 0) {
		ZError (DBG_MISC, "Move file failed -> %s -> %s", filePath, dstPath);
	}
	free(metadata);
	return 0;
}
예제 #2
0
KIO_EXPORT KIO::CopyJob *KIO::pasteDataAsync(const KURL &u, const QByteArray &_data, const QString &text)
{
    KURL new_url = getNewFileName(u, text);

    if(new_url.isEmpty())
        return 0;

    return pasteDataAsyncTo(new_url, _data);
}
LogMng::LogMng(const QString& prefix)
	: m_prefix(prefix)
	, m_fileSize(0)
	, m_sizeOfSingleFile(500000000)
{
	QDir curPath;
	curPath.mkdir("LOG");
	curPath.cd("LOG");
	m_path = curPath.absolutePath();


	m_file.setFileName(getNewFileName());
	qDebug()<<m_file.fileName();
}
예제 #4
0
KIO_EXPORT void KIO::pasteData(const KURL &u, const QByteArray &_data)
{
    KURL new_url = getNewFileName(u, QString::null);
    // We could use KIO::put here, but that would require a class
    // for the slotData call. With NetAccess, we can do a synchronous call.

    if(new_url.isEmpty())
        return;

    KTempFile tempFile;
    tempFile.setAutoDelete(true);
    tempFile.dataStream()->writeRawBytes(_data.data(), _data.size());
    tempFile.close();

    (void)KIO::NetAccess::upload(tempFile.name(), new_url, 0);
}
예제 #5
0
파일: zfs.c 프로젝트: jamesyan84/zbase
static int ProcessPhotoFile(const char *filePath)
{
	ZInfo4(DBG_MISC, "photo: %s", filePath);

	ZDB_METAPHOTO 	*metadata = NULL;
	char		 	filename[MAX_PATH_SIZE] = {0};
	char 			dstPath[MAX_PATH_SIZE] = {0};
	int 			isDir;

	if((metadata = GetPhotoMetadata((char *)filePath)) == NULL) {
		ZError(DBG_MISC, "Get audio metadata failed!");
		return -1;
	}

	getFileName(filePath, &filename[0]);
	sprintf(dstPath, "%s/%s", PHOTO_SORT_FOLDER, filename);
	
	if(ZUtilIsFilePresent(dstPath, &isDir)) {
		getNewFileName(pzfs, filename);
		sprintf(dstPath, "%s/%s", PHOTO_SORT_FOLDER, filename);
		ZInfo3(DBG_MISC, "File exist, will use new filename [%s]", filename);
	}

	if(metadata->res)
		free(metadata->res);
	metadata->res = strdup(dstPath);
	
	if (rename (filePath, dstPath) != 0) {
		ZError (DBG_MISC, "Move file failed -> %s -> %s", filePath, dstPath);
	}
	
	//add by Joe on 2008-10-30
#ifdef 		Z_CFG_PHOTO_THUMBNAIL
	createThumbnailPhoto(dstPath, &metadata->attr2);
#endif
	//end
	
	if(ZDBInsertPhoto(zfs.zPDBHandle, metadata)) {
		ZError(DBG_MISC, "Insert photo to DB failed!");
		free(metadata);
		return -2;
	}
	free(metadata);
	return 0;
}
void LogMng::log(LogTypeEnum type, const QString& msg)
{
	if (!m_file.isOpen())
	{
		if (!m_file.open(QIODevice::Append | QIODevice::Text))
			return;
	}

	if((m_fileSize+msg.length()) >= m_sizeOfSingleFile)
	{
		m_file.close();
		m_file.setFileName(getNewFileName());
		if(!m_file.open(QIODevice::Append | QIODevice::Text)) 
			return;

		m_fileSize = 0;
	}

	m_fileSize += m_file.write((qPrintable(msg)));
	m_file.flush();
}
예제 #7
0
파일: paste.cpp 프로젝트: KDE/kio
KIO::Job *pasteMimeDataImpl(const QMimeData *mimeData, const QUrl &destUrl,
                            const QString &dialogText, QWidget *widget,
                            bool clipboard)
{
    QByteArray ba;
    const QString suggestedFilename = QString::fromUtf8(mimeData->data(QStringLiteral("application/x-kde-suggestedfilename")));

    // Now check for plain text
    // We don't want to display a mimetype choice for a QTextDrag, those mimetypes look ugly.
    if (mimeData->hasText()) {
        ba = mimeData->text().toLocal8Bit(); // encoding OK?
    } else {
        const QStringList formats = extractFormats(mimeData);
        if (formats.isEmpty()) {
            return 0;
        } else if (formats.size() > 1) {
            QUrl newUrl;
            ba = chooseFormatAndUrl(destUrl, mimeData, formats, dialogText, suggestedFilename, widget, clipboard, &newUrl);
            if (ba.isEmpty()) {
                return 0;
            }
            return putDataAsyncTo(newUrl, ba, widget, KIO::Overwrite);
        }
        ba = mimeData->data(formats.first());
    }
    if (ba.isEmpty()) {
        return 0;
    }

    const QUrl newUrl = getNewFileName(destUrl, dialogText, suggestedFilename, widget);
    if (newUrl.isEmpty()) {
        return 0;
    }

    return putDataAsyncTo(newUrl, ba, widget, KIO::Overwrite);
}
예제 #8
0
파일: zfs.c 프로젝트: jamesyan84/zbase
static int ProcessAudioFile(ZFS_TASK *ptask){
	//Audio policy:
	//1. check whether the file exist in imported folder
	//2. if exist, check whether they have same metadata
	// 3. if metadata are the same, skip/delete the file
	// 4. if metadata are not the same, insert to DB
	//5. if file is new, insert to DB
	//6. if the file had extract an alum art, check whether 
	//   the album art had been exist in DB or folder, if not
	//   exist, insert to DB and move to extracted folder
	//7. update import summary
	ZInfo4 (DBG_MISC, "Process Audio file[%s][%s]", ptask->path, ptask->name);

	const int PROCESS_AUDUIO_THUMBNAIL = 1;

	PAUDIO_METADATA metadata = NULL;
	char fileName[MAX_PATH_SIZE] = {0};
	char fullPath[MAX_PATH_SIZE] = {0};
	char dstPath[MAX_PATH_SIZE*2] = {0};
	int isDir;
	int validformat = TRUE;//paul add on 080827,merge from Olive.

	sprintf(&fullPath[0], "%s/%s", ptask->path, ptask->name);
	/* Covert fileName to UTF-8 */
	strcpy (fileName, ptask->name);
	if (ZUtilConvertStringToUTF8 (fileName) != 0) {
		ZError (DBG_MISC, "Covert UTF-8 failed, skip this file->%s", fileName);
		return -1;
	}
	else {
		ZInfo4 (DBG_MISC, "UTF-8 fileName->%s", fileName);
	}
	sprintf(&dstPath[0], "%s/%s", DIR_IMPORTED, fileName);

	if ((metadata = getAudioMetadata (fullPath, &validformat)) == NULL) {
		//paul add on 080827 for invalid format merge from Olive.
		if (validformat == FALSE){
			validformat = TRUE;
			if (removeFile (pzfs, ptask->path, fileName) != 0)
			{
				ZError (DBG_MISC,
						"Remove invalid file failed->%s/%s",
						ptask->path, fileName);
			}
			else{
				ZInfo4 (DBG_MISC,
						"Remove invalid file success->%s/%s",
						ptask->path, fileName);
			}
		}//end paul

		//this is an internal error, if the audio did not have embbed metadata
		//we will genreate an empty one
		ZError (DBG_MISC, "Cannot get any metadata -> %s", metadata);
		return -1;
	}
	ZInfo4 (DBG_MISC, "Get metadata successfully.");

	/* zfs policy here */
	/* First, we will check to see if the file exists in DIR_IMPORTED folder,
	   if yes, we will match the metadata, if the same of metadata, This is the
	   duplicate file, otherwise, it is the new file, so change it's name as the
	   format xxxx_DDUUPPx.ext and insert it into DB */

	/* get the file in DIR_IMPORTED ??? */
	if(ZUtilIsFilePresent(dstPath, &isDir)) {
	//if (matchFile (DIR_IMPORTED, fileName) == 1) {
		/* get the file in the DIR_IMPORT folder */
		/* Now, try to match the metadata */
		// NOTE: not finished
		if (matchMetadata (pzfs, metadata) == 1) {
			ZError (DBG_MISC, "Duplicate file!!! The metadata exists in DB->%s", fullPath);
//			if (removeFile (pzfs, ptask->path, fileName) != 0) {
			if (removeFile (pzfs, ptask->path, ptask->name) != 0) {
				ZError (DBG_MISC, "Remove duplicate file failed->%s/%s",
						ptask->path, fileName);
			}
			else {
				deletedPlusOne ();	/* Deleted plus one */
				saveSummary (pzfs);	/* Sync to DB */
			}

			if (metadata)
				free(metadata);

			return 0;
		}
		else {
			/* not the same metadata, so change the last file name to new name */
			/* filename format xxx_DDUUPPx.xxx */
			getNewFileName (pzfs, fileName);
			sprintf(&dstPath[0], "%s/%s", DIR_IMPORTED, fileName);
			ZInfo3(DBG_MISC, "Have file with same name, use new filename [%s]", fileName);
		}
	}

	if(AUTO_SORT) {
		/* move media file to DIR_IMPORTED */
		if (rename (fullPath, dstPath) != 0) {
			ZError (DBG_MISC, "Move file failed -> %s", fullPath);
			if (removeFile (pzfs, ptask->path, ptask->name) != 0) {
				ZError (DBG_MISC, "Remove file failed -> %s/%s",
						ptask->path, ptask->name);
			}
			else {
				deletedPlusOne ();	/* Deleted plus one */
				saveSummary (pzfs);	/* Sync to DB */
			}

			if (metadata)
				free(metadata);

			return 0;
		}
		strcpy (metadata->path, dstPath);
		ZInfo4 (DBG_MISC, "Move file successfully -> %s", metadata->path);
	}

	if(PROCESS_AUDUIO_THUMBNAIL) {
		/* move thumbnail to DIR_EXTRACTED 2008-3-18 */
		/* Thumbnail Policy:
		   If the thumbnail of the album exist, don't replace it, otherwise move it to
		   DIR_ EXTRACTED with album name */

		//TODO: need to check unknown policy
		// changed by Joe (if album is unknown , do not get the albumArt)
		if ((strcasestr (metadata->album, "unknown") != NULL)
				&& (fileExists (metadata->albumArt) == 1)) {
			remove (metadata->albumArt);
			metadata->albumArt[0] = '\0';
		}

		if (strlen (metadata->albumArt) > 1 && fileExists (metadata->albumArt) == 1) {
			/* NOTE: if the album art exists in zDB, don't replace it */
			int exists = isAlbumArtExists (pzfs, metadata->album);
			if (exists == 0) {
				char tmp[MAX_PATH_SIZE] = {0};
				sprintf (tmp, "%s/%s%s", DIR_EXTRACTED,
						metadata->album,
						THUMBNAIL_EXTENSION);
				/* Move the thumbnail to DIR_EXTRACTED */
				ZInfo4 (DBG_MISC, "Move thumbnail %s to %s",
						metadata->albumArt, tmp);
				/* NOTE: rename don't support over-partition move */
				if (rename (metadata->albumArt, tmp) != 0) {
					ZError (DBG_MISC, "Move thumbnail failed ->%s",
							metadata->albumArt);

					/* Delete the thumbnail */
					remove (metadata->albumArt);
					metadata->albumArt[0] = '\0';
				}
				else {
					strcpy (metadata->albumArt, tmp);
					ZInfo4 (DBG_MISC, "Move thumbnail successfully");
				}
			}
			else {
				if (exists == -1)
					ZError (DBG_MISC, "Get album art info from zDB failed, will not insert albumArt");
				else
					ZInfo4 (DBG_MISC, "Duplicate albumArt, will not insert");

				/* Delete the thumbnail */
				remove (metadata->albumArt);
				//the album art should be cleaned to avoid zDB update the album's album art
				metadata->albumArt[0] = '\0';
			}
		}
	}

	/* add to DB */
	if (addAudioDBItem (pzfs, metadata) != 0) {
		ZError (DBG_MISC, "add metadata to DB failed");

			if (metadata)
				free(metadata);

		return -1;
	}
	else {
		/* import num plus one */
		importedPlusOne ();
		if (saveSummary (pzfs) != 0) {
			ZWarning (DBG_MISC, "Save summary failed 2.");
		}
	}
	
	if(metadata)
		free(metadata);

	return 0;
}
예제 #9
0
파일: set.c 프로젝트: nagyistge/ctn
/* nsetBFBCallback
**
** Purpose:
**	Describe the purpose of the function
**
** Parameter Dictionary:
**	Define the parameters to the function
**
** Return Values:
**
** Notes:
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
static CONDITION
nsetBFBCallback(MSG_N_SET_REQ * nsetRequest,
		MSG_N_SET_RESP * nsetResponse,
		void *sendBack, DUL_PRESENTATIONCONTEXT * pc)
{
#ifdef ASG
    CONDITION
    cond;			/* various condition codes returned by the
				 * facilities */

    PRN_BASICFILMBOX bfbAttrib,	/* structure to hold the attributes of BASIC
				 * FILM BOX */
       *bfbPtr = NULL;		/* pointer to the above structure */
    int
        index;			/* loop indices */
    int
        index2;
    char
       *fileName;		/* filename holding attributes of Basic Film
				 * Box instance that is to be enqueued */
    GQ_ELEM
	gqElement;		/* A GQ element that shall hold the instance
				 * of the Basic Film Box */
    char
       *flagNameList = NULL;	/* holds values and names of attributes that
				 * cause any error during verification */

    static APP_BFBIMAGEDISPLAYFORMAT
        bfbImageDisplayFormat;	/* this structure gets filled by the
				 * verification service as a side-effect */

    /* define the table of all attributes that need to be verified */
    static SUPPORTEDATTRIBUTES supportedAttributeList[] = {
	{PRN_BFB_K_MAGNIFICATIONTYPE, "BFB Magnification Type ",
	bfbMagnificationType, (int) DIM_OF(bfbMagnificationType)},
	{PRN_BFB_K_MAXDENSITY, "BFB Max Density ", NULL, 0},
	{PRN_BFB_K_CONFIGURATIONINFO, "BFB Configuration Information ",
	bfbConfigurationInfo, (int) DIM_OF(bfbConfigurationInfo)},
	{PRN_BFB_K_SMOOTHINGTYPE, "BFB Smoothing Type", NULL, 0},
	{PRN_BFB_K_BORDERDENSITY, "BFB Border Density ",
	bfbBorderDensity, (int) DIM_OF(bfbBorderDensity)},
	{PRN_BFB_K_EMPTYIMAGEDENSITY, "BFB Empty Image Density ",
	bfbEmptyImageDensity, (int) DIM_OF(bfbEmptyImageDensity)},
	{PRN_BFB_K_MINDENSITY, "BFB Min Density ", NULL, 0},
	{PRN_BFB_K_TRIM, "BFB Trim ", bfbTrim, (int) DIM_OF(bfbTrim)}
    };

    /* we build up the response message */
    nsetResponse->type = MSG_K_N_SET_RESP;
    nsetResponse->status = MSG_K_SUCCESS;
    nsetResponse->messageIDRespondedTo = nsetRequest->messageID;
    nsetResponse->dataSetType = DCM_CMDDATANULL;
    nsetResponse->conditionalFields = 0;
    strcpy(nsetResponse->classUID, nsetRequest->classUID);
#ifdef ASG
    nsetResponse->dataSet = NULL;
#endif
    /*
     * verify that the arriving NSet request for the Basic Film Box is for
     * the last created film box instance
     */

    /* Parse the received data set */
    bfbPtr = &bfbAttrib;
    bfbPtr->bfbAttributeFlag = 0x0;
    (void) strcpy(bfbPtr->filmBoxSOPClassUID, nsetRequest->classUID);
    (void) strcpy(bfbPtr->filmBoxSOPInstanceUID, nsetResponse->instanceUID);
    cond = PRN_ParseObject(&nsetRequest->dataSet, PRN_K_BASICFILMBOX,
			   (void **) &bfbPtr);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_ParseObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    if (traceFlag) {
	printf("Basic Film Box Attributes specified by SCU:\n");
	PRN_DumpAttributes(bfbPtr, stdout);
    }
    /*
     * We verify if the performing SCU has provided all mandatory attributes
     * and the requesting SCU has specified values for the mandatory
     * attributes. Further, we also verify if the optional attributes
     * requested by the SCU are supported by the performing SCU. Finally, we
     * verify if the values supplied by the requesting SCU are supported by
     * the performing SCU.
     * 
     * At any point, the function finds a discrepancy, it returns the
     * appropriate error condition
     */
    cond = supportedAttributes(MSG_K_N_CREATE_REQ, bfbPtr,
	       supportedAttributeList, (int) DIM_OF(supportedAttributeList),
			       &flagNameList, (void **) &nsetResponse);
    if (cond != APP_NORMAL) {
	/*
	 * depending upon the condition returned, set the message status
	 * value
	 */
	switch (cond) {
	case APP_MISSINGREQUIREDATTRIBUTE:
	    nsetResponse->status = MSG_K_MISSINGATTRIBUTE;
	    cond = COND_PushCondition(APP_ERROR(cond), flagNameList,
				      "nsetBFBCallback");
	    goto ERROR_RETURN;
	    break;
	case APP_UNSUPPORTEDMANDATORYATTRIBUTE:
	    cond = COND_PushCondition(APP_ERROR(cond), flagNameList,
				      "nsetBFBCallback");
	    goto ERROR_RETURN;
	    break;
	case APP_UNSUPPORTEDOPTIONALATTRIBUTE:
	    /* nsetResponse->status = MSG_K_NOSUCHATTRIBUTE; */
	    nsetResponse->status = MSG_K_SUCCESS;
	    break;
	case APP_UNSUPPORTEDATTRIBUTEVALUE:
	    /* nsetResponse->status = MSG_K_INVALIDATTRIBUTEVALUE; */
	    nsetResponse->status = MSG_K_SUCCESS;
	    break;
	}
    }
    /*
     * we need to build the referenced image box sequence to be included in
     * the data set. We do not support sequence of annotation boxes.
     */
    bfbPtr->referencedBABSeq = NULL;	/* no seq of annotation boxes */
    bfbPtr->referencedBIBSeq = LST_Create();
    if (bfbPtr->referencedBIBSeq == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "LST_Create", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		   APP_ERROR(APP_FAILURE), "LST_Create", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /*
     * We also update the hierarchy. Create a copy of the BFB instance
     */
    if ((bfbInstance = malloc(sizeof(*bfbInstance))) == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_MALLOCFAILURE),
				  "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
			   APP_ERROR(APP_MALLOCFAILURE), "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    (void) strcpy(bfbInstance->bfbInstanceUID, nsetResponse->instanceUID);
    bfbInstance->bfbAttrib = NULL;

    /* now acquire space to store the list of image boxes */
    bfbInstance->babList = NULL;/* we do not have an annotation box */
    bfbInstance->bibList = LST_Create();
    if (bfbInstance->bibList == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "LST_Create", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		   APP_ERROR(APP_FAILURE), "LST_Create", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /*
     * The SCP now creates instances of the BASIC IMAGE BOX SOP class
     * depending on the attribute value viz. imageDisplayFormat
     * 
     */
    switch (bfbImageDisplayFormat.type) {
    case STANDARD_FORMAT:
	/* images are stored in row-major order */
	for (index = 0; index < bfbImageDisplayFormat.format.standard.numRows;
	     index++) {
	    for (index2 = 0; index2 <
	       bfbImageDisplayFormat.format.standard.numColumns; index2++) {
		cond = createBIBList(bfbPtr);
		if (cond != APP_NORMAL) {
		    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
					"createBIBList", "nsetBFBCallback");
		    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "createBIBList",
					      "nsetBFBCallback");
		    goto ERROR_RETURN;
		}
	    }
	}
	break;
    case ROW_FORMAT:
	for (index = 0; index < bfbImageDisplayFormat.format.row.numRows;
	     index++) {
	    for (index2 = 0; index2 <
		 bfbImageDisplayFormat.format.row.imagesPerRow[index];
		 index2++) {
		cond = createBIBList(bfbPtr);
		if (cond != APP_NORMAL) {
		    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
					"createBIBList", "nsetBFBCallback");
		    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "createBIBList",
					      "nsetBFBCallback");
		    goto ERROR_RETURN;
		}
	    }
	}
	break;
    case COL_FORMAT:
	for (index = 0; index < bfbImageDisplayFormat.format.standard.numRows;
	     index++) {
	    for (index2 = 0; index2 <
		 bfbImageDisplayFormat.format.col.imagesPerColumn[index];
		 index2++) {
		cond = createBIBList(bfbPtr);
		if (cond != APP_NORMAL) {
		    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
					"createBIBList", "nsetBFBCallback");
		    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "createBIBList",
					      "nsetBFBCallback");
		    goto ERROR_RETURN;
		}
	    }
	}
	break;
    }
    /*
     * We need to update the following flag since, the SCP provides this
     * attribute.
     */
    bfbPtr->bfbAttributeFlag |= PRN_BFB_K_REFERENCEDBASICIMAGEBOXSEQ;
    /* we now build the response data set */
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
    cond = PRN_BuildObject((void *) bfbPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /* also add this to the hierarchy */
    cond = PRN_BuildObject((void *) bfbPtr, &bfbInstance->bfbAttrib);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /*
     * If the server's terminal has x-capability and wishes to enqueue the
     * film box instance in the GQueue
     */
    if (gqueueFlag) {
	gqElement.prnMessage = PRN_NEWFILMBOX;
	(void) strcpy(gqElement.instanceUID, bfbInstance->bfbInstanceUID);
	/* get a new file name to store the object */
	fileName = getNewFileName();
	(void) strcpy(gqElement.objFile, fileName);

	/* now write the object into the file and enqueue it */
	cond = DCM_WriteFile(&bfbInstance->bfbAttrib, DCM_ORDERLITTLEENDIAN,
			     fileName);
	if (cond != DCM_NORMAL) {
	    unlink(gqElement.objFile);	/* delete the file before exiting */
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "DCM_WriteFile", "nsetBFBCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
		APP_ERROR(APP_FAILURE), "DCM_WriteFile", "nsetBFBCallback");
	    goto ERROR_RETURN;
	}
	cond = GQ_Enqueue((void *) &gqElement);
	if (cond != GQ_NORMAL) {
	    unlink(gqElement.objFile);
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "GQ_Enqueue", "nsetBFBCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
				      APP_ERROR(APP_FAILURE),
				      "GQ_Enqueue", "nsetBFBCallback");
	    goto ERROR_RETURN;
	}
    }
    /*
     * add this bfbInstance to the list of basic film boxes maintained by the
     * the parent Basic Film Session instance
     */
    cond = LST_Enqueue(&bfsInstance.bfbList, bfbInstance);
    if (cond != LST_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "LST_Enqueue", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		  APP_ERROR(APP_FAILURE), "LST_Enqueue", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /* Attributes need to be sent back */
    cond = PRN_BuildObject((void *) bfbPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFBCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFBCallback");
	goto ERROR_RETURN;
    }
    /* everything is successful (may have warnings) */
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
#ifdef ASG
    nsetResponse->status = MSG_K_SUCCESS;
#endif
    if (traceFlag) {
	printf("Returning SRV_NORMAL in nsetBFBCallback\n");
	MSG_DumpMessage(nsetResponse, stdout);
    }
    return SRV_NORMAL;

ERROR_RETURN:
    COND_DumpConditions();
    if (traceFlag) {
	printf("Returning SRV_CALLBACKABORTEDSERVICE in nsetBFBCallback\n");
	MSG_DumpMessage(nsetResponse, stdout);
    }
    return SRV_CALLBACKABORTEDSERVICE;
#endif
    return SRV_NORMAL;
}
예제 #10
0
파일: set.c 프로젝트: nagyistge/ctn
/* nsetBFSCallback
**
** Purpose:
**	Callback function invoked by SRV_NSetResponse to set the attributes
**	of Basic Film Session
**
** Parameter Dictionary:
**	nsetRequest	Pointer to the set request
**	nsetResponse	Pointer to the set response
**	sendBack	Indicates whether attributes are to be sent back
**			to the requesting SCU
**	pc		Presentation context describes this SOP class
**
** Return Values:
**	SRV_NORMAL on success
**	SRV_CALLBACKABORTEDSERVICE on failure
**
** Notes:
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
static CONDITION
nsetBFSCallback(MSG_N_SET_REQ * nsetRequest,
		MSG_N_SET_RESP * nsetResponse,
		void *sendBack, DUL_PRESENTATIONCONTEXT * pc)
{
    CONDITION
    cond;			/* condition code returned by various
				 * facilities used by the callback */
    PRN_BASICFILMSESSION bfsAttrib,	/* holds attributes of the Basic Film
					 * Session received from the
					 * requesting SCU */
       *bfsPtr;			/* a pointer to the above structure */
    char
       *fileName;		/* filename holding attributes of Basic Film
				 * Session instance */
    GQ_ELEM
	gqElement;		/* The GQ element to be enqueued */
    char
       *flagNameList = NULL;	/* holds attribute names for which the
				 * verification service caused an error */

    /* define a table of all those attributes that need to be verified */
    static SUPPORTEDATTRIBUTES supportedAttributeList[] = {
	{PRN_BFS_K_COPIES, "BFS Copies ", bfsSupportedCopies,
	(int) DIM_OF(bfsSupportedCopies)},
	{PRN_BFS_K_PRIORITY, "BFS Priority ", bfsSupportedPriority,
	(int) DIM_OF(bfsSupportedPriority)},
	{PRN_BFS_K_MEDIUMTYPE, "BFS Medium type ", bfsSupportedMediumType,
	(int) DIM_OF(bfsSupportedMediumType)},
	{PRN_BFS_K_FILMDESTINATION, "BFS Film Destination ",
	bfsSupportedFilmDestination, (int) DIM_OF(bfsSupportedFilmDestination)},
	{PRN_BFS_K_FILMSESSIONLABEL, "BFS Film Session Label ",
	    bfsSupportedFilmSessionLabel,
	(int) DIM_OF(bfsSupportedFilmSessionLabel)},
#ifdef ASG
	{PRN_BFS_K_MEMORYALLOCATION, "BFS Memory Allocation ",
	NULL, 0}
#endif
    };

    /* we build up the response message */
    nsetResponse->type = MSG_K_N_SET_RESP;
    nsetResponse->messageIDRespondedTo = nsetRequest->messageID;
    strcpy(nsetResponse->classUID, nsetRequest->classUID);
    strcpy(nsetResponse->instanceUID, nsetRequest->instanceUID);
    nsetResponse->dataSetType = DCM_CMDDATANULL;
    nsetResponse->conditionalFields = 0;
#ifdef ASG
    nsetResponse->dataSet = NULL;
#endif

    /*
     * Verify that the instance UID specified in the Request message is valid
     */
    if (strcmp(bfsInstance.bfsInstanceUID, nsetRequest->instanceUID) != 0) {
	/* instance UID conflict */
	nsetResponse->status = MSG_K_CLASSINSTANCECONFLICT;
	strcpy(nsetResponse->requestedClassUID, nsetRequest->classUID);
	strcpy(nsetResponse->requestedInstanceUID, nsetRequest->instanceUID);
	nsetResponse->conditionalFields |= MSG_K_N_SETRESP_REQUESTEDCLASSUID |
	    MSG_K_N_SETRESP_REQUESTEDINSTANCEUID;
	goto ERROR_RETURN;
    }
    bfsPtr = &bfsAttrib;
    bfsPtr->bfsAttributeFlag = 0x0;
    (void) strcpy(bfsPtr->filmSessionSOPClassUID, nsetResponse->classUID);
    (void) strcpy(bfsPtr->filmSessionSOPInstanceUID,
		  nsetResponse->instanceUID);
    /* Parse the data set sent by SCU */
    cond = PRN_ParseObject(&nsetRequest->dataSet, PRN_K_BASICFILMSESSION,
			   (void **) &bfsPtr);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetBFSCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_ParseObject", "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    if (traceFlag) {
	printf("Film Session Attributes Specified by SCU (NSet Request):\n");
	PRN_DumpAttributes(bfsPtr, stdout);
    }
    /*
     * We verify if the performing SCU has provided all mandatory attributes
     * and the requesting SCU has specified values for the mandatory
     * attributes. Further, we also verify if the optional attributes
     * requested by the SCU are supported by the performing SCU. Finally, we
     * verify if the values supplied by the requesting SCU are supported by
     * the performing SCU.
     * 
     * At any point, the function finds a discrepancy, it returns the
     * appropriate error condition
     */
    cond = supportedAttributes(MSG_K_N_SET_REQ, bfsPtr,
	       supportedAttributeList, (int) DIM_OF(supportedAttributeList),
			       &flagNameList, (void **) &nsetResponse);
    if (cond != APP_NORMAL) {
	/*
	 * depending upon the condition returned, set the message status
	 * value
	 */
	switch (cond) {
	case APP_MISSINGREQUIREDATTRIBUTE:
	    nsetResponse->status = MSG_K_MISSINGATTRIBUTE;
	    break;
	case APP_UNSUPPORTEDMANDATORYATTRIBUTE:
	case APP_UNSUPPORTEDOPTIONALATTRIBUTE:
	    nsetResponse->status = MSG_K_NOSUCHATTRIBUTE;
	    break;
	case APP_UNSUPPORTEDATTRIBUTEVALUE:
	    nsetResponse->status = MSG_K_INVALIDATTRIBUTEVALUE;
	    break;
	}
	cond = COND_PushCondition(APP_ERROR(cond), flagNameList,
				  "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    /*
     * At this point the verification process is successful Proceed by
     * creating the Basic Film Session
     */
    /* UPDATE hierarchy */
    cond = PRN_BuildObject((void *) bfsPtr, &bfsInstance.bfsAttrib);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFSCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    strcpy(bfsInstance.bfsInstanceUID, nsetResponse->instanceUID);
    /*
     * If the server's terminal has x-capability and wishes to enqueue the
     * image in the GQueue
     */
    if (gqueueFlag) {
	gqElement.prnMessage = PRN_NEWFILMSESSION;	/* element type to be
							 * enqueued */
	(void) strcpy(gqElement.instanceUID, bfsInstance.bfsInstanceUID);
	/* get a new file name to store the object */
	fileName = getNewFileName();
	(void) strcpy(gqElement.objFile, fileName);

	/* now write the object into the file and enqueue it */
	cond = DCM_WriteFile(&bfsInstance.bfsAttrib, DCM_ORDERLITTLEENDIAN,
			     fileName);
	if (cond != DCM_NORMAL) {
	    unlink(gqElement.objFile);	/* delete the file before exiting */
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "DCM_WriteFile", "nsetBFSCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
		APP_ERROR(APP_FAILURE), "DCM_WriteFile", "nsetBFSCallback");
	    goto ERROR_RETURN;
	}
	cond = GQ_Enqueue(gqID, (void *) &gqElement);
	if (cond != GQ_NORMAL) {
	    unlink(gqElement.objFile);
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "GQ_Enqueue", "nsetBFSCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
		   APP_ERROR(APP_FAILURE), "GQ_Enqueue", "nsetBFSCallback");
	    goto ERROR_RETURN;
	}
    }
    /* Attributes need to be sent back */
    cond = PRN_BuildObject((void *) bfsPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetBFSCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
	      APP_ERROR(APP_FAILURE), "PRN_BuildObject", "nsetBFSCallback");
	goto ERROR_RETURN;
    }
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
    /* everything is successful */
    nsetResponse->status = MSG_K_SUCCESS;
    return SRV_NORMAL;

    /*
     * This is the exit point for all errors that may have occurred in the
     * callback routine
     */
ERROR_RETURN:
    COND_DumpConditions();
    return SRV_CALLBACKABORTEDSERVICE;
}
예제 #11
0
파일: set.c 프로젝트: nagyistge/ctn
/* nsetImageBoxCallback
**
** Purpose:
**	Call back routine called by SRV_NSetResponse used to build the
**	N-SET response message.
**
** Parameter Dictionary:
**	nsetRequest	Pointer to N-SET Request message
**	nsetResponse	Pointer to N-SET Response message
**	ctx		Pointer to context for this command.
**	pc		Presentation context that describes this SOP Class
**
** Return Values:
**	SRV_NORMAL under error free conditions.
**
**	SRV_CALLBACKABORTEDSERVICE
**	SRV_NORMAL
**
** Algorithm:
**	Description of the algorithm (optional) and any other notes.
*/
static CONDITION
nsetImageBoxCallback(MSG_N_SET_REQ * nsetRequest,
		     MSG_N_SET_RESP * nsetResponse,
		     void *sendBack, DUL_PRESENTATIONCONTEXT * pc)
{

    CONDITION
    cond;			/* condition code returned by various
				 * facilities */
    int
        index;			/* loop index */
    char
       *flagNameList = NULL;	/* holds attribute names that gave errors
				 * during verification process */
    BIB_NODE
	* bibNode;		/* pointer to instance of Image Box */
    char
       *fileName;		/* filename holding attributes of image */
    GQ_ELEM
	gqElement;		/* The GQ element that is to be enqueued */
    PRN_BASICIMAGEBOX
	bibAttrib,		/* structure holding attributes of image box */
	*bibPtr;		/* pointer to the above structure */
    CTNBOOLEAN
	flag = FALSE;		/* to check if the image is present */

    /*
     * For Image Position, we do a runtime check depending on the value of
     * Image Display Format specified by the Film Box attribute.
     */

    /* Now define a table of all supported attributes */
    static SUPPORTEDATTRIBUTES supportedAttributeList[] = {
	{PRN_BIB_K_IMAGEPOSITION, "BIB Image Position ", NULL, 0},
	{PRN_BIB_K_IMAGEMODULE, "BIB Preformatted Image Sequence ",
	NULL, 0},
	{PRN_BIB_K_POLARITY, "BIB Polarity ", bibPolarity,
	(int) DIM_OF(bibPolarity)},
	{PRN_BIB_K_MAGNIFICATIONTYPE, "BIB Magnification type ",
	bibMagnificationType, (int) DIM_OF(bibMagnificationType)},
#ifdef ASG
	{PRN_BIB_K_SMOOTHINGTYPE, "BIB Smooothing Type ",
	bibSmoothingType, (int) DIM_OF(bibSmoothingType)},
	{PRN_BIB_K_REQUESTEDIMAGESIZE, "BIB Requested Image Size ",
	bibRequestedImageSize, (int) DIM_OF(bibRequestedImageSize)}
#endif
    };

    /* we now build up the response message */
    nsetResponse->type = MSG_K_N_SET_RESP;
    nsetResponse->messageIDRespondedTo = nsetRequest->messageID;
    strcpy(nsetResponse->classUID, nsetRequest->classUID);
    strcpy(nsetResponse->instanceUID, nsetRequest->instanceUID);

    /* default */
    nsetResponse->dataSetType = DCM_CMDDATANULL;
#ifdef ASG
    nsetResponse->dataSet = NULL;	/* no data set is sent */
#endif

    bibPtr = &bibAttrib;
    bibPtr->bibAttributeFlag = 0x0;
    (void) strcpy(bibPtr->imageBoxSOPClassUID, nsetRequest->classUID);
    (void) strcpy(bibPtr->imageBoxSOPInstanceUID, nsetRequest->instanceUID);
    /* Parse the data set sent by the SCU */
    cond = PRN_ParseObject(&nsetRequest->dataSet, PRN_K_BASICGREYSCALEIMAGEBOX,
			   (void **) &bibPtr);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetImageBoxCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
				  APP_ERROR(APP_FAILURE), "PRN_ParseObject",
				  "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    /* PRN_DumpAttributes(bibPtr, stdout); */
    cond = supportedAttributes(MSG_K_N_SET_REQ, bibPtr, supportedAttributeList,
			(int) DIM_OF(supportedAttributeList), &flagNameList,
			       (void **) &nsetResponse);
    if (cond != APP_NORMAL) {
	switch (cond) {
	case APP_MISSINGREQUIREDATTRIBUTE:
	    nsetResponse->status = MSG_K_MISSINGATTRIBUTE;
	    break;
	case APP_UNSUPPORTEDMANDATORYATTRIBUTE:
	case APP_UNSUPPORTEDOPTIONALATTRIBUTE:
	    nsetResponse->status = MSG_K_NOSUCHATTRIBUTE;
	    break;
	case APP_UNSUPPORTEDATTRIBUTEVALUE:
	    nsetResponse->status = MSG_K_INVALIDATTRIBUTEVALUE;
	    break;
	}
	cond = COND_PushCondition(APP_ERROR(cond), flagNameList,
				  "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    /*
     * Now we update the hierarchy. We note here that attributes are set for
     * the image boxes belonging to the current BASIC FILM BOX instance which
     * is given by bfbInstance
     */
    bibNode = (BIB_NODE *) LST_Position(&bfbInstance->bibList,
					LST_Head(&bfbInstance->bibList));
    if (bibNode == NULL) {
	cond = COND_PushCondition(APP_ERROR(APP_MISSINGIMAGES),
				  "nsetImageBoxCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
		      APP_ERROR(APP_MISSINGIMAGES), "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    flag = FALSE;
    /*
     * go thru the list of Image SOP instance UIDs maintained by the Film Box
     * instance
     */
    for (index = 0; index < (int) LST_Count(&bfbInstance->bibList)
	 && !flag; index++) {
	/* now see if the instance UID matches */
	if (strcmp(nsetRequest->instanceUID, bibNode->bibInstanceUID) == 0) {
	    flag = TRUE;
	}
	if (!flag)
	    bibNode = (BIB_NODE *) LST_Next(&bfbInstance->bibList);
    }
    if (flag == FALSE) {
	cond = COND_PushCondition(APP_ERROR(APP_NOSUCHINSTANCE),
			  nsetRequest->instanceUID, "nsetImageBoxCallback");
	nsetResponse->status = MSG_K_NOSUCHOBJECTINSTANCE;
	goto ERROR_RETURN;
    }
    /* we now store the attributes of the image box */
    /*
     * To avoid copying so much data, we just make a pointer point to the
     * dataSet
     */
    bibNode->bibAttrib = nsetRequest->dataSet;
    nsetRequest->dataSet = NULL;/* remove the data set from the request
				 * message */

    /*
     * If the server's terminal has x-capability and wishes to enqueue the
     * image in the GQueue
     */
    if (gqueueFlag) {
	gqElement.prnMessage = PRN_NEWIMAGEBOX;
	(void) strcpy(gqElement.instanceUID, bibNode->bibInstanceUID);
	/* get a new file name to store the object */
	fileName = getNewFileName();
	(void) strcpy(gqElement.objFile, fileName);

	/* now write the object into the file and enqueue it */
	cond = DCM_WriteFile(&bibNode->bibAttrib, DCM_ORDERLITTLEENDIAN,
			     fileName);
	if (cond != DCM_NORMAL) {
	    unlink(gqElement.objFile);	/* delete the file before exiting */
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				   "DCM_WriteFile", "nsetImageBoxCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
				    APP_ERROR(APP_FAILURE), "DCM_WriteFile",
				      "nsetImageBoxCallback");
	    goto ERROR_RETURN;
	}
	cond = GQ_Enqueue(gqID, (void *) &gqElement);
	if (cond != GQ_NORMAL) {
	    unlink(gqElement.objFile);
	    cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				      "GQ_Enqueue", "nsetImageBoxCallback");
	    updateOnProcessingFailure((void **) &nsetResponse,
				      APP_ERROR(APP_FAILURE), "GQ_Enqueue",
				      "nsetImageBoxCallback");
	    goto ERROR_RETURN;
	}
    }
    /* send attributes back, but do not send back the image pixel data */
    /* temporarily we reset the FLAG for the pixel data */
    nsetResponse->dataSetType = DCM_CMDDATAOTHER;
    bibPtr->bibAttributeFlag ^= PRN_BIB_K_IMAGEMODULE;
    cond = PRN_BuildObject((void *) bibPtr, &nsetResponse->dataSet);
    if (cond != PRN_NORMAL) {
	cond = COND_PushCondition(APP_ERROR(APP_FAILURE),
				  "PRN_BuildObject", "nsetImageBoxCallback");
	updateOnProcessingFailure((void **) &nsetResponse,
				  APP_ERROR(APP_FAILURE), "PRN_BuildObject",
				  "nsetImageBoxCallback");
	goto ERROR_RETURN;
    }
    /* set back the FLAG */
    bibPtr->bibAttributeFlag |= PRN_BIB_K_IMAGEMODULE;
    /* everything is successful */
    nsetResponse->status = MSG_K_SUCCESS;
    return SRV_NORMAL;

ERROR_RETURN:
    COND_DumpConditions();
    return SRV_CALLBACKABORTEDSERVICE;
}
예제 #12
0
void Database::indexCreate(IndexDefinition &indexDef) {

  if(indexDef.getColumnCount() < 1 || indexDef.getColumnCount() >= MAXKEYFIELDCOUNT) {
    /* must be < MAXKEYFIELDCOUNT because there has to be DbAddr at the end */
    throwSqlError(SQL_KEY_TOO_BIG,_T("Invalid columncount (=%d)"),indexDef.getColumnCount());
  }

  if(indexDef.getIndexType() != INDEXTYPE_PRIMARY &&
     indexDef.getIndexType() != INDEXTYPE_UNIQUE  &&
     indexDef.getIndexType() != INDEXTYPE_NON_UNIQUE) {
     throwSqlError(SQL_INVALID_INDEXTYPE,_T("Invalid indextype (=%d)"),indexDef.getIndexType());
  }

  if(indexDef.m_fileName.length() == 0) {
    indexDef.m_fileName = getNewFileName(_T("KEY"));
  }

  if(indexDef.m_indexName.length() == 0) {
    if(indexDef.getIndexType() == INDEXTYPE_PRIMARY) {
      indexDef.m_indexName = indexDef.m_tableName;
    } else {
      throwSqlError(SQL_INVALID_INDEXNAME,_T("Invalid indexname:<%s>"),indexDef.m_indexName.cstr());
    }
  }

  if(DbFile::exist(indexDef.m_fileName)) {
    throwSqlError(SQL_FILE_ALREADY_EXIST,_T("File <%s> already exist"),indexDef.m_fileName.cstr());
  }

  indexDef.m_tableName = toUpperCase(indexDef.m_tableName);
  indexDef.m_indexName = toUpperCase(indexDef.m_indexName);
  indexDef.m_fileName  = toUpperCase(indexDef.m_fileName);

  const TableDefinition &tableDef = getTableDefinition(indexDef.m_tableName);

  if(tableDef.getTableType() != TABLETYPE_USER) {
    throwSqlError(SQL_INVALID_TABLETYPE,_T("Invalid tabletype (=%c)"),tableDef.getTableType());
  }

/* check that the indexname is not already used */

  KeyFile indexfile2(*this,SYSTEM_INDEXKEY2_FNAME, DBFMODE_READWRITE);
  KeyFileDefinition keydef2(indexfile2);
  KeyType key2;
  keydef2.put(key2,0,indexDef.m_indexName );
  if(indexfile2.searchMin(RELOP_EQ, key2, 1)) {
    throwSqlError(SQL_INDEX_ALREADY_EXIST,_T("Index <%s> already exist"),indexDef.m_indexName.cstr());
  }

  if(!inTMF()) {
    throwSqlError(SQL_NO_TRANSACTION,_T("indexCreate:No active tmf"));
  }

  KeyFileDefinition keydef = tableDef.getKeyFileDefinition(indexDef);

  KeyFile::create(indexDef.m_fileName, keydef);

  try {
    KeyFile  keyFile( indexDef.m_fileName, DBFMODE_READWRITE, false);
    DataFile datafile(tableDef.getFileName(), DBFMODE_READONLY , false);
    const TableInfo &tableInfo = getTableInfo(tableDef.getTableName());

  /* TODO Lock datafile to avoid new records to be inserted */

    if(indexDef.getIndexType() != INDEXTYPE_PRIMARY) {
      dataFileScan(indexDef.m_tableName, KeyGenerator(*this, keyFile, indexDef, tableInfo, keydef));
    }

    sysTabIndexInsert(indexDef);

  /* TODO Invalidate all binded program-packages; Unlock datafile */
  } catch(sqlca) {
    DbFile::destroy(indexDef.m_fileName);
    throw;
  }
  removeFromCache(indexDef.m_tableName);
}