Ver código fonte

Z991239-6460 #comment 部分接口迁移

80374374 1 mês atrás
pai
commit
1dc30637eb

+ 24 - 38
Framework/Common/SpUtility.h

@@ -40,14 +40,6 @@ namespace SP {
 
 	namespace Utility {
 
-		inline static int hex2int(const char c)
-		{
-			if (c >= '0' && c <= '9') return (c - '0');
-			if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
-			if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
-			return 0xFF;
-		}
-
 		inline bool IsStartWith(std::string const& s, std::string const& prefix)
 		{
 			return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
@@ -126,36 +118,6 @@ namespace SP {
 			return replaced;
 		}
 
-		/** remembe to delete[] return value if not null*/
-		inline static char* HexStr2Bytes(const std::string& str)
-        {
-            const int sz = str.length();
-            char* ret = new char[sz / 2 + 1];
-            if (ret == NULL) {
-                return NULL;
-            }
-            for (int i = 0; i < sz; i += 2) {
-                ret[i / 2] = (char)(((hex2int(str[i])) << 4) | hex2int(str[i + 1]));
-            }
-			ret[sz / 2] = 0x00;
-            return ret;
-        }
-
-		inline static std::string Bytes2HexStr(char* bytes, std::size_t byteLen)
-        {
-            std::string str("");
-            const std::string conv("0123456789ABCDEF");
-            for (std::size_t i = 0; i < byteLen; ++i) {
-                int b = 0x0F & (bytes[i] >> 4);
-                str.push_back(conv[b]);
-                //str.append(1, conv[b]);
-                b = 0x0F & (bytes[i]);
-                str.push_back(conv[b]);
-                //str.append(1, conv[b]);
-            }
-            return str;
-        }
-
 		template<typename T>
 		std::string fpToString(T value, int precision) {
 			std::ostringstream oss;
@@ -188,6 +150,30 @@ namespace SP {
             return strs;
         }
 
+		/** Migrate from  LocalMediaplyer::AdvManage, which is functionally similar as the above one [Gifur@2025822]*/
+		inline static void split2(const std::string& src, const std::string& separator, std::vector<std::string>& dest)
+		{
+			std::string str = src;
+			std::string substring;
+			std::string::size_type start = 0, index;
+
+			do
+			{
+				index = str.find_first_of(separator, start);
+				if (index != std::string::npos)
+				{
+					substring = str.substr(start, index - start);
+					dest.push_back(substring);
+					start = str.find_first_not_of(separator, index);
+					if (start == std::string::npos) return;
+				}
+			} while (index != std::string::npos);
+
+			//the last token
+			substring = str.substr(start);
+			dest.push_back(substring);
+		}
+
 		inline std::string ExtractClassName(std::string const& className) 
 		{
 			std::string strClassName = className;

+ 50 - 5
Module/include/CommEntityUtil.hpp

@@ -329,6 +329,16 @@ static bool IsNoStr(const char* str)
 	return true;
 }*/
 
+
+inline static int hex2int(const char c)
+{
+	if (c >= '0' && c <= '9') return (c - '0');
+	if (c >= 'A' && c <= 'F') return (c - 'A' + 10);
+	if (c >= 'a' && c <= 'f') return (c - 'a' + 10);
+	return 0xFF;
+}
+
+
 static unsigned char Ch2Hex(char ch)
 {
 	static const char* hex = "0123456789ABCDEF";
@@ -337,6 +347,23 @@ static unsigned char Ch2Hex(char ch)
 			return i;
 	return 0;
 }
+
+/** remembe to delete[] return value if not null*/
+static char* HexStr2Bytes(const std::string& str)
+{
+	const int sz = str.length();
+	char* ret = new char[sz / 2 + 1];
+	if (ret == NULL) {
+		return NULL;
+	}
+	for (int i = 0; i < sz; i += 2) {
+		ret[i / 2] = (char)(((hex2int(str[i])) << 4) | hex2int(str[i + 1]));
+	}
+	ret[sz / 2] = 0x00;
+	return ret;
+}
+
+/*WARNING: need to delete[] the returned value if it's not null*/
 static char* Hex2Str(const char* src, int& dstLen)
 {
 	int i = 0;
@@ -360,6 +387,8 @@ static char* Hex2Str(const char* src, int& dstLen)
 	dstLen = cnt;
 	return (char*)d;
 }
+
+/*WARNING: need to delete[] the returned value if it's not null*/
 static char* Str2Hex(const char* src, int srcLen)
 {
 	string ret;
@@ -376,6 +405,22 @@ static char* Str2Hex(const char* src, int srcLen)
 	return tmp;
 }
 
+/*duplicate with the above one ??*/
+static std::string Bytes2HexStr(char* bytes, std::size_t byteLen)
+{
+	std::string str("");
+	const std::string conv("0123456789ABCDEF");
+	for (std::size_t i = 0; i < byteLen; ++i) {
+		int b = 0x0F & (bytes[i] >> 4);
+		str.push_back(conv[b]);
+		//str.append(1, conv[b]);
+		b = 0x0F & (bytes[i]);
+		str.push_back(conv[b]);
+		//str.append(1, conv[b]);
+	}
+	return str;
+}
+
 static std::string formatTime(const SYSTEMTIME& time)
 {
     char tBuf[1024] = "";
@@ -383,6 +428,11 @@ static std::string formatTime(const SYSTEMTIME& time)
     return tBuf;
 }
 
+static CSimpleStringA generateConsumeTimeJson(const CSimpleStringA& entityName, const CSimpleStringA& startTime, int cost)
+{
+	return CSimpleStringA::Format("{\"name\":\"%s\",\"time\":\"%s\",\"cost\":%d}", entityName.GetData(), startTime.GetData(), cost);
+}
+
 static bool ShellExecute(const std::string& cmd, std::string& succResult, std::string& errResult)
 {
 	succResult = errResult = "";
@@ -442,11 +492,6 @@ static bool ShellExecute(const std::string& cmd, std::string& succResult, std::s
 #endif //_MSC_VER
 }
 
-static CSimpleStringA generateConsumeTimeJson(const CSimpleStringA& entityName, const CSimpleStringA& startTime, int cost)
-{
-    return CSimpleStringA::Format("{\"name\":\"%s\",\"time\":\"%s\",\"cost\":%d}", entityName.GetData(), startTime.GetData(), cost);
-}
-
 #if defined(_MSC_VER)
 
 static void ConvertUtf82GBK(std::string& str)

+ 0 - 39
Module/mod_chromium/CWSCodec.cpp

@@ -1267,45 +1267,6 @@ namespace Chromium {
 		msgInfo.value = value.second;
 	}
 
-	using namespace std;
-	vector<string> split(const string & s, const string & seperator) {
-		vector<string> result;
-		typedef string::size_type string_size;
-		string_size i = 0;
-
-		while (i != s.size()) {
-			//找到字符串中首个不等于分隔符的字母;
-			int flag = 0;
-			while (i != s.size() && flag == 0) {
-				flag = 1;
-				for (string_size x = 0; x < seperator.size(); ++x)
-					if (s[i] == seperator[x]) {
-						++i;
-						flag = 0;
-						break;
-					}
-			}
-
-			//找到又一个分隔符,将两个分隔符之间的字符串取出;
-			flag = 0;
-			string_size j = i;
-			while (j != s.size() && flag == 0) {
-				for (string_size x = 0; x < seperator.size(); ++x)
-					if (s[j] == seperator[x]) {
-						flag = 1;
-						break;
-					}
-				if (flag == 0)
-					++j;
-			}
-			if (i != j) {
-				result.emplace_back(s.substr(i, j - i));
-				i = j;
-			}
-		}
-		return result;
-	}
-
 	void CWSCodec::SerializeGetVarReq(cJSON * js, char* data, int* wpos, int* capacity, CMedthodInterface * pI, char* errmsg, ws_msgInfo& msgInfo) {
 		auto  transID = json_deal::getIntergerFromCjsonObj(js, "transID");
 		if (transID.first == false)

+ 1 - 24
Module/mod_localmediaplay/AdvertManage/BaseFun.cpp

@@ -19,30 +19,7 @@
 #endif // !RVC_MAX_INI_LEN
 
 
-void split(const string& src, const string& separator, vector<string>& dest)
-{
-	string str = src;
-	string substring;
-	string::size_type start = 0, index;
-
-	do
-	{
-		index = str.find_first_of(separator, start);
-		if (index != string::npos)
-		{
-			substring = str.substr(start, index - start);
-			dest.push_back(substring);
-			start = str.find_first_not_of(separator, index);
-			if (start == string::npos) return;
-		}
-	} while (index != string::npos);
-
-	//the last token
-	substring = str.substr(start);
-	dest.push_back(substring);
-}
-
-//TODO: CrossPlaform  [Gifur@2025730]
+//TODO: CrossPlaform  改成使用 SpUtilty.h 中的 S2W 接口 [Gifur@2025730]
 void StringToWstring(std::wstring& szDst, std::string str)
 {
 #ifdef RVC_OS_WIN

+ 2 - 1
Module/mod_localmediaplay/AdvertManage/BaseFun.h

@@ -10,5 +10,6 @@
 
 using namespace std;
 
-void split(const string& src, const string& separator, vector<string>& dest);
+//TODO: CrossPlaform 这个引入的库文件建议废除,用应用框架提供的替代  [Gifur@2025822]
+
 void StringToWstring(std::wstring& szDst, std::string str);

+ 3 - 43
Module/mod_localmediaplay/AdvertManage/MediaManage.cpp

@@ -9,13 +9,11 @@ mediaManage::mediaManage()
 	m_curParse.clear();
 	if (ExistsDirA(DEFAULT_RESOURSE_PATH))
 	{
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH, DEFAULT_DOWNLOAD_PATH);
 		setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH));
 		setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH));
 	}
 	else
 	{
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH_C, DEFAULT_DOWNLOAD_PATH_C);
 		setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH_C));
 		setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH_C));
 	}
