Sfoglia il codice sorgente

20210323, 调度控制线程的框架

huli 4 anni fa
parent
commit
10c0d3878c

File diff suppressed because it is too large
+ 1456 - 0
dispatch/dispatch_parameter.pb.cc


+ 851 - 0
dispatch/dispatch_parameter.pb.h

@@ -0,0 +1,851 @@
+// Generated by the protocol buffer compiler.  DO NOT EDIT!
+// source: dispatch_parameter.proto
+
+#ifndef PROTOBUF_dispatch_5fparameter_2eproto__INCLUDED
+#define PROTOBUF_dispatch_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_dispatch_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[4];
+  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 InitDefaultsCatcher_parameterImpl();
+void InitDefaultsCatcher_parameter();
+void InitDefaultsCarrier_parameterImpl();
+void InitDefaultsCarrier_parameter();
+void InitDefaultsPassageway_parameterImpl();
+void InitDefaultsPassageway_parameter();
+void InitDefaultsLaser_parameter_allImpl();
+void InitDefaultsLaser_parameter_all();
+inline void InitDefaults() {
+  InitDefaultsCatcher_parameter();
+  InitDefaultsCarrier_parameter();
+  InitDefaultsPassageway_parameter();
+  InitDefaultsLaser_parameter_all();
+}
+}  // namespace protobuf_dispatch_5fparameter_2eproto
+namespace Dispatch_proto {
+class Carrier_parameter;
+class Carrier_parameterDefaultTypeInternal;
+extern Carrier_parameterDefaultTypeInternal _Carrier_parameter_default_instance_;
+class Catcher_parameter;
+class Catcher_parameterDefaultTypeInternal;
+extern Catcher_parameterDefaultTypeInternal _Catcher_parameter_default_instance_;
+class Laser_parameter_all;
+class Laser_parameter_allDefaultTypeInternal;
+extern Laser_parameter_allDefaultTypeInternal _Laser_parameter_all_default_instance_;
+class Passageway_parameter;
+class Passageway_parameterDefaultTypeInternal;
+extern Passageway_parameterDefaultTypeInternal _Passageway_parameter_default_instance_;
+}  // namespace Dispatch_proto
+namespace Dispatch_proto {
+
+// ===================================================================
+
+class Catcher_parameter : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Dispatch_proto.Catcher_parameter) */ {
+ public:
+  Catcher_parameter();
+  virtual ~Catcher_parameter();
+
+  Catcher_parameter(const Catcher_parameter& from);
+
+  inline Catcher_parameter& operator=(const Catcher_parameter& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Catcher_parameter(Catcher_parameter&& from) noexcept
+    : Catcher_parameter() {
+    *this = ::std::move(from);
+  }
+
+  inline Catcher_parameter& operator=(Catcher_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 Catcher_parameter& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Catcher_parameter* internal_default_instance() {
+    return reinterpret_cast<const Catcher_parameter*>(
+               &_Catcher_parameter_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    0;
+
+  void Swap(Catcher_parameter* other);
+  friend void swap(Catcher_parameter& a, Catcher_parameter& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Catcher_parameter* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Catcher_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 Catcher_parameter& from);
+  void MergeFrom(const Catcher_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(Catcher_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 -------------------------------------------------------
+
+  // required int32 id = 1;
+  bool has_id() const;
+  void clear_id();
+  static const int kIdFieldNumber = 1;
+  ::google::protobuf::int32 id() const;
+  void set_id(::google::protobuf::int32 value);
+
+  // @@protoc_insertion_point(class_scope:Dispatch_proto.Catcher_parameter)
+ private:
+  void set_has_id();
+  void clear_has_id();
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::google::protobuf::int32 id_;
+  friend struct ::protobuf_dispatch_5fparameter_2eproto::TableStruct;
+  friend void ::protobuf_dispatch_5fparameter_2eproto::InitDefaultsCatcher_parameterImpl();
+};
+// -------------------------------------------------------------------
+
+class Carrier_parameter : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Dispatch_proto.Carrier_parameter) */ {
+ public:
+  Carrier_parameter();
+  virtual ~Carrier_parameter();
+
+  Carrier_parameter(const Carrier_parameter& from);
+
+  inline Carrier_parameter& operator=(const Carrier_parameter& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Carrier_parameter(Carrier_parameter&& from) noexcept
+    : Carrier_parameter() {
+    *this = ::std::move(from);
+  }
+
+  inline Carrier_parameter& operator=(Carrier_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 Carrier_parameter& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Carrier_parameter* internal_default_instance() {
+    return reinterpret_cast<const Carrier_parameter*>(
+               &_Carrier_parameter_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    1;
+
+  void Swap(Carrier_parameter* other);
+  friend void swap(Carrier_parameter& a, Carrier_parameter& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Carrier_parameter* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Carrier_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 Carrier_parameter& from);
+  void MergeFrom(const Carrier_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(Carrier_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 -------------------------------------------------------
+
+  // required int32 id = 1;
+  bool has_id() const;
+  void clear_id();
+  static const int kIdFieldNumber = 1;
+  ::google::protobuf::int32 id() const;
+  void set_id(::google::protobuf::int32 value);
+
+  // @@protoc_insertion_point(class_scope:Dispatch_proto.Carrier_parameter)
+ private:
+  void set_has_id();
+  void clear_has_id();
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::google::protobuf::int32 id_;
+  friend struct ::protobuf_dispatch_5fparameter_2eproto::TableStruct;
+  friend void ::protobuf_dispatch_5fparameter_2eproto::InitDefaultsCarrier_parameterImpl();
+};
+// -------------------------------------------------------------------
+
+class Passageway_parameter : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Dispatch_proto.Passageway_parameter) */ {
+ public:
+  Passageway_parameter();
+  virtual ~Passageway_parameter();
+
+  Passageway_parameter(const Passageway_parameter& from);
+
+  inline Passageway_parameter& operator=(const Passageway_parameter& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Passageway_parameter(Passageway_parameter&& from) noexcept
+    : Passageway_parameter() {
+    *this = ::std::move(from);
+  }
+
+  inline Passageway_parameter& operator=(Passageway_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 Passageway_parameter& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Passageway_parameter* internal_default_instance() {
+    return reinterpret_cast<const Passageway_parameter*>(
+               &_Passageway_parameter_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    2;
+
+  void Swap(Passageway_parameter* other);
+  friend void swap(Passageway_parameter& a, Passageway_parameter& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Passageway_parameter* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Passageway_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 Passageway_parameter& from);
+  void MergeFrom(const Passageway_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(Passageway_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 -------------------------------------------------------
+
+  // required int32 id = 1;
+  bool has_id() const;
+  void clear_id();
+  static const int kIdFieldNumber = 1;
+  ::google::protobuf::int32 id() const;
+  void set_id(::google::protobuf::int32 value);
+
+  // @@protoc_insertion_point(class_scope:Dispatch_proto.Passageway_parameter)
+ private:
+  void set_has_id();
+  void clear_has_id();
+
+  ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_;
+  ::google::protobuf::internal::HasBits<1> _has_bits_;
+  mutable int _cached_size_;
+  ::google::protobuf::int32 id_;
+  friend struct ::protobuf_dispatch_5fparameter_2eproto::TableStruct;
+  friend void ::protobuf_dispatch_5fparameter_2eproto::InitDefaultsPassageway_parameterImpl();
+};
+// -------------------------------------------------------------------
+
+class Laser_parameter_all : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:Dispatch_proto.Laser_parameter_all) */ {
+ public:
+  Laser_parameter_all();
+  virtual ~Laser_parameter_all();
+
+  Laser_parameter_all(const Laser_parameter_all& from);
+
+  inline Laser_parameter_all& operator=(const Laser_parameter_all& from) {
+    CopyFrom(from);
+    return *this;
+  }
+  #if LANG_CXX11
+  Laser_parameter_all(Laser_parameter_all&& from) noexcept
+    : Laser_parameter_all() {
+    *this = ::std::move(from);
+  }
+
+  inline Laser_parameter_all& operator=(Laser_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 Laser_parameter_all& default_instance();
+
+  static void InitAsDefaultInstance();  // FOR INTERNAL USE ONLY
+  static inline const Laser_parameter_all* internal_default_instance() {
+    return reinterpret_cast<const Laser_parameter_all*>(
+               &_Laser_parameter_all_default_instance_);
+  }
+  static PROTOBUF_CONSTEXPR int const kIndexInFileMessages =
+    3;
+
+  void Swap(Laser_parameter_all* other);
+  friend void swap(Laser_parameter_all& a, Laser_parameter_all& b) {
+    a.Swap(&b);
+  }
+
+  // implements Message ----------------------------------------------
+
+  inline Laser_parameter_all* New() const PROTOBUF_FINAL { return New(NULL); }
+
+  Laser_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 Laser_parameter_all& from);
+  void MergeFrom(const Laser_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(Laser_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 -------------------------------------------------------
+
+  // repeated .Dispatch_proto.Catcher_parameter catcher_parameters = 2;
+  int catcher_parameters_size() const;
+  void clear_catcher_parameters();
+  static const int kCatcherParametersFieldNumber = 2;
+  const ::Dispatch_proto::Catcher_parameter& catcher_parameters(int index) const;
+  ::Dispatch_proto::Catcher_parameter* mutable_catcher_parameters(int index);
+  ::Dispatch_proto::Catcher_parameter* add_catcher_parameters();
+  ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Catcher_parameter >*
+      mutable_catcher_parameters();
+  const ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Catcher_parameter >&
+      catcher_parameters() const;
+
+  // repeated .Dispatch_proto.Carrier_parameter carrier_parameters = 4;
+  int carrier_parameters_size() const;
+  void clear_carrier_parameters();
+  static const int kCarrierParametersFieldNumber = 4;
+  const ::Dispatch_proto::Carrier_parameter& carrier_parameters(int index) const;
+  ::Dispatch_proto::Carrier_parameter* mutable_carrier_parameters(int index);
+  ::Dispatch_proto::Carrier_parameter* add_carrier_parameters();
+  ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Carrier_parameter >*
+      mutable_carrier_parameters();
+  const ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Carrier_parameter >&
+      carrier_parameters() const;
+
+  // repeated .Dispatch_proto.Passageway_parameter passageway_parameters = 6;
+  int passageway_parameters_size() const;
+  void clear_passageway_parameters();
+  static const int kPassagewayParametersFieldNumber = 6;
+  const ::Dispatch_proto::Passageway_parameter& passageway_parameters(int index) const;
+  ::Dispatch_proto::Passageway_parameter* mutable_passageway_parameters(int index);
+  ::Dispatch_proto::Passageway_parameter* add_passageway_parameters();
+  ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Passageway_parameter >*
+      mutable_passageway_parameters();
+  const ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Passageway_parameter >&
+      passageway_parameters() const;
+
+  // required int32 catcher_size = 1;
+  bool has_catcher_size() const;
+  void clear_catcher_size();
+  static const int kCatcherSizeFieldNumber = 1;
+  ::google::protobuf::int32 catcher_size() const;
+  void set_catcher_size(::google::protobuf::int32 value);
+
+  // required int32 carrier_size = 3;
+  bool has_carrier_size() const;
+  void clear_carrier_size();
+  static const int kCarrierSizeFieldNumber = 3;
+  ::google::protobuf::int32 carrier_size() const;
+  void set_carrier_size(::google::protobuf::int32 value);
+
+  // required int32 passageway_size = 5;
+  bool has_passageway_size() const;
+  void clear_passageway_size();
+  static const int kPassagewaySizeFieldNumber = 5;
+  ::google::protobuf::int32 passageway_size() const;
+  void set_passageway_size(::google::protobuf::int32 value);
+
+  // @@protoc_insertion_point(class_scope:Dispatch_proto.Laser_parameter_all)
+ private:
+  void set_has_catcher_size();
+  void clear_has_catcher_size();
+  void set_has_carrier_size();
+  void clear_has_carrier_size();
+  void set_has_passageway_size();
+  void clear_has_passageway_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::RepeatedPtrField< ::Dispatch_proto::Catcher_parameter > catcher_parameters_;
+  ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Carrier_parameter > carrier_parameters_;
+  ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Passageway_parameter > passageway_parameters_;
+  ::google::protobuf::int32 catcher_size_;
+  ::google::protobuf::int32 carrier_size_;
+  ::google::protobuf::int32 passageway_size_;
+  friend struct ::protobuf_dispatch_5fparameter_2eproto::TableStruct;
+  friend void ::protobuf_dispatch_5fparameter_2eproto::InitDefaultsLaser_parameter_allImpl();
+};
+// ===================================================================
+
+
+// ===================================================================
+
+#ifdef __GNUC__
+  #pragma GCC diagnostic push
+  #pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif  // __GNUC__
+// Catcher_parameter
+
+// required int32 id = 1;
+inline bool Catcher_parameter::has_id() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Catcher_parameter::set_has_id() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Catcher_parameter::clear_has_id() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline void Catcher_parameter::clear_id() {
+  id_ = 0;
+  clear_has_id();
+}
+inline ::google::protobuf::int32 Catcher_parameter::id() const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Catcher_parameter.id)
+  return id_;
+}
+inline void Catcher_parameter::set_id(::google::protobuf::int32 value) {
+  set_has_id();
+  id_ = value;
+  // @@protoc_insertion_point(field_set:Dispatch_proto.Catcher_parameter.id)
+}
+
+// -------------------------------------------------------------------
+
+// Carrier_parameter
+
+// required int32 id = 1;
+inline bool Carrier_parameter::has_id() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Carrier_parameter::set_has_id() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Carrier_parameter::clear_has_id() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline void Carrier_parameter::clear_id() {
+  id_ = 0;
+  clear_has_id();
+}
+inline ::google::protobuf::int32 Carrier_parameter::id() const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Carrier_parameter.id)
+  return id_;
+}
+inline void Carrier_parameter::set_id(::google::protobuf::int32 value) {
+  set_has_id();
+  id_ = value;
+  // @@protoc_insertion_point(field_set:Dispatch_proto.Carrier_parameter.id)
+}
+
+// -------------------------------------------------------------------
+
+// Passageway_parameter
+
+// required int32 id = 1;
+inline bool Passageway_parameter::has_id() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Passageway_parameter::set_has_id() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Passageway_parameter::clear_has_id() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline void Passageway_parameter::clear_id() {
+  id_ = 0;
+  clear_has_id();
+}
+inline ::google::protobuf::int32 Passageway_parameter::id() const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Passageway_parameter.id)
+  return id_;
+}
+inline void Passageway_parameter::set_id(::google::protobuf::int32 value) {
+  set_has_id();
+  id_ = value;
+  // @@protoc_insertion_point(field_set:Dispatch_proto.Passageway_parameter.id)
+}
+
+// -------------------------------------------------------------------
+
+// Laser_parameter_all
+
+// required int32 catcher_size = 1;
+inline bool Laser_parameter_all::has_catcher_size() const {
+  return (_has_bits_[0] & 0x00000001u) != 0;
+}
+inline void Laser_parameter_all::set_has_catcher_size() {
+  _has_bits_[0] |= 0x00000001u;
+}
+inline void Laser_parameter_all::clear_has_catcher_size() {
+  _has_bits_[0] &= ~0x00000001u;
+}
+inline void Laser_parameter_all::clear_catcher_size() {
+  catcher_size_ = 0;
+  clear_has_catcher_size();
+}
+inline ::google::protobuf::int32 Laser_parameter_all::catcher_size() const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Laser_parameter_all.catcher_size)
+  return catcher_size_;
+}
+inline void Laser_parameter_all::set_catcher_size(::google::protobuf::int32 value) {
+  set_has_catcher_size();
+  catcher_size_ = value;
+  // @@protoc_insertion_point(field_set:Dispatch_proto.Laser_parameter_all.catcher_size)
+}
+
+// repeated .Dispatch_proto.Catcher_parameter catcher_parameters = 2;
+inline int Laser_parameter_all::catcher_parameters_size() const {
+  return catcher_parameters_.size();
+}
+inline void Laser_parameter_all::clear_catcher_parameters() {
+  catcher_parameters_.Clear();
+}
+inline const ::Dispatch_proto::Catcher_parameter& Laser_parameter_all::catcher_parameters(int index) const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Laser_parameter_all.catcher_parameters)
+  return catcher_parameters_.Get(index);
+}
+inline ::Dispatch_proto::Catcher_parameter* Laser_parameter_all::mutable_catcher_parameters(int index) {
+  // @@protoc_insertion_point(field_mutable:Dispatch_proto.Laser_parameter_all.catcher_parameters)
+  return catcher_parameters_.Mutable(index);
+}
+inline ::Dispatch_proto::Catcher_parameter* Laser_parameter_all::add_catcher_parameters() {
+  // @@protoc_insertion_point(field_add:Dispatch_proto.Laser_parameter_all.catcher_parameters)
+  return catcher_parameters_.Add();
+}
+inline ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Catcher_parameter >*
+Laser_parameter_all::mutable_catcher_parameters() {
+  // @@protoc_insertion_point(field_mutable_list:Dispatch_proto.Laser_parameter_all.catcher_parameters)
+  return &catcher_parameters_;
+}
+inline const ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Catcher_parameter >&
+Laser_parameter_all::catcher_parameters() const {
+  // @@protoc_insertion_point(field_list:Dispatch_proto.Laser_parameter_all.catcher_parameters)
+  return catcher_parameters_;
+}
+
+// required int32 carrier_size = 3;
+inline bool Laser_parameter_all::has_carrier_size() const {
+  return (_has_bits_[0] & 0x00000002u) != 0;
+}
+inline void Laser_parameter_all::set_has_carrier_size() {
+  _has_bits_[0] |= 0x00000002u;
+}
+inline void Laser_parameter_all::clear_has_carrier_size() {
+  _has_bits_[0] &= ~0x00000002u;
+}
+inline void Laser_parameter_all::clear_carrier_size() {
+  carrier_size_ = 0;
+  clear_has_carrier_size();
+}
+inline ::google::protobuf::int32 Laser_parameter_all::carrier_size() const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Laser_parameter_all.carrier_size)
+  return carrier_size_;
+}
+inline void Laser_parameter_all::set_carrier_size(::google::protobuf::int32 value) {
+  set_has_carrier_size();
+  carrier_size_ = value;
+  // @@protoc_insertion_point(field_set:Dispatch_proto.Laser_parameter_all.carrier_size)
+}
+
+// repeated .Dispatch_proto.Carrier_parameter carrier_parameters = 4;
+inline int Laser_parameter_all::carrier_parameters_size() const {
+  return carrier_parameters_.size();
+}
+inline void Laser_parameter_all::clear_carrier_parameters() {
+  carrier_parameters_.Clear();
+}
+inline const ::Dispatch_proto::Carrier_parameter& Laser_parameter_all::carrier_parameters(int index) const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Laser_parameter_all.carrier_parameters)
+  return carrier_parameters_.Get(index);
+}
+inline ::Dispatch_proto::Carrier_parameter* Laser_parameter_all::mutable_carrier_parameters(int index) {
+  // @@protoc_insertion_point(field_mutable:Dispatch_proto.Laser_parameter_all.carrier_parameters)
+  return carrier_parameters_.Mutable(index);
+}
+inline ::Dispatch_proto::Carrier_parameter* Laser_parameter_all::add_carrier_parameters() {
+  // @@protoc_insertion_point(field_add:Dispatch_proto.Laser_parameter_all.carrier_parameters)
+  return carrier_parameters_.Add();
+}
+inline ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Carrier_parameter >*
+Laser_parameter_all::mutable_carrier_parameters() {
+  // @@protoc_insertion_point(field_mutable_list:Dispatch_proto.Laser_parameter_all.carrier_parameters)
+  return &carrier_parameters_;
+}
+inline const ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Carrier_parameter >&
+Laser_parameter_all::carrier_parameters() const {
+  // @@protoc_insertion_point(field_list:Dispatch_proto.Laser_parameter_all.carrier_parameters)
+  return carrier_parameters_;
+}
+
+// required int32 passageway_size = 5;
+inline bool Laser_parameter_all::has_passageway_size() const {
+  return (_has_bits_[0] & 0x00000004u) != 0;
+}
+inline void Laser_parameter_all::set_has_passageway_size() {
+  _has_bits_[0] |= 0x00000004u;
+}
+inline void Laser_parameter_all::clear_has_passageway_size() {
+  _has_bits_[0] &= ~0x00000004u;
+}
+inline void Laser_parameter_all::clear_passageway_size() {
+  passageway_size_ = 0;
+  clear_has_passageway_size();
+}
+inline ::google::protobuf::int32 Laser_parameter_all::passageway_size() const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Laser_parameter_all.passageway_size)
+  return passageway_size_;
+}
+inline void Laser_parameter_all::set_passageway_size(::google::protobuf::int32 value) {
+  set_has_passageway_size();
+  passageway_size_ = value;
+  // @@protoc_insertion_point(field_set:Dispatch_proto.Laser_parameter_all.passageway_size)
+}
+
+// repeated .Dispatch_proto.Passageway_parameter passageway_parameters = 6;
+inline int Laser_parameter_all::passageway_parameters_size() const {
+  return passageway_parameters_.size();
+}
+inline void Laser_parameter_all::clear_passageway_parameters() {
+  passageway_parameters_.Clear();
+}
+inline const ::Dispatch_proto::Passageway_parameter& Laser_parameter_all::passageway_parameters(int index) const {
+  // @@protoc_insertion_point(field_get:Dispatch_proto.Laser_parameter_all.passageway_parameters)
+  return passageway_parameters_.Get(index);
+}
+inline ::Dispatch_proto::Passageway_parameter* Laser_parameter_all::mutable_passageway_parameters(int index) {
+  // @@protoc_insertion_point(field_mutable:Dispatch_proto.Laser_parameter_all.passageway_parameters)
+  return passageway_parameters_.Mutable(index);
+}
+inline ::Dispatch_proto::Passageway_parameter* Laser_parameter_all::add_passageway_parameters() {
+  // @@protoc_insertion_point(field_add:Dispatch_proto.Laser_parameter_all.passageway_parameters)
+  return passageway_parameters_.Add();
+}
+inline ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Passageway_parameter >*
+Laser_parameter_all::mutable_passageway_parameters() {
+  // @@protoc_insertion_point(field_mutable_list:Dispatch_proto.Laser_parameter_all.passageway_parameters)
+  return &passageway_parameters_;
+}
+inline const ::google::protobuf::RepeatedPtrField< ::Dispatch_proto::Passageway_parameter >&
+Laser_parameter_all::passageway_parameters() const {
+  // @@protoc_insertion_point(field_list:Dispatch_proto.Laser_parameter_all.passageway_parameters)
+  return passageway_parameters_;
+}
+
+#ifdef __GNUC__
+  #pragma GCC diagnostic pop
+#endif  // __GNUC__
+// -------------------------------------------------------------------
+
+// -------------------------------------------------------------------
+
+// -------------------------------------------------------------------
+
+
+// @@protoc_insertion_point(namespace_scope)
+
+}  // namespace Dispatch_proto
+
+// @@protoc_insertion_point(global_scope)
+
+#endif  // PROTOBUF_dispatch_5fparameter_2eproto__INCLUDED

