Преглед изворни кода

添加web command日志和异常处理

zzj пре 6 година
родитељ
комит
6653e18d00
5 измењених фајлова са 55 додато и 4 уклоњено
  1. 1 1
      db/db_card.cpp
  2. 1 1
      forbid_staff_down_mine.cpp
  3. 5 1
      select_tool.h
  4. 30 0
      test.cpp
  5. 18 1
      websocket/wsClient.cpp

+ 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);

+ 18 - 1
websocket/wsClient.cpp

@@ -193,6 +193,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->get_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 +203,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->get_string().c_str());
 			}
 
 			__recv_ping_time = time(0);