-/*
- * Dlt Test Client - Diagnostic Log and Trace
+/**
* @licence app begin@
+ * Copyright (C) 2012 BMW AG
+ *
+ * This file is part of GENIVI Project Dlt - Diagnostic Log and Trace console apps.
+ *
+ * Contributions are licensed to the GENIVI Alliance under one or more
+ * Contribution License Agreements.
*
- * Copyright (C) 2011, BMW AG - Alexander Wenzel <alexander.wenzel@bmw.de>
- *
- * This program is free software; you can redistribute it and/or modify it under the terms of the
- * GNU Lesser General Public License, version 2.1, as published by the Free Software Foundation.
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
- * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
- * Public License, version 2.1, for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License, version 2.1, along
- * with this program; if not, see <http://www.gnu.org/licenses/lgpl-2.1.html>.
- *
- * Note that the copyright holders assume that the GNU Lesser General Public License, version 2.1, may
- * also be applicable to programs even in cases in which the program is not a library in the technical sense.
- *
- * Linking DLT statically or dynamically with other modules is making a combined work based on DLT. You may
- * license such other modules under the GNU Lesser General Public License, version 2.1. If you do not want to
- * license your linked modules under the GNU Lesser General Public License, version 2.1, you
- * may use the program under the following exception.
- *
- * As a special exception, the copyright holders of DLT give you permission to combine DLT
- * with software programs or libraries that are released under any license unless such a combination is not
- * permitted by the license of such a software program or library. You may copy and distribute such a
- * system following the terms of the GNU Lesser General Public License, version 2.1, including this
- * special exception, for DLT and the licenses of the other code concerned.
- *
- * Note that people who make modified versions of DLT are not obligated to grant this special exception
- * for their modified versions; it is their choice whether to do so. The GNU Lesser General Public License,
- * version 2.1, gives permission to release a modified version without this exception; this exception
- * also makes it possible to release a modified version which carries forward this exception.
+ * \copyright
+ * This Source Code Form is subject to the terms of the
+ * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with
+ * this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
+ *
+ * \author Alexander Wenzel <alexander.aw.wenzel@bmw.de> BMW 2011-2012
+ *
+ * \file dlt_filetransfer.c
+ * For further information see http://www.genivi.org/.
* @licence end@
*/
return (unsigned long)st.st_size;
}
+/** A simple Hash function for C-strings
+ * @param str input string. E.g. a file path.
+ * @param hash start and result value for hash computation
+ *
+ */
+void stringHash(const char* str, unsigned long *hash )
+{
+ if (!str || !hash)
+ return;
+ unsigned int len = strlen(str);
+
+ unsigned int i = 0;
+ if (len <= 0){
+ return;
+ }
+
+ for(i = 0; i < len; i++)
+ {
+ *hash = 53 * *hash + str[i];
+ }
+
+}
+
+
//!Get some information about the file serial number of a file
/** See stat(2) for more informations.
* @param file Absolute file path
*/
unsigned long getFileSerialNumber(const char* file){
struct stat st;
+ unsigned long ret;
stat(file, &st);
- return (unsigned long)st.st_ino;
+ ret = st.st_ino;
+ ret = ret << (sizeof(ret)*8)/2;
+ ret |= st.st_size;
+ ret ^= st.st_ctime;
+ stringHash(file, &ret);
+ return ret;
}
//!Returns the creation date of a file
* See the Mainpages.c for more informations.
* @param fileContext Specific context to log the file to dlt
* @param filename Absolute file path
+ * @param alias Alias for the file. An alternative name to show in the receiving end
+ * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned.
+ */
+int dlt_user_log_file_header_alias(DltContext *fileContext,const char *filename, const char *alias){
+
+ if(isFile(filename))
+ {
+ DLT_LOG(*fileContext,DLT_LOG_INFO,
+ DLT_STRING("FLST"),
+ DLT_UINT(getFileSerialNumber(filename)),
+ DLT_STRING(alias),
+ DLT_UINT(getFilesize(filename)),
+ DLT_STRING(getFileCreationDate2(filename));
+ DLT_UINT(dlt_user_log_file_packagesCount(fileContext,filename)),
+ DLT_UINT(BUFFER_SIZE),
+ DLT_STRING("FLST")
+ );
+
+ return 0;
+ }
+ else
+ {
+ dlt_user_log_file_errorMessage(fileContext,filename, DLT_FILETRANSFER_ERROR_FILE_HEAD);
+ return DLT_FILETRANSFER_ERROR_FILE_HEAD;
+ }
+}
+
+//!Transfer the head of the file as a dlt logs.
+/**The head of the file must be logged to dlt because the head contains inforamtion about the file serial number,
+ * the file name, the file size, package number the file have and the buffer size.
+ * All these informations are needed from the plugin of the dlt viewer.
+ * See the Mainpages.c for more informations.
+ * @param fileContext Specific context to log the file to dlt
+ * @param filename Absolute file path
* @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned.
*/
int dlt_user_log_file_header(DltContext *fileContext,const char *filename){
DLT_STRING("for File:"),
DLT_STRING(filename)
);
+ fclose(file);
return DLT_FILETRANSFER_ERROR_FILE_DATA;
}