+ 28 - 0
dispatch/dispatch_parameter.proto

@@ -0,0 +1,28 @@
+
+syntax = "proto2";
+package Dispatch_proto;
+
+message Catcher_parameter
+{
+    required int32                  id = 1;
+}
+
+message Carrier_parameter
+{
+    required int32                  id = 1;
+}
+
+message Passageway_parameter
+{
+    required int32                  id = 1;
+}
+
+message Laser_parameter_all
+{
+    required int32                  catcher_size=1;
+    repeated Catcher_parameter      catcher_parameters=2;
+    required int32                  carrier_size=3;
+    repeated Carrier_parameter      carrier_parameters=4;
+    required int32                  passageway_size=5;
+    repeated Passageway_parameter   passageway_parameters=6;
+}

+ 266 - 0
dispatch/dispatch_process.cpp

@@ -0,0 +1,266 @@
+//
+// Created by huli on 2021/3/22.
+//
+
+#include "dispatch_process.h"
+#include "../system/system_communication.h"
+#include "../dispatch/dispatch_manager.h"
+
+Dispatch_process::Dispatch_process()
+{
+	m_dispatch_process_status = DISPATCH_PROCESS_STATUS_UNKNOW;
+	m_dispatch_process_type = DISPATCH_PROCESS_TYPE_UNKNOW;
+	m_dispatch_source = 0;
+	m_dispatch_destination = 0;
+}
+
+Dispatch_process::~Dispatch_process()
+{
+	Dispatch_process_uninit();
+}
+
+//初始化, 就把主控发送的请求传入即可.
+Error_manager Dispatch_process::Dispatch_process_init(message::Dispatch_request_msg dispatch_request_msg)
+{
+	if ( dispatch_request_msg.base_info().has_timeout_ms() )
+	{
+		m_timeout_ms = dispatch_request_msg.base_info().timeout_ms() - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
+	}
+	else
+	{
+		m_timeout_ms = DISPATCH_PROCESS_TIMEOUT_MS - DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS;
+	}
+	m_command_key = dispatch_request_msg.command_key();
+	m_start_time = std::chrono::system_clock::now();
+
+	if ( dispatch_request_msg.dispatch_motion_direction() == message::E_STORE_CAR )
+	{
+		m_dispatch_process_type = DISPATCH_PROCESS_STORE;
+		m_dispatch_source = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
+		m_dispatch_destination = dispatch_request_msg.parkspace_info().parkspace_id() + PARKSPACE_ID_BASE;
+		Common_data::copy_data(m_parkspace_information, dispatch_request_msg.parkspace_info());
+		Common_data::copy_data(m_car_measure_information, dispatch_request_msg.locate_information());
+	}
+	else if( dispatch_request_msg.dispatch_motion_direction() == message::E_PICKUP_CAR )
+	{
+		m_dispatch_process_type = DISPATCH_PROCESS_PICKUP;
+		m_dispatch_source = dispatch_request_msg.parkspace_info().parkspace_id() + PARKSPACE_ID_BASE;
+		m_dispatch_destination = dispatch_request_msg.terminal_id() + PASSAGEWAY_ID_BASE ;
+		Common_data::copy_data(m_parkspace_information, dispatch_request_msg.parkspace_info());
+	}
+	else
+	{
+		m_dispatch_process_type = DISPATCH_PROCESS_TYPE_UNKNOW;
+		return Error_manager(Error_code::PARAMETER_ERROR, Error_level::MINOR_ERROR,
+							"  Dispatch_process::Dispatch_process_init ERROR ");
+	}
+
+	m_dispatch_process_status = DISPATCH_PROCESS_CREATED;
+	return Error_code::SUCCESS;
+}
+
+//反初始化
+Error_manager Dispatch_process::Dispatch_process_uninit()
+{
+	return Error_code::SUCCESS;
+}
+
+void Dispatch_process::Main()
+{
+	Error_manager t_error;
+
+	//主流程, 循环执行
+	while ( std::chrono::system_clock::now() - m_start_time < std::chrono::milliseconds(m_timeout_ms) )
+	{
+		std::this_thread::sleep_for(std::chrono::microseconds(1));
+
+	    switch ( m_dispatch_process_status )
+	    {
+	        case DISPATCH_PROCESS_CREATED:
+	        {
+				//检查调度请求
+				m_result = check_dispatch_request_msg();
+				if ( m_result !=Error_code::SUCCESS)
+				{
+					m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
+					break;
+				}
+				//发送调度总计划
+				m_result = send_dispatch_plan_request_msg();
+				if ( m_result !=Error_code::SUCCESS)
+				{
+					m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
+					break;
+				}
+				//流程正常, 就进入等待状态, 等待调度控制发送动作指令
+				m_dispatch_process_status = DISPATCH_PROCESS_READY;
+	            break;
+	        }
+	        case DISPATCH_PROCESS_READY:
+	        {
+				//等待控制指令
+				m_result = wait_dispatch_control_request_msg();
+				if ( m_result !=Error_code::SUCCESS)
+				{
+					//不成功, 就表示没有新的指令, 那么什么都不做, 原地待命
+				}
+				else
+				{
+					//流程正常, 就进入工作状态,
+					m_dispatch_process_status = DISPATCH_PROCESS_WORKING;
+					break;
+				}
+
+				//等待调度总计划答复
+				m_result = wait_dispatch_plan_response_msg();
+				if ( m_result !=Error_code::SUCCESS)
+				{
+					//不成功, 就表示没有总计划答复, 那么什么都不做, 原地待命
+				}
+				else
+				{
+					//流程正常, 就进入完成状态,
+					m_dispatch_process_status = DISPATCH_PROCESS_OVER;
+					break;
+				}
+				break;
+	        }
+			case DISPATCH_PROCESS_WORKING:
+			{
+				break;
+			}
+			case DISPATCH_PROCESS_OVER:
+			{
+				//发送调度答复, 发给主控的
+				m_result = send_dispatch_response_msg();
+				if ( m_result !=Error_code::SUCCESS)
+				{
+					m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
+					break;
+				}
+				//流程正常, 就进入等待状态, 等待调度控制发送动作指令
+				m_dispatch_process_status = DISPATCH_PROCESS_RELEASE;
+				break;
+			}
+			case DISPATCH_PROCESS_RELEASE:
+			{
+				//通知调度管理, 释放资源,
+				m_result = release_resource();
+				if ( m_result !=Error_code::SUCCESS)
+				{
+					m_dispatch_process_status = DISPATCH_PROCESS_FAULT;
+					break;
+				}
+
+				//在这里, 整个流程彻底结束, 之后线程池会自动回收 这个流程对象的资源
+				return;
+				break;
+			}
+			case DISPATCH_PROCESS_FAULT:
+			{
+				break;
+			}
+	        default:
+	        {
+
+	            break;
+	        }
+	    }
+	}
+
+	//任务超时
+
+	return;
+}
+
+
+//检查调度请求
+Error_manager Dispatch_process::check_dispatch_request_msg()
+{
+	std::unique_lock<std::mutex> t_lock(m_lock);
+	return Error_code::SUCCESS;
+}
+
+//发送调度总计划
+Error_manager Dispatch_process::send_dispatch_plan_request_msg()
+{
+	std::unique_lock<std::mutex> t_lock(m_lock);
+	m_dispatch_plan_request_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_plan_request_msg);
+	m_dispatch_plan_request_msg.mutable_base_info()->set_timeout_ms(m_timeout_ms);
+	m_dispatch_plan_request_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_mamager);
+	m_dispatch_plan_request_msg.mutable_base_info()->set_receiver(message::Communicator::eDispatch_control);
+	m_dispatch_plan_request_msg.set_command_key(m_command_key);
+
+	m_dispatch_plan_request_msg.set_dispatch_task_type((message::Dispatch_task_type)m_dispatch_process_type);
+	m_dispatch_plan_request_msg.set_dispatch_source(m_dispatch_source);
+	m_dispatch_plan_request_msg.set_dispatch_destination(m_dispatch_destination);
+	//这里不写错误码
+
+	std::string t_msg = m_dispatch_plan_request_msg.SerializeAsString();
+	System_communication::get_instance_references().encapsulate_msg(t_msg);
+	return Error_code::SUCCESS;
+}
+
+
+//等待控制指令
+Error_manager Dispatch_process::wait_dispatch_control_request_msg()
+{
+	std::unique_lock<std::mutex> t_lock(m_lock);
+	//key不相等 就表示 收到了新的控制指令
+	if ( m_dispatch_control_request_msg.command_key() == m_dispatch_control_response_msg.command_key() )
+	{
+		return Error_code::NODATA;
+	}
+	else
+	{
+	    return Error_code::SUCCESS;
+	}
+}
+
+//执行调度控制指令, 并根据完成情况给答复
+Error_manager Dispatch_process::excute_dispatch_control()
+{
+	std::unique_lock<std::mutex> t_lock(m_lock);
+
+	return Error_code::SUCCESS;
+}
+
+
+
+//等待调度总计划答复
+Error_manager Dispatch_process::wait_dispatch_plan_response_msg()
+{
+	std::unique_lock<std::mutex> t_lock(m_lock);
+	//key 相等 就表示 收到了总计划答复
+	if ( m_dispatch_plan_request_msg.command_key() == m_dispatch_plan_response_msg.command_key() )
+	{
+		return Error_code::SUCCESS;
+	}
+	else
+	{
+		return Error_code::NODATA;
+	}
+}
+
+//发送调度答复, 发给主控的
+Error_manager Dispatch_process::send_dispatch_response_msg()
+{
+	std::unique_lock<std::mutex> t_lock(m_lock);
+	m_dispatch_response_msg.mutable_base_info()->set_msg_type(message::Message_type::eDispatch_response_msg);
+	m_dispatch_response_msg.mutable_base_info()->set_timeout_ms(m_timeout_ms);
+	m_dispatch_response_msg.mutable_base_info()->set_sender(message::Communicator::eDispatch_mamager);
+	m_dispatch_response_msg.mutable_base_info()->set_receiver(message::Communicator::eMain);
+	m_dispatch_response_msg.set_command_key(m_command_key);
+
+	m_dispatch_response_msg.mutable_error_manager()->CopyFrom(m_dispatch_plan_response_msg.error_manager());
+
+	std::string t_msg = m_dispatch_response_msg.SerializeAsString();
+	System_communication::get_instance_references().encapsulate_msg(t_msg);
+	return Error_code::SUCCESS;
+}
+
+//通知调度管理, 释放资源,
+Error_manager Dispatch_process::release_resource()
+{
+	return Dispatch_manager::get_instance_references().release_dispatch_process(m_command_key);
+}

