| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- #include <iostream>
- #include "Log.h"
- #include "FsProxy.h"
- #include "Config.h"
- #include "TimeScheduler.h"
- #include "TtsBaidu.h"
- #include "SqlWrite.h"
- #include "SoftAuth.h"
- #include <string>
- #ifdef WIN32
- //
- #else
- #include <sys/resource.h>
- #define CORE_SIZE 1024 * 1024 * 500
- #endif // WIN32
- void AuthFun()
- {
- bool isStop = false;
- while (!isStop)
- {
- std::this_thread::sleep_for(std::chrono::hours(1));
- if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序
- {
- LOG_WARN("授权到期,自动关闭程序!");
- isStop = true;
- CFsProxy::GetInstance().release();
- exit(EXIT_SUCCESS);
- }
- }
- }
- int main()
- {
- MYLog::instance()->Init("log4cpp.conf");
- LOG_INFO_S("程序开始启动...");
- struct rlimit crlmt;
- if (getrlimit(RLIMIT_CORE, &crlmt) == -1) {
- return -1;
- }
- //printf("Before set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
- LOG_INFO("Before set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
- crlmt.rlim_cur = (rlim_t)CORE_SIZE;
- crlmt.rlim_max = (rlim_t)CORE_SIZE;
- if (setrlimit(RLIMIT_CORE, &crlmt) == -1) {
- return -1;
- }
- if (getrlimit(RLIMIT_CORE, &crlmt) == -1) {
- return -1;
- }
- //printf("After set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
- LOG_INFO("After set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max);
- //if (!SoftAuth::GetInstance()->Auth())
- //{
- // std::cout << "该机器未授权,请授权后使用" << std::endl;
- // std::string hardc;
- // SoftAuth::GetInstance()->getMachineCode(hardc);
- // //std::cout << SoftAuth::GetInstance()->getMachineCode(hardc) << std::endl;
- // std::cout << "机器码:" << hardc << std::endl;
- // //SoftAuth::GetInstance()->MakeAuth(hardc);
- //
- // std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2";
- // std::cout << "请输入授权码:" << std::endl;
- // std::cin >> code;
- // if (!SoftAuth::GetInstance()->Auth(code))
- // {
- // LOG_WARN("授权验证失败,自动关闭程序!");
- // CFsProxy::GetInstance().release();
- // //exit(EXIT_SUCCESS);
- // return 0;
- // }
- //}
- if (!SoftAuth::GetInstance()->AuthV2())
- {
- std::cout << "该机器未授权,请授权后使用" << std::endl;
- std::string hardc;
- if (!SoftAuth::GetInstance()->getMachineCode(hardc))
- {
- std::cout << "机器码获取失败,请用root权限运行!" << std::endl;
- return 0;
- }
- std::cout << "机器码:" << hardc << std::endl;
- std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2";
- std::cout << "请输入授权码:" << std::endl;
- std::cin >> code;
- if (!SoftAuth::GetInstance()->AuthV2(code))
- {
- LOG_WARN("授权验证失败,自动关闭程序!");
- CFsProxy::GetInstance().release();
- //exit(EXIT_SUCCESS);
- return 0;
- }
- }
- AuthInfo aInfo;
- SoftAuth::GetInstance()->getAuthInfo(aInfo);
- LOG_INFO_S("授权到期时间:" + aInfo.data);
- LOG_INFO_S("授权中继数量:" + std::to_string(aInfo.trunkNum));
- LOG_INFO_S("授权坐席数量:" + std::to_string(aInfo.agentNum));
- if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序
- {
- LOG_WARN("授权到期,自动关闭程序!");
- return 0;
- }
- std::thread(std::bind(AuthFun)).detach();
-
-
- CConfig *cfg = CConfig::GetInstance();
- if (!cfg->load())
- {
- LOG_WARN_S("配置文件加载失败!");
- cfg->write();
- return 0;
- }
- if (CFsProxy::GetInstance().init())
- {
- LOG_INFO_S("程序初始化完成,开始运行...");
- CFsProxy::GetInstance().run();
- }
- else
- LOG_ERROR_S("程序初始化失败,程序即将关闭");
- CFsProxy::GetInstance().release();
- exit(EXIT_SUCCESS);
- return 0;
- }
|