Skip to content

Commit

Permalink
update cppcheck info
Browse files Browse the repository at this point in the history
  • Loading branch information
fasiondog committed Apr 2, 2024
1 parent 6355aa1 commit 1ae09fc
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions hikyuu_cpp/hikyuu/global/sysinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ std::atomic<int> g_latest_version{0};
std::atomic_bool g_runningInPython{false}; // 是否是在 python 中运行
std::atomic_bool g_pythonInJupyter{false}; // python 是否为交互模式

boost::uuids::uuid g_uid;
std::string g_feedback_host;
uint64_t g_feedback_port;

bool HKU_API runningInPython() {
return g_runningInPython;
}
Expand Down Expand Up @@ -72,36 +76,35 @@ std::string getVersionWithGit() {
}

// cppcheck-suppress constParameterReference
static bool readUUID(boost::uuids::uuid& out) {
static bool readUUID() {
std::string filename = fmt::format("{}/.hikyuu/uid", getUserDir());
FILE* fp = fopen(filename.c_str(), "rb");
HKU_IF_RETURN(!fp, false);

bool ret = true;
if (16 != fread((void*)out.data, 1, 16, fp)) {
if (16 != fread((void*)g_uid.data, 1, 16, fp)) {
ret = false;
}

fclose(fp);
return ret;
}

static void saveUUID(const boost::uuids::uuid& uid) {
static void saveUUID() {
std::string filename = fmt::format("{}/.hikyuu/uid", getUserDir());
FILE* fp = fopen(filename.c_str(), "wb");
HKU_IF_RETURN(!fp, void());

fwrite(uid.data, 16, 1, fp);
g_uid = boost::uuids::random_generator()();
fwrite(g_uid.data, 16, 1, fp);
fclose(fp);
}

void sendFeedback() {
std::thread t([] {
try {
boost::uuids::uuid uid;
if (!readUUID(uid)) {
uid = boost::uuids::random_generator()();
saveUUID(uid);
if (!readUUID()) {
saveUUID();
}

NodeClient client(FEEDBACK_SERVER_ADDR);
Expand All @@ -110,15 +113,15 @@ void sendFeedback() {
json req, res;
req["cmd"] = 2;
client.post(req, res);
std::string host = res["host"].get<std::string>();
uint64_t port = res["port"].get<uint64_t>();
g_feedback_host = res["host"].get<std::string>();
g_feedback_port = res["port"].get<uint64_t>();
g_latest_version = res.contains("last_version") ? res["last_version"].get<int>() : 0;
client.close();

client.setServerAddr(fmt::format("tcp://{}:{}", host, port));
client.setServerAddr(fmt::format("tcp://{}:{}", g_feedback_host, g_feedback_port));
client.dial();
req["cmd"] = 1;
req["uid"] = boost::uuids::to_string(uid);
req["uid"] = boost::uuids::to_string(g_uid);
req["part"] = "hikyuu";
req["version"] = HKU_VERSION;
req["build"] = fmt::format("{}", HKU_VERSION_BUILD);
Expand All @@ -137,19 +140,9 @@ void sendFeedback() {
void sendPythonVersionFeedBack(int major, int minor, int micro) {
std::thread t([=]() {
try {
NodeClient client(FEEDBACK_SERVER_ADDR);
NodeClient client(fmt::format("tcp://{}:{}", g_feedback_host, g_feedback_port));
client.dial();

json req, res;
req["cmd"] = 2;
client.post(req, res);
std::string host = res["host"].get<std::string>();
uint64_t port = res["port"].get<uint64_t>();
g_latest_version = res.contains("last_version") ? res["last_version"].get<int>() : 0;
client.close();

client.setServerAddr(fmt::format("tcp://{}:{}", host, port));
client.dial();
req["cmd"] = 3;
req["major"] = major;
req["minor"] = minor;
Expand Down

0 comments on commit 1ae09fc

Please sign in to comment.