+ 150 - 0
dispatch/dispatch_process.h

@@ -0,0 +1,150 @@
+
+
+
+
+/*
+        dispatch_source 和 dispatch_destination 的表示含义
+
+        1~165           2楼~12楼的停车位
+
+        1100            0号出口(在一楼)(目前没有)
+        1101~1106       1~6号出入口 (在一楼)
+        1107            7号出口(在一楼)
+        1201~1206       1~6号出入口上方2楼处
+        1301~1306       1~6号出入口上方3楼处
+        1401~1406       1~6号出入口上方4楼处
+
+        2101~2112       左侧电梯井(1楼~12楼)(一号搬运器的待机点)
+        2201~2212       右侧电梯井(1楼~12楼)(二号搬运器的待机点)
+*/
+
+
+
+
+#ifndef NNXX_TESTS_DISPATCH_PROCESS_H
+#define NNXX_TESTS_DISPATCH_PROCESS_H
+
+#include <error_code.h>
+#include "../tool/thread_condition.h"
+#include "../tool/TaskQueue/BaseTask.h"
+#include "../tool/common_data.h"
+#include <glog/logging.h>
+#include "../dispatch/carrier.h"
+#include "../dispatch/catcher.h"
+#include "../dispatch/passageway.h"
+
+#include "../message/dispatch_message.pb.h"
+#include "../message/dispatch_control.pb.h"
+
+//调度流程 存车
+class Dispatch_process : public tq::BaseTask
+{
+public:
+	//调度指令超时时间 300000ms = 5min
+#define DISPATCH_PROCESS_TIMEOUT_MS							300000
+//调度指令超时时间  衰减值 在原有的基础上减少30秒
+#define DISPATCH_PROCESS_ATTENUATION_TIMEOUT_MS				30000
+
+	//调度流程的状态, 控制步骤
+	enum Dispatch_process_status
+	{
+		DISPATCH_PROCESS_STATUS_UNKNOW          = 0,    //未知
+		DISPATCH_PROCESS_CREATED				= 1, 	//流程创建,
+		DISPATCH_PROCESS_READY               	= 2,    //流程准备,待机
+		DISPATCH_PROCESS_WORKING				= 3, 	//流程工作正忙
+		DISPATCH_PROCESS_OVER					= 4, 	//流程完成
+		DISPATCH_PROCESS_RELEASE				= 5, 	//流程释放
+
+		DISPATCH_PROCESS_FAULT					= 10,	//故障
+		DISPATCH_PROCESS_MOTION_FAILED			= 11,	//单个小动作执行失败
+	};
+	//调度任务类型
+	enum Dispatch_process_type
+	{
+		DISPATCH_PROCESS_TYPE_UNKNOW 			= 0,    //未知
+		DISPATCH_PROCESS_STORE  				= 101,    //存车
+		DISPATCH_PROCESS_PICKUP					= 102,	//取车
+	};
+public:
+	Dispatch_process();
+	Dispatch_process(const Dispatch_process& other)= default;
+	Dispatch_process& operator =(const Dispatch_process& other)= default;
+	~Dispatch_process();
+public://API functions
+	//初始化, 就把主控发送的请求传入即可.
+	Error_manager Dispatch_process_init(message::Dispatch_request_msg dispatch_request_msg);
+	//反初始化
+	Error_manager Dispatch_process_uninit();
+
+public://get or set member variable
+
+protected://member functions
+
+	//主线程
+	virtual void Main();
+
+	//检查调度请求
+	Error_manager check_dispatch_request_msg();
+	//发送调度总计划
+	Error_manager send_dispatch_plan_request_msg();
+
+	//等待控制指令
+	Error_manager wait_dispatch_control_request_msg();
+
+	//执行调度控制指令, 并根据完成情况给答复
+	Error_manager excute_dispatch_control();
+
+	//等待调度总计划答复
+	Error_manager wait_dispatch_plan_response_msg();
+
+	//发送调度答复, 发给主控的
+	Error_manager send_dispatch_response_msg();
+
+	//通知调度管理, 释放资源,
+	Error_manager release_resource();
+
+	//异常处理
+	Error_manager Exception_handling();
+
+public://member variable
+	Dispatch_process_status					m_dispatch_process_status;	//调度流程的状态, 控制步骤
+
+	//流程总规划数据, 外部指令
+	std::mutex                          	m_lock;
+	Dispatch_process_type					m_dispatch_process_type;	//调度任务类型
+	int 									m_dispatch_source;			//调度的起点,源头
+	int 									m_dispatch_destination;		//调度的终点,目的地
+	Common_data::Car_measure_information	m_car_measure_information;	//整车的测量信息
+	Common_data::Parkspace_information		m_parkspace_information;	//单个车位基本信息与状态信息,车位信息以及车位上的车辆信息
+
+	//硬件资源
+	std::shared_ptr<Catcher>				mp_catcher;					//抓车器指针, 内存由Dispatch_manager来管理
+	std::shared_ptr<Task_Base>				mp_catcher_task;			//抓车器任务, 内存由本模块管理
+	std::shared_ptr<Carrier>				mp_carrier;					//搬运器指针, 内存由Dispatch_manager来管理
+	std::shared_ptr<Task_Base>				mp_carrier_task;			//搬运器任务, 内存由本模块管理
+	std::shared_ptr<Passageway>				mp_passageway;				//通道口指针, 内存由Dispatch_manager来管理
+	std::shared_ptr<Task_Base>				mp_passageway_task;			//通道口任务, 内存由本模块管理
+
+
+	std::string								m_command_key;						//任务唯一码
+	int 									m_timeout_ms;						//超时时间,单位ms
+	std::chrono::system_clock::time_point	m_start_time;						//流程开始时间
+	Error_manager 							m_result;							//流程的执行结果
+
+
+	//通信缓存
+	message::Dispatch_request_msg			m_dispatch_request_msg;				//1执行搬运请求(主控->调度管理)
+	message::Dispatch_plan_request_msg		m_dispatch_plan_request_msg;		//2调度总规划的请求, 用于启动整个调度算法(调度管理->调度算法)
+	message::Dispatch_control_request_msg	m_dispatch_control_request_msg;		//3调度控制的任务请求(调度算法->调度管理)
+	message::Dispatch_control_response_msg	m_dispatch_control_response_msg;	//4调度控制的任务答复(调度管理->调度算法)
+	message::Dispatch_plan_response_msg		m_dispatch_plan_response_msg;		//5调度总规划的答复(调度算法->调度管理)
+	message::Dispatch_response_msg			m_dispatch_response_msg;			//6搬运动作执行完成后反馈结果(调度管理->主控)
+	//流程通信顺序为  收1->发2->收3->发4->收3->发4->收3->发4->收5->发6
+
+private:
+
+};
+
+
+#endif //NNXX_TESTS_DISPATCH_PROCESS_H
+

+ 33 - 0
tool/TaskQueue/BaseTask.cpp

@@ -0,0 +1,33 @@
+//
+//  BaseTaskQueue.cpp
+//  LibDriveRating-CXX
+//
+//  Created by Melo Yao on 6/9/14.
+//  Copyright (c) 2014 AutoNavi. All rights reserved.
+//
+
+#include "BaseTask.h"
+
+namespace tq {
+    BaseTask::BaseTask():ITask(),_cancelled(false)
+    {
+    }
+    
+    void BaseTask::Cancel()
+    {
+        _cancelled = true;
+    }
+    
+    bool BaseTask::IsCancelled() const
+    {
+        return _cancelled;
+    }
+    
+    void BaseTask::Run()
+    {
+        if (_cancelled) {
+            return;
+        }
+        Main();
+    }
+}

+ 29 - 0
tool/TaskQueue/BaseTask.h

@@ -0,0 +1,29 @@
+//
+//  BaseTaskQueue.h
+//  LibDriveRating-CXX
+//
+//  Created by Melo Yao on 6/9/14.
+//  Copyright (c) 2014 AutoNavi. All rights reserved.
+//
+
+#ifndef __LibDriveRating_CXX__BaseTaskQueue__
+#define __LibDriveRating_CXX__BaseTaskQueue__
+
+#include "TQInterface.h"
+namespace tq
+{
+    class BaseTask : public ITask
+    {
+    private:
+        volatile bool _cancelled;
+    public:
+        BaseTask();
+        void Run();
+        virtual void Cancel();
+        bool IsCancelled() const;
+        
+        virtual void Main() = 0;
+        TaskCategory GetCategory() const {return NoCategory;}
+    };
+}
+#endif /* defined(__LibDriveRating_CXX__BaseTaskQueue__) */

+ 23 - 0
tool/TaskQueue/TQFactory.cpp

@@ -0,0 +1,23 @@
+//
+//  TQFactory.cpp
+//  LibDriveRating-CXX
+//
+//  Created by Melo Yao on 6/10/14.
+//  Copyright (c) 2014 AutoNavi. All rights reserved.
+//
+
+#include "TQFactory.h"
+#include "ThreadTaskQueue.h"
+namespace tq {
+    IQueue* TQFactory::CreateDefaultQueue()
+    {
+        return new ThreadTaskQueue();
+    }
+    
+    void TQFactory::ReleaseQueue(IQueue* queue)
+    {
+        delete queue;
+    }
+    
+    
+}

+ 24 - 0
tool/TaskQueue/TQFactory.h

@@ -0,0 +1,24 @@
+//
+//  TQFactory.h
+//  LibDriveRating-CXX
+//
+//  Created by Melo Yao on 6/10/14.
+//  Copyright (c) 2014 AutoNavi. All rights reserved.
+//
+
+#ifndef __LibDriveRating_CXX__TQFactory__
+#define __LibDriveRating_CXX__TQFactory__
+
+#include "TQInterface.h"
+
+namespace tq {
+    class TQFactory
+    {
+    public:
+        static IQueue* CreateDefaultQueue();
+
+        static void ReleaseQueue(IQueue* queue);
+    };
+}
+
+#endif /* defined(__LibDriveRating_CXX__TQFactory__) */

+ 58 - 0
tool/TaskQueue/TQInterface.h

@@ -0,0 +1,58 @@
+//
+//  TQInterface.h
+//  LibDriveRating-CXX
+//
+//  Created by Melo Yao on 6/9/14.
+//  Copyright (c) 2014 AutoNavi. All rights reserved.
+//
+
+#ifndef __LibDriveRating_CXX__TQInterface__
+#define __LibDriveRating_CXX__TQInterface__
+
+namespace tq {
+    typedef unsigned long TaskCategory;
+
+    const TaskCategory NoCategory = 0;
+
+    class ITask
+    {
+    public:
+        virtual void Run() = 0;
+        virtual void Cancel() = 0;
+        virtual bool IsCancelled() const = 0;
+        virtual TaskCategory GetCategory() const = 0;
+        virtual ~ITask(){}
+    };
+    
+    typedef void (*TaskRecycler)(ITask* task,void* context);
+
+    class IQueue
+    {
+    public:
+        virtual void Start(unsigned int nThreads = 1) = 0;
+
+        virtual void Stop() = 0;
+
+        virtual void AddTask(ITask* task) = 0;
+        
+        virtual void GetTasks(ITask** tasksBuf, unsigned int taskBufSize) const= 0;
+        
+        virtual unsigned int TaskCount() const = 0;
+        
+        virtual void CancelAll() = 0;
+        
+        virtual void WaitForFinish() = 0;
+
+        virtual void Suspend() = 0;
+        
+        virtual void Resume() = 0;
+        
+        virtual void SetTaskRecycler(TaskCategory cat, TaskRecycler recycler,void *context){}
+
+        virtual void ClearTaskRecycler(TaskCategory cat){}
+
+        virtual ~IQueue() {}
+    };
+}
+
+#endif /* defined(__LibDriveRating_CXX__TQInterface__) */

+ 89 - 0
tool/TaskQueue/TaskPool.h

@@ -0,0 +1,89 @@
+#ifndef H_TASK_POOL_H
+#define H_TASK_POOL_H
+#include <list>
+#include "threadpp/threadpp.h"
+#include <cstdlib>
+#include <cstdio>
+namespace tq
+{
+    template <typename TaskType>
+    class TaskPool
+    {
+    public:
+        TaskPool(unsigned capacity = 10);
+        ~TaskPool();
+        TaskType* GetTask(TaskType const& taskPrototype);
+        void RecycleTask(TaskType* task);
+        void Purge();
+    private:
+        threadpp::lock _mutex;
+        std::list<TaskType*> _tasks;
+        unsigned _capacity;
+    };
+
+    template <typename TaskType>
+    TaskType* TaskPool<TaskType>::GetTask(TaskType const& taskPrototype)
+    {
+        _mutex.lock();
+        if(!_tasks.empty())
+        {
+
+            TaskType* taskptr = _tasks.front();
+            _tasks.pop_front();
+            _mutex.unlock();
+            new (taskptr)TaskType(taskPrototype);
+            return taskptr;
+        }
+        else
+        {
+            _mutex.unlock();
+            static int newcount = 0;
+            TaskType* taskptr = new TaskType(taskPrototype);
+            return taskptr;
+        }
+    }
+
+    template <typename TaskType>
+    void TaskPool<TaskType>::RecycleTask(TaskType* task)
+    {
+        (*task).~TaskType();
+        _mutex.lock();
+        if(_tasks.size()<_capacity)
+        {
+            _tasks.push_back(task);
+        }
+        else
+        {
+            free(task);
+        }
+        _mutex.unlock();
+    }
+    
+    template <typename TaskType>
+    void TaskPool<TaskType>::Purge()
+    {
+        _mutex.lock();
+        if(!_tasks.empty())
+        {
+            for(typename std::list<TaskType*>::const_iterator it = _tasks.begin();it!=_tasks.end();++it)
+            {
+                free(*it);
+            }
+            _tasks.clear();
+        }
+        _mutex.unlock();
+    }
+
+    template <typename TaskType>
+    TaskPool<TaskType>::TaskPool(unsigned capacity):
+    _capacity(capacity)
+    {
+    }
+
+    template <typename TaskType>
+    TaskPool<TaskType>::~TaskPool()
+    {
+        this->Purge();
+    }
+}
+#endif

+ 288 - 0
tool/TaskQueue/ThreadTaskQueue.cpp

@@ -0,0 +1,288 @@
+//
+//  ThreadTaskQueue.cpp
+//  LibDriveRating-CXX
+//
+//  Created by Melo Yao on 6/9/14.
+//  Copyright (c) 2014 AutoNavi. All rights reserved.
+//
+
+#include "ThreadTaskQueue.h"
+#include <algorithm>
+#define WAIT_TIMEOUT 5000
+
+using namespace threadpp;
+
+namespace tq{
+    
+    class QueueRunnable
+    {
+        ThreadTaskQueue* queue;
+        ITask* currentTask;
+    protected:
+        static void run_callback(void*);
+        thread* th;
+        
+        QueueRunnable(ThreadTaskQueue* q):queue(q),currentTask(NULL){}
+        void run();
+        void CancelCurrentTask();
+        bool TaskIsRunning() const;
+        friend class ThreadTaskQueue;
+    };
+    
+    void QueueRunnable::run_callback(void *ctx)
+    {
+        ((QueueRunnable*) ctx)->run();
+    }
+    
+    void QueueRunnable::run()
+    {
+        while (queue->IsStarted()) {
+            queue->LockQueue();
+            ITask* task = queue->NextTask();
+            if (task == NULL) {
+                queue->UnlockQueue();
+                continue;
+            }
+            currentTask = task;
+            queue->UnlockQueue();
+            task->Run();
+
+            queue->LockQueue();
+            currentTask = NULL;
+            queue->FinishTask(task);
+            queue->NotifyQueue();
+            queue->UnlockQueue();
+        }
+    }
+    
+    void QueueRunnable::CancelCurrentTask()
+    {
+        queue->LockQueue();
+        if(currentTask)
+        {
+            currentTask->Cancel();
+        }
+        queue->UnlockQueue();
+    }
+    
+    bool QueueRunnable::TaskIsRunning() const
+    {
+        return currentTask != NULL;
+    }
+    
+    ThreadTaskQueue::ThreadTaskQueue():_tasklist(),_started(false),_suspended(false)
+    {
+        
+    }
+    
+    void ThreadTaskQueue::Start(unsigned int nThreads)
+    {
+        _mutex.lock();
+        if (_started) {
+            _mutex.unlock();
+            return;
+        }
+        _started = true;
+        _threads.reserve(nThreads);
+        for (int i = 0; i<nThreads; ++i) {
+            QueueRunnable* runnable = new QueueRunnable(this);
+            runnable->th = new thread(QueueRunnable::run_callback, runnable);
+            _threads.push_back(runnable);
+        }
+        _mutex.unlock();
+    }
+    
+    void ThreadTaskQueue::Stop()
+    {
+        _mutex.lock();
+        if (!_started) {
+            _mutex.unlock();
+            return;
+        }
+        _started = false;
+        for (std::list<ITask*>::iterator it = _tasklist.begin(); it!= _tasklist.end(); ++it) {
+            delete *it;
+        }
+        _tasklist.clear();
+        _mutex.notify_all();
+        std::vector<QueueRunnable*> copy(_threads);
+        _threads.clear();
+        _mutex.unlock();
+        for (std::vector<QueueRunnable*>::iterator it = copy.begin(); it!=copy.end(); ++it) {
+            (*it)->th->join();
+            thread* t = (*it)->th;
+            delete (*it);
+            delete t;
+        }
+    }
+    
+    bool ThreadTaskQueue::IsStarted() const
+    {
+        return _started;
+    }
+
+
+    void ThreadTaskQueue::AddTask(ITask* task)
+    {
+        _mutex.lock();
+        if (_started) {
+            _tasklist.push_back(task);
+            _mutex.notify_all();
+        }
+        _mutex.unlock();
+    }
+    
+    void ThreadTaskQueue::GetTasks(ITask** tasksBuf, unsigned int taskBufSize) const
+    {
+        recursivelock* mutex = const_cast<recursivelock*>(&_mutex);
+        mutex->lock();
+        size_t count = 0;
+        for (std::list<ITask*>::const_iterator it = _tasklist.begin(); it!=_tasklist.end(); ++it) {
+            if (count<taskBufSize) {
+                tasksBuf[count] = *it;
+                count++;
+            }
+            else
+            {
+                break;
+            }
+        }
+        mutex->unlock();
+    }
+    
+    unsigned int ThreadTaskQueue::TaskCount() const
+    {
+        recursivelock* mutex = const_cast<recursivelock*>(&_mutex);
+        mutex->lock();
+        unsigned int count = (unsigned int)_tasklist.size();
+        mutex->unlock();
+        return count;
+    }
+    
+    void ThreadTaskQueue::CancelAll()
+    {
+        _mutex.lock();
+        for (std::vector<QueueRunnable*>::iterator it = _threads.begin(); it!=_threads.end(); ++it) {
+            (*it)->CancelCurrentTask();
+        }
+        for (std::list<ITask*>::const_iterator it = _tasklist.begin(); it!=_tasklist.end(); ++it) {
+            (*it)->Cancel();
+        }
+        _mutex.unlock();
+        
+    }
+    
+    void ThreadTaskQueue::WaitForFinish()
+    {
+        
+        while (true) {
+            _mutex.lock();
+            bool isExecuting = false;
+            for (std::vector<QueueRunnable*>::iterator it = _threads.begin(); it!=_threads.end(); ++it) {
+                if ((*it)->TaskIsRunning()) {
+                    isExecuting = true;
+                    break;
+                }
+            }
+            if (!isExecuting&&_tasklist.size() == 0) {
+                _mutex.unlock();
+                break;
+            }
+            _mutex.wait(100);
+            _mutex.unlock();
+        }
+        
+    }
+    
+    void ThreadTaskQueue::Suspend()
+    {
+        _mutex.lock();
+        _suspended = true;
+        _mutex.unlock();
+    }
+    
+    void ThreadTaskQueue::Resume()
+    {
+        _mutex.lock();
+        _suspended = false;
+        _mutex.notify_all();
+        _mutex.unlock();
+
+    }
+    
+    void ThreadTaskQueue::NotifyQueue()
+    {
+        _mutex.notify_all();
+    }
+    
+    ITask* ThreadTaskQueue::NextTask()
+    {
+        while (_started && (_tasklist.empty()||_suspended)) {
+            _mutex.wait(WAIT_TIMEOUT);//defensive waiting time limit.
+        }
+        ITask* task = NULL;
+        if (_tasklist.size()>0) {
+            task = _tasklist.front();
+            _tasklist.pop_front();
+        }
+        return task;
+    }
+    
+    inline
+    void ThreadTaskQueue::LockQueue()
+    {
+        _mutex.lock();
+    }
+    
+    inline
+    void ThreadTaskQueue::UnlockQueue()
+    {
+        _mutex.unlock();
+    }
+
+    inline
+    void ThreadTaskQueue::FinishTask(ITask* task)
+    {
+        if(task->GetCategory() != NoCategory)
+        {
+            _recyclerMutex.lock();
+            std::map<TaskCategory,RecyclerPair>::iterator it = _recyclers.find(task->GetCategory());
+            if(it!=_recyclers.end())
+            {
+                RecyclerPair pair = it->second;
+                _recyclerMutex.unlock();
+                pair.recycler(task,pair.context);
+                return;
+            }
+            _recyclerMutex.unlock();
+        }
+        //析构任务
+        delete task;
+
+    }
+    
+    void ThreadTaskQueue::SetTaskRecycler(TaskCategory cat, TaskRecycler recycler,void *context)
+    {
+        _recyclerMutex.lock();
+        std::pair<TaskCategory,RecyclerPair> pair(cat, RecyclerPair(recycler,context));
+        _recyclers.insert(pair);
+        _recyclerMutex.unlock();
+    }
+
+    void ThreadTaskQueue::ClearTaskRecycler(TaskCategory cat)
+    {
+        _recyclerMutex.lock();
+        std::map<TaskCategory,RecyclerPair>::iterator it = _recyclers.find(cat);
+        if(it!=_recyclers.end())
+        {
+            _recyclers.erase(it);
+        }
+        _recyclerMutex.unlock();
+    }
+
+    ThreadTaskQueue::~ThreadTaskQueue()
+    {
+        this->Stop();//Defensive stop.
+    }
+    
+}

+ 89 - 0
tool/TaskQueue/ThreadTaskQueue.h

@@ -0,0 +1,89 @@
+//
+//  ThreadTaskQueue.h
+//  LibDriveRating-CXX
+//
+//  Created by Melo Yao on 6/9/14.
+//  Copyright (c) 2014 AutoNavi. All rights reserved.
+//
+
+#ifndef __LibDriveRating_CXX__ThreadTaskQueue__
+#define __LibDriveRating_CXX__ThreadTaskQueue__
+
+#include "TQInterface.h"
+#include "BaseTask.h"
+#include <list>
+#include <map>
+#include <vector>
+#include "threadpp/threadpp.h"
+
+namespace tq
+{
+    class QueueRunnable;
+    
+    class ThreadTaskQueue:public IQueue
+    {
+    public:
+        ThreadTaskQueue();
+        
+        void Start(unsigned int nThreads = 1);
+        
+        void Stop();
+        
+        bool IsStarted() const;
+
+        void AddTask(ITask* task);//Will transfer the ownership of task.
+        
+        void GetTasks(ITask** tasksBuf, unsigned int taskBufSize) const;
+        
+        unsigned int TaskCount() const;
+        
+        void CancelAll();
+        
+        void WaitForFinish() ;
+        
+        void Suspend();
+        
+        void Resume();
+
+        void SetTaskRecycler(TaskCategory cat, TaskRecycler recycler,void *context);
+
+        void ClearTaskRecycler(TaskCategory cat);
+        
+        ~ThreadTaskQueue();
+        
+    protected:
+        
+        void LockQueue();
+        
+        void UnlockQueue();
+        
+        void NotifyQueue();
+        
+        ITask* NextTask();
+
+        void FinishTask(ITask* task);
+        
+        friend class QueueRunnable;
+
+    private:
+        struct RecyclerPair
+        {
+            TaskRecycler recycler;
+            void *context;
+            RecyclerPair(TaskRecycler r,void* c):
+                recycler(r),context(c)
+            {
+            }
+        };
+
+        std::map<TaskCategory,RecyclerPair> _recyclers;
+        std::list<ITask*> _tasklist;
+        std::vector<QueueRunnable*> _threads;
+        threadpp::recursivelock _mutex;
+        threadpp::lock _recyclerMutex;
+        bool _started;
+        bool _suspended;
+    };
+}
+
+#endif /* defined(__LibDriveRating_CXX__ThreadTaskQueue__) */

+ 35 - 0
tool/TaskQueue/threadpp/impl/pthread_lock.h

@@ -0,0 +1,35 @@
+//
+//  pthread_lock.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef __threadpp__pthread_lock__
+#define __threadpp__pthread_lock__
+//extern "C"
+//{
+#include <pthread.h>
+//}
+namespace threadpp
+{
+    class pthread_lock
+    {
+        pthread_mutex_t _mutex;
+        pthread_cond_t _cond;
+        void operator=(const pthread_lock& l){};
+        pthread_lock(const pthread_lock& l){};
+    public:
+        pthread_lock();
+        ~pthread_lock();
+        void lock();
+        void unlock();
+        void wait();
+        void wait(unsigned long millisecs);
+        void notify();
+        void notify_all();
+    };
+}
+#include "pthread_lock.hpp"
+#endif /* defined(__threadpp__pthread_lock__) */

+ 73 - 0
tool/TaskQueue/threadpp/impl/pthread_lock.hpp

@@ -0,0 +1,73 @@
+//
+//  pthread_lock.cpp
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+#ifndef __threadpp__pthread_lock__hpp__
+#define __threadpp__pthread_lock__hpp__
+#include "../threadpp_assert.h"
+#include <errno.h>
+#include <cstring>
+
+#include <sys/time.h>
+
+static inline void timespec_for(struct timespec* t,unsigned long millisecs) {
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+    t->tv_nsec = tv.tv_usec*1000 + millisecs*1000000;
+    t->tv_sec = tv.tv_sec + (t->tv_nsec/1000000000);
+    t->tv_nsec = t->tv_nsec%1000000000;
+}
+
+namespace threadpp{
+    inline pthread_lock::pthread_lock()
+    {
+        pthread_mutex_init(&_mutex, NULL);
+        pthread_cond_init(&_cond, NULL);
+    }
+    
+    inline pthread_lock::~pthread_lock()
+    {
+        pthread_mutex_destroy(&_mutex);
+        pthread_cond_destroy(&_cond);
+    }
+    
+    inline void pthread_lock::lock()
+    {
+        int code = pthread_mutex_lock(&_mutex);
+        ASSERT(code == 0, "lock failed,error:%s",strerror(code));
+    }
+    
+    inline void pthread_lock::unlock()
+    {
+        int code = pthread_mutex_unlock(&_mutex);
+        ASSERT(code == 0, "unlock failed,error:%s",strerror(code));
+    }
+    
+    inline void pthread_lock::wait()
+    {
+        int code = pthread_cond_wait(&_cond, &_mutex);
+        ASSERT(code == 0 || code == ETIMEDOUT, "wait failed,error:%s",strerror(code));
+    }
+    
+    inline void pthread_lock::wait(unsigned long millisecs)
+    {
+        struct timespec ts;
+        timespec_for(&ts,millisecs);
+        int code = pthread_cond_timedwait(&_cond, &_mutex, &ts);
+        ASSERT(code == 0 || code == ETIMEDOUT, "timed wait failed,error:%s",strerror(code));
+    }
+    
+    inline void pthread_lock::notify()
+    {
+        pthread_cond_signal(&_cond);
+    }
+    
+    inline void pthread_lock::notify_all()
+    {
+        pthread_cond_broadcast(&_cond);
+    }
+}
+#endif

+ 45 - 0
tool/TaskQueue/threadpp/impl/pthread_thread.h

@@ -0,0 +1,45 @@
+//
+//  pthread_thread.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef __threadpp__pthread_thread__
+#define __threadpp__pthread_thread__
+#include <pthread.h>
+namespace threadpp
+{
+    class pthread_thread
+    {
+        struct pthread_context
+        {
+            void(*fp)(void* context);
+            void* context;
+        } _context;
+        
+        pthread_t _thread;
+        pthread_thread(){};
+        void operator=(const pthread_thread& t){};
+        pthread_thread(const pthread_thread& t){};
+        static void* pthread_fp_delegate(void*);
+    public:
+        typedef void (*runnable)(void* ctx);
+        typedef unsigned long long id_type;
+        
+        static id_type null_id();
+        
+        pthread_thread(runnable r,void* t);
+        
+        ~pthread_thread();
+        void join();
+        void detach();
+        bool is_equal(const pthread_thread& t) const;
+        id_type get_id() const;
+        static id_type current_thread_id();
+        static void sleep(unsigned long millisecs);
+    };
+}
+#include "pthread_thread.hpp"
+#endif /* defined(__threadpp__pthread_thread__) */

+ 110 - 0
tool/TaskQueue/threadpp/impl/pthread_thread.hpp

@@ -0,0 +1,110 @@
+//
+//  pthread_thread.cpp
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef __threadpp__pthread_thread__hpp__
+#define __threadpp__pthread_thread__hpp__
+
+#include <errno.h>
+#include "../threadpp_assert.h"
+#include <cstring>
+#include <cmath>
+#include <unistd.h>
+namespace threadpp
+{
+    inline pthread_thread::id_type pthread_thread::null_id()
+    {
+        return 0;
+    }
+    
+    inline void* pthread_thread::pthread_fp_delegate(void* ctx)
+    {
+        pthread_thread::pthread_context* pctx =static_cast<pthread_thread::pthread_context*>(ctx);
+        pctx->fp(pctx->context);
+        return NULL;
+    }
+    
+    inline pthread_thread::pthread_thread(runnable r,void* t)
+    {
+        _context.fp = r;
+        _context.context = t;
+        int code = pthread_create(&_thread, NULL, pthread_thread::pthread_fp_delegate, &_context);
+        ASSERT(code==0,"create thread failed,error:%s",strerror(code));
+    }
+    
+//    pthread_thread::pthread_thread(runnable r,void* t,float priority)
+//    {
+//        _context.fp = r;
+//        _context.context = t;
+//        pthread_attr_t tattr;
+//        pthread_attr_init(&tattr);
+//        struct sched_param schp;
+//        int policy = SCHED_FIFO;
+//        pthread_attr_getschedpolicy(&tattr, &policy);
+//        pthread_attr_getschedparam(&tattr, &schp);
+//        float pr =fminf(1.0f,fmaxf(0.0f, priority));
+//        schp.sched_priority = sched_get_priority_min(policy) + pr*(sched_get_priority_max(policy) - sched_get_priority_min(policy));
+//        pthread_attr_setschedparam(&tattr, &schp);
+//        int code = pthread_create(&_thread, &tattr, pthread_thread::pthread_fp_delegate, &_context);
+//        ASSERT(code==0,"create thread failed,error:%s",strerror(code));
+//        pthread_attr_destroy(&tattr);
+//    }
+    
+    inline pthread_thread::~pthread_thread()
+    {
+        ASSERT(_thread == 0,"%s","must join or detach a thread before destructing it");
+    }
+    
+    inline void pthread_thread::join()
+    {
+        void* ret = NULL;
+        int code = pthread_join(_thread, &ret);
+        _thread = 0;
+        ASSERT(code==0,"join thread failed,error:%s",strerror(code));
+    }
+    
+    inline void pthread_thread::detach()
+    {
+        int code = pthread_detach(_thread);
+        _thread = 0;
+        ASSERT(code==0,"join thread failed,error:%s",strerror(code));
+
+    }
+    
+    inline bool pthread_thread::is_equal(const pthread_thread& t) const
+    {
+        return pthread_equal(_thread, t._thread);
+    }
+    
+    inline void pthread_thread::sleep(unsigned long millisecs)
+    {
+        usleep((useconds_t)millisecs*1000);
+    }
+    
+    inline pthread_thread::id_type pthread_thread::get_id() const
+    {
+#ifdef __APPLE__
+        __uint64_t tid;
+        return pthread_threadid_np(_thread, &tid);
+        return tid;
+#else
+        return (unsigned long long)(_thread);
+#endif
+    }
+    
+    inline pthread_thread::id_type pthread_thread::current_thread_id()
+    {
+#ifdef __APPLE__
+        __uint64_t tid;
+        pthread_threadid_np(pthread_self(), &tid);
+        return tid;
+#else
+        return (unsigned long long)(pthread_self());
+#endif
+    }
+}
+#endif

+ 33 - 0
tool/TaskQueue/threadpp/impl/std_lock.h

@@ -0,0 +1,33 @@
+//
+//  std_lock.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef __threadpp__std_lock__
+#define __threadpp__std_lock__
+#include <mutex>
+#include <condition_variable>
+namespace threadpp
+{
+    class std_lock
+    {
+        std::mutex _mutex;
+        std::condition_variable_any _cond;
+        void operator=(const std_lock& l){};
+        std_lock(const std_lock& l){};
+    public:
+        std_lock();
+        ~std_lock();
+        void lock();
+        void unlock();
+        void wait();
+        void wait(unsigned long millisecs);
+        void notify();
+        void notify_all();
+    };
+}
+#include "std_lock.hpp"
+#endif /* defined(__threadpp__std_lock__) */

+ 52 - 0
tool/TaskQueue/threadpp/impl/std_lock.hpp

@@ -0,0 +1,52 @@
+//
+//  std_lock.cpp
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+#ifndef __threadpp__std_lock__hpp__
+#define __threadpp__std_lock__hpp__
+#include "../threadpp_assert.h"
+
+namespace threadpp{
+    
+    inline std_lock::std_lock():_mutex(),_cond()
+    {
+    }
+    
+    inline std_lock::~std_lock()
+    {
+    }
+    
+    inline void std_lock::lock()
+    {
+        _mutex.lock();
+    }
+    
+    inline void std_lock::unlock()
+    {
+        _mutex.unlock();
+    }
+    
+    inline void std_lock::wait()
+    {
+        _cond.wait(_mutex);
+    }
+    
+    inline void std_lock::wait(unsigned long millisecs)
+    {
+        _cond.wait_for(_mutex, std::chrono::milliseconds(millisecs));
+    }
+    
+    inline void std_lock::notify()
+    {
+        _cond.notify_one();
+    }
+    
+    inline void std_lock::notify_all()
+    {
+        _cond.notify_all();
+    }
+}
+#endif

+ 40 - 0
tool/TaskQueue/threadpp/impl/std_thread.h

@@ -0,0 +1,40 @@
+//
+//  std_thread.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef __threadpp__std_thread__
+#define __threadpp__std_thread__
+#include <thread>
+
+namespace threadpp
+{
+    class std_thread
+    {
+        std::thread _thread;
+        std_thread(){};
+        void operator=(const std_thread& t){};
+        std_thread(const std_thread& t){};
+    public:
+        typedef unsigned long long id_type;
+        
+        typedef void (*runnable)(void* ctx);
+        
+        static id_type null_id();
+        
+        std_thread(runnable r,void* t);
+        
+        ~std_thread();
+        void join();
+        void detach();
+        bool is_equal(const std_thread& t) const;
+        id_type get_id() const;
+        static id_type current_thread_id();
+        static void sleep(unsigned long millisecs);
+    };
+}
+#include "std_thread.hpp"
+#endif /* defined(__threadpp__std_thread__) */

+ 64 - 0
tool/TaskQueue/threadpp/impl/std_thread.hpp

@@ -0,0 +1,64 @@
+//
+//  std_thread.cpp
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+#ifndef __threadpp__std_thread__hpp__
+#define __threadpp__std_thread__hpp__
+#include <functional>
+#include <algorithm>
+namespace threadpp
+{
+    inline std_thread::id_type std_thread::null_id()
+    {
+        return 0;
+    }
+    
+    inline void* std_fp_delegate(std_thread::runnable r, void* context)
+    {
+        r(context);
+        return nullptr;
+    }
+    
+    inline std_thread::std_thread(runnable r,void* t):_thread(std::bind(std_fp_delegate,r,t))
+    {
+    }
+    
+    inline std_thread::~std_thread()
+    {
+        
+    }
+    
+    inline void std_thread::join()
+    {
+        _thread.join();
+    }
+    
+    inline void std_thread::detach()
+    {
+        _thread.detach();
+    }
+    
+    inline bool std_thread::is_equal(const std_thread& t) const
+    {
+        return _thread.get_id() == t._thread.get_id();
+    }
+    
+    inline std_thread::id_type std_thread::get_id() const
+    {
+        return std::hash<std::thread::id>()(_thread.get_id());
+    }
+    
+    inline void std_thread::sleep(unsigned long millisecs)
+    {
+        std::this_thread::sleep_for(std::chrono::milliseconds(millisecs));
+    }
+    
+    inline std_thread::id_type std_thread::current_thread_id()
+    {
+        return std::hash<std::thread::id>()(std::this_thread::get_id());
+    }
+}
+#endif

+ 37 - 0
tool/TaskQueue/threadpp/impl/win_lock.h

@@ -0,0 +1,37 @@
+//
+//  win_lock.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef __threadpp__win_lock__
+#define __threadpp__win_lock__
+
+#include <windows.h>
+
+namespace threadpp
+{
+    class win_lock
+    {
+        CRITICAL_SECTION _mutex;
+        CONDITION_VARIABLE _cond;
+        volatile unsigned int _owner;
+        volatile unsigned int _count;
+        void operator=(const win_lock& l){};
+        win_lock(const win_lock& l){};
+    public:
+        win_lock();
+        ~win_lock();
+        void lock();
+        void unlock();
+        void wait();
+        void wait(unsigned long millisecs);
+        void notify();
+        void notify_all();
+    };
+}
+
+#include "win_lock.hpp"
+#endif /* defined(__threadpp__win_lock__) */

+ 80 - 0
tool/TaskQueue/threadpp/impl/win_lock.hpp

@@ -0,0 +1,80 @@
+//
+//  win_lock.cpp
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+#ifndef __threadpp__win_lock__hpp__
+#define __threadpp__win_lock__hpp__
+
+#include "win_thread.h"
+#include "../threadpp_assert.h"
+#include "stdio.h"
+namespace threadpp{
+    
+    static inline void test_error(const char* title)
+    {
+        DWORD e = GetLastError();
+        ASSERT(e==0,"%s failed,error:%d",title,e);
+    }
+    
+    inline win_lock::win_lock():_owner(0),_count(0)
+    {
+        SetLastError(0);
+        InitializeCriticalSection(&_mutex);
+        InitializeConditionVariable(&_cond);
+        test_error("init");
+    }
+    
+    inline win_lock::~win_lock()
+    {
+        DeleteCriticalSection(&_mutex);
+    }
+    
+    inline void win_lock::lock()
+    {
+        SetLastError(0);
+        
+        EnterCriticalSection(&_mutex);
+        
+        test_error("lock");
+    }
+    
+    inline void win_lock::unlock()
+    {
+        SetLastError(0);
+        LeaveCriticalSection(&_mutex);
+        test_error("unlock");
+    }
+    
+    inline void win_lock::wait()
+    {
+        SetLastError(0);
+        SleepConditionVariableCS(&_cond,&_mutex,0xFFFFFFFF);
+        test_error("wait");
+    }
+    
+    inline void win_lock::wait(unsigned long millisecs)
+    {
+        SetLastError(0);
+        SleepConditionVariableCS(&_cond,&_mutex,millisecs);
+        DWORD e = GetLastError();
+        ASSERT(e==0||e == ERROR_TIMEOUT,"timed wait failed,error:",e);
+    }
+    
+    inline void win_lock::notify()
+    {
+        SetLastError(0);
+        WakeConditionVariable(&_cond);
+        test_error("notify");
+    }
+    
+    inline void win_lock::notify_all()
+    {
+        SetLastError(0);
+        WakeAllConditionVariable(&_cond);
+        test_error("notify all");
+    }
+}
+#endif

+ 53 - 0
tool/TaskQueue/threadpp/impl/win_thread.h

@@ -0,0 +1,53 @@
+//
+//  win_thread.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef __threadpp__win_thread__
+#define __threadpp__win_thread__
+
+#include <windows.h>
+
+namespace threadpp
+{
+    class win_thread
+    {
+        struct win_context
+        {
+            void(*fp)(void*);
+            void* context;
+        } _context;
+#if NO_CRT
+        typedef DWORD handle_t;
+#else
+		typedef unsigned handle_t;
+#endif
+		static handle_t __stdcall win_fp_delegate(void* context);
+        handle_t _thread_id;
+        HANDLE _handle;
+        win_thread(){};
+        void operator=(const win_thread& t){};
+        win_thread(const win_thread& t){};
+    public:
+        typedef void (*runnable)(void* ctx);
+        typedef unsigned int id_type;
+        
+        static id_type null_id();
+        
+        win_thread(runnable r,void* t);
+        
+        ~win_thread();
+        void join();
+        void detach();
+        bool is_equal(const win_thread& t) const;
+        id_type get_id() const;
+        static id_type current_thread_id();
+        static void sleep(unsigned long millisecs);
+    };
+}
+
+#include "win_thread.hpp"
+#endif /* defined(__threadpp__win_thread__) */

+ 81 - 0
tool/TaskQueue/threadpp/impl/win_thread.hpp

@@ -0,0 +1,81 @@
+//
+//  win_thread.cpp
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+#ifndef __threadpp__win_thread__hpp__
+#define __threadpp__win_thread__hpp__
+
+#include "../threadpp_assert.h"
+#if NO_CRT
+#else
+#include <process.h>
+#endif
+namespace threadpp
+{
+
+    inline win_thread::id_type win_thread::null_id()
+    {
+        return 0;
+    }
+    
+	inline win_thread::handle_t win_thread::win_fp_delegate(void *context)
+    {
+        win_context* wctx = static_cast<win_context*>(context);
+        wctx->fp(wctx->context);
+        return 0;
+    }
+    
+    inline win_thread::win_thread(runnable r,void* t)
+    {
+        _context.fp = r;
+        _context.context = t;
+#if NO_CRT
+		_handle = CreateThread(NULL,NULL,win_thread::win_fp_delegate,&_context,0,&_thread_id);
+#else
+		_handle = (HANDLE)_beginthreadex(NULL,0,win_thread::win_fp_delegate,&_context,0,&_thread_id);
+#endif		
+    }
+    
+    inline win_thread::~win_thread()
+    {
+        ASSERT(_handle == 0,"%s","must join or detach a thread before destructing it");
+    }
+    
+    inline void win_thread::join()
+    {
+        unsigned code = WaitForSingleObject(_handle,0xFFFFFFFF);
+        CloseHandle(_handle);
+        _handle = 0;
+        ASSERT(code == WAIT_OBJECT_0 || code == WAIT_ABANDONED, "failed to join,error:%d",code);
+    }
+    
+    inline void win_thread::detach()
+    {
+		CloseHandle(_handle);
+        _handle = 0;
+    }
+    
+    inline bool win_thread::is_equal(const win_thread& t) const
+    {
+        return _thread_id == t._thread_id;
+    }
+    
+    inline void win_thread::sleep(unsigned long millisecs)
+    {
+		Sleep(millisecs);
+    }
+    
+	inline win_thread::id_type win_thread::get_id() const
+	{
+		return static_cast<unsigned int>(_thread_id);
+	}
+
+	inline win_thread::id_type win_thread::current_thread_id()
+	{
+		return  static_cast<unsigned int>(GetCurrentThreadId());
+	}
+}
+#endif

+ 101 - 0
tool/TaskQueue/threadpp/recursive_lock.h

@@ -0,0 +1,101 @@
+//
+//  recursive_lock.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/16/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef threadpp_recursive_lock_h
+#define threadpp_recursive_lock_h
+#include "threadpp_assert.h"
+namespace threadpp
+{
+    template <typename locktype,typename threadtype>
+    class recursive_lock
+    {
+        locktype _lock;
+        volatile typename threadtype::id_type _owner;
+        volatile unsigned int _count;
+    public:
+        recursive_lock();
+        void lock();
+        void unlock();
+        void wait();
+        void wait(unsigned long millisecs);
+        void notify();
+        void notify_all();
+    };
+    
+    template <typename locktype,typename threadtype>
+    recursive_lock<locktype,threadtype>::recursive_lock():_owner(threadtype::null_id()),_count(0)
+    {
+    }
+    
+    template <typename locktype,typename threadtype>
+    void recursive_lock<locktype,threadtype>::lock()
+    {
+        typename threadtype::id_type tid = threadtype::current_thread_id();
+        if(tid == _owner)
+        {
+            _count++;
+        }
+        else
+        {
+            _lock.lock();
+            _owner = tid;
+            _count=1;
+        }
+    }
+    
+    template <typename locktype,typename threadtype>
+    void recursive_lock<locktype,threadtype>::unlock()
+    {
+        typename threadtype::id_type tid = threadtype::current_thread_id();
+        ASSERT(tid == _owner,"%s", "unlock failed,try to unlock not owned mutex");
+        _count--;
+        if (_count == 0) {
+            _owner = threadtype::null_id();
+            _lock.unlock();
+        }
+    }
+    
+    template <typename locktype,typename threadtype>
+    void recursive_lock<locktype,threadtype>::wait()
+    {
+        typename threadtype::id_type owner = _owner;
+        unsigned count = _count;
+        _owner = threadtype::null_id();
+        _count = 0;
+        _lock.wait();
+        _owner = owner;
+        _count = count;
+
+    }
+    
+    template <typename locktype,typename threadtype>
+    void recursive_lock<locktype,threadtype>::wait(unsigned long millisecs)
+    {
+        typename threadtype::id_type owner = _owner;
+        unsigned count = _count;
+        _owner = threadtype::null_id();
+        _count = 0;
+        _lock.wait(millisecs);
+        _owner = owner;
+        _count = count;
+    }
+    
+    template <typename locktype,typename threadtype>
+    void recursive_lock<locktype,threadtype>::notify()
+    {
+        _lock.notify();
+    }
+    
+    template <typename locktype,typename threadtype>
+    void recursive_lock<locktype,threadtype>::notify_all()
+    {
+        _lock.notify_all();
+    }
+}
+
+#endif

+ 40 - 0
tool/TaskQueue/threadpp/threadpp.h

@@ -0,0 +1,40 @@
+//
+//  threadpp.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef threadpp_threadpp_h
+#define threadpp_threadpp_h
+#include "recursive_lock.h"
+#if __posix || __APPLE__ || __linux
+#include "impl/pthread_thread.h"
+#include "impl/pthread_lock.h"
+namespace threadpp
+{
+    typedef pthread_thread thread;
+    typedef pthread_lock lock;
+    typedef recursive_lock<pthread_lock, pthread_thread> recursivelock;
+}
+#elif defined(WIN32)
+#include "impl/win_thread.h"
+#include "impl/win_lock.h"
+namespace threadpp
+{
+    typedef win_thread thread;
+    typedef win_lock lock;
+    typedef recursive_lock<win_lock, win_thread> recursivelock;
+}
+#elif __cplusplus>=201103L
+#include "impl/std_thread.h"
+#include "impl/std_lock.h"
+namespace threadpp
+{
+    typedef std_thread thread;
+    typedef std_lock lock;
+    typedef recursive_lock<std_lock, std_thread> recursivelock;
+}
+#endif
+#endif

+ 33 - 0
tool/TaskQueue/threadpp/threadpp_assert.h

@@ -0,0 +1,33 @@
+//
+//  defines.h
+//  threadpp
+//
+//  Created by Melo Yao on 1/15/15.
+//  Copyright (c) 2015 Melo Yao. All rights reserved.
+//
+
+#ifndef threadpp_assert_h
+#define threadpp_assert_h
+
+//forward VC++ DEBUG symbol.
+#if defined(_DEBUG) && !defined(DEBUG)
+#define DEBUG _DEBUG
+#endif
+
+#if DEBUG //assertions
+#ifdef __cplusplus
+#include <cassert>
+#include <cstdio>
+#else
+#include <assert.h>
+#include <stdio.h>
+#endif
+#define ASSERT0(__cond__) assert(__cond__)
+#define ASSERT(__cond__,__msg__,...) \
+do {if(!(__cond__)){printf(__msg__,__VA_ARGS__);printf("\n");assert(false);}}while(0)
+#else
+#define ASSERT0(__cond__)
+#define ASSERT(__cond__,__msg__,...)
+#endif //assertions
+
+#endif

+ 133 - 0
tool/time_tool.cpp

@@ -0,0 +1,133 @@
+//
+// Created by wk on 2020/9/25.
+//
+
+#include "time_tool.h"
+Time_tool::Time_tool()
+{
+}
+Time_tool::~Time_tool()
+{
+	Time_tool_uninit();
+}
+void Time_tool::set_points_digits(int num)
+{
+	std::cout.precision(num);
+	std::cout.setf(std::ios::fixed);
+}
+std::chrono::system_clock::time_point Time_tool::get_system_point()
+{
+	return std::chrono::system_clock::now();
+}
+tm Time_tool::get_current_time_struct()
+{
+	auto now = std::chrono::system_clock::now();
+	time_t tt = std::chrono::system_clock::to_time_t(now);
+	tm time_tm=*localtime(&tt);
+	return time_tm;
+}
+std::string Time_tool::get_current_time_seconds()
+{
+	auto time_tm = get_current_time_struct();
+	char strTime[100] = "";
+	sprintf(strTime, "%d-%02d-%02d %02d:%02d:%02d", time_tm.tm_year + 1900,
+			time_tm.tm_mon + 1, time_tm.tm_mday, time_tm.tm_hour,
+			time_tm.tm_min, time_tm.tm_sec);
+	std::string str=strTime;
+	return str;
+}
+std::string Time_tool::get_current_time_millisecond()
+{
+
+	auto now = std::chrono::system_clock::now();
+	//通过不同精度获取相差的毫秒数
+	uint64_t dis_millseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count()
+							   - std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count() * 1000;
+	std::string strTime=get_current_time_seconds()+" "+std::to_string((int)dis_millseconds);
+	return strTime;
+}
+std::string Time_tool::get_current_time_microsecond()
+{
+
+	auto now = std::chrono::system_clock::now();
+	//通过不同精度获取相差的微秒
+	uint64_t dis_microseconds = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()).count()
+							   - std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count() * 1000;
+	std::string strTime=get_current_time_millisecond()+" "+std::to_string((int)dis_microseconds);
+	return strTime;
+}
+void Time_tool::time_start(int key)
+{
+	timetool_map[key].t_time_start=get_system_point();//保存开始的时间 //单位为微秒
+}
+
+void Time_tool::time_end(int key)
+{
+	if ( timetool_map.find(key)!=timetool_map.end() )
+	{
+		timetool_map[key].t_time_end = get_system_point();//保存结束的时间
+		timetool_map[key].t_time_difference = timetool_map[key].t_time_end - timetool_map[key].t_time_start;//保存时差
+	}
+	else
+	{
+	    std::cout << "计时器:" << key<<"还未开始"<<std::endl;
+	}
+
+}
+void Time_tool::cout_time_seconds(int key)
+{
+
+	if ( timetool_map.find(key)!=timetool_map.end() )
+	{
+		double dieoutTime=(double)timetool_map[key].t_time_difference.count()/1000000000;
+		std::cout << "计时器:"<<key<<" 计时的时间为:" <<dieoutTime<<" 秒" << std::endl;
+	}
+	else
+	{
+		std::cout<<"没有此计时器:"<<key<<std::endl;
+	}
+}
+void Time_tool::cout_time_millisecond(int key)
+{
+	if ( timetool_map.find(key)!=timetool_map.end() )
+	{
+		double dieoutTime=(double)timetool_map[key].t_time_difference.count()/1000000;
+		std::cout << "计时器:"<<key<<" 计时的时间为:" <<dieoutTime<<" 毫秒" << std::endl;
+	}
+	else
+	{
+		std::cout<<"没有此计时器:"<<key<<std::endl;
+	}
+}
+void Time_tool::cout_time_microsecond(int key)
+{
+	if ( timetool_map.find(key)!=timetool_map.end() )
+	{
+		double dieoutTime=(double)timetool_map[key].t_time_difference.count()/1000;
+
+		std::cout << "计时器:"<<key<<" 计时的时间为:" <<dieoutTime<<" 微秒" << std::endl;
+	}
+	else
+	{
+		std::cout<<"没有此计时器:"<<key<<std::endl;
+	}
+}
+void Time_tool::cout_time_nanosecond(int key)
+{
+	if ( timetool_map.find(key)!=timetool_map.end() )
+	{
+		std::cout << "计时器:"<<key<<" 计时的时间为:" <<timetool_map[key].t_time_difference.count()<<" 纳秒" << std::endl;
+	}
+	else
+	{
+		std::cout<<"没有此计时器:"<<key<<std::endl;
+	}
+}
+void Time_tool::clear_timer()
+{
+	Time_tool_uninit();
+}
+void Time_tool::Time_tool_uninit()
+{
+	timetool_map.clear();
+}

+ 81 - 0
tool/time_tool.h

@@ -0,0 +1,81 @@
+//
+// Created by wk on 2020/9/25.
+//
+
+#ifndef PKGNAME_TIME_TOOL_H
+#define PKGNAME_TIME_TOOL_H
+
+#include <thread>
+#include <map>
+#include <iostream>
+#include<time.h>
+#include <queue>
+#include "./singleton.h"
+
+class Time_tool:public Singleton<Time_tool>
+{
+// 子类必须把父类设定为友元函数,这样父类才能使用子类的私有构造函数。
+   friend class Singleton<Time_tool>;
+struct time_data
+{
+	std::chrono::system_clock::time_point		t_time_start;//计时开始
+	std::chrono::system_clock::time_point 		t_time_end;//计时结束
+	std::chrono::system_clock::duration			t_time_difference;//时差
+};
+private:
+ // 父类的构造函数必须保护,子类的构造函数必须私有。
+   Time_tool();
+public:
+    //必须关闭拷贝构造和赋值构造,只能通过 get_instance 函数来进行操作唯一的实例。
+    Time_tool(const Time_tool& other) = delete;
+    Time_tool& operator =(const Time_tool& other) = delete;
+    ~Time_tool();
+public://API functions
+	void Time_tool_uninit();
+
+    //获取当前系统时间点
+	std::chrono::system_clock::time_point get_system_point();
+
+	//设置输出格式  保留小数点后几位  不设置默认为系统输出
+	void set_points_digits(int);
+
+	//获取当前时间 精确到秒
+	 std::string get_current_time_seconds();
+
+	//获取当前时间 精确到毫秒
+	std::string get_current_time_millisecond();
+
+	//获取当前时间 精确到微妙
+	std::string get_current_time_microsecond();
+
+	//获取当前时间结构体
+	tm get_current_time_struct();
+
+	//计时开始
+	void time_start(int key=1);
+
+	//指定计时器计时结束
+	void time_end(int key=1);
+
+	//打印计时时差 精确到秒
+	void cout_time_seconds(int key=1);
+
+	//打印计时时差 精确到毫秒
+	void cout_time_millisecond(int key=1);
+
+	//打印计时时差 精确到微秒
+	void cout_time_microsecond(int key=1);
+
+	//打印计时时差 精确到纳秒
+	void cout_time_nanosecond(int key=1);
+
+	//清除计时器
+	void clear_timer();
+public://get or set member variable
+protected://member variable
+
+    
+private:
+	std::map<int,time_data> 			timetool_map;
+};
+#endif //PKGNAME_TIME_TOOL_H