Browse Source

add parkspace lock status, confirm req/res. DB basic connection and CURD ops were tested.

youchen 4 years ago
parent
commit
51b4fc48f8

+ 19 - 4
CMakeLists.txt

@@ -3,7 +3,7 @@ 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")
+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)
@@ -11,7 +11,6 @@ FIND_PACKAGE(Glog REQUIRED)
 FIND_PACKAGE(OpenCV REQUIRED)
 FIND_PACKAGE(PCL REQUIRED)
 
-
 include_directories(
         /usr/local/include
         ${PCL_INCLUDE_DIRS}
@@ -23,13 +22,14 @@ include_directories(
         message
         error_code
         tool
-	system
+        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 )
@@ -59,6 +59,7 @@ target_link_libraries(parkspace_test
         ${PROTOBUF_LIBRARIES}
         /usr/local/lib/libglog.a
         /usr/local/lib/libgflags.a
+        libmysqlcppconn.so
         )
 add_executable(parkspace_client
         ./test/parkspace_client.cpp
@@ -74,3 +75,17 @@ target_link_libraries(parkspace_client
         /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
+        )

+ 3 - 1
communication/communication_message.h

@@ -42,6 +42,8 @@ public:
 		eParkspace_release_response_msg = 0x37,		//释放车位反馈消息
 		eParkspace_force_update_request_msg = 0x38,	//手动修改车位消息
 		eParkspace_force_update_response_msg = 0x39,//手动修改车位反馈消息
+		eParkspace_confirm_alloc_request_msg = 0x40,//确认分配车位请求消息
+		eParkspace_confirm_alloc_response_msg = 0x41,//确认分配车位反馈消息
 	};
 
 	//通讯单元
@@ -50,7 +52,7 @@ public:
 		eEmpty=0x0000,		//空
 		eMain=0x0001,    	//主流程
 		eTerminor=0x0100,	//终端
-		eParkspace_allocator=0x0200,		//数据表
+		eParkspace=0x0200,		//数据表
 		eMeasurer=0x0300,	//测量单元
 		eProcess=0x0400,	//调度机构
 		//...

+ 11 - 1
error_code/error_code.h

@@ -296,7 +296,17 @@ enum Error_code
     PARKSPACE_ALLOCATOR_SEARCH_FAILED,              //未找到车辆对应车位
     PARKSPACE_ALLOCATOR_RELEASE_FAILED,             //未找到匹配的车位,车位未释放
     PARKSPACE_ALLOCATOR_FORCE_UPDATE_FAILED,        //手动更新失败,未找到匹配车位
-    PARKSPACE_ALLOCATOR_PARAM_ERROR,                //传入待释放车位参数错误,内部无车辆信息
+    PARKSPACE_ALLOCATOR_PARAM_ERROR,                //传入参数错误,内部无车辆信息
+    PARKSPACE_ALLOCATOR_CONFIRM_ALLOC_ERROR,        //确认分配车位错误
+
+    // 数据库操作
+    DB_ERROR_BASE                                   = 0x20020000,
+    DB_INIT_FAILED,
+    DB_CONNECT_FAILED,                              //数据库连接失败
+    DB_INSERT_FAILED,                               //数据库插入失败
+    DB_DELETE_FAILED,                               //数据库删除失败
+    DB_UPDATE_FAILED,                               //数据库更新失败
+    DB_QUERY_FAILED,                                //数据库查询失败
 };
 
 //错误等级,用来做故障处理

+ 13 - 9
message/message_base.pb.cc

@@ -236,7 +236,7 @@ void AddDescriptorsImpl() {
       "\030\004 \001(\002\022\024\n\014locate_width\030\005 \001(\002\022\025\n\rlocate_h"
       "eight\030\006 \001(\002\022\031\n\021locate_wheel_base\030\007 \001(\002\022\032"
       "\n\022locate_wheel_width\030\010 \001(\002\022\026\n\016locate_cor"
-      "rect\030\t \001(\010*\237\004\n\014Message_type\022\r\n\teBase_msg"
+      "rect\030\t \001(\010*\364\004\n\014Message_type\022\r\n\teBase_msg"
       "\020\000\022\020\n\014eCommand_msg\020\001\022\026\n\022eLocate_status_m"
       "sg\020\021\022\027\n\023eLocate_request_msg\020\022\022\030\n\024eLocate"
       "_response_msg\020\023\022\026\n\022eHarware_statu_msg\020!\022"
@@ -249,16 +249,18 @@ void AddDescriptorsImpl() {
       "\022\"\n\036eParkspace_release_request_msg\0206\022#\n\037"
       "eParkspace_release_response_msg\0207\022\'\n#ePa"
       "rkspace_force_update_request_msg\0208\022(\n$eP"
-      "arkspace_force_update_response_msg\0209*e\n\014"
-      "Communicator\022\n\n\006eEmpty\020\000\022\t\n\005eMain\020\001\022\016\n\te"
-      "Terminor\020\200\002\022\017\n\neParkspace\020\200\004\022\016\n\teMeasure"
-      "r\020\200\006\022\r\n\010eProcess\020\200\010*e\n\013Error_level\022\n\n\006NO"
-      "RMAL\020\000\022\024\n\020NEGLIGIBLE_ERROR\020\001\022\017\n\013MINOR_ER"
-      "ROR\020\002\022\017\n\013MAJOR_ERROR\020\003\022\022\n\016CRITICAL_ERROR"
-      "\020\004"
+      "arkspace_force_update_response_msg\0209\022(\n$"
+      "eParkspace_confirm_alloc_request_msg\020@\022)"
+      "\n%eParkspace_confirm_alloc_response_msg\020"
+      "A*e\n\014Communicator\022\n\n\006eEmpty\020\000\022\t\n\005eMain\020\001"
+      "\022\016\n\teTerminor\020\200\002\022\017\n\neParkspace\020\200\004\022\016\n\teMe"
+      "asurer\020\200\006\022\r\n\010eProcess\020\200\010*e\n\013Error_level\022"
+      "\n\n\006NORMAL\020\000\022\024\n\020NEGLIGIBLE_ERROR\020\001\022\017\n\013MIN"
+      "OR_ERROR\020\002\022\017\n\013MAJOR_ERROR\020\003\022\022\n\016CRITICAL_"
+      "ERROR\020\004"
   };
   ::google::protobuf::DescriptorPool::InternalAddGeneratedFile(
-      descriptor, 1322);
+      descriptor, 1407);
   ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile(
     "message_base.proto", &protobuf_RegisterTypes);
 }