@@ -42,16 +40,6 @@ int mediaManage::GetPlayListByLocal(vector<ResourceParse>& resourceList)
 {
 	int iNum = 0;
 	resourceList.clear();
-	//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-	for each (auto i in m_localList)
-	{
-		if (checkInVaildTime(i.vaildTime, true) && checkInPlayTime(i.playTime, true)) {
-			resourceList.push_back(i);
-			iNum++;
-		}
-	}
-#else
 	for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end(); it++)
 	{
 		if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) {
@@ -59,9 +47,6 @@ int mediaManage::GetPlayListByLocal(vector<ResourceParse>& resourceList)
 			iNum++;
 		}
 	}
-
-#endif // _WIN32
-
 	return iNum;
 }
 
@@ -72,7 +57,6 @@ int mediaManage::GetPlayListByLocal(CResourceParse** ResourceArr, int iSize)
 
 	for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end() && iNum < iSize; it++)
 	{
-		//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new deep copy play extend %c:%s, %s, %s, %s", it->type, it->resourcePath.c_str(), it->videoNames.c_str(), it->vaildTime.c_str(), it->playTime.c_str());
 		if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) {
 			CResourceParse* pNode = new CResourceParse();
 			pNode->type = it->type;
@@ -106,10 +90,6 @@ int mediaManage::GetPlayListByLocal(CResourceParse** ResourceArr, int iSize)
 				memcpy(pNode->playTime, it->playTime.c_str(), it->playTime.length());
 			}
 			ResourceArr[iNum++] = pNode;
