12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #include <time.h>
- #include <RestfulFunc.h>
- #include "json/json.h"
- #include "baseFun.h"
- #include <mutex>
- #include <condition_variable>
- std::mutex m_mutex;
- std::condition_variable condition_variable;
- long LOG_GET_TIME()
- {
- return time(NULL);
- }
- RvcLogSdkManager& RvcLogSdkManager::getInstance() {
- static RvcLogSdkManager instance;
- return instance;
- }
- std::list<log_group_builder*> &RvcLogSdkManager::getResendFrameList() {
- return m_resend_frame_list;
- }
- RvcLogSdkManager::RvcLogSdkManager() {
- m_resend_frame_list.clear();
- m_testLogMode = false;
- }
- bool RvcLogSdkManager::wait_for_counter_greater_than_one_with_timeout() {
- std::unique_lock<std::mutex> lock(m_mutex);
- // 等待条件满足(即 counter > 1),最多等待 100 毫秒
- bool timed_out = !condition_variable.wait_for(lock, std::chrono::milliseconds(100), [&] { return m_logFlush_num > 0; });
- m_logFlush_num = 0;//已经刷新了,后续重新计数
- return true;
- }
- int RvcLogSdkManager::LOG_OS_TestLogPost(const char* url, const char* body)
- {
- HttpClientResponseResult result;
- HttpClientRequestConfig config(HttpRequestMethod::POST, url);
- std::string str((const char*)body);
- config.SetJsonBody(str.c_str());
- RestfulClient client = RestfulClient::getInstance();
- config.PreDo();
- client.Do(&config, &result, NULL);//Test Logs
- return 0;
- }
- int RvcLogSdkManager::SendTestLog(const char* body)
- {
- if (m_testLogMode == false)
- return -1;
- HttpClientRequestConfig sendErr(HttpRequestMethod::POST, "http://99.12.43.134:9000/upload_msg");
- HttpClientResponseResult curResult;
- Json::Value rootReq;
- Json::FastWriter writer;
- rootReq["req"] = body;
- rootReq["ans"] = "Json_not_vaild";
- std::string jsonReq = writer.write(rootReq);
- sendErr.SetJsonBody(jsonReq.c_str());
- RestfulClient client = RestfulClient::getInstance();
- sendErr.PreDo();
- client.Do(&sendErr, &curResult, NULL);//Test Logs
- return 0;
- }
- #ifndef _WIN32
- #ifndef CLOCK_MONOTONIC_RAW
- #define CLOCK_MONOTONIC_RAW 4
- #endif
- uint32_t GetTickCount(void)
- {
- uint32_t ticks = 0;
- struct timespec ts;
- if (!clock_gettime(CLOCK_MONOTONIC_RAW, &ts))
- ticks = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
- return ticks;
- }
- #endif
|