@@ -298,6 +300,8 @@ bool Message_type_IsValid(int value) {
     case 55:
     case 56:
     case 57:
+    case 64:
+    case 65:
       return true;
     default:
       return false;

+ 4 - 2
message/message_base.pb.h

@@ -91,11 +91,13 @@ enum Message_type {
   eParkspace_release_request_msg = 54,
   eParkspace_release_response_msg = 55,
   eParkspace_force_update_request_msg = 56,
-  eParkspace_force_update_response_msg = 57
+  eParkspace_force_update_response_msg = 57,
+  eParkspace_confirm_alloc_request_msg = 64,
+  eParkspace_confirm_alloc_response_msg = 65
 };
 bool Message_type_IsValid(int value);
 const Message_type Message_type_MIN = eBase_msg;
-const Message_type Message_type_MAX = eParkspace_force_update_response_msg;
+const Message_type Message_type_MAX = eParkspace_confirm_alloc_response_msg;
 const int Message_type_ARRAYSIZE = Message_type_MAX + 1;
 
 const ::google::protobuf::EnumDescriptor* Message_type_descriptor();

+ 2 - 0
message/message_base.proto

@@ -26,6 +26,8 @@ enum Message_type
     eParkspace_release_response_msg = 0x37;		//释放车位反馈消息
     eParkspace_force_update_request_msg = 0x38;	//手动修改车位消息
     eParkspace_force_update_response_msg = 0x39;//手动修改车位反馈消息
+    eParkspace_confirm_alloc_request_msg = 0x40;//确认分配车位请求消息
+    eParkspace_confirm_alloc_response_msg = 0x41;//确认分配车位反馈消息
 }
 
 //通讯单元

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


+ 622 - 5
message/parkspace_allocation_message.pb.h

