Explorar el Código

1、添加进程变量类;
2、添加grpc功能;
3、删除管理代码;

LiuZe hace 1 año
padre
commit
ec310f137c

+ 21 - 2
CMakeLists.txt

@@ -45,9 +45,28 @@ find_package(Glog)
 find_package(PCL REQUIRED)
 find_package(Eigen3 REQUIRED)
 find_package(OpenCV REQUIRED)
-find_package(Protobuf REQUIRED)
+find_package(Protobuf CONFIG)
+#if(NOT Protobuf_FOUND)
+#    find_package(Protobuf REQUIRED)
+#endif()
 
-execute_process(COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/protoc.sh ${CMAKE_CURRENT_LIST_DIR})
+find_package(absl REQUIRED)
+set(absl_LIBRARIES
+        absl::algorithm
+        absl::base
+        absl::debugging
+        absl::flat_hash_map
+        absl::memory
+        absl::meta
+        absl::numeric
+        absl::str_format
+        absl::strings
+        absl::synchronization
+        absl::time
+        absl::utility
+)
+
+#execute_process(COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/protoc.sh ${CMAKE_CURRENT_LIST_DIR})
 
 if (EXISTS "${CMAKE_SOURCE_DIR}/include/CMakeLists.txt")
     include_directories(${CMAKE_SOURCE_DIR}/include)

+ 23 - 2
include/file/pathcreator.cpp

@@ -1,8 +1,6 @@
 #include "pathcreator.h"
 
-#include <unistd.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <time.h>
 #include <stdint.h>
 #include <stdio.h>
@@ -92,3 +90,26 @@ bool PathCreator::CreateDatePath(std::string root, bool add_time)
     }
     return Mkdir(buf);
 }
+
+bool PathCreator::IsPathExist(const std::string& path) {
+    if (access(path.c_str(), 0) == F_OK) {
+        return true;
+    }
+    return false;
+}
+bool PathCreator::IsFile(const std::string& path) {
+    if (!IsPathExist(path)) {
+        printf("%s:%d %s not exist\n", __FILE__, __LINE__, path.c_str());
+        return false;
+    }
+    struct stat buffer;
+    return (stat(path.c_str(), &buffer) == 0 && S_ISREG(buffer.st_mode));
+}
+
+bool PathCreator::IsFolder(const std::string& path) {
+    if (!IsPathExist(path)) {
+        return false;
+    }
+    struct stat buffer;
+    return (stat(path.c_str(), &buffer) == 0 && S_ISDIR(buffer.st_mode));
+}

+ 11 - 0
include/file/pathcreator.h

@@ -1,6 +1,9 @@
 #ifndef PATHCREATOR_H
 #define PATHCREATOR_H
 #include <string>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fstream>
 
 class PathCreator
 {
@@ -10,6 +13,14 @@ public:
     std::string GetCurPath();
     bool Mkdir(std::string dir);
     bool CreateDatePath(std::string root, bool add_time = true);
+
+
+    static bool IsPathExist(const std::string& path);
+
+    static bool IsFile(const std::string& path);
+
+    static bool IsFolder(const std::string& path);
+
 protected:
     std::string m_current_path;
 };

+ 1 - 1
include/protobuf/load_protobuf.hpp

@@ -53,7 +53,7 @@ static bool readJsonProtobufFile(const std::string& file_path, ::google::protobu
         return false;
     }
 
-    return google::protobuf::util::JsonStringToMessage(json_data, &message) == google::protobuf::util::Status::OK;
+    return google::protobuf::util::JsonStringToMessage(json_data, &message) == absl::OkStatus();
 }
 
 static Error_manager loadProtobufFile(const std::string &file, ::google::protobuf::Message &message) {

+ 56 - 0
include/tool/timedlockdata.hpp

@@ -0,0 +1,56 @@
+//
+// Created by zx on 22-12-1.
+//
+
+#pragma once
+#include <chrono>
+#include <mutex>
+
+template <typename T>
+class TimedLockData {
+public:
+    TimedLockData();
+    void reset(const T& tdata,double timeout=0.1);
+    bool timeout();
+    T Get();
+
+protected:
+    T data_;
+    std::chrono::steady_clock::time_point tp_;
+    std::mutex mutex_;
+    double timeout_;
+
+};
+
+template <typename T>
+TimedLockData<T>::TimedLockData()
+{
+  timeout_=0.1;
+}
+
+template <typename T>
+void TimedLockData<T>::reset(const T& tdata,double timeout)
+{
+  std::lock_guard<std::mutex> lck (mutex_);
+  data_=tdata;
+  timeout_=timeout;
+  tp_=std::chrono::steady_clock::now();
+}
+
+template <typename T>
+bool TimedLockData<T>::timeout()
+{
+  auto now=std::chrono::steady_clock::now();
+  auto duration = std::chrono::duration_cast<std::chrono::microseconds>(now - tp_);
+  double time = double(duration.count()) * std::chrono::microseconds::period::num / std::chrono::microseconds::period::den;
+  return time>timeout_;
+}
+
+template <typename T>
+T TimedLockData<T>::Get()
+{
+  std::lock_guard<std::mutex> lck (mutex_);
+  return data_;
+}
+
+

+ 8 - 3
protoc.sh

@@ -7,7 +7,12 @@ filenames=()
 for file in ${files[@]}; do
     path=$(dirname $file)
     filename=$(basename $file)
-    paths+=("$path")
-    filenames+=("$filename")
-    protoc -I="$path" $filename --cpp_out="$path"
+#    paths+=("$path")
+#    filenames+=("$filename#*.")
+    if [ "${filename#*.}" = "grpc.proto" ]; then
+        # 打印文件名
+        protoc -I="$path" $filename --cpp_out="$path" --grpc_out="$path" --plugin=protoc-gen-grpc=`which grpc_cpp_plugin`
+    elif [ "${filename#*.}" = "proto" ]; then
+        protoc -I="$path" $filename --cpp_out="$path"
+    fi
 done