|
@@ -20,7 +20,7 @@
|
|
|
#include "mine_business.h"
|
|
|
#include "main_test.h"
|
|
|
#include "ya_setting.h"
|
|
|
-#include<atomic>
|
|
|
+#include "websocket/web_connect.h"
|
|
|
|
|
|
config_file config;
|
|
|
void handlereader(uint32_t readerid,bool duration,uint32_t t)
|
|
@@ -39,94 +39,6 @@ void Handle_ThreeRates_Event_Callback(const int evType, const int evId, uint64_t
|
|
|
event_tool::instance()->handle_event((OBJECT_TYPE)evType,(EVENT_TYPE)evId,id,limitVal,curVal,bFalg);
|
|
|
}
|
|
|
|
|
|
-#define BEATHEART_COUNT_NUM 1000
|
|
|
-std::atomic<int> beatheart_count;
|
|
|
-void web_beatheart( int ID, std::string const& name,
|
|
|
- sio::message::ptr const& data, bool need_ack, sio::message::list &ack_resp )
|
|
|
-{
|
|
|
- beatheart_count=BEATHEART_COUNT_NUM;
|
|
|
-}
|
|
|
-
|
|
|
-void web_init(const std::vector<std::string>&uri_list,int32_t st)
|
|
|
-{
|
|
|
- std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE> MsgFuncList;
|
|
|
-
|
|
|
- module_mgr::init(config, MsgFuncList);
|
|
|
-
|
|
|
- MsgFuncList.insert( std::make_pair( "beatheart", web_beatheart ) );
|
|
|
-
|
|
|
- swsClientMgr.Build( uri_list, MsgFuncList );
|
|
|
-
|
|
|
- //init thread...
|
|
|
- YA::_THREAD_CONFIG_ Config;
|
|
|
- Config.SendInterval = st;
|
|
|
- swsTimerThrd.Init( Config );
|
|
|
-}
|
|
|
-
|
|
|
-bool web_connect()
|
|
|
-{
|
|
|
- //连接服务器
|
|
|
- if ( swsClientMgr.connect() != 0 )
|
|
|
- {
|
|
|
- log_error("web socket 连接失败....");
|
|
|
- std_error("websocket 连接失败....");
|
|
|
- return false;
|
|
|
- }
|
|
|
- //登录
|
|
|
- swsClientMgr.login();
|
|
|
-
|
|
|
- swsTimerThrd.Start();
|
|
|
-
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-void web_close()
|
|
|
-{
|
|
|
- swsTimerThrd.Stop();
|
|
|
- swsClientMgr.close();
|
|
|
-}
|
|
|
-
|
|
|
-void web_beatheart_thread()
|
|
|
-{
|
|
|
- while (true)
|
|
|
- {
|
|
|
- std::this_thread::sleep_for(std::chrono::seconds(3));
|
|
|
- if(beatheart_count==0)//一次都没收到web的心跳信号
|
|
|
- {
|
|
|
- log_info("没有收到web心跳信号");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if(beatheart_count==BEATHEART_COUNT_NUM)
|
|
|
- {
|
|
|
- beatheart_count++;
|
|
|
- log_info("接收到web心跳信号");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- beatheart_count=0;
|
|
|
-
|
|
|
- int count=0;
|
|
|
- while (true)
|
|
|
- {
|
|
|
- count++;
|
|
|
- if(count>=10000)
|
|
|
- {
|
|
|
- count=10000;
|
|
|
- }
|
|
|
-
|
|
|
- web_close();
|
|
|
- log_error("web连接异常中断, 开始重连web(第%d次)", count);
|
|
|
- std::this_thread::sleep_for(std::chrono::seconds(2));
|
|
|
- if(web_connect())
|
|
|
- {
|
|
|
- log_info("重连web ok");
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
struct Init_Setting
|
|
|
{
|
|
|
void init()
|
|
@@ -203,9 +115,12 @@ struct Init_Setting
|
|
|
|
|
|
bool wsClientMgr_init(const std::vector<std::string>&uri_list,int32_t st)
|
|
|
{
|
|
|
- web_init(uri_list, st);
|
|
|
+ std::map<std::string, YA::MSG_HANDLE_FUNC_TYPE> MsgFuncList;
|
|
|
+ module_mgr::init(config, MsgFuncList);
|
|
|
+
|
|
|
+ web_connect::init(uri_list, st, MsgFuncList);
|
|
|
|
|
|
- return web_connect();
|
|
|
+ return web_connect::connect();
|
|
|
}
|
|
|
};
|
|
|
|
|
@@ -213,7 +128,7 @@ struct Init_Setting
|
|
|
void cleanup()
|
|
|
{
|
|
|
module_mgr::stop();
|
|
|
- swsTimerThrd.Stop();
|
|
|
+ web_connect::close();
|
|
|
}
|
|
|
|
|
|
void usage(char ** argv)
|
|
@@ -257,8 +172,7 @@ int main(int argc ,char * argv[])
|
|
|
test_find_path(point(4600,-75),point(4727,-90));
|
|
|
|
|
|
module_mgr::start();
|
|
|
- auto th = std::thread(web_beatheart_thread);
|
|
|
- th.detach();
|
|
|
+ web_connect::start_beatheart_monitor();
|
|
|
atexit(&cleanup);
|
|
|
|
|
|
net_service mh;
|