@@ -38,7 +38,7 @@ namespace protobuf_parkspace_5fallocation_5fmessage_2eproto {
 struct TableStruct {
   static const ::google::protobuf::internal::ParseTableField entries[];
   static const ::google::protobuf::internal::AuxillaryParseTableField aux[];
-  static const ::google::protobuf::internal::ParseTable schema[11];
+  static const ::google::protobuf::internal::ParseTable schema[13];
   static const ::google::protobuf::internal::FieldMetadata field_metadata[];
   static const ::google::protobuf::internal::SerializationTable serialization_table[];
   static const ::google::protobuf::uint32 offsets[];
@@ -64,6 +64,10 @@ void InitDefaultsParkspace_force_update_request_msgImpl();
 void InitDefaultsParkspace_force_update_request_msg();
 void InitDefaultsParkspace_force_update_response_msgImpl();
 void InitDefaultsParkspace_force_update_response_msg();
+void InitDefaultsParkspace_confirm_alloc_request_msgImpl();
+void InitDefaultsParkspace_confirm_alloc_request_msg();
+void InitDefaultsParkspace_confirm_alloc_response_msgImpl();
+void InitDefaultsParkspace_confirm_alloc_response_msg();
 void InitDefaultsParkspace_allocation_status_msgImpl();
 void InitDefaultsParkspace_allocation_status_msg();
 inline void InitDefaults() {
@@ -77,6 +81,8 @@ inline void InitDefaults() {
   InitDefaultsParkspace_release_response_msg();
   InitDefaultsParkspace_force_update_request_msg();
   InitDefaultsParkspace_force_update_response_msg();
+  InitDefaultsParkspace_confirm_alloc_request_msg();
+  InitDefaultsParkspace_confirm_alloc_response_msg();
   InitDefaultsParkspace_allocation_status_msg();
 }
 }  // namespace protobuf_parkspace_5fallocation_5fmessage_2eproto
@@ -93,6 +99,12 @@ extern Parkspace_allocation_response_msgDefaultTypeInternal _Parkspace_allocatio
 class Parkspace_allocation_status_msg;
 class Parkspace_allocation_status_msgDefaultTypeInternal;
 extern Parkspace_allocation_status_msgDefaultTypeInternal _Parkspace_allocation_status_msg_default_instance_;
+class Parkspace_confirm_alloc_request_msg;
+class Parkspace_confirm_alloc_request_msgDefaultTypeInternal;
+extern Parkspace_confirm_alloc_request_msgDefaultTypeInternal _Parkspace_confirm_alloc_request_msg_default_instance_;
+class Parkspace_confirm_alloc_response_msg;
+class Parkspace_confirm_alloc_response_msgDefaultTypeInternal;
+extern Parkspace_confirm_alloc_response_msgDefaultTypeInternal _Parkspace_confirm_alloc_response_msg_default_instance_;
 class Parkspace_force_update_request_msg;
 class Parkspace_force_update_request_msgDefaultTypeInternal;
 extern Parkspace_force_update_request_msgDefaultTypeInternal _Parkspace_force_update_request_msg_default_instance_;
@@ -119,9 +131,10 @@ namespace message {
 
 enum Parkspace_status {
   eParkspace_empty = 0,
-  eParkspace_occupied = 1,
-  eParkspace_reserverd = 2,
-  eParkspace_error = 3
+  eParkspace_locked = 1,
+  eParkspace_occupied = 2,
+  eParkspace_reserved = 3,
+  eParkspace_error = 4
 };
 bool Parkspace_status_IsValid(int value);
 const Parkspace_status Parkspace_status_MIN = eParkspace_empty;
@@ -1695,6 +1708,292 @@ class Parkspace_force_update_response_msg : public ::google::protobuf::Message /
 };
 // -------------------------------------------------------------------
 
+class Parkspace_confirm_alloc_request_msg : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:message.Parkspace_confirm_alloc_request_msg) */ {
+ public:
+  Parkspace_confirm_alloc_request_msg();
+  virtual ~Parkspace_confirm_alloc_request_msg();
+
+  Parkspace_confirm_alloc_request_msg(const Parkspace_confirm_alloc_request_msg& from);
+
+  inline Parkspace_confirm_alloc_request_msg& operator=(const Parkspace_confirm_alloc_request_msg& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Parkspace_confirm_alloc_request_msg(Parkspace_confirm_alloc_request_msg&& from) noexcept
+    : Parkspace_confirm_alloc_request_msg() {
+    *this = ::std::move(from);
+  }
+
+  inline Parkspace_confirm_alloc_request_msg& operator=(Parkspace_confirm_alloc_request_msg&& 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 Parkspace_confirm_alloc_request_msg& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Parkspace_confirm_alloc_request_msg* internal_default_instance() {
+    return reinterpret_cast<const Parkspace_confirm_alloc_request_msg*>(
+               &_Parkspace_confirm_alloc_request_msg_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    10;
+
+  void Swap(Parkspace_confirm_alloc_request_msg* other);
+  friend void swap(Parkspace_confirm_alloc_request_msg& a, Parkspace_confirm_alloc_request_msg& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Parkspace_confirm_alloc_request_msg* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Parkspace_confirm_alloc_request_msg* 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 Parkspace_confirm_alloc_request_msg& from);
+  void MergeFrom(const Parkspace_confirm_alloc_request_msg& 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(Parkspace_confirm_alloc_request_msg* 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 .message.Base_info base_info = 1;
+  bool has_base_info() const;
+  void clear_base_info();
+  static const int kBaseInfoFieldNumber = 1;
+  const ::message::Base_info& base_info() const;
+  ::message::Base_info* release_base_info();
+  ::message::Base_info* mutable_base_info();
+  void set_allocated_base_info(::message::Base_info* base_info);
+
+  // required .message.Parkspace_info confirm_space_info = 3;
+  bool has_confirm_space_info() const;
+  void clear_confirm_space_info();
+  static const int kConfirmSpaceInfoFieldNumber = 3;
+  const ::message::Parkspace_info& confirm_space_info() const;
+  ::message::Parkspace_info* release_confirm_space_info();
+  ::message::Parkspace_info* mutable_confirm_space_info();
+  void set_allocated_confirm_space_info(::message::Parkspace_info* confirm_space_info);
+
+  // required int32 command_id = 2;
+  bool has_command_id() const;
+  void clear_command_id();
+  static const int kCommandIdFieldNumber = 2;
+  ::google::protobuf::int32 command_id() const;
+  void set_command_id(::google::protobuf::int32 value);
+
+  // @@protoc_insertion_point(class_scope:message.Parkspace_confirm_alloc_request_msg)
+ private:
+  void set_has_base_info();
+  void clear_has_base_info();
+  void set_has_command_id();
+  void clear_has_command_id();
+  void set_has_confirm_space_info();
+  void clear_has_confirm_space_info();
+
+  // helper for ByteSizeLong()
+  size_t RequiredFieldsByteSizeFallback() const;
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::message::Base_info* base_info_;
+  ::message::Parkspace_info* confirm_space_info_;
+  ::google::protobuf::int32 command_id_;
+  friend struct ::protobuf_parkspace_5fallocation_5fmessage_2eproto::TableStruct;
+  friend void ::protobuf_parkspace_5fallocation_5fmessage_2eproto::InitDefaultsParkspace_confirm_alloc_request_msgImpl();
+};
+// -------------------------------------------------------------------
+
+class Parkspace_confirm_alloc_response_msg : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:message.Parkspace_confirm_alloc_response_msg) */ {
+ public:
+  Parkspace_confirm_alloc_response_msg();
+  virtual ~Parkspace_confirm_alloc_response_msg();
+
+  Parkspace_confirm_alloc_response_msg(const Parkspace_confirm_alloc_response_msg& from);
+
+  inline Parkspace_confirm_alloc_response_msg& operator=(const Parkspace_confirm_alloc_response_msg& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Parkspace_confirm_alloc_response_msg(Parkspace_confirm_alloc_response_msg&& from) noexcept
+    : Parkspace_confirm_alloc_response_msg() {
+    *this = ::std::move(from);
+  }
+
+  inline Parkspace_confirm_alloc_response_msg& operator=(Parkspace_confirm_alloc_response_msg&& 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 Parkspace_confirm_alloc_response_msg& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Parkspace_confirm_alloc_response_msg* internal_default_instance() {
+    return reinterpret_cast<const Parkspace_confirm_alloc_response_msg*>(
+               &_Parkspace_confirm_alloc_response_msg_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    11;
+
+  void Swap(Parkspace_confirm_alloc_response_msg* other);
+  friend void swap(Parkspace_confirm_alloc_response_msg& a, Parkspace_confirm_alloc_response_msg& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Parkspace_confirm_alloc_response_msg* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Parkspace_confirm_alloc_response_msg* 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 Parkspace_confirm_alloc_response_msg& from);
+  void MergeFrom(const Parkspace_confirm_alloc_response_msg& 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(Parkspace_confirm_alloc_response_msg* 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 .message.Base_info base_info = 1;
+  bool has_base_info() const;
+  void clear_base_info();
+  static const int kBaseInfoFieldNumber = 1;
+  const ::message::Base_info& base_info() const;
+  ::message::Base_info* release_base_info();
+  ::message::Base_info* mutable_base_info();
+  void set_allocated_base_info(::message::Base_info* base_info);
+
+  // required .message.Error_manager error_manager = 3;
+  bool has_error_manager() const;
+  void clear_error_manager();
+  static const int kErrorManagerFieldNumber = 3;
+  const ::message::Error_manager& error_manager() const;
+  ::message::Error_manager* release_error_manager();
+  ::message::Error_manager* mutable_error_manager();
+  void set_allocated_error_manager(::message::Error_manager* error_manager);
+
+  // required .message.Parkspace_info confirm_alloc_space_info = 4;
+  bool has_confirm_alloc_space_info() const;
+  void clear_confirm_alloc_space_info();
+  static const int kConfirmAllocSpaceInfoFieldNumber = 4;
+  const ::message::Parkspace_info& confirm_alloc_space_info() const;
+  ::message::Parkspace_info* release_confirm_alloc_space_info();
+  ::message::Parkspace_info* mutable_confirm_alloc_space_info();
+  void set_allocated_confirm_alloc_space_info(::message::Parkspace_info* confirm_alloc_space_info);
+
+  // required int32 command_id = 2;
+  bool has_command_id() const;
+  void clear_command_id();
+  static const int kCommandIdFieldNumber = 2;
+  ::google::protobuf::int32 command_id() const;
+  void set_command_id(::google::protobuf::int32 value);
+
+  // @@protoc_insertion_point(class_scope:message.Parkspace_confirm_alloc_response_msg)
+ private:
+  void set_has_base_info();
+  void clear_has_base_info();
+  void set_has_command_id();
+  void clear_has_command_id();
+  void set_has_error_manager();
+  void clear_has_error_manager();
+  void set_has_confirm_alloc_space_info();
+  void clear_has_confirm_alloc_space_info();
+
+  // helper for ByteSizeLong()
+  size_t RequiredFieldsByteSizeFallback() const;
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::message::Base_info* base_info_;
+  ::message::Error_manager* error_manager_;
+  ::message::Parkspace_info* confirm_alloc_space_info_;
+  ::google::protobuf::int32 command_id_;
+  friend struct ::protobuf_parkspace_5fallocation_5fmessage_2eproto::TableStruct;
+  friend void ::protobuf_parkspace_5fallocation_5fmessage_2eproto::InitDefaultsParkspace_confirm_alloc_response_msgImpl();
+};
+// -------------------------------------------------------------------
+
 class Parkspace_allocation_status_msg : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:message.Parkspace_allocation_status_msg) */ {
  public:
   Parkspace_allocation_status_msg();
@@ -1737,7 +2036,7 @@ class Parkspace_allocation_status_msg : public ::google::protobuf::Message /* @@
                &_Parkspace_allocation_status_msg_default_instance_);
   }
   static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
-    10;
+    12;
 
   void Swap(Parkspace_allocation_status_msg* other);
   friend void swap(Parkspace_allocation_status_msg& a, Parkspace_allocation_status_msg& b) {
@@ -3639,6 +3938,320 @@ inline void Parkspace_force_update_response_msg::set_allocated_update_space_info
 
 // -------------------------------------------------------------------
 
+// Parkspace_confirm_alloc_request_msg
+
+// required .message.Base_info base_info = 1;
+inline bool Parkspace_confirm_alloc_request_msg::has_base_info() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Parkspace_confirm_alloc_request_msg::set_has_base_info() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Parkspace_confirm_alloc_request_msg::clear_has_base_info() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline const ::message::Base_info& Parkspace_confirm_alloc_request_msg::base_info() const {
+  const ::message::Base_info* p = base_info_;
+  // @@protoc_insertion_point(field_get:message.Parkspace_confirm_alloc_request_msg.base_info)
+  return p != NULL ? *p : *reinterpret_cast<const ::message::Base_info*>(
+      &::message::_Base_info_default_instance_);
+}
+inline ::message::Base_info* Parkspace_confirm_alloc_request_msg::release_base_info() {
+  // @@protoc_insertion_point(field_release:message.Parkspace_confirm_alloc_request_msg.base_info)
+  clear_has_base_info();
+  ::message::Base_info* temp = base_info_;
+  base_info_ = NULL;
+  return temp;
+}
+inline ::message::Base_info* Parkspace_confirm_alloc_request_msg::mutable_base_info() {
+  set_has_base_info();
+  if (base_info_ == NULL) {
+    base_info_ = new ::message::Base_info;
+  }
+  // @@protoc_insertion_point(field_mutable:message.Parkspace_confirm_alloc_request_msg.base_info)
+  return base_info_;
+}
+inline void Parkspace_confirm_alloc_request_msg::set_allocated_base_info(::message::Base_info* base_info) {
+  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+  if (message_arena == NULL) {
+    delete reinterpret_cast< ::google::protobuf::MessageLite*>(base_info_);
+  }
+  if (base_info) {
+    ::google::protobuf::Arena* submessage_arena = NULL;
+    if (message_arena != submessage_arena) {
+      base_info = ::google::protobuf::internal::GetOwnedMessage(
+          message_arena, base_info, submessage_arena);
+    }
+    set_has_base_info();
+  } else {
+    clear_has_base_info();
+  }
+  base_info_ = base_info;
+  // @@protoc_insertion_point(field_set_allocated:message.Parkspace_confirm_alloc_request_msg.base_info)
+}
+
+// required int32 command_id = 2;
+inline bool Parkspace_confirm_alloc_request_msg::has_command_id() const {
+  return (_has_bits_[0] & 0x00000004u) != 0;
+}
+inline void Parkspace_confirm_alloc_request_msg::set_has_command_id() {
+  _has_bits_[0] |= 0x00000004u;
+}
+inline void Parkspace_confirm_alloc_request_msg::clear_has_command_id() {
+  _has_bits_[0] &= ~0x00000004u;
+}
+inline void Parkspace_confirm_alloc_request_msg::clear_command_id() {
+  command_id_ = 0;
+  clear_has_command_id();
+}
+inline ::google::protobuf::int32 Parkspace_confirm_alloc_request_msg::command_id() const {
+  // @@protoc_insertion_point(field_get:message.Parkspace_confirm_alloc_request_msg.command_id)
+  return command_id_;
+}
+inline void Parkspace_confirm_alloc_request_msg::set_command_id(::google::protobuf::int32 value) {
+  set_has_command_id();
+  command_id_ = value;
+  // @@protoc_insertion_point(field_set:message.Parkspace_confirm_alloc_request_msg.command_id)
+}
+
+// required .message.Parkspace_info confirm_space_info = 3;
+inline bool Parkspace_confirm_alloc_request_msg::has_confirm_space_info() const {
+  return (_has_bits_[0] & 0x00000002u) != 0;
+}
+inline void Parkspace_confirm_alloc_request_msg::set_has_confirm_space_info() {
+  _has_bits_[0] |= 0x00000002u;
+}
+inline void Parkspace_confirm_alloc_request_msg::clear_has_confirm_space_info() {
+  _has_bits_[0] &= ~0x00000002u;
+}
+inline void Parkspace_confirm_alloc_request_msg::clear_confirm_space_info() {
+  if (confirm_space_info_ != NULL) confirm_space_info_->Clear();
+  clear_has_confirm_space_info();
+}
+inline const ::message::Parkspace_info& Parkspace_confirm_alloc_request_msg::confirm_space_info() const {
+  const ::message::Parkspace_info* p = confirm_space_info_;
+  // @@protoc_insertion_point(field_get:message.Parkspace_confirm_alloc_request_msg.confirm_space_info)
+  return p != NULL ? *p : *reinterpret_cast<const ::message::Parkspace_info*>(
+      &::message::_Parkspace_info_default_instance_);
+}
+inline ::message::Parkspace_info* Parkspace_confirm_alloc_request_msg::release_confirm_space_info() {
+  // @@protoc_insertion_point(field_release:message.Parkspace_confirm_alloc_request_msg.confirm_space_info)
+  clear_has_confirm_space_info();
+  ::message::Parkspace_info* temp = confirm_space_info_;
+  confirm_space_info_ = NULL;
+  return temp;
+}
+inline ::message::Parkspace_info* Parkspace_confirm_alloc_request_msg::mutable_confirm_space_info() {
+  set_has_confirm_space_info();
+  if (confirm_space_info_ == NULL) {
+    confirm_space_info_ = new ::message::Parkspace_info;
+  }
+  // @@protoc_insertion_point(field_mutable:message.Parkspace_confirm_alloc_request_msg.confirm_space_info)
+  return confirm_space_info_;
+}
+inline void Parkspace_confirm_alloc_request_msg::set_allocated_confirm_space_info(::message::Parkspace_info* confirm_space_info) {
+  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+  if (message_arena == NULL) {
+    delete confirm_space_info_;
+  }
+  if (confirm_space_info) {
+    ::google::protobuf::Arena* submessage_arena = NULL;
+    if (message_arena != submessage_arena) {
+      confirm_space_info = ::google::protobuf::internal::GetOwnedMessage(
+          message_arena, confirm_space_info, submessage_arena);
+    }
+    set_has_confirm_space_info();
+  } else {
+    clear_has_confirm_space_info();
+  }
+  confirm_space_info_ = confirm_space_info;
+  // @@protoc_insertion_point(field_set_allocated:message.Parkspace_confirm_alloc_request_msg.confirm_space_info)
+}
+
+// -------------------------------------------------------------------
+
+// Parkspace_confirm_alloc_response_msg
+
+// required .message.Base_info base_info = 1;
+inline bool Parkspace_confirm_alloc_response_msg::has_base_info() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_has_base_info() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Parkspace_confirm_alloc_response_msg::clear_has_base_info() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline const ::message::Base_info& Parkspace_confirm_alloc_response_msg::base_info() const {
+  const ::message::Base_info* p = base_info_;
+  // @@protoc_insertion_point(field_get:message.Parkspace_confirm_alloc_response_msg.base_info)
+  return p != NULL ? *p : *reinterpret_cast<const ::message::Base_info*>(
+      &::message::_Base_info_default_instance_);
+}
+inline ::message::Base_info* Parkspace_confirm_alloc_response_msg::release_base_info() {
+  // @@protoc_insertion_point(field_release:message.Parkspace_confirm_alloc_response_msg.base_info)
+  clear_has_base_info();
+  ::message::Base_info* temp = base_info_;
+  base_info_ = NULL;
+  return temp;
+}
+inline ::message::Base_info* Parkspace_confirm_alloc_response_msg::mutable_base_info() {
+  set_has_base_info();
+  if (base_info_ == NULL) {
+    base_info_ = new ::message::Base_info;
+  }
+  // @@protoc_insertion_point(field_mutable:message.Parkspace_confirm_alloc_response_msg.base_info)
+  return base_info_;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_allocated_base_info(::message::Base_info* base_info) {
+  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+  if (message_arena == NULL) {
+    delete reinterpret_cast< ::google::protobuf::MessageLite*>(base_info_);
+  }
+  if (base_info) {
+    ::google::protobuf::Arena* submessage_arena = NULL;
+    if (message_arena != submessage_arena) {
+      base_info = ::google::protobuf::internal::GetOwnedMessage(
+          message_arena, base_info, submessage_arena);
+    }
+    set_has_base_info();
+  } else {
+    clear_has_base_info();
+  }
+  base_info_ = base_info;
+  // @@protoc_insertion_point(field_set_allocated:message.Parkspace_confirm_alloc_response_msg.base_info)
+}
+
+// required int32 command_id = 2;
+inline bool Parkspace_confirm_alloc_response_msg::has_command_id() const {
+  return (_has_bits_[0] & 0x00000008u) != 0;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_has_command_id() {
+  _has_bits_[0] |= 0x00000008u;
+}
+inline void Parkspace_confirm_alloc_response_msg::clear_has_command_id() {
+  _has_bits_[0] &= ~0x00000008u;
+}
+inline void Parkspace_confirm_alloc_response_msg::clear_command_id() {
+  command_id_ = 0;
+  clear_has_command_id();
+}
+inline ::google::protobuf::int32 Parkspace_confirm_alloc_response_msg::command_id() const {
+  // @@protoc_insertion_point(field_get:message.Parkspace_confirm_alloc_response_msg.command_id)
+  return command_id_;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_command_id(::google::protobuf::int32 value) {
+  set_has_command_id();
+  command_id_ = value;
+  // @@protoc_insertion_point(field_set:message.Parkspace_confirm_alloc_response_msg.command_id)
+}
+
+// required .message.Error_manager error_manager = 3;
+inline bool Parkspace_confirm_alloc_response_msg::has_error_manager() const {
+  return (_has_bits_[0] & 0x00000002u) != 0;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_has_error_manager() {
+  _has_bits_[0] |= 0x00000002u;
+}
+inline void Parkspace_confirm_alloc_response_msg::clear_has_error_manager() {
+  _has_bits_[0] &= ~0x00000002u;
+}
+inline const ::message::Error_manager& Parkspace_confirm_alloc_response_msg::error_manager() const {
+  const ::message::Error_manager* p = error_manager_;
+  // @@protoc_insertion_point(field_get:message.Parkspace_confirm_alloc_response_msg.error_manager)
+  return p != NULL ? *p : *reinterpret_cast<const ::message::Error_manager*>(
+      &::message::_Error_manager_default_instance_);
+}
+inline ::message::Error_manager* Parkspace_confirm_alloc_response_msg::release_error_manager() {
+  // @@protoc_insertion_point(field_release:message.Parkspace_confirm_alloc_response_msg.error_manager)
+  clear_has_error_manager();
+  ::message::Error_manager* temp = error_manager_;
+  error_manager_ = NULL;
+  return temp;
+}
+inline ::message::Error_manager* Parkspace_confirm_alloc_response_msg::mutable_error_manager() {
+  set_has_error_manager();
+  if (error_manager_ == NULL) {
+    error_manager_ = new ::message::Error_manager;
+  }
+  // @@protoc_insertion_point(field_mutable:message.Parkspace_confirm_alloc_response_msg.error_manager)
+  return error_manager_;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_allocated_error_manager(::message::Error_manager* error_manager) {
+  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+  if (message_arena == NULL) {
+    delete reinterpret_cast< ::google::protobuf::MessageLite*>(error_manager_);
+  }
+  if (error_manager) {
+    ::google::protobuf::Arena* submessage_arena = NULL;
+    if (message_arena != submessage_arena) {
+      error_manager = ::google::protobuf::internal::GetOwnedMessage(
+          message_arena, error_manager, submessage_arena);
+    }
+    set_has_error_manager();
+  } else {
+    clear_has_error_manager();
+  }
+  error_manager_ = error_manager;
+  // @@protoc_insertion_point(field_set_allocated:message.Parkspace_confirm_alloc_response_msg.error_manager)
+}
+
+// required .message.Parkspace_info confirm_alloc_space_info = 4;
+inline bool Parkspace_confirm_alloc_response_msg::has_confirm_alloc_space_info() const {
+  return (_has_bits_[0] & 0x00000004u) != 0;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_has_confirm_alloc_space_info() {
+  _has_bits_[0] |= 0x00000004u;
+}
+inline void Parkspace_confirm_alloc_response_msg::clear_has_confirm_alloc_space_info() {
+  _has_bits_[0] &= ~0x00000004u;
+}
+inline void Parkspace_confirm_alloc_response_msg::clear_confirm_alloc_space_info() {
+  if (confirm_alloc_space_info_ != NULL) confirm_alloc_space_info_->Clear();
+  clear_has_confirm_alloc_space_info();
+}
+inline const ::message::Parkspace_info& Parkspace_confirm_alloc_response_msg::confirm_alloc_space_info() const {
+  const ::message::Parkspace_info* p = confirm_alloc_space_info_;
+  // @@protoc_insertion_point(field_get:message.Parkspace_confirm_alloc_response_msg.confirm_alloc_space_info)
+  return p != NULL ? *p : *reinterpret_cast<const ::message::Parkspace_info*>(
+      &::message::_Parkspace_info_default_instance_);
+}
+inline ::message::Parkspace_info* Parkspace_confirm_alloc_response_msg::release_confirm_alloc_space_info() {
+  // @@protoc_insertion_point(field_release:message.Parkspace_confirm_alloc_response_msg.confirm_alloc_space_info)
+  clear_has_confirm_alloc_space_info();
+  ::message::Parkspace_info* temp = confirm_alloc_space_info_;
+  confirm_alloc_space_info_ = NULL;
+  return temp;
+}
+inline ::message::Parkspace_info* Parkspace_confirm_alloc_response_msg::mutable_confirm_alloc_space_info() {
+  set_has_confirm_alloc_space_info();
+  if (confirm_alloc_space_info_ == NULL) {
+    confirm_alloc_space_info_ = new ::message::Parkspace_info;
+  }
+  // @@protoc_insertion_point(field_mutable:message.Parkspace_confirm_alloc_response_msg.confirm_alloc_space_info)
+  return confirm_alloc_space_info_;
+}
+inline void Parkspace_confirm_alloc_response_msg::set_allocated_confirm_alloc_space_info(::message::Parkspace_info* confirm_alloc_space_info) {
+  ::google::protobuf::Arena* message_arena = GetArenaNoVirtual();
+  if (message_arena == NULL) {
+    delete confirm_alloc_space_info_;
+  }
+  if (confirm_alloc_space_info) {
+    ::google::protobuf::Arena* submessage_arena = NULL;
+    if (message_arena != submessage_arena) {
+      confirm_alloc_space_info = ::google::protobuf::internal::GetOwnedMessage(
+          message_arena, confirm_alloc_space_info, submessage_arena);
+    }
+    set_has_confirm_alloc_space_info();
+  } else {
+    clear_has_confirm_alloc_space_info();
+  }
+  confirm_alloc_space_info_ = confirm_alloc_space_info;
+  // @@protoc_insertion_point(field_set_allocated:message.Parkspace_confirm_alloc_response_msg.confirm_alloc_space_info)
+}
+
+// -------------------------------------------------------------------
+
 // Parkspace_allocation_status_msg
 
 // required .message.Base_info base_info = 1;
@@ -3794,6 +4407,10 @@ Parkspace_allocation_status_msg::parkspace_info() const {
 
 // -------------------------------------------------------------------
 
+// -------------------------------------------------------------------
+
+// -------------------------------------------------------------------
+
 
 // @@protoc_insertion_point(namespace_scope)
 

+ 20 - 3
message/parkspace_allocation_message.proto

@@ -7,6 +7,7 @@ import "message_base.proto";
 // 2.查询车辆位置
 // 3.解锁车位
 // 4.手动操作修改车位状态
+// 5.临时锁定车位
 
 message Car_info
 {
@@ -20,9 +21,10 @@ message Car_info
 enum Parkspace_status
 {
     eParkspace_empty            = 0;         //空闲,可分配
-    eParkspace_occupied         = 1;         //被占用,不可分配
-    eParkspace_reserverd        = 2;         //被预约,预约车辆可分配
-    eParkspace_error            = 3;         //车位机械结构或硬件故障   
+    eParkspace_locked           = 1;         //临时锁定,不可分配
+    eParkspace_occupied         = 2;         //被车辆占用,不可分配
+    eParkspace_reserved        = 3;          //被预约,预约车辆可分配
+    eParkspace_error            = 4;         //车位机械结构或硬件故障   
 }
 
 enum Direction
@@ -116,6 +118,21 @@ message Parkspace_force_update_response_msg
     required Parkspace_info             update_space_info=4;    //已修改后的车位信息
 }
 
+// 5.临时锁定车位
+message Parkspace_confirm_alloc_request_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required int32                      command_id=2;           //指令唯一标识符id
+    required Parkspace_info             confirm_space_info=3;    //已修改后的车位信息
+}
+
+message Parkspace_confirm_alloc_response_msg
+{
+    required Base_info                  base_info=1;            //消息类型
+    required int32                      command_id=2;           //指令唯一标识符id
+    required Error_manager              error_manager=3;        //分配成功与否标志
+    required Parkspace_info             confirm_alloc_space_info=4;    //已修改后的车位信息
+}
 
 // 车位心跳状态信息
 message Parkspace_allocation_status_msg

+ 413 - 0
parkspace_allocation/database_controller.cpp

@@ -0,0 +1,413 @@
+/*
+ * @Description: 数据库操作类
+ * @Author: yct
+ * @Date: 2020-07-15 14:08:46
+ * @LastEditTime: 2020-07-19 00:02:06
+ * @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;
+    }
+    //创建连接池
+    m_conn_mutex.lock();
+    for (int i = 0; i < m_conn_pool_size; i++)
+    {
+        try
+        {
+            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->isValid())
+            {
+                m_db_conn_pool.push(t_conn_ptr);
+                std::cout << "conn pushed." << std::endl;
+            }
+            else
+            {
+                std::cout << "conn create failed." << std::endl;
+            }
+        }
+        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;
+        }
+    }
+    m_conn_mutex.unlock();
+    
+    //守护线程,检查连接状态并保持连接数量
+    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;
+    }
+}
+
+//数据库连接状态
+bool Database_controller::is_connected()
+{
+    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", e.what(), e.getErrorCode(), e.getSQLState().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 ",e.what(),__FILE__);
+                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", e.what(), e.getErrorCode(), e.getSQLState().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 ",e.what(),__FILE__);
+                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", e.what(), e.getErrorCode(), e.getSQLState().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 ",e.what(),__FILE__);
+                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", e.what(), e.getErrorCode(), e.getSQLState().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 ",e.what(),__FILE__);
+                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

+ 7 - 1
parkspace_allocation/parkspace_allocation_communicator.cpp

@@ -75,6 +75,10 @@ Error_manager Parkspace_allocation_communicator::encapsulate_msg(Communication_m
         {
             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");
     }
@@ -95,7 +99,7 @@ Error_manager Parkspace_allocation_communicator::execute_msg(Communication_messa
 Error_manager Parkspace_allocation_communicator::check_msg(Communication_message* p_msg)
 {
     //通过 p_msg->get_message_type() 和 p_msg->get_receiver() 判断这条消息是不是车位请求消息.
-    if(p_msg->get_receiver() == Communication_message::Communicator::eParkspace_allocator)
+    if(p_msg->get_receiver() == Communication_message::Communicator::eParkspace)
     {
         switch(p_msg->get_message_type())
         {
@@ -107,6 +111,8 @@ Error_manager Parkspace_allocation_communicator::check_msg(Communication_message
                 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;
         }

+ 89 - 12
parkspace_allocation/parkspace_allocator.cpp

@@ -2,7 +2,7 @@
  * @Description: 车位分配算法模块,使用单例模式,接收外部请求并通过调用通信块接口发送反馈
  * @Author: yct
  * @Date: 2020-07-10 11:02:40
- * @LastEditTime: 2020-07-10 16:57:14
+ * @LastEditTime: 2020-07-17 09:19:38
  * @LastEditors: yct
  */ 
 
@@ -120,6 +120,21 @@ Error_manager Parkspace_allocator::execute_msg(Communication_message* p_msg)
             m_thread_pool.enqueue(&Parkspace_allocator::execute_for_force_update, this, request.update_space_info(), request.command_id());
             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_force_update, this, request.confirm_space_info(), request.command_id());
+            return SUCCESS;
+        }
 	}
 	return Error_code::PARKSPACE_ALLOCATOR_MSG_REQUEST_TYPE_ERROR;
 }
@@ -189,7 +204,7 @@ void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int t
             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_occupied);
+            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);
             // 分配车位后更新车位状态
@@ -201,9 +216,9 @@ void Parkspace_allocator::execute_for_allocate(message::Car_info car_info, int t
     response_msg.set_command_id(command_id);
     response_msg.mutable_error_manager()->CopyFrom(t_error);
     response_msg.mutable_allocated_space_info()->CopyFrom(t_allocated_space);
-    Communication_message* response=new Communication_message();
-    response->reset(t_response_header, response_msg.SerializeAsString());
-    Parkspace_allocation_communicator::get_instance_references().send_response(response);
+    Communication_message response=Communication_message();
+    response.reset(t_response_header, response_msg.SerializeAsString());
+    Parkspace_allocation_communicator::get_instance_references().send_response(&response);
 }
 
 //查询车位线程函数
@@ -259,9 +274,9 @@ void Parkspace_allocator::execute_for_search(message::Car_info car_info, int com
     response_msg.set_command_id(command_id);
     response_msg.mutable_error_manager()->CopyFrom(t_error);
     response_msg.mutable_car_position()->CopyFrom(t_car_position);
-    Communication_message* response=new Communication_message();
-    response->reset(t_response_header, response_msg.SerializeAsString());
-    Parkspace_allocation_communicator::get_instance_references().send_response(response);
+    Communication_message response=Communication_message();
+    response.reset(t_response_header, response_msg.SerializeAsString());
+    Parkspace_allocation_communicator::get_instance_references().send_response(&response);
 }
 
 //释放车位线程函数
@@ -299,7 +314,8 @@ void Parkspace_allocator::execute_for_release(message::Parkspace_info space_info
         {
             // 找到高于车高且空闲车位,则分配
             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_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())
             {
@@ -379,7 +395,68 @@ void Parkspace_allocator::execute_for_force_update(message::Parkspace_info space
     response_msg.set_command_id(command_id);
     response_msg.mutable_error_manager()->CopyFrom(t_error);
     response_msg.mutable_update_space_info()->CopyFrom(t_update_space);
-    Communication_message* response=new Communication_message();
-    response->reset(t_response_header, response_msg.SerializeAsString());
-    Parkspace_allocation_communicator::get_instance_references().send_response(response);
+    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, int command_id)
+{
+    std::lock_guard<std::mutex> lck(m_mutex);
+    LOG(INFO) << "确认分配";
+    //根据车位信息定位待确认占用车位
+    message::Parkspace_confirm_alloc_response_msg response_msg;
+    message::Base_info t_response_header;
+    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).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);
+            LOG(WARNING) << "确认占用车位失败";
+        }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);
+            // 分配车位后更新车位状态
+            Parkspace_allocation_communicator::get_instance_references().update_parkspace_status(index, t_confirm_space);
+            LOG(INFO) << "第"<<index<<"号位已确认占用, id: "<<t_confirm_space.parkspace_id();
+        }
+    }
+    response_msg.mutable_base_info()->CopyFrom(t_response_header);
+    response_msg.set_command_id(command_id);
+    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);
 }

+ 3 - 1
parkspace_allocation/parkspace_allocator.h

@@ -2,7 +2,7 @@
  * @Description: 车位分配算法模块,使用单例模式,接收外部请求并通过调用通信块接口发送反馈
  * @Author: yct
  * @Date: 2020-07-10 09:25:56
- * @LastEditTime: 2020-07-10 15:24:08
+ * @LastEditTime: 2020-07-15 17:30:18
  * @LastEditors: yct
  */ 
 
@@ -60,6 +60,8 @@ public://execute_msg创建各线程进行处理
     void execute_for_release(message::Parkspace_info space_info, int command_id);
     //强制更新车位信息线程函数
     void execute_for_force_update(message::Parkspace_info space_info, int command_id);
+    //确认分配车位线程函数
+    void execute_for_confirm_alloc(message::Parkspace_info space_info, int command_id);
 
 private:
     parkspace_allocator_status  m_current_status;               //分配器当前状态

+ 51 - 0
test/db_test.cpp

@@ -0,0 +1,51 @@
+/*
+ * @Description: 数据库测试
+ * @Author: yct
+ * @Date: 2020-07-18 21:46:45
+ * @LastEditTime: 2020-07-18 23:57:19
+ * @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 id,content 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;
+            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;
+}