Bladeren bron

Kleine Änderungen.

Rind 5 jaren geleden
bovenliggende
commit
63902d35d9
6 gewijzigde bestanden met toevoegingen van 394 en 56 verwijderingen
  1. 83 12
      gfasitarautils.pro
  2. 1 0
      src/gfasitarautils.h
  3. 262 0
      src/suconv.c
  4. 38 0
      src/suconv.h
  5. 3 36
      src/sucycletimer.cpp
  6. 7 8
      src/sucycletimer.h

+ 83 - 12
gfasitarautils.pro

@@ -1,15 +1,34 @@
 TEMPLATE = lib
 VERSION = 1.0
-TARGET = gfasitarautils
-CONFIG -= app_bundle
-CONFIG -= qt
+CONFIG -= qt app_bundle
+CONFIG += c++11 shared thread
+
+HEADERS += \
+    src/gfasitarautils.h \
+    src/suconv.h \
+    src/sucycletimer.h
+
+SOURCES += \
+    src/suconv.c \
+    src/sucycletimer.cpp
+
+####################################################################################
+
+GFA_LIB_PATH = /usr/lib/gfa
+GFA_INC_PATH = /usr/include/gfa
+QMAKE_RPATHLINKDIR += $$GFA_LIB_PATH
+QMAKE_RPATHDIR += $$GFA_LIB_PATH
+QMAKE_DEL_DIR = rmdir --ignore-fail-on-non-empty
+QMAKE_LN_SHLIB = :
+
+####################################################################################
 
 CONFIG(debug, debug|release) {
     QMAKE_CXXFLAGS -= -Os
     QMAKE_CFLAGS -= -Os
     QMAKE_CXXFLAGS += -D_DEBUG
     QMAKE_CFLAGS += -D_DEBUG
-	TARGET = gfasitarautilsd
+	TARGET = $$join(TARGET,,,d)
 }
 
 linux-buildroot-g++ {
@@ -19,14 +38,66 @@ linux-buildroot-g++ {
     QMAKE_CFLAGS += -D_SITARA
 }
 
-# QMAKE_INCDIR += src
+####################################################################################
 
-# do not create symbolic links
-QMAKE_LN_SHLIB = :
+target.path = $$GFA_LIB_PATH
+INSTALLS += target
 
-HEADERS += \
-    src/gfasitarautils.h \
-    src/sucycletimer.h
+####################################################################################
 
-SOURCES += \
-    src/sucycletimer.cpp
+linux-g++ {
+	includes.path = $$GFA_INC_PATH
+	includes.extra += -$(INSTALL_FILE) $$PWD/src/gfasitarautils.h $(INSTALL_ROOT)$$includes.path
+	includes.extra += $$escape_expand(\\n\\t)-$(INSTALL_FILE) $$PWD/src/suconv.h $(INSTALL_ROOT)$$includes.path
+	includes.extra += $$escape_expand(\\n\\t)-$(INSTALL_FILE) $$PWD/src/sucycletimer.h $(INSTALL_ROOT)$$includes.path
+	includes.uninstall += -$(DEL_FILE) $(INSTALL_ROOT)$$includes.path/gfasitarautils.h
+	includes.uninstall += $$escape_expand(\\n\\t)-$(DEL_FILE) $(INSTALL_ROOT)$$includes.path/suconv.h
+	includes.uninstall += $$escape_expand(\\n\\t)-$(DEL_FILE) $(INSTALL_ROOT)$$includes.path/sucycletimer.h
+	INSTALLS += includes
+}
+
+####################################################################################
+
+linux-buildroot-g++ {
+	exists($$[QT_SYSROOT]) {
+		library.path = $$[QT_SYSROOT]$$target.path
+		library.extra += -$(INSTALL_PROGRAM) $(TARGET) $(INSTALL_ROOT)$$library.path/$(TARGET)
+		library.extra += $$escape_expand(\\n\\t)-$(SYMLINK) $(TARGET) $(INSTALL_ROOT)$$library.path/$(TARGET0)
+		library.extra += $$escape_expand(\\n\\t)-$(SYMLINK) $(TARGET) $(INSTALL_ROOT)$$library.path/$(TARGET1)
+		library.extra += $$escape_expand(\\n\\t)-$(SYMLINK) $(TARGET) $(INSTALL_ROOT)$$library.path/$(TARGET2)
+		library.uninstall += -$(DEL_FILE) $(INSTALL_ROOT)$$library.path/$(TARGET)
+		library.uninstall += $$escape_expand(\\n\\t)-$(DEL_FILE) $(INSTALL_ROOT)$$library.path/$(TARGET0)
+		library.uninstall += $$escape_expand(\\n\\t)-$(DEL_FILE) $(INSTALL_ROOT)$$library.path/$(TARGET1)
+		library.uninstall += $$escape_expand(\\n\\t)-$(DEL_FILE) $(INSTALL_ROOT)$$library.path/$(TARGET2)
+		INSTALLS += library
+
+		includes.path = $$[QT_SYSROOT]$$GFA_INC_PATH
+		includes.extra += -$(INSTALL_FILE) $$PWD/src/gfasitarautils.h $(INSTALL_ROOT)$$includes.path
+		includes.extra += $$escape_expand(\\n\\t)-$(INSTALL_FILE) $$PWD/src/suconv.h $(INSTALL_ROOT)$$includes.path
+		includes.extra += $$escape_expand(\\n\\t)-$(INSTALL_FILE) $$PWD/src/sucycletimer.h $(INSTALL_ROOT)$$includes.path
+		includes.uninstall += -$(DEL_FILE) $(INSTALL_ROOT)$$includes.path/gfasitarautils.h
+		includes.uninstall += $$escape_expand(\\n\\t)-$(DEL_FILE) $(INSTALL_ROOT)$$includes.path/suconv.h
+		includes.uninstall += $$escape_expand(\\n\\t)-$(DEL_FILE) $(INSTALL_ROOT)$$includes.path/sucycletimer.h
+		INSTALLS += includes
+
+		itoolchain.target = install_toolchain
+		itoolchain.depends = install_library install_includes
+		QMAKE_EXTRA_TARGETS += itoolchain
+
+		utoolchain.target = uninstall_toolchain
+		utoolchain.depends = uninstall_library uninstall_includes
+		QMAKE_EXTRA_TARGETS += utoolchain
+	}
+}
+
+####################################################################################
+
+deploylib.target = deploylib
+deploylib.commands = @echo BASENAME="$(QMAKE_TARGET)" > deploytargets
+deploylib.commands += $$escape_expand(\\n\\t)@echo TARGET="$(TARGET)" >> deploytargets
+deploylib.commands += $$escape_expand(\\n\\t)@echo TARGET0="$(TARGET0)" >> deploytargets
+deploylib.commands += $$escape_expand(\\n\\t)@echo TARGET1="$(TARGET1)" >> deploytargets
+deploylib.commands += $$escape_expand(\\n\\t)@echo TARGET2="$(TARGET2)" >> deploytargets
+deploylib.commands += $$escape_expand(\\n\\t)@echo HEADERS="\\\"gfasitarautils.h suconv.h sucycletimer.h\\\"" >> deploytargets
+PRE_TARGETDEPS += deploylib
+QMAKE_EXTRA_TARGETS += deploylib

+ 1 - 0
src/gfasitarautils.h

@@ -4,6 +4,7 @@
 #if !defined(AGD_GFASITARAUTILS_H__4D286252_22F3_4C84_8A32_8F74C353FC23__INCLUDED_)
 #define AGD_GFASITARAUTILS_H__4D286252_22F3_4C84_8A32_8F74C353FC23__INCLUDED_
 
+#include "suconv.h"
 #include "sucycletimer.h"
 
 /////////////////////////////////////////////////////////////////////////////

+ 262 - 0
src/suconv.c

@@ -0,0 +1,262 @@
+#include <errno.h>
+#include <string.h>
+#include <iconv.h>
+#include "suconv.h"
+
+#ifndef __BYTE_ORDER__
+#error __BYTE_ORDER__ not defined!
+#endif	//	__BYTE_ORDER__
+
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define _UTF_16			"UTF-16LE//"
+#define _UTF_32			"UTF-32LE//"
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define _UTF_16			"UTF-16BE//"
+#define _UTF_32			"UTF-32BE//"
+#else	//	__BYTE_ORDER__
+#error Invalid Byte Order!
+#endif	//	__BYTE_ORDER__
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+static size_t _Conv(iconv_t cd, char **pszIn, size_t nCbIn, char **pszOut, size_t nCbOut, size_t *pnTruncated)
+{
+    size_t nRet = nCbOut;
+    iconv(cd, pszIn, &nCbIn, pszOut, &nCbOut);
+    if(pnTruncated)
+    	*pnTruncated = nCbIn;
+	return nRet - nCbOut;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+size_t wcs16len(const char16_t *psz)
+{
+	const char16_t *p = psz;
+	while(*p)
+		p++;
+	return (size_t)(p - psz);
+}
+
+size_t wcs32len(const char32_t *psz)
+{
+	const char32_t *p = psz;
+	while(*p)
+		p++;
+	return (size_t)(p - psz);
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+size_t EncToUtf8(const char *pszEncIn, const void *pszIn, size_t nCbIn, char *pszOut, size_t nCbOut)
+{
+	if(pszEncIn && pszIn && pszOut && nCbOut && nCbIn != (size_t)-1)
+	{
+	    iconv_t desc = iconv_open("UTF-8//", pszEncIn);
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			memset(pszOut, 0, nCbOut);
+			nRet = _Conv(desc, &pIn, nCbIn, &pszOut, nCbOut - 1, &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+size_t Utf8ToLatin1(const char *pszIn, size_t nCbIn, char *pszOut, size_t nCbOut)
+{
+	if(pszIn && pszOut && nCbOut)
+	{
+	    iconv_t desc = iconv_open("LATIN1//", "UTF-8//");
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCbIn == (size_t)-1)
+				nCbIn = strlen(pszIn);
+			memset(pszOut, 0, nCbOut);
+			nRet = _Conv(desc, &pIn, nCbIn, &pszOut, nCbOut - 1, &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+size_t Latin1ToUtf8(const char *pszIn, size_t nCbIn, char *pszOut, size_t nCbOut)
+{
+	if(pszIn && pszOut && nCbOut)
+	{
+	    iconv_t desc = iconv_open("UTF-8//", "LATIN1//");
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCbIn == (size_t)-1)
+				nCbIn = strlen(pszIn);
+			memset(pszOut, 0, nCbOut);
+			nRet = _Conv(desc, &pIn, nCbIn, &pszOut, nCbOut - 1, &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+size_t Utf8ToUtf16(const char *pszIn, size_t nCbIn, char16_t *pszOut, size_t nCChOut)
+{
+	if(pszIn && pszOut && nCChOut)
+	{
+        iconv_t desc = iconv_open(_UTF_16, "UTF-8//");
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCbIn == (size_t)-1)
+				nCbIn = strlen(pszIn);
+			memset(pszOut, 0, nCChOut * sizeof(char16_t));
+			nRet = _Conv(desc, &pIn, nCbIn, (char**)&pszOut, (nCChOut - 1) * sizeof(char16_t), &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+size_t Utf16ToUtf8(const char16_t *pszIn, size_t nCChIn, char *pszOut, size_t nCbOut)
+{
+	if(pszIn && pszOut && nCbOut)
+	{
+	    iconv_t desc = iconv_open("UTF-8//", _UTF_16);
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCChIn == (size_t)-1)
+				nCChIn = wcs16len(pszIn);
+			memset(pszOut, 0, nCbOut);
+			nRet = _Conv(desc, &pIn, nCChIn * sizeof(char16_t), &pszOut, nCbOut - 1, &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+size_t Utf8ToUtf32(const char *pszIn, size_t nCbIn, char32_t *pszOut, size_t nCChOut)
+{
+	if(pszIn && pszOut && nCChOut)
+	{
+	    iconv_t desc = iconv_open(_UTF_32, "UTF-8//");
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCbIn == (size_t)-1)
+				nCbIn = strlen(pszIn);
+			memset(pszOut, 0, nCChOut * sizeof(char32_t));
+			nRet = _Conv(desc, &pIn, nCbIn, (char**)&pszOut, (nCChOut - 1) * sizeof(char32_t), &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+size_t Utf32ToUtf8(const char32_t *pszIn, size_t nCChIn, char *pszOut, size_t nCbOut)
+{
+	if(pszIn && pszOut && nCbOut)
+	{
+	    iconv_t desc = iconv_open("UTF-8//", _UTF_32);
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCChIn == (size_t)-1)
+				nCChIn = wcs32len(pszIn);
+			memset(pszOut, 0, nCbOut);
+			nRet = _Conv(desc, &pIn, nCChIn * sizeof(char32_t), &pszOut, nCbOut - 1, &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+size_t Utf8ToWcs(const char *pszIn, size_t nCbIn, wchar_t *pszOut, size_t nCChOut)
+{
+	if(pszIn && pszOut && nCChOut)
+	{
+	    iconv_t desc = iconv_open("WCHAR_T//", "UTF-8//");
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCbIn == (size_t)-1)
+				nCbIn = strlen(pszIn);
+			memset(pszOut, 0, nCChOut * sizeof(wchar_t));
+			nRet = _Conv(desc, &pIn, nCbIn, (char**)&pszOut, (nCChOut - 1) * sizeof(wchar_t), &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}
+
+size_t WcsToUtf8(const wchar_t *pszIn, size_t nCChIn, char *pszOut, size_t nCbOut)
+{
+	if(pszIn && pszOut && nCbOut)
+	{
+	    iconv_t desc = iconv_open("UTF-8//", "WCHAR_T//");
+
+		if(desc != (iconv_t)-1)
+		{
+			size_t nRet;
+			size_t nTrunc;
+			char *pIn = (char*)pszIn;
+			if(nCChIn == (size_t)-1)
+				nCChIn = wcslen(pszIn);
+			memset(pszOut, 0, nCbOut);
+			nRet = _Conv(desc, &pIn, nCChIn * sizeof(wchar_t), &pszOut, nCbOut - 1, &nTrunc);
+			iconv_close(desc);
+			return nRet;
+		}
+	}
+	
+	return 0;
+}

+ 38 - 0
src/suconv.h

@@ -0,0 +1,38 @@
+// suconv.h :
+//
+
+#if !defined(AGD_SUCONV_H__EBA88F70_2DC9_4AB7_BF9E_BEBB3E8E02BA__INCLUDED_)
+#define AGD_SUCONV_H__EBA88F70_2DC9_4AB7_BF9E_BEBB3E8E02BA__INCLUDED_
+
+#include <wchar.h>
+#include <uchar.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif	//	__cplusplus
+
+/////////////////////////////////////////////////////////////////////////////
+// suconv.h - Declarations:
+
+size_t wcs16len(const char16_t *psz);
+size_t wcs32len(const char32_t *psz);
+
+size_t EncToUtf8(const char *pszEncIn, const void *pszIn, size_t nCbIn, char *pszOut, size_t nCbOut);
+
+size_t Latin1ToUtf8(const char *pszIn, size_t nCbIn, char *pszOut, size_t nCbOut);
+size_t Utf8ToLatin1(const char *pszIn, size_t nCbIn, char *pszOut, size_t nCbOut);
+
+size_t Utf16ToUtf8(const char16_t *pszIn, size_t nCChIn, char *pszOut, size_t nCbOut);
+size_t Utf8ToUtf16(const char *pszIn, size_t nCbIn, char16_t *pszOut, size_t nCChOut);
+
+size_t Utf32ToUtf8(const char32_t *pszIn, size_t nCChIn, char *pszOut, size_t nCbOut);
+size_t Utf8ToUtf32(const char *pszIn, size_t nCbIn, char32_t *pszOut, size_t nCChOut);
+
+size_t WcsToUtf8(const wchar_t *pszIn, size_t nCChIn, char *pszOut, size_t nCbOut);
+size_t Utf8ToWcs(const char *pszIn, size_t nCbIn, wchar_t *pszOut, size_t nCChOut);
+
+/////////////////////////////////////////////////////////////////////////////
+#ifdef __cplusplus
+}
+#endif	//	__cplusplus
+#endif	//	!defined(AGD_SUCONV_H__EBA88F70_2DC9_4AB7_BF9E_BEBB3E8E02BA__INCLUDED_)

+ 3 - 36
src/sucycletimer.cpp

@@ -11,9 +11,9 @@ CCycleTimer::CCycleTimer(unsigned int nMaxCycleIntervalMilliSec1, unsigned int n
 	::clock_getres(CLOCK_MONOTONIC, &m_res);
 }
 
-CCycleTimer::CCycleTimer(const struct timespec &rts1, const struct timespec &rts2, const struct timespec &rts3) :	m_nMaxCycleNanoSec1(Timespec2NanoSec(rts1)),
-																													m_nMaxCycleNanoSec2(Timespec2NanoSec(rts2)),
-																													m_nMaxCycleNanoSec3(Timespec2NanoSec(rts3))
+CCycleTimer::CCycleTimer(const struct timespec *pts1, const struct timespec *pts2, const struct timespec *pts3) :	m_nMaxCycleNanoSec1(pts1 ? Timespec2NanoSec(*pts1) : 0),
+																													m_nMaxCycleNanoSec2(pts2 ? Timespec2NanoSec(*pts2) : 0),
+																													m_nMaxCycleNanoSec3(pts3 ? Timespec2NanoSec(*pts3) : 0)
 {
 	memset(&m_ts, 0, sizeof(m_ts));
 	::clock_getres(CLOCK_MONOTONIC, &m_res);
@@ -29,7 +29,6 @@ cy_time_t CCycleTimer::GetNanoTick(struct timespec *pts)
 {
 	struct timespec ts;
 	struct timespec &rts = pts ? *pts : ts;
-
 	::clock_gettime(CLOCK_MONOTONIC, &rts);
 	return Timespec2NanoSec(rts);
 }
@@ -76,38 +75,6 @@ int CCycleTimer::Sleep(const cy_time_t &rnMaxCycleNanoSec, bool bResumeOnIntr) c
 	return 0;
 }
 
-#if 0
-int CCycleTimer::Sleep1(bool bResumeOnIntr) const
-{
-	cy_time_t nIntv;
-	struct timespec ts;//, rem;
-
-	::clock_gettime(CLOCK_MONOTONIC, &ts);
-
-	if((nIntv = GetRemainingCycleNanoSec1(&ts)) > 0)
-	{
-		int nRet;
-//		NanoSec2Timespec(nIntv, ts);
-		TimespecAddSubNanoSec(ts, nIntv);
-
-//		if((nRet = ::clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, &rem)))
-		if((nRet = ::clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &ts, NULL)))
-		{
-			if(bResumeOnIntr)
-			{
-				while(nRet == EINTR)
-				{
-//					nRet = ::clock_nanosleep(CLOCK_MONOTONIC, 0, &rem, &rem);
-					nRet = ::clock_nanosleep(CLOCK_MONOTONIC, 0, &ts, NULL);
-				}
-			}
-		}
-	}
-
-	return 0;
-}
-#endif
-
 void CCycleTimer::TimespecAddSubNanoSec(struct timespec &rts, cy_time_t nNanoSec)
 {
 	cy_time_t n = Timespec2NanoSec(rts) + nNanoSec;

+ 7 - 8
src/sucycletimer.h

@@ -37,7 +37,7 @@ class CCycleTimer
 {
 public:
 	CCycleTimer(unsigned int nMaxCycleIntervalMilliSec1, unsigned int nMaxCycleIntervalMilliSec2 = 0, unsigned int nMaxCycleIntervalMilliSec3 = 0);
-	CCycleTimer(const struct timespec &rts1, const struct timespec &rts2, const struct timespec &rts3);
+	CCycleTimer(const struct timespec *pts1, const struct timespec *pts2 = NULL, const struct timespec *pts3 = NULL);
 	virtual ~CCycleTimer(void);
 
 public:
@@ -97,34 +97,33 @@ public:
 		return m_nMaxCycleNanoSec3 - GetNanoSecElapsed(ptsComparand);
 	}
 	
-	void SetMaxCycleInterval11(unsigned int nMilliSec){
+	inline void SetMaxCycleInterval11(unsigned int nMilliSec){
 		m_nMaxCycleNanoSec1 = nMilliSec * _NSEC_PER_MSEC;
 	}
 	
-	void SetMaxCycleInterval12(unsigned int nMilliSec){
+	inline void SetMaxCycleInterval12(unsigned int nMilliSec){
 		m_nMaxCycleNanoSec2 = nMilliSec * _NSEC_PER_MSEC;
 	}
 	
-	void SetMaxCycleInterval13(unsigned int nMilliSec){
+	inline void SetMaxCycleInterval13(unsigned int nMilliSec){
 		m_nMaxCycleNanoSec3 = nMilliSec * _NSEC_PER_MSEC;
 	}
 	
 	static void TimespecAddSubNanoSec(struct timespec &rts, cy_time_t nNanoSec);
 
-	int Sleep1(bool bResumeOnIntr = false) const {
+	inline int Sleep1(bool bResumeOnIntr = false) const {
 		return Sleep(m_nMaxCycleNanoSec1, bResumeOnIntr);
 	}
 
-	int Sleep2(bool bResumeOnIntr = false) const {
+	inline int Sleep2(bool bResumeOnIntr = false) const {
 		return Sleep(m_nMaxCycleNanoSec2, bResumeOnIntr);
 	}
 
-	int Sleep3(bool bResumeOnIntr = false) const {
+	inline int Sleep3(bool bResumeOnIntr = false) const {
 		return Sleep(m_nMaxCycleNanoSec3, bResumeOnIntr);
 	}
 
 private:
-
 	int Sleep(const cy_time_t &rnMaxCycleNanoSec, bool bResumeOnIntr) const;
 
 private: