lixioayao 6 yıl önce
ebeveyn
işleme
ba35857fae

+ 1 - 1
db/db_card.cpp

@@ -139,7 +139,7 @@ namespace db_card
 		int nCount = DBRes.GetRecordCount( Error );
 		if (nCount < 1)
 		{
-			log_error("增加或修改失败,数据库中找不到: sql", sql.c_str());
+			log_error("增加或修改失败,数据库中找不到: sql=%s", sql.c_str());
 			return map;
 		}
 

+ 1 - 1
forbid_staff_down_mine.cpp

@@ -16,7 +16,7 @@ void forbid_staff_down_mine::init_forbid_staff(int id /* = -1*/,int etype)
     int nCount = DBRes.GetRecordCount( Error );
     if (nCount < 1)
     {
-        log_error("增加或修改失败,数据库中找不到: sql", sql.c_str());
+        log_error("增加或修改失败,数据库中找不到: sql=%s", sql.c_str());
         return ;
     }
     while ( DBRes.GetNextRecod(Error) )

+ 5 - 1
select_tool.h

@@ -352,7 +352,9 @@ struct car_point_filter:select_point_object
 		//sit_location.set(sit->x,sit->y);
 		sit_location = sit->get_dstp(m_turning_pt);
 		if(sit_location.empty())
-		  std_error("%d get_dstp point error.....",sit->m_id);
+		{
+		  log_error("%d get_dstp point error.....",sit->m_id);
+		}
 		double dist1=sit_location.dist(rpt);
 		double dist2=sit_location.dist(m_turning_pt);
 		double dist3=m_turning_pt.dist(rpt);	// dist1 is supposed to be = dist2+dist3
@@ -403,7 +405,9 @@ struct car_point_filter:select_point_object
 			//dstp.set(sit->x,sit->y);
 			dstp = sit->get_dstp(pt);
 			if(dstp.empty())
+			{
 			  log_error("error.here....here.");
+			}
 		}
 		else
 		{

+ 30 - 0
test.cpp

@@ -4,10 +4,14 @@
 
 #include <stdint.h>
 
+#include <iostream>
 #include <sstream>
 #include <vector>
 #include <line.h>
 
+#include "tool_time.h"
+
+
 #define log_error printf
 #define log_info printf
 struct path
@@ -290,8 +294,34 @@ void gen_help(int cnt,int bit=1)
 	}
 }
 
+static uint64_t morning_of_today_ms2()
+{   
+	time_t now = time(0);
+
+	return (now+8*3600)/86400*86400-8*3600;
+}   
+static uint64_t morning_of_today_ms()
+{   
+	time_t now = time(0);
+	struct tm * loc_t = localtime(&now);
+	loc_t->tm_hour=0;loc_t->tm_min=0;loc_t->tm_sec=0;
+	time_t x = mktime(loc_t);
+	return x*1000;
+}   
+
 int main()
 {
+	unsigned now=time(0);
+
+	std::cout<<morning_of_today_ms2()<<","<<morning_of_today_ms()<<std::endl;
+
+
+//	std::cout<<"sizeof(time_t)="<<sizeof(now)<<std::endl;
+	uint64_t x=now*1000LL;
+	std::cout<<now<<"|||"<<x<<std::endl;
+
+
+
 	help_bit=0;
 	gen_help(10,0);
 	gen_help(60,1);

+ 71 - 0
websocket/sio/sio_message.h

@@ -12,6 +12,7 @@
 #include <map>
 #include <cassert>
 #include <type_traits>
+#include <sstream>
 namespace sio
 {
     class message
@@ -58,6 +59,14 @@ namespace sio
             return 0;
         }
 
+        virtual std::string to_string() const
+        {
+            assert(false);
+            static std::string s_empty_string;
+            s_empty_string.clear();
+            return s_empty_string;
+        }
+
         virtual std::string const& get_string() const
         {
             assert(false);
@@ -147,6 +156,11 @@ namespace sio
         {
             return _v;
         }
+
+		std::string to_string()const
+		{
+			return _v?"true":"false";
+		}
     };
 
     class int_message : public message
@@ -173,6 +187,11 @@ namespace sio
         {
             return static_cast<double>(_v);
         }
+
+		std::string to_string()const
+		{
+			return std::to_string(_v);
+		}
     };
 
     class double_message : public message
@@ -193,6 +212,11 @@ namespace sio
         {
             return _v;
         }
+
+		std::string to_string()const
+		{
+			return std::to_string(_v);
+		}
     };
 
     class string_message : public message
@@ -222,6 +246,11 @@ namespace sio
         {
             return _v;
         }
+
+		std::string to_string()const
+		{
+			return "'"+_v+"'";
+		}
     };
 
     class binary_message : public message
@@ -335,6 +364,20 @@ namespace sio
         {
             return _v;
         }
+
+		std::string to_string()const
+		{
+			std::ostringstream ss;
+			ss<<"[";
+			for(size_t i=0;i<size();i++)
+			{
+				ss<<_v[i]->to_string()<<",";
+			}
+
+			ss<<"]";
+
+			return ss.str();
+		}
     };
 
     class object_message : public message
@@ -409,6 +452,20 @@ namespace sio
         {
             return _v;
         }
+
+		std::string to_string()const
+		{
+			std::ostringstream ss;
+			ss<<"{";
+			for(auto&it:_v)
+			{
+				ss<<it.first<<":"<<it.second->to_string()<<",";
+			}
+
+			ss<<"}";
+
+			return ss.str();
+		}
     };
 
     class message::list
@@ -561,6 +618,20 @@ namespace sio
             return arr;
         }
 
+		std::string to_string()const
+		{
+			std::ostringstream ss;
+			ss<<"[";
+			for(size_t i=0;i<size();i++)
+			{
+				ss<<m_vector[i]->to_string()<<",";
+			}
+
+			ss<<"]";
+
+			return ss.str();
+		}
+
     private:
         std::vector<message::ptr> m_vector;
     };

+ 28 - 1
websocket/wsClient.cpp

@@ -31,11 +31,21 @@ namespace YA
 		__Logined = false;
 	}
 
+	static void beatheart(int, std::string const&, sio::message::ptr const&, bool, sio::message::list & )
+	{
+	
+	}
+
 	void wsClient::init( int ID, const std::string & uri, const std::map<std::string, MSG_HANDLE_FUNC_TYPE>& MsgFuncList )
 	{
 		__ID          = ID;
 		__uri         = uri;
 		__MsgFuncList = MsgFuncList;
+
+		//MsgFuncList.insert( std::make_pair( "beatheart", &web_connect::_beatheart_callback ) );
+
+		__MsgFuncList.insert(std::make_pair("beatheart",&beatheart));
+
 		__wsclient.set_reconnect_attempts( 0 );
 		using std::placeholders::_1;
 		using std::placeholders::_2;
@@ -193,6 +203,8 @@ namespace YA
 
 	void wsClient::_OnCallMessage( std::string const& name, sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
 	{
+		log_info("web-message:%s",data->to_string().c_str());
+
 		if ( data->get_flag() == sio::message::flag_object ) 
 		{
 			std::string cmd = data->get_map()[JSON_ROOT_KEY_CMD]->get_string();
@@ -201,7 +213,22 @@ namespace YA
 			mit_func = __MsgFuncList.find( cmd );
 			if ( mit_func != __MsgFuncList.end() )
 			{
-				mit_func->second( GetID(), name, data, need_ack, ack_resp );
+				try
+				{
+					mit_func->second( GetID(), name, data, need_ack, ack_resp );
+				}
+				catch(const std::exception&e)
+				{
+					log_error("捕获到异常:%s",e.what());
+				}
+				catch(...)
+				{
+					log_error("捕获到未知异常");
+				}
+			}
+			else
+			{
+				log_error("web-message没有找到对应的处理函数:%s",data->to_string().c_str());
 			}
 
 			__recv_ping_time = time(0);

+ 3 - 0
websocket/wsClientMgr.cpp

@@ -195,6 +195,8 @@ namespace YA
 		{
 			unsigned int t = w->GetPingTime();
 			// 间隔小于15秒 认为是正常
+
+//			log_info("now=%ud,ping=%ud,now-ping=%d",cur_time,t,cur_time-t);
 			if (w->IsConnected() && (t == 0 || cur_time - t < 15))
 			{
 				continue;
@@ -203,6 +205,7 @@ namespace YA
 			Disconnet(w);
 			std::this_thread::sleep_for(std::chrono::milliseconds(10));
 			Reconnect(w);
+			std::this_thread::sleep_for(std::chrono::seconds(3));
 		}
 	}
 }