-			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("aftercopy play extend pNode->type=0x%08x:pNode->presourcePath=0x%08x, pNode->pvideoNames=0x%08x, pNode->pvaildTime=0x%08x, pNode->playTime=0x%08x", pNode->type, pNode->presourcePath, pNode->pvideoNames, pNode->pvaildTime, pNode->playTime);
-			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("aftercopy play extend %c:%s, %s, %s, %s", pNode->type, pNode->presourcePath, pNode->pvideoNames, pNode->pvaildTime, pNode->playTime);
-			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d    ResourceList[%d] address is 0x%08x, pNode address is 0x%08x.", __FUNCTION__, __LINE__, uNum-1, ResourceArr[uNum-1], pNode);
-			
 		}
 	}
 
@@ -241,40 +221,20 @@ void mediaManage::InitResourceListByLocal()
 	uint32_t unetworkList = 0;
 	bool blog = false;
 
-
-	//TODO: CrossPlaform  [Gifur@2025729]
-#ifdef RVC_OS_WIN
-	for each (auto i in headList) {
-		m_localList.push_back(i);
-		uheadList++;
-	}
-		
-	for each (auto i in branchList) {
-		m_localList.push_back(i);
-		ubranchList++;
-	}
-
-	for each (auto i in networkList) {
-		m_localList.push_back(i);
-		unetworkList++;
-	}
-		
-#else
-	for (vector<ResourceParse>::iterator it = headList.begin(); it < headList.end(); ++it){
+	for (vector<ResourceParse>::iterator it = headList.begin(); it < headList.end(); ++it) {
 		m_localList.push_back(*it);
 		uheadList++;
 	}
 
-	for (vector<ResourceParse>::iterator it = branchList.begin(); it < branchList.end(); ++it){
+	for (vector<ResourceParse>::iterator it = branchList.begin(); it < branchList.end(); ++it) {
 		m_localList.push_back(*it);
 		ubranchList++;
 	}
 
-	for (vector<ResourceParse>::iterator it = networkList.begin(); it < networkList.end(); ++it){
+	for (vector<ResourceParse>::iterator it = networkList.begin(); it < networkList.end(); ++it) {
 		m_localList.push_back(*it);
 		unetworkList++;
 	}
-#endif // RVC_OS_WIN
 
 	if (m_ilist_size != m_localList.size()) {
 		m_ilist_size = (int)m_localList.size();

+ 7 - 84
Module/mod_localmediaplay/AdvertManage/resourceIniParse.cpp

@@ -10,8 +10,11 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#endif 
+#endif
+#include <winpr/string.h>
+#include "SpUtility.h"
 
+//TODO: CrossPlaform 这个引入的库文件建议废除,用应用框架提供的替代  [Gifur@2025822]
 
 int ReadInterger(LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szFileName, int iDefaultValue)
 {
@@ -57,44 +60,6 @@ string ReadString(LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szFileName, LPCTSTR
 	return string(tempResult);
 }
 
-void WriteBoolean(LPCTSTR szSection, LPCTSTR szKey, BOOL szBool, LPCTSTR szFileName)
-{
-	TCHAR szDefault[MAX_PATH] = {0};
-#ifdef RVC_OS_WIN
-	_stprintf_s(szDefault, _T("%d"), szBool);
-	WritePrivateProfileString(szSection, szKey, szDefault, szFileName);
-#else
-	snprintf(szDefault, MAX_PATH, "%d", szBool);
-	inifile_write_str(szSection, szKey, szDefault, szFileName);
-	//WritePrivateProfileStringEx(szSection, szKey, szDefault, szFileName);
-#endif 
-}
-
-void WriteInt(LPCTSTR szSection, LPCTSTR szKey, int szInt, LPCTSTR szFileName)
-{
-	TCHAR szDefault[MAX_PATH] = { 0 };
-	//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-	_stprintf_s(szDefault, _T("%d"), szInt);
-	WritePrivateProfileString(szSection, szKey, szDefault, szFileName);
-#else
-	//snprintf(szDefault, MAX_PATH, "%d", szInt);
-	inifile_write_int(szFileName,szSection, szKey, szInt);
-	//WritePrivateProfileStringEx(szSection, szKey, szDefault, szFileName);
-#endif 
-}
-
-void WriteString(LPCTSTR szSection, LPCTSTR szKey, LPCTSTR szString, LPCTSTR szFileName)
-{
-	//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-	WritePrivateProfileString(szSection, szKey, szString, szFileName);
-#else
-	inifile_write_str(szSection, szKey, szString, szFileName);
-	//WritePrivateProfileStringEx(szSection, szKey, szString, szFileName);
-#endif 
-}
-
 bool checkInPlayTime(string playTime, bool checkCurTime)
 {
 	//get localTime
@@ -113,13 +78,7 @@ bool checkInPlayTime(string playTime, bool checkCurTime)
 	t_beginHour = t_beginMin = t_endHour = t_endMin = 0;
 	try
 	{
-		//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
 		sscanf_s(playTime.c_str(), "%d:%d-%d:%d", &t_beginHour, &t_beginMin, &t_endHour, &t_endMin);
-#else
-		sscanf(playTime.c_str(), "%d:%d-%d:%d", &t_beginHour, &t_beginMin, &t_endHour, &t_endMin);
-#endif // RVC_OS_WIN
-
 		long curTime = local.tm_hour * 3600 + local.tm_min * 60 + local.tm_sec;
 		long beginTime = t_beginHour * 3600 + t_beginMin * 60;
 		long endTime = t_endHour * 3600 + t_endMin * 60 + 60;
@@ -154,37 +113,22 @@ bool checkInVaildTime(string vaildTime, bool checkCurData)
 #endif // RVC_OS_WIN
 
 	vector<string> dateList;
-	split(vaildTime, ",", dateList);
+	SP::Utility::split2(vaildTime, ",", dateList);
 	try {
 		for (vector<string>::iterator i = dateList.begin(); i != dateList.end(); i++)
 		{
 			tm beginData = { 0 }, endData = {0};
 			int tempYear, tempMon, tempDay, tempYear2, tempMon2, tempDay2;
 			tempYear = tempMon = tempDay = tempYear2 = tempMon2 = tempDay2 = 0;
-			//ZeroMemory(&beginData, sizeof(tm));
-			//ZeroMemory(&endData, sizeof(tm));
 			if (-1 == i->find('-'))	//单日期
 			{
-				//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
 				sscanf_s(i->c_str(), "%d/%d/%d", &tempYear, &tempMon, &tempDay);
-#else
-				sscanf(i->c_str(), "%d/%d/%d", &tempYear, &tempMon, &tempDay);
-#endif // RVC_OS_WIN
-
-				
 				if (checkCurData && (local.tm_year + 1900 == tempYear) && (local.tm_mon + 1 == tempMon) && (local.tm_mday == tempDay))
 					return true;//find the data
 			}
 			else
 			{
-				//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
 				sscanf_s(i->c_str(), "%d/%d/%d-%d/%d/%d", &tempYear, &tempMon, &tempDay, &tempYear2, &tempMon2, &tempDay2);
-#else
-				sscanf(i->c_str(), "%d/%d/%d-%d/%d/%d", &tempYear, &tempMon, &tempDay, &tempYear2, &tempMon2, &tempDay2);
-#endif // RVC_OS_WIN
-
 				beginData.tm_year = tempYear - 1900;
 				beginData.tm_mon = tempMon - 1;
 				beginData.tm_mday = tempDay;
@@ -213,6 +157,7 @@ bool checkInVaildTime(string vaildTime, bool checkCurData)
 
 bool parseResourceIni(const char* filePath, vector<ResourceParse> &ret)
 {
+	/** 这段代码的意义在哪?如果只是判断文件在不在,直接用ExistFileA的跨平台函数即可  [Gifur@2025822]*/
 #ifdef RVC_OS_WIN
 	if (INVALID_FILE_ATTRIBUTES == GetFileAttributes(filePath))
 	{
@@ -237,14 +182,7 @@ bool parseResourceIni(const char* filePath, vector<ResourceParse> &ret)
 	{
 		//get section name
 		TCHAR sectionMedia[30] = STR_NULL;
-		//TODO: CrossPlaform  [Gifur@2025730]
-#ifdef RVC_OS_WIN
-		_stprintf_s(sectionMedia, _T("%s%d"), SECTION_MEDIA, i);
-#else
-		snprintf(sectionMedia, 30, "%s%d", SECTION_MEDIA, i);
-#endif // RVC_OS_WIN
-
-		//ResourceParse curResource;
+		sprintf_s(sectionMedia, 30, "%s%d", SECTION_MEDIA, i);
 		ResourceParse* item = new ResourceParse();
 		//获取type属性及校验
 		string type = ReadString(sectionMedia, MEDIA_TYPE, filePath, STR_NULL);
@@ -271,18 +209,3 @@ bool parseResourceIni(const char* filePath, vector<ResourceParse> &ret)
 		return false;
 	return true;
 }
-
-
-int ReleaseCResourceArrs(CResourceParse** resourceArr, uint32_t uSize)
-{
-	int iRet = 0;
-	for (int i = 0; i < uSize; i++) {
-		if (resourceArr && resourceArr[i]){
-			CResourceParse* pData = resourceArr[i];
-			delete pData;
-			resourceArr[i] = NULL;
-		}
-	}
-
-	return iRet;
-}

+ 0 - 3
Module/mod_localmediaplay/AdvertManage/resourceIniParse.h

@@ -126,9 +126,6 @@ typedef struct rvcResourceParse_s {
 	char strResourcePath[MAX_PATH];
 }rvcResourceParse_t;
 
-
-
 bool checkInPlayTime(string playTime, bool checkCurTime = false);
 bool parseResourceIni(const char* filePath, vector<ResourceParse> &ret);
 bool checkInVaildTime(string vaildTime, bool checkCurData = false);
-int ReleaseCResourceArrs(CResourceParse** resourceArr, uint32_t uSize);