Bladeren bron

2021 02/22 普爱测试通信第一版

wk 4 jaren geleden
commit
33d0c50c47
54 gewijzigde bestanden met toevoegingen van 24920 en 0 verwijderingen
  1. 91 0
      CMakeLists.txt
  2. 729 0
      communication/communication.pb.cc
  3. 530 0
      communication/communication.pb.h
  4. 14 0
      communication/communication.proto
  5. 91 0
      communication/communication_message.cpp
  6. 104 0
      communication/communication_message.h
  7. 612 0
      communication/communication_socket_base.cpp
  8. 165 0
      communication/communication_socket_base.h
  9. 537 0
      error_code/error_code.cpp
  10. 489 0
      error_code/error_code.h
  11. 3218 0
      message/message_base.pb.cc
  12. 2341 0
      message/message_base.pb.h
  13. 205 0
      message/message_base.proto
  14. 5437 0
      message/parkspace_allocation_message.pb.cc
  15. 3927 0
      message/parkspace_allocation_message.pb.h
  16. 116 0
      message/parkspace_allocation_message.proto
  17. 391 0
      parkspace_allocation/database_controller.cpp
  18. 101 0
      parkspace_allocation/database_controller.h
  19. 179 0
      parkspace_allocation/parkspace_allocation_communicator.cpp
  20. 48 0
      parkspace_allocation/parkspace_allocation_communicator.h
  21. 642 0
      parkspace_allocation/parkspace_allocator.cpp
  22. 79 0
      parkspace_allocation/parkspace_allocator.h
  23. 660 0
      parkspace_allocation/parkspace_db_manager.cpp
  24. 74 0
      parkspace_allocation/parkspace_db_manager.h
  25. 695 0
      parkspace_allocation/parkspace_parameter.pb.cc
  26. 574 0
      parkspace_allocation/parkspace_parameter.pb.h
  27. 12 0
      parkspace_allocation/parkspace_parameter.proto
  28. 8 0
      proto.sh
  29. 17 0
      setting/communication.prototxt
  30. 54 0
      test/db_test.cpp
  31. 241 0
      test/parkspace_client.cpp
  32. 80 0
      test/test_parkspace_sample.cpp
  33. 341 0
      tool/binary_buf.cpp
  34. 91 0
      tool/binary_buf.h
  35. 85 0
      tool/binary_buf.puml
  36. 94 0
      tool/pathcreator.cpp
  37. 18 0
      tool/pathcreator.h
  38. 0 0
      tool/pcl_cloud_with_lock.cpp
  39. 30 0
      tool/pcl_cloud_with_lock.h
  40. 42 0
      tool/proto_tool.cpp
  41. 56 0
      tool/proto_tool.h
  42. 4 0
      tool/singleton.cpp
  43. 81 0
      tool/singleton.h
  44. 175 0
      tool/thread_condition.cpp
  45. 183 0
      tool/thread_condition.h
  46. 96 0
      tool/thread_condition.puml
  47. 262 0
      tool/thread_pool.h
  48. 6 0
      tool/thread_safe_list.cpp
  49. 354 0
      tool/thread_safe_list.h
  50. 5 0
      tool/thread_safe_map.cpp
  51. 55 0
      tool/thread_safe_map.h
  52. 34 0
      tool/thread_safe_queue.cpp
  53. 339 0
      tool/thread_safe_queue.h
  54. 108 0
      tool/thread_safe_queue.puml

+ 91 - 0
CMakeLists.txt

@@ -0,0 +1,91 @@
+project(nnxx_tests)
+
+cmake_minimum_required(VERSION 3.5)
+
+set (CMAKE_CXX_STANDARD 11)
+set(PCL_DIR "/home/youchen/pcl-1.8/share/pcl-1.8")
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(nanomsg REQUIRED nanomsg)
+FIND_PACKAGE(Protobuf REQUIRED)
+#FIND_PACKAGE(Glog REQUIRED)
+FIND_PACKAGE(OpenCV REQUIRED)
+FIND_PACKAGE(PCL REQUIRED)
+
+include_directories(
+        /usr/local/include
+        ${PCL_INCLUDE_DIRS}
+        ${OpenCV_INCLUDE_DIRS}
+        ${PROTOBUF_INCLUDE_DIRS}
+        laser
+        Locate
+        communication
+        message
+        error_code
+        tool
+        system
+        parkspace_allocation
+        /usr/local/include/cppconn/
+)
+link_directories("/usr/local/lib")
+
+message(STATUS ${EXECUTABLE_OUTPUT_PATH})
+
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/error_code error_src )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/message message_src )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/lidar_locate locate_src )
+#aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/robot robot_src )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/laser LASER_SRC )
+#aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/plc PLC_SRC )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/locate LOCATE_SRC )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/terminor TERMINOR_SRC )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/task TASK_MANAGER_SRC )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/tool TOOL_SRC )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/communication COMMUNICATION_SRC )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/system SYSTEM_SRC )
+aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/parkspace_allocation PARKSPACE_ALLOC_SRC )
+
+# 车位分配测试
+add_executable(parkspace_test
+        ./test/test_parkspace_sample.cpp
+        ${error_src}
+        ${message_src}
+        ${TOOL_SRC}
+        ${COMMUNICATION_SRC}
+        ${PARKSPACE_ALLOC_SRC}
+        )
+target_link_libraries(parkspace_test
+        nnxx
+        nanomsg
+        ${PROTOBUF_LIBRARIES}
+        /usr/local/lib/libglog.a
+        /usr/local/lib/libgflags.a
+        libmysqlcppconn.so
+        )
+#add_executable(parkspace_client
+#        ./test/parkspace_client.cpp
+#        ${error_src}
+#        ${message_src}
+#        ${TOOL_SRC}
+#        ${COMMUNICATION_SRC}
+#        )
+#target_link_libraries(parkspace_client
+#        nnxx
+#        nanomsg
+#        ${PROTOBUF_LIBRARIES}
+#        /usr/local/lib/libglog.a
+#        /usr/local/lib/libgflags.a
+#        )
+
+# db test
+add_executable(db_test
+        ./test/db_test.cpp
+        ./parkspace_allocation/database_controller.cpp
+        ${error_src}
+        ${TOOL_SRC}
+        )
+target_link_libraries(db_test
+        ${PROTOBUF_LIBRARIES}
+        /usr/local/lib/libglog.a
+        /usr/local/lib/libgflags.a
+        libmysqlcppconn.so pthread
+        )

+ 729 - 0
communication/communication.pb.cc

@@ -0,0 +1,729 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// source: communication.proto
+
+#include "communication.pb.h"
+
+#include <algorithm>
+
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/port.h>
+#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/wire_format_lite_inl.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/generated_message_reflection.h>
+#include <google/protobuf/reflection_ops.h>
+#include <google/protobuf/wire_format.h>
+// This is a temporary google only hack
+#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+#include "third_party/protobuf/version.h"
+#endif
+// @@protoc_insertion_point(includes)
+namespace Communication_proto {
+class Communication_parameterDefaultTypeInternal {
+ public:
+  ::google::protobuf::internal::ExplicitlyConstructed<Communication_parameter>
+      _instance;
+} _Communication_parameter_default_instance_;
+class Communication_parameter_allDefaultTypeInternal {
+ public:
+  ::google::protobuf::internal::ExplicitlyConstructed<Communication_parameter_all>
+      _instance;
+} _Communication_parameter_all_default_instance_;
+}  // namespace Communication_proto
+namespace protobuf_communication_2eproto {
+void InitDefaultsCommunication_parameterImpl() {
+  GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+  ::google::protobuf::internal::InitProtobufDefaultsForceUnique();
+#else
+  ::google::protobuf::internal::InitProtobufDefaults();
+#endif  // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+  {
+    void* ptr = &::Communication_proto::_Communication_parameter_default_instance_;
+    new (ptr) ::Communication_proto::Communication_parameter();
+    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
+  }
+  ::Communication_proto::Communication_parameter::InitAsDefaultInstance();
+}
+
+void InitDefaultsCommunication_parameter() {
+  static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+  ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsCommunication_parameterImpl);
+}
+
+void InitDefaultsCommunication_parameter_allImpl() {
+  GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+  ::google::protobuf::internal::InitProtobufDefaultsForceUnique();
+#else
+  ::google::protobuf::internal::InitProtobufDefaults();
+#endif  // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+  protobuf_communication_2eproto::InitDefaultsCommunication_parameter();
+  {
+    void* ptr = &::Communication_proto::_Communication_parameter_all_default_instance_;
+    new (ptr) ::Communication_proto::Communication_parameter_all();
+    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
+  }
+  ::Communication_proto::Communication_parameter_all::InitAsDefaultInstance();
+}
+
+void InitDefaultsCommunication_parameter_all() {
+  static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+  ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsCommunication_parameter_allImpl);
+}
+
+::google::protobuf::Metadata file_level_metadata[2];
+
+const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::Communication_proto::Communication_parameter, _has_bits_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::Communication_proto::Communication_parameter, _internal_metadata_),
+  ~0u,  // no _extensions_
+  ~0u,  // no _oneof_case_
+  ~0u,  // no _weak_field_map_
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::Communication_proto::Communication_parameter, bind_string_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::Communication_proto::Communication_parameter, connect_string_vector_),
+  0,
+  ~0u,
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::Communication_proto::Communication_parameter_all, _has_bits_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::Communication_proto::Communication_parameter_all, _internal_metadata_),
+  ~0u,  // no _extensions_
+  ~0u,  // no _oneof_case_
+  ~0u,  // no _weak_field_map_
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::Communication_proto::Communication_parameter_all, communication_parameters_),
+  0,
+};
+static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
+  { 0, 7, sizeof(::Communication_proto::Communication_parameter)},
+  { 9, 15, sizeof(::Communication_proto::Communication_parameter_all)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+  reinterpret_cast<const ::google::protobuf::Message*>(&::Communication_proto::_Communication_parameter_default_instance_),
+  reinterpret_cast<const ::google::protobuf::Message*>(&::Communication_proto::_Communication_parameter_all_default_instance_),
+};
+
+void protobuf_AssignDescriptors() {
+  AddDescriptors();
+  ::google::protobuf::MessageFactory* factory = NULL;
+  AssignDescriptors(
+      "communication.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+      file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+  static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+  ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
+}
+
+void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
+void protobuf_RegisterTypes(const ::std::string&) {
+  protobuf_AssignDescriptorsOnce();
+  ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 2);
+}
+
+void AddDescriptorsImpl() {
+  InitDefaults();
+  static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
+      "\n\023communication.proto\022\023Communication_pro"
+      "to\"M\n\027Communication_parameter\022\023\n\013bind_st"
+      "ring\030\001 \001(\t\022\035\n\025connect_string_vector\030\002 \003("
+      "\t\"m\n\033Communication_parameter_all\022N\n\030comm"
+      "unication_parameters\030\001 \001(\0132,.Communicati"
+      "on_proto.Communication_parameter"
+  };
+  ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
+      descriptor, 232);
+  ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
+    "communication.proto", &protobuf_RegisterTypes);
+}
+
+void AddDescriptors() {
+  static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+  ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
+// Force AddDescriptors() to be called at dynamic initialization time.
+struct StaticDescriptorInitializer {
+  StaticDescriptorInitializer() {
+    AddDescriptors();
+  }
+} static_descriptor_initializer;
+}  // namespace protobuf_communication_2eproto
+namespace Communication_proto {
+
+// ===================================================================
+
+void Communication_parameter::InitAsDefaultInstance() {
+}
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const int Communication_parameter::kBindStringFieldNumber;
+const int Communication_parameter::kConnectStringVectorFieldNumber;
+#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
+
+Communication_parameter::Communication_parameter()
+  : ::google::protobuf::Message(), _internal_metadata_(NULL) {
+  if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+    ::protobuf_communication_2eproto::InitDefaultsCommunication_parameter();
+  }
+  SharedCtor();
+  // @@protoc_insertion_point(constructor:Communication_proto.Communication_parameter)
+}
+Communication_parameter::Communication_parameter(const Communication_parameter& from)
+  : ::google::protobuf::Message(),
+      _internal_metadata_(NULL),
+      _has_bits_(from._has_bits_),
+      _cached_size_(0),
+      connect_string_vector_(from.connect_string_vector_) {
+  _internal_metadata_.MergeFrom(from._internal_metadata_);
+  bind_string_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  if (from.has_bind_string()) {
+    bind_string_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.bind_string_);
+  }
+  // @@protoc_insertion_point(copy_constructor:Communication_proto.Communication_parameter)
+}
+
+void Communication_parameter::SharedCtor() {
+  _cached_size_ = 0;
+  bind_string_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+
+Communication_parameter::~Communication_parameter() {
+  // @@protoc_insertion_point(destructor:Communication_proto.Communication_parameter)
+  SharedDtor();
+}
+
+void Communication_parameter::SharedDtor() {
+  bind_string_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+
+void Communication_parameter::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const ::google::protobuf::Descriptor* Communication_parameter::descriptor() {
+  ::protobuf_communication_2eproto::protobuf_AssignDescriptorsOnce();
+  return ::protobuf_communication_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
+}
+
+const Communication_parameter& Communication_parameter::default_instance() {
+  ::protobuf_communication_2eproto::InitDefaultsCommunication_parameter();
+  return *internal_default_instance();
+}
+
+Communication_parameter* Communication_parameter::New(::google::protobuf::Arena* arena) const {
+  Communication_parameter* n = new Communication_parameter;
+  if (arena != NULL) {
+    arena->Own(n);
+  }
+  return n;
+}
+
+void Communication_parameter::Clear() {
+// @@protoc_insertion_point(message_clear_start:Communication_proto.Communication_parameter)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  // Prevent compiler warnings about cached_has_bits being unused
+  (void) cached_has_bits;
+
+  connect_string_vector_.Clear();
+  cached_has_bits = _has_bits_[0];
+  if (cached_has_bits & 0x00000001u) {
+    GOOGLE_DCHECK(!bind_string_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+    (*bind_string_.UnsafeRawStringPointer())->clear();
+  }
+  _has_bits_.Clear();
+  _internal_metadata_.Clear();
+}
+
+bool Communication_parameter::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
+  ::google::protobuf::uint32 tag;
+  // @@protoc_insertion_point(parse_start:Communication_proto.Communication_parameter)
+  for (;;) {
+    ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
+    tag = p.first;
+    if (!p.second) goto handle_unusual;
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // optional string bind_string = 1;
+      case 1: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_bind_string()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+            this->bind_string().data(), static_cast<int>(this->bind_string().length()),
+            ::google::protobuf::internal::WireFormat::PARSE,
+            "Communication_proto.Communication_parameter.bind_string");
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      // repeated string connect_string_vector = 2;
+      case 2: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->add_connect_string_vector()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+            this->connect_string_vector(this->connect_string_vector_size() - 1).data(),
+            static_cast<int>(this->connect_string_vector(this->connect_string_vector_size() - 1).length()),
+            ::google::protobuf::internal::WireFormat::PARSE,
+            "Communication_proto.Communication_parameter.connect_string_vector");
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      default: {
+      handle_unusual:
+        if (tag == 0) {
+          goto success;
+        }
+        DO_(::google::protobuf::internal::WireFormat::SkipField(
+              input, tag, _internal_metadata_.mutable_unknown_fields()));
+        break;
+      }
+    }
+  }
+success:
+  // @@protoc_insertion_point(parse_success:Communication_proto.Communication_parameter)
+  return true;
+failure:
+  // @@protoc_insertion_point(parse_failure:Communication_proto.Communication_parameter)
+  return false;
+#undef DO_
+}
+
+void Communication_parameter::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // @@protoc_insertion_point(serialize_start:Communication_proto.Communication_parameter)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  // optional string bind_string = 1;
+  if (cached_has_bits & 0x00000001u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->bind_string().data(), static_cast<int>(this->bind_string().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "Communication_proto.Communication_parameter.bind_string");
+    ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+      1, this->bind_string(), output);
+  }
+
+  // repeated string connect_string_vector = 2;
+  for (int i = 0, n = this->connect_string_vector_size(); i < n; i++) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->connect_string_vector(i).data(), static_cast<int>(this->connect_string_vector(i).length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "Communication_proto.Communication_parameter.connect_string_vector");
+    ::google::protobuf::internal::WireFormatLite::WriteString(
+      2, this->connect_string_vector(i), output);
+  }
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
+        _internal_metadata_.unknown_fields(), output);
+  }
+  // @@protoc_insertion_point(serialize_end:Communication_proto.Communication_parameter)
+}
+
+::google::protobuf::uint8* Communication_parameter::InternalSerializeWithCachedSizesToArray(
+    bool deterministic, ::google::protobuf::uint8* target) const {
+  (void)deterministic; // Unused
+  // @@protoc_insertion_point(serialize_to_array_start:Communication_proto.Communication_parameter)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  // optional string bind_string = 1;
+  if (cached_has_bits & 0x00000001u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->bind_string().data(), static_cast<int>(this->bind_string().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "Communication_proto.Communication_parameter.bind_string");
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        1, this->bind_string(), target);
+  }
+
+  // repeated string connect_string_vector = 2;
+  for (int i = 0, n = this->connect_string_vector_size(); i < n; i++) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->connect_string_vector(i).data(), static_cast<int>(this->connect_string_vector(i).length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "Communication_proto.Communication_parameter.connect_string_vector");
+    target = ::google::protobuf::internal::WireFormatLite::
+      WriteStringToArray(2, this->connect_string_vector(i), target);
+  }
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
+        _internal_metadata_.unknown_fields(), target);
+  }
+  // @@protoc_insertion_point(serialize_to_array_end:Communication_proto.Communication_parameter)
+  return target;
+}
+
+size_t Communication_parameter::ByteSizeLong() const {
+// @@protoc_insertion_point(message_byte_size_start:Communication_proto.Communication_parameter)
+  size_t total_size = 0;
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    total_size +=
+      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+        _internal_metadata_.unknown_fields());
+  }
+  // repeated string connect_string_vector = 2;
+  total_size += 1 *
+      ::google::protobuf::internal::FromIntSize(this->connect_string_vector_size());
+  for (int i = 0, n = this->connect_string_vector_size(); i < n; i++) {
+    total_size += ::google::protobuf::internal::WireFormatLite::StringSize(
+      this->connect_string_vector(i));
+  }
+
+  // optional string bind_string = 1;
+  if (has_bind_string()) {
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->bind_string());
+  }
+
+  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = cached_size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+  return total_size;
+}
+
+void Communication_parameter::MergeFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_merge_from_start:Communication_proto.Communication_parameter)
+  GOOGLE_DCHECK_NE(&from, this);
+  const Communication_parameter* source =
+      ::google::protobuf::internal::DynamicCastToGenerated<const Communication_parameter>(
+          &from);
+  if (source == NULL) {
+  // @@protoc_insertion_point(generalized_merge_from_cast_fail:Communication_proto.Communication_parameter)
+    ::google::protobuf::internal::ReflectionOps::Merge(from, this);
+  } else {
+  // @@protoc_insertion_point(generalized_merge_from_cast_success:Communication_proto.Communication_parameter)
+    MergeFrom(*source);
+  }
+}
+
+void Communication_parameter::MergeFrom(const Communication_parameter& from) {
+// @@protoc_insertion_point(class_specific_merge_from_start:Communication_proto.Communication_parameter)
+  GOOGLE_DCHECK_NE(&from, this);
+  _internal_metadata_.MergeFrom(from._internal_metadata_);
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  connect_string_vector_.MergeFrom(from.connect_string_vector_);
+  if (from.has_bind_string()) {
+    set_has_bind_string();
+    bind_string_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.bind_string_);
+  }
+}
+
+void Communication_parameter::CopyFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_copy_from_start:Communication_proto.Communication_parameter)
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+void Communication_parameter::CopyFrom(const Communication_parameter& from) {
+// @@protoc_insertion_point(class_specific_copy_from_start:Communication_proto.Communication_parameter)
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+bool Communication_parameter::IsInitialized() const {
+  return true;
+}
+
+void Communication_parameter::Swap(Communication_parameter* other) {
+  if (other == this) return;
+  InternalSwap(other);
+}
+void Communication_parameter::InternalSwap(Communication_parameter* other) {
+  using std::swap;
+  connect_string_vector_.InternalSwap(&other->connect_string_vector_);
+  bind_string_.Swap(&other->bind_string_);
+  swap(_has_bits_[0], other->_has_bits_[0]);
+  _internal_metadata_.Swap(&other->_internal_metadata_);
+  swap(_cached_size_, other->_cached_size_);
+}
+
+::google::protobuf::Metadata Communication_parameter::GetMetadata() const {
+  protobuf_communication_2eproto::protobuf_AssignDescriptorsOnce();
+  return ::protobuf_communication_2eproto::file_level_metadata[kIndexInFileMessages];
+}
+
+
+// ===================================================================
+
+void Communication_parameter_all::InitAsDefaultInstance() {
+  ::Communication_proto::_Communication_parameter_all_default_instance_._instance.get_mutable()->communication_parameters_ = const_cast< ::Communication_proto::Communication_parameter*>(
+      ::Communication_proto::Communication_parameter::internal_default_instance());
+}
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const int Communication_parameter_all::kCommunicationParametersFieldNumber;
+#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
+
+Communication_parameter_all::Communication_parameter_all()
+  : ::google::protobuf::Message(), _internal_metadata_(NULL) {
+  if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+    ::protobuf_communication_2eproto::InitDefaultsCommunication_parameter_all();
+  }
+  SharedCtor();
+  // @@protoc_insertion_point(constructor:Communication_proto.Communication_parameter_all)
+}
+Communication_parameter_all::Communication_parameter_all(const Communication_parameter_all& from)
+  : ::google::protobuf::Message(),
+      _internal_metadata_(NULL),
+      _has_bits_(from._has_bits_),
+      _cached_size_(0) {
+  _internal_metadata_.MergeFrom(from._internal_metadata_);
+  if (from.has_communication_parameters()) {
+    communication_parameters_ = new ::Communication_proto::Communication_parameter(*from.communication_parameters_);
+  } else {
+    communication_parameters_ = NULL;
+  }
+  // @@protoc_insertion_point(copy_constructor:Communication_proto.Communication_parameter_all)
+}
+
+void Communication_parameter_all::SharedCtor() {
+  _cached_size_ = 0;
+  communication_parameters_ = NULL;
+}
+
+Communication_parameter_all::~Communication_parameter_all() {
+  // @@protoc_insertion_point(destructor:Communication_proto.Communication_parameter_all)
+  SharedDtor();
+}
+
+void Communication_parameter_all::SharedDtor() {
+  if (this != internal_default_instance()) delete communication_parameters_;
+}
+
+void Communication_parameter_all::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const ::google::protobuf::Descriptor* Communication_parameter_all::descriptor() {
+  ::protobuf_communication_2eproto::protobuf_AssignDescriptorsOnce();
+  return ::protobuf_communication_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
+}
+
+const Communication_parameter_all& Communication_parameter_all::default_instance() {
+  ::protobuf_communication_2eproto::InitDefaultsCommunication_parameter_all();
+  return *internal_default_instance();
+}
+
+Communication_parameter_all* Communication_parameter_all::New(::google::protobuf::Arena* arena) const {
+  Communication_parameter_all* n = new Communication_parameter_all;
+  if (arena != NULL) {
+    arena->Own(n);
+  }
+  return n;
+}
+
+void Communication_parameter_all::Clear() {
+// @@protoc_insertion_point(message_clear_start:Communication_proto.Communication_parameter_all)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  // Prevent compiler warnings about cached_has_bits being unused
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  if (cached_has_bits & 0x00000001u) {
+    GOOGLE_DCHECK(communication_parameters_ != NULL);
+    communication_parameters_->Clear();
+  }
+  _has_bits_.Clear();
+  _internal_metadata_.Clear();
+}
+
+bool Communication_parameter_all::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
+  ::google::protobuf::uint32 tag;
+  // @@protoc_insertion_point(parse_start:Communication_proto.Communication_parameter_all)
+  for (;;) {
+    ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
+    tag = p.first;
+    if (!p.second) goto handle_unusual;
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // optional .Communication_proto.Communication_parameter communication_parameters = 1;
+      case 1: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadMessage(
+               input, mutable_communication_parameters()));
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      default: {
+      handle_unusual:
+        if (tag == 0) {
+          goto success;
+        }
+        DO_(::google::protobuf::internal::WireFormat::SkipField(
+              input, tag, _internal_metadata_.mutable_unknown_fields()));
+        break;
+      }
+    }
+  }
+success:
+  // @@protoc_insertion_point(parse_success:Communication_proto.Communication_parameter_all)
+  return true;
+failure:
+  // @@protoc_insertion_point(parse_failure:Communication_proto.Communication_parameter_all)
+  return false;
+#undef DO_
+}
+
+void Communication_parameter_all::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // @@protoc_insertion_point(serialize_start:Communication_proto.Communication_parameter_all)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  // optional .Communication_proto.Communication_parameter communication_parameters = 1;
+  if (cached_has_bits & 0x00000001u) {
+    ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray(
+      1, *this->communication_parameters_, output);
+  }
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
+        _internal_metadata_.unknown_fields(), output);
+  }
+  // @@protoc_insertion_point(serialize_end:Communication_proto.Communication_parameter_all)
+}
+
+::google::protobuf::uint8* Communication_parameter_all::InternalSerializeWithCachedSizesToArray(
+    bool deterministic, ::google::protobuf::uint8* target) const {
+  (void)deterministic; // Unused
+  // @@protoc_insertion_point(serialize_to_array_start:Communication_proto.Communication_parameter_all)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  // optional .Communication_proto.Communication_parameter communication_parameters = 1;
+  if (cached_has_bits & 0x00000001u) {
+    target = ::google::protobuf::internal::WireFormatLite::
+      InternalWriteMessageToArray(
+        1, *this->communication_parameters_, deterministic, target);
+  }
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
+        _internal_metadata_.unknown_fields(), target);
+  }
+  // @@protoc_insertion_point(serialize_to_array_end:Communication_proto.Communication_parameter_all)
+  return target;
+}
+
+size_t Communication_parameter_all::ByteSizeLong() const {
+// @@protoc_insertion_point(message_byte_size_start:Communication_proto.Communication_parameter_all)
+  size_t total_size = 0;
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    total_size +=
+      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+        _internal_metadata_.unknown_fields());
+  }
+  // optional .Communication_proto.Communication_parameter communication_parameters = 1;
+  if (has_communication_parameters()) {
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::MessageSize(
+        *this->communication_parameters_);
+  }
+
+  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = cached_size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+  return total_size;
+}
+
+void Communication_parameter_all::MergeFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_merge_from_start:Communication_proto.Communication_parameter_all)
+  GOOGLE_DCHECK_NE(&from, this);
+  const Communication_parameter_all* source =
+      ::google::protobuf::internal::DynamicCastToGenerated<const Communication_parameter_all>(
+          &from);
+  if (source == NULL) {
+  // @@protoc_insertion_point(generalized_merge_from_cast_fail:Communication_proto.Communication_parameter_all)
+    ::google::protobuf::internal::ReflectionOps::Merge(from, this);
+  } else {
+  // @@protoc_insertion_point(generalized_merge_from_cast_success:Communication_proto.Communication_parameter_all)
+    MergeFrom(*source);
+  }
+}
+
+void Communication_parameter_all::MergeFrom(const Communication_parameter_all& from) {
+// @@protoc_insertion_point(class_specific_merge_from_start:Communication_proto.Communication_parameter_all)
+  GOOGLE_DCHECK_NE(&from, this);
+  _internal_metadata_.MergeFrom(from._internal_metadata_);
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  if (from.has_communication_parameters()) {
+    mutable_communication_parameters()->::Communication_proto::Communication_parameter::MergeFrom(from.communication_parameters());
+  }
+}
+
+void Communication_parameter_all::CopyFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_copy_from_start:Communication_proto.Communication_parameter_all)
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+void Communication_parameter_all::CopyFrom(const Communication_parameter_all& from) {
+// @@protoc_insertion_point(class_specific_copy_from_start:Communication_proto.Communication_parameter_all)
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+bool Communication_parameter_all::IsInitialized() const {
+  return true;
+}
+
+void Communication_parameter_all::Swap(Communication_parameter_all* other) {
+  if (other == this) return;
+  InternalSwap(other);
+}
+void Communication_parameter_all::InternalSwap(Communication_parameter_all* other) {
+  using std::swap;
+  swap(communication_parameters_, other->communication_parameters_);
+  swap(_has_bits_[0], other->_has_bits_[0]);
+  _internal_metadata_.Swap(&other->_internal_metadata_);
+  swap(_cached_size_, other->_cached_size_);
+}
+
+::google::protobuf::Metadata Communication_parameter_all::GetMetadata() const {
+  protobuf_communication_2eproto::protobuf_AssignDescriptorsOnce();
+  return ::protobuf_communication_2eproto::file_level_metadata[kIndexInFileMessages];
+}
+
+
+// @@protoc_insertion_point(namespace_scope)
+}  // namespace Communication_proto
+
+// @@protoc_insertion_point(global_scope)

+ 530 - 0
communication/communication.pb.h

@@ -0,0 +1,530 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// source: communication.proto
+
+#ifndef PROTOBUF_communication_2eproto__INCLUDED
+#define PROTOBUF_communication_2eproto__INCLUDED
+
+#include <string>
+
+#include <google/protobuf/stubs/common.h>
+
+#if GOOGLE_PROTOBUF_VERSION < 3005000
+#error This file was generated by a newer version of protoc which is
+#error incompatible with your Protocol Buffer headers.  Please update
+#error your headers.
+#endif
+#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#error This file was generated by an older version of protoc which is
+#error incompatible with your Protocol Buffer headers.  Please
+#error regenerate this file with a newer version of protoc.
+#endif
+
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/arena.h>
+#include <google/protobuf/arenastring.h>
+#include <google/protobuf/generated_message_table_driven.h>
+#include <google/protobuf/generated_message_util.h>
+#include <google/protobuf/metadata.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/repeated_field.h>  // IWYU pragma: export
+#include <google/protobuf/extension_set.h>  // IWYU pragma: export
+#include <google/protobuf/unknown_field_set.h>
+// @@protoc_insertion_point(includes)
+
+namespace protobuf_communication_2eproto {
+// Internal implementation detail -- do not use these members.
+struct TableStruct {
+  static const ::google::protobuf::internal::ParseTableField entries[];
+  static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
+  static const ::google::protobuf::internal::ParseTable schema[2];
+  static const ::google::protobuf::internal::FieldMetadata field_metadata[];
+  static const ::google::protobuf::internal::SerializationTable serialization_table[];
+  static const ::google::protobuf::uint32 offsets[];
+};
+void AddDescriptors();
+void InitDefaultsCommunication_parameterImpl();
+void InitDefaultsCommunication_parameter();
+void InitDefaultsCommunication_parameter_allImpl();
+void InitDefaultsCommunication_parameter_all();
+inline void InitDefaults() {
+  InitDefaultsCommunication_parameter();
+  InitDefaultsCommunication_parameter_all();
+}
+}  // namespace protobuf_communication_2eproto
+namespace Communication_proto {
+class Communication_parameter;
+class Communication_parameterDefaultTypeInternal;
+extern Communication_parameterDefaultTypeInternal _Communication_parameter_default_instance_;
+class Communication_parameter_all;
+class Communication_parameter_allDefaultTypeInternal;
+extern Communication_parameter_allDefaultTypeInternal _Communication_parameter_all_default_instance_;
+}  // namespace Communication_proto
+namespace Communication_proto {
+
+// ===================================================================
+
+class Communication_parameter : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Communication_proto.Communication_parameter) */ {
+ public:
+  Communication_parameter();
+  virtual ~Communication_parameter();
+
+  Communication_parameter(const Communication_parameter& from);
+
+  inline Communication_parameter& operator=(const Communication_parameter& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Communication_parameter(Communication_parameter&& from) noexcept
+    : Communication_parameter() {
+    *this = ::std::move(from);
+  }
+
+  inline Communication_parameter& operator=(Communication_parameter&& from) noexcept {
+    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+      if (this != &from) InternalSwap(&from);
+    } else {
+      CopyFrom(from);
+    }
+    return *this;
+  }
+  #endif
+  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
+    return _internal_metadata_.unknown_fields();
+  }
+  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
+    return _internal_metadata_.mutable_unknown_fields();
+  }
+
+  static const ::google::protobuf::Descriptor* descriptor();
+  static const Communication_parameter& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Communication_parameter* internal_default_instance() {
+    return reinterpret_cast<const Communication_parameter*>(
+               &_Communication_parameter_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    0;
+
+  void Swap(Communication_parameter* other);
+  friend void swap(Communication_parameter& a, Communication_parameter& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Communication_parameter* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Communication_parameter* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+  void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+  void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+  void CopyFrom(const Communication_parameter& from);
+  void MergeFrom(const Communication_parameter& from);
+  void Clear() PROTOBUF_FINAL;
+  bool IsInitialized() const PROTOBUF_FINAL;
+
+  size_t ByteSizeLong() const PROTOBUF_FINAL;
+  bool MergePartialFromCodedStream(
+      ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
+  void SerializeWithCachedSizes(
+      ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
+  ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
+      bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+  int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
+  private:
+  void SharedCtor();
+  void SharedDtor();
+  void SetCachedSize(int size) const PROTOBUF_FINAL;
+  void InternalSwap(Communication_parameter* other);
+  private:
+  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
+    return NULL;
+  }
+  inline void* MaybeArenaPtr() const {
+    return NULL;
+  }
+  public:
+
+  ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
+
+  // nested types ----------------------------------------------------
+
+  // accessors -------------------------------------------------------
+
+  // repeated string connect_string_vector = 2;
+  int connect_string_vector_size() const;
+  void clear_connect_string_vector();
+  static const int kConnectStringVectorFieldNumber = 2;
+  const ::std::string& connect_string_vector(int index) const;
+  ::std::string* mutable_connect_string_vector(int index);
+  void set_connect_string_vector(int index, const ::std::string& value);
+  #if LANG_CXX11
+  void set_connect_string_vector(int index, ::std::string&& value);
+  #endif
+  void set_connect_string_vector(int index, const char* value);
+  void set_connect_string_vector(int index, const char* value, size_t size);
+  ::std::string* add_connect_string_vector();
+  void add_connect_string_vector(const ::std::string& value);
+  #if LANG_CXX11
+  void add_connect_string_vector(::std::string&& value);
+  #endif
+  void add_connect_string_vector(const char* value);
+  void add_connect_string_vector(const char* value, size_t size);
+  const ::google::protobuf::RepeatedPtrField< ::std::string>& connect_string_vector() const;
+  ::google::protobuf::RepeatedPtrField< ::std::string>* mutable_connect_string_vector();
+
+  // optional string bind_string = 1;
+  bool has_bind_string() const;
+  void clear_bind_string();
+  static const int kBindStringFieldNumber = 1;
+  const ::std::string& bind_string() const;
+  void set_bind_string(const ::std::string& value);
+  #if LANG_CXX11
+  void set_bind_string(::std::string&& value);
+  #endif
+  void set_bind_string(const char* value);
+  void set_bind_string(const char* value, size_t size);
+  ::std::string* mutable_bind_string();
+  ::std::string* release_bind_string();
+  void set_allocated_bind_string(::std::string* bind_string);
+
+  // @@protoc_insertion_point(class_scope:Communication_proto.Communication_parameter)
+ private:
+  void set_has_bind_string();
+  void clear_has_bind_string();
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::google::protobuf::RepeatedPtrField< ::std::string> connect_string_vector_;
+  ::google::protobuf::internal::ArenaStringPtr bind_string_;
+  friend struct ::protobuf_communication_2eproto::TableStruct;
+  friend void ::protobuf_communication_2eproto::InitDefaultsCommunication_parameterImpl();
+};
+// -------------------------------------------------------------------
+
+class Communication_parameter_all : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Communication_proto.Communication_parameter_all) */ {
+ public:
+  Communication_parameter_all();
+  virtual ~Communication_parameter_all();
+
+  Communication_parameter_all(const Communication_parameter_all& from);
+
+  inline Communication_parameter_all& operator=(const Communication_parameter_all& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Communication_parameter_all(Communication_parameter_all&& from) noexcept
+    : Communication_parameter_all() {
+    *this = ::std::move(from);
+  }
+
+  inline Communication_parameter_all& operator=(Communication_parameter_all&& from) noexcept {
+    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+      if (this != &from) InternalSwap(&from);
+    } else {
+      CopyFrom(from);
+    }
+    return *this;
+  }
+  #endif
+  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
+    return _internal_metadata_.unknown_fields();
+  }
+  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
+    return _internal_metadata_.mutable_unknown_fields();
+  }
+
+  static const ::google::protobuf::Descriptor* descriptor();
+  static const Communication_parameter_all& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Communication_parameter_all* internal_default_instance() {
+    return reinterpret_cast<const Communication_parameter_all*>(
+               &_Communication_parameter_all_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    1;
+
+  void Swap(Communication_parameter_all* other);
+  friend void swap(Communication_parameter_all& a, Communication_parameter_all& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Communication_parameter_all* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Communication_parameter_all* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+  void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+  void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+  void CopyFrom(const Communication_parameter_all& from);
+  void MergeFrom(const Communication_parameter_all& from);
+  void Clear() PROTOBUF_FINAL;
+  bool IsInitialized() const PROTOBUF_FINAL;
+
+  size_t ByteSizeLong() const PROTOBUF_FINAL;
+  bool MergePartialFromCodedStream(
+      ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
+  void SerializeWithCachedSizes(
+      ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
+  ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
+      bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+  int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
+  private:
+  void SharedCtor();
+  void SharedDtor();
+  void SetCachedSize(int size) const PROTOBUF_FINAL;
+  void InternalSwap(Communication_parameter_all* other);
+  private:
+  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
+    return NULL;
+  }
+  inline void* MaybeArenaPtr() const {
+    return NULL;
+  }
+  public:
+
+  ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
+
+  // nested types ----------------------------------------------------
+
+  // accessors -------------------------------------------------------
+
+  // optional .Communication_proto.Communication_parameter communication_parameters = 1;
+  bool has_communication_parameters() const;
+  void clear_communication_parameters();
+  static const int kCommunicationParametersFieldNumber = 1;
+  const ::Communication_proto::Communication_parameter& communication_parameters() const;
+  ::Communication_proto::Communication_parameter* release_communication_parameters();
+  ::Communication_proto::Communication_parameter* mutable_communication_parameters();
+  void set_allocated_communication_parameters(::Communication_proto::Communication_parameter* communication_parameters);
+
+  // @@protoc_insertion_point(class_scope:Communication_proto.Communication_parameter_all)
+ private:
+  void set_has_communication_parameters();
+  void clear_has_communication_parameters();
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::Communication_proto::Communication_parameter* communication_parameters_;
+  friend struct ::protobuf_communication_2eproto::TableStruct;
+  friend void ::protobuf_communication_2eproto::InitDefaultsCommunication_parameter_allImpl();
+};
+// ===================================================================
+
+
+// ===================================================================
+
+#ifdef __GNUC__
+  #pragma GCC diagnostic push
+  #pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif  // __GNUC__
+// Communication_parameter
+
+// optional string bind_string = 1;
+inline bool Communication_parameter::has_bind_string() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Communication_parameter::set_has_bind_string() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Communication_parameter::clear_has_bind_string() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline void Communication_parameter::clear_bind_string() {
+  bind_string_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  clear_has_bind_string();
+}
+inline const ::std::string& Communication_parameter::bind_string() const {
+  // @@protoc_insertion_point(field_get:Communication_proto.Communication_parameter.bind_string)
+  return bind_string_.GetNoArena();
+}
+inline void Communication_parameter::set_bind_string(const ::std::string& value) {
+  set_has_bind_string();
+  bind_string_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+  // @@protoc_insertion_point(field_set:Communication_proto.Communication_parameter.bind_string)
+}
+#if LANG_CXX11
+inline void Communication_parameter::set_bind_string(::std::string&& value) {
+  set_has_bind_string();
+  bind_string_.SetNoArena(
+    &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+  // @@protoc_insertion_point(field_set_rvalue:Communication_proto.Communication_parameter.bind_string)
+}
+#endif
+inline void Communication_parameter::set_bind_string(const char* value) {
+  GOOGLE_DCHECK(value != NULL);
+  set_has_bind_string();
+  bind_string_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+  // @@protoc_insertion_point(field_set_char:Communication_proto.Communication_parameter.bind_string)
+}
+inline void Communication_parameter::set_bind_string(const char* value, size_t size) {
+  set_has_bind_string();
+  bind_string_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+      ::std::string(reinterpret_cast<const char*>(value), size));
+  // @@protoc_insertion_point(field_set_pointer:Communication_proto.Communication_parameter.bind_string)
+}
+inline ::std::string* Communication_parameter::mutable_bind_string() {
+  set_has_bind_string();
+  // @@protoc_insertion_point(field_mutable:Communication_proto.Communication_parameter.bind_string)
+  return bind_string_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* Communication_parameter::release_bind_string() {
+  // @@protoc_insertion_point(field_release:Communication_proto.Communication_parameter.bind_string)
+  clear_has_bind_string();
+  return bind_string_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void Communication_parameter::set_allocated_bind_string(::std::string* bind_string) {
+  if (bind_string != NULL) {
+    set_has_bind_string();
+  } else {
+    clear_has_bind_string();
+  }
+  bind_string_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), bind_string);
+  // @@protoc_insertion_point(field_set_allocated:Communication_proto.Communication_parameter.bind_string)
+}
+
+// repeated string connect_string_vector = 2;
+inline int Communication_parameter::connect_string_vector_size() const {
+  return connect_string_vector_.size();
+}
+inline void Communication_parameter::clear_connect_string_vector() {
+  connect_string_vector_.Clear();
+}
+inline const ::std::string& Communication_parameter::connect_string_vector(int index) const {
+  // @@protoc_insertion_point(field_get:Communication_proto.Communication_parameter.connect_string_vector)
+  return connect_string_vector_.Get(index);
+}
+inline ::std::string* Communication_parameter::mutable_connect_string_vector(int index) {
+  // @@protoc_insertion_point(field_mutable:Communication_proto.Communication_parameter.connect_string_vector)
+  return connect_string_vector_.Mutable(index);
+}
+inline void Communication_parameter::set_connect_string_vector(int index, const ::std::string& value) {
+  // @@protoc_insertion_point(field_set:Communication_proto.Communication_parameter.connect_string_vector)
+  connect_string_vector_.Mutable(index)->assign(value);
+}
+#if LANG_CXX11
+inline void Communication_parameter::set_connect_string_vector(int index, ::std::string&& value) {
+  // @@protoc_insertion_point(field_set:Communication_proto.Communication_parameter.connect_string_vector)
+  connect_string_vector_.Mutable(index)->assign(std::move(value));
+}
+#endif
+inline void Communication_parameter::set_connect_string_vector(int index, const char* value) {
+  GOOGLE_DCHECK(value != NULL);
+  connect_string_vector_.Mutable(index)->assign(value);
+  // @@protoc_insertion_point(field_set_char:Communication_proto.Communication_parameter.connect_string_vector)
+}
+inline void Communication_parameter::set_connect_string_vector(int index, const char* value, size_t size) {
+  connect_string_vector_.Mutable(index)->assign(
+    reinterpret_cast<const char*>(value), size);
+  // @@protoc_insertion_point(field_set_pointer:Communication_proto.Communication_parameter.connect_string_vector)
+}
+inline ::std::string* Communication_parameter::add_connect_string_vector() {
+  // @@protoc_insertion_point(field_add_mutable:Communication_proto.Communication_parameter.connect_string_vector)
+  return connect_string_vector_.Add();
+}
+inline void Communication_parameter::add_connect_string_vector(const ::std::string& value) {
+  connect_string_vector_.Add()->assign(value);
+  // @@protoc_insertion_point(field_add:Communication_proto.Communication_parameter.connect_string_vector)
+}
+#if LANG_CXX11
+inline void Communication_parameter::add_connect_string_vector(::std::string&& value) {
+  connect_string_vector_.Add(std::move(value));
+  // @@protoc_insertion_point(field_add:Communication_proto.Communication_parameter.connect_string_vector)
+}
+#endif
+inline void Communication_parameter::add_connect_string_vector(const char* value) {
+  GOOGLE_DCHECK(value != NULL);
+  connect_string_vector_.Add()->assign(value);
+  // @@protoc_insertion_point(field_add_char:Communication_proto.Communication_parameter.connect_string_vector)
+}
+inline void Communication_parameter::add_connect_string_vector(const char* value, size_t size) {
+  connect_string_vector_.Add()->assign(reinterpret_cast<const char*>(value), size);
+  // @@protoc_insertion_point(field_add_pointer:Communication_proto.Communication_parameter.connect_string_vector)
+}
+inline const ::google::protobuf::RepeatedPtrField< ::std::string>&
+Communication_parameter::connect_string_vector() const {
+  // @@protoc_insertion_point(field_list:Communication_proto.Communication_parameter.connect_string_vector)
+  return connect_string_vector_;
+}
+inline ::google::protobuf::RepeatedPtrField< ::std::string>*
+Communication_parameter::mutable_connect_string_vector() {
+  // @@protoc_insertion_point(field_mutable_list:Communication_proto.Communication_parameter.connect_string_vector)
+  return &connect_string_vector_;
+}
+
+// -------------------------------------------------------------------
+
+// Communication_parameter_all
+
+// optional .Communication_proto.Communication_parameter communication_parameters = 1;
+inline bool Communication_parameter_all::has_communication_parameters() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Communication_parameter_all::set_has_communication_parameters() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Communication_parameter_all::clear_has_communication_parameters() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline void Communication_parameter_all::clear_communication_parameters() {
+  if (communication_parameters_ != NULL) communication_parameters_->Clear();
+  clear_has_communication_parameters();
+}
+inline const ::Communication_proto::Communication_parameter& Communication_parameter_all::communication_parameters() const {
+  const ::Communication_proto::Communication_parameter* p = communication_parameters_;
+  // @@protoc_insertion_point(field_get:Communication_proto.Communication_parameter_all.communication_parameters)
+  return p != NULL ? *p : *reinterpret_cast<const ::Communication_proto::Communication_parameter*>(
+      &::Communication_proto::_Communication_parameter_default_instance_);
+}
+inline ::Communication_proto::Communication_parameter* Communication_parameter_all::release_communication_parameters() {
+  // @@protoc_insertion_point(field_release:Communication_proto.Communication_parameter_all.communication_parameters)
+  clear_has_communication_parameters();
+  ::Communication_proto::Communication_parameter* temp = communication_parameters_;
+  communication_parameters_ = NULL;
+  return temp;
+}
+inline ::Communication_proto::Communication_parameter* Communication_parameter_all::mutable_communication_parameters() {
+  set_has_communication_parameters();
+  if (communication_parameters_ == NULL) {
+    communication_parameters_ = new ::Communication_proto::Communication_parameter;
+  }
+  // @@protoc_insertion_point(field_mutable:Communication_proto.Communication_parameter_all.communication_parameters)
+  return communication_parameters_;
+}
+inline void Communication_parameter_all::set_allocated_communication_parameters(::Communication_proto::Communication_parameter* communication_parameters) {
+  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+  if (message_arena == NULL) {
+    delete communication_parameters_;
+  }
+  if (communication_parameters) {
+    ::google::protobuf::Arena* submessage_arena = NULL;
+    if (message_arena != submessage_arena) {
+      communication_parameters = ::google::protobuf::internal::GetOwnedMessage(
+          message_arena, communication_parameters, submessage_arena);
+    }
+    set_has_communication_parameters();
+  } else {
+    clear_has_communication_parameters();
+  }
+  communication_parameters_ = communication_parameters;
+  // @@protoc_insertion_point(field_set_allocated:Communication_proto.Communication_parameter_all.communication_parameters)
+}
+
+#ifdef __GNUC__
+  #pragma GCC diagnostic pop
+#endif  // __GNUC__
+// -------------------------------------------------------------------
+
+
+// @@protoc_insertion_point(namespace_scope)
+
+}  // namespace Communication_proto
+
+// @@protoc_insertion_point(global_scope)
+
+#endif  // PROTOBUF_communication_2eproto__INCLUDED

+ 14 - 0
communication/communication.proto

@@ -0,0 +1,14 @@
+syntax = "proto2";
+package Communication_proto;
+
+message Communication_parameter
+{
+    optional string bind_string = 1;
+    repeated string connect_string_vector = 2;
+
+}
+
+message Communication_parameter_all
+{
+    optional Communication_parameter        communication_parameters=1;
+}

+ 91 - 0
communication/communication_message.cpp

@@ -0,0 +1,91 @@
+//
+// Created by huli on 2020/6/29.
+//
+
+#include "communication_message.h"
+
+
+Communication_message::Communication_message()
+{
+	m_message_type = eBase_msg;
+	m_receive_time = std::chrono::system_clock::now();
+	m_timeout_ms = std::chrono::milliseconds(5000);		//超时默认5秒
+	m_sender = eEmpty;
+	m_receiver = eEmpty;
+//	m_message_buf = "";
+}
+
+Communication_message::Communication_message(std::string message_buf)
+{
+	m_message_type = eBase_msg;
+	m_receive_time = std::chrono::system_clock::now();
+	m_timeout_ms = std::chrono::milliseconds(5000);		//超时默认5秒
+	m_sender = eEmpty;
+	m_receiver = eEmpty;
+	m_message_buf = message_buf;
+}
+
+Communication_message::Communication_message(char* p_buf, int size)
+{
+	m_message_type = eBase_msg;
+	m_receive_time = std::chrono::system_clock::now();
+	m_timeout_ms = std::chrono::milliseconds(5000);		//超时默认5秒
+	m_sender = eEmpty;
+	m_receiver = eEmpty;
+	m_message_buf = std::string(p_buf, size);
+}
+
+
+
+Communication_message::~Communication_message()
+{
+
+}
+
+bool Communication_message::is_over_time()
+{
+	std::cout<<"interval: "<<std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now() - m_receive_time).count()<<std::endl;
+	std::cout<<"timeout: "<<m_timeout_ms.count()<<std::endl;
+	if ( std::chrono::system_clock::now() - m_receive_time > m_timeout_ms)
+	{
+	    return true;
+	}
+	else
+	{
+		return false;
+	}
+}
+
+
+void Communication_message::reset(const message::Base_info& base_info, std::string receive_string)
+{
+	m_message_type = (Message_type)(base_info.msg_type());
+
+	m_receive_time = std::chrono::system_clock::now();
+	m_timeout_ms = std::chrono::milliseconds(base_info.timeout_ms());
+	m_sender = (Communicator)(base_info.sender());
+	m_receiver = (Communicator)(base_info.receiver());
+	m_message_buf = receive_string;
+}
+
+Communication_message::Message_type Communication_message::get_message_type()
+{
+	return m_message_type;
+}
+Communication_message::Communicator Communication_message::get_sender()
+{
+	return m_sender;
+}
+Communication_message::Communicator Communication_message::get_receiver()
+{
+	return m_receiver;
+}
+std::string& Communication_message::get_message_buf()
+{
+	return m_message_buf;
+}
+
+
+
+
+

+ 104 - 0
communication/communication_message.h

@@ -0,0 +1,104 @@
+//
+// Created by huli on 2020/6/29.
+//
+
+#ifndef NNXX_TESTS_COMMUNICATION_MESSAGE_H
+#define NNXX_TESTS_COMMUNICATION_MESSAGE_H
+
+#include "../error_code/error_code.h"
+
+#include <time.h>
+#include <sys/time.h>
+#include <chrono>
+//#include <iosfwd>
+
+#include <string>
+#include "../message/message_base.pb.h"
+
+
+class Communication_message
+{
+public:
+	//消息类型定义,每个在网络上传输的消息必须含有这个属性
+	enum Message_type
+	{
+		eBase_msg=0x00,
+		eCommand_msg=0x01,                      //指令消息
+
+		eLocate_status_msg=0x11,                //定位模块状态消息
+		eLocate_request_msg=0x12,               //定位请求消息
+		eLocate_response_msg=0x13,              //定位反馈消息
+
+        eDispatch_status_msg=0x21,                //调度模块硬件状态消息
+        eDispatch_request_msg=0x22,              //请求调度消息
+        eDispatch_response_msg=0x23,             //调度结果反馈消息
+
+        eParkspace_allocation_status_msg = 0x31,   //车位分配模块状态消息,包括车位信息
+        eParkspace_allocation_request_msg = 0x32,  //请求分配车位消息
+        eParkspace_allocation_response_msg = 0x33, //分配车位结果反馈消息
+        eParkspace_search_request_msg = 0x34,    //查询车位请求消息
+        eParkspace_search_response_msg = 0x35,    //查询车位反馈消息
+        eParkspace_release_request_msg = 0x36,    //释放车位请求消息
+        eParkspace_release_response_msg = 0x37,    //释放车位反馈消息
+        eParkspace_force_update_request_msg = 0x38,	//手动修改车位消息
+        eParkspace_force_update_response_msg = 0x39,//手动修改车位反馈消息
+        eParkspace_confirm_alloc_request_msg = 0x3A,//确认分配车位请求消息
+        eParkspace_confirm_alloc_response_msg = 0x3B,//确认分配车位反馈消息
+
+        eStore_command_request_msg=0x41,                    //终端停车请求消息
+        eStore_command_response_msg=0x42,                   //停车请求反馈消息
+        ePickup_command_request_msg=0x43,                   //取车请求消息
+        ePickup_command_response_msg=0x44,                  //取车请求反馈消息
+
+        eStoring_process_statu_msg=0x90,                    //停车进度条消息
+        ePicking_process_statu_msg=0x91,                    //取车进度消息
+
+        eCentral_controller_statu_msg=0xa0,                 //中控状态消息
+
+        eEntrance_manual_operation_msg=0xb0,            //针对出入口状态操作的手动消息
+        eProcess_manual_operation_msg=0xb1,
+	};
+
+	//通讯单元
+	enum Communicator
+	{
+		eEmpty=0x0000,		//空
+		eMain=0x0001,    	//主流程
+		eTerminor=0x0100,	//终端
+		eParkspace=0x0200,		//数据表
+		eMeasurer=0x0300,	//测量单元
+		eProcess=0x0400,	//调度机构
+		//...
+	};
+public:
+	Communication_message();
+	Communication_message(std::string message_buf);
+	Communication_message(char* p_buf, int size);
+	Communication_message(const Communication_message& other)= default;
+	Communication_message& operator =(const Communication_message& other)= default;
+	~Communication_message();
+public://API functions
+	bool is_over_time();
+public://get or set member variable
+	void reset(const message::Base_info& base_info, std::string receive_string);
+
+	Message_type get_message_type();
+	Communicator get_sender();
+	Communicator get_receiver();
+	std::string& get_message_buf();
+
+protected://member variable
+	Message_type								m_message_type;				//消息类型
+	std::chrono::system_clock::time_point		m_receive_time;				//接收消息的时间点
+	std::chrono::milliseconds					m_timeout_ms;				//超时时间, 整个软件都统一为毫秒
+	Communicator								m_sender;					//发送者
+	Communicator								m_receiver;					//接受者
+
+	std::string									m_message_buf;				//消息数据
+
+private:
+
+};
+
+
+#endif //NNXX_TESTS_COMMUNICATION_MESSAGE_H

+ 612 - 0
communication/communication_socket_base.cpp

@@ -0,0 +1,612 @@
+
+
+
+#include "communication_socket_base.h"
+#include "../tool/proto_tool.h"
+
+Communication_socket_base::Communication_socket_base()
+{
+	m_communication_statu = COMMUNICATION_UNKNOW;
+
+	mp_receive_data_thread = NULL;
+	mp_analysis_data_thread = NULL;
+	mp_send_data_thread = NULL;
+	mp_encapsulate_data_thread = NULL;
+
+	m_analysis_cycle_time = 1000;//默认1000ms,就自动解析(接受list)
+	m_encapsulate_cycle_time = 1000;//默认1000ms,就自动发送一次状态信息
+}
+
+Communication_socket_base::~Communication_socket_base()
+{
+	communication_uninit();
+}
+
+//初始化 通信 模块。如下三选一
+Error_manager Communication_socket_base::communication_init()
+{
+	LOG(INFO) << " ---Communication_socket_base::communication_init() run--- "<< this;
+
+	return  communication_init_from_protobuf(COMMUNICATION_PARAMETER_PATH);
+}
+
+//初始化 通信 模块。从文件读取
+Error_manager Communication_socket_base::communication_init_from_protobuf(std::string prototxt_path)
+{
+	Communication_proto::Communication_parameter_all t_communication_parameter_all;
+	if(!  proto_tool::read_proto_param(prototxt_path,t_communication_parameter_all) )
+	{
+		return Error_manager(COMMUNICATION_READ_PROTOBUF_ERROR,MINOR_ERROR,
+		"Communication_socket_base read_proto_param  failed");
+	}
+
+	return communication_init_from_protobuf(t_communication_parameter_all);
+}
+
+//初始化 通信 模块。从protobuf读取
+Error_manager Communication_socket_base::communication_init_from_protobuf(Communication_proto::Communication_parameter_all& communication_parameter_all)
+{
+	LOG(INFO) << " ---Communication_socket_base::communication_init_from_protobuf() run--- "<< this;
+	Error_manager t_error;
+
+	if ( communication_parameter_all.communication_parameters().has_bind_string() )
+	{
+		t_error = communication_bind(communication_parameter_all.communication_parameters().bind_string());
+		if ( t_error != Error_code::SUCCESS )
+		{
+			return t_error;
+		}
+	}
+	std::cout << "communication_parameter_all.communication_parameters().connect_string_vector_size() " <<
+		communication_parameter_all.communication_parameters().connect_string_vector_size()<< std::endl;
+	for(int i=0;i<communication_parameter_all.communication_parameters().connect_string_vector_size();++i)
+	{
+		t_error = communication_connect( communication_parameter_all.communication_parameters().connect_string_vector(i) );
+		if ( t_error != Error_code::SUCCESS )
+		{
+			return t_error;
+		}
+	}
+
+	//启动通信, run thread
+	communication_run();
+
+	return Error_code::SUCCESS;
+}
+
+//初始化
+Error_manager Communication_socket_base::communication_init(std::string bind_string, std::vector<std::string>& connect_string_vector)
+{
+	LOG(INFO) << " ---Communication_socket_base::communication_init() run--- "<< this;
+	Error_manager t_error;
+
+	t_error = communication_bind(bind_string);
+	if ( t_error != Error_code::SUCCESS )
+	{
+		return t_error;
+	}
+
+	t_error = communication_connect(connect_string_vector);
+	if ( t_error != Error_code::SUCCESS )
+	{
+		return t_error;
+	}
+
+	//启动通信, run thread
+	communication_run();
+
+	return Error_code::SUCCESS;
+}
+//bind
+Error_manager Communication_socket_base::communication_bind(std::string bind_string)
+{
+	Error_manager t_error;
+	int t_socket_result;
+
+	//m_socket 自己作为一个服务器, 绑定一个端口
+	t_socket_result = m_socket.bind(bind_string);
+	if ( t_socket_result <0 )
+	{
+		return Error_manager(Error_code::COMMUNICATION_BIND_ERROR, Error_level::MINOR_ERROR,
+							 " m_socket.bind error ");
+	}
+	LOG(INFO) << " ---Communication_socket_base::communication_bind() bind::  "<< bind_string << "  " << this;
+
+	return Error_code::SUCCESS;
+}
+//connect
+Error_manager Communication_socket_base::communication_connect(std::vector<std::string>& connect_string_vector)
+{
+	Error_manager t_error;
+	for (auto iter = connect_string_vector.begin(); iter != connect_string_vector.end(); ++iter)
+	{
+		t_error = communication_connect(*iter);
+		if ( t_error != Error_code::SUCCESS )
+		{
+			return t_error;
+		}
+	}
+	return Error_code::SUCCESS;
+}
+//connect
+Error_manager Communication_socket_base::communication_connect(std::string connect_string)
+{
+	Error_manager t_error;
+	int t_socket_result;
+	//m_socket 和远端通信, 连接远端服务器的端口
+	t_socket_result = m_socket.connect(connect_string);
+	if ( t_socket_result <0 )
+	{
+		return Error_manager(Error_code::COMMUNICATION_CONNECT_ERROR, Error_level::MINOR_ERROR,
+							 " m_socket.connect error ");
+	}
+	LOG(INFO) << " ---Communication_socket_base::communication_connect() connect::  "<< connect_string << "  " << this;
+
+	return Error_code::SUCCESS;
+}
+//启动通信, run thread
+Error_manager Communication_socket_base::communication_run()
+{
+	m_communication_statu = COMMUNICATION_READY;
+	//启动4个线程。
+	//接受线程默认循环, 内部的nn_recv进行等待, 超时1ms
+	m_receive_condition.reset(false, false, false);
+	mp_receive_data_thread = new std::thread(&Communication_socket_base::receive_data_thread, this);
+	//解析线程默认等待, 需要接受线程去唤醒, 超时1ms, 超时后主动遍历m_receive_data_list
+	m_analysis_data_condition.reset(false, false, false);
+	mp_analysis_data_thread = new std::thread(&Communication_socket_base::analysis_data_thread, this);
+	//发送线程默认循环, 内部的wait_and_pop进行等待,
+	m_send_data_condition.reset(false, true, false);
+	mp_send_data_thread = new std::thread(&Communication_socket_base::send_data_thread, this);
+	//封装线程默认等待, ...., 超时1ms, 超时后主动 封装心跳和状态信息,
+	m_encapsulate_data_condition.reset(false, false, false);
+	mp_encapsulate_data_thread = new std::thread(&Communication_socket_base::encapsulate_data_thread, this);
+
+	return Error_code::SUCCESS;
+}
+
+
+//反初始化 通信 模块。
+Error_manager Communication_socket_base::communication_uninit()
+{
+	//终止list,防止 wait_and_pop 阻塞线程。
+	m_receive_data_list.termination_list();
+	m_send_data_list.termination_list();
+
+	//杀死4个线程,强制退出
+	if (mp_receive_data_thread)
+	{
+		m_receive_condition.kill_all();
+	}
+	if (mp_analysis_data_thread)
+	{
+		m_analysis_data_condition.kill_all();
+	}
+	if (mp_send_data_thread)
+	{
+		m_send_data_condition.kill_all();
+	}
+	if (mp_encapsulate_data_thread)
+	{
+		m_encapsulate_data_condition.kill_all();
+	}
+	//回收4个线程的资源
+	if (mp_receive_data_thread)
+	{
+		mp_receive_data_thread->join();
+		delete mp_receive_data_thread;
+		mp_receive_data_thread = NULL;
+	}
+	if (mp_analysis_data_thread)
+	{
+		mp_analysis_data_thread->join();
+		delete mp_analysis_data_thread;
+		mp_analysis_data_thread = 0;
+	}
+	if (mp_send_data_thread)
+	{
+		mp_send_data_thread->join();
+		delete mp_send_data_thread;
+		mp_send_data_thread = NULL;
+	}
+	if (mp_encapsulate_data_thread)
+	{
+		mp_encapsulate_data_thread->join();
+		delete mp_encapsulate_data_thread;
+		mp_encapsulate_data_thread = NULL;
+	}
+
+	//清空list
+	m_receive_data_list.clear_and_delete();
+	m_send_data_list.clear_and_delete();
+
+	m_communication_statu = COMMUNICATION_UNKNOW;
+	m_socket.close();
+
+	return Error_code::SUCCESS;
+}
+
+
+void Communication_socket_base::set_analysis_cycle_time(unsigned int analysis_cycle_time)
+{
+	m_analysis_cycle_time = analysis_cycle_time;
+}
+void Communication_socket_base::set_encapsulate_cycle_time(unsigned int encapsulate_cycle_time)
+{
+	m_encapsulate_cycle_time = encapsulate_cycle_time;
+}
+
+
+
+
+//mp_receive_data_thread 接受线程执行函数,
+//receive_data_thread 内部线程负责接受消息
+void Communication_socket_base::receive_data_thread()
+{
+	LOG(INFO) << " Communication_socket_base::receive_data_thread start "<< this;
+
+	//通信接受线程, 负责接受socket消息, 并存入 m_receive_data_list
+	while (m_receive_condition.is_alive())
+	{
+		m_receive_condition.wait_for_ex(std::chrono::microseconds(1));
+		if ( m_receive_condition.is_alive() )
+		{
+			std::this_thread::yield();
+
+			std::string t_receive_string;
+			{//这个大括号表示只对 recv 和 send 加锁, 不要因为后面的复杂逻辑影响通信效率
+				std::unique_lock<std::mutex> lk(m_mutex);
+				//flags为1, 非阻塞接受消息, 如果接收到消息, 那么接受数据长度大于0
+				t_receive_string = m_socket.recv<std::string>(1);
+			}
+			if ( t_receive_string.size()>0 )
+			{
+				//如果这里接受到了消息, 在这提前解析消息最前面的Base_msg (消息公共内容), 用于后续的check
+				message::Base_msg t_base_msg;
+				if( t_base_msg.ParseFromString(t_receive_string) )
+				{
+					//第一次解析之后转化为, Communication_message, 自定义的通信消息格式
+					Communication_message  * tp_communication_message = new Communication_message;
+					tp_communication_message->reset(t_base_msg.base_info(), t_receive_string);
+					//检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
+					if ( check_msg(tp_communication_message) == SUCCESS )
+					{
+						bool is_push = m_receive_data_list.push(tp_communication_message);
+						//push成功之后, tp_communication_message内存的管理权限交给链表, 如果失败就要回收内存
+						if ( is_push )
+						{
+							//唤醒解析线程一次,
+							m_analysis_data_condition.notify_all(false, true);
+						}
+						else
+						{
+//						push失败, 就要回收内存
+							delete(tp_communication_message);
+							tp_communication_message = NULL;
+//					return Error_manager(Error_code::CONTAINER_IS_TERMINATE, Error_level::MINOR_ERROR,
+//										 " m_receive_data_list.push error ");
+						}
+					}
+					else
+					{
+						delete(tp_communication_message);
+						tp_communication_message = NULL;
+					}
+
+
+				}
+				//解析失败, 就当做什么也没发生, 认为接收消息无效,
+			}
+			//没有接受到消息, 返回空字符串
+		}
+	}
+
+	LOG(INFO) << " Communication_socket_base::receive_data_thread end "<< this;
+	return;
+}
+
+//检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
+Error_manager Communication_socket_base::check_msg(Communication_message*  p_msg)
+{
+	//通过 p_msg->get_message_type() 和 p_msg->get_receiver() 判断这条消息是不是给我的.
+	//子类重载时, 增加自己模块的判断逻辑, 以后再写.
+	if ( p_msg->get_message_type() == Communication_message::Message_type::eBase_msg
+		 && p_msg->get_receiver() == Communication_message::Communicator::eMain )
+	{
+		return Error_code::SUCCESS;
+	}
+	else
+	{
+		//无效的消息,
+		return Error_code::INVALID_MESSAGE;
+	}
+}
+
+//mp_analysis_data_thread 解析线程执行函数,
+//analysis_data_thread 内部线程负责解析消息
+void Communication_socket_base::analysis_data_thread()
+{
+	LOG(INFO) << " Communication_socket_base::analysis_data_thread start "<< this;
+
+	//通信解析线程, 负责巡检m_receive_data_list, 并解析和处理消息
+	while (m_analysis_data_condition.is_alive())
+	{
+		bool t_pass_flag = m_analysis_data_condition.wait_for_millisecond(m_analysis_cycle_time);
+		if ( m_analysis_data_condition.is_alive() )
+		{
+			std::this_thread::yield();
+			//如果解析线程被主动唤醒, 那么就表示 收到新的消息, 那就遍历整个链表
+			if ( t_pass_flag )
+			{
+				analysis_receive_list();
+			}
+				//如果解析线程超时通过, 那么就定时处理链表残留的消息,
+			else
+			{
+				analysis_receive_list();
+			}
+		}
+	}
+
+	LOG(INFO) << " Communication_socket_base::analysis_data_thread end "<< this;
+	return;
+}
+
+//循环接受链表, 解析消息,
+Error_manager Communication_socket_base::analysis_receive_list()
+{
+	Error_manager t_error;
+	if ( m_receive_data_list.m_termination_flag )
+	{
+		return Error_manager(Error_code::CONTAINER_IS_TERMINATE, Error_level::MINOR_ERROR,
+							 " Communication_socket_base::analysis_receive_list error ");
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_receive_data_list.m_mutex);
+		for (auto iter = m_receive_data_list.m_data_list.begin(); iter != m_receive_data_list.m_data_list.end(); )
+		{
+			Communication_message* tp_msg = **iter;
+			if ( tp_msg == NULL )
+			{
+				iter = m_receive_data_list.m_data_list.erase(iter);
+				//注:erase 删除当前 iter 之后返回下一个节点,当前的 iter 无效化,
+			}
+			else
+			{
+				//检查消息是否可以被处理
+				t_error = check_executer(tp_msg);
+				if ( t_error == SUCCESS)
+				{
+					//处理消息
+					t_error = execute_msg(tp_msg);
+//				if ( t_error )
+//				{
+//					//执行结果不管
+//				}
+//				else
+//				{
+//					//执行结果不管
+//				}
+					delete(tp_msg);
+					tp_msg = NULL;
+					iter = m_receive_data_list.m_data_list.erase(iter);
+					//注:erase 删除当前 iter 之后返回下一个节点,当前的 iter 无效化,
+				}
+				else if( t_error == COMMUNICATION_EXCUTER_IS_BUSY)
+				{
+					//处理器正忙, 那就不做处理, 直接处理下一个
+					//注:这条消息就被保留了下来, wait_for_millisecond 超时通过之后, 会循环检查残留的消息.
+					iter++;
+				}
+				else //if( t_error == COMMUNICATION_ANALYSIS_TIME_OUT )
+				{
+					//超时了就直接删除
+					delete(tp_msg);
+					tp_msg = NULL;
+					iter = m_receive_data_list.m_data_list.erase(iter);
+					//注:erase 删除当前 iter 之后返回下一个节点,当前的 iter 无效化,
+
+					//注:消息删除之后, 不需要发送答复消息, 发送方也会有超时处理的,  只有 execute_msg 里面可以答复消息
+				}
+			}
+		}
+	}
+	return Error_code::SUCCESS;
+}
+
+
+
+//检查执行者的状态, 判断能否处理这条消息, 需要子类重载
+Error_manager Communication_socket_base::check_executer(Communication_message*  p_msg)
+{
+	//检查对应模块的状态, 判断是否可以处理这条消息
+	//同时也要判断是否超时, 超时返回 COMMUNICATION_ANALYSIS_TIME_OUT
+	//如果处理器正在忙别的, 那么返回 COMMUNICATION_EXCUTER_IS_BUSY
+
+	if ( p_msg->is_over_time() )
+	{
+		std::cout << "Communication_socket_base::check_msg  p_buf =  " << p_msg->get_message_buf() << std::endl;
+		std::cout << "Communication_socket_base::check_msg   size =  " << p_msg->get_message_buf().size() << std::endl;
+		std::cout << "COMMUNICATION_ANALYSIS_TIME_OUT , " << std::endl;
+		return Error_code::COMMUNICATION_ANALYSIS_TIME_OUT;
+	}
+	else
+	{
+		bool executer_is_ready = false;
+		//通过 p_msg->get_message_type() 和 p_msg->get_receiver() 找到处理模块的实例对象, 查询执行人是否可以处理这条消息
+		//这里子类重载时, 增加判断逻辑, 以后再写.
+		executer_is_ready = true;
+
+		std::cout << "Communication_socket_base::check_msg  p_buf =  " << p_msg->get_message_buf() << std::endl;
+		std::cout << "Communication_socket_base::check_msg   size =  " << p_msg->get_message_buf().size() << std::endl;
+
+		if ( executer_is_ready )
+		{
+			std::cout << "executer_is_ready , " << std::endl;
+			return Error_code::SUCCESS;
+		}
+		else
+		{
+			std::cout << "executer_is_busy , " << std::endl;
+			return Error_code::COMMUNICATION_EXCUTER_IS_BUSY;
+		}
+	}
+
+	return Error_code::SUCCESS;
+}
+
+//处理消息
+Error_manager Communication_socket_base::execute_msg(Communication_message*  p_msg)
+{
+	//先将 p_msg 转化为 对应的格式, 使用对应模块的protobuf来二次解析
+	// 不能一直使用 Communication_message*  p_msg, 这个是要销毁的
+	//然后处理这个消息, 就是调用对应模块的 execute 接口函数
+	//执行结果不管, 如果需要答复, 那么对应模块 在自己内部 封装一条消息发送即可.
+	//子类重载, 需要完全重写, 以后再写.
+
+	//注注注注注意了, 本模块只是用来做通信,
+	//在做处理消息的时候, 可能会调用执行者的接口函数,
+	//这里不应该长时间阻塞或者处理复杂的逻辑,
+	//请执行者另开线程来处理任务.
+
+	std::cout << "Communication_socket_base::excute_msg  p_buf =  " << p_msg->get_message_buf() << std::endl;
+	std::cout << "Communication_socket_base::excute_msg   size =  " << p_msg->get_message_buf().size() << std::endl;
+	return Error_code::SUCCESS;
+}
+
+//mp_send_data_thread 发送线程执行函数,
+//send_data_thread 内部线程负责发送消息
+void Communication_socket_base::send_data_thread()
+{
+	LOG(INFO) << " Communication_socket_base::send_data_thread start "<< this;
+
+	//通信发送线程, 负责巡检m_send_data_list, 并发送消息
+	while (m_send_data_condition.is_alive())
+	{
+		m_send_data_condition.wait();
+		if ( m_send_data_condition.is_alive() )
+		{
+			std::this_thread::yield();
+
+			Communication_message* tp_msg = NULL;
+			//这里 wait_and_pop 会使用链表内部的 m_data_cond 条件变量来控制等待,
+			//封装线程使用push的时候, 会唤醒线程并通过等待, 此时 m_send_data_condition 是一直通过的.
+			//如果需要退出, 那么就要 m_send_data_list.termination_list();	和 m_send_data_condition.kill_all();
+			bool is_pop = m_send_data_list.wait_and_pop(tp_msg);
+			if ( is_pop )
+			{
+				if ( tp_msg != NULL )
+				{
+					{//这个大括号表示只对 recv 和 send 加锁, 不要因为后面的复杂逻辑影响通信效率
+						std::unique_lock<std::mutex> lk(m_mutex);
+						m_socket.send(tp_msg->get_message_buf());
+					}
+					delete(tp_msg);
+					tp_msg = NULL;
+				}
+			}
+			else
+			{
+				//没有取出, 那么应该就是 m_termination_flag 结束了
+//				return Error_manager(Error_code::CONTAINER_IS_TERMINATE, Error_level::MINOR_ERROR,
+//									 " Communication_socket_base::send_data_thread() error ");
+			}
+		}
+	}
+
+	LOG(INFO) << " Communication_socket_base::send_data_thread end "<< this;
+	return;
+}
+
+//mp_encapsulate_data_thread 封装线程执行函数,
+//encapsulate_data_thread 内部线程负责封装消息
+void Communication_socket_base::encapsulate_data_thread()
+{
+	LOG(INFO) << " Communication_socket_base::encapsulate_data_thread start "<< this;
+
+	//通信封装线程, 负责定时封装消息, 并存入 m_send_data_list
+	while (m_encapsulate_data_condition.is_alive())
+	{
+		bool t_pass_flag = m_encapsulate_data_condition.wait_for_millisecond(m_encapsulate_cycle_time);
+
+		if ( m_encapsulate_data_condition.is_alive() )
+		{
+			std::this_thread::yield();
+			//如果封装线程被主动唤醒, 那么就表示 需要主动发送消息,
+			if ( t_pass_flag )
+			{
+				//主动发送消息,
+			}
+				//如果封装线程超时通过, 那么就定时封装心跳和状态信息
+			else
+			{
+				encapsulate_send_data();
+			}
+		}
+	}
+
+	LOG(INFO) << " Communication_socket_base::encapsulate_data_thread end "<< this;
+	return;
+}
+
+
+//定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
+Error_manager Communication_socket_base::encapsulate_send_data()
+{
+//	char buf[256] = {0};
+//	static unsigned int t_heartbeat = 0;
+//	sprintf(buf, "Communication_socket_base, heartbeat = %d\0\0\0, test\0", t_heartbeat);
+//	t_heartbeat++;
+    return SUCCESS;
+	message::Base_msg t_base_msg;
+	t_base_msg.mutable_base_info()->set_msg_type(message::Message_type::eBase_msg);
+	t_base_msg.mutable_base_info()->set_timeout_ms(5000);
+	t_base_msg.mutable_base_info()->set_sender(message::Communicator::eMain);
+	t_base_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
+
+	Communication_message* tp_msg = new Communication_message(t_base_msg.SerializeAsString());
+	bool is_push = m_send_data_list.push(tp_msg);
+	if ( is_push == false )
+	{
+		delete(tp_msg);
+		tp_msg = NULL;
+		return Error_manager(Error_code::CONTAINER_IS_TERMINATE, Error_level::MINOR_ERROR,
+							 " Communication_socket_base::encapsulate_msg error ");
+	}
+	return Error_code::SUCCESS;
+}
+
+
+
+//封装消息, 需要子类重载
+Error_manager Communication_socket_base::encapsulate_msg(std::string message)
+{
+	Communication_message* tp_msg = new Communication_message(message);
+	bool is_push = m_send_data_list.push(tp_msg);
+	if ( is_push == false )
+	{
+		delete(tp_msg);
+		tp_msg = NULL;
+		return Error_manager(Error_code::CONTAINER_IS_TERMINATE, Error_level::MINOR_ERROR,
+							 " Communication_socket_base::encapsulate_msg error ");
+	}
+	return Error_code::SUCCESS;
+}
+
+//封装消息, 需要子类重载
+Error_manager Communication_socket_base::encapsulate_msg(Communication_message* p_msg)
+{
+	Communication_message* tp_msg = new Communication_message(*p_msg);
+	bool is_push = m_send_data_list.push(tp_msg);
+	if ( is_push == false )
+	{
+		delete(tp_msg);
+		tp_msg = NULL;
+		return Error_manager(Error_code::CONTAINER_IS_TERMINATE, Error_level::MINOR_ERROR,
+							 " Communication_socket_base::encapsulate_msg error ");
+	}
+	return Error_code::SUCCESS;
+}
+
+

+ 165 - 0
communication/communication_socket_base.h

@@ -0,0 +1,165 @@
+
+
+/*
+ * communication_socket_base 通信模块的基类,
+ * 用户从这个基类继承, 初始化之后, 便可以自动进行通信
+ * 重载解析消息和封装消息,
+ *
+ *Thread_safe_list<Binary_buf*> 使用 Binary_buf , 而不是string
+ * 主要是为了支持直接发送数字0
+ * 
+ * 
+ * */
+
+#ifndef __COMMUNICATION_SOCKET_BASE__HH__
+#define __COMMUNICATION_SOCKET_BASE__HH__
+
+
+#include <nnxx/message>
+#include <nnxx/socket.h>
+#include <nnxx/bus.h>
+
+#include <glog/logging.h>
+#include "../error_code/error_code.h"
+#include "../tool/binary_buf.h"
+#include "../tool/thread_safe_list.h"
+#include "../tool/thread_condition.h"
+
+#include "../communication/communication.pb.h"
+#include "../communication/communication_message.h"
+
+#include "../message/message_base.pb.h"
+//#include "../message/measure_message.pb.h"
+
+
+
+#define COMMUNICATION_PARAMETER_PATH "../setting/communication.prototxt"
+
+class Communication_socket_base
+{
+	//通信状态
+	enum Communication_statu
+	{
+		COMMUNICATION_UNKNOW		=0,	        //通信状态 未知
+		COMMUNICATION_READY			=1,			//通信状态 正常
+
+		COMMUNICATION_FAULT			=3,         //通信状态 错误
+	};
+
+public:
+	Communication_socket_base();
+	Communication_socket_base(const Communication_socket_base& other)= delete;
+	Communication_socket_base& operator =(const Communication_socket_base& other)= delete;
+	~Communication_socket_base();
+public://API functions
+	//初始化 通信 模块。如下三选一
+	virtual Error_manager communication_init();
+	//初始化 通信 模块。从文件读取
+	Error_manager communication_init_from_protobuf(std::string prototxt_path);
+	//初始化 通信 模块。从protobuf读取
+	Error_manager communication_init_from_protobuf(Communication_proto::Communication_parameter_all& communication_parameter_all);
+
+	//初始化
+	virtual Error_manager communication_init(std::string bind_string, std::vector<std::string>& connect_string_vector);
+	//bind
+	virtual Error_manager communication_bind(std::string bind_string);
+	//connect
+	virtual Error_manager communication_connect(std::vector<std::string>& connect_string_vector);
+	//connect
+	virtual Error_manager communication_connect(std::string connect_string);
+	//启动通信, run thread
+	virtual Error_manager communication_run();
+
+	//反初始化 通信 模块。
+	virtual Error_manager communication_uninit();
+	
+	
+public://get or set member variable
+	void set_analysis_cycle_time(unsigned int analysis_cycle_time);
+	void set_encapsulate_cycle_time(unsigned int encapsulate_cycle_time);
+
+protected:
+	//mp_receive_data_thread 接受线程执行函数,
+	//receive_data_thread 内部线程负责接受消息
+	void receive_data_thread();
+
+	//检查消息是否有效, 主要检查消息类型和接受者, 判断这条消息是不是给我的.
+	virtual Error_manager check_msg(Communication_message* p_msg);
+
+	//mp_analysis_data_thread 解析线程执行函数,
+	//analysis_data_thread 内部线程负责解析消息
+	void analysis_data_thread();
+
+	//遍历接受链表, 解析消息,
+	Error_manager analysis_receive_list();
+
+	//检查执行者的状态, 判断能否处理这条消息, 需要子类重载
+	virtual Error_manager check_executer(Communication_message* p_msg);
+
+	//处理消息, 需要子类重载
+	virtual Error_manager execute_msg(Communication_message* p_msg);
+
+	//mp_send_data_thread 发送线程执行函数,
+	//send_data_thread 内部线程负责发送消息
+	void send_data_thread();
+
+	//mp_encapsulate_data_thread 封装线程执行函数,
+	//encapsulate_data_thread 内部线程负责封装消息
+	void encapsulate_data_thread();
+
+	//定时封装发送消息, 一般为心跳和状态信息, 需要子类重载
+	virtual Error_manager encapsulate_send_data();
+
+public:
+	//封装消息, 需要子类重载
+	virtual Error_manager encapsulate_msg(std::string message);
+	//封装消息, 需要子类重载
+	virtual Error_manager encapsulate_msg(Communication_message* p_msg);
+
+protected://member variable
+
+	//通用的网络编程接口, 默认使用总线模式, (网状结构)
+	nnxx::socket 						m_socket { nnxx::SP, nnxx::BUS };
+	std::mutex 							m_mutex;				//m_socket的锁
+
+	//通信状态
+	Communication_statu 				m_communication_statu;			//通信状态
+
+	//接受模块,
+	Thread_safe_list<Communication_message*>		m_receive_data_list; 			//接受的list容器
+	std::thread*						mp_receive_data_thread;    		//接受的线程指针
+	Thread_condition					m_receive_condition;			//接受的条件变量
+	std::thread*						mp_analysis_data_thread;    	//解析的线程指针
+	Thread_condition					m_analysis_data_condition;		//解析的条件变量
+	unsigned int 						m_analysis_cycle_time;			//自动解析的时间周期
+
+	//发送模块,
+	Thread_safe_list<Communication_message*>		m_send_data_list;				//发送的list容器
+	std::thread*						mp_send_data_thread;    		//发送的线程指针
+	Thread_condition					m_send_data_condition;			//发送的条件变量
+	std::thread*						mp_encapsulate_data_thread;    	//封装的线程指针
+	Thread_condition					m_encapsulate_data_condition;	//封装的条件变量
+	unsigned int 						m_encapsulate_cycle_time;		//自动封装的时间周期
+
+
+
+private:
+
+};
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif //__COMMUNICATION_SOCKET_BASE__HH__

+ 537 - 0
error_code/error_code.cpp

@@ -0,0 +1,537 @@
+
+//Error_code是错误码的底层通用模块,
+//功能:用作故障分析和处理。
+
+//用法:所有的功能接口函数return错误管理类,
+//然后上层判断分析错误码,并进行故障处理。
+
+
+
+#include "error_code.h"
+
+/////////////////////////////////////////////
+//构造函数
+Error_manager::Error_manager()
+{
+    m_error_code = SUCCESS;
+    m_error_level = NORMAL;
+    pm_error_description = 0;
+    m_description_length = 0;
+    return ;
+}
+//拷贝构造
+Error_manager::Error_manager(const Error_manager & error_manager)
+{
+    this->m_error_code = error_manager.m_error_code;
+    this->m_error_level = error_manager.m_error_level;
+    pm_error_description = NULL;
+    m_description_length = 0;
+    reallocate_memory_and_copy_string(error_manager.pm_error_description, error_manager.m_description_length);
+    return ;
+}
+//赋值构造
+Error_manager::Error_manager(Error_code error_code, Error_level error_level,
+    const char* p_error_description, int description_length)
+{
+    m_error_code = error_code;
+    m_error_level = error_level;
+    pm_error_description = NULL;
+    m_description_length = 0;
+    reallocate_memory_and_copy_string(p_error_description, description_length);
+    return ;
+}
+//赋值构造
+Error_manager::Error_manager(Error_code error_code, Error_level error_level , std::string & error_aggregate_string)
+{
+    m_error_code = error_code;
+    m_error_level = error_level;
+    pm_error_description = NULL;
+    m_description_length = 0;
+    reallocate_memory_and_copy_string(error_aggregate_string);
+    return ;
+}
+//析构函数
+Error_manager::~Error_manager()
+{
+    free_description();
+}
+
+//初始化
+void Error_manager::error_manager_init()
+{
+    error_manager_clear_all();
+    return;
+}
+//初始化
+void Error_manager::error_manager_init(Error_code error_code, Error_level error_level, const char* p_error_description, int description_length)
+{
+    m_error_code = error_code;
+    m_error_level = error_level;
+    reallocate_memory_and_copy_string(p_error_description, description_length);
+    return ;
+}
+//初始化
+void Error_manager::error_manager_init(Error_code error_code, Error_level error_level , std::string & error_aggregate_string)
+{
+    m_error_code = error_code;
+    m_error_level = error_level;
+    reallocate_memory_and_copy_string(error_aggregate_string);
+    return ;
+}
+//重置
+void Error_manager::error_manager_reset(Error_code error_code, Error_level error_level, const char* p_error_description, int description_length)
+{
+    m_error_code = error_code;
+    m_error_level = error_level;
+    reallocate_memory_and_copy_string(p_error_description, description_length);
+    return ;
+}
+//重置
+void Error_manager::error_manager_reset(Error_code error_code, Error_level error_level , std::string & error_aggregate_string)
+{
+    m_error_code = error_code;
+    m_error_level = error_level;
+    reallocate_memory_and_copy_string(error_aggregate_string);
+    return ;
+}
+//重置
+void Error_manager::error_manager_reset(const Error_manager & error_manager)
+{
+    this->m_error_code = error_manager.m_error_code;
+    this->m_error_level = error_manager.m_error_level;
+    reallocate_memory_and_copy_string(error_manager.pm_error_description, error_manager.m_description_length);
+    return ;
+}
+//清除所有内容
+void Error_manager::error_manager_clear_all()
+{
+    m_error_code = SUCCESS;
+    m_error_level = NORMAL;
+    free_description();
+}
+
+//重载=
+Error_manager& Error_manager::operator=(const Error_manager & error_manager)
+{
+    error_manager_reset(error_manager);
+}
+//重载=,支持Error_manager和Error_code的直接转化,会清空错误等级和描述
+Error_manager& Error_manager::operator=(Error_code error_code)
+{
+    error_manager_clear_all();
+    set_error_code(error_code);
+}
+//重载==
+bool Error_manager::operator==(const Error_manager & error_manager)
+{
+    is_equal_error_manager(error_manager);
+}
+//重载==,支持Error_manager和Error_code的直接比较
+bool Error_manager::operator==(Error_code error_code)
+{
+    if(m_error_code == error_code)
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+
+//重载!=
+bool Error_manager::operator!=(const Error_manager & error_manager)
+{
+    ! is_equal_error_manager(error_manager);
+}
+//重载!=,支持Error_manager和Error_code的直接比较
+bool Error_manager::operator!=(Error_code error_code)
+{
+    if(m_error_code != error_code)
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+//重载<<,支持cout<<
+std::ostream & operator<<(std::ostream &out, Error_manager &error_manager)
+{
+	out << error_manager.to_string();
+	return out;
+}
+
+//获取错误码
+Error_code Error_manager::get_error_code()
+{
+    return m_error_code;
+}
+//获取错误等级
+Error_level Error_manager::get_error_level()
+{
+    return m_error_level;
+}
+//获取错误描述的指针,(浅拷贝)
+char* Error_manager::get_error_description()
+{
+    return pm_error_description;
+}
+
+int Error_manager::get_description_length()
+{
+	return m_description_length;
+}
+
+//复制错误描述,(深拷贝)
+//output:p_error_description     错误描述的字符串指针,不可以为NULL,必须要有实际的内存
+//output:description_length      错误描述的字符串长度,不可以为0,长度最好足够大,一般256即可。
+void Error_manager::copy_error_description(const char* p_error_description, int description_length)
+{
+    if(p_error_description != NULL && pm_error_description != NULL)
+    {
+        char *pt_source = (char *)p_error_description;
+        char* pt_destination = pm_error_description;
+
+        int t_length_min = m_description_length;
+        if(m_description_length > description_length)
+        {
+            t_length_min = description_length;
+        }
+
+        for(int i=0;i<t_length_min; i++)
+        {
+            *pt_destination = *pt_source;
+            pt_destination++;
+            pt_source++;
+        }
+    }
+
+    return;
+}
+//复制错误描述,(深拷贝)
+//output:error_description_string     错误描述的string
+void Error_manager::copy_error_description(std::string & error_description_string)
+{
+    if( (!error_description_string.empty() ) && pm_error_description != NULL)
+    {
+        error_description_string = pm_error_description;
+    }
+    return;
+}
+
+//设置错误码
+void Error_manager::set_error_code(Error_code error_code)
+{
+    m_error_code = error_code;
+    return;
+}
+//比较错误等级并升级,取高等级的结果
+void Error_manager::set_error_level_up(Error_level error_level)
+{
+    if(m_error_level < error_level)
+    {
+        m_error_level = error_level;
+    }
+    return;
+}
+//比较错误等级并降级,取低等级的结果
+void Error_manager::set_error_level_down(Error_level error_level)
+{
+    if(m_error_level > error_level)
+    {
+        m_error_level = error_level;
+    }
+    return;
+}
+//错误等级,设定到固定值
+void Error_manager::set_error_level_location(Error_level error_level)
+{
+    m_error_level = error_level;
+    return;
+}
+//设置错误描述
+void Error_manager::set_error_description(const char* p_error_description, int description_length)
+{
+    reallocate_memory_and_copy_string(p_error_description, description_length);
+    return ;
+}
+//设置错误描述
+void Error_manager::set_error_description(std::string & error_description_string)
+{
+    reallocate_memory_and_copy_string(error_description_string);
+    return ;
+}
+
+//尾部追加错误描述
+void Error_manager::add_error_description(const char* p_error_description, int description_length)
+{
+    if(p_error_description !=NULL)
+    {
+        char* pt_description_front = pm_error_description;
+        int t_description_front_length = m_description_length;
+        char* pt_description_back = (char *)p_error_description;
+        int t_description_back_length = 0;
+
+        if(description_length == 0)
+        {
+            t_description_back_length = 0;
+            while (*pt_description_back != '\0')
+            {
+                t_description_back_length++;
+                pt_description_back++;
+            }
+            t_description_back_length++;
+            pt_description_back = (char *)p_error_description;
+        }
+        else
+        {
+            t_description_back_length = description_length;
+        }
+
+        int t_description_new_length = t_description_front_length + 5 + t_description_back_length - 1;
+        char* pt_description_new =  (char*) malloc(t_description_new_length );
+
+        sprintf(pt_description_new, "%s ### %s", pt_description_front, pt_description_back);
+        free_description();
+        pm_error_description = pt_description_new;
+        m_description_length = t_description_new_length;
+    }
+    return ;
+}
+//尾部追加错误描述
+void Error_manager::add_error_description(std::string & error_description_string)
+{
+    if( ! error_description_string.empty() )
+    {
+        std::string t_description_string = pm_error_description ;
+        t_description_string += (" ### "+ error_description_string);
+
+        reallocate_memory_and_copy_string(t_description_string);
+    }
+}
+
+//比较错误是否相同,
+// 注:只比较错误码和等级
+bool Error_manager::is_equal_error_manager(const Error_manager & error_manager)
+{
+    if(this->m_error_code == error_manager.m_error_code
+       && this->m_error_level == error_manager.m_error_level)
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
+}
+//比较并覆盖错误,讲低级错误转为字符串存放于描述中,
+//如果错误相同,则保留this的,将输入参数转入描述。
+void Error_manager::compare_and_cover_error(const Error_manager & error_manager)
+{
+    if(this->m_error_code == SUCCESS)
+    {
+        error_manager_reset(error_manager);
+    }
+    else if (error_manager.m_error_code == SUCCESS)
+    {
+		return;
+    }
+    else
+    {
+        Error_manager t_error_manager_new;
+        char* pt_string_inside = NULL;
+        int t_string_inside_length = 0;
+        if(this->m_error_level < error_manager.m_error_level)
+        {
+            t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + this->m_description_length;
+            pt_string_inside = (char*)malloc(t_string_inside_length);
+            translate_error_to_string(pt_string_inside, t_string_inside_length);
+
+            error_manager_reset(error_manager);
+            add_error_description(pt_string_inside,t_string_inside_length);
+        }
+        else
+        {
+            t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + error_manager.m_description_length;
+            pt_string_inside = (char*)malloc(t_string_inside_length);
+			((Error_manager & )error_manager).translate_error_to_string(pt_string_inside, t_string_inside_length);
+
+            add_error_description(pt_string_inside,t_string_inside_length);
+        }
+    }
+}
+//比较并覆盖错误,讲低级错误转为字符串存放于描述中,
+//如果错误相同,则保留this的,将输入参数转入描述。
+void Error_manager::compare_and_cover_error( Error_manager * p_error_manager)
+{
+	if(this->m_error_code == SUCCESS)
+	{
+		error_manager_reset(*p_error_manager);
+	}
+	else if (p_error_manager->m_error_code == SUCCESS)
+	{
+		//
+	}
+	else
+	{
+		Error_manager t_error_manager_new;
+		char* pt_string_inside = NULL;
+		int t_string_inside_length = 0;
+		if(this->m_error_level < p_error_manager->m_error_level)
+		{
+			t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + this->m_description_length;
+			pt_string_inside = (char*)malloc(t_string_inside_length);
+			translate_error_to_string(pt_string_inside, t_string_inside_length);
+
+			error_manager_reset(*p_error_manager);
+			add_error_description(pt_string_inside,t_string_inside_length);
+		}
+		else
+		{
+			t_string_inside_length = ERROR_NAMAGER_TO_STRING_FRONT_LENGTH + p_error_manager->m_description_length;
+			pt_string_inside = (char*)malloc(t_string_inside_length);
+			p_error_manager->translate_error_to_string(pt_string_inside, t_string_inside_length);
+
+			add_error_description(pt_string_inside,t_string_inside_length);
+		}
+	}
+}
+
+//将所有的错误信息,格式化为字符串,用作日志打印。
+//output:p_error_description     错误汇总的字符串指针,不可以为NULL,必须要有实际的内存
+//output:description_length      错误汇总的字符串长度,不可以为0,长度最好足够大,一般256即可。
+void Error_manager::translate_error_to_string(char* p_error_aggregate, int aggregate_length )
+{
+    char t_string_array[ERROR_NAMAGER_TO_STRING_FRONT_LENGTH] = {0};
+    char* pt_index_front = t_string_array;
+    char* pt_index_back = pm_error_description;
+    char* pt_index = p_error_aggregate;
+
+    sprintf(t_string_array, "error_code:0x%08x, error_level:%02d, error_description:", m_error_code , m_error_level );
+
+    int t_length_min = m_description_length + ERROR_NAMAGER_TO_STRING_FRONT_LENGTH -1;
+    if(t_length_min > aggregate_length)
+    {
+        t_length_min = aggregate_length;
+    }
+
+    for(int i=0;i<t_length_min; i++)
+    {
+        if(i < ERROR_NAMAGER_TO_STRING_FRONT_LENGTH -1)
+        {
+            *pt_index = *pt_index_front;
+            pt_index++;
+            pt_index_front++;
+        }
+        else
+        {
+            *pt_index = *pt_index_back;
+            pt_index++;
+            pt_index_back++;
+        }
+    }
+}
+//output:error_description_string     错误汇总的string
+void Error_manager::translate_error_to_string(std::string & error_aggregate_string)
+{
+    char t_string_array[ERROR_NAMAGER_TO_STRING_FRONT_LENGTH] = {0};
+    sprintf(t_string_array, "error_code:0x%08x, error_level:%02d, error_description:", m_error_code , m_error_level );
+
+    error_aggregate_string = t_string_array ;
+    if(pm_error_description != NULL)
+    {
+        error_aggregate_string += pm_error_description;
+    }
+    else
+    {
+        //error_aggregate_string += "NULL";
+    }
+}
+//错误码转字符串的简易版,可支持cout<<
+//return     错误汇总的string
+std::string Error_manager::to_string()
+{
+    std::string t_string;
+    translate_error_to_string(t_string);
+    return t_string;
+}
+
+
+
+
+//释放错误描述的内存,
+void Error_manager::free_description()
+{
+    if(pm_error_description != NULL)
+    {
+        free (pm_error_description);
+        pm_error_description = NULL;
+    }
+    m_description_length = 0;
+}
+
+//重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
+//input:p_error_description     错误描述的字符串指针,可以为NULL,
+//input:description_length      错误描述的字符串长度,如果为0,则从p_error_description里面获取有效的长度
+void Error_manager::reallocate_memory_and_copy_string(const char* p_error_description, int description_length)
+{
+    free_description();
+
+    if(p_error_description != NULL)
+    {
+        char* pt_source = (char *)p_error_description;
+        char* pt_destination = NULL;
+
+        if(description_length == 0)
+        {
+            m_description_length = 0;
+            while (*pt_source != '\0')
+            {
+                m_description_length++;
+                pt_source++;
+            }
+            m_description_length++;
+            pt_source = (char *)p_error_description;
+        }
+        else
+        {
+            m_description_length = description_length;
+        }
+
+        pm_error_description =  (char*) malloc(m_description_length );
+        pt_destination = pm_error_description;
+
+        for(int i=0;i<m_description_length; i++)
+        {
+            *pt_destination = *pt_source;
+            pt_destination++;
+            pt_source++;
+        }
+    }
+
+    return;
+}
+
+
+//重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
+//input:error_aggregate_string     错误描述的string
+void Error_manager::reallocate_memory_and_copy_string(std::string & error_aggregate_string)
+{
+    free_description();
+
+    if( ! error_aggregate_string.empty())
+    {
+        m_description_length = error_aggregate_string.length()+1;
+
+        pm_error_description =  (char*) malloc( m_description_length );
+
+        strcpy(pm_error_description ,   error_aggregate_string.c_str()  );
+    }
+}
+
+
+
+
+

+ 489 - 0
error_code/error_code.h

@@ -0,0 +1,489 @@
+
+//Error_code是错误码的底层通用模块,
+//功能:用作故障分析和处理。
+
+//用法:所有的功能接口函数return错误管理类,
+//然后上层判断分析错误码,并进行故障处理。
+
+
+
+#ifndef TEST_ERROR_ERROR_CODE_H
+#define TEST_ERROR_ERROR_CODE_H
+
+#include <string>
+#include <string.h>
+#include<iostream>
+
+//错误管理类转化为字符串 的前缀,固定长度为58
+//这个是由显示格式来确定的,如果要修改格式或者 Error_code长度超过8位,Error_level长度超过2位,折需要重新计算
+#define ERROR_NAMAGER_TO_STRING_FRONT_LENGTH   58
+
+//进程加锁的状态,
+enum Lock_status
+{
+    UNLOCK      = 0,
+    LOCK        = 1,
+};
+
+//设备使能状态,
+enum Able_status
+{
+    UNABLE      = 0,
+    ENABLE      = 1,
+};
+
+//数据是否为空
+enum Empty_status
+{
+    NON_EMPTY   = 0,
+    EMPTY       = 1,
+};
+
+
+//错误码的枚举,用来做故障分析
+enum Error_code
+{
+    //成功,没有错误,默认值0
+    SUCCESS                         = 0x00000000,
+
+
+    //基本错误码,
+    ERROR                           = 0x00000001,//错误
+    PARTIAL_SUCCESS                 = 0x00000002,//部分成功
+    WARNING                         = 0x00000003,//警告
+    FAILED                          = 0x00000004,//失败
+
+    NO_DATA                         = 0x00000010,//没有数据,传入参数容器内部没有数据时,
+	INVALID_MESSAGE					= 0x00000011, //无效的消息,
+    RESPONSE_TIMEOUT                = 0x00000012,
+
+    POINTER_IS_NULL                 = 0x00000101,//空指针
+    PARAMETER_ERROR                 = 0x00000102,//参数错误,传入参数不符合规范时,
+    POINTER_MALLOC_FAIL             = 0x00000103,//手动分配内存失败
+
+    CLASS_BASE_FUNCTION_CANNOT_USE  = 0x00000201,//基类函数不允许使用,必须使用子类的
+
+	CONTAINER_IS_TERMINATE			= 0x00000301,//容器被终止
+
+
+
+
+//    错误码的规范,
+//    错误码是int型,32位,十六进制。
+//    例如0x12345678
+//    12表示功能模块,例如:laser雷达模块               	框架制定
+//    34表示文件名称,例如:laser_livox.cpp             框架制定
+//    56表示具体的类,例如:class laser_livox           个人制定
+//    78表示类的函数,例如:laser_livox::start();       个人制定
+//    注:错误码的制定从1开始,不要从0开始,
+//        0用作错误码的基数,用来位运算,来判断错误码的范围。
+
+//    laser扫描模块
+    LASER_ERROR_BASE                = 0x01000000,
+
+//    laser_base基类
+	LASER_BASE_ERROR_BASE			= 0x01010000,
+    LASER_TASK_PARAMETER_ERROR      = 0x01010001,   //雷达基类模块, 任务输入参数错误
+    LASER_CONNECT_FAILED,							//雷达基类模块, 连接失败
+	LASER_START_FAILED,								//雷达基类模块, 开始扫描失败
+	LASER_CHECK_FAILED,								//雷达基类模块, 检查失败
+	LASER_STATUS_BUSY,								//雷达基类模块, 状态正忙
+	LASER_STATUS_ERROR,								//雷达基类模块, 状态错误
+	LASER_TASK_OVER_TIME,							//雷达基类模块, 任务超时
+	LASER_QUEUE_ERROR,								//雷达基类模块, 数据缓存错误
+
+
+//    laser_livox.cpp的错误码
+    LIVOX_ERROR_BASE                = 0x01020000,
+    LIVOX_START_FAILE,								//livox模块,开始扫描失败
+	LIVOX_TASK_TYPE_ERROR,							//livox模块,任务类型错误
+	lIVOX_CANNOT_PUSH_DATA,							//livox模块,不能添加扫描的数据
+	lIVOX_CHECK_FAILED,								//livox模块,检查失败
+	lIVOX_STATUS_BUSY,								//livox模块,状态正忙
+	lIVOX_STATUS_ERROR,								//livox模块,状态错误
+
+	//laser_manager 雷达管理模块
+	LASER_MANAGER_ERROR_BASE						= 0x01030000,
+	LASER_MANAGER_READ_PROTOBUF_ERROR,				//雷达管理模块,读取参数错误
+	LASER_MANAGER_STATUS_BUSY,						//雷达管理模块,状态正忙
+	LASER_MANAGER_STATUS_ERROR,						//雷达管理模块,状态错误
+	LASER_MANAGER_TASK_TYPE_ERROR,					//雷达管理模块,任务类型错误
+	LASER_MANAGER_IS_NOT_READY,						//雷达管理模块,不在准备状态
+	LASER_MANAGER_LASER_INDEX_ERRPR,				//雷达管理模块,雷达索引错误,编号错误。
+	LASER_MANAGER_TASK_OVER_TIME,					//雷达管理模块,任务超时
+	LASER_MANAGER_LASER_INDEX_REPEAT,				//雷达管理模块,需要扫描的雷达索引重复,可忽略的错误,提示作用
+
+//livox_driver 雷达livox驱动模块
+	LIVOX_DRIVER_ERROR_BASE							= 0x01040000,
+	LIVOX_DRIVER_SN_REPEAT,							//livox驱动模块, 雷达广播码重复
+	LIVOX_DRIVER_SN_ERROR,							//livox驱动模块, 雷达广播码错误
+	LIVOX_SKD_INIT_FAILED,							//livox驱动模块, livox_sdk初始化失败
+	LIVOX_DRIVER_NOT_READY,							//livox驱动模块, livox没有准备好.
+
+
+
+
+    //locate 定位模块,
+	LOCATER_ERROR_BASE                				= 0x03000000,
+
+	//LASER_MANAGER 定位管理模块
+	LOCATER_MANAGER_ERROR_BASE                		= 0x03010000,
+	LOCATER_MANAGER_READ_PROTOBUF_ERROR,				//定位管理模块,读取参数错误
+	LOCATER_MANAGER_STATUS_BUSY,						//定位管理模块,状态正忙
+	LOCATER_MANAGER_STATUS_ERROR,						//定位管理模块,状态错误
+	LOCATER_MANAGER_TASK_TYPE_ERROR,					//定位管理模块,任务类型错误
+	LOCATER_MANAGER_IS_NOT_READY,						//定位管理模块,不在准备状态
+	LOCATER_MANAGER_CLOUD_MAP_ERROR,					//定位管理模块,任务输入点云map的error
+	LOCATE_MANAGER_TASK_OVER_TIME,
+
+
+	//Locater.cpp error from 0x0301000-0x030100FF
+	LOCATER_TASK_INIT_CLOUD_EMPTY ,
+    LOCATER_TASK_ERROR,
+    LOCATER_TASK_INPUT_CLOUD_UNINIT,
+    LOCATER_INPUT_CLOUD_EMPTY,
+    LOCATER_YOLO_UNINIT,
+    LOCATER_POINTSIFT_UNINIT,
+    LOCATER_3DCNN_UNINIT,
+    LOCATER_INPUT_YOLO_CLOUD_EMPTY,
+    LOCATER_Y_OUT_RANGE_BY_PLC,
+    LOCATER_MEASURE_HEIGHT_CLOUD_UNINIT,
+    LOCATER_MEASURE_HEIGHT_CLOUD_EMPTY,
+    LOCATER_INPUT_CLOUD_UNINIT,
+
+
+    //point sift from 0x03010100-0x030101FF
+    LOCATER_SIFT_INIT_FAILED=0x03010100,
+    LOCATER_SIFT_INPUT_CLOUD_UNINIT,
+	LOCATER_SIFT_INPUT_CLOUD_EMPTY,
+	LOCATER_SIFT_GRID_ERROR,
+	LOCATER_SIFT_SELECT_ERROR,
+	LOCATER_SIFT_CLOUD_VERY_LITTLE,
+	LOCATER_SIFT_CREATE_INPUT_DATA_FAILED,
+	LOCATER_SIFT_PREDICT_FAILED,
+	LOCATER_SIFT_PREDICT_NO_WHEEL_POINT,
+	LOCATER_SIFT_PREDICT_NO_CAR_POINT,
+
+    LOCATER_SIFT_FILTE_OBS_FAILED,
+    LOCATER_SIFT_INPUT_BOX_PARAMETER_FAILED,
+
+//    //yolo from 0x03010200-0x030102FF
+//        LOCATER_YOLO_DETECT_FAILED=0x03010200,
+//    LOCATER_YOLO_DETECT_NO_TARGET,
+//    LOCATER_YOLO_PARAMETER_INVALID,
+//    LOCATER_YOLO_INPUT_CLOUD_UNINIT,
+
+    //3dcnn from 0x03010300-0x030103FF
+    LOCATER_3DCNN_INIT_FAILED=0x03010300,
+    LOCATER_3DCNN_INPUT_CLOUD_UNINIT,
+	LOCATER_3DCNN_INPUT_CLOUD_EMPTY,
+	LOCATER_3DCNN_INPUT_CLOUD_MAP_ERROR,
+	LOCATER_3DCNN_PCA_OUT_ERROR,
+	LOCATER_3DCNN_EXTRACT_RECT_ERROR,
+	LOCATER_3DCNN_RECT_SIZE_ERROR,
+
+    LOCATER_3DCNN_PREDICT_FAILED,
+    LOCATER_3DCNN_VERIFY_RECT_FAILED_3,
+    LOCATER_3DCNN_VERIFY_RECT_FAILED_4,
+    LOCATER_3DCNN_KMEANS_FAILED,
+    LOCATER_3DCNN_IIU_FAILED,
+    LOCATER_3DCNN_PCA_OUT_CLOUD_EMPTY,
+
+    //System_manager error from 0x04010000-0x0401FFFF
+    SYSTEM_READ_PARAMETER_ERROR=0x04010100,
+    SYSTEM_PARAMETER_ERROR,
+    SYSTEM_INPUT_TERMINOR_NO_LASERS,
+
+    //terminor_command_executor.cpp from 0x04010200-0x040102FF
+    TERMINOR_NOT_READY=0x04010200,
+    TERMINOR_INPUT_LASER_NULL,
+    TERMINOR_NOT_CONTAINS_LASER,
+    TERMINOR_INPUT_PLC_NULL,
+    TERMINOR_INPUT_LOCATER_NULL,
+    TERMINOR_CREATE_WORKING_THREAD_FAILED,
+    TERMINOR_FORCE_QUIT,
+    TERMINOR_LASER_TIMEOUT,
+    TERMINOR_POST_PLC_TIMEOUT,
+    TERMINOR_CHECK_RESULTS_ERROR,
+
+    ////Hardware limit from 0x05010000 - 0x0501ffff
+    ///railing.cpp from 0x05010100-0x050101ff
+    HARDWARE_LIMIT_LEFT_RAILING=0x05010100,         //左栏杆限制
+    HARDWARE_LIMIT_RAILING_PARAMETER_ERROR,
+    HARDWARE_LIMIT_RAILING_ERROR,
+    HARDWARE_LIMIT_CENTER_X_LEFT,
+    HARDWARE_LIMIT_CENTER_X_RIGHT,
+    HARDWARE_LIMIT_CENTER_Y_TOP,
+    HARDWARE_LIMIT_CENTER_Y_BOTTOM,
+    HARDWARE_LIMIT_HEIGHT_OUT_RANGE,
+    HARDWARE_LIMIT_ANGLE_OUT_RANGE,
+    //termonal_limit from 0x05010200-0x050102ff
+    HARDWARE_LIMIT_TERMINAL_LEFT_ERROR,
+    HARDWARE_LIMIT_TERMINAL_RIGHT_ERROR,
+    HARDWARE_LIMIT_TERMINAL_LR_ERROR,
+
+
+    //wj_lidar error from 0x06010000-0x0601FFFF
+        WJ_LIDAR_CONNECT_FAILED=0x06010000,
+    WJ_LIDAR_UNINITIALIZED,
+    WJ_LIDAR_READ_FAILED,
+    WJ_LIDAR_WRITE_FAILED,
+    WJ_LIDAR_GET_CLOUD_TIMEOUT,
+
+    //wj lidar protocol error from 0x06020000-0x0602FFFF
+        WJ_PROTOCOL_ERROR_BASE=0x06020000,
+    WJ_PROTOCOL_INTEGRITY_ERROR,
+    WJ_PROTOCOL_PARSE_FAILED,
+    WJ_PROTOCOL_EMPTY_PACKAGE,
+    WJ_PROTOCOL_EXCEED_MAX_SIZE,
+
+    //wj region detect error from 0x06030000-0x0603FFFF
+        WJ_REGION_EMPTY_CLOUD=0x06030000,
+    WJ_REGION_RECTANGLE_ANGLE_ERROR,
+    WJ_REGION_RECTANGLE_SIZE_ERROR,
+    WJ_REGION_RECTANGLE_SYMMETRY_ERROR,
+    WJ_REGION_CLUSTER_SIZE_ERROR,
+
+    //wj manager error from 0x06040000-0x0604FFFF
+    WJ_MANAGER_UNINITIALIZED=0x06040000,
+    WJ_MANAGER_LIDAR_DISCONNECTED,
+    WJ_MANAGER_PLC_DISCONNECTED,
+    WJ_MANAGER_EMPTY_CLOUD,
+
+    WJ_LIDAR_TASK_EMPTY_RESULT=0x06050000,
+    WJ_LIDAR_TASK_EMPTY_TASK,
+    WJ_LIDAR_TASK_WRONG_TYPE,
+    WJ_LIDAR_TASK_INVALID_TASK,
+    WJ_LIDAR_TASK_MEASURE_FAILED,
+
+
+
+    //task module, 任务模块  error from 0x10010000-0x1001FFFF
+	TASK_MODULE_ERROR_BASE 							= 0x10010000,
+	TASK_TYPE_IS_UNKNOW,
+	TASK_NO_RECEIVER,
+
+
+	//Communication module, 通信模块
+	COMMUNICATION_BASE_ERROR_BASE					= 0x11010000,
+	COMMUNICATION_READ_PROTOBUF_ERROR,				//模块,读取参数错误
+	COMMUNICATION_BIND_ERROR,
+	COMMUNICATION_CONNECT_ERROR,
+	COMMUNICATION_ANALYSIS_TIME_OUT,									//解析超时,
+	COMMUNICATION_EXCUTER_IS_BUSY,										//处理器正忙, 请稍等
+
+	//system module, 系统模块
+	SYSTEM_EXECUTOR_ERROR_BASE						= 0x12010000,		//系统执行模块,
+	SYSTEM_EXECUTOR_PARSE_ERROR,										//系统执行模块, 解析消息错误
+	SYSTEM_EXECUTOR_STATUS_BUSY,										//系统执行模块, 状态正忙
+	SYSTEM_EXECUTOR_STATUS_ERROR,										//系统执行模块, 状态错误
+	SYSTEM_EXECUTOR_CHECK_ERROR,										//系统执行模块, 检查错误
+
+	LOCATER_MSG_TABLE_NOT_EXIST ,
+    LOCATER_MSG_RESPONSE_TYPE_ERROR,
+    LOCATER_MSG_RESPONSE_INFO_ERROR,
+    LOCATER_MSG_REQUEST_INVALID,
+    LOCATER_MSG_RESPONSE_HAS_NO_REQUEST,
+    
+    
+    //parkspace allocator,车位分配模块
+    PARKSPACE_ALLOCATOR_ERROR_BASE                  = 0x20010000,     
+    PARKSPACE_ALLOCATOR_MSG_REQUEST_TYPE_ERROR,    //反馈车位消息类型错误 
+    PARKSPACE_ALLOCATOR_MSG_RESPONSE_TYPE_ERROR,    //反馈车位消息类型错误
+    PARKSPACE_ALLOCATOR_MSG_PARSE_ERROR,            //请求消息解析错误
+    PARKSPACE_ALLOCATOR_SPACE_EMPTY,                //空车位异常,车库无车位。或许由模块初始化异常产生
+    PARKSPACE_ALLOCATOR_ALLOCATE_FAILED,            //无合适车位,分配失败
+    PARKSPACE_ALLOCATOR_SEARCH_FAILED,              //未找到车辆对应车位
+    PARKSPACE_ALLOCATOR_RELEASE_FAILED,             //未找到匹配的车位,车位未释放
+    PARKSPACE_ALLOCATOR_FORCE_UPDATE_FAILED,        //手动更新失败,未找到匹配车位
+    PARKSPACE_ALLOCATOR_PARAM_ERROR,                //传入参数错误,内部无车辆信息
+    PARKSPACE_ALLOCATOR_CONFIRM_ALLOC_ERROR,        //确认分配车位错误
+    PARKSPACE_ALLOCATOR_CAR_ALREADY_EXIST,          //车辆已存在
+
+    // 数据库操作
+    DB_ERROR_BASE                                   = 0x20020000,
+    DB_INIT_FAILED,
+    DB_CONNECT_FAILED,                              //数据库连接失败
+    DB_INSERT_FAILED,                               //数据库插入失败
+    DB_DELETE_FAILED,                               //数据库删除失败
+    DB_UPDATE_FAILED,                               //数据库更新失败
+    DB_QUERY_FAILED,                                //数据库查询失败
+    DB_UNINITIALIZED,                               //数据库外层未初始化
+    DB_DISCONNECTED,                                //数据库外层连接失去
+    DB_RESULT_SET_EMPTY,                            //数据库外层查询返回结果空指针
+    DB_RESULT_SET_PARSE_ERROR,                      //数据库外层查询结果解析失败
+
+};
+
+//错误等级,用来做故障处理
+enum Error_level
+{
+//    正常,没有错误,默认值0
+    NORMAL                = 0,
+
+
+//    轻微故障,可忽略的故障,NEGLIGIBLE_ERROR
+//    提示作用,不做任何处理,不影响代码的流程,
+//    用作一些不重要的事件,即使出错也不会影响到系统功能,
+//    例如:文件保存错误,等
+    NEGLIGIBLE_ERROR      = 1,
+
+
+//    一般故障,MINOR_ERROR
+//    用作底层功能函数的错误返回,表示该功能函数执行失败,
+//    返回给应用层之后,需要做故障分析和处理,
+//    例如:雷达数据传输失败,应用层就需要进行重新扫描,或者重连,或者重置参数等。
+    MINOR_ERROR           = 2,
+
+
+//    严重故障,MAJOR_ERROR
+//    用作应用层的任务事件的结果,表示该功能模块失败。
+//    通常是底层函数返回一般故障之后,应用层无法处理并解决故障,此时就要进行故障升级,
+//    从一般故障升级为严重故障,然后进行回退流程,回退已经执行的操作,最终回到故障待机状态。
+//    需要外部清除故障,并复位至正常待机状态,才能恢复功能的使用。
+//    例如:雷达扫描任务失败,且无法自动恢复。
+    MAJOR_ERROR           = 3,
+
+
+//    致命故障,CRITICAL_ERROR
+//    系统出现致命错误。导致系统无法正常运行,
+//    此时系统应该紧急停机,执行紧急流程,快速停机。
+//    此时不允许再执行任何函数和任务指令,防止系统故障更加严重。
+//    也不需要做任何错误处理了,快速执行紧急流程。
+//    例如:内存错误,进程挂死,关键设备失控,监控设备报警,等
+    CRITICAL_ERROR        = 4,
+};
+
+
+class Error_manager
+{
+public://外部接口函数
+    //构造函数
+    Error_manager();
+    //拷贝构造
+    Error_manager(const Error_manager & error_manager);
+    //赋值构造
+    Error_manager(Error_code error_code, Error_level error_level = NORMAL,
+                  const char* p_error_description = NULL, int description_length = 0);
+    //赋值构造
+    Error_manager(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
+    //析构函数
+    ~Error_manager();
+
+    //初始化
+    void error_manager_init();
+    //初始化
+    void error_manager_init(Error_code error_code, Error_level error_level = NORMAL,
+                            const char* p_error_description = NULL, int description_length = 0);
+    //初始化
+    void error_manager_init(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
+    //重置
+    void error_manager_reset(Error_code error_code, Error_level error_level = NORMAL,
+                             const char* p_error_description = NULL, int description_length = 0);
+    //重置
+    void error_manager_reset(Error_code error_code, Error_level error_level , std::string & error_aggregate_string);
+    //重置
+    void error_manager_reset(const Error_manager & error_manager);
+    //清除所有内容
+    void error_manager_clear_all();
+
+    //重载=
+    Error_manager& operator=(const Error_manager & error_manager);
+    //重载=,支持Error_manager和Error_code的直接转化,会清空错误等级和描述
+    Error_manager& operator=(Error_code error_code);
+    //重载==
+    bool operator==(const Error_manager & error_manager);
+    //重载==,支持Error_manager和Error_code的直接比较
+    bool operator==(Error_code error_code);
+    //重载!=
+    bool operator!=(const Error_manager & error_manager);
+    //重载!=,支持Error_manager和Error_code的直接比较
+    bool operator!=(Error_code error_code);
+	//重载<<,支持cout<<
+	friend std::ostream & operator<<(std::ostream &out, Error_manager &error_manager);
+
+
+    //获取错误码
+    Error_code get_error_code();
+    //获取错误等级
+    Error_level get_error_level();
+    //获取错误描述的指针,(浅拷贝)
+    char* get_error_description();
+
+	int get_description_length();
+
+    //复制错误描述,(深拷贝)
+    //output:p_error_description     错误描述的字符串指针,不可以为NULL,必须要有实际的内存
+    //output:description_length      错误描述的字符串长度,不可以为0,长度最好足够大,一般256即可。
+    void copy_error_description(const char* p_error_description, int description_length);
+    //复制错误描述,(深拷贝)
+    //output:error_description_string     错误描述的string
+    void copy_error_description(std::string & error_description_string);
+
+    //设置错误码
+    void set_error_code(Error_code error_code);
+    //比较错误等级并升级,取高等级的结果
+    void set_error_level_up(Error_level error_level);
+    //比较错误等级并降级,取低等级的结果
+    void set_error_level_down(Error_level error_level);
+    //错误等级,设定到固定值
+    void set_error_level_location(Error_level error_level);
+    //设置错误描述
+    void set_error_description(const char* p_error_description, int description_length = 0);
+    //设置错误描述
+    void set_error_description(std::string & error_description_string);
+
+    //尾部追加错误描述
+    void add_error_description(const char* p_error_description, int description_length = 0);
+    //尾部追加错误描述
+    void add_error_description(std::string & error_description_string);
+
+    //比较错误是否相同,
+    // 注:只比较错误码和等级
+	bool is_equal_error_manager(const Error_manager & error_manager);
+	//比较并覆盖错误,讲低级错误转为字符串存放于描述中,
+	//如果错误相同,则保留this的,将输入参数转入描述。
+	void compare_and_cover_error(const Error_manager & error_manager);
+	//比较并覆盖错误,讲低级错误转为字符串存放于描述中,
+	//如果错误相同,则保留this的,将输入参数转入描述。
+	void compare_and_cover_error( Error_manager * p_error_manager);
+
+	//将所有的错误信息,格式化为字符串,用作日志打印。
+    //output:p_error_description     错误汇总的字符串指针,不可以为NULL,必须要有实际的内存
+    //output:description_length      错误汇总的字符串长度,不可以为0,长度最好足够大,一般256即可。
+    void translate_error_to_string(char* p_error_aggregate, int aggregate_length);
+    //output:error_description_string     错误汇总的string
+    void translate_error_to_string(std::string & error_aggregate_string);
+    //错误码转字符串的简易版,可支持cout<<
+    //return     错误汇总的string
+    std::string to_string();
+
+
+
+protected:
+    Error_code              m_error_code;               //错误码
+    Error_level             m_error_level;              //错误等级
+    char*                   pm_error_description;       //错误描述
+    int                     m_description_length;       //错误描述的字符长度
+
+protected://内部功能函数
+public:
+    //释放错误描述的内存,
+    void free_description();
+
+    //重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
+    //input:p_error_description     错误描述的字符串指针,可以为NULL,
+    //input:description_length      错误描述的字符串长度,如果为0,则从p_error_description里面获取有效的长度
+    void reallocate_memory_and_copy_string(const char* p_error_description, int description_length = 0);
+
+    //重新分配错误描述的内存,并从外部拷贝新的(深拷贝)
+    //input:error_aggregate_string     错误描述的string
+    void reallocate_memory_and_copy_string(std::string & error_aggregate_string);
+};
+
+
+
+
+#endif //TEST_ERROR_ERROR_CODE_H
+
+

File diff suppressed because it is too large
+ 3218 - 0
message/message_base.pb.cc


File diff suppressed because it is too large
+ 2341 - 0
message/message_base.pb.h


+ 205 - 0
message/message_base.proto

@@ -0,0 +1,205 @@
+syntax = "proto2";
+package message;
+
+//消息类型定义;每个在网络上传输的消息必须含有这个属性
+enum Message_type
+{
+    eBase_msg=0x00;
+    eCommand_msg=0x01;                      //指令消息
+
+
+    eLocate_status_msg=0x11;                //定位模块状态消息
+    eLocate_request_msg=0x12;               //定位请求消息
+    eLocate_response_msg=0x13;              //定位反馈消息
+
+
+    eDispatch_status_msg=0x21;                //调度模块硬件状态消息
+    eDispatch_request_msg=0x22;              //请求调度消息
+    eDispatch_response_msg=0x23;             //调度结果反馈消息
+
+    eParkspace_allocation_status_msg=0x31;  //车位分配模块状态消息,包括车位信息
+    eParkspace_allocation_request_msg=0x32; //请求分配车位消息
+    eParkspace_allocation_response_msg=0x33;//分配车位结果反馈消息
+    eParkspace_search_request_msg = 0x34;		//查询车位请求消息
+    eParkspace_search_response_msg = 0x35;		//查询车位反馈消息
+    eParkspace_release_request_msg = 0x36;		//释放车位请求消息
+    eParkspace_release_response_msg = 0x37;		//释放车位反馈消息
+    eParkspace_force_update_request_msg = 0x38;	//手动修改车位消息
+    eParkspace_force_update_response_msg = 0x39;//手动修改车位反馈消息
+    eParkspace_confirm_alloc_request_msg = 0x3A;//确认分配车位请求消息
+    eParkspace_confirm_alloc_response_msg = 0x3B;//确认分配车位反馈消息
+
+
+    eStore_command_request_msg=0x41;        //终端停车请求消息
+    eStore_command_response_msg=0x42;       //停车请求反馈消息
+    ePickup_command_request_msg=0x43;       //取车请求消息
+    ePickup_command_response_msg=0x44;       //取车请求反馈消息
+
+
+
+    eStoring_process_statu_msg=0x90;        //停车指令进度条消息
+    ePicking_process_statu_msg=0x91;        //取车指令进度消息
+
+
+    eCentral_controller_statu_msg=0xa0;     //中控系统状态消息
+
+
+    eEntrance_manual_operation_msg=0xb0;            //针对出入口状态操作的手动消息
+    eProcess_manual_operation_msg=0xb1;             //针对流程的手动消息
+
+
+}
+
+//通讯单元
+enum Communicator
+{
+    eEmpty=0x0000;
+    eMain=0x0001;    //主流程
+
+    eTerminor=0x0100;
+    //车位表
+    eParkspace=0x0200;
+    //测量单元
+    eMeasurer=0x0300;
+    //调度机构
+    eDispatch=0x0400;
+    //...
+
+
+}
+////base message 用于解析未知类型的消息
+message Base_info
+{
+    required Message_type               msg_type=1;
+    optional int32                      timeout_ms=2;
+    required Communicator               sender=3;                       //发送者
+    required Communicator               receiver=4;                     //接收者
+}
+
+// 事件,停车或者取车
+enum Process_type
+{
+    eStoring=1;
+    ePicking=2;
+}
+
+
+message Base_msg
+{
+    required Base_info                  base_info=1;
+}
+
+//错误等级,用来做故障处理
+enum Error_level
+{
+    NORMAL                = 0;      //    正常,没有错误,默认值0
+
+    NEGLIGIBLE_ERROR      = 1;      //    轻微故障;可忽略的故障,NEGLIGIBLE_ERROR
+
+    MINOR_ERROR           = 2;      //    一般故障,MINOR_ERROR
+
+    MAJOR_ERROR           = 3;      //    严重故障,MAJOR_ERROR
+
+    CRITICAL_ERROR        = 4;      //    致命故障,CRITICAL_ERROR
+
+}
+
+message Error_manager
+{
+    required int32                      error_code = 1;
+    optional Error_level                error_level = 2;
+    optional string                     error_description = 3;
+}
+
+//测量结果结构体
+message Locate_information
+{    
+    optional float locate_x = 1;				//整车的中心点x值; 四轮的中心
+    optional float locate_y = 2;				//整车的中心点y值; 四轮的中心
+    optional float locate_angle = 3;			//整车的旋转角; 四轮的旋转角
+    optional float locate_length = 4;		    //整车的长度; 用于规避碰撞
+    optional float locate_width = 5;			//整车的宽度; 用于规避碰撞
+    optional float locate_height = 6;		    //整车的高度; 用于规避碰撞
+    optional float locate_wheel_base = 7;	    //整车的轮距; 前后轮的距离; 用于机器人或agv的抓车
+    optional float locate_wheel_width = 8;	    //整车的轮距; 左右轮的距离; 用于机器人或agv的抓车
+    optional bool locate_correct = 9;		    //整车的校准标记位
+}
+
+//车辆基本信息
+message Car_info
+{
+    optional float                      car_length=1;           //车长
+    optional float                      car_width=2;            //车宽
+    optional float                      car_height=3;           //车高
+    optional string                     license=4;              //车辆凭证号
+}
+
+//车位状态枚举
+enum Parkspace_status
+{
+    eParkspace_empty            = 0;         //空闲,可分配
+    eParkspace_occupied         = 1;         //被占用,不可分配
+    eParkspace_reserved        = 2;         //被预约,预约车辆可分配
+    eParkspace_locked           = 3;         //临时锁定,不可分配
+    eParkspace_error            = 4;         //车位机械结构或硬件故障   
+}
+
+enum Direction
+{
+    eForward = 1;
+    eBackward = 2;
+}
+
+//单个车位基本信息与状态信息,车位信息以及车位上的车辆信息
+message Parkspace_info
+{
+    optional int32              parkspace_id=1;         //车位编号
+    optional int32              index=2;                //同层编号
+    optional Direction          direction=3;            //前后
+    optional int32              floor=4;                //楼层
+    optional float              length=5;               //车位长
+    optional float              width=6;                //车位宽
+    optional float              height=7;               //车位高
+    optional Parkspace_status   parkspace_status=8;     //车位当前状态
+    optional Car_info           car_info=9;              //当前车位存入车辆的凭证号
+    optional string             entry_time=10;          //入场时间
+    optional string             leave_time=11;          //离场时间
+}
+
+/*
+*流程中的步骤类型, 例如:停车流程包含5个步骤 , 分配车位-测量-检验结果-搬运-更新车位表
+*/
+enum Step_type
+{
+    eAlloc_step=0;
+    eMeasure_step=1;
+    eCompare_step=2;
+    eDispatch_step=3;
+    eConfirm_step=4;
+
+    eSearch_step=5;        //查询数据库
+    eWait_step=6;             //等待车辆离开
+    eRelease_step=7;          //释放车位
+
+    eComplete=8;              //完成
+
+    eBackConfirm_step=9;
+    eBack_compare_step=10;
+    eBackMeasure_step=11;
+    eBackAlloc_step=12;
+
+    eBackWait_step=13;
+    eBackDispatch_step=14;
+    eBackSearch_step=15;
+
+    eBackComplete=16;
+}
+//步骤状态,每个步骤有四中可能状态 ,等待中-执行中-完成或者错误  四个状态
+enum Step_statu
+{
+    eWaiting=0;               //完成/空闲
+    eWorking=1;
+    eError=2;
+    eFinished=3;
+}
+

File diff suppressed because it is too large
+ 5437 - 0
message/parkspace_allocation_message.pb.cc


File diff suppressed because it is too large
+ 3927 - 0
message/parkspace_allocation_message.pb.h


+ 116 - 0
message/parkspace_allocation_message.proto

@@ -0,0 +1,116 @@
+syntax = "proto2";
+package message;
+import "message_base.proto";
+
+// 请求
+// 1.分配车位
+// 2.查询车辆位置
+// 3.解锁车位
+// 4.手动操作修改车位状态
+// 5.临时锁定车位
+
+//车辆状态枚举
+enum Vehicle_status
+{
+    eVehicle_idle           = 0;         //车辆空闲
+    eVehicle_in_garage      = 1;         //车辆已入库
+    eVehicle_parking        = 2;         //车辆停车中
+    eVehicle_fetching       = 3;         //车辆取车中
+    eVehicle_reserved       = 4;         //已预约未停入
+    eVehicle_unknown        = 5;         //未知状态
+}
+
+//1.分配车位请求
+message Parkspace_allocation_request_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Car_info                   car_info=3;
+    required int32                      terminal_id=4;          //终端id,优化车位分配用
+}
+
+//分配车位反馈
+message Parkspace_allocation_response_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Error_manager              error_manager=3;        //分配成功与否标志
+    required Parkspace_info             allocated_space_info=4; //分配车位信息
+}
+
+//2.查询车辆位置请求
+message Parkspace_search_request_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Car_info                   car_info=3;              //车辆凭证或号牌
+}
+
+//查询车辆位置反馈
+message Parkspace_search_response_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Error_manager              error_manager=3;        //分配成功与否标志
+    optional Parkspace_info             car_position=4;         //待查询车辆存放位置
+}
+
+//3.解锁车位请求
+message Parkspace_release_request_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Parkspace_info             release_space_info=3;   //待释放车位信息
+}
+
+//解锁车位反馈
+message Parkspace_release_response_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Error_manager              error_manager=3;        //分配成功与否标志
+    required Parkspace_info             release_space_info=4;   //待释放车位信息
+}
+
+// 4.手动操作修改车位状态
+message Parkspace_force_update_request_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Parkspace_info             update_space_info=3;    //待手动修改车位信息,通过id定位
+}
+
+//手动操作反馈
+message Parkspace_force_update_response_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Error_manager              error_manager=3;        //分配成功与否标志
+    required Parkspace_info             update_space_info=4;    //已修改后的车位信息
+}
+
+// 5.临时锁定车位
+message Parkspace_confirm_alloc_request_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Parkspace_info             confirm_space_info=3;    //已修改后的车位信息
+}
+
+message Parkspace_confirm_alloc_response_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required string                     command_key=2;           //指令唯一标识符id
+    required Error_manager              error_manager=3;        //分配成功与否标志
+    required Parkspace_info             confirm_alloc_space_info=4;    //已修改后的车位信息
+}
+
+// 车位心跳状态信息
+message Parkspace_allocation_status_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required Error_manager              error_manager=2;
+    repeated Parkspace_info             parkspace_info=3;       //车位状态
+}
+
+

+ 391 - 0
parkspace_allocation/database_controller.cpp

@@ -0,0 +1,391 @@
+/*
+ * @Description: 数据库操作类
+ * @Author: yct
+ * @Date: 2020-07-15 14:08:46
+ * @LastEditTime: 2020-07-24 14:19:31
+ * @LastEditors: yct
+ */
+
+#include "database_controller.h"
+
+//初始化
+Error_manager Database_controller::database_controller_init(std::string ip, int port, std::string username, std::string pass, std::string db_name, int conn_size)
+{
+    //系统结束标记与连接池大小
+    mb_exit = false;
+    m_conn_pool_size = conn_size;
+    m_db_param.connect_string = std::string("tcp://").append(ip).append(":").append(std::to_string(port));
+    m_db_param.username = username;
+    m_db_param.pass = pass;
+    m_db_param.db_name = db_name;
+    //mysql驱动
+    if(m_mysql_driver == nullptr)
+    {
+        m_mysql_driver = sql::mysql::get_driver_instance();
+    }
+    if(m_mysql_driver == nullptr)
+    {
+        mb_initialized = false;
+        return DB_INIT_FAILED;
+    }
+    //创建连接池
+    fill_up_pool(m_conn_pool_size);
+    
+    //守护线程,检查连接状态并保持连接数量
+    mp_guard_thread = new std::thread(&Database_controller::database_status_update, this);
+    mb_initialized = true;
+    if(check_status() == SUCCESS)
+    {
+        mb_connected = true;
+    }else{
+        mb_connected = false;
+    }
+
+    return SUCCESS;
+}
+
+//反初始化
+Error_manager Database_controller::database_controller_uninit()
+{
+    mb_exit = true;
+    if(mp_guard_thread!=nullptr)
+    {
+        if(mp_guard_thread->joinable())
+            mp_guard_thread->join();
+        delete mp_guard_thread;
+        mp_guard_thread = nullptr;
+    }
+    return SUCCESS;
+}
+
+//数据库连接状态
+bool Database_controller::is_connected()
+{
+    check_status();
+    return mb_connected;
+}
+
+//****** 增删改查功能 *******
+//增
+Error_manager Database_controller::sql_insert(std::string sql_str)
+{
+    // 1.检查状态,一旦无可用连接,则主动创建一个,若依然失败则直接返回错误
+    Error_manager ec = check_status();
+    if(ec != SUCCESS)
+    {
+        ec = fill_up_pool(1);
+    }
+    if(ec == SUCCESS)
+    {
+        // 从连接池获取连接
+        m_conn_mutex.lock();
+        boost::shared_ptr<sql::Connection> t_conn_ptr = m_db_conn_pool.front();
+        m_db_conn_pool.pop();
+        m_conn_mutex.unlock();
+        // 使用该连接并在结束判断连接状态,将正常连接丢回队列
+        if(t_conn_ptr!= nullptr && t_conn_ptr->isValid()){
+            char buf[1024];
+            memset(buf, 0, 1024);
+            try
+            {
+                t_conn_ptr->setSchema(m_db_param.db_name);
+                boost::scoped_ptr<sql::Statement> stmt(t_conn_ptr->createStatement());
+                stmt->execute(sql_str);
+                // 丢回队列
+                if(t_conn_ptr!= nullptr && t_conn_ptr->isValid())
+                {
+                    m_conn_mutex.lock();
+                    m_db_conn_pool.push(t_conn_ptr);
+                    m_conn_mutex.unlock();
+                }
+                return SUCCESS;
+            }
+            catch (sql::SQLException &e)
+            {
+                /* Use what() (derived from std::runtime_error) to fetch the error message */
+                sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s\nsql: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str(), sql_str.c_str());
+                usleep(1000* 3000);
+                return Error_manager(DB_INSERT_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+            catch (std::runtime_error &e)
+            {
+                sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s \nsql: %s",e.what(),__FILE__, sql_str.c_str());
+                return Error_manager(DB_INSERT_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+            // catch (std::exception &e)
+            // {
+            //     sprintf(buf, "# ERR: %s\n ERR: Standard exception in  %s ",e.what(),__FILE__);
+            //     return Error_manager(DB_INSERT_FAILED, NEGLIGIBLE_ERROR, buf);
+            // }
+        }
+        else
+        {
+            return DB_CONNECT_FAILED;
+        }
+    }else{
+        return ec;
+    }
+}
+
+//删
+Error_manager Database_controller::sql_delete(std::string sql_str)
+{
+    // 1.检查状态,一旦无可用连接,则主动创建一个,若依然失败则直接返回错误
+    Error_manager ec = check_status();
+    if(ec != SUCCESS)
+    {
+        ec = fill_up_pool(1);
+    }
+    if(ec == SUCCESS)
+    {
+        // 从连接池获取连接
+        m_conn_mutex.lock();
+        boost::shared_ptr<sql::Connection> t_conn_ptr = m_db_conn_pool.front();
+        m_db_conn_pool.pop();
+        m_conn_mutex.unlock();
+        // 使用该连接并在结束判断连接状态,将正常连接丢回队列
+        if(t_conn_ptr!= nullptr && t_conn_ptr->isValid()){
+            char buf[1024];
+            memset(buf, 0, 1024);
+            try
+            {
+                t_conn_ptr->setSchema(m_db_param.db_name);
+                boost::scoped_ptr<sql::Statement> stmt(t_conn_ptr->createStatement());
+                stmt->execute(sql_str);
+                // 丢回队列
+                if(t_conn_ptr!= nullptr && t_conn_ptr->isValid())
+                {
+                    m_conn_mutex.lock();
+                    m_db_conn_pool.push(t_conn_ptr);
+                    m_conn_mutex.unlock();
+                }
+                return SUCCESS;
+            }
+            catch (sql::SQLException &e)
+            {
+                /* Use what() (derived from std::runtime_error) to fetch the error message */
+                sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s\nsql: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str(), sql_str.c_str());
+                return Error_manager(DB_DELETE_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+            catch (std::runtime_error &e)
+            {
+                sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s \nsql: %s",e.what(),__FILE__, sql_str.c_str());
+                return Error_manager(DB_DELETE_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+        }
+        else
+        {
+            return DB_CONNECT_FAILED;
+        }
+    }else{
+        return ec;
+    }
+}
+
+//改
+Error_manager Database_controller::sql_update(std::string sql_str)
+{
+    // 1.检查状态,一旦无可用连接,则主动创建一个,若依然失败则直接返回错误
+    Error_manager ec = check_status();
+    if(ec != SUCCESS)
+    {
+        ec = fill_up_pool(1);
+    }
+    if(ec == SUCCESS)
+    {
+        // 从连接池获取连接
+        m_conn_mutex.lock();
+        boost::shared_ptr<sql::Connection> t_conn_ptr = m_db_conn_pool.front();
+        m_db_conn_pool.pop();
+        m_conn_mutex.unlock();
+        // 使用该连接并在结束判断连接状态,将正常连接丢回队列
+        if(t_conn_ptr!= nullptr && t_conn_ptr->isValid()){
+            char buf[1024];
+            memset(buf, 0, 1024);
+            try
+            {
+                t_conn_ptr->setSchema(m_db_param.db_name);
+                boost::scoped_ptr<sql::Statement> stmt(t_conn_ptr->createStatement());
+                int affected_rows = stmt->executeUpdate(sql_str);
+                // 丢回队列
+                if(t_conn_ptr!= nullptr && t_conn_ptr->isValid())
+                {
+                    m_conn_mutex.lock();
+                    m_db_conn_pool.push(t_conn_ptr);
+                    m_conn_mutex.unlock();
+                }
+                if (affected_rows > 0)
+                {
+                    return SUCCESS;
+                }
+                else
+                {
+                    return DB_UPDATE_FAILED;
+                }
+            }
+            catch (sql::SQLException &e)
+            {
+                /* Use what() (derived from std::runtime_error) to fetch the error message */
+                sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s\nsql: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str(), sql_str.c_str());
+                return Error_manager(DB_UPDATE_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+            catch (std::runtime_error &e)
+            {
+                sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s \nsql: %s",e.what(),__FILE__, sql_str.c_str());
+                return Error_manager(DB_UPDATE_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+        }
+        else
+        {
+            return DB_CONNECT_FAILED;
+        }
+    }else{
+        return ec;
+    }
+}
+
+//查
+Error_manager Database_controller::sql_query(std::string sql_str, boost::shared_ptr< sql::ResultSet > &query_result)
+{
+    // 1.检查状态,一旦无可用连接,则主动创建一个,若依然失败则直接返回错误
+    Error_manager ec = check_status();
+    if(ec != SUCCESS)
+    {
+        ec = fill_up_pool(1);
+    }
+    if(ec == SUCCESS)
+    {
+        // 从连接池获取连接
+        m_conn_mutex.lock();
+        boost::shared_ptr<sql::Connection> t_conn_ptr = m_db_conn_pool.front();
+        // std::cout<<"conn handle: "<<t_conn_ptr<<std::endl;
+        m_db_conn_pool.pop();
+        // std::cout<<"conn handle after pop: "<<t_conn_ptr<<std::endl;
+        m_conn_mutex.unlock();
+        // 使用该连接并在结束判断连接状态,将正常连接丢回队列
+        if(t_conn_ptr!= nullptr && t_conn_ptr->isValid()){
+            char buf[1024];
+            memset(buf, 0, 1024);
+            try
+            {
+                t_conn_ptr->setSchema(m_db_param.db_name);
+                boost::scoped_ptr< sql::Statement > stmt(t_conn_ptr->createStatement());
+                query_result = boost::shared_ptr< sql::ResultSet >(stmt->executeQuery(sql_str));
+                // 丢回队列
+                if(t_conn_ptr!= nullptr && t_conn_ptr->isValid())
+                {
+                    m_conn_mutex.lock();
+                    m_db_conn_pool.push(t_conn_ptr);
+                    m_conn_mutex.unlock();
+                }
+                // 检查结果
+                if(query_result!=nullptr)
+                {
+                    return SUCCESS;
+                }else{
+                    return DB_QUERY_FAILED;
+                }
+            }
+            catch (sql::SQLException &e)
+            {
+                /* Use what() (derived from std::runtime_error) to fetch the error message */
+                sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s\nsql: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str(), sql_str.c_str());
+                return Error_manager(DB_UPDATE_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+            catch (std::runtime_error &e)
+            {
+                sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s \nsql: %s",e.what(),__FILE__, sql_str.c_str());
+                return Error_manager(DB_UPDATE_FAILED, NEGLIGIBLE_ERROR, buf);
+            }
+        }else{
+            return DB_CONNECT_FAILED;
+        }
+    }else{
+        return ec;
+    }
+}
+
+void Database_controller::database_status_update()
+{
+    while(!mb_exit && mb_initialized)
+    {
+        //std::cout<<"guard thread working."<<std::endl;
+        // 检查连接状态,直到获得正常连接或队列为空为止
+        check_status();
+        fill_up_pool(m_conn_pool_size);
+        usleep(1000*DB_UPDATE_INTERVAL_MILLI);
+    }
+}
+
+// 检查连接状态
+Error_manager Database_controller::check_status()
+{
+    std::lock_guard<std::mutex> lck(m_conn_mutex);
+    while (m_db_conn_pool.size() > 0)
+    {
+        boost::shared_ptr<sql::Connection> t_conn_ptr = m_db_conn_pool.front();
+        if (t_conn_ptr != nullptr && t_conn_ptr->isValid())
+        {
+            mb_connected = true;
+            break;
+        }
+        else
+        {
+            mb_connected = false;
+            m_db_conn_pool.pop();
+        }
+    }
+    if(mb_connected)
+        return SUCCESS;
+    else
+        return DB_CONNECT_FAILED;
+}
+
+// 补充连接
+Error_manager Database_controller::fill_up_pool(int add_num)
+{
+    std::lock_guard<std::mutex> lck(m_conn_mutex);
+    // 填充连接池
+    int retry_count = 3;
+    int added_num = 0;
+    while (m_db_conn_pool.size() < m_conn_pool_size && added_num<add_num)
+    {
+        try
+        {
+            // 三次创建连接失败则暂时释放锁
+            if (retry_count <= 0)
+            {
+                mb_connected = false;
+                break;
+            }
+
+            boost::shared_ptr<sql::Connection> t_conn_ptr(m_mysql_driver->connect(m_db_param.connect_string, m_db_param.username, m_db_param.pass));
+
+            if (t_conn_ptr != nullptr && t_conn_ptr->isValid())
+            {
+                m_db_conn_pool.push(t_conn_ptr);
+                added_num++;
+            }
+            else
+            {
+                retry_count--;
+            }
+            
+        }
+        catch (sql::SQLException &e)
+        {
+            char buf[1024];
+            memset(buf, 0, 1024);
+            sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str());
+            std::cout << buf << std::endl;
+            retry_count--;
+        }
+    }
+    m_conn_mutex.unlock();
+    if(mb_connected)
+    {
+        return SUCCESS;
+    }else{
+        return DB_CONNECT_FAILED;
+    }
+}

+ 101 - 0
parkspace_allocation/database_controller.h

@@ -0,0 +1,101 @@
+/*
+ * @Description: 数据库操作类
+ * @Author: yct
+ * @Date: 2020-07-14 14:09:35
+ * @LastEditTime: 2020-07-18 23:57:10
+ * @LastEditors: yct
+ */ 
+#ifndef DATABASE_CONTROLLER_HH
+#define DATABASE_CONTROLLER_HH
+
+#include <mysql_driver.h>
+#include <mysql_connection.h>
+#include <cppconn/driver.h>
+#include <cppconn/exception.h>
+#include <cppconn/resultset.h>
+#include <cppconn/statement.h>
+
+#include "../tool/singleton.h"
+#include "../error_code/error_code.h"
+#include <stdio.h>
+#include <mutex>
+#include <queue>
+#include <thread>
+#include <atomic>
+#include <unistd.h>
+#include <string.h>
+#include <iostream>
+#include <cstddef>
+#include <boost/shared_ptr.hpp>
+
+
+
+#define DB_UPDATE_INTERVAL_MILLI 20000 
+
+class Database_controller : public Singleton<Database_controller>
+{
+    // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
+    friend class Singleton<Database_controller>;
+public:
+    typedef struct DB_PARAM
+    {
+        std::string connect_string;
+        std::string username;
+        std::string pass;
+        std::string db_name;
+    } db_param;
+
+    // 必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
+    Database_controller(const Database_controller &) = delete;
+    Database_controller &operator=(const Database_controller &) = delete;
+    ~Database_controller() = default;
+
+    //初始化
+    Error_manager database_controller_init(std::string ip, int port, std::string username, std::string pass, std::string db_name, int conn_size=5);
+    //反初始化
+    Error_manager database_controller_uninit();
+    //数据库连接状态
+    bool is_connected();
+    //****** 增删改查功能 *******
+    //增
+    Error_manager sql_insert(std::string sql_str);
+    //删
+    Error_manager sql_delete(std::string sql_str);
+    //改
+    Error_manager sql_update(std::string sql_str);
+    //查
+    Error_manager sql_query(std::string sql_str, boost::shared_ptr< sql::ResultSet > &query_result);
+
+private:
+    // 父类的构造函数必须保护,子类的构造函数必须私有。
+    Database_controller() = default;
+    // 守护线程,维持连接数量,以及自身状态更新
+    void database_status_update();
+    // 检查连接状态
+    Error_manager check_status();
+    // 补充连接
+    Error_manager fill_up_pool(int add_num);
+
+private:
+    //mysql驱动句柄
+    sql::Driver * m_mysql_driver;
+    //连接状态
+    std::atomic_bool mb_connected;
+    //初始化状态
+    std::atomic_bool mb_initialized;
+    //系统关闭标记
+    std::atomic_bool mb_exit;
+    //连接池访问锁
+    std::mutex m_conn_mutex;
+    //数据库连接池
+    std::queue< boost::shared_ptr< sql::Connection> > m_db_conn_pool;
+    //守护线程
+    std::thread *mp_guard_thread;
+    //连接池大小
+    int m_conn_pool_size;
+    //连接参数
+    db_param m_db_param; 
+
+};
+
+#endif // !DATABASE_CONTROLLER_HH

+ 179 - 0
parkspace_allocation/parkspace_allocation_communicator.cpp

@@ -0,0 +1,179 @@
+
+#include "parkspace_allocation_communicator.h"
+#include "parkspace_allocator.h"
+
+Parkspace_allocation_communicator::Parkspace_allocation_communicator()
+{
+}
+
+Parkspace_allocation_communicator::~Parkspace_allocation_communicator()
+{
+}
+
+//************************************* 公有函数 ****************************************
+//外部调用发送分配车位结果
+Error_manager Parkspace_allocation_communicator::send_response(Communication_message *message)
+{
+    return encapsulate_msg(message);
+}
+
+//外部调用更新所有车位信息/初始化所有车位
+Error_manager Parkspace_allocation_communicator::update_parkspace_status(message::Parkspace_allocation_status_msg status_msg)
+{
+    std::lock_guard<std::mutex> lck(m_status_mutex);
+    m_parkspace_status_msg.CopyFrom(status_msg);
+    return SUCCESS;
+}
+
+//外部调用更新单一车位信息
+Error_manager Parkspace_allocation_communicator::update_parkspace_status(int parkspace_id, message::Parkspace_info parkspace_info)
+{
+    std::lock_guard<std::mutex> lck(m_status_mutex);
+    if(m_parkspace_status_msg.parkspace_info_size() > parkspace_id)
+    {
+        m_parkspace_status_msg.mutable_parkspace_info(parkspace_id)->CopyFrom(parkspace_info);
+    }
+    return SUCCESS;
+}
+
+//外部调用获取当前车位状态消息
+message::Parkspace_allocation_status_msg Parkspace_allocation_communicator::get_status()
+{
+    std::lock_guard<std::mutex> lck(m_status_mutex);
+    message::Parkspace_allocation_status_msg parkspace_status_msg;
+    parkspace_status_msg.CopyFrom(m_parkspace_status_msg);
+    return parkspace_status_msg;
+}
+
+//************************************* 内部函数 ****************************************
+//封装反馈消息自动发送
+Error_manager Parkspace_allocation_communicator::encapsulate_msg(Communication_message *message)
+{
+    if (message == nullptr)
+    {
+        return Error_manager(POINTER_IS_NULL, NEGLIGIBLE_ERROR, "Parkspace_allocation_communicator::message null pointer");
+    }
+    //针对待发送的不同反馈消息,分别进行校核
+    switch(message->get_message_type())
+    {
+        case Communication_message::eParkspace_allocation_response_msg:
+        {
+            // message::Parkspace_allocation_response_msg response;
+            // bool result = response.ParseFromString(message->get_message_buf());
+            // //可增加待发送分配车位反馈消息校核
+            break;
+        }
+        case Communication_message::eParkspace_search_response_msg:
+        {
+            break;
+        }
+        case Communication_message::eParkspace_release_response_msg:
+        {
+            break;
+        }
+        case Communication_message::eParkspace_force_update_response_msg:
+        {
+            break;
+        }
+        case Communication_message::eParkspace_confirm_alloc_response_msg:
+        {
+            break;
+        }
+        default:
+            return Error_manager(PARKSPACE_ALLOCATOR_MSG_RESPONSE_TYPE_ERROR, NEGLIGIBLE_ERROR, "Parkspace_allocation_communicator::message response type error");
+    }
+
+    //发送请求
+    return Communication_socket_base::encapsulate_msg(message);
+}
+
+//重载执行消息,父类线程通过check_msg接收到车位分配请求后调用,解析内容并进行相应处理
+Error_manager Parkspace_allocation_communicator::execute_msg(Communication_message *p_msg)
+{
+    return Parkspace_allocator::get_instance_references().execute_msg(p_msg);
+    // return Error_manager(PARKSPACE_ALLOCATOR_MSG_RESPONSE_TYPE_ERROR, NEGLIGIBLE_ERROR, "parkspace allocation wrong request type");
+}
+
+//检查消息是否应由本模块接收
+//本模块接收车位分配请求、车位查询请求与车位释放请求
+Error_manager Parkspace_allocation_communicator::check_msg(Communication_message* p_msg)
+{
+    //通过 p_msg->get_message_type() 和 p_msg->get_receiver() 判断这条消息是不是车位请求消息.
+
+//    std::cout<<  22222222222  << std::endl;
+//    std::cout<<  "p_msg->get_receiver() = " << p_msg->get_receiver()  << std::endl;
+//    std::cout<<  "p_msg->get_message_type() = " << p_msg->get_message_type()  << std::endl;
+
+
+    if(p_msg->get_receiver() == Communication_message::Communicator::eParkspace)
+    {
+        switch(p_msg->get_message_type())
+        {
+            case Communication_message::Message_type::eParkspace_allocation_request_msg:
+                return Error_code::SUCCESS;
+            case Communication_message::Message_type::eParkspace_search_request_msg:
+                return Error_code::SUCCESS;
+            case Communication_message::Message_type::eParkspace_release_request_msg:
+                return Error_code::SUCCESS;
+            case Communication_message::Message_type::eParkspace_force_update_request_msg:
+                return Error_code::SUCCESS;
+            case Communication_message::Message_type::eParkspace_confirm_alloc_request_msg:
+                return Error_code::SUCCESS;
+            default:
+                return Error_code::INVALID_MESSAGE;
+        }
+    }
+	return Error_code::INVALID_MESSAGE;
+}
+
+Error_manager Parkspace_allocation_communicator::check_executer(Communication_message*  p_msg)
+{
+    //检查对应模块的状态, 判断是否可以处理这条消息
+	//同时也要判断是否超时, 超时返回 COMMUNICATION_ANALYSIS_TIME_OUT
+	//如果处理器正在忙别的, 那么返回 COMMUNICATION_EXCUTER_IS_BUSY
+
+	Error_manager t_error;
+	if ( p_msg->is_over_time() )
+	{
+		std::cout << "Parkspace_allocation_communicator...COMMUNICATION_ANALYSIS_TIME_OUT , " << std::endl;
+		//超时:接收方不做处理,发送方会进行超时处理
+		return Error_code::COMMUNICATION_ANALYSIS_TIME_OUT;
+	}
+	else
+	{
+		return Parkspace_allocator::get_instance_references().check_executer(p_msg);
+	}
+	return Error_code::SUCCESS;
+}
+
+//重载心跳与车位状态发送函数
+Error_manager Parkspace_allocation_communicator::encapsulate_send_data()
+{
+    // return Error_code::SUCCESS;
+    std::lock_guard<std::mutex> lck(m_status_mutex);
+    //车位信息消息赋值
+	message::Parkspace_allocation_status_msg t_parkspace_status_msg;
+    t_parkspace_status_msg.CopyFrom(m_parkspace_status_msg);
+    message::Base_info t_base_info;
+    message::Error_manager t_error;
+	t_base_info.set_msg_type(message::Message_type::eParkspace_allocation_status_msg);
+	t_base_info.set_timeout_ms(5000);
+	t_base_info.set_sender(message::Communicator::eParkspace);
+	t_base_info.set_receiver(message::Communicator::eMain);
+    t_error.set_error_code(0);
+    t_parkspace_status_msg.mutable_base_info()->CopyFrom(t_base_info);
+    t_parkspace_status_msg.mutable_error_manager()->CopyFrom(t_error);
+
+	Communication_message* tp_msg = new Communication_message(t_parkspace_status_msg.SerializeAsString());
+    //重置消息,填入头信息
+    tp_msg->reset(t_base_info, tp_msg->get_message_buf());
+	bool is_push = m_send_data_list.push(tp_msg);
+	if ( is_push == false )
+	{
+		delete(tp_msg);
+		tp_msg = NULL;
+		return Error_manager(Error_code::CONTAINER_IS_TERMINATE, Error_level::MINOR_ERROR,
+							 " Parkspace_allocation_communicator::send status error ");
+	}
+	return Error_code::SUCCESS;
+}

+ 48 - 0
parkspace_allocation/parkspace_allocation_communicator.h

@@ -0,0 +1,48 @@
+//
+// Created by zx on 2020/6/18.
+//
+
+#ifndef PARKSPACE_ALLOCATION_COMMUNICATOR_H
+#define PARKSPACE_ALLOCATION_COMMUNICATOR_H
+
+#include <mutex>
+#include "communication_socket_base.h"
+#include "singleton.h"
+
+#include "parkspace_allocation_message.pb.h"
+#include "error_code.h"
+
+class Parkspace_allocation_communicator: public Singleton<Parkspace_allocation_communicator>, public Communication_socket_base
+{
+    friend Singleton<Parkspace_allocation_communicator>;
+public:
+    virtual ~Parkspace_allocation_communicator();
+    //外部调用,反馈结果消息
+    Error_manager send_response(Communication_message* message);
+    //更新所有车位状态,现有状态将被全部覆盖,车位数量可能变动
+    Error_manager update_parkspace_status(message::Parkspace_allocation_status_msg message);
+    //更新某个车位状态,不修改车位数量,车位按编号从0开始
+    Error_manager update_parkspace_status(int parkspace_id, message::Parkspace_info parkspace_info);
+    //获取所有车位状态
+    message::Parkspace_allocation_status_msg get_status();
+
+protected:
+    Parkspace_allocation_communicator();
+    //封装反馈消息,加入队列父类自行发送
+    virtual Error_manager encapsulate_msg(Communication_message* message);
+    //解析车位分配请求消息具体内容,激活车位分配单例处理函数(不可阻塞),获得结果后由车位分配单例封装消息发送
+    virtual Error_manager execute_msg(Communication_message* p_msg);
+    //检查是否接收到本模块需要的消息,重载后父类自行调用判断
+    virtual Error_manager check_msg(Communication_message* p_msg);
+    //重载检查执行者函数,判断执行者状态
+    virtual Error_manager check_executer(Communication_message*  p_msg);
+    //心跳与车位实时信息
+    virtual Error_manager encapsulate_send_data();
+
+protected:
+    message::Parkspace_allocation_status_msg                                m_parkspace_status_msg;
+    std::mutex                                                              m_status_mutex;
+};
+
+
+#endif //PARKSPACE_ALLOCATION_COMMUNICATOR_H

+ 642 - 0
parkspace_allocation/parkspace_allocator.cpp

@@ -0,0 +1,642 @@
+/*
+ * @Description: 车位分配算法模块,使用单例模式,接收外部请求并通过调用通信块接口发送反馈
+ * @Author: yct
+ * @Date: 2020-07-10 11:02:40
+ * @LastEditTime: 2020-08-06 10:32:28
+ * @LastEditors: yct
+ */ 
+
+#include "parkspace_allocator.h"
+#include "parkspace_allocation_communicator.h"
+
+Parkspace_allocator::Parkspace_allocator()
+{
+}
+
+Parkspace_allocator::~Parkspace_allocator()
+{
+	parkspace_allocator_uninit();
+}
+
+//初始化
+Error_manager Parkspace_allocator::parkspace_allocator_init(int threads_size, parkspace_proto::database_config db_config)
+{
+    // 初始化db连接
+    mp_db_manager = Parkspace_db_manager::get_instance_pointer();
+    if(mp_db_manager == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }
+    Error_manager ec = mp_db_manager->Parkspace_db_manager_init(db_config);
+    if(ec != SUCCESS)
+    {
+        return ec;
+    }
+    // 初始化任务处理线程池
+	m_thread_pool.thread_pool_init(threads_size);
+    // 读数据库车位数据,初始化车位管理
+    message::Parkspace_allocation_status_msg all_parkspace_info;
+    ec = mp_db_manager->get_all_parkspace_info(all_parkspace_info);
+    if(ec != SUCCESS)
+    {
+        return ec;
+    }
+    Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(all_parkspace_info);
+	m_current_status = eParkspace_allocator_normal;
+	return Error_code::SUCCESS;
+}
+
+//反初始化
+Error_manager Parkspace_allocator::parkspace_allocator_uninit()
+{
+	m_thread_pool.thread_pool_uninit();
+    mp_db_manager->Parkspace_db_manager_uninit();
+	m_current_status = eParkspace_allocator_unknown;
+	return Error_code::SUCCESS;
+}
+
+//检查执行者的状态, 判断能否处理这条消息,
+Error_manager Parkspace_allocator::check_executer(Communication_message* p_msg)
+{
+	if ( p_msg == NULL )
+	{
+		return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
+							 "  POINTER IS NULL ");
+	}
+
+	Error_manager t_error = SUCCESS;
+
+	return t_error;
+}
+
+//处理消息的执行函数
+Error_manager Parkspace_allocator::execute_msg(Communication_message* p_msg)
+{
+	if ( p_msg == nullptr )
+	{
+		return Error_manager(Error_code::POINTER_IS_NULL, Error_level::MINOR_ERROR,
+							 "  POINTER IS NULL ");
+	}
+
+	std::cout<<  111111111  << std::endl;
+    std::cout<<  "p_msg->get_message_type() = "<< p_msg->get_message_type()  << std::endl;
+
+
+
+
+    switch ( p_msg->get_message_type() )
+	{
+		///车位分配请求消息
+        case Communication_message::eParkspace_allocation_request_msg:
+        {
+            message::Parkspace_allocation_request_msg request;
+            bool result = request.ParseFromString(p_msg->get_message_buf());
+            LOG(INFO)<<"allocation request, car license: "<<request.car_info().license();
+            if(!result)
+            {
+                return Error_manager(Error_code::PARKSPACE_ALLOCATOR_MSG_PARSE_ERROR, Error_level::MINOR_ERROR,
+			    					" message::Parkspace_allocation_request_msg  ParseFromString error ");
+            }
+            //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
+            m_thread_pool.enqueue(&Parkspace_allocator::execute_for_allocate, this,
+            request.car_info(), request.terminal_id(), request.command_key());
+            return SUCCESS;
+        }
+        // 车位查询请求消息
+        case Communication_message::eParkspace_search_request_msg:
+        {
+            message::Parkspace_search_request_msg request;
+            bool result = request.ParseFromString(p_msg->get_message_buf());
+            LOG(INFO)<<"search request, car license: "<<request.car_info().license();
+            if(!result)
+            {
+                return Error_manager(Error_code::PARKSPACE_ALLOCATOR_MSG_PARSE_ERROR, Error_level::MINOR_ERROR,
+			    					" message::Parkspace_search_request_msg  ParseFromString error ");
+            }
+            //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
+            m_thread_pool.enqueue(&Parkspace_allocator::execute_for_search, this, request.car_info(), request.command_key());
+            return SUCCESS;
+        }
+        // 车位释放请求消息
+        case Communication_message::eParkspace_release_request_msg:
+        {
+            message::Parkspace_release_request_msg request;
+            bool result = request.ParseFromString(p_msg->get_message_buf());
+            LOG(INFO)<<"release request, parkspace id: "<<request.release_space_info().parkspace_id();
+            if(!result)
+            {
+                return Error_manager(Error_code::PARKSPACE_ALLOCATOR_MSG_PARSE_ERROR, Error_level::MINOR_ERROR,
+			    					" message::Parkspace_release_request_msg  ParseFromString error ");
+            }
+            //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
+            m_thread_pool.enqueue(&Parkspace_allocator::execute_for_release, this, request.release_space_info(), request.command_key());
+            return SUCCESS;
+        }
+        // 车位手动更新请求消息
+        case Communication_message::eParkspace_force_update_request_msg:
+        {
+            message::Parkspace_force_update_request_msg request;
+            bool result = request.ParseFromString(p_msg->get_message_buf());
+            LOG(INFO)<<"force update request, parkspace id: "<<request.update_space_info().parkspace_id();
+            if(!result)
+            {
+                return Error_manager(Error_code::PARKSPACE_ALLOCATOR_MSG_PARSE_ERROR, Error_level::MINOR_ERROR,
+			    					" message::Parkspace_force_update_request_msg  ParseFromString error ");
+            }
+            //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
+            m_thread_pool.enqueue(&Parkspace_allocator::execute_for_force_update, this, request.update_space_info(), request.command_key());
+            return SUCCESS;
+        }
+        // 车位确认占用请求消息
+        case Communication_message::eParkspace_confirm_alloc_request_msg:
+        {
+            message::Parkspace_confirm_alloc_request_msg request;
+            bool result = request.ParseFromString(p_msg->get_message_buf());
+            LOG(INFO)<<"confirm alloc request, parkspace id: "<<request.confirm_space_info().parkspace_id();
+            if(!result)
+            {
+                return Error_manager(Error_code::PARKSPACE_ALLOCATOR_MSG_PARSE_ERROR, Error_level::MINOR_ERROR,
+			    					" message::Parkspace_force_update_request_msg  ParseFromString error ");
+            }
+            //往线程池添加执行任务, 之后会唤醒一个线程去执行他.
+            m_thread_pool.enqueue(&Parkspace_allocator::execute_for_confirm_alloc, this, request.confirm_space_info(), request.command_key());
+            return SUCCESS;
+        }
+	}
+	return Error_code::PARKSPACE_ALLOCATOR_MSG_REQUEST_TYPE_ERROR;
+}
+
+//判断是否为待机,如果已经准备好,则可以执行任务。
+bool Parkspace_allocator::is_ready()
+{
+	if ( m_current_status == eParkspace_allocator_normal && m_thread_pool.thread_is_full_load() == false )
+	{
+	    return true;
+	}
+	else
+	{
+		return false;
+	}
+}
+
+Parkspace_allocator::parkspace_allocator_status Parkspace_allocator::get_parkspace_allocator_status()
+{
+	return m_current_status;
+}
+
+// 检查车辆是否已存在,通常分配前调用
+bool Parkspace_allocator::check_car_existence(std::string license, message::Parkspace_allocation_status_msg status_msg)
+{
+    for (size_t i = 0; i < status_msg.parkspace_info_size(); i++)
+    {
+        // 找到相同号牌,且车位状态锁定或占用
+        if(status_msg.parkspace_info(i).has_car_info() 
+            && status_msg.parkspace_info(i).car_info().license() == license
+            && (status_msg.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_locked || 
+            status_msg.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_occupied))
+        {   
+            return true;
+        }
+    }
+    return false;
+}
+
+//分配车位线程函数
+void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int terminal_id, std::string command_key)
+{
+    std::lock_guard<std::mutex> lck(m_mutex);
+    LOG(INFO) << "分配";
+    //根据请求的信息反馈分配的车位,并封装发送
+    message::Parkspace_allocation_response_msg response_msg;
+    message::Base_info t_response_header;
+    t_response_header.set_msg_type(message::Message_type::eParkspace_allocation_response_msg);
+    t_response_header.set_timeout_ms(1000);
+    t_response_header.set_sender(message::Communicator::eParkspace);
+    t_response_header.set_receiver(message::Communicator::eMain);
+    message::Error_manager t_error;
+    message::Parkspace_info t_allocated_space;
+    //获取当前所有车位状态,分配车位
+    message::Parkspace_allocation_status_msg t_current_parkspace_status = Parkspace_allocation_communicator::get_instance_references().get_status();
+    int index = -1;
+    if(t_current_parkspace_status.parkspace_info_size()<=0)
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_SPACE_EMPTY);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(ERROR) << "无车位";
+    }
+    else if(check_car_existence(car_info.license(), t_current_parkspace_status))
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_CAR_ALREADY_EXIST);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(ERROR) << "车辆已存在";
+    }
+    else
+    {   
+        for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
+        {
+            // 找到高于车高且空闲车位,则分配
+            if (t_current_parkspace_status.parkspace_info(i).has_car_info() 
+            /* && t_current_parkspace_status.parkspace_info(i).height() > car_info.car_height() 
+            && t_current_parkspace_status.parkspace_info(i).width() > car_info.car_width() */
+            && t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_empty)
+            {
+                index = i;
+                break;
+            }
+        }
+        
+        if(index<0){
+            t_error.set_error_code(PARKSPACE_ALLOCATOR_ALLOCATE_FAILED);
+            t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+            t_allocated_space.CopyFrom(t_current_parkspace_status.parkspace_info(0));
+            t_allocated_space.mutable_car_info()->CopyFrom(car_info);
+            LOG(WARNING) << "分配车位失败";
+        }else{
+            t_error.set_error_code(SUCCESS);
+            t_error.set_error_level(message::Error_level::NORMAL);
+            message::Parkspace_info t_space_to_lock = t_current_parkspace_status.parkspace_info(index);
+            t_space_to_lock.set_parkspace_status(message::Parkspace_status::eParkspace_locked);
+            t_space_to_lock.mutable_car_info()->CopyFrom(car_info);
+            t_allocated_space.CopyFrom(t_space_to_lock);
+            // 分配车位后更新车位状态
+            Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(index, t_space_to_lock);
+            LOG(INFO) << "第"<<index<<"号位占用, id: "<<t_space_to_lock.parkspace_id()<<", 号牌: "<<t_space_to_lock.car_info().license();
+            // 数据库操作,修改车位状态为锁定,车辆状态为停车中
+            message::Vehicle_status t_vehicle_status = message::Vehicle_status::eVehicle_parking;
+            Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_space_to_lock);
+            if(ec != SUCCESS)
+            {
+                LOG(ERROR) << "更新db车位状态失败: "<< ec.to_string();
+            }
+            ec = Parkspace_db_manager::get_instance_references().update_vehicle_status(t_space_to_lock, t_vehicle_status);
+            if (ec != SUCCESS)
+            {
+                LOG(ERROR) << "更新db车辆状态失败: " <<ec.to_string();
+            }
+        }
+    }
+    response_msg.mutable_base_info()->CopyFrom(t_response_header);
+    response_msg.set_command_key(command_key);
+    response_msg.mutable_error_manager()->CopyFrom(t_error);
+    response_msg.mutable_allocated_space_info()->CopyFrom(t_allocated_space);
+    Communication_message response=Communication_message();
+    response.reset(t_response_header, response_msg.SerializeAsString());
+    Parkspace_allocation_communicator::get_instance_references().send_response(&response);
+}
+
+//查询车位线程函数
+void Parkspace_allocator::execute_for_search(message::Car_info car_info,std::string command_key)
+{
+    std::lock_guard<std::mutex> lck(m_mutex);
+    LOG(INFO) << "查询";
+    //根据车辆凭证信息查询车辆位置
+    message::Parkspace_search_response_msg response_msg;
+    message::Base_info t_response_header;
+    message::Error_manager t_error;
+    message::Parkspace_info t_car_position;
+    t_response_header.set_msg_type(message::Message_type::eParkspace_search_response_msg);
+    t_response_header.set_timeout_ms(1000);
+    t_response_header.set_sender(message::Communicator::eParkspace);
+    t_response_header.set_receiver(message::Communicator::eMain);
+    //获取当前所有车位状态,查询车辆位置
+    message::Parkspace_allocation_status_msg t_current_parkspace_status = Parkspace_allocation_communicator::get_instance_references().get_status();
+    int index = -1;
+    if(t_current_parkspace_status.parkspace_info_size()<=0)
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_SPACE_EMPTY);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(ERROR) << "无车位";
+    }
+    else
+    {
+        for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
+        {
+            // 找到凭证号/号牌对应车位,记录
+            if (t_current_parkspace_status.parkspace_info(i).has_car_info() 
+            && t_current_parkspace_status.parkspace_info(i).car_info().license() == car_info.license() 
+            && t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_occupied)
+            {
+                index = i;
+                break;
+            }
+        }
+        if(index<0){
+            t_error.set_error_code(PARKSPACE_ALLOCATOR_SEARCH_FAILED);
+            t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+            // 默认第一个车位
+            t_car_position.CopyFrom(t_current_parkspace_status.parkspace_info(0));
+            LOG(INFO) << "查询车位失败";
+        }else{
+            t_error.set_error_code(SUCCESS);
+            t_error.set_error_level(message::Error_level::NORMAL);
+            message::Parkspace_info t_space_searching = t_current_parkspace_status.parkspace_info(index);
+            t_car_position.CopyFrom(t_space_searching);
+            LOG(INFO) << "车辆"<<car_info.license() <<"在第"<<index<<"号位, id: "<<t_space_searching.parkspace_id();
+            // 无数据库操作
+        }
+    }
+    response_msg.mutable_base_info()->CopyFrom(t_response_header);
+    response_msg.set_command_key(command_key);
+    response_msg.mutable_error_manager()->CopyFrom(t_error);
+    response_msg.mutable_car_position()->CopyFrom(t_car_position);
+    Communication_message response=Communication_message();
+    response.reset(t_response_header, response_msg.SerializeAsString());
+    Parkspace_allocation_communicator::get_instance_references().send_response(&response);
+}
+
+//释放车位线程函数
+void Parkspace_allocator::execute_for_release(message::Parkspace_info space_info, std::string command_key)
+{
+    std::lock_guard<std::mutex> lck(m_mutex);
+    LOG(INFO) << "释放";
+    //根据车位信息定位待释放车位位置,车辆凭证号用于校验
+    message::Parkspace_release_response_msg response_msg;
+    message::Base_info t_response_header;
+    t_response_header.set_msg_type(message::eParkspace_release_response_msg);
+    t_response_header.set_sender(message::eParkspace);
+    t_response_header.set_receiver(message::eMain);
+    t_response_header.set_timeout_ms(1000);
+    message::Error_manager t_error;
+    message::Parkspace_info t_release_space;
+    //获取当前所有车位状态,找到待释放的车位
+    message::Parkspace_allocation_status_msg t_current_parkspace_status = Parkspace_allocation_communicator::get_instance_references().get_status();
+    int index = -1;
+    if(t_current_parkspace_status.parkspace_info_size()<=0)
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_SPACE_EMPTY);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(ERROR) << "无车位";
+    }
+    else if (!space_info.has_car_info())
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_RELEASE_FAILED);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(WARNING) << "传入待释放车位无车辆信息";
+    }
+    else
+    {
+        for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
+        {
+            // 找到占用或锁定的车位,且车辆信息匹配
+            if (t_current_parkspace_status.parkspace_info(i).parkspace_id() == space_info.parkspace_id()
+            && (t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_occupied
+                ||t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_locked)
+            && t_current_parkspace_status.parkspace_info(i).has_car_info()
+            && t_current_parkspace_status.parkspace_info(i).car_info().license() == space_info.car_info().license())
+            {
+                index = i;
+                break;
+            }
+        }
+        if(index<0){
+            t_error.set_error_code(PARKSPACE_ALLOCATOR_RELEASE_FAILED);
+            t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+            // 传入默认车位信息
+            t_release_space.CopyFrom(space_info);
+            LOG(WARNING) << "释放车位失败 input:"<<space_info.DebugString()<<", self:"<<t_current_parkspace_status.parkspace_info(space_info.parkspace_id()-1).DebugString();
+        }else{
+            t_error.set_error_code(SUCCESS);
+            t_error.set_error_level(message::Error_level::NORMAL);
+            message::Parkspace_info t_space_to_release = t_current_parkspace_status.parkspace_info(index);
+            t_space_to_release.set_parkspace_status(message::Parkspace_status::eParkspace_empty);
+            t_release_space.CopyFrom(t_space_to_release);
+            // 分配车位后更新车位状态
+            Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(index, t_space_to_release);
+            LOG(INFO) << "第"<<index<<"号位释放, id: "<<t_space_to_release.parkspace_id();
+            // 数据库操作,车位状态改为空闲,查询车辆状态,确定是停车失败还是取车完成
+            // 停车失败仅修改车位与车辆状态
+            // 取车完成同时还修改停车记录
+            Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_space_to_release);
+            if(ec != SUCCESS)
+            {
+                LOG(ERROR) << "更新db车位状态失败: "<< ec.to_string();
+            }
+            message::Vehicle_status t_vehicle_status = message::Vehicle_status::eVehicle_idle;
+            ec = Parkspace_db_manager::get_instance_references().update_vehicle_status(t_space_to_release, t_vehicle_status);
+            if(ec != SUCCESS)
+            {
+                LOG(ERROR) << "更新db车辆状态失败: "<< ec.to_string();
+            }
+            int t_park_record_id;
+            ec = Parkspace_db_manager::get_instance_references().query_vehicle(t_space_to_release.car_info().license(), t_vehicle_status, t_park_record_id);
+            if(ec != SUCCESS)
+            {
+                LOG(ERROR) << "查询db车辆状态失败: "<< ec.to_string();
+            }else if(t_vehicle_status == message::Vehicle_status::eVehicle_in_garage)
+            {
+                time_t tt = time(NULL);
+                tm *t = localtime(&tt);
+                char my_time_buf[255];
+                memset(my_time_buf, 0, 255);
+                sprintf(my_time_buf, "%d-%02d-%02d %02d:%02d:%02d",
+                        t->tm_year + 1900,
+                        t->tm_mon + 1,
+                        t->tm_mday,
+                        t->tm_hour,
+                        t->tm_min,
+                        t->tm_sec);
+                t_space_to_release.set_leave_time(my_time_buf);
+                ec = Parkspace_db_manager::get_instance_references().update_parking_record(t_space_to_release, t_park_record_id);
+                if(ec != SUCCESS)
+                {
+                    LOG(ERROR) << "更新db停车记录失败: "<< ec.to_string();
+                }
+            }
+        }
+    }
+    response_msg.mutable_base_info()->CopyFrom(t_response_header);
+    response_msg.set_command_key(command_key);
+    response_msg.mutable_error_manager()->CopyFrom(t_error);
+    response_msg.mutable_release_space_info()->CopyFrom(t_release_space);
+    Communication_message response=Communication_message();
+    response.reset(t_response_header, response_msg.SerializeAsString());
+    Parkspace_allocation_communicator::get_instance_references().send_response(&response);
+}
+
+//强制更新车位信息线程函数
+void Parkspace_allocator::execute_for_force_update(message::Parkspace_info space_info, std::string command_key)
+{
+    std::lock_guard<std::mutex> lck(m_mutex);
+    LOG(INFO) << "手动";
+    //根据车位信息定位待释放车位位置,车辆凭证号用于校验
+    //!!!!!此处跳过外部处理与调用的过程,直接在内部调用,发送分配结果用于测试,目前一直发布第一个车位
+    message::Parkspace_force_update_response_msg response_msg;
+    message::Base_info t_response_header;
+    t_response_header.set_msg_type(message::eParkspace_force_update_response_msg);
+    t_response_header.set_sender(message::eParkspace);
+    t_response_header.set_receiver(message::eMain);
+    t_response_header.set_timeout_ms(1000);
+    message::Error_manager t_error;
+    message::Parkspace_info t_update_space;
+    //获取当前所有车位状态,找到待释放的车位
+    message::Parkspace_allocation_status_msg t_current_parkspace_status = Parkspace_allocation_communicator::get_instance_references().get_status();
+    int index = -1;
+    if(t_current_parkspace_status.parkspace_info_size()<=0)
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_SPACE_EMPTY);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(ERROR) << "无车位";
+    }
+    else
+    {
+        // id 9999为特殊情况,复位所有车位状态
+        if (space_info.parkspace_id() == 9999)
+        {
+            t_error.set_error_code(SUCCESS);
+            t_error.set_error_level(message::Error_level::NORMAL);
+            t_update_space.CopyFrom(space_info);
+            // 复位所有车位状态
+            for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
+            {
+                t_current_parkspace_status.mutable_parkspace_info(i)->set_parkspace_status(message::Parkspace_status::eParkspace_empty);
+                t_current_parkspace_status.mutable_parkspace_info(i)->mutable_car_info()->set_license("");
+            }
+            
+            Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(t_current_parkspace_status);
+            LOG(INFO) << "所有车位已手动更新 ";
+            // 数据库操作,车位状态根据手动值进行修改
+            Error_manager ec = Parkspace_db_manager::get_instance_references().clean_all_parkspace_info();
+            if (ec != SUCCESS)
+            {
+                LOG(ERROR) << "复位db车位状态失败: " << ec.to_string();
+            }
+        }
+        else
+        {
+            for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
+            {
+                // 找到高于车高且空闲车位,则分配
+                if (t_current_parkspace_status.parkspace_info(i).parkspace_id() == space_info.parkspace_id())
+                {
+                    index = i;
+                    break;
+                }
+            }
+            if (index < 0)
+            {
+                t_error.set_error_code(PARKSPACE_ALLOCATOR_FORCE_UPDATE_FAILED);
+                t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+                t_update_space.CopyFrom(space_info);
+                LOG(WARNING) << "手动更新车位失败";
+            }
+            else
+            {
+                t_error.set_error_code(SUCCESS);
+                t_error.set_error_level(message::Error_level::NORMAL);
+                t_update_space.CopyFrom(space_info);
+                // 分配车位后更新车位状态
+                Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(index, t_update_space);
+                LOG(INFO) << "第" << index << "号位已手动更新, id: " << t_update_space.parkspace_id();
+                // 数据库操作,车位状态根据手动值进行修改
+                Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_update_space);
+                if (ec != SUCCESS)
+                {
+                    LOG(ERROR) << "更新db车位状态失败: " << ec.to_string();
+                }
+            }
+        }
+    }
+    response_msg.mutable_base_info()->CopyFrom(t_response_header);
+    response_msg.set_command_key(command_key);
+    response_msg.mutable_error_manager()->CopyFrom(t_error);
+    response_msg.mutable_update_space_info()->CopyFrom(t_update_space);
+    Communication_message response=Communication_message();
+    response.reset(t_response_header, response_msg.SerializeAsString());
+    Parkspace_allocation_communicator::get_instance_references().send_response(&response);
+}
+
+//确认分配车位线程函数
+void Parkspace_allocator::execute_for_confirm_alloc(message::Parkspace_info space_info, std::string command_key)
+{
+    std::lock_guard<std::mutex> lck(m_mutex);
+    LOG(INFO) << "确认分配";
+    //根据车位信息定位待确认占用车位
+    message::Parkspace_confirm_alloc_response_msg response_msg;
+    message::Base_info t_response_header;
+    t_response_header.set_msg_type(message::eParkspace_confirm_alloc_response_msg);
+    t_response_header.set_sender(message::eParkspace);
+    t_response_header.set_receiver(message::eMain);
+    t_response_header.set_timeout_ms(1000);
+    message::Error_manager t_error;
+    message::Parkspace_info t_confirm_space;
+    //获取当前所有车位状态,找到待释放的车位
+    message::Parkspace_allocation_status_msg t_current_parkspace_status = Parkspace_allocation_communicator::get_instance_references().get_status();
+    int index = -1;
+    if(t_current_parkspace_status.parkspace_info_size()<=0)
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_SPACE_EMPTY);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(ERROR) << "无车位";
+    }
+    else if (!space_info.has_car_info())
+    {
+        t_error.set_error_code(PARKSPACE_ALLOCATOR_PARAM_ERROR);
+        t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+        LOG(WARNING) << "传入确认占用车位无车辆信息";
+    }
+    else
+    {
+        for (size_t i = 0; i < t_current_parkspace_status.parkspace_info_size(); i++)
+        {
+            // 找到相同车位,车辆信息匹配,且车位为锁定状态
+            if (t_current_parkspace_status.parkspace_info(i).parkspace_id() == space_info.parkspace_id()
+                && t_current_parkspace_status.parkspace_info(i).parkspace_status() == message::Parkspace_status::eParkspace_locked
+                && t_current_parkspace_status.parkspace_info(i).has_car_info()
+                && t_current_parkspace_status.parkspace_info(i).car_info().license() == space_info.car_info().license())
+            {
+                index = i;
+                break;
+            }
+        }
+        if(index<0){
+            t_error.set_error_code(PARKSPACE_ALLOCATOR_CONFIRM_ALLOC_ERROR);
+            t_error.set_error_level(message::Error_level::MAJOR_ERROR);
+            t_confirm_space.CopyFrom(space_info);
+            LOG(WARNING) << "确认占用车位失败, " << t_confirm_space.DebugString()<<", self:"<<t_current_parkspace_status.parkspace_info(space_info.parkspace_id()-1).DebugString();
+        }else{
+            t_error.set_error_code(SUCCESS);
+            t_error.set_error_level(message::Error_level::NORMAL);
+            t_confirm_space.CopyFrom(space_info);
+            t_confirm_space.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+            time_t tt = time(NULL);
+            tm *t = localtime(&tt);
+            char my_time_buf[255];
+            memset(my_time_buf, 0, 255);
+            sprintf(my_time_buf, "%d-%02d-%02d %02d:%02d:%02d",
+                   t->tm_year + 1900,
+                   t->tm_mon + 1,
+                   t->tm_mday,
+                   t->tm_hour,
+                   t->tm_min,
+                   t->tm_sec);
+            t_confirm_space.set_entry_time(my_time_buf);
+            // 分配车位后更新车位状态
+            Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(index, t_confirm_space);
+            LOG(INFO) << "第" << index << "号位已确认占用, id: " << t_confirm_space.parkspace_id();
+            // 数据库操作,车位状态改为占用,插入停车记录,更新车辆状态为入库
+            Error_manager ec = Parkspace_db_manager::get_instance_references().update_parkspace_status(t_confirm_space);
+            if(ec != SUCCESS)
+            {
+                LOG(ERROR) << "更新db车位状态失败: "<< ec.to_string();
+            }
+            ec = Parkspace_db_manager::get_instance_references().insert_parking_record(t_confirm_space);
+            if(ec != SUCCESS)
+            {
+                LOG(ERROR) << "插入db停车记录失败: "<< ec.to_string();
+            }
+            message::Vehicle_status t_vehicle_status = message::Vehicle_status::eVehicle_in_garage;
+            ec = Parkspace_db_manager::get_instance_references().update_vehicle_status(t_confirm_space, t_vehicle_status);
+            if(ec != SUCCESS)
+            {
+                LOG(ERROR) << "更新db车辆状态失败: "<< ec.to_string();
+            }
+        }
+    }
+    response_msg.mutable_base_info()->CopyFrom(t_response_header);
+    response_msg.set_command_key(command_key);
+    response_msg.mutable_error_manager()->CopyFrom(t_error);
+    response_msg.mutable_confirm_alloc_space_info()->CopyFrom(t_confirm_space);
+    Communication_message response=Communication_message();
+    response.reset(t_response_header, response_msg.SerializeAsString());
+    Parkspace_allocation_communicator::get_instance_references().send_response(&response);
+}

+ 79 - 0
parkspace_allocation/parkspace_allocator.h

@@ -0,0 +1,79 @@
+/*
+ * @Description: 车位分配算法模块,使用单例模式,接收外部请求并通过调用通信块接口发送反馈
+ * @Author: yct
+ * @Date: 2020-07-10 09:25:56
+ * @LastEditTime: 2020-08-06 10:18:56
+ * @LastEditors: yct
+ */ 
+
+#ifndef PARKSPACE_ALLOCATOR_HH
+#define PARKSPACE_ALLOCATOR_HH
+
+#include "../tool/thread_pool.h"
+#include "../tool/singleton.h"
+#include "../error_code/error_code.h"
+#include "../communication/communication_message.h"
+#include "../message/parkspace_allocation_message.pb.h"
+#include "parkspace_db_manager.h"
+#include <ctime>
+
+class Parkspace_allocator : public Singleton<Parkspace_allocator>
+{
+    friend class Singleton<Parkspace_allocator>;
+public:
+    enum parkspace_allocator_status
+    {
+        eParkspace_allocator_unknown,
+        eParkspace_allocator_normal,
+        eParkspace_allocator_fault
+    };
+
+private:
+    // 父类的构造函数必须保护,子类的构造函数必须私有。
+    Parkspace_allocator();
+public:
+    // 必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
+    Parkspace_allocator(const Parkspace_allocator &) = delete;
+    Parkspace_allocator &operator=(const Parkspace_allocator &) = delete;
+    ~Parkspace_allocator();
+public://API functions
+	//初始化
+	Error_manager parkspace_allocator_init(int threads_size, parkspace_proto::database_config db_config);
+	//反初始化
+	Error_manager parkspace_allocator_uninit();
+
+	//检查执行者的状态, 判断能否处理这条消息,
+	Error_manager check_executer(Communication_message* p_msg);
+	//处理消息的执行函数
+	Error_manager execute_msg(Communication_message* p_msg);
+
+	//判断是否为待机,如果已经准备好,则可以执行任务。
+	bool is_ready();
+
+    // 获取模块状态
+    parkspace_allocator_status get_parkspace_allocator_status();
+
+    // 检查车辆是否已存在,通常分配前调用
+    bool check_car_existence(std::string license, message::Parkspace_allocation_status_msg status_msg);
+
+public://execute_msg创建各线程进行处理
+	//分配车位线程函数
+    void execute_for_allocate(message::Car_info car_info, int terminal_id,std::string command_key);
+    //查询车位线程函数
+    void execute_for_search(message::Car_info car_info,std::string command_key);
+    //释放车位线程函数
+    void execute_for_release(message::Parkspace_info space_info, std::string command_key);
+    //强制更新车位信息线程函数
+    void execute_for_force_update(message::Parkspace_info space_info, std::string command_key);
+    //确认分配车位线程函数
+    void execute_for_confirm_alloc(message::Parkspace_info space_info, std::string command_key);
+
+private:
+    parkspace_allocator_status  m_current_status;               //分配器当前状态
+	Thread_pool 				m_thread_pool;					//执行多任务的线程池
+    std::mutex                  m_mutex;                        //车位变动锁
+    Parkspace_db_manager*       mp_db_manager;                  //车位模块数据库管理句柄
+
+};
+
+#endif // !PARKSPACE_ALLOCATOR_HH

+ 660 - 0
parkspace_allocation/parkspace_db_manager.cpp

@@ -0,0 +1,660 @@
+/*
+ * @Description: 车位数据库管理
+ * @Author: yct
+ * @Date: 2020-07-19 09:57:45
+ * @LastEditTime: 2020-07-22 19:07:45
+ * @LastEditors: yct
+ */
+
+#include "parkspace_db_manager.h"
+
+// 车位数据库管理初始化
+Error_manager Parkspace_db_manager::Parkspace_db_manager_init(parkspace_proto::database_config config)
+{
+    Error_manager ec = SUCCESS;
+    mp_db_controller = boost::shared_ptr<Database_controller>(Database_controller::get_instance_pointer());
+    if(mp_db_controller != nullptr)
+    {
+        ec = mp_db_controller->database_controller_init(config.db_ip(), config.db_port(), config.db_username(), config.db_passwd(), config.db_name(), config.db_conn_pool_size());
+        mb_initialized = true;
+        return ec;
+    }
+    else
+    {
+        mb_initialized = false;
+        return POINTER_IS_NULL;
+    }
+}
+// 车位数据库管理反初始化
+Error_manager Parkspace_db_manager::Parkspace_db_manager_uninit()
+{
+    if(mp_db_controller!=nullptr)
+    {
+        return mp_db_controller->database_controller_uninit();
+    }else{
+        return POINTER_IS_NULL;
+    }
+}
+
+// 连接状态
+bool Parkspace_db_manager::is_connected()
+{
+    if(mp_db_controller!=nullptr)
+    {
+        mb_connected = mp_db_controller->is_connected();
+        return mb_connected;
+    }
+    else{
+        return false;
+    }
+}
+
+// 初始化状态
+bool Parkspace_db_manager::is_initialized()
+{
+    return mb_initialized;
+}
+
+// 从数据库获得所有车位信息,用于车位模块初始化
+Error_manager Parkspace_db_manager::get_all_parkspace_info(message::Parkspace_allocation_status_msg &all_parkspace_info)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        std::string get_all_space_sql = "select * from parkingspace";
+        boost::shared_ptr<sql::ResultSet>  tp_result = nullptr;
+        Error_manager ec = mp_db_controller->sql_query(get_all_space_sql, tp_result);
+        if(ec == SUCCESS)
+        {
+            if(tp_result == nullptr)
+            {
+                return DB_RESULT_SET_EMPTY;
+            }
+            all_parkspace_info.clear_parkspace_info();
+            while (tp_result->next())
+            {
+                message::Parkspace_info *t_parkspace = all_parkspace_info.add_parkspace_info();
+                char buf[1024];
+                memset(buf, 0, 1024);
+                try
+                {
+                    t_parkspace->set_parkspace_id(tp_result->getInt("parkingSpaceID"));
+                    t_parkspace->set_index(tp_result->getInt("parkingSpaceIndex"));
+                    if (tp_result->getInt("parkingSpaceDirection") > 0)
+                    {
+                        t_parkspace->set_direction(message::Direction::eForward);
+                    }
+                    else
+                    {
+                        t_parkspace->set_direction(message::Direction::eBackward);
+                    }
+                    t_parkspace->set_floor(tp_result->getInt("parkingSpaceFloor"));
+                    switch (tp_result->getInt("parkingSpaceState"))
+                    {
+                    case 0:
+                        t_parkspace->set_parkspace_status(message::Parkspace_status::eParkspace_empty);
+                        break;
+                    case 1:
+                        t_parkspace->set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+                        break;
+                    case 2:
+                        t_parkspace->set_parkspace_status(message::Parkspace_status::eParkspace_reserved);
+                        break;
+                    case 3:
+                        t_parkspace->set_parkspace_status(message::Parkspace_status::eParkspace_locked);
+                        break;
+                    case 4:
+                        t_parkspace->set_parkspace_status(message::Parkspace_status::eParkspace_error);
+                        break;
+                    default:
+                        t_parkspace->set_parkspace_status(message::Parkspace_status::eParkspace_error);
+                        break;
+                    }
+                    t_parkspace->set_width(tp_result->getDouble("parkSpaceWidth"));
+                    t_parkspace->set_height(tp_result->getDouble("parkSpaceHeight"));
+                    t_parkspace->mutable_car_info()->set_license(tp_result->getString("parkSpaceCarLicense"));
+                    t_parkspace->mutable_car_info()->set_car_length(tp_result->getDouble("parkSpaceCarLength"));
+                    t_parkspace->mutable_car_info()->set_car_width(tp_result->getDouble("parkSpaceCarWidth"));
+                    t_parkspace->mutable_car_info()->set_car_height(tp_result->getDouble("parkSpaceCarHeight"));
+                    t_parkspace->set_entry_time(tp_result->getString("entryTime"));
+                    t_parkspace->set_leave_time(tp_result->getString("leaveTime"));
+                }
+                catch (sql::SQLException &e)
+                {
+                    /* Use what() (derived from std::runtime_error) to fetch the error message */
+                    sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str());
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+                catch (std::runtime_error &e)
+                {
+                    sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s ", e.what(), __FILE__);
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+            }
+            return SUCCESS;
+        }
+        else
+        {
+            return ec;
+        }
+    }
+}
+
+// 清除数据库中所有车位号牌,状态全修改为空闲
+Error_manager Parkspace_db_manager::clean_all_parkspace_info()
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        char update_space_sql[1024];
+        memset(update_space_sql, 0, 1024);
+        sprintf(update_space_sql, "update parkingspace set parkingSpaceState = 0, parkSpaceCarLicense=''");
+        Error_manager ec = mp_db_controller->sql_update(update_space_sql);
+        return ec;
+    }
+    return ERROR;
+}
+
+// 更新数据库中所有车位信息
+Error_manager Parkspace_db_manager::update_all_parkspace_info(message::Parkspace_allocation_status_msg all_parkspace_info)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else if(all_parkspace_info.parkspace_info_size() >0){
+        Error_manager ec = SUCCESS;
+        for (size_t i = 0; i < all_parkspace_info.parkspace_info_size(); i++)
+        {
+            Error_manager t_ec = update_parkspace_status(all_parkspace_info.parkspace_info(i));
+            ec.compare_and_cover_error(&t_ec);
+        }
+        return ec;
+    }
+    return ERROR;
+}
+
+// 更新数据库中车位状态
+Error_manager Parkspace_db_manager::update_parkspace_status(message::Parkspace_info parkspace_info)
+{
+// 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        char update_space_sql[1024];
+        memset(update_space_sql, 0, 1024);
+        int status = -1;
+        switch (parkspace_info.parkspace_status())
+        {
+        case message::Parkspace_status::eParkspace_empty:
+            status = 0;
+            break;
+        case message::Parkspace_status::eParkspace_occupied:
+            status = 1;
+            break;
+        case message::Parkspace_status::eParkspace_reserved:
+            status = 2;
+            break;
+        case message::Parkspace_status::eParkspace_locked:
+            status = 3;
+            break;
+        case message::Parkspace_status::eParkspace_error:
+            status = 4;
+            break;
+        default:
+            break;
+        }
+        if(parkspace_info.has_car_info())
+        {
+            sprintf(update_space_sql, "update parkingspace set parkingSpaceState = %d,parkSpaceCarLicense = '%s',parkSpaceCarLength = %.3f,parkSpaceCarWidth = %.3f,parkSpaceCarHeight = %.3f,entryTime = '%s',leaveTime = '%s' where parkingSpaceID = %d",
+                    status, 
+                    parkspace_info.car_info().license().c_str(),
+                    parkspace_info.car_info().has_car_length()?parkspace_info.car_info().car_length():0.0f,
+                    parkspace_info.car_info().car_width(),
+                    parkspace_info.car_info().car_height(),
+                    parkspace_info.entry_time().c_str(),
+                    parkspace_info.leave_time().c_str(),
+                    parkspace_info.parkspace_id());
+        }else{
+            sprintf(update_space_sql, "update parkingspace set parkingSpaceState = %d where parkingSpaceID = %d", status, parkspace_info.parkspace_id());
+        }
+        if(status < 0)
+            return ERROR;
+        //boost::shared_ptr<sql::ResultSet>  tp_result = nullptr;
+        Error_manager ec = mp_db_controller->sql_update(update_space_sql);
+        return ec;
+    }
+}
+
+// 更新数据库车辆状态,车位信息中包含车辆信息用于匹配更新
+Error_manager Parkspace_db_manager::update_vehicle_status(message::Parkspace_info parkspace_info, message::Vehicle_status &vehicle_status)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        if(!parkspace_info.has_car_info())
+        {
+            return PARAMETER_ERROR;
+        }
+        std::string find_vehicle_sql = std::string("select * from vehicle where numberPlate = '").append(parkspace_info.car_info().license()).append("'");
+        boost::shared_ptr<sql::ResultSet> query_vehicle_result = nullptr;
+        mp_db_controller->sql_query(find_vehicle_sql, query_vehicle_result);
+        //判断车辆是否存在
+        if(query_vehicle_result == nullptr || !query_vehicle_result->next())
+        {
+            return insert_vehicle(parkspace_info, vehicle_status);
+        }else{
+            char update_vehicle_sql[1024];
+            memset(update_vehicle_sql, 0, 1024);
+            int vehicle_status_code = -1;
+            switch (vehicle_status)
+            {
+            case message::Vehicle_status::eVehicle_idle:
+                vehicle_status_code = 0;
+                break;
+            case message::Vehicle_status::eVehicle_in_garage:
+                vehicle_status_code = 1;
+                break;
+            case message::Vehicle_status::eVehicle_parking:
+                vehicle_status_code = 2;
+                break;
+            case message::Vehicle_status::eVehicle_fetching:
+                vehicle_status_code = 3;
+                break;
+            case message::Vehicle_status::eVehicle_reserved:
+                vehicle_status_code = 4;
+                break;
+            default:
+                break;
+            }
+            //车位为空,仅更新车辆状态与长宽高
+            if(parkspace_info.parkspace_id() <= 0)
+            {
+                sprintf(update_vehicle_sql, "update vehicle set vehicleParkState = %d,carLength=%.3f,carWidth=%.3f,carHeight=%.3f where numberPlate = '%s'", 
+                        vehicle_status_code,
+                        parkspace_info.car_info().car_length(),
+                        parkspace_info.car_info().car_width(),
+                        parkspace_info.car_info().car_height(),
+                        parkspace_info.car_info().license().c_str());
+            }
+            //车位不为空,表示车辆所在车位,同时更新
+            else
+            {
+                 sprintf(update_vehicle_sql, "update vehicle set vehicleParkState = %d,carLength=%.3f,carWidth=%.3f,carHeight=%.3f,parkingSpaceID=%d where numberPlate = '%s'", 
+                        vehicle_status_code,
+                        parkspace_info.car_info().car_length(),
+                        parkspace_info.car_info().car_width(),
+                        parkspace_info.car_info().car_height(),
+                        parkspace_info.parkspace_id(),
+                        parkspace_info.car_info().license().c_str());
+            }
+            if (vehicle_status_code < 0)
+                return ERROR;
+            Error_manager ec = mp_db_controller->sql_update(update_vehicle_sql);
+            return ec;
+        }
+    }
+}
+
+// 插入车辆
+Error_manager Parkspace_db_manager::insert_vehicle(message::Parkspace_info parkspace_info, message::Vehicle_status &vehicle_status)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        if(!parkspace_info.has_car_info())
+        {
+            return PARAMETER_ERROR;
+        }
+        char insert_vehicle_sql[1024];
+        memset(insert_vehicle_sql, 0, 1024);
+        int vehicle_status_code = -1;
+        switch (vehicle_status)
+        {
+        case message::Vehicle_status::eVehicle_idle:
+            vehicle_status_code = 0;
+            break;
+        case message::Vehicle_status::eVehicle_in_garage:
+            vehicle_status_code = 1;
+            break;
+        case message::Vehicle_status::eVehicle_parking:
+            vehicle_status_code = 2;
+            break;
+        case message::Vehicle_status::eVehicle_fetching:
+            vehicle_status_code = 3;
+            break;
+        case message::Vehicle_status::eVehicle_reserved:
+            vehicle_status_code = 4;
+            break;
+        default:
+            break;
+        }
+        //车位为空,仅更新车辆状态与长宽高
+        if(parkspace_info.parkspace_id() <= 0)
+        {
+            sprintf(insert_vehicle_sql, "INSERT INTO vehicle (numberPlate,vehicleParkState,carLength,carWidth,carHeight) values ('%s',%d,%.3f,%.3f,%.3f)", 
+                    parkspace_info.car_info().license().c_str(),
+                    vehicle_status_code,
+                    parkspace_info.car_info().car_length(),
+                    parkspace_info.car_info().car_width(),
+                    parkspace_info.car_info().car_height());
+        }
+        //车位不为空,表示车辆在车位,同时更新
+        else
+        {
+            sprintf(insert_vehicle_sql, "INSERT INTO vehicle (numberPlate,vehicleParkState,carLength,carWidth,carHeight,parkingSpaceID) values ('%s',%d,%.3f,%.3f,%.3f,%d)", 
+                parkspace_info.car_info().license().c_str(),
+                vehicle_status_code,
+                parkspace_info.car_info().car_length(),
+                parkspace_info.car_info().car_width(),
+                parkspace_info.car_info().car_height(),
+                parkspace_info.parkspace_id());
+        }
+        if (vehicle_status_code < 0)
+            return ERROR;
+        Error_manager ec = mp_db_controller->sql_insert(insert_vehicle_sql);
+        return ec;
+    }
+}
+
+// 插入停车记录
+Error_manager Parkspace_db_manager::insert_parking_record(message::Parkspace_info parkspace_info)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //参数中必须包含车辆信息与车位编号
+        if(!parkspace_info.has_car_info() || parkspace_info.parkspace_id() <= 0)
+        {
+            return PARAMETER_ERROR;
+        }
+        char insert_parking_record_sql[1024];
+        memset(insert_parking_record_sql, 0, 1024);
+        //将车辆号牌,车位ID,记录状态,停车与取车时间写入
+            sprintf(insert_parking_record_sql, "INSERT INTO parkingrecords (numberPlate,parkingSpaceID,realParkTime) values ('%s',%d,'%s')", 
+                    parkspace_info.car_info().license().c_str(),
+                    parkspace_info.parkspace_id(),
+                    parkspace_info.entry_time().c_str());
+        Error_manager ec = mp_db_controller->sql_insert(insert_parking_record_sql);
+        return ec;
+    }
+}
+
+// 更新停车记录,待计费系统加入后完善!!!
+Error_manager Parkspace_db_manager::update_parking_record(message::Parkspace_info parkspace_info, int record_id)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        if(!parkspace_info.has_car_info() || parkspace_info.parkspace_id() <= 0)
+        {
+            return PARAMETER_ERROR;
+        }
+        char update_parking_record_sql[1024];
+        memset(update_parking_record_sql, 0, 1024);
+        sprintf(update_parking_record_sql, "update parkingrecords set realGetTime='%s',parkingPrice=%d where parkingRecordsID = %d",
+                parkspace_info.leave_time().c_str(),
+                0,
+                record_id);
+        Error_manager ec = mp_db_controller->sql_update(update_parking_record_sql);
+        return ec;
+    }
+}
+
+// 根据车位编号查询车位状态
+Error_manager Parkspace_db_manager::query_parkspace(int parkspace_id, message::Parkspace_info &parkspace_info)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        std::string query_parkspace_sql = std::string("select * from parkingspace where parkspace_id=").append(std::to_string(parkspace_id));
+        boost::shared_ptr<sql::ResultSet>  tp_result = nullptr;
+        Error_manager ec = mp_db_controller->sql_query(query_parkspace_sql, tp_result);
+        if(ec == SUCCESS)
+        {
+            if(tp_result == nullptr)
+            {
+                return DB_RESULT_SET_EMPTY;
+            }
+            if (tp_result->next())
+            {
+                char buf[1024];
+                memset(buf, 0, 1024);
+                try
+                {
+                    switch (tp_result->getInt("parkingSpaceState"))
+                    {
+                    case 0:
+                        parkspace_info.set_parkspace_status(message::Parkspace_status::eParkspace_empty);
+                        break;
+                    case 1:
+                        parkspace_info.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+                        break;
+                    case 2:
+                        parkspace_info.set_parkspace_status(message::Parkspace_status::eParkspace_reserved);
+                        break;
+                    case 3:
+                        parkspace_info.set_parkspace_status(message::Parkspace_status::eParkspace_locked);
+                        break;
+                    case 4:
+                        parkspace_info.set_parkspace_status(message::Parkspace_status::eParkspace_error);
+                        break;
+                    default:
+                        parkspace_info.set_parkspace_status(message::Parkspace_status::eParkspace_error);
+                        break;
+                    }
+                    parkspace_info.set_index(tp_result->getInt("parkingSpaceIndex"));
+                    parkspace_info.set_direction(tp_result->getInt("parkingSpaceDirection") > 0 ? message::Direction::eForward : message::Direction::eBackward);
+                    parkspace_info.set_floor(tp_result->getInt("parkingSpaceFloor"));
+                    parkspace_info.mutable_car_info()->set_license(tp_result->getString("parkSpaceCarLicense"));
+                    parkspace_info.mutable_car_info()->set_car_length(tp_result->getDouble("parkSpaceCatLength"));
+                    parkspace_info.mutable_car_info()->set_car_width(tp_result->getDouble("parkSpaceCarWidth"));
+                    parkspace_info.mutable_car_info()->set_car_height(tp_result->getDouble("parkSpaceCarHeight"));
+                    parkspace_info.set_entry_time(tp_result->getString("entryTime"));
+                    parkspace_info.set_leave_time(tp_result->getString("leaveTime"));
+                }
+                catch (sql::SQLException &e)
+                {
+                    /* Use what() (derived from std::runtime_error) to fetch the error message */
+                    sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str());
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+                catch (std::runtime_error &e)
+                {
+                    sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s ", e.what(), __FILE__);
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+            }
+            return SUCCESS;
+        }
+        else
+        {
+            return ec;
+        }
+    }
+}
+
+// 查询车辆状态,暂时不使用
+Error_manager Parkspace_db_manager::query_vehicle(std::string license, message::Vehicle_status &vehicle_status, int &park_record_id)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        std::string query_parkspace_sql = std::string("select * from vehicle where numberPlate='").append(license).append("'");
+        boost::shared_ptr<sql::ResultSet>  tp_result = nullptr;
+        Error_manager ec = mp_db_controller->sql_query(query_parkspace_sql, tp_result);
+        if(ec == SUCCESS)
+        {
+            if(tp_result == nullptr)
+            {
+                return DB_RESULT_SET_EMPTY;
+            }
+            if (tp_result->next())
+            {
+                char buf[1024];
+                memset(buf, 0, 1024);
+                try
+                {
+                    switch (tp_result->getInt("vehicleParkState"))
+                    {
+                    case 0:
+                        vehicle_status = message::Vehicle_status::eVehicle_idle;
+                        break;
+                    case 1:
+                        vehicle_status = message::Vehicle_status::eVehicle_in_garage;
+                        break;
+                    case 2:
+                        vehicle_status = message::Vehicle_status::eVehicle_parking;
+                        break;
+                    case 3:
+                        vehicle_status = message::Vehicle_status::eVehicle_fetching;
+                        break;
+                    case 4:
+                        vehicle_status = message::Vehicle_status::eVehicle_reserved;
+                        break;
+                    default:
+                        vehicle_status = message::Vehicle_status::eVehicle_reserved;
+                        break;
+                    }
+                    park_record_id = tp_result->getInt("parkingRecordsID");
+                }
+                catch (sql::SQLException &e)
+                {
+                    /* Use what() (derived from std::runtime_error) to fetch the error message */
+                    sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str());
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+                catch (std::runtime_error &e)
+                {
+                    sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s ", e.what(), __FILE__);
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+            }
+            return SUCCESS;
+        }
+        else
+        {
+            return ec;
+        }
+    }
+}
+
+// 查询停车记录,根据车牌号、车位id查询,反馈停车记录id
+Error_manager Parkspace_db_manager::query_parking_record(message::Parkspace_info &parkspace_info, int &record_id)
+{
+    // 基本条件判断
+    if(!mb_initialized)
+    {
+        return DB_UNINITIALIZED;
+    }
+    if(mp_db_controller == nullptr)
+    {
+        return POINTER_IS_NULL;
+    }else{
+        //执行sql操作
+        if(!parkspace_info.has_car_info() || parkspace_info.parkspace_id() <= 0)
+        {
+            return PARAMETER_ERROR;
+        }
+        std::string query_park_record_sql = std::string("select * from parkingrecords where numberPlate='").append(parkspace_info.car_info().license()).append("' and parkingSpaceID=").append(std::to_string(parkspace_info.parkspace_id())).append(" ORDER BY parkingRecordsID DESC");
+        boost::shared_ptr<sql::ResultSet>  tp_result = nullptr;
+        Error_manager ec = mp_db_controller->sql_query(query_park_record_sql, tp_result);
+        if(ec == SUCCESS)
+        {
+            if(tp_result == nullptr)
+            {
+                return DB_RESULT_SET_EMPTY;
+            }
+            if (tp_result->next())
+            {
+                char buf[1024];
+                memset(buf, 0, 1024);
+                try
+                {
+                    record_id = tp_result->getInt("parkingRecordsID");
+                }
+                catch (sql::SQLException &e)
+                {
+                    /* Use what() (derived from std::runtime_error) to fetch the error message */
+                    sprintf(buf, "# ERR: %s\n (MySQL error code: %d, SQLState: %s", e.what(), e.getErrorCode(), e.getSQLState().c_str());
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+                catch (std::runtime_error &e)
+                {
+                    sprintf(buf, "# ERR: %s\n ERR: runtime_error in  %s ", e.what(), __FILE__);
+                    return Error_manager(DB_RESULT_SET_PARSE_ERROR, NEGLIGIBLE_ERROR, buf);
+                }
+            }
+            return SUCCESS;
+        }
+        else
+        {
+            return ec;
+        }
+    }
+}

+ 74 - 0
parkspace_allocation/parkspace_db_manager.h

@@ -0,0 +1,74 @@
+/*
+ * @Description: 车位模块数据库管理类,提供接口实现特定的数据库操作
+ * @Author: yct
+ * @Date: 2020-07-19 09:44:17
+ * @LastEditTime: 2020-07-21 16:22:12
+ * @LastEditors: yct
+ */ 
+
+#ifndef PARKSPACE_DB_MANAGER_HH
+#define PARKSPACE_DB_MANAGER_HH
+
+#include "../tool/singleton.h"
+#include "../error_code/error_code.h"
+#include "../communication/communication_message.h"
+#include "../message/parkspace_allocation_message.pb.h"
+#include "parkspace_parameter.pb.h"
+
+#include "database_controller.h"
+#include <atomic>
+
+class Parkspace_db_manager : public Singleton<Parkspace_db_manager>
+{
+    // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
+    friend class Singleton<Parkspace_db_manager>;
+
+public:
+    // 必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
+    Parkspace_db_manager(const Parkspace_db_manager &) = delete;
+    Parkspace_db_manager &operator=(const Parkspace_db_manager &) = delete;
+    ~Parkspace_db_manager() = default;
+    // 车位数据库管理初始化
+    Error_manager Parkspace_db_manager_init(parkspace_proto::database_config config);
+    // 车位数据库管理反初始化
+    Error_manager Parkspace_db_manager_uninit();
+    // 连接状态
+    bool is_connected();
+    // 初始化状态
+    bool is_initialized();
+    // ******** 数据库具体操作函数 *********
+    // 从数据库获得所有车位信息,用于车位模块初始化
+    Error_manager get_all_parkspace_info(message::Parkspace_allocation_status_msg &all_parkspace_info);
+    // 清除数据库中所有车位号牌,状态全修改为空闲
+    Error_manager clean_all_parkspace_info();
+    // 更新数据库中所有车位信息
+    Error_manager update_all_parkspace_info(message::Parkspace_allocation_status_msg all_parkspace_info);
+    // 更新数据库中车位状态
+    Error_manager update_parkspace_status(message::Parkspace_info parkspace_info);
+    // 更新数据库车辆状态,车位信息中包含车辆信息用于匹配更新
+    Error_manager update_vehicle_status(message::Parkspace_info parkspace_info, message::Vehicle_status &vehicle_status);
+    // 插入车辆
+    Error_manager insert_vehicle(message::Parkspace_info parkspace_info, message::Vehicle_status &vehicle_status);
+    // 插入停车记录
+    Error_manager insert_parking_record(message::Parkspace_info parkspace_info);
+    // 更新停车记录,待计费系统加入后完善!!!
+    Error_manager update_parking_record(message::Parkspace_info parkspace_info, int record_id);
+    // 根据车位编号查询车位状态
+    Error_manager query_parkspace(int parkspace_id, message::Parkspace_info &parkspace_info);
+    // 查询车辆状态,暂时不使用
+    Error_manager query_vehicle(std::string license, message::Vehicle_status &vehicle_status, int &park_record_id);
+    // 查询停车记录
+    Error_manager query_parking_record(message::Parkspace_info &parkspace_info, int &record_id);
+
+private:
+    // 父类的构造函数必须保护,子类的构造函数必须私有。
+    Parkspace_db_manager() = default;
+    // 数据库操作单例句柄
+    boost::shared_ptr<Database_controller> mp_db_controller;
+    // 初始化状态
+    std::atomic_bool mb_initialized;
+    // 连接状态
+    std::atomic_bool mb_connected;
+};
+
+#endif // !PARKSPACE_DB_MANAGER_HH

+ 695 - 0
parkspace_allocation/parkspace_parameter.pb.cc

@@ -0,0 +1,695 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// source: parkspace_parameter.proto
+
+#include "parkspace_parameter.pb.h"
+
+#include <algorithm>
+
+#include <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/port.h>
+#include <google/protobuf/stubs/once.h>
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/wire_format_lite_inl.h>
+#include <google/protobuf/descriptor.h>
+#include <google/protobuf/generated_message_reflection.h>
+#include <google/protobuf/reflection_ops.h>
+#include <google/protobuf/wire_format.h>
+// This is a temporary google only hack
+#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+#include "third_party/protobuf/version.h"
+#endif
+// @@protoc_insertion_point(includes)
+namespace parkspace_proto {
+class database_configDefaultTypeInternal {
+ public:
+  ::google::protobuf::internal::ExplicitlyConstructed<database_config>
+      _instance;
+} _database_config_default_instance_;
+}  // namespace parkspace_proto
+namespace protobuf_parkspace_5fparameter_2eproto {
+void InitDefaultsdatabase_configImpl() {
+  GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+#ifdef GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+  ::google::protobuf::internal::InitProtobufDefaultsForceUnique();
+#else
+  ::google::protobuf::internal::InitProtobufDefaults();
+#endif  // GOOGLE_PROTOBUF_ENFORCE_UNIQUENESS
+  {
+    void* ptr = &::parkspace_proto::_database_config_default_instance_;
+    new (ptr) ::parkspace_proto::database_config();
+    ::google::protobuf::internal::OnShutdownDestroyMessage(ptr);
+  }
+  ::parkspace_proto::database_config::InitAsDefaultInstance();
+}
+
+void InitDefaultsdatabase_config() {
+  static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+  ::google::protobuf::GoogleOnceInit(&once, &InitDefaultsdatabase_configImpl);
+}
+
+::google::protobuf::Metadata file_level_metadata[1];
+
+const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, _has_bits_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, _internal_metadata_),
+  ~0u,  // no _extensions_
+  ~0u,  // no _oneof_case_
+  ~0u,  // no _weak_field_map_
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, db_ip_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, db_port_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, db_username_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, db_passwd_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, db_name_),
+  GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(::parkspace_proto::database_config, db_conn_pool_size_),
+  0,
+  4,
+  1,
+  2,
+  3,
+  5,
+};
+static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
+  { 0, 11, sizeof(::parkspace_proto::database_config)},
+};
+
+static ::google::protobuf::Message const * const file_default_instances[] = {
+  reinterpret_cast<const ::google::protobuf::Message*>(&::parkspace_proto::_database_config_default_instance_),
+};
+
+void protobuf_AssignDescriptors() {
+  AddDescriptors();
+  ::google::protobuf::MessageFactory* factory = NULL;
+  AssignDescriptors(
+      "parkspace_parameter.proto", schemas, file_default_instances, TableStruct::offsets, factory,
+      file_level_metadata, NULL, NULL);
+}
+
+void protobuf_AssignDescriptorsOnce() {
+  static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+  ::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
+}
+
+void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
+void protobuf_RegisterTypes(const ::std::string&) {
+  protobuf_AssignDescriptorsOnce();
+  ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 1);
+}
+
+void AddDescriptorsImpl() {
+  InitDefaults();
+  static const char descriptor[] GOOGLE_PROTOBUF_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {
+      "\n\031parkspace_parameter.proto\022\017parkspace_p"
+      "roto\"\207\001\n\017database_config\022\r\n\005db_ip\030\001 \002(\t\022"
+      "\017\n\007db_port\030\002 \002(\003\022\023\n\013db_username\030\003 \002(\t\022\023\n"
+      "\tdb_passwd\030\004 \001(\t:\000\022\017\n\007db_name\030\005 \002(\t\022\031\n\021d"
+      "b_conn_pool_size\030\006 \001(\003"
+  };
+  ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
+      descriptor, 182);
+  ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
+    "parkspace_parameter.proto", &protobuf_RegisterTypes);
+}
+
+void AddDescriptors() {
+  static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
+  ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
+}
+// Force AddDescriptors() to be called at dynamic initialization time.
+struct StaticDescriptorInitializer {
+  StaticDescriptorInitializer() {
+    AddDescriptors();
+  }
+} static_descriptor_initializer;
+}  // namespace protobuf_parkspace_5fparameter_2eproto
+namespace parkspace_proto {
+
+// ===================================================================
+
+void database_config::InitAsDefaultInstance() {
+}
+#if !defined(_MSC_VER) || _MSC_VER >= 1900
+const int database_config::kDbIpFieldNumber;
+const int database_config::kDbPortFieldNumber;
+const int database_config::kDbUsernameFieldNumber;
+const int database_config::kDbPasswdFieldNumber;
+const int database_config::kDbNameFieldNumber;
+const int database_config::kDbConnPoolSizeFieldNumber;
+#endif  // !defined(_MSC_VER) || _MSC_VER >= 1900
+
+database_config::database_config()
+  : ::google::protobuf::Message(), _internal_metadata_(NULL) {
+  if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {
+    ::protobuf_parkspace_5fparameter_2eproto::InitDefaultsdatabase_config();
+  }
+  SharedCtor();
+  // @@protoc_insertion_point(constructor:parkspace_proto.database_config)
+}
+database_config::database_config(const database_config& from)
+  : ::google::protobuf::Message(),
+      _internal_metadata_(NULL),
+      _has_bits_(from._has_bits_),
+      _cached_size_(0) {
+  _internal_metadata_.MergeFrom(from._internal_metadata_);
+  db_ip_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  if (from.has_db_ip()) {
+    db_ip_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_ip_);
+  }
+  db_username_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  if (from.has_db_username()) {
+    db_username_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_username_);
+  }
+  db_passwd_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  if (from.has_db_passwd()) {
+    db_passwd_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_passwd_);
+  }
+  db_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  if (from.has_db_name()) {
+    db_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_name_);
+  }
+  ::memcpy(&db_port_, &from.db_port_,
+    static_cast<size_t>(reinterpret_cast<char*>(&db_conn_pool_size_) -
+    reinterpret_cast<char*>(&db_port_)) + sizeof(db_conn_pool_size_));
+  // @@protoc_insertion_point(copy_constructor:parkspace_proto.database_config)
+}
+
+void database_config::SharedCtor() {
+  _cached_size_ = 0;
+  db_ip_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  db_username_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  db_passwd_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  db_name_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  ::memset(&db_port_, 0, static_cast<size_t>(
+      reinterpret_cast<char*>(&db_conn_pool_size_) -
+      reinterpret_cast<char*>(&db_port_)) + sizeof(db_conn_pool_size_));
+}
+
+database_config::~database_config() {
+  // @@protoc_insertion_point(destructor:parkspace_proto.database_config)
+  SharedDtor();
+}
+
+void database_config::SharedDtor() {
+  db_ip_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  db_username_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  db_passwd_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  db_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+
+void database_config::SetCachedSize(int size) const {
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+}
+const ::google::protobuf::Descriptor* database_config::descriptor() {
+  ::protobuf_parkspace_5fparameter_2eproto::protobuf_AssignDescriptorsOnce();
+  return ::protobuf_parkspace_5fparameter_2eproto::file_level_metadata[kIndexInFileMessages].descriptor;
+}
+
+const database_config& database_config::default_instance() {
+  ::protobuf_parkspace_5fparameter_2eproto::InitDefaultsdatabase_config();
+  return *internal_default_instance();
+}
+
+database_config* database_config::New(::google::protobuf::Arena* arena) const {
+  database_config* n = new database_config;
+  if (arena != NULL) {
+    arena->Own(n);
+  }
+  return n;
+}
+
+void database_config::Clear() {
+// @@protoc_insertion_point(message_clear_start:parkspace_proto.database_config)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  // Prevent compiler warnings about cached_has_bits being unused
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  if (cached_has_bits & 15u) {
+    if (cached_has_bits & 0x00000001u) {
+      GOOGLE_DCHECK(!db_ip_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+      (*db_ip_.UnsafeRawStringPointer())->clear();
+    }
+    if (cached_has_bits & 0x00000002u) {
+      GOOGLE_DCHECK(!db_username_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+      (*db_username_.UnsafeRawStringPointer())->clear();
+    }
+    if (cached_has_bits & 0x00000004u) {
+      GOOGLE_DCHECK(!db_passwd_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+      (*db_passwd_.UnsafeRawStringPointer())->clear();
+    }
+    if (cached_has_bits & 0x00000008u) {
+      GOOGLE_DCHECK(!db_name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()));
+      (*db_name_.UnsafeRawStringPointer())->clear();
+    }
+  }
+  if (cached_has_bits & 48u) {
+    ::memset(&db_port_, 0, static_cast<size_t>(
+        reinterpret_cast<char*>(&db_conn_pool_size_) -
+        reinterpret_cast<char*>(&db_port_)) + sizeof(db_conn_pool_size_));
+  }
+  _has_bits_.Clear();
+  _internal_metadata_.Clear();
+}
+
+bool database_config::MergePartialFromCodedStream(
+    ::google::protobuf::io::CodedInputStream* input) {
+#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure
+  ::google::protobuf::uint32 tag;
+  // @@protoc_insertion_point(parse_start:parkspace_proto.database_config)
+  for (;;) {
+    ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(127u);
+    tag = p.first;
+    if (!p.second) goto handle_unusual;
+    switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) {
+      // required string db_ip = 1;
+      case 1: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_db_ip()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+            this->db_ip().data(), static_cast<int>(this->db_ip().length()),
+            ::google::protobuf::internal::WireFormat::PARSE,
+            "parkspace_proto.database_config.db_ip");
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      // required int64 db_port = 2;
+      case 2: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) {
+          set_has_db_port();
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>(
+                 input, &db_port_)));
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      // required string db_username = 3;
+      case 3: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_db_username()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+            this->db_username().data(), static_cast<int>(this->db_username().length()),
+            ::google::protobuf::internal::WireFormat::PARSE,
+            "parkspace_proto.database_config.db_username");
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      // optional string db_passwd = 4 [default = ""];
+      case 4: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_db_passwd()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+            this->db_passwd().data(), static_cast<int>(this->db_passwd().length()),
+            ::google::protobuf::internal::WireFormat::PARSE,
+            "parkspace_proto.database_config.db_passwd");
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      // required string db_name = 5;
+      case 5: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) {
+          DO_(::google::protobuf::internal::WireFormatLite::ReadString(
+                input, this->mutable_db_name()));
+          ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+            this->db_name().data(), static_cast<int>(this->db_name().length()),
+            ::google::protobuf::internal::WireFormat::PARSE,
+            "parkspace_proto.database_config.db_name");
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      // optional int64 db_conn_pool_size = 6;
+      case 6: {
+        if (static_cast< ::google::protobuf::uint8>(tag) ==
+            static_cast< ::google::protobuf::uint8>(48u /* 48 & 0xFF */)) {
+          set_has_db_conn_pool_size();
+          DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive<
+                   ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>(
+                 input, &db_conn_pool_size_)));
+        } else {
+          goto handle_unusual;
+        }
+        break;
+      }
+
+      default: {
+      handle_unusual:
+        if (tag == 0) {
+          goto success;
+        }
+        DO_(::google::protobuf::internal::WireFormat::SkipField(
+              input, tag, _internal_metadata_.mutable_unknown_fields()));
+        break;
+      }
+    }
+  }
+success:
+  // @@protoc_insertion_point(parse_success:parkspace_proto.database_config)
+  return true;
+failure:
+  // @@protoc_insertion_point(parse_failure:parkspace_proto.database_config)
+  return false;
+#undef DO_
+}
+
+void database_config::SerializeWithCachedSizes(
+    ::google::protobuf::io::CodedOutputStream* output) const {
+  // @@protoc_insertion_point(serialize_start:parkspace_proto.database_config)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  // required string db_ip = 1;
+  if (cached_has_bits & 0x00000001u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_ip().data(), static_cast<int>(this->db_ip().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_ip");
+    ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+      1, this->db_ip(), output);
+  }
+
+  // required int64 db_port = 2;
+  if (cached_has_bits & 0x00000010u) {
+    ::google::protobuf::internal::WireFormatLite::WriteInt64(2, this->db_port(), output);
+  }
+
+  // required string db_username = 3;
+  if (cached_has_bits & 0x00000002u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_username().data(), static_cast<int>(this->db_username().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_username");
+    ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+      3, this->db_username(), output);
+  }
+
+  // optional string db_passwd = 4 [default = ""];
+  if (cached_has_bits & 0x00000004u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_passwd().data(), static_cast<int>(this->db_passwd().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_passwd");
+    ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+      4, this->db_passwd(), output);
+  }
+
+  // required string db_name = 5;
+  if (cached_has_bits & 0x00000008u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_name().data(), static_cast<int>(this->db_name().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_name");
+    ::google::protobuf::internal::WireFormatLite::WriteStringMaybeAliased(
+      5, this->db_name(), output);
+  }
+
+  // optional int64 db_conn_pool_size = 6;
+  if (cached_has_bits & 0x00000020u) {
+    ::google::protobuf::internal::WireFormatLite::WriteInt64(6, this->db_conn_pool_size(), output);
+  }
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    ::google::protobuf::internal::WireFormat::SerializeUnknownFields(
+        _internal_metadata_.unknown_fields(), output);
+  }
+  // @@protoc_insertion_point(serialize_end:parkspace_proto.database_config)
+}
+
+::google::protobuf::uint8* database_config::InternalSerializeWithCachedSizesToArray(
+    bool deterministic, ::google::protobuf::uint8* target) const {
+  (void)deterministic; // Unused
+  // @@protoc_insertion_point(serialize_to_array_start:parkspace_proto.database_config)
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  cached_has_bits = _has_bits_[0];
+  // required string db_ip = 1;
+  if (cached_has_bits & 0x00000001u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_ip().data(), static_cast<int>(this->db_ip().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_ip");
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        1, this->db_ip(), target);
+  }
+
+  // required int64 db_port = 2;
+  if (cached_has_bits & 0x00000010u) {
+    target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(2, this->db_port(), target);
+  }
+
+  // required string db_username = 3;
+  if (cached_has_bits & 0x00000002u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_username().data(), static_cast<int>(this->db_username().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_username");
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        3, this->db_username(), target);
+  }
+
+  // optional string db_passwd = 4 [default = ""];
+  if (cached_has_bits & 0x00000004u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_passwd().data(), static_cast<int>(this->db_passwd().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_passwd");
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        4, this->db_passwd(), target);
+  }
+
+  // required string db_name = 5;
+  if (cached_has_bits & 0x00000008u) {
+    ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField(
+      this->db_name().data(), static_cast<int>(this->db_name().length()),
+      ::google::protobuf::internal::WireFormat::SERIALIZE,
+      "parkspace_proto.database_config.db_name");
+    target =
+      ::google::protobuf::internal::WireFormatLite::WriteStringToArray(
+        5, this->db_name(), target);
+  }
+
+  // optional int64 db_conn_pool_size = 6;
+  if (cached_has_bits & 0x00000020u) {
+    target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(6, this->db_conn_pool_size(), target);
+  }
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(
+        _internal_metadata_.unknown_fields(), target);
+  }
+  // @@protoc_insertion_point(serialize_to_array_end:parkspace_proto.database_config)
+  return target;
+}
+
+size_t database_config::RequiredFieldsByteSizeFallback() const {
+// @@protoc_insertion_point(required_fields_byte_size_fallback_start:parkspace_proto.database_config)
+  size_t total_size = 0;
+
+  if (has_db_ip()) {
+    // required string db_ip = 1;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->db_ip());
+  }
+
+  if (has_db_username()) {
+    // required string db_username = 3;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->db_username());
+  }
+
+  if (has_db_name()) {
+    // required string db_name = 5;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->db_name());
+  }
+
+  if (has_db_port()) {
+    // required int64 db_port = 2;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::Int64Size(
+        this->db_port());
+  }
+
+  return total_size;
+}
+size_t database_config::ByteSizeLong() const {
+// @@protoc_insertion_point(message_byte_size_start:parkspace_proto.database_config)
+  size_t total_size = 0;
+
+  if (_internal_metadata_.have_unknown_fields()) {
+    total_size +=
+      ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(
+        _internal_metadata_.unknown_fields());
+  }
+  if (((_has_bits_[0] & 0x0000001b) ^ 0x0000001b) == 0) {  // All required fields are present.
+    // required string db_ip = 1;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->db_ip());
+
+    // required string db_username = 3;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->db_username());
+
+    // required string db_name = 5;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->db_name());
+
+    // required int64 db_port = 2;
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::Int64Size(
+        this->db_port());
+
+  } else {
+    total_size += RequiredFieldsByteSizeFallback();
+  }
+  // optional string db_passwd = 4 [default = ""];
+  if (has_db_passwd()) {
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::StringSize(
+        this->db_passwd());
+  }
+
+  // optional int64 db_conn_pool_size = 6;
+  if (has_db_conn_pool_size()) {
+    total_size += 1 +
+      ::google::protobuf::internal::WireFormatLite::Int64Size(
+        this->db_conn_pool_size());
+  }
+
+  int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);
+  GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();
+  _cached_size_ = cached_size;
+  GOOGLE_SAFE_CONCURRENT_WRITES_END();
+  return total_size;
+}
+
+void database_config::MergeFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_merge_from_start:parkspace_proto.database_config)
+  GOOGLE_DCHECK_NE(&from, this);
+  const database_config* source =
+      ::google::protobuf::internal::DynamicCastToGenerated<const database_config>(
+          &from);
+  if (source == NULL) {
+  // @@protoc_insertion_point(generalized_merge_from_cast_fail:parkspace_proto.database_config)
+    ::google::protobuf::internal::ReflectionOps::Merge(from, this);
+  } else {
+  // @@protoc_insertion_point(generalized_merge_from_cast_success:parkspace_proto.database_config)
+    MergeFrom(*source);
+  }
+}
+
+void database_config::MergeFrom(const database_config& from) {
+// @@protoc_insertion_point(class_specific_merge_from_start:parkspace_proto.database_config)
+  GOOGLE_DCHECK_NE(&from, this);
+  _internal_metadata_.MergeFrom(from._internal_metadata_);
+  ::google::protobuf::uint32 cached_has_bits = 0;
+  (void) cached_has_bits;
+
+  cached_has_bits = from._has_bits_[0];
+  if (cached_has_bits & 63u) {
+    if (cached_has_bits & 0x00000001u) {
+      set_has_db_ip();
+      db_ip_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_ip_);
+    }
+    if (cached_has_bits & 0x00000002u) {
+      set_has_db_username();
+      db_username_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_username_);
+    }
+    if (cached_has_bits & 0x00000004u) {
+      set_has_db_passwd();
+      db_passwd_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_passwd_);
+    }
+    if (cached_has_bits & 0x00000008u) {
+      set_has_db_name();
+      db_name_.AssignWithDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), from.db_name_);
+    }
+    if (cached_has_bits & 0x00000010u) {
+      db_port_ = from.db_port_;
+    }
+    if (cached_has_bits & 0x00000020u) {
+      db_conn_pool_size_ = from.db_conn_pool_size_;
+    }
+    _has_bits_[0] |= cached_has_bits;
+  }
+}
+
+void database_config::CopyFrom(const ::google::protobuf::Message& from) {
+// @@protoc_insertion_point(generalized_copy_from_start:parkspace_proto.database_config)
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+void database_config::CopyFrom(const database_config& from) {
+// @@protoc_insertion_point(class_specific_copy_from_start:parkspace_proto.database_config)
+  if (&from == this) return;
+  Clear();
+  MergeFrom(from);
+}
+
+bool database_config::IsInitialized() const {
+  if ((_has_bits_[0] & 0x0000001b) != 0x0000001b) return false;
+  return true;
+}
+
+void database_config::Swap(database_config* other) {
+  if (other == this) return;
+  InternalSwap(other);
+}
+void database_config::InternalSwap(database_config* other) {
+  using std::swap;
+  db_ip_.Swap(&other->db_ip_);
+  db_username_.Swap(&other->db_username_);
+  db_passwd_.Swap(&other->db_passwd_);
+  db_name_.Swap(&other->db_name_);
+  swap(db_port_, other->db_port_);
+  swap(db_conn_pool_size_, other->db_conn_pool_size_);
+  swap(_has_bits_[0], other->_has_bits_[0]);
+  _internal_metadata_.Swap(&other->_internal_metadata_);
+  swap(_cached_size_, other->_cached_size_);
+}
+
+::google::protobuf::Metadata database_config::GetMetadata() const {
+  protobuf_parkspace_5fparameter_2eproto::protobuf_AssignDescriptorsOnce();
+  return ::protobuf_parkspace_5fparameter_2eproto::file_level_metadata[kIndexInFileMessages];
+}
+
+
+// @@protoc_insertion_point(namespace_scope)
+}  // namespace parkspace_proto
+
+// @@protoc_insertion_point(global_scope)

+ 574 - 0
parkspace_allocation/parkspace_parameter.pb.h

@@ -0,0 +1,574 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// source: parkspace_parameter.proto
+
+#ifndef PROTOBUF_parkspace_5fparameter_2eproto__INCLUDED
+#define PROTOBUF_parkspace_5fparameter_2eproto__INCLUDED
+
+#include <string>
+
+#include <google/protobuf/stubs/common.h>
+
+#if GOOGLE_PROTOBUF_VERSION < 3005000
+#error This file was generated by a newer version of protoc which is
+#error incompatible with your Protocol Buffer headers.  Please update
+#error your headers.
+#endif
+#if 3005000 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
+#error This file was generated by an older version of protoc which is
+#error incompatible with your Protocol Buffer headers.  Please
+#error regenerate this file with a newer version of protoc.
+#endif
+
+#include <google/protobuf/io/coded_stream.h>
+#include <google/protobuf/arena.h>
+#include <google/protobuf/arenastring.h>
+#include <google/protobuf/generated_message_table_driven.h>
+#include <google/protobuf/generated_message_util.h>
+#include <google/protobuf/metadata.h>
+#include <google/protobuf/message.h>
+#include <google/protobuf/repeated_field.h>  // IWYU pragma: export
+#include <google/protobuf/extension_set.h>  // IWYU pragma: export
+#include <google/protobuf/unknown_field_set.h>
+// @@protoc_insertion_point(includes)
+
+namespace protobuf_parkspace_5fparameter_2eproto {
+// Internal implementation detail -- do not use these members.
+struct TableStruct {
+  static const ::google::protobuf::internal::ParseTableField entries[];
+  static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
+  static const ::google::protobuf::internal::ParseTable schema[1];
+  static const ::google::protobuf::internal::FieldMetadata field_metadata[];
+  static const ::google::protobuf::internal::SerializationTable serialization_table[];
+  static const ::google::protobuf::uint32 offsets[];
+};
+void AddDescriptors();
+void InitDefaultsdatabase_configImpl();
+void InitDefaultsdatabase_config();
+inline void InitDefaults() {
+  InitDefaultsdatabase_config();
+}
+}  // namespace protobuf_parkspace_5fparameter_2eproto
+namespace parkspace_proto {
+class database_config;
+class database_configDefaultTypeInternal;
+extern database_configDefaultTypeInternal _database_config_default_instance_;
+}  // namespace parkspace_proto
+namespace parkspace_proto {
+
+// ===================================================================
+
+class database_config : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:parkspace_proto.database_config) */ {
+ public:
+  database_config();
+  virtual ~database_config();
+
+  database_config(const database_config& from);
+
+  inline database_config& operator=(const database_config& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  database_config(database_config&& from) noexcept
+    : database_config() {
+    *this = ::std::move(from);
+  }
+
+  inline database_config& operator=(database_config&& from) noexcept {
+    if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {
+      if (this != &from) InternalSwap(&from);
+    } else {
+      CopyFrom(from);
+    }
+    return *this;
+  }
+  #endif
+  inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
+    return _internal_metadata_.unknown_fields();
+  }
+  inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
+    return _internal_metadata_.mutable_unknown_fields();
+  }
+
+  static const ::google::protobuf::Descriptor* descriptor();
+  static const database_config& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const database_config* internal_default_instance() {
+    return reinterpret_cast<const database_config*>(
+               &_database_config_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    0;
+
+  void Swap(database_config* other);
+  friend void swap(database_config& a, database_config& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline database_config* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  database_config* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL;
+  void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+  void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL;
+  void CopyFrom(const database_config& from);
+  void MergeFrom(const database_config& from);
+  void Clear() PROTOBUF_FINAL;
+  bool IsInitialized() const PROTOBUF_FINAL;
+
+  size_t ByteSizeLong() const PROTOBUF_FINAL;
+  bool MergePartialFromCodedStream(
+      ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL;
+  void SerializeWithCachedSizes(
+      ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;
+  ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray(
+      bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL;
+  int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; }
+  private:
+  void SharedCtor();
+  void SharedDtor();
+  void SetCachedSize(int size) const PROTOBUF_FINAL;
+  void InternalSwap(database_config* other);
+  private:
+  inline ::google::protobuf::Arena* GetArenaNoVirtual() const {
+    return NULL;
+  }
+  inline void* MaybeArenaPtr() const {
+    return NULL;
+  }
+  public:
+
+  ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL;
+
+  // nested types ----------------------------------------------------
+
+  // accessors -------------------------------------------------------
+
+  // required string db_ip = 1;
+  bool has_db_ip() const;
+  void clear_db_ip();
+  static const int kDbIpFieldNumber = 1;
+  const ::std::string& db_ip() const;
+  void set_db_ip(const ::std::string& value);
+  #if LANG_CXX11
+  void set_db_ip(::std::string&& value);
+  #endif
+  void set_db_ip(const char* value);
+  void set_db_ip(const char* value, size_t size);
+  ::std::string* mutable_db_ip();
+  ::std::string* release_db_ip();
+  void set_allocated_db_ip(::std::string* db_ip);
+
+  // required string db_username = 3;
+  bool has_db_username() const;
+  void clear_db_username();
+  static const int kDbUsernameFieldNumber = 3;
+  const ::std::string& db_username() const;
+  void set_db_username(const ::std::string& value);
+  #if LANG_CXX11
+  void set_db_username(::std::string&& value);
+  #endif
+  void set_db_username(const char* value);
+  void set_db_username(const char* value, size_t size);
+  ::std::string* mutable_db_username();
+  ::std::string* release_db_username();
+  void set_allocated_db_username(::std::string* db_username);
+
+  // optional string db_passwd = 4 [default = ""];
+  bool has_db_passwd() const;
+  void clear_db_passwd();
+  static const int kDbPasswdFieldNumber = 4;
+  const ::std::string& db_passwd() const;
+  void set_db_passwd(const ::std::string& value);
+  #if LANG_CXX11
+  void set_db_passwd(::std::string&& value);
+  #endif
+  void set_db_passwd(const char* value);
+  void set_db_passwd(const char* value, size_t size);
+  ::std::string* mutable_db_passwd();
+  ::std::string* release_db_passwd();
+  void set_allocated_db_passwd(::std::string* db_passwd);
+
+  // required string db_name = 5;
+  bool has_db_name() const;
+  void clear_db_name();
+  static const int kDbNameFieldNumber = 5;
+  const ::std::string& db_name() const;
+  void set_db_name(const ::std::string& value);
+  #if LANG_CXX11
+  void set_db_name(::std::string&& value);
+  #endif
+  void set_db_name(const char* value);
+  void set_db_name(const char* value, size_t size);
+  ::std::string* mutable_db_name();
+  ::std::string* release_db_name();
+  void set_allocated_db_name(::std::string* db_name);
+
+  // required int64 db_port = 2;
+  bool has_db_port() const;
+  void clear_db_port();
+  static const int kDbPortFieldNumber = 2;
+  ::google::protobuf::int64 db_port() const;
+  void set_db_port(::google::protobuf::int64 value);
+
+  // optional int64 db_conn_pool_size = 6;
+  bool has_db_conn_pool_size() const;
+  void clear_db_conn_pool_size();
+  static const int kDbConnPoolSizeFieldNumber = 6;
+  ::google::protobuf::int64 db_conn_pool_size() const;
+  void set_db_conn_pool_size(::google::protobuf::int64 value);
+
+  // @@protoc_insertion_point(class_scope:parkspace_proto.database_config)
+ private:
+  void set_has_db_ip();
+  void clear_has_db_ip();
+  void set_has_db_port();
+  void clear_has_db_port();
+  void set_has_db_username();
+  void clear_has_db_username();
+  void set_has_db_passwd();
+  void clear_has_db_passwd();
+  void set_has_db_name();
+  void clear_has_db_name();
+  void set_has_db_conn_pool_size();
+  void clear_has_db_conn_pool_size();
+
+  // helper for ByteSizeLong()
+  size_t RequiredFieldsByteSizeFallback() const;
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::google::protobuf::internal::ArenaStringPtr db_ip_;
+  ::google::protobuf::internal::ArenaStringPtr db_username_;
+  ::google::protobuf::internal::ArenaStringPtr db_passwd_;
+  ::google::protobuf::internal::ArenaStringPtr db_name_;
+  ::google::protobuf::int64 db_port_;
+  ::google::protobuf::int64 db_conn_pool_size_;
+  friend struct ::protobuf_parkspace_5fparameter_2eproto::TableStruct;
+  friend void ::protobuf_parkspace_5fparameter_2eproto::InitDefaultsdatabase_configImpl();
+};
+// ===================================================================
+
+
+// ===================================================================
+
+#ifdef __GNUC__
+  #pragma GCC diagnostic push
+  #pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif  // __GNUC__
+// database_config
+
+// required string db_ip = 1;
+inline bool database_config::has_db_ip() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void database_config::set_has_db_ip() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void database_config::clear_has_db_ip() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline void database_config::clear_db_ip() {
+  db_ip_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  clear_has_db_ip();
+}
+inline const ::std::string& database_config::db_ip() const {
+  // @@protoc_insertion_point(field_get:parkspace_proto.database_config.db_ip)
+  return db_ip_.GetNoArena();
+}
+inline void database_config::set_db_ip(const ::std::string& value) {
+  set_has_db_ip();
+  db_ip_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+  // @@protoc_insertion_point(field_set:parkspace_proto.database_config.db_ip)
+}
+#if LANG_CXX11
+inline void database_config::set_db_ip(::std::string&& value) {
+  set_has_db_ip();
+  db_ip_.SetNoArena(
+    &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+  // @@protoc_insertion_point(field_set_rvalue:parkspace_proto.database_config.db_ip)
+}
+#endif
+inline void database_config::set_db_ip(const char* value) {
+  GOOGLE_DCHECK(value != NULL);
+  set_has_db_ip();
+  db_ip_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+  // @@protoc_insertion_point(field_set_char:parkspace_proto.database_config.db_ip)
+}
+inline void database_config::set_db_ip(const char* value, size_t size) {
+  set_has_db_ip();
+  db_ip_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+      ::std::string(reinterpret_cast<const char*>(value), size));
+  // @@protoc_insertion_point(field_set_pointer:parkspace_proto.database_config.db_ip)
+}
+inline ::std::string* database_config::mutable_db_ip() {
+  set_has_db_ip();
+  // @@protoc_insertion_point(field_mutable:parkspace_proto.database_config.db_ip)
+  return db_ip_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* database_config::release_db_ip() {
+  // @@protoc_insertion_point(field_release:parkspace_proto.database_config.db_ip)
+  clear_has_db_ip();
+  return db_ip_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void database_config::set_allocated_db_ip(::std::string* db_ip) {
+  if (db_ip != NULL) {
+    set_has_db_ip();
+  } else {
+    clear_has_db_ip();
+  }
+  db_ip_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), db_ip);
+  // @@protoc_insertion_point(field_set_allocated:parkspace_proto.database_config.db_ip)
+}
+
+// required int64 db_port = 2;
+inline bool database_config::has_db_port() const {
+  return (_has_bits_[0] & 0x00000010u) != 0;
+}
+inline void database_config::set_has_db_port() {
+  _has_bits_[0] |= 0x00000010u;
+}
+inline void database_config::clear_has_db_port() {
+  _has_bits_[0] &= ~0x00000010u;
+}
+inline void database_config::clear_db_port() {
+  db_port_ = GOOGLE_LONGLONG(0);
+  clear_has_db_port();
+}
+inline ::google::protobuf::int64 database_config::db_port() const {
+  // @@protoc_insertion_point(field_get:parkspace_proto.database_config.db_port)
+  return db_port_;
+}
+inline void database_config::set_db_port(::google::protobuf::int64 value) {
+  set_has_db_port();
+  db_port_ = value;
+  // @@protoc_insertion_point(field_set:parkspace_proto.database_config.db_port)
+}
+
+// required string db_username = 3;
+inline bool database_config::has_db_username() const {
+  return (_has_bits_[0] & 0x00000002u) != 0;
+}
+inline void database_config::set_has_db_username() {
+  _has_bits_[0] |= 0x00000002u;
+}
+inline void database_config::clear_has_db_username() {
+  _has_bits_[0] &= ~0x00000002u;
+}
+inline void database_config::clear_db_username() {
+  db_username_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  clear_has_db_username();
+}
+inline const ::std::string& database_config::db_username() const {
+  // @@protoc_insertion_point(field_get:parkspace_proto.database_config.db_username)
+  return db_username_.GetNoArena();
+}
+inline void database_config::set_db_username(const ::std::string& value) {
+  set_has_db_username();
+  db_username_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+  // @@protoc_insertion_point(field_set:parkspace_proto.database_config.db_username)
+}
+#if LANG_CXX11
+inline void database_config::set_db_username(::std::string&& value) {
+  set_has_db_username();
+  db_username_.SetNoArena(
+    &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+  // @@protoc_insertion_point(field_set_rvalue:parkspace_proto.database_config.db_username)
+}
+#endif
+inline void database_config::set_db_username(const char* value) {
+  GOOGLE_DCHECK(value != NULL);
+  set_has_db_username();
+  db_username_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+  // @@protoc_insertion_point(field_set_char:parkspace_proto.database_config.db_username)
+}
+inline void database_config::set_db_username(const char* value, size_t size) {
+  set_has_db_username();
+  db_username_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+      ::std::string(reinterpret_cast<const char*>(value), size));
+  // @@protoc_insertion_point(field_set_pointer:parkspace_proto.database_config.db_username)
+}
+inline ::std::string* database_config::mutable_db_username() {
+  set_has_db_username();
+  // @@protoc_insertion_point(field_mutable:parkspace_proto.database_config.db_username)
+  return db_username_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* database_config::release_db_username() {
+  // @@protoc_insertion_point(field_release:parkspace_proto.database_config.db_username)
+  clear_has_db_username();
+  return db_username_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void database_config::set_allocated_db_username(::std::string* db_username) {
+  if (db_username != NULL) {
+    set_has_db_username();
+  } else {
+    clear_has_db_username();
+  }
+  db_username_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), db_username);
+  // @@protoc_insertion_point(field_set_allocated:parkspace_proto.database_config.db_username)
+}
+
+// optional string db_passwd = 4 [default = ""];
+inline bool database_config::has_db_passwd() const {
+  return (_has_bits_[0] & 0x00000004u) != 0;
+}
+inline void database_config::set_has_db_passwd() {
+  _has_bits_[0] |= 0x00000004u;
+}
+inline void database_config::clear_has_db_passwd() {
+  _has_bits_[0] &= ~0x00000004u;
+}
+inline void database_config::clear_db_passwd() {
+  db_passwd_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  clear_has_db_passwd();
+}
+inline const ::std::string& database_config::db_passwd() const {
+  // @@protoc_insertion_point(field_get:parkspace_proto.database_config.db_passwd)
+  return db_passwd_.GetNoArena();
+}
+inline void database_config::set_db_passwd(const ::std::string& value) {
+  set_has_db_passwd();
+  db_passwd_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+  // @@protoc_insertion_point(field_set:parkspace_proto.database_config.db_passwd)
+}
+#if LANG_CXX11
+inline void database_config::set_db_passwd(::std::string&& value) {
+  set_has_db_passwd();
+  db_passwd_.SetNoArena(
+    &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+  // @@protoc_insertion_point(field_set_rvalue:parkspace_proto.database_config.db_passwd)
+}
+#endif
+inline void database_config::set_db_passwd(const char* value) {
+  GOOGLE_DCHECK(value != NULL);
+  set_has_db_passwd();
+  db_passwd_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+  // @@protoc_insertion_point(field_set_char:parkspace_proto.database_config.db_passwd)
+}
+inline void database_config::set_db_passwd(const char* value, size_t size) {
+  set_has_db_passwd();
+  db_passwd_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+      ::std::string(reinterpret_cast<const char*>(value), size));
+  // @@protoc_insertion_point(field_set_pointer:parkspace_proto.database_config.db_passwd)
+}
+inline ::std::string* database_config::mutable_db_passwd() {
+  set_has_db_passwd();
+  // @@protoc_insertion_point(field_mutable:parkspace_proto.database_config.db_passwd)
+  return db_passwd_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* database_config::release_db_passwd() {
+  // @@protoc_insertion_point(field_release:parkspace_proto.database_config.db_passwd)
+  clear_has_db_passwd();
+  return db_passwd_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void database_config::set_allocated_db_passwd(::std::string* db_passwd) {
+  if (db_passwd != NULL) {
+    set_has_db_passwd();
+  } else {
+    clear_has_db_passwd();
+  }
+  db_passwd_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), db_passwd);
+  // @@protoc_insertion_point(field_set_allocated:parkspace_proto.database_config.db_passwd)
+}
+
+// required string db_name = 5;
+inline bool database_config::has_db_name() const {
+  return (_has_bits_[0] & 0x00000008u) != 0;
+}
+inline void database_config::set_has_db_name() {
+  _has_bits_[0] |= 0x00000008u;
+}
+inline void database_config::clear_has_db_name() {
+  _has_bits_[0] &= ~0x00000008u;
+}
+inline void database_config::clear_db_name() {
+  db_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+  clear_has_db_name();
+}
+inline const ::std::string& database_config::db_name() const {
+  // @@protoc_insertion_point(field_get:parkspace_proto.database_config.db_name)
+  return db_name_.GetNoArena();
+}
+inline void database_config::set_db_name(const ::std::string& value) {
+  set_has_db_name();
+  db_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value);
+  // @@protoc_insertion_point(field_set:parkspace_proto.database_config.db_name)
+}
+#if LANG_CXX11
+inline void database_config::set_db_name(::std::string&& value) {
+  set_has_db_name();
+  db_name_.SetNoArena(
+    &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value));
+  // @@protoc_insertion_point(field_set_rvalue:parkspace_proto.database_config.db_name)
+}
+#endif
+inline void database_config::set_db_name(const char* value) {
+  GOOGLE_DCHECK(value != NULL);
+  set_has_db_name();
+  db_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::string(value));
+  // @@protoc_insertion_point(field_set_char:parkspace_proto.database_config.db_name)
+}
+inline void database_config::set_db_name(const char* value, size_t size) {
+  set_has_db_name();
+  db_name_.SetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(),
+      ::std::string(reinterpret_cast<const char*>(value), size));
+  // @@protoc_insertion_point(field_set_pointer:parkspace_proto.database_config.db_name)
+}
+inline ::std::string* database_config::mutable_db_name() {
+  set_has_db_name();
+  // @@protoc_insertion_point(field_mutable:parkspace_proto.database_config.db_name)
+  return db_name_.MutableNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline ::std::string* database_config::release_db_name() {
+  // @@protoc_insertion_point(field_release:parkspace_proto.database_config.db_name)
+  clear_has_db_name();
+  return db_name_.ReleaseNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
+}
+inline void database_config::set_allocated_db_name(::std::string* db_name) {
+  if (db_name != NULL) {
+    set_has_db_name();
+  } else {
+    clear_has_db_name();
+  }
+  db_name_.SetAllocatedNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), db_name);
+  // @@protoc_insertion_point(field_set_allocated:parkspace_proto.database_config.db_name)
+}
+
+// optional int64 db_conn_pool_size = 6;
+inline bool database_config::has_db_conn_pool_size() const {
+  return (_has_bits_[0] & 0x00000020u) != 0;
+}
+inline void database_config::set_has_db_conn_pool_size() {
+  _has_bits_[0] |= 0x00000020u;
+}
+inline void database_config::clear_has_db_conn_pool_size() {
+  _has_bits_[0] &= ~0x00000020u;
+}
+inline void database_config::clear_db_conn_pool_size() {
+  db_conn_pool_size_ = GOOGLE_LONGLONG(0);
+  clear_has_db_conn_pool_size();
+}
+inline ::google::protobuf::int64 database_config::db_conn_pool_size() const {
+  // @@protoc_insertion_point(field_get:parkspace_proto.database_config.db_conn_pool_size)
+  return db_conn_pool_size_;
+}
+inline void database_config::set_db_conn_pool_size(::google::protobuf::int64 value) {
+  set_has_db_conn_pool_size();
+  db_conn_pool_size_ = value;
+  // @@protoc_insertion_point(field_set:parkspace_proto.database_config.db_conn_pool_size)
+}
+
+#ifdef __GNUC__
+  #pragma GCC diagnostic pop
+#endif  // __GNUC__
+
+// @@protoc_insertion_point(namespace_scope)
+
+}  // namespace parkspace_proto
+
+// @@protoc_insertion_point(global_scope)
+
+#endif  // PROTOBUF_parkspace_5fparameter_2eproto__INCLUDED

+ 12 - 0
parkspace_allocation/parkspace_parameter.proto

@@ -0,0 +1,12 @@
+syntax = "proto2";
+package parkspace_proto;
+
+message database_config
+{
+    required string db_ip=1;
+    required int64 db_port=2;
+    required string db_username=3;
+    optional string db_passwd=4[default=""];
+    required string db_name=5;
+    optional int64 db_conn_pool_size=6;
+}

+ 8 - 0
proto.sh

@@ -0,0 +1,8 @@
+protoc -I=./message message_base.proto --cpp_out=./message
+#protoc -I=./message measure_message.proto --cpp_out=./message
+#protoc -I=./message hardware_message.proto --cpp_out=./message
+protoc -I=./message parkspace_allocation_message.proto --cpp_out=./message
+#protoc -I=./ setting.proto --cpp_out=./
+protoc -I=./parkspace_allocation parkspace_parameter.proto --cpp_out=./parkspace_allocation
+
+protoc -I=./communication communication.proto --cpp_out=./communication

+ 17 - 0
setting/communication.prototxt

@@ -0,0 +1,17 @@
+
+
+communication_parameters
+{
+
+#   bind_string:"tcp://192.168.2.166:9000"
+ #  connect_string_vector:"tcp://192.168.2.166:9001"
+ # connect_string_vector:"tcp://192.168.2.166:9002"
+
+  # connect_string_vector:"tcp://192.168.2.125:9876"
+  # connect_string_vector:"tcp://192.168.2.166:1234"
+
+   bind_string:"tcp://192.168.2.166:4444"
+
+
+}
+

+ 54 - 0
test/db_test.cpp

@@ -0,0 +1,54 @@
+/*
+ * @Description: 数据库测试
+ * @Author: yct
+ * @Date: 2020-07-18 21:46:45
+ * @LastEditTime: 2020-07-20 14:56:48
+ * @LastEditors: yct
+ */ 
+
+#include "../parkspace_allocation/database_controller.h"
+using std::cout;
+using std::endl;
+int main()
+{
+    Database_controller *db = Database_controller::get_instance_pointer();
+    db->database_controller_init("127.0.0.1", 3306, "yct", "123456", "test");
+    // usleep(1000*1000);
+    if(db->is_connected())
+    {
+        // 增加
+        Error_manager ec = db->sql_insert("INSERT INTO my_test (content) VALUES ('aaa')");
+        // usleep(1000*3000);
+        cout<<"insert: "<< ec.to_string() <<endl;
+        // 查询
+        boost::shared_ptr<sql::ResultSet> query_result = nullptr;
+        // cout<<"---"<<endl;
+        ec = db->sql_query("SELECT * FROM my_test where id < 5", query_result);
+        cout<<"search: "<< ec.to_string() <<endl;
+        while(query_result!=nullptr && query_result->next())
+        {
+            cout << query_result->getInt("id") << endl;
+            if(query_result->getString("content") != ""){
+                cout << query_result->getInt("numm") << endl;
+                cout << query_result->getString("content") << endl;
+            }
+        }
+        // 删除
+        ec = db->sql_delete("DELETE FROM my_test WHERE id=2");
+        cout<<"delete: "<< ec.to_string() <<endl;
+        // 修改
+        ec = db->sql_update("UPDATE my_test SET content='modified_12345' WHERE id=3");
+        cout<<"update: "<< ec.to_string() <<endl;
+
+        for (size_t i = 0; i < 5; i++)
+        {
+            usleep(1000 * 5000);
+            ec = db->sql_query("SELECT id,content FROM my_test where id < 5", query_result);
+            cout << "search: " << ec.to_string() << endl;
+        }
+    }else{
+        cout<<"connection failed "<<endl;
+    }
+    getchar();
+    return 0;
+}

+ 241 - 0
test/parkspace_client.cpp

@@ -0,0 +1,241 @@
+/*
+ * @Description: 模拟主程序发送车位分配请求,并监听状态信息
+ * @Author: yct
+ * @Date: 2020-07-08 15:44:43
+ * @LastEditTime: 2020-07-22 18:15:55
+ * @LastEditors: yct
+ */
+
+#include <iostream>
+#include <nnxx/message>
+#include <nnxx/socket.h>
+#include <nnxx/bus.h>
+#include "unistd.h"
+
+#include "parkspace_allocation_message.pb.h"
+#include <thread>
+
+std::string send_allocation_request(int n)
+{
+    // 发送车位分配请求
+    message::Error_manager error_code;
+    message::Base_info base_info;
+    message::Car_info car_info;
+    message::Parkspace_allocation_request_msg request;
+
+    base_info.set_msg_type(message::Message_type::eParkspace_allocation_request_msg);
+    base_info.set_sender(message::eMain);
+    base_info.set_receiver(message::eParkspace);
+    base_info.set_timeout_ms(2000);
+    car_info.set_car_height(1.0);
+    car_info.set_car_width(1.0);
+    car_info.set_license("鄂A12345");
+
+    request.mutable_base_info()->CopyFrom(base_info);
+    request.set_command_id(n);
+    request.set_terminal_id(1);
+    request.mutable_car_info()->CopyFrom(car_info);
+
+    // socket.send(request.SerializeAsString());
+    return request.SerializeAsString();
+}
+
+std::string send_search_requests(int n, std::string license="鄂A12345")
+{
+    // 发送车位查询请求
+    message::Error_manager error_code;
+    message::Base_info base_info;
+    message::Car_info car_info;
+    message::Parkspace_search_request_msg request;
+
+    base_info.set_msg_type(message::Message_type::eParkspace_search_request_msg);
+    base_info.set_sender(message::eMain);
+    base_info.set_receiver(message::eParkspace);
+    base_info.set_timeout_ms(10);
+    car_info.set_car_height(2.0);
+    car_info.set_car_width(2.0);
+    car_info.set_license(license);
+
+    request.mutable_base_info()->CopyFrom(base_info);
+    request.set_command_id(n);
+    request.mutable_car_info()->CopyFrom(car_info);
+
+    // socket.send(request.SerializeAsString());
+    return request.SerializeAsString();
+}
+
+std::string send_release_request(int n)
+{
+    // 发送车位释放请求
+    message::Error_manager error_code;
+    message::Base_info base_info;
+    message::Car_info car_info;
+    message::Parkspace_info space_info;
+    message::Parkspace_release_request_msg request;
+
+    base_info.set_msg_type(message::Message_type::eParkspace_release_request_msg);
+    base_info.set_sender(message::eMain);
+    base_info.set_receiver(message::eParkspace);
+    base_info.set_timeout_ms(2000);
+    car_info.set_car_height(1.5);
+    car_info.set_car_width(1.85);
+    car_info.set_license("鄂A12345");
+    space_info.set_parkspace_id(1);
+    space_info.set_index(1);
+    space_info.set_direction(message::Direction::eForward);
+    space_info.set_floor(33);
+    space_info.set_width(1.5);
+    space_info.set_height(1.5);
+    space_info.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+    space_info.mutable_car_info()->CopyFrom(car_info);
+
+    request.mutable_base_info()->CopyFrom(base_info);
+    request.set_command_id(n);
+    request.mutable_release_space_info()->CopyFrom(space_info);
+
+    // socket.send(request.SerializeAsString());
+    return request.SerializeAsString();
+}
+
+std::string send_confirm_request(int n)
+{
+    // 发送车位释放请求
+    message::Error_manager error_code;
+    message::Base_info base_info;
+    message::Car_info car_info;
+    message::Parkspace_info space_info;
+    message::Parkspace_confirm_alloc_request_msg request;
+
+    base_info.set_msg_type(message::Message_type::eParkspace_confirm_alloc_request_msg);
+    base_info.set_sender(message::eMain);
+    base_info.set_receiver(message::eParkspace);
+    base_info.set_timeout_ms(2000);
+    car_info.set_car_height(1.5);
+    car_info.set_car_width(1.85);
+    car_info.set_license("鄂A12345");
+    space_info.set_parkspace_id(1);
+    space_info.set_index(1);
+    space_info.set_direction(message::Direction::eForward);
+    space_info.set_floor(33);
+    space_info.set_width(1.5);
+    space_info.set_height(1.5);
+    space_info.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+    space_info.mutable_car_info()->CopyFrom(car_info);
+
+    request.mutable_base_info()->CopyFrom(base_info);
+    request.set_command_id(n);
+    request.mutable_confirm_space_info()->CopyFrom(space_info);
+
+    // socket.send(request.SerializeAsString());
+    return request.SerializeAsString();
+}
+
+int main()
+{
+    nnxx::socket socket{nnxx::SP, nnxx::BUS};
+    // socket.bind("tcp://127.0.0.1:7000");
+    socket.connect("tcp://127.0.0.1:7001");
+    int n = 0;
+    message::Base_msg base_msg;
+
+    usleep(1000 * 3000);
+
+    std::string alloc_req = send_allocation_request(1);
+    socket.send(alloc_req);
+    usleep(1000 * 500);
+    // alloc_req = send_allocation_request(2);
+    // socket.send(alloc_req);
+    // alloc_req = send_allocation_request(3);
+    // socket.send(alloc_req);
+    // alloc_req = send_allocation_request(4);
+    // socket.send(alloc_req);
+    // alloc_req = send_allocation_request(5);
+    // socket.send(alloc_req);
+
+    std::string confirm_req = send_confirm_request(1);
+    socket.send(confirm_req);
+    usleep(1000 * 500);
+    
+    std::string search_req = send_search_requests(1);
+    socket.send(search_req);
+    usleep(1000 * 500);
+
+    std::string release_req = send_release_request(1);
+    socket.send(release_req);
+    usleep(1000 * 500);
+
+    // usleep(1000*200);
+    // search_req = send_search_requests(3);
+    // socket.send(search_req);
+    // release_req = send_release_request(3);
+    // socket.send(release_req);
+
+    while (1)
+    {
+        // std::string alloc_req = send_allocation_request(n);
+        // std::string search_req = send_search_requests(n);
+
+        // std::string alloc_req = send_allocation_request(n);
+        // socket.send(alloc_req);
+        // usleep(1000*2000);
+        // std::string search_req = send_search_requests(n);
+        // socket.send(search_req);
+        // // usleep(1000*2000);
+        // std::string release_req = send_release_request(n);
+        // socket.send(release_req);
+        // usleep(1000*2000);
+
+        for (size_t i = 0; i < 5; i++)
+        {
+            // 接收消息
+            std::string t_receive_string = socket.recv<std::string>(1);
+            if (t_receive_string.length() > 0)
+            {
+                bool result = base_msg.ParseFromString(t_receive_string);
+                // 接收并打印车位状态信息
+                std::cout << "========================" << result << "============================" << std::endl;
+                std::cout << "cycle " << n << std::endl;
+                if (base_msg.base_info().msg_type() == message::Message_type::eParkspace_allocation_status_msg)
+                {
+                    message::Parkspace_allocation_status_msg parkspace_status;
+                    std::cout << "----------------- 车位状态 -----------------" << std::endl;
+                    parkspace_status.ParseFromString(t_receive_string);
+                    std::cout << parkspace_status.DebugString() << std::endl;
+                    // continue;
+                }
+                else if (base_msg.base_info().msg_type() == message::Message_type::eParkspace_allocation_response_msg)
+                {
+                    message::Parkspace_allocation_response_msg response;
+                    response.ParseFromString(t_receive_string);
+                    std::cout << "----------------- 分配车位结果 -----------------" << std::endl;
+                    std::cout << response.DebugString() << std::endl;
+                }
+                else if (base_msg.base_info().msg_type() == message::Message_type::eParkspace_search_response_msg)
+                {
+                    message::Parkspace_search_response_msg response;
+                    response.ParseFromString(t_receive_string);
+                    std::cout << "----------------- 查询车辆位置结果 -----------------" << std::endl;
+                    std::cout << response.DebugString() << std::endl;
+                }
+                else if (base_msg.base_info().msg_type() == message::Message_type::eParkspace_release_response_msg)
+                {
+                    message::Parkspace_release_response_msg response;
+                    response.ParseFromString(t_receive_string);
+                    std::cout << "----------------- 释放车位结果 -----------------" << std::endl;
+                    std::cout << response.DebugString() << std::endl;
+                }
+                else if (base_msg.base_info().msg_type() == message::Message_type::eParkspace_confirm_alloc_response_msg)
+                {
+                    message::Parkspace_confirm_alloc_response_msg response;
+                    response.ParseFromString(t_receive_string);
+                    std::cout << "----------------- 确认占用车位结果 -----------------" << std::endl;
+                    std::cout << response.DebugString() << std::endl;
+                }
+            }
+        }
+
+        // std::this_thread::yield();
+        n++;
+        usleep(1000 * 1000);
+    }
+}

+ 80 - 0
test/test_parkspace_sample.cpp

@@ -0,0 +1,80 @@
+/*
+ * @Description: 测试车位分配模块通信情况
+ * @Author: yct
+ * @Date: 2020-07-08 15:51:46
+ * @LastEditTime: 2020-07-24 10:54:17
+ * @LastEditors: yct
+ */ 
+#include "../parkspace_allocation/parkspace_allocation_communicator.h"
+#include "../parkspace_allocation/parkspace_allocator.h"
+
+int main()
+{
+
+	//20200129test
+    google::InitGoogleLogging("parkspace_allocator");
+    google::SetStderrLogging(google::INFO);
+    google::InstallFailureSignalHandler();
+    FLAGS_colorlogtostderr = true; 
+
+    Parkspace_allocation_communicator *p_parkspace_allocation_communicater = Parkspace_allocation_communicator::get_instance_pointer();
+    Parkspace_allocator *p_parkspace_allocator = Parkspace_allocator::get_instance_pointer();
+
+
+    parkspace_proto::database_config config;
+    config.set_db_ip("192.168.0.164");
+    config.set_db_port(3306);
+    config.set_db_username("root");
+    config.set_db_passwd("123456");
+    config.set_db_name("test");
+    config.set_db_conn_pool_size(5);
+    p_parkspace_allocator->parkspace_allocator_init(4, config);
+    p_parkspace_allocation_communicater->communication_connect("tcp://192.168.0.64:30000");
+    p_parkspace_allocation_communicater->communication_bind("tcp://192.168.0.64:30008");
+    // p_parkspace_allocation_communicater->communication_bind("tcp://192.168.2.125:7001");
+    // p_parkspace_allocation_communicater->communication_connect("tcp://127.0.0.1:7000");
+    p_parkspace_allocation_communicater->communication_run();
+
+    // // 初始化车位,创建三个车位
+    // message::Parkspace_allocation_status_msg parkspace_status;
+    // for (size_t i = 1; i < 1000; i++)
+    // {
+    //     message::Parkspace_info* space = parkspace_status.add_parkspace_info();
+    //     space->set_parkspace_id(i);
+    //     space->set_index(i);
+    //     space->set_direction(message::Direction::eForward);
+    //     space->set_floor(2+i);
+    //     space->set_length(5.5);
+    //     space->set_width(2.2);
+    //     space->set_height(1.75);
+    //     space->set_parkspace_status(message::Parkspace_status::eParkspace_empty);
+    // }
+    // message::Base_info base_msg;
+    // message::Error_manager error;
+    // base_msg.set_msg_type(message::Message_type::eParkspace_allocation_response_msg);
+    // base_msg.set_timeout_ms(1000);
+    // base_msg.set_sender(message::Communicator::eParkspace);
+    // base_msg.set_receiver(message::Communicator::eMain);
+    // error.set_error_code(0);
+    // parkspace_status.mutable_base_info()->CopyFrom(base_msg);
+    // parkspace_status.mutable_error_manager()->CopyFrom(error);
+    // p_parkspace_allocation_communicater->update_parkspace_status(parkspace_status);
+    int k=1;
+
+    while(1) {
+        // message::Parkspace_info space;
+        // space.set_parkspace_id(3);
+        // space.set_index(k);
+        // space.set_direction(message::Direction::eForward);
+        // space.set_floor(k*3);
+        // space.set_length(5500);
+        // space.set_width(2200);
+        // space.set_height(k*400);
+        // space.set_parkspace_status(message::Parkspace_status::eParkspace_occupied);
+        // p_parkspace_allocator->update_parkspace_status(3, space);
+        usleep(1000*1000);
+        k++;
+    }
+    p_parkspace_allocator->parkspace_allocator_uninit();
+    return 0;
+}

+ 341 - 0
tool/binary_buf.cpp

@@ -0,0 +1,341 @@
+
+/*
+ * binary_buf是二进制缓存
+ * 这里用字符串,来存储雷达的通信消息的原始数据
+ * Binary_buf 的内容格式:消息类型 + 消息数据
+ *
+ * 例如思科的雷达的消息类型
+ * ready->ready->start->data->data->data->stop->ready->ready
+ *
+ * 提供了 is_equal 系列的函数,来进行判断前面的消息类型
+ * 
+ * 注意了:m_buf是中间可以允许有‘\0’的,不是单纯的字符串格式
+ * 			末尾也不一定是‘\0’
+ */
+
+#include "binary_buf.h"
+
+#include <string>
+#include <string.h>
+
+Binary_buf::Binary_buf()
+{
+	mp_buf = NULL;
+	m_length = 0;
+}
+
+Binary_buf::Binary_buf(const Binary_buf& other)
+{
+	mp_buf = NULL;
+	m_length = 0;
+
+	if ( other.m_length > 0 && other.mp_buf != NULL)
+	{
+		mp_buf = (char*)malloc(other.m_length);
+		memcpy(mp_buf, other.mp_buf, other.m_length);
+		m_length = other.m_length;
+	}
+}
+
+Binary_buf::~Binary_buf()
+{
+	if ( mp_buf )
+	{
+		free(mp_buf);
+		mp_buf = NULL;
+	}
+	m_length = 0;
+
+//	std::cout << "Binary_buf::~Binary_buf()" << std::endl;
+}
+
+
+//使用参数构造,深拷贝,len为0时,使用strlen(buf),不存储结束符'\0'
+Binary_buf::Binary_buf(const char* p_buf, int len)
+{
+	mp_buf = NULL;
+	m_length = 0;
+
+	if ( p_buf != NULL)
+	{
+		if (len <= 0)
+		{
+			len = strlen(p_buf);
+		}
+
+		mp_buf = (char*)malloc(len);
+		memcpy(mp_buf, p_buf, len);
+		m_length = len;
+	}
+}
+
+
+//使用参数构造,深拷贝,len为0时,使用strlen(buf),不存储结束符'\0'
+Binary_buf::Binary_buf(char* p_buf, int len)
+{
+	mp_buf = NULL;
+	m_length = 0;
+
+	if ( p_buf != NULL)
+	{
+		if (len <= 0)
+		{
+			len = strlen(p_buf);
+		}
+
+		mp_buf = (char*)malloc(len);
+		memcpy(mp_buf, p_buf, len);
+		m_length = len;
+	}
+}
+
+//重载=,深拷贝,
+Binary_buf& Binary_buf::operator=(const Binary_buf& other)
+{
+	clear();
+
+	if ( other.m_length > 0 && other.mp_buf != NULL)
+	{
+		mp_buf = (char*)malloc(other.m_length);
+		memcpy(mp_buf, other.mp_buf, other.m_length);
+		m_length = other.m_length;
+	}
+	return *this;
+}
+
+//重载=,深拷贝,使用strlen(buf),不存储结束符'\0'
+Binary_buf& Binary_buf::operator=(const char* p_buf)
+{
+	clear();
+
+	if ( p_buf != NULL)
+	{
+		int len = strlen(p_buf);
+		mp_buf = (char*)malloc(len);
+		memcpy(mp_buf, p_buf, len);
+		m_length = len;
+	}
+	return *this;
+}
+
+//重载+,other追加在this的后面,
+Binary_buf& Binary_buf::operator+(Binary_buf& other)
+{
+	if (other.mp_buf != NULL && other.m_length > 0)
+	{
+		int t_length_total = m_length + other.m_length;
+		char* tp_buf_total = (char*)malloc(t_length_total);
+		memcpy(tp_buf_total, mp_buf, m_length);
+		memcpy(tp_buf_total + m_length, other.mp_buf, other.m_length);
+		free(mp_buf);
+		mp_buf = tp_buf_total;
+		m_length = t_length_total;
+	}
+	return *this;
+}
+
+//重载+,追加在this的后面,使用strlen(buf),不存储结束符'\0'
+Binary_buf& Binary_buf::operator+(const char* p_buf)
+{
+	if (p_buf != NULL )
+	{
+		int t_length_back = strlen(p_buf);
+		int t_length_total = m_length + t_length_back;
+		char* tp_buf_total = (char*)malloc(t_length_total);
+		memcpy(tp_buf_total, mp_buf, m_length);
+		memcpy(tp_buf_total + m_length, p_buf, t_length_back);
+		free(mp_buf);
+		mp_buf = tp_buf_total;
+		m_length = t_length_total;
+	}
+	return *this;
+}
+
+//重载[],允许直接使用数组的形式,直接访问buf的内存。注意,n值必须在0~m_length之间,
+char& Binary_buf::operator[](int n)
+{
+	if (n >= 0 && n < m_length)
+	{
+		return mp_buf[n];
+	}
+	else
+	{
+		throw (n);
+	}
+}
+
+
+//判空
+bool Binary_buf::is_empty()
+{
+	if ( mp_buf != NULL && m_length > 0 )
+	{
+		return false;
+	}
+	else
+	{
+		return true;
+	}
+}
+
+//清空
+void Binary_buf::clear()
+{
+	if ( mp_buf )
+	{
+		free(mp_buf);
+		mp_buf = NULL;
+	}
+	m_length = 0;
+}
+
+
+//比较前面部分的buf是否相等,使用 other.m_length 为标准
+bool Binary_buf::is_equal_front(const Binary_buf& other)
+{
+	if ( other.mp_buf == NULL || other.m_length <= 0 )
+	{
+		if ( mp_buf == NULL || m_length <= 0 )
+		{
+			return true;
+		}
+		else
+		{
+			return false;
+		}
+	}
+	else
+	{
+		if ( mp_buf != NULL && m_length > 0 )
+		{
+			if ( other.m_length > m_length )
+			{
+				return false;
+			}
+			return  (strncmp((const char*)mp_buf, other.mp_buf, other.m_length) == 0);
+		}
+		else
+		{
+			return false;
+		}
+
+	}
+}
+
+//比较前面部分的buf是否相等,len为0时,使用strlen(buf)为标准,不比较结束符'\0'
+bool Binary_buf::is_equal_front(const char* p_buf, int len)
+{
+	if ( p_buf == NULL )
+	{
+		if ( mp_buf == NULL || m_length <= 0 )
+		{
+			return true;
+		}
+		else
+		{
+			return false;
+		}
+	}
+	else
+	{
+		if ( mp_buf != NULL && m_length > 0 )
+		{
+			if ( len == 0 )
+			{
+				len = strlen(p_buf);
+			}
+			if ( len > m_length )
+			{
+				return false;
+			}
+			return  (strncmp((const char*)mp_buf, p_buf, len) == 0);
+		}
+		else
+		{
+			return false;
+		}
+
+	}
+}
+
+//比较的buf是否全部相等,
+bool Binary_buf::is_equal_all(const Binary_buf& other)
+{
+	if ( other.mp_buf == NULL || other.m_length <= 0 )
+	{
+		if ( mp_buf == NULL || m_length <= 0 )
+		{
+			return true;
+		}
+		else
+		{
+			return false;
+		}
+	}
+	else
+	{
+		if ( mp_buf != NULL && m_length > 0 )
+		{
+			if ( other.m_length != m_length )
+			{
+				return false;
+			}
+			return  (strncmp((const char*)mp_buf, other.mp_buf, other.m_length) == 0);
+		}
+		else
+		{
+			return false;
+		}
+
+	}
+}
+//比较的buf是否全部相等,不比较结束符'\0'
+bool Binary_buf::is_equal_all(const char* p_buf)
+{
+	if ( p_buf == NULL )
+	{
+		if ( mp_buf == NULL || m_length <= 0 )
+		{
+			return true;
+		}
+		else
+		{
+			return false;
+		}
+	}
+	else
+	{
+		if ( mp_buf != NULL && m_length > 0 )
+		{
+			int	len = strlen(p_buf);
+			if ( len != m_length )
+			{
+				return false;
+			}
+			return  (strncmp((const char*)mp_buf, p_buf, len) == 0);
+		}
+		else
+		{
+			return false;
+		}
+
+	}
+}
+
+
+
+
+char*	Binary_buf::get_buf()const
+{
+	return mp_buf;
+}
+
+int		Binary_buf::get_length()const
+{
+	return m_length;
+}
+
+
+
+
+

+ 91 - 0
tool/binary_buf.h

@@ -0,0 +1,91 @@
+
+/*
+ * binary_buf是二进制缓存
+ * 这里用字符串,来存储雷达的通信消息的原始数据
+ * Binary_buf 的内容格式:消息类型 + 消息数据
+ *
+ * 例如思科的雷达的消息类型
+ * ready->ready->start->data->data->data->stop->ready->ready
+ *
+ * 提供了 is_equal 系列的函数,来进行判断前面的消息类型
+ *
+ * 注意了:m_buf是中间可以允许有‘\0’的,不是单纯的字符串格式
+ * 			末尾也不一定是‘\0’
+ */
+
+#ifndef LIDARMEASURE_BINARY_BUF_H
+#define LIDARMEASURE_BINARY_BUF_H
+#include <iostream>
+
+
+//雷达消息的类型
+//在通信消息的前面一部分字符串,表示这条消息的类型。
+//在解析消息的时候,先解析前面的消息类型,来判断这条消息的功用
+enum Buf_type
+{
+	//默认值 BUF_UNKNOW = 0
+	BUF_UNKNOW   		=0,	//未知消息
+	BUF_READY  			=1,	//待机消息
+	BUF_START 			=2,	//开始消息
+	BUF_DATA   			=3,	//数据消息
+	BUF_STOP  			=4,	//结束消息
+	BUF_ERROR   		=5,	//错误消息
+};
+
+
+//二进制缓存,
+class Binary_buf
+{
+public:
+	Binary_buf();
+	Binary_buf(const Binary_buf& other);
+	~Binary_buf();
+
+	//使用参数构造,深拷贝,len为0时,使用strlen(buf),不存储结束符'\0'
+	Binary_buf(const char* p_buf, int len = 0);
+	//使用参数构造,深拷贝,len为0时,使用strlen(buf),不存储结束符'\0'
+	Binary_buf(char* p_buf, int len = 0);
+	//重载=,深拷贝,
+	Binary_buf& operator=(const Binary_buf& other);
+	//重载=,深拷贝,使用strlen(buf),不存储结束符'\0'
+	Binary_buf& operator=(const char* p_buf);
+	//重载+,other追加在this的后面,
+	Binary_buf& operator+(Binary_buf& other);
+	//重载+,追加在this的后面,使用strlen(buf),不存储结束符'\0'
+	Binary_buf& operator+(const char* p_buf);
+	//重载[],允许直接使用数组的形式,直接访问buf的内存。注意,n值必须在0~m_length之间,
+	char& operator[](int n);
+
+	//判空
+	bool is_empty();
+	//清空
+	void clear();
+
+	//比较前面部分的buf是否相等,使用 other.m_length 为标准
+	bool is_equal_front(const Binary_buf& other);
+	//比较前面部分的buf是否相等,len为0时,使用strlen(buf)为标准,不比较结束符'\0'
+	bool is_equal_front(const char* p_buf, int len = 0);
+
+	//比较的buf是否全部相等,
+	bool is_equal_all(const Binary_buf& other);
+	//比较的buf是否全部相等,不比较结束符'\0'
+	bool is_equal_all(const char* p_buf);
+
+
+
+public:
+	char* get_buf()const;
+	int	get_length()const;
+
+protected:
+	char*		mp_buf;				//二进制缓存指针
+	int			m_length;			//二进制缓存长度
+
+private:
+
+};
+
+
+
+
+#endif //LIDARMEASURE_BINARY_BUF_H

+ 85 - 0
tool/binary_buf.puml

@@ -0,0 +1,85 @@
+@startuml
+skinparam classAttributeIconSize 0
+
+title  binary_buf是二进制缓存
+
+note left of Binary_buf
+/*
+ * binary_buf是二进制缓存
+ * 这里用字符串,来存储雷达的通信消息的原始数据
+ * Binary_buf 的内容格式:消息类型 + 消息数据
+ *
+ * 例如思科的雷达的消息类型
+ * ready->ready->start->data->data->data->stop->ready->ready
+ *
+ * 提供了 is_equal 系列的函数,来进行判断前面的消息类型
+ *
+ * 注意了:m_buf是中间可以允许有‘\0’的,不是单纯的字符串格式
+ * 			末尾也不一定是‘\0’
+ */
+end note
+
+
+
+enum Buf_type
+{
+//雷达消息的类型
+//在通信消息的前面一部分字符串,表示这条消息的类型。
+//在解析消息的时候,先解析前面的消息类型,来判断这条消息的功用
+	//默认值 BUF_UNKNOW = 0
+	BUF_UNKNOW   		=0,	//未知消息
+	BUF_READY  			=1,	//待机消息
+	BUF_START 			=2,	//开始消息
+	BUF_DATA   			=3,	//数据消息
+	BUF_STOP  			=4,	//结束消息
+	BUF_ERROR   		=5,	//错误消息
+}
+
+
+
+class Binary_buf
+{
+//二进制缓存,
+==public:==
+	Binary_buf();
+	Binary_buf(const Binary_buf& other);
+	~Binary_buf();
+..
+	//使用参数构造,深拷贝,len为0时,使用strlen(buf),不存储结束符'\0'
+	Binary_buf(const char* p_buf, int len = 0);
+	//重载=,深拷贝,
+	Binary_buf& operator=(const Binary_buf& other);
+	//重载=,深拷贝,使用strlen(buf),不存储结束符'\0'
+	Binary_buf& operator=(const char* p_buf);
+	//重载+,other追加在this的后面,
+	Binary_buf& operator+(Binary_buf& other);
+	//重载+,追加在this的后面,使用strlen(buf),不存储结束符'\0'
+	Binary_buf& operator+(const char* p_buf);
+	//重载[],允许直接使用数组的形式,直接访问buf的内存。注意,n值必须在0~m_length之间,
+	char& operator[](int n);
+..
+	//判空
+	bool is_empty();
+	//清空
+	void clear();
+..
+	//比较前面部分的buf是否相等,使用 other.m_length 为标准
+	bool is_equal_front(const Binary_buf& other);
+	//比较前面部分的buf是否相等,len为0时,使用strlen(buf)为标准,不比较结束符'\0'
+	bool is_equal_front(const char* p_buf, int len = 0);
+
+	//比较的buf是否全部相等,
+	bool is_equal_all(const Binary_buf& other);
+	//比较的buf是否全部相等,不比较结束符'\0'
+	bool is_equal_all(const char* p_buf);
+==public:==
+	char* get_buf()const;
+	int	get_length()const;
+==protected:==
+	char*		mp_buf;				//二进制缓存指针
+	int			m_length;			//二进制缓存长度
+==private:==
+}
+
+
+@enduml

+ 94 - 0
tool/pathcreator.cpp

@@ -0,0 +1,94 @@
+#include "pathcreator.h"
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <stdint.h>
+#include <stdio.h>
+
+PathCreator::PathCreator()
+{
+
+}
+
+PathCreator::~PathCreator()
+{
+
+}
+
+std::string PathCreator::GetCurPath()
+{
+    return m_current_path;
+}
+bool PathCreator::Mkdir(std::string dirName)
+{
+    uint32_t beginCmpPath = 0;
+    uint32_t endCmpPath = 0;
+    std::string fullPath = "";
+
+    if('/' != dirName[0])
+    {
+        fullPath = getcwd(nullptr, 0);
+        beginCmpPath = fullPath.size();
+        fullPath = fullPath + "/" + dirName;
+    }
+    else
+    {
+        //Absolute path
+        fullPath = dirName;
+        beginCmpPath = 1;
+    }
+    if (fullPath[fullPath.size() - 1] != '/')
+    {
+        fullPath += "/";
+    }
+    endCmpPath = fullPath.size();
+
+    //create dirs;
+    for(uint32_t i = beginCmpPath; i < endCmpPath ; i++ )
+    {
+        if('/' == fullPath[i])
+        {
+            std::string curPath = fullPath.substr(0, i);
+            if(access(curPath.c_str(), F_OK) != 0)
+            {
+                if(mkdir(curPath.c_str(), /*S_IRUSR|S_IRGRP|S_IROTH|S_IWUSR|S_IWGRP|S_IWOTH*/0777) == -1)
+                {
+                    printf("mkdir(%s) failed\n", curPath.c_str());
+                    return false;
+                }
+            }
+        }
+    }
+    m_current_path=fullPath;
+    return true;
+
+}
+
+bool PathCreator::CreateDatePath(std::string root, bool add_time)
+{
+    time_t tt;
+    time( &tt );
+    tt = tt + 8*3600;  // transform the time zone
+    tm* t= gmtime( &tt );
+    char buf[255]={0};
+    if (add_time)
+    {
+        sprintf(buf, "%s/%d%02d%02d-%02d%02d%02d", root.c_str(),
+                t->tm_year + 1900,
+                t->tm_mon + 1,
+                t->tm_mday,
+                t->tm_hour,
+                t->tm_min,
+                t->tm_sec);
+    }
+    else
+    {
+        sprintf(buf, "%s/%d%02d%02d", root.c_str(),
+                t->tm_year + 1900,
+                t->tm_mon + 1,
+                t->tm_mday);
+    }
+    return Mkdir(buf);
+}

+ 18 - 0
tool/pathcreator.h

@@ -0,0 +1,18 @@
+#ifndef PATHCREATOR_H
+#define PATHCREATOR_H
+#include <string>
+
+class PathCreator
+{
+public:
+    PathCreator();
+    ~PathCreator();
+    std::string GetCurPath();
+    bool Mkdir(std::string dir);
+    bool CreateDatePath(std::string root, bool add_time = true);
+protected:
+    std::string m_current_path;
+};
+
+
+#endif // PATHCREATOR_H

+ 0 - 0
tool/pcl_cloud_with_lock.cpp


+ 30 - 0
tool/pcl_cloud_with_lock.h

@@ -0,0 +1,30 @@
+
+
+
+#ifndef PCL_CLOUD_WITH_LOCK_H
+#define PCL_CLOUD_WITH_LOCK_H
+
+
+class Pcl_cloud_with_lock
+{
+public:
+	Pcl_cloud_with_lock();
+	Pcl_cloud_with_lock(const Pcl_cloud_with_lock& other);
+	~Pcl_cloud_with_lock();
+public://API functions
+
+public://get or set member variable
+
+
+protected://member variable
+//	//三维点云的数据保护锁,
+//	std::mutex*                     mp_task_cloud_lock;
+//	//三维点云容器的智能指针,这里不直接分配内存,
+//	pcl::PointCloud<pcl::PointXYZ>::Ptr        mp_task_point_cloud;
+
+private:
+
+};
+
+
+#endif //PCL_CLOUD_WITH_LOCK_H

+ 42 - 0
tool/proto_tool.cpp

@@ -0,0 +1,42 @@
+
+
+
+#include "proto_tool.h"
+#include <fcntl.h>
+#include<unistd.h>
+#include <google/protobuf/io/zero_copy_stream_impl.h>
+#include <google/protobuf/text_format.h>
+using google::protobuf::io::FileInputStream;
+using google::protobuf::io::FileOutputStream;
+using google::protobuf::io::ZeroCopyInputStream;
+using google::protobuf::io::CodedInputStream;
+using google::protobuf::io::ZeroCopyOutputStream;
+using google::protobuf::io::CodedOutputStream;
+using google::protobuf::Message;
+
+
+//读取protobuf 配置文件,转化为protobuf参数形式
+//input:	prototxt_path :prototxt文件路径
+//ouput:	parameter: protobuf参数,这里是消息基类,实际调用时传入对应的子类即可。
+bool proto_tool::read_proto_param(std::string prototxt_path, ::google::protobuf::Message& protobuf_parameter)
+{
+	int fd = open(prototxt_path.c_str(), O_RDONLY);
+	if (fd == -1) return false;
+	FileInputStream* input = new FileInputStream(fd);
+	bool success = google::protobuf::TextFormat::Parse(input, &protobuf_parameter);
+	delete input;
+	close(fd);
+	return success;
+}
+
+
+
+
+
+
+
+
+
+
+
+

+ 56 - 0
tool/proto_tool.h

@@ -0,0 +1,56 @@
+
+
+
+
+
+#ifndef __PROTO_TOOL_H
+#define __PROTO_TOOL_H
+
+#include "../tool/singleton.h"
+#include <istream>
+#include <google/protobuf/message.h>
+
+class proto_tool:public Singleton<proto_tool>
+{
+	// 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
+	friend class Singleton<proto_tool>;
+public:
+	// 必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
+	proto_tool(const proto_tool&)=delete;
+	proto_tool& operator =(const proto_tool&)= delete;
+	~proto_tool()=default;
+private:
+	// 父类的构造函数必须保护,子类的构造函数必须私有。
+	proto_tool()=default;
+
+
+public:
+	//读取protobuf 配置文件,转化为protobuf参数形式
+	//input:	prototxt_path :prototxt文件路径
+	//ouput:	parameter: protobuf参数,这里是消息基类,实际调用时传入对应的子类即可。
+	static bool read_proto_param(std::string prototxt_path, ::google::protobuf::Message& protobuf_parameter);
+};
+
+
+
+
+#endif //__PROTO_TOOL_H
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 4 - 0
tool/singleton.cpp

@@ -0,0 +1,4 @@
+
+#include "singleton.h"
+
+

+ 81 - 0
tool/singleton.h

@@ -0,0 +1,81 @@
+
+/* Singleton 是单例类的模板。
+ * https://www.cnblogs.com/sunchaothu/p/10389842.html
+ * 单例 Singleton 是设计模式的一种,其特点是只提供唯一一个类的实例,具有全局变量的特点,在任何位置都可以通过接口获取到那个唯一实例;
+ * 全局只有一个实例:static 特性,同时禁止用户自己声明并定义实例(把构造函数设为 private 或者 protected)
+ * Singleton 模板类对这种方法进行了一层封装。
+ * 单例类需要从Singleton继承。
+ * 子类需要将自己作为模板参数T 传递给 Singleton<T> 模板;
+ * 同时需要将基类声明为友元,这样Singleton才能调用子类的私有构造函数。
+// 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
+// 父类的构造函数必须保护,子类的构造函数必须私有。
+// 必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来操作 唯一的实例。
+ * */
+
+#ifndef __SINGLIETON_H
+#define __SINGLIETON_H
+
+//#include <iostream>
+
+template<typename T>
+class Singleton
+{
+public:
+	//获取单例的引用
+	static T& get_instance_references()
+	{
+		static T instance;
+		return instance;
+	}
+	//获取单例的指针
+	static T* get_instance_pointer()
+	{
+		return &(get_instance_references());
+	}
+
+	virtual ~Singleton()
+	{
+//		std::cout<<"destructor called!"<<std::endl;
+	}
+
+	Singleton(const Singleton&)=delete;					//关闭拷贝构造函数
+	Singleton& operator =(const Singleton&)=delete;		//关闭赋值函数
+
+protected:
+	//构造函数需要是 protected,这样子类才能继承;
+	Singleton()
+	{
+//		std::cout<<"constructor called!"<<std::endl;
+	}
+
+};
+
+/*
+// 如下是 使用样例:
+// 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
+// 父类的构造函数必须保护,子类的构造函数必须私有。
+// 必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
+
+class DerivedSingle:public Singleton<DerivedSingle>
+{
+ // 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
+	friend class Singleton<DerivedSingle>;
+public:
+ // 必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
+	DerivedSingle(const DerivedSingle&)=delete;
+	DerivedSingle& operator =(const DerivedSingle&)= delete;
+ 	~DerivedSingle()=default;
+private:
+ // 父类的构造函数必须保护,子类的构造函数必须私有。
+	DerivedSingle()=default;
+};
+
+int main(int argc, char* argv[]){
+	DerivedSingle& instance1 = DerivedSingle::get_instance_references();
+	DerivedSingle* p_instance2 = DerivedSingle::get_instance_pointer();
+	return 0;
+}
+
+ */
+
+#endif

+ 175 - 0
tool/thread_condition.cpp

@@ -0,0 +1,175 @@
+
+
+/* Thread_condition 是多线程的条件控制类,主要是控制线程的启停和退出
+ * 线程创建后,一般是循环运行,
+ * 为了防止线程暂满整个cpu,那么需要线程在不工作的是否进入等待状态。
+ * Thread_condition 就可以控制线程的运行状态。
+ *
+	std::atomic<bool> m_pass_ever		//线程能否直接通过等待,对后面的线程也生效。
+	std::atomic<bool> m_pass_once		//线程能否直接通过等待,一次(通过一次之后,wait里面自动改为false)
+ * 外部调用notify系列的函数,唤醒等待的线程,让线程执行功能函数。
+ * 如果需要线程循环多次执行功能函数,那么就使用 notify_all(true),后面的线程可以直接通过等待了。
+ * 再使用 notify_all(false) ,即可停止线程,让其继续等待。
+ * 如果只想要线程执行一次,那就使用 notify_all(false, true)
+ * 注:notify_all(false, true)和notify_one(false, true) 一样,只能让其中一个线程执行一次
+ *
+ * m_kill_flag //是否杀死线程,让线程强制退出,
+ * 外部调用 kill_all() 函数,可以直接通知线程自动退出。
+	//杀死所有的线程,强制退出线程函数,只是操作受当前Thread_condition影响的所有线程
+	//唤醒所有线程,使其通过等待,但是不能运行功能函数,必须直接return
+	// 注:只是修改m_kill为true,需要线程函数实时检测kill的状态,来return线程。
+	//		通过等待之后,也要检查kill的状态,如果为真,那么就不能执行功能函数,应该直接return
+
+ 注:notify唤醒线程之后,wait里面的判断函数会重新判断。
+ */
+
+#include "thread_condition.h"
+
+Thread_condition::Thread_condition()
+{
+	m_kill_flag = false;
+	m_pass_ever = false;
+	m_pass_once = false;
+	m_working_flag = false;
+}
+Thread_condition::~Thread_condition()
+{
+	kill_all();
+}
+
+//无限等待,由 is_pass_wait 决定是否阻塞。
+//返回m_pass,
+bool Thread_condition::wait()
+{
+	std::unique_lock<std::mutex> loc(m_mutex);
+	m_condition_variable.wait(loc,std::bind(is_pass_wait,this));
+	bool t_pass = is_pass_wait(this);
+	m_pass_once = false;
+
+	//只要前面通过了, 那就进入工作状态
+	m_working_flag = true;
+
+	return t_pass;
+}
+//等待一定的时间(默认时间单位:毫秒ms),由 is_pass_wait 决定是否阻塞。
+//return:is_pass_wait的结果,	true:线程直接通过等待,false:线程超时了,然后通过等待。
+//注意了:线程阻塞期间,是不会return的。
+bool Thread_condition::wait_for_millisecond(unsigned int millisecond)
+{
+	std::unique_lock<std::mutex> loc(m_mutex);
+	m_condition_variable.wait_for(loc, std::chrono::milliseconds(millisecond), std::bind(is_pass_wait, this));
+	bool t_pass = is_pass_wait(this);
+	m_pass_once = false;
+
+	//只要前面通过了, 那就进入工作状态 , 超时通过也算通过
+	m_working_flag = true;
+
+	return t_pass;
+}
+
+
+//唤醒已经阻塞的线程,唤醒一个线程
+//pass_ever 或者 pass_once 为真时,才能唤醒线程。都为假时,线程进入等待。
+void Thread_condition::notify_one(bool pass_ever, bool pass_once)
+{
+	std::unique_lock<std::mutex> loc(m_mutex);
+	m_pass_ever = pass_ever;
+	m_pass_once = pass_once;
+	m_condition_variable.notify_one();
+}
+//唤醒已经阻塞的线程,唤醒全部线程
+//pass_ever 或者 pass_once 为真时,才能唤醒线程。都为假时,线程进入等待。
+void Thread_condition::notify_all(bool pass_ever, bool pass_once)
+{
+	std::unique_lock<std::mutex> loc(m_mutex);
+	m_pass_ever = pass_ever;
+	m_pass_once = pass_once;
+	m_condition_variable.notify_all();
+}
+//注:notify_all(false, true)和notify_one(false, true) 一样,只能让其中一个线程执行一次
+
+
+//杀死所有的线程,强制退出线程函数,只是操作受当前Thread_condition影响的所有线程
+//唤醒所有线程,使其通过等待,但是不能运行功能函数,必须直接return
+// 注:只是修改m_kill为true,需要线程函数实时检测kill的状态,来return线程。
+//		通过等待之后,也要检查kill的状态,如果为真,那么就不能执行功能函数,应该直接return
+void Thread_condition::kill_all()
+{
+	std::unique_lock<std::mutex> loc(m_mutex);
+	m_kill_flag = true;
+	m_condition_variable.notify_all();
+}
+
+//判断是否存活,只有活着才能继续支持子线程从功能函数,否则需要强制退出函数并结束子线程
+bool Thread_condition::is_alive()
+{
+	return !m_kill_flag;
+}
+
+
+//判断是否等待, 外部线程通过这个函数来查询this线程的工作状态,
+bool Thread_condition::is_waiting()
+{
+	return !m_working_flag;
+}
+//判断是否工作, 外部线程通过这个函数来查询this线程的工作状态,
+bool Thread_condition::is_working()
+{
+	return m_working_flag;
+}
+
+
+bool Thread_condition::get_kill_flag()
+{
+	return m_kill_flag;
+}
+bool Thread_condition::get_pass_ever()
+{
+	return m_pass_ever;
+}
+bool Thread_condition::get_pass_once()
+{
+	return m_pass_once;
+}
+void Thread_condition::set_kill_flag(bool kill)
+{
+	m_kill_flag = kill;
+}
+void Thread_condition::set_pass_ever(bool pass_ever)
+{
+	m_pass_ever = pass_ever;
+}
+void Thread_condition::set_pass_once(bool pass_once)
+{
+	m_pass_once = pass_once;
+}
+void Thread_condition::reset(bool kill, bool pass_ever, bool pass_once)
+{
+	m_kill_flag = kill;
+	m_pass_ever = pass_ever;
+	m_pass_once = pass_once;
+}
+
+
+//判断线程是否可以通过等待,wait系列函数的判断标志
+//注:m_kill或者m_pass为真时,return true
+bool Thread_condition::is_pass_wait(Thread_condition * other)
+{
+	if ( other == NULL )
+	{
+		throw (other);
+		return false;
+	}
+
+	bool result = (other->m_kill_flag || other->m_pass_ever || other->m_pass_once);
+
+	//如果不能通过等待, 那么线程状态改为等待中,
+	if ( !result )
+	{
+		other->m_working_flag = false;
+	}
+
+
+	return result;
+}
+

+ 183 - 0
tool/thread_condition.h

@@ -0,0 +1,183 @@
+
+
+/* Thread_condition 是多线程的条件控制类,主要是控制线程的启停和退出
+ * 线程创建后,一般是循环运行,
+ * 为了防止线程暂满整个cpu,那么需要线程在不工作的是否进入等待状态。
+ * Thread_condition 就可以控制线程的运行状态。
+ *
+	std::atomic<bool> m_pass_ever		//线程能否直接通过等待,对后面的线程也生效。
+	std::atomic<bool> m_pass_once		//线程能否直接通过等待,一次(通过一次之后,wait里面自动改为false)
+ * 外部调用notify系列的函数,唤醒等待的线程,让线程执行功能函数。
+ * 如果需要线程循环多次执行功能函数,那么就使用 notify_all(true),后面的线程可以直接通过等待了。
+ * 再使用 notify_all(false) ,即可停止线程,让其继续等待。
+ * 如果只想要线程执行一次,那就使用 notify_all(false, true)
+ * 注:notify_all(false, true)和notify_one(false, true) 一样,只能让其中一个线程执行一次
+ *
+ * m_kill_flag //是否杀死线程,让线程强制退出,
+ * 外部调用 kill_all() 函数,可以直接通知线程自动退出。
+	//杀死所有的线程,强制退出线程函数,只是操作受当前Thread_condition影响的所有线程
+	//唤醒所有线程,使其通过等待,但是不能运行功能函数,必须直接return
+	// 注:只是修改m_kill为true,需要线程函数实时检测kill的状态,来return线程。
+	//		通过等待之后,也要检查kill的状态,如果为真,那么就不能执行功能函数,应该直接return
+
+ 注:notify唤醒线程之后,wait里面的判断函数会重新判断。
+
+
+ 最下面有使用样例,
+
+ */
+
+#ifndef LIDARMEASURE_THREAD_CONDITION_H
+#define LIDARMEASURE_THREAD_CONDITION_H
+
+#include <ratio>
+#include <chrono>
+#include <thread>
+#include <atomic>
+#include <mutex>
+#include <condition_variable>
+#include <functional>
+
+class Thread_condition
+{
+public:
+	Thread_condition();
+	Thread_condition(const Thread_condition& other) = delete;
+	~Thread_condition();
+
+	//无限等待,由 is_pass_wait 决定是否阻塞。
+	//返回m_pass,
+	bool wait();
+	//等待一定的时间(默认时间单位:毫秒ms),由 is_pass_wait 决定是否阻塞。
+	//return:is_pass_wait的结果,	true:线程直接通过等待,false:线程超时了,然后通过等待。
+	//注意了:线程阻塞期间,是不会return的。
+	bool wait_for_millisecond(unsigned int millisecond);
+
+	//等待一定的时间(时间单位可调),由 is_pass_wait 决定是否阻塞。
+	//return:is_pass_wait的结果,	true:线程直接通过等待,false:线程超时了,然后通过等待。
+	//注意了:线程阻塞期间,是不会return的。
+	template<typename _Rep, typename _Period>
+	bool wait_for_ex(const std::chrono::duration<_Rep, _Period>& time_duration);
+
+	//唤醒已经阻塞的线程,唤醒一个线程
+	//pass_ever 或者 pass_once 为真时,才能唤醒线程。都为假时,线程进入等待。
+	void notify_one(bool pass_ever, bool pass_once = false);
+	//唤醒已经阻塞的线程,唤醒全部线程
+	//pass_ever 或者 pass_once 为真时,才能唤醒线程。都为假时,线程进入等待。
+	void notify_all(bool pass_ever, bool pass_once = false);
+	//注:notify_all(false, true)和notify_one(false, true) 一样,只能让其中一个线程执行一次
+
+	//杀死所有的线程,强制退出线程函数,只是操作受当前Thread_condition影响的所有线程
+	//唤醒所有线程,使其通过等待,但是不能运行功能函数,必须直接return
+	// 注:只是修改m_kill为true,需要线程函数实时检测kill的状态,来return线程。
+	//		通过等待之后,也要检查kill的状态,如果为真,那么就不能执行功能函数,应该直接return
+	void kill_all();
+
+	//判断是否存活,只有活着才能继续支持子线程从功能函数,否则需要强制退出函数并结束子线程
+	bool is_alive();
+
+	//判断是否等待, 外部线程通过这个函数来查询this线程的工作状态,
+	bool is_waiting();
+	//判断是否工作, 外部线程通过这个函数来查询this线程的工作状态,
+	bool is_working();
+
+public:
+
+	bool get_kill_flag();
+	bool get_pass_ever();
+	bool get_pass_once();
+	void set_kill_flag(bool kill);
+	void set_pass_ever(bool pass_ever);
+	void set_pass_once(bool pass_once);
+	void reset(bool kill = false, bool pass_ever = false, bool pass_once = false);
+
+protected:
+	//判断线程是否可以通过等待,wait系列函数的判断标志
+	//注:m_kill或者m_pass为真时,return true
+	static bool is_pass_wait(Thread_condition * other);
+
+	std::atomic<bool> 		m_kill_flag;			//是否杀死线程,让线程强制退出,
+	std::atomic<bool> 		m_pass_ever;			//线程能否直接通过等待,对后面的线程也生效。
+	std::atomic<bool> 		m_pass_once;			//线程能否直接通过等待,一次(通过一次之后,wait里面自动改为false)
+
+	std::atomic<bool> 		m_working_flag;			//线程是否进入工作的标志位, false:表示线程进行进入wait等待, true:表示线程仍然在运行中,
+
+	std::mutex 				m_mutex;				//线程的锁
+	std::condition_variable m_condition_variable;	//线程的条件变量
+
+private:
+
+};
+
+//等待一定的时间(时间单位可调),由 is_pass_wait 决定是否阻塞。
+//return:is_pass_wait的结果,	true:线程直接通过等待,false:线程超时了,然后通过等待。
+//注意了:线程阻塞期间,是不会return的。
+template<typename _Rep, typename _Period>
+bool Thread_condition::wait_for_ex(const std::chrono::duration<_Rep, _Period>& time_duration)
+{
+	std::unique_lock<std::mutex> loc(m_mutex);
+	m_condition_variable.wait_for(loc, std::chrono::duration<_Rep, _Period>(time_duration), std::bind(is_pass_wait, this));
+	bool t_pass = is_pass_wait(this);
+	m_pass_once = false;
+	return t_pass;
+}
+
+#endif //LIDARMEASURE_THREAD_CONDITION_H
+
+
+
+
+
+/*
+//使用样例:
+std::thread*						mp_thread_receive;    		//接受缓存的线程指针
+Thread_condition					m_condition_receive;		//接受缓存的条件变量
+
+void thread_receive()
+{
+	while (m_condition_receive.is_alive())
+	{
+		m_condition_receive.wait();
+		if ( m_condition_receive.is_alive() )
+		{
+			//do everything
+
+		}
+	}
+
+	return;
+}
+
+//main函数的主线程
+int main(int argc,char* argv[])
+{
+ 	//线程创建之后, 默认等待
+	m_condition_receive.reset(false, false, false);
+	mp_thread_receive = new std::thread(& thread_receive );
+
+
+	//唤醒所有线程, 然后线程可以一直通过wait等待, 线程进入无限制的循环工作.
+	m_condition_receive.notify_all(true);
+
+	//暂停所有线程, 然后线程还是继续工作, 直到下一次循环, 进入wait等待
+	m_condition_receive.notify_all(false);
+
+	//如果线程单次循环运行时间较长, 需要等待线程完全停止, 才能读写公共的内存,
+	if ( m_condition_receive.is_waiting() )
+	{
+	    // 读写公共的内存,
+	}
+
+	//唤醒一个线程, 然后线程循环一次, 然后下次循环进入等待
+	m_condition_receive.notify_all(false, true);
+
+
+	//杀死线程,
+	m_condition_receive.kill_all();
+
+	//在线程join结束之后, 就可以可以回收线程内存资源
+	mp_thread_receive->join();
+	delete mp_thread_receive;
+	mp_thread_receive = NULL;
+}
+*/

+ 96 - 0
tool/thread_condition.puml

@@ -0,0 +1,96 @@
+@startuml
+skinparam classAttributeIconSize 0
+
+title  Thread_condition 是多线程的条件控制类,主要是控制线程的启停和退出
+note left of Thread_condition
+/* Thread_condition 是多线程的条件控制类,主要是控制线程的启停和退出
+ * 线程创建后,一般是循环运行,
+ * 为了防止线程暂满整个cpu,那么需要线程在不工作的是否进入等待状态。
+ * Thread_condition 就可以控制线程的运行状态。
+ *
+	std::atomic<bool> m_pass_ever		//线程能否直接通过等待,对后面的线程也生效。
+	std::atomic<bool> m_pass_once		//线程能否直接通过等待,一次(通过一次之后,wait里面自动改为false)
+ * 外部调用notify系列的函数,唤醒等待的线程,让线程执行功能函数。
+ * 如果需要线程循环多次执行功能函数,那么就使用 notify_all(true),后面的线程可以直接通过等待了。
+ * 再使用 notify_all(false) ,即可停止线程,让其继续等待。
+ * 如果只想要线程执行一次,那就使用 notify_all(false, true)
+ * 注:notify_all(false, true)和notify_one(false, true) 一样,只能让其中一个线程执行一次
+ *
+ * m_kill_flag //是否杀死线程,让线程强制退出,
+ * 外部调用 kill_all() 函数,可以直接通知线程自动退出。
+	//杀死所有的线程,强制退出线程函数,只是操作受当前Thread_condition影响的所有线程
+	//唤醒所有线程,使其通过等待,但是不能运行功能函数,必须直接return
+	// 注:只是修改m_kill为true,需要线程函数实时检测kill的状态,来return线程。
+	//		通过等待之后,也要检查kill的状态,如果为真,那么就不能执行功能函数,应该直接return
+
+ 注:notify唤醒线程之后,wait里面的判断函数会重新判断。
+ */
+end note
+
+
+
+class Thread_condition
+{
+==public:==
+	Thread_condition();
+	Thread_condition(const Thread_condition& other) = delete;
+	~Thread_condition();
+..
+	//无限等待,由 is_pass_wait 决定是否阻塞。
+	//返回m_pass,
+	bool wait();
+..
+	//等待一定的时间(默认时间单位:毫秒ms),由 is_pass_wait 决定是否阻塞。
+	//return:is_pass_wait的结果,	true:线程直接通过等待,false:线程超时了,然后通过等待。
+	//注意了:线程阻塞期间,是不会return的。
+	bool wait_for_millisecond(unsigned int millisecond);
+..
+	//等待一定的时间(时间单位可调),由 is_pass_wait 决定是否阻塞。
+	//return:is_pass_wait的结果,	true:线程直接通过等待,false:线程超时了,然后通过等待。
+	//注意了:线程阻塞期间,是不会return的。
+	template<typename _Rep, typename _Period>
+	bool wait_for_ex(const std::chrono::duration<_Rep, _Period>& time_duration);
+..
+	//唤醒已经阻塞的线程,唤醒一个线程
+	//pass_ever 或者 pass_once 为真时,才能唤醒线程。都为假时,线程进入等待。
+	void notify_one(bool pass_ever, bool pass_once = false);
+..
+	//唤醒已经阻塞的线程,唤醒全部线程
+	//pass_ever 或者 pass_once 为真时,才能唤醒线程。都为假时,线程进入等待。
+	void notify_all(bool pass_ever, bool pass_once = false);
+	//注:notify_all(false, true)和notify_one(false, true) 一样,只能让其中一个线程执行一次
+..
+	//杀死所有的线程,强制退出线程函数,只是操作受当前Thread_condition影响的所有线程
+	//唤醒所有线程,使其通过等待,但是不能运行功能函数,必须直接return
+	// 注:只是修改m_kill为true,需要线程函数实时检测kill的状态,来return线程。
+	//		通过等待之后,也要检查kill的状态,如果为真,那么就不能执行功能函数,应该直接return
+	void kill_all();
+..
+	//判断是否或者,return !m_kill_flag
+	bool is_alive();
+==public:==
+	bool get_kill_flag();
+	bool get_pass_ever();
+	bool get_pass_once();
+	void set_kill_flag(bool kill);
+	void set_pass_ever(bool pass_ever);
+	void set_pass_once(bool pass_once);
+	void reset(bool kill = false, bool pass_ever = false, bool pass_once = false);
+==protected:==
+	//判断线程是否可以通过等待,wait系列函数的判断标志
+	//注:m_kill或者m_pass为真时,return true
+	static bool is_pass_wait(Thread_condition * other);
+
+	std::atomic<bool> 		m_kill_flag;			//是否杀死线程,让线程强制退出,
+	std::atomic<bool> 		m_pass_ever;			//线程能否直接通过等待,对后面的线程也生效。
+	std::atomic<bool> 		m_pass_once;			//线程能否直接通过等待,一次(通过一次之后,wait里面自动改为false)
+
+	std::mutex 				m_mutex;				//线程的锁
+	std::condition_variable m_condition_variable;	//线程的条件变量
+
+==private:==
+
+}
+
+
+@enduml

+ 262 - 0
tool/thread_pool.h

@@ -0,0 +1,262 @@
+/*
+ * Thread_pool 线程池,
+ *
+ * */
+
+
+
+//例如
+// Thread_pool thread_pool(4);
+// std::future<int> x =  thread_pool.enqueue( []{return 0;} );
+// std::cout << x.get() << std::endl;
+
+//例如
+/*
+Thread_pool pool(4);
+std::vector< std::future<int> > results;
+
+for(int i = 0; i < 8; ++i) {
+results.emplace_back(
+pool.enqueue([i] {
+std::cout << "hello " << i << std::endl;
+std::this_thread::sleep_for(std::chrono::seconds(1));
+std::cout << "world " << i << std::endl;
+return i*i;
+})
+);
+}
+
+for(auto && result: results)
+std::cout << result.get() << ' ';
+std::cout << std::endl;
+return 0;
+*/
+
+#ifndef THREAD_POOL_H
+#define THREAD_POOL_H
+
+#include <vector>
+#include <queue>
+#include <memory>
+#include <thread>
+#include <mutex>
+#include <condition_variable>
+#include <future>
+#include <functional>
+#include <stdexcept>
+
+class Thread_pool {
+public:
+	//构造函数, 会自动初始化 threads_size 数量的线程
+    Thread_pool(size_t threads_size);
+
+	//构造函数,没有初始化的,后续需要调用init才能正常使用
+	Thread_pool();
+	//初始化,初始化 threads_size 数量的线程
+	void thread_pool_init(size_t threads_size);
+
+	//反初始化
+	void thread_pool_uninit();
+
+	//往线程池添加执行任务, 之后会唤醒一个线程去执行他.
+	//input: F&& f  			函数指针(函数名)
+	//input: Args&&... args		函数的参数, 自定义
+    template<class F, class... Args>
+    auto enqueue(F&& f, Args&&... args) 
+        -> std::future<typename std::result_of<F(Args...)>::type>;
+
+
+    ~Thread_pool();
+
+	//判断线程池是否超载
+    bool thread_is_full_load();
+
+private:
+    // 线程数组
+    std::vector< std::thread > workers;
+	//每个线程的工作状态, true:线程正在执行任务,  false:线程空闲等待
+	std::vector< bool > working_flag_vector;
+    // 任务函数 队列, 里面存入的是任务函数的指针
+    std::queue< std::function<void()> > tasks;
+    
+    // 线程锁和条件变量
+    std::mutex queue_mutex;
+    std::condition_variable condition;
+
+    //终止标志位
+    bool stop;
+};
+
+//构造函数, 会自动初始化 threads_size 数量的线程
+inline Thread_pool::Thread_pool(size_t threads_size)
+    :   stop(false)
+{
+	//每个线程的工作状态
+	for(size_t i = 0;i<threads_size;++i)
+	{
+		working_flag_vector.push_back(false);
+	}
+
+	//初始化 threads_size 数量的线程
+    for(size_t i = 0;i<threads_size;++i)
+        workers.emplace_back(
+            [i,this]   //每个线程的执行的基本函数,
+            {
+                for(;;)
+                {
+                    std::function<void()> task;
+
+					{
+						std::unique_lock<std::mutex> lock(this->queue_mutex);
+						this->working_flag_vector[i] = false;//线程等待
+						this->condition.wait(lock,
+											 [this]    //线程等待的判断函数
+											 { return this->stop || !this->tasks.empty(); });
+						if (this->stop )//&& this->tasks.empty()) //这里修改了, 不需要把任务池都执行完才退出, stop之后就可以退了.
+						{
+							return;//只有在终止标志位true, 那么就退出线程执行函数
+						}
+						this->working_flag_vector[i] = true;//线程工作
+						//从 任务池 里面取出 执行函数
+						task = std::move(this->tasks.front());
+						this->tasks.pop();
+					}
+
+					//运行执行函数
+                    task();
+                }
+            }
+        );
+}
+
+
+//构造函数,没有初始化的,后续需要调用init才能正常使用
+inline Thread_pool::Thread_pool()
+:   stop(false)
+{
+
+}
+//初始化,初始化 threads_size 数量的线程
+inline void Thread_pool::thread_pool_init(size_t threads_size)
+{
+	stop = false;
+
+	//每个线程的工作状态
+	for(size_t i = 0;i<threads_size;++i)
+	{
+		working_flag_vector.push_back(false);
+	}
+
+	//初始化 threads_size 数量的线程
+	for(size_t i = 0;i<threads_size;++i)
+		workers.emplace_back(
+		[i,this]   //每个线程的执行的基本函数,
+		{
+			for(;;)
+			{
+				std::function<void()> task;
+
+				{
+					std::unique_lock<std::mutex> lock(this->queue_mutex);
+					this->working_flag_vector[i] = false;//线程等待
+					this->condition.wait(lock,
+										 [this]    //线程等待的判断函数
+										 { return this->stop || !this->tasks.empty(); });
+					if (this->stop )//&& this->tasks.empty()) //这里修改了, 不需要把任务池都执行完才退出, stop之后就可以退了.
+					{
+						return;//只有在终止标志位true, 那么就退出线程执行函数
+					}
+					this->working_flag_vector[i] = true;//线程工作
+					//从 任务池 里面取出 执行函数
+					task = std::move(this->tasks.front());
+					this->tasks.pop();
+				}
+
+				//运行执行函数
+				task();
+			}
+		}
+		);
+}
+
+//反初始化
+inline void Thread_pool::thread_pool_uninit()
+{
+	{
+		std::unique_lock<std::mutex> lock(queue_mutex);
+		stop = true;
+	}
+	condition.notify_all();
+
+	for (auto iter = workers.begin(); iter != workers.end(); )
+	{
+		iter->join();
+		iter = workers.erase(iter);
+	}
+	working_flag_vector.clear();
+}
+
+
+//往线程池添加执行任务, 之后会唤醒一个线程去执行他.
+//input: F&& f  			函数指针(函数名)
+//input: Args&&... args		函数的参数, 自定义
+//注注注注注意了:::::  res是enqueue的返回值, 由于线程异步, 使用future, 可以返回未来的一个值,
+// 在子线程执行完成之后, 将结果返回给外部主线程
+// 外部主线程 调用时, 必须使用 std::future<return_type> 格式去接受
+template<class F, class... Args>
+auto Thread_pool::enqueue(F&& f, Args&&... args) 
+    -> std::future<typename std::result_of<F(Args...)>::type>
+{
+    using return_type = typename std::result_of<F(Args...)>::type;
+
+    auto task = std::make_shared< std::packaged_task<return_type()> >(
+            std::bind(std::forward<F>(f), std::forward<Args>(args)...)
+        );
+
+
+    std::future<return_type> res = task->get_future();
+    {
+        std::unique_lock<std::mutex> lock(queue_mutex);
+
+        // don't allow enqueueing after stopping the pool
+        if(stop)
+            throw std::runtime_error("enqueue on stopped Thread_pool");
+
+        tasks.emplace([task](){ (*task)(); });
+    }
+    condition.notify_one();
+    return res;
+}
+
+// the destructor joins all threads
+inline Thread_pool::~Thread_pool()
+{
+    {
+        std::unique_lock<std::mutex> lock(queue_mutex);
+        stop = true;
+    }
+    condition.notify_all();
+    for(std::thread &worker: workers)
+	{  worker.join();}
+
+
+}
+
+//判断线程池是否超载
+inline bool Thread_pool::thread_is_full_load()
+{
+	//只要有一个线程wait, 那么就认为没有超载,
+	std::unique_lock<std::mutex> lock(queue_mutex);
+	bool result = true;
+	for(bool t_working_flag: working_flag_vector)
+	{
+		if ( !t_working_flag )
+		{
+			result = false;
+		}
+	}
+	return result;
+}
+
+
+#endif

+ 6 - 0
tool/thread_safe_list.cpp

@@ -0,0 +1,6 @@
+
+
+
+#include "thread_safe_queue.h"
+
+

+ 354 - 0
tool/thread_safe_list.h

@@ -0,0 +1,354 @@
+
+
+/*
+ * (1)这个实现要求构建工具支持C++11的atomic mutex condition_veriable功能。这是C++11的基础特性,一般2011年以后的C++编译器都能支持。 例如,visual studio 2012以上。
+
+(2)这个类的实现中有两处使用了unique_lock而不是lock_guard,这是data_cond.wait所需要的,unique_lock是lock_guard的增强版。
+
+通过std::move的使用(前提是我们实现的类型T定义了移动构造函数和移动赋值函数),能利用移动语义带来的性能优势。
+
+使用shared_ptr<T>返回元素,用户无需释放元素的内存。
+
+
+原文链接:https://blog.csdn.net/weixin_41855721/article/details/81703818
+ 增加了一些功能函数,
+ 补充了注释说明
+
+ termination_list
+ 	// 在退出状态下,所有的功能函数不可用,返回false或者null。
+	// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+
+ pop系列函数
+	//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+	//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+	//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+注注注注注意了:模板类不支持分离编译。 模板类的实现必须放在头文件
+ 为了方便阅读和编程规范,依然将声明和实现分开,就像是把cpp文件的代码复制到h文件的尾部。
+
+ 如果将实现放到cpp里面,那么就要为cpp文件加 ifndef define endif 防止重定义。
+ 然后在调用方include包含cpp文件,但是这样不好。
+
+
+ thread_safe_queue  就是在 Thread_safe_queue 的基础上修改的,
+
+ * */
+
+#ifndef __THREAD_SAFE_LIST_H__
+#define __THREAD_SAFE_LIST_H__
+
+#include <list>
+
+#include <atomic>
+#include <mutex>
+#include <condition_variable>
+
+
+template<class T>
+class Thread_safe_list
+{
+public:
+	Thread_safe_list();
+	Thread_safe_list(const Thread_safe_list& other);
+	~Thread_safe_list();
+
+	//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+	//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+	//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+	//等待并弹出数据,成功弹出则返回true
+	// 队列为空则无限等待,termination终止队列,则返回false
+	bool wait_and_pop(T& value);
+	//尝试弹出数据,成功弹出则返回true
+	//队列为空 或者 termination终止队列,返回false
+	bool try_pop(T& value);
+	//等待并弹出数据,成功弹出则返回true
+	// 队列为空则无限等待,termination终止队列,则返回false
+	std::shared_ptr<T> wait_and_pop();
+	//尝试弹出数据,成功弹出则返回true
+	//队列为空 或者 termination终止队列,返回false
+	std::shared_ptr<T> try_pop();
+	//插入一项,并唤醒一个线程,
+	//如果成功插入,则返回true,  失败则返回false
+	//注:只能唤醒一个线程,防止多线程误判empty()
+	bool push(T new_value);
+	//清除队列,只是将队列的实例抛出。T是实例内存,系统自动回收的。
+	bool clear();
+	//清除队列,抛出之后还要delete指针。T是动态内存,需要手动回收的。
+	bool clear_and_delete();
+
+public:
+	//判空
+	bool empty();
+	//获取队列大小
+	size_t size();
+	//设置队列为退出状态。并唤醒所有的线程,使其通过wait
+	// 在退出状态下,所有的功能函数不可用,必须直接返回false或者null。
+	// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+	void termination_list();
+	//唤醒队列,恢复所有的功能函数。wait_and_pop会继续阻塞。
+	void wake_list();
+	//获取退出状态
+	bool get_termination_flag();
+	//判断是否可以直接通过wait,  m_data_list不为空或者m_termination终止时都可以通过等待。
+	bool is_pass();
+
+public:
+	std::mutex 						m_mutex;				//队列的锁
+	std::list<std::shared_ptr<T>> 	m_data_list;			//队列数据,使用智能指针shared_ptr
+	std::condition_variable 		m_data_cond;			//条件变量
+	std::atomic<bool> 				m_termination_flag;		//终止标志位
+
+private:
+
+
+};
+
+
+
+
+
+
+
+
+template<class T>
+Thread_safe_list<T>::Thread_safe_list()
+{
+	m_termination_flag = false;
+}
+template<class T>
+Thread_safe_list<T>::Thread_safe_list(const Thread_safe_list& other)
+{
+	std::unique_lock<std::mutex> lock_this(m_mutex);
+	std::unique_lock<std::mutex> lock_other(other.m_mutex);
+	m_data_list = other.data_list;
+	m_termination_flag = other.m_termination_flag;
+}
+template<class T>
+Thread_safe_list<T>::~Thread_safe_list()
+{
+	//析构时,终止队列,让线程通过等待,方便线程推出。
+	termination_list();
+}
+
+//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+//等待并弹出数据,成功弹出则返回true
+// 队列为空则无限等待,termination终止队列,则返回false
+template<class T>
+bool Thread_safe_list<T>::wait_and_pop(T& value)
+{
+	if ( m_termination_flag )
+	{
+		return false;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		//无限等待,一直阻塞,除非有新的数据加入或者终止队列
+		m_data_cond.wait(lk, [this]
+		{ return ((!m_data_list.empty()) || m_termination_flag); });
+		if (m_termination_flag)
+		{
+			return false;
+		}
+		else
+		{
+//			value = move(*m_data_list.front());
+			value = (*m_data_list.front());
+
+			m_data_list.pop_front();
+			return true;
+		}
+	}
+}
+//尝试弹出数据,成功弹出则返回true
+//队列为空 或者 termination终止队列,返回false
+template<class T>
+bool Thread_safe_list<T>::try_pop(T& value)
+{
+	if ( m_termination_flag )
+	{
+		return false;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		if (m_data_list.empty())
+		{
+			return false;
+		}
+		else
+		{
+//			value = move(*m_data_list.front());
+			value = (*m_data_list.front());
+
+			m_data_list.pop();
+			return true;
+		}
+	}
+}
+
+
+
+//等待并弹出数据,成功弹出则返回true
+// 队列为空则无限等待,termination终止队列,则返回false
+template<class T>
+std::shared_ptr<T> Thread_safe_list<T>::wait_and_pop()
+{
+	if ( m_termination_flag )
+	{
+		return NULL;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		//无限等待,一直阻塞,除非有新的数据加入或者终止队列
+		m_data_cond.wait(lk, [this]
+		{ return ((!m_data_list.empty()) || m_termination_flag); });
+		if (m_termination_flag)
+		{
+			return NULL;
+		}
+		else
+		{
+			std::shared_ptr<T> res = m_data_list.front();
+			m_data_list.pop();
+			return res;
+		}
+	}
+}
+//尝试弹出数据,成功弹出则返回true
+//队列为空 或者 termination终止队列,返回false
+template<class T>
+std::shared_ptr<T> Thread_safe_list<T>::try_pop()
+{
+	if ( m_termination_flag )
+	{
+		return NULL;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		if (m_data_list.empty())
+		{
+			return NULL;
+		}
+		else
+		{
+			std::shared_ptr<T> res = m_data_list.front();
+			m_data_list.pop();
+			return res;
+		}
+	}
+}
+//插入一项,并唤醒一个线程,
+//如果成功插入,则返回true,  失败则返回false
+//注:只能唤醒一个线程,防止多线程误判empty()
+template<class T>
+bool Thread_safe_list<T>::push(T new_value)
+{
+	if (m_termination_flag)
+	{
+		return false;
+	}
+	else
+	{
+//		std::shared_ptr<T> data(std::make_shared<T>(move(new_value)));
+		std::shared_ptr<T> data(std::make_shared<T>((new_value)));
+		std::unique_lock<std::mutex> lk(m_mutex);
+		m_data_list.push_back(data);
+		m_data_cond.notify_one();
+		return true;
+	}
+}
+//清除队列,只是将队列的实例抛出。T是实例内存,系统自动回收的。
+template<class T>
+bool Thread_safe_list<T>::clear()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	while (!m_data_list.empty())
+	{
+		m_data_list.pop_front();
+	}
+	return true;
+
+}
+
+//清除队列,抛出之后还要delete指针。T是动态内存,需要手动回收的。
+template<class T>
+bool Thread_safe_list<T>::clear_and_delete()
+{
+
+	std::unique_lock<std::mutex> lk(m_mutex);
+	while (!m_data_list.empty())
+	{
+		T res = NULL;
+//		res = move(*m_data_list.front());
+		res = (*m_data_list.front());
+
+		m_data_list.pop_front();
+		if(res != NULL)
+		{
+			delete(res);
+
+		}
+	}
+	return true;
+}
+
+
+
+//判空
+template<class T>
+bool Thread_safe_list<T>::empty()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	return m_data_list.empty();
+}
+//获取队列大小
+template<class T>
+size_t Thread_safe_list<T>::size()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	return m_data_list.size();
+}
+//设置队列为退出状态。并唤醒所有的线程,使其通过wait
+// 在退出状态下,所有的功能函数不可用,必须直接返回false或者null。
+// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+template<class T>
+void Thread_safe_list<T>::termination_list()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	m_termination_flag = true;
+	m_data_cond.notify_all();
+}
+//唤醒队列,恢复所有的功能函数。wait_and_pop会继续阻塞。
+template<class T>
+void Thread_safe_list<T>::wake_list()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	m_termination_flag = false;
+	m_data_cond.notify_all();
+}
+//获取退出状态
+template<class T>
+bool Thread_safe_list<T>::get_termination_flag()
+{
+	return m_termination_flag;
+}
+//判断是否可以直接通过wait,  m_data_list不为空或者m_termination终止时都可以通过等待。
+template<class T>
+bool Thread_safe_list<T>::is_pass()
+{
+	return (!m_data_list.empty() || m_termination_flag);
+}
+
+
+
+
+
+
+#endif //__THREAD_SAFE_LIST_H__

+ 5 - 0
tool/thread_safe_map.cpp

@@ -0,0 +1,5 @@
+//
+// Created by zx on 2020/7/3.
+//
+
+#include "thread_safe_map.h"

+ 55 - 0
tool/thread_safe_map.h

@@ -0,0 +1,55 @@
+//
+// Created by zx on 2020/7/3.
+//
+
+#ifndef NNXX_TESTS_THREAD_SAFE_MAP_H
+#define NNXX_TESTS_THREAD_SAFE_MAP_H
+
+
+#include <map>
+#include <mutex>
+template<typename Key, typename Val>
+class thread_safe_map
+{
+public:
+    typedef typename std::map<Key, Val>::iterator this_iterator;
+    typedef typename std::map<Key, Val>::const_iterator this_const_iterator;
+    Val& operator [](const Key& key)
+    {
+        std::lock_guard<std::mutex> lk(mtx_);
+        return dataMap_[key];
+    }
+    int erase(const Key& key )
+    {
+        std::lock_guard<std::mutex> lk(mtx_);
+        return dataMap_.erase(key);
+    }
+
+    this_iterator find( const Key& key )
+    {
+        std::lock_guard<std::mutex> lk(mtx_);
+        return dataMap_.find(key);
+    }
+    this_const_iterator find( const Key& key ) const
+    {
+        std::lock_guard<std::mutex> lk(mtx_);
+        return dataMap_.find(key);
+    }
+
+    this_iterator end()
+    {
+        return dataMap_.end();
+    }
+
+    this_const_iterator end() const
+    {
+        return dataMap_.end();
+    }
+
+private:
+    std::map<Key, Val> dataMap_;
+    std::mutex mtx_;
+};
+
+
+#endif //NNXX_TESTS_THREAD_SAFE_MAP_H

+ 34 - 0
tool/thread_safe_queue.cpp

@@ -0,0 +1,34 @@
+
+
+/*
+ * (1)这个实现要求构建工具支持C++11的atomic std::mutex condition_veriable功能。这是C++11的基础特性,一般2011年以后的C++编译器都能支持。 例如,visual studio 2012以上。
+
+(2)这个类的实现中有两处使用了unique_lock而不是lock_guard,这是data_cond.wait所需要的,unique_lock是lock_guard的增强版。
+
+通过std::move的使用(前提是我们实现的类型T定义了移动构造函数和移动赋值函数),能利用移动语义带来的性能优势。
+
+使用shared_ptr<T>返回元素,用户无需释放元素的内存。
+
+
+原文链接:https://blog.csdn.net/weixin_41855721/article/details/81703818
+引用了他的思路,增加了一些功能函数, 补充了注释说明
+
+ termination_queue
+ 	// 在退出状态下,所有的功能函数不可用,返回false或者null。
+	// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+
+ pop系列函数
+	//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+	//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+	//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+注注注注注意了:模板类不支持分离编译。 模板类的实现必须放在头文件
+ 为了方便阅读和编程规范,依然将声明和实现分开,就像是把cpp文件的代码复制到h文件的尾部。
+
+ 如果将实现放到cpp里面,那么就要为cpp文件加 ifndef define endif
+ 然后在调用方include包含cpp文件,但是这样不好。
+ * */
+
+#include "thread_safe_queue.h"
+
+

+ 339 - 0
tool/thread_safe_queue.h

@@ -0,0 +1,339 @@
+
+
+/*
+ * (1)这个实现要求构建工具支持C++11的atomic mutex condition_veriable功能。这是C++11的基础特性,一般2011年以后的C++编译器都能支持。 例如,visual studio 2012以上。
+
+(2)这个类的实现中有两处使用了unique_lock而不是lock_guard,这是data_cond.wait所需要的,unique_lock是lock_guard的增强版。
+
+通过std::move的使用(前提是我们实现的类型T定义了移动构造函数和移动赋值函数),能利用移动语义带来的性能优势。
+
+使用shared_ptr<T>返回元素,用户无需释放元素的内存。
+
+
+原文链接:https://blog.csdn.net/weixin_41855721/article/details/81703818
+ 增加了一些功能函数,
+ 补充了注释说明
+
+ termination_queue
+ 	// 在退出状态下,所有的功能函数不可用,返回false或者null。
+	// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+
+ pop系列函数
+	//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+	//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+	//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+注注注注注意了:模板类不支持分离编译。 模板类的实现必须放在头文件
+ 为了方便阅读和编程规范,依然将声明和实现分开,就像是把cpp文件的代码复制到h文件的尾部。
+
+ 如果将实现放到cpp里面,那么就要为cpp文件加 ifndef define endif 防止重定义。
+ 然后在调用方include包含cpp文件,但是这样不好。
+
+
+ * */
+
+#ifndef LIDARMEASURE_THREAD_SAFE_QUEUE_H
+#define LIDARMEASURE_THREAD_SAFE_QUEUE_H
+
+#include <queue>
+
+#include <atomic>
+#include <mutex>
+#include <condition_variable>
+
+
+template<class T>
+class Thread_safe_queue
+{
+public:
+	Thread_safe_queue();
+	Thread_safe_queue(const Thread_safe_queue& other);
+	~Thread_safe_queue();
+
+	//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+	//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+	//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+	//等待并弹出数据,成功弹出则返回true
+	// 队列为空则无限等待,termination终止队列,则返回false
+	bool wait_and_pop(T& value);
+	//尝试弹出数据,成功弹出则返回true
+	//队列为空 或者 termination终止队列,返回false
+	bool try_pop(T& value);
+	//等待并弹出数据,成功弹出则返回true
+	// 队列为空则无限等待,termination终止队列,则返回false
+	std::shared_ptr<T> wait_and_pop();
+	//尝试弹出数据,成功弹出则返回true
+	//队列为空 或者 termination终止队列,返回false
+	std::shared_ptr<T> try_pop();
+	//插入一项,并唤醒一个线程,
+	//如果成功插入,则返回true,  失败则返回false
+	//注:只能唤醒一个线程,防止多线程误判empty()
+	bool push(T new_value);
+	//清除队列,只是将队列的实例抛出。T是实例内存,系统自动回收的。
+	bool clear();
+	//清除队列,抛出之后还要delete指针。T是动态内存,需要手动回收的。
+	bool clear_and_delete();
+
+public:
+	//判空
+	bool empty();
+	//获取队列大小
+	size_t size();
+	//设置队列为退出状态。并唤醒所有的线程,使其通过wait
+	// 在退出状态下,所有的功能函数不可用,必须直接返回false或者null。
+	// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+	void termination_queue();
+	//唤醒队列,恢复所有的功能函数。wait_and_pop会继续阻塞。
+	void wake_queue();
+	//获取退出状态
+	bool get_termination_flag();
+	//判断是否可以直接通过wait,  m_data_queue不为空或者m_termination终止时都可以通过等待。
+	bool is_pass();
+
+protected:
+	std::mutex 						m_mutex;				//队列的锁
+	std::queue<std::shared_ptr<T>> 	m_data_queue;			//队列数据,使用智能指针shared_ptr
+	std::condition_variable 		m_data_cond;			//条件变量
+	std::atomic<bool> 				m_termination_flag;		//终止标志位
+
+private:
+
+
+};
+
+
+
+
+
+
+
+
+template<class T>
+Thread_safe_queue<T>::Thread_safe_queue()
+{
+	m_termination_flag = false;
+}
+template<class T>
+Thread_safe_queue<T>::Thread_safe_queue(const Thread_safe_queue& other)
+{
+	std::unique_lock<std::mutex> lock_this(m_mutex);
+	std::unique_lock<std::mutex> lock_other(other.m_mutex);
+	m_data_queue = other.data_queue;
+	m_termination_flag = other.m_termination_flag;
+}
+template<class T>
+Thread_safe_queue<T>::~Thread_safe_queue()
+{
+	//析构时,终止队列,让线程通过等待,方便线程推出。
+	termination_queue();
+}
+
+//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+//等待并弹出数据,成功弹出则返回true
+// 队列为空则无限等待,termination终止队列,则返回false
+template<class T>
+bool Thread_safe_queue<T>::wait_and_pop(T& value)
+{
+	if ( m_termination_flag )
+	{
+		return false;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		//无限等待,一直阻塞,除非有新的数据加入或者终止队列
+		m_data_cond.wait(lk, [this]
+		{ return ((!m_data_queue.empty()) || m_termination_flag); });
+		if (m_termination_flag)
+		{
+			return false;
+		}
+		else
+		{
+			value = move(*m_data_queue.front());
+			m_data_queue.pop();
+			return true;
+		}
+	}
+}
+//尝试弹出数据,成功弹出则返回true
+//队列为空 或者 termination终止队列,返回false
+template<class T>
+bool Thread_safe_queue<T>::try_pop(T& value)
+{
+	if ( m_termination_flag )
+	{
+		return false;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		if (m_data_queue.empty())
+		{
+			return false;
+		}
+		else
+		{
+			value = move(*m_data_queue.front());
+			m_data_queue.pop();
+			return true;
+		}
+	}
+}
+//等待并弹出数据,成功弹出则返回true
+// 队列为空则无限等待,termination终止队列,则返回false
+template<class T>
+std::shared_ptr<T> Thread_safe_queue<T>::wait_and_pop()
+{
+	if ( m_termination_flag )
+	{
+		return NULL;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		//无限等待,一直阻塞,除非有新的数据加入或者终止队列
+		m_data_cond.wait(lk, [this]
+		{ return ((!m_data_queue.empty()) || m_termination_flag); });
+		if (m_termination_flag)
+		{
+			return NULL;
+		}
+		else
+		{
+			std::shared_ptr<T> res = m_data_queue.front();
+			m_data_queue.pop();
+			return res;
+		}
+	}
+}
+//尝试弹出数据,成功弹出则返回true
+//队列为空 或者 termination终止队列,返回false
+template<class T>
+std::shared_ptr<T> Thread_safe_queue<T>::try_pop()
+{
+	if ( m_termination_flag )
+	{
+		return NULL;
+	}
+	else
+	{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		if (m_data_queue.empty())
+		{
+			return NULL;
+		}
+		else
+		{
+			std::shared_ptr<T> res = m_data_queue.front();
+			m_data_queue.pop();
+			return res;
+		}
+	}
+}
+//插入一项,并唤醒一个线程,
+//如果成功插入,则返回true,  失败则返回false
+//注:只能唤醒一个线程,防止多线程误判empty()
+template<class T>
+bool Thread_safe_queue<T>::push(T new_value)
+{
+	if (m_termination_flag)
+	{
+		return false;
+	}
+	else
+	{
+		std::shared_ptr<T> data(std::make_shared<T>(move(new_value)));
+		std::unique_lock<std::mutex> lk(m_mutex);
+		m_data_queue.push(data);
+		m_data_cond.notify_one();
+		return true;
+	}
+}
+//清除队列,只是将队列的实例抛出。T是实例内存,系统自动回收的。
+template<class T>
+bool Thread_safe_queue<T>::clear()
+{
+		std::unique_lock<std::mutex> lk(m_mutex);
+		while (!m_data_queue.empty())
+		{
+			m_data_queue.pop();
+		}
+		return true;
+
+}
+//清除队列,抛出之后还要delete指针。T是动态内存,需要手动回收的。
+template<class T>
+bool Thread_safe_queue<T>::clear_and_delete()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	while (!m_data_queue.empty())
+	{
+		T res = NULL;
+		res = move(*m_data_queue.front());
+		m_data_queue.pop();
+		if(res != NULL)
+		{
+			delete(res);
+
+		}
+	}
+	return true;
+
+}
+
+//判空
+template<class T>
+bool Thread_safe_queue<T>::empty()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	return m_data_queue.empty();
+}
+//获取队列大小
+template<class T>
+size_t Thread_safe_queue<T>::size()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	return m_data_queue.size();
+}
+//设置队列为退出状态。并唤醒所有的线程,使其通过wait
+// 在退出状态下,所有的功能函数不可用,必须直接返回false或者null。
+// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+template<class T>
+void Thread_safe_queue<T>::termination_queue()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	m_termination_flag = true;
+	m_data_cond.notify_all();
+}
+//唤醒队列,恢复所有的功能函数。wait_and_pop会继续阻塞。
+template<class T>
+void Thread_safe_queue<T>::wake_queue()
+{
+	std::unique_lock<std::mutex> lk(m_mutex);
+	m_termination_flag = false;
+	m_data_cond.notify_all();
+}
+//获取退出状态
+template<class T>
+bool Thread_safe_queue<T>::get_termination_flag()
+{
+	return m_termination_flag;
+}
+//判断是否可以直接通过wait,  m_data_queue不为空或者m_termination终止时都可以通过等待。
+template<class T>
+bool Thread_safe_queue<T>::is_pass()
+{
+	return (!m_data_queue.empty() || m_termination_flag);
+}
+
+
+
+
+
+
+#endif //LIDARMEASURE_THREAD_SAFE_QUEUE_H

+ 108 - 0
tool/thread_safe_queue.puml

@@ -0,0 +1,108 @@
+@startuml
+skinparam classAttributeIconSize 0
+
+title  Thread_safe_queue 安全线程队列
+
+note left of Thread_safe_queue
+
+/*
+ * (1)这个实现要求构建工具支持C++11的atomic mutex condition_veriable功能。这是C++11的基础特性,一般2011年以后的C++编译器都能支持。 例如,visual studio 2012以上。
+
+(2)这个类的实现中有两处使用了unique_lock而不是lock_guard,这是data_cond.wait所需要的,unique_lock是lock_guard的增强版。
+
+通过std::move的使用(前提是我们实现的类型T定义了移动构造函数和移动赋值函数),能利用移动语义带来的性能优势。
+
+使用shared_ptr<T>返回元素,用户无需释放元素的内存。
+
+
+原文链接:https://blog.csdn.net/weixin_41855721/article/details/81703818
+ 增加了一些功能函数,
+ 补充了注释说明
+
+ termination_queue
+ 	// 在退出状态下,所有的功能函数不可用,返回false或者null。
+	// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+
+ pop系列函数
+	//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+	//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+	//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+
+注注注注注意了:模板类不支持分离编译。 模板类的实现必须放在头文件
+ 为了方便阅读和编程规范,依然将声明和实现分开,就像是把cpp文件的代码复制到h文件的尾部。
+
+ 如果将实现放到cpp里面,那么就要为cpp文件加 ifndef define endif 防止重定义。
+ 然后在调用方include包含cpp文件,但是这样不好。
+
+
+ * */
+end note
+
+
+
+class Thread_safe_queue <<    template<class T>    >>
+{
+==public:==
+	Thread_safe_queue();
+	Thread_safe_queue(const Thread_safe_queue& other);
+	~Thread_safe_queue();
+..
+	//(1)没有调用termination时,每调用一次出队一个元素,直到队列为空本方法阻塞线程。
+	//(2)在调用了termination后,本方法永不阻塞,如果原本已经处于阻塞状态,解除阻塞状态。
+	//(3)返回true时,value值有效。返回false时,value值无效。调用了termination且队列为空时返回false.
+	//等待并弹出数据,成功弹出则返回true
+	// 队列为空则无限等待,termination终止队列,则返回false
+	bool wait_and_pop(T& value);
+..
+	//尝试弹出数据,成功弹出则返回true
+	//队列为空 或者 termination终止队列,返回false
+	bool try_pop(T& value);
+..
+	//等待并弹出数据,成功弹出则返回true
+	// 队列为空则无限等待,termination终止队列,则返回false
+	std::shared_ptr<T> wait_and_pop();
+..
+	//尝试弹出数据,成功弹出则返回true
+	//队列为空 或者 termination终止队列,返回false
+	std::shared_ptr<T> try_pop();
+..
+	//插入一项,并唤醒一个线程,
+	//如果成功插入,则返回true,  失败则返回false
+	//注:只能唤醒一个线程,防止多线程误判empty()
+	bool push(T new_value);
+..
+	//清除队列,只是将队列的实例抛出。T是实例内存,系统自动回收的。
+	bool clear();
+..
+	//清除队列,抛出之后还要delete指针。T是动态内存,需要手动回收的。
+	bool clear_and_delete();
+==public:==
+	//判空
+	bool empty();
+..
+	//获取队列大小
+	size_t size();
+..
+	//设置队列为退出状态。并唤醒所有的线程,使其通过wait
+	// 在退出状态下,所有的功能函数不可用,必须直接返回false或者null。
+	// wait_and_pop不会阻塞。让其直接通过,通过后直接return,不允许做其他的。
+	void termination_queue();
+..
+	//唤醒队列,恢复所有的功能函数。wait_and_pop会继续阻塞。
+	void wake_queue();
+..
+	//获取退出状态
+	bool get_termination_flag();
+..
+	//判断是否可以直接通过wait,  m_data_queue不为空或者m_termination终止时都可以通过等待。
+	bool is_pass();
+==protected:==
+	std::mutex 						m_mutex;				//队列的锁
+	std::queue<std::shared_ptr<T>> 	m_data_queue;			//队列数据,使用智能指针shared_ptr
+	std::condition_variable 		m_data_cond;			//条件变量
+	std::atomic<bool> 				m_termination_flag;		//终止标志位
+==private:==
+}
+
+
+@enduml