diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a832a9..8214e21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,11 @@ cmake_minimum_required(VERSION 3.5) -# cmake_policy(SET CMP0074 NEW) +# cmake_policy(SET CMP0146 NEW) message("NVIDIA NX PLATFORM") set(PROJECT_NAME train) project(${PROJECT_NAME} VERSION 1.0) - + add_definitions(-std=c++11) add_definitions(-DAPI_EXPORTS) @@ -100,18 +100,19 @@ include_directories( ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common #common engine include - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine +# ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine + ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine + ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ApiEngine #common tools rtsp_server include ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/3rdpart/md5 @@ -180,17 +181,18 @@ file(GLOB_RECURSE COMMON_SRCS_LISTS #common engine src ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp - - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine/*.cpp +# ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine/*.cpp + ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp + ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SocketEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/*.cpp + ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ApiEngine/*.cpp #common tools rtsp_server src ${PROJECT_SOURCE_DIR}/nvidia_ascend_tools/common_tools/rtsp_server/net/*.cpp @@ -199,18 +201,6 @@ file(GLOB_RECURSE COMMON_SRCS_LISTS file(GLOB_RECURSE SRCS_LISTS #nvidia engine src - #nvidia engine include - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/ControlEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataSourceEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataUploadEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/FilterEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/MergerEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SaveEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/SelectBestEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TrainAnaEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/TransEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/common_engine/DataDealEngine/*.cpp - ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepOneEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/ChkDateStepTwoEngine/*.cpp ${PROJECT_SOURCE_DIR}/nvidia_ascend_engine/nvidia_engine/MyYaml/*.cpp diff --git a/README.md b/README.md index ec07105..8a636fd 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,2 @@ # Train_Identify -火车车号识别 \ No newline at end of file diff --git a/ai_matrix/Http/httplib.h b/ai_matrix/Http/httplib.h deleted file mode 100644 index be35c57..0000000 --- a/ai_matrix/Http/httplib.h +++ /dev/null @@ -1,9388 +0,0 @@ -// -// httplib.h -// -// Copyright (c) 2023 Yuji Hirose. All rights reserved. -// MIT License -// - -#ifndef CPPHTTPLIB_HTTPLIB_H -#define CPPHTTPLIB_HTTPLIB_H - -#define CPPHTTPLIB_VERSION "0.14.3" - -/* - * Configuration - */ - -#ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND -#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5 -#endif - -#ifndef CPPHTTPLIB_KEEPALIVE_MAX_COUNT -#define CPPHTTPLIB_KEEPALIVE_MAX_COUNT 5 -#endif - -#ifndef CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND -#define CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND 300 -#endif - -#ifndef CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND -#define CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND 0 -#endif - -#ifndef CPPHTTPLIB_READ_TIMEOUT_SECOND -#define CPPHTTPLIB_READ_TIMEOUT_SECOND 5 -#endif - -#ifndef CPPHTTPLIB_READ_TIMEOUT_USECOND -#define CPPHTTPLIB_READ_TIMEOUT_USECOND 0 -#endif - -#ifndef CPPHTTPLIB_WRITE_TIMEOUT_SECOND -#define CPPHTTPLIB_WRITE_TIMEOUT_SECOND 5 -#endif - -#ifndef CPPHTTPLIB_WRITE_TIMEOUT_USECOND -#define CPPHTTPLIB_WRITE_TIMEOUT_USECOND 0 -#endif - -#ifndef CPPHTTPLIB_IDLE_INTERVAL_SECOND -#define CPPHTTPLIB_IDLE_INTERVAL_SECOND 0 -#endif - -#ifndef CPPHTTPLIB_IDLE_INTERVAL_USECOND -#ifdef _WIN32 -#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 10000 -#else -#define CPPHTTPLIB_IDLE_INTERVAL_USECOND 0 -#endif -#endif - -#ifndef CPPHTTPLIB_REQUEST_URI_MAX_LENGTH -#define CPPHTTPLIB_REQUEST_URI_MAX_LENGTH 8192 -#endif - -#ifndef CPPHTTPLIB_HEADER_MAX_LENGTH -#define CPPHTTPLIB_HEADER_MAX_LENGTH 8192 -#endif - -#ifndef CPPHTTPLIB_REDIRECT_MAX_COUNT -#define CPPHTTPLIB_REDIRECT_MAX_COUNT 20 -#endif - -#ifndef CPPHTTPLIB_MULTIPART_FORM_DATA_FILE_MAX_COUNT -#define CPPHTTPLIB_MULTIPART_FORM_DATA_FILE_MAX_COUNT 1024 -#endif - -#ifndef CPPHTTPLIB_PAYLOAD_MAX_LENGTH -#define CPPHTTPLIB_PAYLOAD_MAX_LENGTH ((std::numeric_limits::max)()) -#endif - -#ifndef CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH -#define CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH 8192 -#endif - -#ifndef CPPHTTPLIB_TCP_NODELAY -#define CPPHTTPLIB_TCP_NODELAY false -#endif - -#ifndef CPPHTTPLIB_RECV_BUFSIZ -#define CPPHTTPLIB_RECV_BUFSIZ size_t(4096u) -#endif - -#ifndef CPPHTTPLIB_COMPRESSION_BUFSIZ -#define CPPHTTPLIB_COMPRESSION_BUFSIZ size_t(16384u) -#endif - -#ifndef CPPHTTPLIB_THREAD_POOL_COUNT -#define CPPHTTPLIB_THREAD_POOL_COUNT \ - ((std::max)(8u, std::thread::hardware_concurrency() > 0 \ - ? std::thread::hardware_concurrency() - 1 \ - : 0)) -#endif - -#ifndef CPPHTTPLIB_RECV_FLAGS -#define CPPHTTPLIB_RECV_FLAGS 0 -#endif - -#ifndef CPPHTTPLIB_SEND_FLAGS -#define CPPHTTPLIB_SEND_FLAGS 0 -#endif - -#ifndef CPPHTTPLIB_LISTEN_BACKLOG -#define CPPHTTPLIB_LISTEN_BACKLOG 5 -#endif - -/* - * Headers - */ - -#ifdef _WIN32 -#ifndef _CRT_SECURE_NO_WARNINGS -#define _CRT_SECURE_NO_WARNINGS -#endif //_CRT_SECURE_NO_WARNINGS - -#ifndef _CRT_NONSTDC_NO_DEPRECATE -#define _CRT_NONSTDC_NO_DEPRECATE -#endif //_CRT_NONSTDC_NO_DEPRECATE - -#if defined(_MSC_VER) -#if _MSC_VER < 1900 -#error Sorry, Visual Studio versions prior to 2015 are not supported -#endif - -#pragma comment(lib, "ws2_32.lib") - -#ifdef _WIN64 -using ssize_t = __int64; -#else -using ssize_t = long; -#endif -#endif // _MSC_VER - -#ifndef S_ISREG -#define S_ISREG(m) (((m)&S_IFREG) == S_IFREG) -#endif // S_ISREG - -#ifndef S_ISDIR -#define S_ISDIR(m) (((m)&S_IFDIR) == S_IFDIR) -#endif // S_ISDIR - -#ifndef NOMINMAX -#define NOMINMAX -#endif // NOMINMAX - -#include -#include -#include - -#ifndef WSA_FLAG_NO_HANDLE_INHERIT -#define WSA_FLAG_NO_HANDLE_INHERIT 0x80 -#endif - -using socket_t = SOCKET; -#ifdef CPPHTTPLIB_USE_POLL -#define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout) -#endif - -#else // not _WIN32 - -#include -#if !defined(_AIX) && !defined(__MVS__) -#include -#endif -#ifdef __MVS__ -#include -#ifndef NI_MAXHOST -#define NI_MAXHOST 1025 -#endif -#endif -#include -#include -#include -#ifdef __linux__ -#include -#endif -#include -#ifdef CPPHTTPLIB_USE_POLL -#include -#endif -#include -#include -#include -#include -#include -#include -#include - -using socket_t = int; -#ifndef INVALID_SOCKET -#define INVALID_SOCKET (-1) -#endif -#endif //_WIN32 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -#ifdef _WIN32 -#include - -// these are defined in wincrypt.h and it breaks compilation if BoringSSL is -// used -#undef X509_NAME -#undef X509_CERT_PAIR -#undef X509_EXTENSIONS -#undef PKCS7_SIGNER_INFO - -#ifdef _MSC_VER -#pragma comment(lib, "crypt32.lib") -#endif -#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__) -#include -#if TARGET_OS_OSX -#include -#include -#endif // TARGET_OS_OSX -#endif // _WIN32 - -#include -#include -#include -#include - -#if defined(_WIN32) && defined(OPENSSL_USE_APPLINK) -#include -#endif - -#include -#include - -#if OPENSSL_VERSION_NUMBER < 0x30000000L -#error Sorry, OpenSSL versions prior to 3.0.0 are not supported -#endif - -#endif - -#ifdef CPPHTTPLIB_ZLIB_SUPPORT -#include -#endif - -#ifdef CPPHTTPLIB_BROTLI_SUPPORT -#include -#include -#endif - -/* - * Declaration - */ -namespace httplib { - -namespace detail { - -/* - * Backport std::make_unique from C++14. - * - * NOTE: This code came up with the following stackoverflow post: - * https://stackoverflow.com/questions/10149840/c-arrays-and-make-unique - * - */ - -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(Args &&...args) { - return std::unique_ptr(new T(std::forward(args)...)); -} - -template -typename std::enable_if::value, std::unique_ptr>::type -make_unique(std::size_t n) { - typedef typename std::remove_extent::type RT; - return std::unique_ptr(new RT[n]); -} - -struct ci { - bool operator()(const std::string &s1, const std::string &s2) const { - return std::lexicographical_compare(s1.begin(), s1.end(), s2.begin(), - s2.end(), - [](unsigned char c1, unsigned char c2) { - return ::tolower(c1) < ::tolower(c2); - }); - } -}; - -// This is based on -// "http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4189". - -struct scope_exit { - explicit scope_exit(std::function &&f) - : exit_function(std::move(f)), execute_on_destruction{true} {} - - scope_exit(scope_exit &&rhs) noexcept - : exit_function(std::move(rhs.exit_function)), - execute_on_destruction{rhs.execute_on_destruction} { - rhs.release(); - } - - ~scope_exit() { - if (execute_on_destruction) { this->exit_function(); } - } - - void release() { this->execute_on_destruction = false; } - -private: - scope_exit(const scope_exit &) = delete; - void operator=(const scope_exit &) = delete; - scope_exit &operator=(scope_exit &&) = delete; - - std::function exit_function; - bool execute_on_destruction; -}; - -} // namespace detail - -enum StatusCode { - // Information responses - Continue_100 = 100, - SwitchingProtocol_101 = 101, - Processing_102 = 102, - EarlyHints_103 = 103, - - // Successful responses - OK_200 = 200, - Created_201 = 201, - Accepted_202 = 202, - NonAuthoritativeInformation_203 = 203, - NoContent_204 = 204, - ResetContent_205 = 205, - PartialContent_206 = 206, - MultiStatus_207 = 207, - AlreadyReported_208 = 208, - IMUsed_226 = 226, - - // Redirection messages - MultipleChoices_300 = 300, - MovedPermanently_301 = 301, - Found_302 = 302, - SeeOther_303 = 303, - NotModified_304 = 304, - UseProxy_305 = 305, - unused_306 = 306, - TemporaryRedirect_307 = 307, - PermanentRedirect_308 = 308, - - // Client error responses - BadRequest_400 = 400, - Unauthorized_401 = 401, - PaymentRequired_402 = 402, - Forbidden_403 = 403, - NotFound_404 = 404, - MethodNotAllowed_405 = 405, - NotAcceptable_406 = 406, - ProxyAuthenticationRequired_407 = 407, - RequestTimeout_408 = 408, - Conflict_409 = 409, - Gone_410 = 410, - LengthRequired_411 = 411, - PreconditionFailed_412 = 412, - PayloadTooLarge_413 = 413, - UriTooLong_414 = 414, - UnsupportedMediaType_415 = 415, - RangeNotSatisfiable_416 = 416, - ExpectationFailed_417 = 417, - ImATeapot_418 = 418, - MisdirectedRequest_421 = 421, - UnprocessableContent_422 = 422, - Locked_423 = 423, - FailedDependency_424 = 424, - TooEarly_425 = 425, - UpgradeRequired_426 = 426, - PreconditionRequired_428 = 428, - TooManyRequests_429 = 429, - RequestHeaderFieldsTooLarge_431 = 431, - UnavailableForLegalReasons_451 = 451, - - // Server error responses - InternalServerError_500 = 500, - NotImplemented_501 = 501, - BadGateway_502 = 502, - ServiceUnavailable_503 = 503, - GatewayTimeout_504 = 504, - HttpVersionNotSupported_505 = 505, - VariantAlsoNegotiates_506 = 506, - InsufficientStorage_507 = 507, - LoopDetected_508 = 508, - NotExtended_510 = 510, - NetworkAuthenticationRequired_511 = 511, -}; - -using Headers = std::multimap; - -using Params = std::multimap; -using Match = std::smatch; - -using Progress = std::function; - -struct Response; -using ResponseHandler = std::function; - -struct MultipartFormData { - std::string name; - std::string content; - std::string filename; - std::string content_type; -}; -using MultipartFormDataItems = std::vector; -using MultipartFormDataMap = std::multimap; - -class DataSink { -public: - DataSink() : os(&sb_), sb_(*this) {} - - DataSink(const DataSink &) = delete; - DataSink &operator=(const DataSink &) = delete; - DataSink(DataSink &&) = delete; - DataSink &operator=(DataSink &&) = delete; - - std::function write; - std::function is_writable; - std::function done; - std::function done_with_trailer; - std::ostream os; - -private: - class data_sink_streambuf : public std::streambuf { - public: - explicit data_sink_streambuf(DataSink &sink) : sink_(sink) {} - - protected: - std::streamsize xsputn(const char *s, std::streamsize n) override { - sink_.write(s, static_cast(n)); - return n; - } - - private: - DataSink &sink_; - }; - - data_sink_streambuf sb_; -}; - -using ContentProvider = - std::function; - -using ContentProviderWithoutLength = - std::function; - -using ContentProviderResourceReleaser = std::function; - -struct MultipartFormDataProvider { - std::string name; - ContentProviderWithoutLength provider; - std::string filename; - std::string content_type; -}; -using MultipartFormDataProviderItems = std::vector; - -using ContentReceiverWithProgress = - std::function; - -using ContentReceiver = - std::function; - -using MultipartContentHeader = - std::function; - -class ContentReader { -public: - using Reader = std::function; - using MultipartReader = std::function; - - ContentReader(Reader reader, MultipartReader multipart_reader) - : reader_(std::move(reader)), - multipart_reader_(std::move(multipart_reader)) {} - - bool operator()(MultipartContentHeader header, - ContentReceiver receiver) const { - return multipart_reader_(std::move(header), std::move(receiver)); - } - - bool operator()(ContentReceiver receiver) const { - return reader_(std::move(receiver)); - } - - Reader reader_; - MultipartReader multipart_reader_; -}; - -using Range = std::pair; -using Ranges = std::vector; - -struct Request { - std::string method; - std::string path; - Headers headers; - std::string body; - - std::string remote_addr; - int remote_port = -1; - std::string local_addr; - int local_port = -1; - - // for server - std::string version; - std::string target; - Params params; - MultipartFormDataMap files; - Ranges ranges; - Match matches; - std::unordered_map path_params; - - // for client - ResponseHandler response_handler; - ContentReceiverWithProgress content_receiver; - Progress progress; -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - const SSL *ssl = nullptr; -#endif - - bool has_header(const std::string &key) const; - std::string get_header_value(const std::string &key, size_t id = 0) const; - uint64_t get_header_value_u64(const std::string &key, size_t id = 0) const; - size_t get_header_value_count(const std::string &key) const; - void set_header(const std::string &key, const std::string &val); - - bool has_param(const std::string &key) const; - std::string get_param_value(const std::string &key, size_t id = 0) const; - size_t get_param_value_count(const std::string &key) const; - - bool is_multipart_form_data() const; - - bool has_file(const std::string &key) const; - MultipartFormData get_file_value(const std::string &key) const; - std::vector get_file_values(const std::string &key) const; - - // private members... - size_t redirect_count_ = CPPHTTPLIB_REDIRECT_MAX_COUNT; - size_t content_length_ = 0; - ContentProvider content_provider_; - bool is_chunked_content_provider_ = false; - size_t authorization_count_ = 0; -}; - -struct Response { - std::string version; - int status = -1; - std::string reason; - Headers headers; - std::string body; - std::string location; // Redirect location - - bool has_header(const std::string &key) const; - std::string get_header_value(const std::string &key, size_t id = 0) const; - uint64_t get_header_value_u64(const std::string &key, size_t id = 0) const; - size_t get_header_value_count(const std::string &key) const; - void set_header(const std::string &key, const std::string &val); - - void set_redirect(const std::string &url, int status = StatusCode::Found_302); - void set_content(const char *s, size_t n, const std::string &content_type); - void set_content(const std::string &s, const std::string &content_type); - - void set_content_provider( - size_t length, const std::string &content_type, ContentProvider provider, - ContentProviderResourceReleaser resource_releaser = nullptr); - - void set_content_provider( - const std::string &content_type, ContentProviderWithoutLength provider, - ContentProviderResourceReleaser resource_releaser = nullptr); - - void set_chunked_content_provider( - const std::string &content_type, ContentProviderWithoutLength provider, - ContentProviderResourceReleaser resource_releaser = nullptr); - - Response() = default; - Response(const Response &) = default; - Response &operator=(const Response &) = default; - Response(Response &&) = default; - Response &operator=(Response &&) = default; - ~Response() { - if (content_provider_resource_releaser_) { - content_provider_resource_releaser_(content_provider_success_); - } - } - - // private members... - size_t content_length_ = 0; - ContentProvider content_provider_; - ContentProviderResourceReleaser content_provider_resource_releaser_; - bool is_chunked_content_provider_ = false; - bool content_provider_success_ = false; -}; - -class Stream { -public: - virtual ~Stream() = default; - - virtual bool is_readable() const = 0; - virtual bool is_writable() const = 0; - - virtual ssize_t read(char *ptr, size_t size) = 0; - virtual ssize_t write(const char *ptr, size_t size) = 0; - virtual void get_remote_ip_and_port(std::string &ip, int &port) const = 0; - virtual void get_local_ip_and_port(std::string &ip, int &port) const = 0; - virtual socket_t socket() const = 0; - - template - ssize_t write_format(const char *fmt, const Args &...args); - ssize_t write(const char *ptr); - ssize_t write(const std::string &s); -}; - -class TaskQueue { -public: - TaskQueue() = default; - virtual ~TaskQueue() = default; - - virtual bool enqueue(std::function fn) = 0; - virtual void shutdown() = 0; - - virtual void on_idle() {} -}; - -class ThreadPool : public TaskQueue { -public: - explicit ThreadPool(size_t n, size_t mqr = 0) - : shutdown_(false), max_queued_requests_(mqr) { - while (n) { - threads_.emplace_back(worker(*this)); - n--; - } - } - - ThreadPool(const ThreadPool &) = delete; - ~ThreadPool() override = default; - - bool enqueue(std::function fn) override { - { - std::unique_lock lock(mutex_); - if (max_queued_requests_ > 0 && jobs_.size() >= max_queued_requests_) { - return false; - } - jobs_.push_back(std::move(fn)); - } - - cond_.notify_one(); - return true; - } - - void shutdown() override { - // Stop all worker threads... - { - std::unique_lock lock(mutex_); - shutdown_ = true; - } - - cond_.notify_all(); - - // Join... - for (auto &t : threads_) { - t.join(); - } - } - -private: - struct worker { - explicit worker(ThreadPool &pool) : pool_(pool) {} - - void operator()() { - for (;;) { - std::function fn; - { - std::unique_lock lock(pool_.mutex_); - - pool_.cond_.wait( - lock, [&] { return !pool_.jobs_.empty() || pool_.shutdown_; }); - - if (pool_.shutdown_ && pool_.jobs_.empty()) { break; } - - fn = std::move(pool_.jobs_.front()); - pool_.jobs_.pop_front(); - } - - assert(true == static_cast(fn)); - fn(); - } - } - - ThreadPool &pool_; - }; - friend struct worker; - - std::vector threads_; - std::list> jobs_; - - bool shutdown_; - size_t max_queued_requests_ = 0; - - std::condition_variable cond_; - std::mutex mutex_; -}; - -using Logger = std::function; - -using SocketOptions = std::function; - -void default_socket_options(socket_t sock); - -const char *status_message(int status); - -std::string get_bearer_token_auth(const Request &req); - -namespace detail { - -class MatcherBase { -public: - virtual ~MatcherBase() = default; - - // Match request path and populate its matches and - virtual bool match(Request &request) const = 0; -}; - -/** - * Captures parameters in request path and stores them in Request::path_params - * - * Capture name is a substring of a pattern from : to /. - * The rest of the pattern is matched agains the request path directly - * Parameters are captured starting from the next character after - * the end of the last matched static pattern fragment until the next /. - * - * Example pattern: - * "/path/fragments/:capture/more/fragments/:second_capture" - * Static fragments: - * "/path/fragments/", "more/fragments/" - * - * Given the following request path: - * "/path/fragments/:1/more/fragments/:2" - * the resulting capture will be - * {{"capture", "1"}, {"second_capture", "2"}} - */ -class PathParamsMatcher : public MatcherBase { -public: - PathParamsMatcher(const std::string &pattern); - - bool match(Request &request) const override; - -private: - static constexpr char marker = ':'; - // Treat segment separators as the end of path parameter capture - // Does not need to handle query parameters as they are parsed before path - // matching - static constexpr char separator = '/'; - - // Contains static path fragments to match against, excluding the '/' after - // path params - // Fragments are separated by path params - std::vector static_fragments_; - // Stores the names of the path parameters to be used as keys in the - // Request::path_params map - std::vector param_names_; -}; - -/** - * Performs std::regex_match on request path - * and stores the result in Request::matches - * - * Note that regex match is performed directly on the whole request. - * This means that wildcard patterns may match multiple path segments with /: - * "/begin/(.*)/end" will match both "/begin/middle/end" and "/begin/1/2/end". - */ -class RegexMatcher : public MatcherBase { -public: - RegexMatcher(const std::string &pattern) : regex_(pattern) {} - - bool match(Request &request) const override; - -private: - std::regex regex_; -}; - -ssize_t write_headers(Stream &strm, const Headers &headers); - -} // namespace detail - -class Server { -public: - using Handler = std::function; - - using ExceptionHandler = - std::function; - - enum class HandlerResponse { - Handled, - Unhandled, - }; - using HandlerWithResponse = - std::function; - - using HandlerWithContentReader = std::function; - - using Expect100ContinueHandler = - std::function; - - Server(); - - virtual ~Server(); - - virtual bool is_valid() const; - - Server &Get(const std::string &pattern, Handler handler); - Server &Post(const std::string &pattern, Handler handler); - Server &Post(const std::string &pattern, HandlerWithContentReader handler); - Server &Put(const std::string &pattern, Handler handler); - Server &Put(const std::string &pattern, HandlerWithContentReader handler); - Server &Patch(const std::string &pattern, Handler handler); - Server &Patch(const std::string &pattern, HandlerWithContentReader handler); - Server &Delete(const std::string &pattern, Handler handler); - Server &Delete(const std::string &pattern, HandlerWithContentReader handler); - Server &Options(const std::string &pattern, Handler handler); - - bool set_base_dir(const std::string &dir, - const std::string &mount_point = std::string()); - bool set_mount_point(const std::string &mount_point, const std::string &dir, - Headers headers = Headers()); - bool remove_mount_point(const std::string &mount_point); - Server &set_file_extension_and_mimetype_mapping(const std::string &ext, - const std::string &mime); - Server &set_default_file_mimetype(const std::string &mime); - Server &set_file_request_handler(Handler handler); - - Server &set_error_handler(HandlerWithResponse handler); - Server &set_error_handler(Handler handler); - Server &set_exception_handler(ExceptionHandler handler); - Server &set_pre_routing_handler(HandlerWithResponse handler); - Server &set_post_routing_handler(Handler handler); - - Server &set_expect_100_continue_handler(Expect100ContinueHandler handler); - Server &set_logger(Logger logger); - - Server &set_address_family(int family); - Server &set_tcp_nodelay(bool on); - Server &set_socket_options(SocketOptions socket_options); - - Server &set_default_headers(Headers headers); - Server & - set_header_writer(std::function const &writer); - - Server &set_keep_alive_max_count(size_t count); - Server &set_keep_alive_timeout(time_t sec); - - Server &set_read_timeout(time_t sec, time_t usec = 0); - template - Server &set_read_timeout(const std::chrono::duration &duration); - - Server &set_write_timeout(time_t sec, time_t usec = 0); - template - Server &set_write_timeout(const std::chrono::duration &duration); - - Server &set_idle_interval(time_t sec, time_t usec = 0); - template - Server &set_idle_interval(const std::chrono::duration &duration); - - Server &set_payload_max_length(size_t length); - - bool bind_to_port(const std::string &host, int port, int socket_flags = 0); - int bind_to_any_port(const std::string &host, int socket_flags = 0); - bool listen_after_bind(); - - bool listen(const std::string &host, int port, int socket_flags = 0); - - bool is_running() const; - void wait_until_ready() const; - void stop(); - - std::function new_task_queue; - -protected: - bool process_request(Stream &strm, bool close_connection, - bool &connection_closed, - const std::function &setup_request); - - std::atomic svr_sock_{INVALID_SOCKET}; - size_t keep_alive_max_count_ = CPPHTTPLIB_KEEPALIVE_MAX_COUNT; - time_t keep_alive_timeout_sec_ = CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND; - time_t read_timeout_sec_ = CPPHTTPLIB_READ_TIMEOUT_SECOND; - time_t read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND; - time_t write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND; - time_t write_timeout_usec_ = CPPHTTPLIB_WRITE_TIMEOUT_USECOND; - time_t idle_interval_sec_ = CPPHTTPLIB_IDLE_INTERVAL_SECOND; - time_t idle_interval_usec_ = CPPHTTPLIB_IDLE_INTERVAL_USECOND; - size_t payload_max_length_ = CPPHTTPLIB_PAYLOAD_MAX_LENGTH; - -private: - using Handlers = - std::vector, Handler>>; - using HandlersForContentReader = - std::vector, - HandlerWithContentReader>>; - - static std::unique_ptr - make_matcher(const std::string &pattern); - - socket_t create_server_socket(const std::string &host, int port, - int socket_flags, - SocketOptions socket_options) const; - int bind_internal(const std::string &host, int port, int socket_flags); - bool listen_internal(); - - bool routing(Request &req, Response &res, Stream &strm); - bool handle_file_request(const Request &req, Response &res, - bool head = false); - bool dispatch_request(Request &req, Response &res, - const Handlers &handlers) const; - bool dispatch_request_for_content_reader( - Request &req, Response &res, ContentReader content_reader, - const HandlersForContentReader &handlers) const; - - bool parse_request_line(const char *s, Request &req) const; - void apply_ranges(const Request &req, Response &res, - std::string &content_type, std::string &boundary) const; - bool write_response(Stream &strm, bool close_connection, const Request &req, - Response &res); - bool write_response_with_content(Stream &strm, bool close_connection, - const Request &req, Response &res); - bool write_response_core(Stream &strm, bool close_connection, - const Request &req, Response &res, - bool need_apply_ranges); - bool write_content_with_provider(Stream &strm, const Request &req, - Response &res, const std::string &boundary, - const std::string &content_type); - bool read_content(Stream &strm, Request &req, Response &res); - bool - read_content_with_content_receiver(Stream &strm, Request &req, Response &res, - ContentReceiver receiver, - MultipartContentHeader multipart_header, - ContentReceiver multipart_receiver); - bool read_content_core(Stream &strm, Request &req, Response &res, - ContentReceiver receiver, - MultipartContentHeader multipart_header, - ContentReceiver multipart_receiver) const; - - virtual bool process_and_close_socket(socket_t sock); - - std::atomic is_running_{false}; - std::atomic done_{false}; - - struct MountPointEntry { - std::string mount_point; - std::string base_dir; - Headers headers; - }; - std::vector base_dirs_; - std::map file_extension_and_mimetype_map_; - std::string default_file_mimetype_ = "application/octet-stream"; - Handler file_request_handler_; - - Handlers get_handlers_; - Handlers post_handlers_; - HandlersForContentReader post_handlers_for_content_reader_; - Handlers put_handlers_; - HandlersForContentReader put_handlers_for_content_reader_; - Handlers patch_handlers_; - HandlersForContentReader patch_handlers_for_content_reader_; - Handlers delete_handlers_; - HandlersForContentReader delete_handlers_for_content_reader_; - Handlers options_handlers_; - - HandlerWithResponse error_handler_; - ExceptionHandler exception_handler_; - HandlerWithResponse pre_routing_handler_; - Handler post_routing_handler_; - Expect100ContinueHandler expect_100_continue_handler_; - - Logger logger_; - - int address_family_ = AF_UNSPEC; - bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY; - SocketOptions socket_options_ = default_socket_options; - - Headers default_headers_; - std::function header_writer_ = - detail::write_headers; -}; - -enum class Error { - Success = 0, - Unknown, - Connection, - BindIPAddress, - Read, - Write, - ExceedRedirectCount, - Canceled, - SSLConnection, - SSLLoadingCerts, - SSLServerVerification, - UnsupportedMultipartBoundaryChars, - Compression, - ConnectionTimeout, - ProxyConnection, - - // For internal use only - SSLPeerCouldBeClosed_, -}; - -std::string to_string(Error error); - -std::ostream &operator<<(std::ostream &os, const Error &obj); - -class Result { -public: - Result() = default; - Result(std::unique_ptr &&res, Error err, - Headers &&request_headers = Headers{}) - : res_(std::move(res)), err_(err), - request_headers_(std::move(request_headers)) {} - // Response - operator bool() const { return res_ != nullptr; } - bool operator==(std::nullptr_t) const { return res_ == nullptr; } - bool operator!=(std::nullptr_t) const { return res_ != nullptr; } - const Response &value() const { return *res_; } - Response &value() { return *res_; } - const Response &operator*() const { return *res_; } - Response &operator*() { return *res_; } - const Response *operator->() const { return res_.get(); } - Response *operator->() { return res_.get(); } - - // Error - Error error() const { return err_; } - - // Request Headers - bool has_request_header(const std::string &key) const; - std::string get_request_header_value(const std::string &key, - size_t id = 0) const; - uint64_t get_request_header_value_u64(const std::string &key, - size_t id = 0) const; - size_t get_request_header_value_count(const std::string &key) const; - -private: - std::unique_ptr res_; - Error err_ = Error::Unknown; - Headers request_headers_; -}; - -class ClientImpl { -public: - explicit ClientImpl(const std::string &host); - - explicit ClientImpl(const std::string &host, int port); - - explicit ClientImpl(const std::string &host, int port, - const std::string &client_cert_path, - const std::string &client_key_path); - - virtual ~ClientImpl(); - - virtual bool is_valid() const; - - Result Get(const std::string &path); - Result Get(const std::string &path, const Headers &headers); - Result Get(const std::string &path, Progress progress); - Result Get(const std::string &path, const Headers &headers, - Progress progress); - Result Get(const std::string &path, ContentReceiver content_receiver); - Result Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver); - Result Get(const std::string &path, ContentReceiver content_receiver, - Progress progress); - Result Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver, Progress progress); - Result Get(const std::string &path, ResponseHandler response_handler, - ContentReceiver content_receiver); - Result Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver); - Result Get(const std::string &path, ResponseHandler response_handler, - ContentReceiver content_receiver, Progress progress); - Result Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, ContentReceiver content_receiver, - Progress progress); - - Result Get(const std::string &path, const Params ¶ms, - const Headers &headers, Progress progress = nullptr); - Result Get(const std::string &path, const Params ¶ms, - const Headers &headers, ContentReceiver content_receiver, - Progress progress = nullptr); - Result Get(const std::string &path, const Params ¶ms, - const Headers &headers, ResponseHandler response_handler, - ContentReceiver content_receiver, Progress progress = nullptr); - - Result Head(const std::string &path); - Result Head(const std::string &path, const Headers &headers); - - Result Post(const std::string &path); - Result Post(const std::string &path, const Headers &headers); - Result Post(const std::string &path, const char *body, size_t content_length, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, const char *body, - size_t content_length, const std::string &content_type); - Result Post(const std::string &path, const std::string &body, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - Result Post(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type); - Result Post(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, - size_t content_length, ContentProvider content_provider, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Post(const std::string &path, const Params ¶ms); - Result Post(const std::string &path, const Headers &headers, - const Params ¶ms); - Result Post(const std::string &path, const MultipartFormDataItems &items); - Result Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items); - Result Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, const std::string &boundary); - Result Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items); - - Result Put(const std::string &path); - Result Put(const std::string &path, const char *body, size_t content_length, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, const char *body, - size_t content_length, const std::string &content_type); - Result Put(const std::string &path, const std::string &body, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - Result Put(const std::string &path, size_t content_length, - ContentProvider content_provider, const std::string &content_type); - Result Put(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, - size_t content_length, ContentProvider content_provider, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Put(const std::string &path, const Params ¶ms); - Result Put(const std::string &path, const Headers &headers, - const Params ¶ms); - Result Put(const std::string &path, const MultipartFormDataItems &items); - Result Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items); - Result Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, const std::string &boundary); - Result Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items); - - Result Patch(const std::string &path); - Result Patch(const std::string &path, const char *body, size_t content_length, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type); - Result Patch(const std::string &path, const std::string &body, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - Result Patch(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type); - Result Patch(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - size_t content_length, ContentProvider content_provider, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - - Result Delete(const std::string &path); - Result Delete(const std::string &path, const Headers &headers); - Result Delete(const std::string &path, const char *body, - size_t content_length, const std::string &content_type); - Result Delete(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type); - Result Delete(const std::string &path, const std::string &body, - const std::string &content_type); - Result Delete(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - - Result Options(const std::string &path); - Result Options(const std::string &path, const Headers &headers); - - bool send(Request &req, Response &res, Error &error); - Result send(const Request &req); - - void stop(); - - std::string host() const; - int port() const; - - size_t is_socket_open() const; - socket_t socket() const; - - void set_hostname_addr_map(std::map addr_map); - - void set_default_headers(Headers headers); - - void - set_header_writer(std::function const &writer); - - void set_address_family(int family); - void set_tcp_nodelay(bool on); - void set_socket_options(SocketOptions socket_options); - - void set_connection_timeout(time_t sec, time_t usec = 0); - template - void - set_connection_timeout(const std::chrono::duration &duration); - - void set_read_timeout(time_t sec, time_t usec = 0); - template - void set_read_timeout(const std::chrono::duration &duration); - - void set_write_timeout(time_t sec, time_t usec = 0); - template - void set_write_timeout(const std::chrono::duration &duration); - - void set_basic_auth(const std::string &username, const std::string &password); - void set_bearer_token_auth(const std::string &token); -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void set_digest_auth(const std::string &username, - const std::string &password); -#endif - - void set_keep_alive(bool on); - void set_follow_location(bool on); - - void set_url_encode(bool on); - - void set_compress(bool on); - - void set_decompress(bool on); - - void set_interface(const std::string &intf); - - void set_proxy(const std::string &host, int port); - void set_proxy_basic_auth(const std::string &username, - const std::string &password); - void set_proxy_bearer_token_auth(const std::string &token); -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void set_proxy_digest_auth(const std::string &username, - const std::string &password); -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void set_ca_cert_path(const std::string &ca_cert_file_path, - const std::string &ca_cert_dir_path = std::string()); - void set_ca_cert_store(X509_STORE *ca_cert_store); - X509_STORE *create_ca_cert_store(const char *ca_cert, std::size_t size) const; -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void enable_server_certificate_verification(bool enabled); -#endif - - void set_logger(Logger logger); - -protected: - struct Socket { - socket_t sock = INVALID_SOCKET; -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - SSL *ssl = nullptr; -#endif - - bool is_open() const { return sock != INVALID_SOCKET; } - }; - - virtual bool create_and_connect_socket(Socket &socket, Error &error); - - // All of: - // shutdown_ssl - // shutdown_socket - // close_socket - // should ONLY be called when socket_mutex_ is locked. - // Also, shutdown_ssl and close_socket should also NOT be called concurrently - // with a DIFFERENT thread sending requests using that socket. - virtual void shutdown_ssl(Socket &socket, bool shutdown_gracefully); - void shutdown_socket(Socket &socket) const; - void close_socket(Socket &socket); - - bool process_request(Stream &strm, Request &req, Response &res, - bool close_connection, Error &error); - - bool write_content_with_provider(Stream &strm, const Request &req, - Error &error) const; - - void copy_settings(const ClientImpl &rhs); - - // Socket endpoint information - const std::string host_; - const int port_; - const std::string host_and_port_; - - // Current open socket - Socket socket_; - mutable std::mutex socket_mutex_; - std::recursive_mutex request_mutex_; - - // These are all protected under socket_mutex - size_t socket_requests_in_flight_ = 0; - std::thread::id socket_requests_are_from_thread_ = std::thread::id(); - bool socket_should_be_closed_when_request_is_done_ = false; - - // Hostname-IP map - std::map addr_map_; - - // Default headers - Headers default_headers_; - - // Header writer - std::function header_writer_ = - detail::write_headers; - - // Settings - std::string client_cert_path_; - std::string client_key_path_; - - time_t connection_timeout_sec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_SECOND; - time_t connection_timeout_usec_ = CPPHTTPLIB_CONNECTION_TIMEOUT_USECOND; - time_t read_timeout_sec_ = CPPHTTPLIB_READ_TIMEOUT_SECOND; - time_t read_timeout_usec_ = CPPHTTPLIB_READ_TIMEOUT_USECOND; - time_t write_timeout_sec_ = CPPHTTPLIB_WRITE_TIMEOUT_SECOND; - time_t write_timeout_usec_ = CPPHTTPLIB_WRITE_TIMEOUT_USECOND; - - std::string basic_auth_username_; - std::string basic_auth_password_; - std::string bearer_token_auth_token_; -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - std::string digest_auth_username_; - std::string digest_auth_password_; -#endif - - bool keep_alive_ = false; - bool follow_location_ = false; - - bool url_encode_ = true; - - int address_family_ = AF_UNSPEC; - bool tcp_nodelay_ = CPPHTTPLIB_TCP_NODELAY; - SocketOptions socket_options_ = nullptr; - - bool compress_ = false; - bool decompress_ = true; - - std::string interface_; - - std::string proxy_host_; - int proxy_port_ = -1; - - std::string proxy_basic_auth_username_; - std::string proxy_basic_auth_password_; - std::string proxy_bearer_token_auth_token_; -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - std::string proxy_digest_auth_username_; - std::string proxy_digest_auth_password_; -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - std::string ca_cert_file_path_; - std::string ca_cert_dir_path_; - - X509_STORE *ca_cert_store_ = nullptr; -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - bool server_certificate_verification_ = true; -#endif - - Logger logger_; - -private: - bool send_(Request &req, Response &res, Error &error); - Result send_(Request &&req); - - socket_t create_client_socket(Error &error) const; - bool read_response_line(Stream &strm, const Request &req, - Response &res) const; - bool write_request(Stream &strm, Request &req, bool close_connection, - Error &error); - bool redirect(Request &req, Response &res, Error &error); - bool handle_request(Stream &strm, Request &req, Response &res, - bool close_connection, Error &error); - std::unique_ptr send_with_content_provider( - Request &req, const char *body, size_t content_length, - ContentProvider content_provider, - ContentProviderWithoutLength content_provider_without_length, - const std::string &content_type, Error &error); - Result send_with_content_provider( - const std::string &method, const std::string &path, - const Headers &headers, const char *body, size_t content_length, - ContentProvider content_provider, - ContentProviderWithoutLength content_provider_without_length, - const std::string &content_type); - ContentProviderWithoutLength get_multipart_content_provider( - const std::string &boundary, const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items) const; - - std::string adjust_host_string(const std::string &host) const; - - virtual bool process_socket(const Socket &socket, - std::function callback); - virtual bool is_ssl() const; -}; - -class Client { -public: - // Universal interface - explicit Client(const std::string &scheme_host_port); - - explicit Client(const std::string &scheme_host_port, - const std::string &client_cert_path, - const std::string &client_key_path); - - // HTTP only interface - explicit Client(const std::string &host, int port); - - explicit Client(const std::string &host, int port, - const std::string &client_cert_path, - const std::string &client_key_path); - - Client(Client &&) = default; - - ~Client(); - - bool is_valid() const; - - Result Get(const std::string &path); - Result Get(const std::string &path, const Headers &headers); - Result Get(const std::string &path, Progress progress); - Result Get(const std::string &path, const Headers &headers, - Progress progress); - Result Get(const std::string &path, ContentReceiver content_receiver); - Result Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver); - Result Get(const std::string &path, ContentReceiver content_receiver, - Progress progress); - Result Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver, Progress progress); - Result Get(const std::string &path, ResponseHandler response_handler, - ContentReceiver content_receiver); - Result Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver); - Result Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, ContentReceiver content_receiver, - Progress progress); - Result Get(const std::string &path, ResponseHandler response_handler, - ContentReceiver content_receiver, Progress progress); - - Result Get(const std::string &path, const Params ¶ms, - const Headers &headers, Progress progress = nullptr); - Result Get(const std::string &path, const Params ¶ms, - const Headers &headers, ContentReceiver content_receiver, - Progress progress = nullptr); - Result Get(const std::string &path, const Params ¶ms, - const Headers &headers, ResponseHandler response_handler, - ContentReceiver content_receiver, Progress progress = nullptr); - - Result Head(const std::string &path); - Result Head(const std::string &path, const Headers &headers); - - Result Post(const std::string &path); - Result Post(const std::string &path, const Headers &headers); - Result Post(const std::string &path, const char *body, size_t content_length, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, const char *body, - size_t content_length, const std::string &content_type); - Result Post(const std::string &path, const std::string &body, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - Result Post(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type); - Result Post(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, - size_t content_length, ContentProvider content_provider, - const std::string &content_type); - Result Post(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Post(const std::string &path, const Params ¶ms); - Result Post(const std::string &path, const Headers &headers, - const Params ¶ms); - Result Post(const std::string &path, const MultipartFormDataItems &items); - Result Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items); - Result Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, const std::string &boundary); - Result Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items); - - Result Put(const std::string &path); - Result Put(const std::string &path, const char *body, size_t content_length, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, const char *body, - size_t content_length, const std::string &content_type); - Result Put(const std::string &path, const std::string &body, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - Result Put(const std::string &path, size_t content_length, - ContentProvider content_provider, const std::string &content_type); - Result Put(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, - size_t content_length, ContentProvider content_provider, - const std::string &content_type); - Result Put(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Put(const std::string &path, const Params ¶ms); - Result Put(const std::string &path, const Headers &headers, - const Params ¶ms); - Result Put(const std::string &path, const MultipartFormDataItems &items); - Result Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items); - Result Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, const std::string &boundary); - Result Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items); - - Result Patch(const std::string &path); - Result Patch(const std::string &path, const char *body, size_t content_length, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type); - Result Patch(const std::string &path, const std::string &body, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - Result Patch(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type); - Result Patch(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - size_t content_length, ContentProvider content_provider, - const std::string &content_type); - Result Patch(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type); - - Result Delete(const std::string &path); - Result Delete(const std::string &path, const Headers &headers); - Result Delete(const std::string &path, const char *body, - size_t content_length, const std::string &content_type); - Result Delete(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type); - Result Delete(const std::string &path, const std::string &body, - const std::string &content_type); - Result Delete(const std::string &path, const Headers &headers, - const std::string &body, const std::string &content_type); - - Result Options(const std::string &path); - Result Options(const std::string &path, const Headers &headers); - - bool send(Request &req, Response &res, Error &error); - Result send(const Request &req); - - void stop(); - - std::string host() const; - int port() const; - - size_t is_socket_open() const; - socket_t socket() const; - - void set_hostname_addr_map(std::map addr_map); - - void set_default_headers(Headers headers); - - void - set_header_writer(std::function const &writer); - - void set_address_family(int family); - void set_tcp_nodelay(bool on); - void set_socket_options(SocketOptions socket_options); - - void set_connection_timeout(time_t sec, time_t usec = 0); - template - void - set_connection_timeout(const std::chrono::duration &duration); - - void set_read_timeout(time_t sec, time_t usec = 0); - template - void set_read_timeout(const std::chrono::duration &duration); - - void set_write_timeout(time_t sec, time_t usec = 0); - template - void set_write_timeout(const std::chrono::duration &duration); - - void set_basic_auth(const std::string &username, const std::string &password); - void set_bearer_token_auth(const std::string &token); -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void set_digest_auth(const std::string &username, - const std::string &password); -#endif - - void set_keep_alive(bool on); - void set_follow_location(bool on); - - void set_url_encode(bool on); - - void set_compress(bool on); - - void set_decompress(bool on); - - void set_interface(const std::string &intf); - - void set_proxy(const std::string &host, int port); - void set_proxy_basic_auth(const std::string &username, - const std::string &password); - void set_proxy_bearer_token_auth(const std::string &token); -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void set_proxy_digest_auth(const std::string &username, - const std::string &password); -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void enable_server_certificate_verification(bool enabled); -#endif - - void set_logger(Logger logger); - - // SSL -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - void set_ca_cert_path(const std::string &ca_cert_file_path, - const std::string &ca_cert_dir_path = std::string()); - - void set_ca_cert_store(X509_STORE *ca_cert_store); - void load_ca_cert_store(const char *ca_cert, std::size_t size); - - long get_openssl_verify_result() const; - - SSL_CTX *ssl_context() const; -#endif - -private: - std::unique_ptr cli_; - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - bool is_ssl_ = false; -#endif -}; - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -class SSLServer : public Server { -public: - SSLServer(const char *cert_path, const char *private_key_path, - const char *client_ca_cert_file_path = nullptr, - const char *client_ca_cert_dir_path = nullptr, - const char *private_key_password = nullptr); - - SSLServer(X509 *cert, EVP_PKEY *private_key, - X509_STORE *client_ca_cert_store = nullptr); - - SSLServer( - const std::function &setup_ssl_ctx_callback); - - ~SSLServer() override; - - bool is_valid() const override; - - SSL_CTX *ssl_context() const; - -private: - bool process_and_close_socket(socket_t sock) override; - - SSL_CTX *ctx_; - std::mutex ctx_mutex_; -}; - -class SSLClient : public ClientImpl { -public: - explicit SSLClient(const std::string &host); - - explicit SSLClient(const std::string &host, int port); - - explicit SSLClient(const std::string &host, int port, - const std::string &client_cert_path, - const std::string &client_key_path); - - explicit SSLClient(const std::string &host, int port, X509 *client_cert, - EVP_PKEY *client_key); - - ~SSLClient() override; - - bool is_valid() const override; - - void set_ca_cert_store(X509_STORE *ca_cert_store); - void load_ca_cert_store(const char *ca_cert, std::size_t size); - - long get_openssl_verify_result() const; - - SSL_CTX *ssl_context() const; - -private: - bool create_and_connect_socket(Socket &socket, Error &error) override; - void shutdown_ssl(Socket &socket, bool shutdown_gracefully) override; - void shutdown_ssl_impl(Socket &socket, bool shutdown_gracefully); - - bool process_socket(const Socket &socket, - std::function callback) override; - bool is_ssl() const override; - - bool connect_with_proxy(Socket &sock, Response &res, bool &success, - Error &error); - bool initialize_ssl(Socket &socket, Error &error); - - bool load_certs(); - - bool verify_host(X509 *server_cert) const; - bool verify_host_with_subject_alt_name(X509 *server_cert) const; - bool verify_host_with_common_name(X509 *server_cert) const; - bool check_host_name(const char *pattern, size_t pattern_len) const; - - SSL_CTX *ctx_; - std::mutex ctx_mutex_; - std::once_flag initialize_cert_; - - std::vector host_components_; - - long verify_result_ = 0; - - friend class ClientImpl; -}; -#endif - -/* - * Implementation of template methods. - */ - -namespace detail { - -template -inline void duration_to_sec_and_usec(const T &duration, U callback) { - auto sec = std::chrono::duration_cast(duration).count(); - auto usec = std::chrono::duration_cast( - duration - std::chrono::seconds(sec)) - .count(); - callback(static_cast(sec), static_cast(usec)); -} - -inline uint64_t get_header_value_u64(const Headers &headers, - const std::string &key, size_t id, - uint64_t def) { - auto rng = headers.equal_range(key); - auto it = rng.first; - std::advance(it, static_cast(id)); - if (it != rng.second) { - return std::strtoull(it->second.data(), nullptr, 10); - } - return def; -} - -} // namespace detail - -inline uint64_t Request::get_header_value_u64(const std::string &key, - size_t id) const { - return detail::get_header_value_u64(headers, key, id, 0); -} - -inline uint64_t Response::get_header_value_u64(const std::string &key, - size_t id) const { - return detail::get_header_value_u64(headers, key, id, 0); -} - -template -inline ssize_t Stream::write_format(const char *fmt, const Args &...args) { - const auto bufsiz = 2048; - std::array buf{}; - - auto sn = snprintf(buf.data(), buf.size() - 1, fmt, args...); - if (sn <= 0) { return sn; } - - auto n = static_cast(sn); - - if (n >= buf.size() - 1) { - std::vector glowable_buf(buf.size()); - - while (n >= glowable_buf.size() - 1) { - glowable_buf.resize(glowable_buf.size() * 2); - n = static_cast( - snprintf(&glowable_buf[0], glowable_buf.size() - 1, fmt, args...)); - } - return write(&glowable_buf[0], n); - } else { - return write(buf.data(), n); - } -} - -inline void default_socket_options(socket_t sock) { - int yes = 1; -#ifdef _WIN32 - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - reinterpret_cast(&yes), sizeof(yes)); - setsockopt(sock, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, - reinterpret_cast(&yes), sizeof(yes)); -#else -#ifdef SO_REUSEPORT - setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, - reinterpret_cast(&yes), sizeof(yes)); -#else - setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, - reinterpret_cast(&yes), sizeof(yes)); -#endif -#endif -} - -inline const char *status_message(int status) { - switch (status) { - case StatusCode::Continue_100: return "Continue"; - case StatusCode::SwitchingProtocol_101: return "Switching Protocol"; - case StatusCode::Processing_102: return "Processing"; - case StatusCode::EarlyHints_103: return "Early Hints"; - case StatusCode::OK_200: return "OK"; - case StatusCode::Created_201: return "Created"; - case StatusCode::Accepted_202: return "Accepted"; - case StatusCode::NonAuthoritativeInformation_203: - return "Non-Authoritative Information"; - case StatusCode::NoContent_204: return "No Content"; - case StatusCode::ResetContent_205: return "Reset Content"; - case StatusCode::PartialContent_206: return "Partial Content"; - case StatusCode::MultiStatus_207: return "Multi-Status"; - case StatusCode::AlreadyReported_208: return "Already Reported"; - case StatusCode::IMUsed_226: return "IM Used"; - case StatusCode::MultipleChoices_300: return "Multiple Choices"; - case StatusCode::MovedPermanently_301: return "Moved Permanently"; - case StatusCode::Found_302: return "Found"; - case StatusCode::SeeOther_303: return "See Other"; - case StatusCode::NotModified_304: return "Not Modified"; - case StatusCode::UseProxy_305: return "Use Proxy"; - case StatusCode::unused_306: return "unused"; - case StatusCode::TemporaryRedirect_307: return "Temporary Redirect"; - case StatusCode::PermanentRedirect_308: return "Permanent Redirect"; - case StatusCode::BadRequest_400: return "Bad Request"; - case StatusCode::Unauthorized_401: return "Unauthorized"; - case StatusCode::PaymentRequired_402: return "Payment Required"; - case StatusCode::Forbidden_403: return "Forbidden"; - case StatusCode::NotFound_404: return "Not Found"; - case StatusCode::MethodNotAllowed_405: return "Method Not Allowed"; - case StatusCode::NotAcceptable_406: return "Not Acceptable"; - case StatusCode::ProxyAuthenticationRequired_407: - return "Proxy Authentication Required"; - case StatusCode::RequestTimeout_408: return "Request Timeout"; - case StatusCode::Conflict_409: return "Conflict"; - case StatusCode::Gone_410: return "Gone"; - case StatusCode::LengthRequired_411: return "Length Required"; - case StatusCode::PreconditionFailed_412: return "Precondition Failed"; - case StatusCode::PayloadTooLarge_413: return "Payload Too Large"; - case StatusCode::UriTooLong_414: return "URI Too Long"; - case StatusCode::UnsupportedMediaType_415: return "Unsupported Media Type"; - case StatusCode::RangeNotSatisfiable_416: return "Range Not Satisfiable"; - case StatusCode::ExpectationFailed_417: return "Expectation Failed"; - case StatusCode::ImATeapot_418: return "I'm a teapot"; - case StatusCode::MisdirectedRequest_421: return "Misdirected Request"; - case StatusCode::UnprocessableContent_422: return "Unprocessable Content"; - case StatusCode::Locked_423: return "Locked"; - case StatusCode::FailedDependency_424: return "Failed Dependency"; - case StatusCode::TooEarly_425: return "Too Early"; - case StatusCode::UpgradeRequired_426: return "Upgrade Required"; - case StatusCode::PreconditionRequired_428: return "Precondition Required"; - case StatusCode::TooManyRequests_429: return "Too Many Requests"; - case StatusCode::RequestHeaderFieldsTooLarge_431: - return "Request Header Fields Too Large"; - case StatusCode::UnavailableForLegalReasons_451: - return "Unavailable For Legal Reasons"; - case StatusCode::NotImplemented_501: return "Not Implemented"; - case StatusCode::BadGateway_502: return "Bad Gateway"; - case StatusCode::ServiceUnavailable_503: return "Service Unavailable"; - case StatusCode::GatewayTimeout_504: return "Gateway Timeout"; - case StatusCode::HttpVersionNotSupported_505: - return "HTTP Version Not Supported"; - case StatusCode::VariantAlsoNegotiates_506: return "Variant Also Negotiates"; - case StatusCode::InsufficientStorage_507: return "Insufficient Storage"; - case StatusCode::LoopDetected_508: return "Loop Detected"; - case StatusCode::NotExtended_510: return "Not Extended"; - case StatusCode::NetworkAuthenticationRequired_511: - return "Network Authentication Required"; - - default: - case StatusCode::InternalServerError_500: return "Internal Server Error"; - } -} - -inline std::string get_bearer_token_auth(const Request &req) { - if (req.has_header("Authorization")) { - static std::string BearerHeaderPrefix = "Bearer "; - return req.get_header_value("Authorization") - .substr(BearerHeaderPrefix.length()); - } - return ""; -} - -template -inline Server & -Server::set_read_timeout(const std::chrono::duration &duration) { - detail::duration_to_sec_and_usec( - duration, [&](time_t sec, time_t usec) { set_read_timeout(sec, usec); }); - return *this; -} - -template -inline Server & -Server::set_write_timeout(const std::chrono::duration &duration) { - detail::duration_to_sec_and_usec( - duration, [&](time_t sec, time_t usec) { set_write_timeout(sec, usec); }); - return *this; -} - -template -inline Server & -Server::set_idle_interval(const std::chrono::duration &duration) { - detail::duration_to_sec_and_usec( - duration, [&](time_t sec, time_t usec) { set_idle_interval(sec, usec); }); - return *this; -} - -inline std::string to_string(const Error error) { - switch (error) { - case Error::Success: return "Success (no error)"; - case Error::Connection: return "Could not establish connection"; - case Error::BindIPAddress: return "Failed to bind IP address"; - case Error::Read: return "Failed to read connection"; - case Error::Write: return "Failed to write connection"; - case Error::ExceedRedirectCount: return "Maximum redirect count exceeded"; - case Error::Canceled: return "Connection handling canceled"; - case Error::SSLConnection: return "SSL connection failed"; - case Error::SSLLoadingCerts: return "SSL certificate loading failed"; - case Error::SSLServerVerification: return "SSL server verification failed"; - case Error::UnsupportedMultipartBoundaryChars: - return "Unsupported HTTP multipart boundary characters"; - case Error::Compression: return "Compression failed"; - case Error::ConnectionTimeout: return "Connection timed out"; - case Error::ProxyConnection: return "Proxy connection failed"; - case Error::Unknown: return "Unknown"; - default: break; - } - - return "Invalid"; -} - -inline std::ostream &operator<<(std::ostream &os, const Error &obj) { - os << to_string(obj); - os << " (" << static_cast::type>(obj) << ')'; - return os; -} - -inline uint64_t Result::get_request_header_value_u64(const std::string &key, - size_t id) const { - return detail::get_header_value_u64(request_headers_, key, id, 0); -} - -template -inline void ClientImpl::set_connection_timeout( - const std::chrono::duration &duration) { - detail::duration_to_sec_and_usec(duration, [&](time_t sec, time_t usec) { - set_connection_timeout(sec, usec); - }); -} - -template -inline void ClientImpl::set_read_timeout( - const std::chrono::duration &duration) { - detail::duration_to_sec_and_usec( - duration, [&](time_t sec, time_t usec) { set_read_timeout(sec, usec); }); -} - -template -inline void ClientImpl::set_write_timeout( - const std::chrono::duration &duration) { - detail::duration_to_sec_and_usec( - duration, [&](time_t sec, time_t usec) { set_write_timeout(sec, usec); }); -} - -template -inline void Client::set_connection_timeout( - const std::chrono::duration &duration) { - cli_->set_connection_timeout(duration); -} - -template -inline void -Client::set_read_timeout(const std::chrono::duration &duration) { - cli_->set_read_timeout(duration); -} - -template -inline void -Client::set_write_timeout(const std::chrono::duration &duration) { - cli_->set_write_timeout(duration); -} - -/* - * Forward declarations and types that will be part of the .h file if split into - * .h + .cc. - */ - -std::string hosted_at(const std::string &hostname); - -void hosted_at(const std::string &hostname, std::vector &addrs); - -std::string append_query_params(const std::string &path, const Params ¶ms); - -std::pair make_range_header(Ranges ranges); - -std::pair -make_basic_authentication_header(const std::string &username, - const std::string &password, - bool is_proxy = false); - -namespace detail { - -std::string encode_query_param(const std::string &value); - -std::string decode_url(const std::string &s, bool convert_plus_to_space); - -void read_file(const std::string &path, std::string &out); - -std::string trim_copy(const std::string &s); - -void split(const char *b, const char *e, char d, - std::function fn); - -void split(const char *b, const char *e, char d, size_t m, - std::function fn); - -bool process_client_socket(socket_t sock, time_t read_timeout_sec, - time_t read_timeout_usec, time_t write_timeout_sec, - time_t write_timeout_usec, - std::function callback); - -socket_t create_client_socket( - const std::string &host, const std::string &ip, int port, - int address_family, bool tcp_nodelay, SocketOptions socket_options, - time_t connection_timeout_sec, time_t connection_timeout_usec, - time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, - time_t write_timeout_usec, const std::string &intf, Error &error); - -const char *get_header_value(const Headers &headers, const std::string &key, - size_t id = 0, const char *def = nullptr); - -std::string params_to_query_str(const Params ¶ms); - -void parse_query_text(const std::string &s, Params ¶ms); - -bool parse_multipart_boundary(const std::string &content_type, - std::string &boundary); - -bool parse_range_header(const std::string &s, Ranges &ranges); - -int close_socket(socket_t sock); - -ssize_t send_socket(socket_t sock, const void *ptr, size_t size, int flags); - -ssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags); - -enum class EncodingType { None = 0, Gzip, Brotli }; - -EncodingType encoding_type(const Request &req, const Response &res); - -class BufferStream : public Stream { -public: - BufferStream() = default; - ~BufferStream() override = default; - - bool is_readable() const override; - bool is_writable() const override; - ssize_t read(char *ptr, size_t size) override; - ssize_t write(const char *ptr, size_t size) override; - void get_remote_ip_and_port(std::string &ip, int &port) const override; - void get_local_ip_and_port(std::string &ip, int &port) const override; - socket_t socket() const override; - - const std::string &get_buffer() const; - -private: - std::string buffer; - size_t position = 0; -}; - -class compressor { -public: - virtual ~compressor() = default; - - typedef std::function Callback; - virtual bool compress(const char *data, size_t data_length, bool last, - Callback callback) = 0; -}; - -class decompressor { -public: - virtual ~decompressor() = default; - - virtual bool is_valid() const = 0; - - typedef std::function Callback; - virtual bool decompress(const char *data, size_t data_length, - Callback callback) = 0; -}; - -class nocompressor : public compressor { -public: - ~nocompressor() override = default; - - bool compress(const char *data, size_t data_length, bool /*last*/, - Callback callback) override; -}; - -#ifdef CPPHTTPLIB_ZLIB_SUPPORT -class gzip_compressor : public compressor { -public: - gzip_compressor(); - ~gzip_compressor() override; - - bool compress(const char *data, size_t data_length, bool last, - Callback callback) override; - -private: - bool is_valid_ = false; - z_stream strm_; -}; - -class gzip_decompressor : public decompressor { -public: - gzip_decompressor(); - ~gzip_decompressor() override; - - bool is_valid() const override; - - bool decompress(const char *data, size_t data_length, - Callback callback) override; - -private: - bool is_valid_ = false; - z_stream strm_; -}; -#endif - -#ifdef CPPHTTPLIB_BROTLI_SUPPORT -class brotli_compressor : public compressor { -public: - brotli_compressor(); - ~brotli_compressor(); - - bool compress(const char *data, size_t data_length, bool last, - Callback callback) override; - -private: - BrotliEncoderState *state_ = nullptr; -}; - -class brotli_decompressor : public decompressor { -public: - brotli_decompressor(); - ~brotli_decompressor(); - - bool is_valid() const override; - - bool decompress(const char *data, size_t data_length, - Callback callback) override; - -private: - BrotliDecoderResult decoder_r; - BrotliDecoderState *decoder_s = nullptr; -}; -#endif - -// NOTE: until the read size reaches `fixed_buffer_size`, use `fixed_buffer` -// to store data. The call can set memory on stack for performance. -class stream_line_reader { -public: - stream_line_reader(Stream &strm, char *fixed_buffer, - size_t fixed_buffer_size); - const char *ptr() const; - size_t size() const; - bool end_with_crlf() const; - bool getline(); - -private: - void append(char c); - - Stream &strm_; - char *fixed_buffer_; - const size_t fixed_buffer_size_; - size_t fixed_buffer_used_size_ = 0; - std::string glowable_buffer_; -}; - -class mmap { -public: - mmap(const char *path); - ~mmap(); - - bool open(const char *path); - void close(); - - bool is_open() const; - size_t size() const; - const char *data() const; - -private: -#if defined(_WIN32) - HANDLE hFile_; - HANDLE hMapping_; -#else - int fd_; -#endif - size_t size_; - void *addr_; -}; - -} // namespace detail - -// ---------------------------------------------------------------------------- - -/* - * Implementation that will be part of the .cc file if split into .h + .cc. - */ - -namespace detail { - -inline bool is_hex(char c, int &v) { - if (0x20 <= c && isdigit(c)) { - v = c - '0'; - return true; - } else if ('A' <= c && c <= 'F') { - v = c - 'A' + 10; - return true; - } else if ('a' <= c && c <= 'f') { - v = c - 'a' + 10; - return true; - } - return false; -} - -inline bool from_hex_to_i(const std::string &s, size_t i, size_t cnt, - int &val) { - if (i >= s.size()) { return false; } - - val = 0; - for (; cnt; i++, cnt--) { - if (!s[i]) { return false; } - auto v = 0; - if (is_hex(s[i], v)) { - val = val * 16 + v; - } else { - return false; - } - } - return true; -} - -inline std::string from_i_to_hex(size_t n) { - static const auto charset = "0123456789abcdef"; - std::string ret; - do { - ret = charset[n & 15] + ret; - n >>= 4; - } while (n > 0); - return ret; -} - -inline size_t to_utf8(int code, char *buff) { - if (code < 0x0080) { - buff[0] = static_cast(code & 0x7F); - return 1; - } else if (code < 0x0800) { - buff[0] = static_cast(0xC0 | ((code >> 6) & 0x1F)); - buff[1] = static_cast(0x80 | (code & 0x3F)); - return 2; - } else if (code < 0xD800) { - buff[0] = static_cast(0xE0 | ((code >> 12) & 0xF)); - buff[1] = static_cast(0x80 | ((code >> 6) & 0x3F)); - buff[2] = static_cast(0x80 | (code & 0x3F)); - return 3; - } else if (code < 0xE000) { // D800 - DFFF is invalid... - return 0; - } else if (code < 0x10000) { - buff[0] = static_cast(0xE0 | ((code >> 12) & 0xF)); - buff[1] = static_cast(0x80 | ((code >> 6) & 0x3F)); - buff[2] = static_cast(0x80 | (code & 0x3F)); - return 3; - } else if (code < 0x110000) { - buff[0] = static_cast(0xF0 | ((code >> 18) & 0x7)); - buff[1] = static_cast(0x80 | ((code >> 12) & 0x3F)); - buff[2] = static_cast(0x80 | ((code >> 6) & 0x3F)); - buff[3] = static_cast(0x80 | (code & 0x3F)); - return 4; - } - - // NOTREACHED - return 0; -} - -// NOTE: This code came up with the following stackoverflow post: -// https://stackoverflow.com/questions/180947/base64-decode-snippet-in-c -inline std::string base64_encode(const std::string &in) { - static const auto lookup = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - std::string out; - out.reserve(in.size()); - - auto val = 0; - auto valb = -6; - - for (auto c : in) { - val = (val << 8) + static_cast(c); - valb += 8; - while (valb >= 0) { - out.push_back(lookup[(val >> valb) & 0x3F]); - valb -= 6; - } - } - - if (valb > -6) { out.push_back(lookup[((val << 8) >> (valb + 8)) & 0x3F]); } - - while (out.size() % 4) { - out.push_back('='); - } - - return out; -} - -inline bool is_file(const std::string &path) { -#ifdef _WIN32 - return _access_s(path.c_str(), 0) == 0; -#else - struct stat st; - return stat(path.c_str(), &st) >= 0 && S_ISREG(st.st_mode); -#endif -} - -inline bool is_dir(const std::string &path) { - struct stat st; - return stat(path.c_str(), &st) >= 0 && S_ISDIR(st.st_mode); -} - -inline bool is_valid_path(const std::string &path) { - size_t level = 0; - size_t i = 0; - - // Skip slash - while (i < path.size() && path[i] == '/') { - i++; - } - - while (i < path.size()) { - // Read component - auto beg = i; - while (i < path.size() && path[i] != '/') { - i++; - } - - auto len = i - beg; - assert(len > 0); - - if (!path.compare(beg, len, ".")) { - ; - } else if (!path.compare(beg, len, "..")) { - if (level == 0) { return false; } - level--; - } else { - level++; - } - - // Skip slash - while (i < path.size() && path[i] == '/') { - i++; - } - } - - return true; -} - -inline std::string encode_query_param(const std::string &value) { - std::ostringstream escaped; - escaped.fill('0'); - escaped << std::hex; - - for (auto c : value) { - if (std::isalnum(static_cast(c)) || c == '-' || c == '_' || - c == '.' || c == '!' || c == '~' || c == '*' || c == '\'' || c == '(' || - c == ')') { - escaped << c; - } else { - escaped << std::uppercase; - escaped << '%' << std::setw(2) - << static_cast(static_cast(c)); - escaped << std::nouppercase; - } - } - - return escaped.str(); -} - -inline std::string encode_url(const std::string &s) { - std::string result; - result.reserve(s.size()); - - for (size_t i = 0; s[i]; i++) { - switch (s[i]) { - case ' ': result += "%20"; break; - case '+': result += "%2B"; break; - case '\r': result += "%0D"; break; - case '\n': result += "%0A"; break; - case '\'': result += "%27"; break; - case ',': result += "%2C"; break; - // case ':': result += "%3A"; break; // ok? probably... - case ';': result += "%3B"; break; - default: - auto c = static_cast(s[i]); - if (c >= 0x80) { - result += '%'; - char hex[4]; - auto len = snprintf(hex, sizeof(hex) - 1, "%02X", c); - assert(len == 2); - result.append(hex, static_cast(len)); - } else { - result += s[i]; - } - break; - } - } - - return result; -} - -inline std::string decode_url(const std::string &s, - bool convert_plus_to_space) { - std::string result; - - for (size_t i = 0; i < s.size(); i++) { - if (s[i] == '%' && i + 1 < s.size()) { - if (s[i + 1] == 'u') { - auto val = 0; - if (from_hex_to_i(s, i + 2, 4, val)) { - // 4 digits Unicode codes - char buff[4]; - size_t len = to_utf8(val, buff); - if (len > 0) { result.append(buff, len); } - i += 5; // 'u0000' - } else { - result += s[i]; - } - } else { - auto val = 0; - if (from_hex_to_i(s, i + 1, 2, val)) { - // 2 digits hex codes - result += static_cast(val); - i += 2; // '00' - } else { - result += s[i]; - } - } - } else if (convert_plus_to_space && s[i] == '+') { - result += ' '; - } else { - result += s[i]; - } - } - - return result; -} - -inline void read_file(const std::string &path, std::string &out) { - std::ifstream fs(path, std::ios_base::binary); - fs.seekg(0, std::ios_base::end); - auto size = fs.tellg(); - fs.seekg(0); - out.resize(static_cast(size)); - fs.read(&out[0], static_cast(size)); -} - -inline std::string file_extension(const std::string &path) { - std::smatch m; - static auto re = std::regex("\\.([a-zA-Z0-9]+)$"); - if (std::regex_search(path, m, re)) { return m[1].str(); } - return std::string(); -} - -inline bool is_space_or_tab(char c) { return c == ' ' || c == '\t'; } - -inline std::pair trim(const char *b, const char *e, size_t left, - size_t right) { - while (b + left < e && is_space_or_tab(b[left])) { - left++; - } - while (right > 0 && is_space_or_tab(b[right - 1])) { - right--; - } - return std::make_pair(left, right); -} - -inline std::string trim_copy(const std::string &s) { - auto r = trim(s.data(), s.data() + s.size(), 0, s.size()); - return s.substr(r.first, r.second - r.first); -} - -inline std::string trim_double_quotes_copy(const std::string &s) { - if (s.length() >= 2 && s.front() == '"' && s.back() == '"') { - return s.substr(1, s.size() - 2); - } - return s; -} - -inline void split(const char *b, const char *e, char d, - std::function fn) { - return split(b, e, d, (std::numeric_limits::max)(), fn); -} - -inline void split(const char *b, const char *e, char d, size_t m, - std::function fn) { - size_t i = 0; - size_t beg = 0; - size_t count = 1; - - while (e ? (b + i < e) : (b[i] != '\0')) { - if (b[i] == d && count < m) { - auto r = trim(b, e, beg, i); - if (r.first < r.second) { fn(&b[r.first], &b[r.second]); } - beg = i + 1; - count++; - } - i++; - } - - if (i) { - auto r = trim(b, e, beg, i); - if (r.first < r.second) { fn(&b[r.first], &b[r.second]); } - } -} - -inline stream_line_reader::stream_line_reader(Stream &strm, char *fixed_buffer, - size_t fixed_buffer_size) - : strm_(strm), fixed_buffer_(fixed_buffer), - fixed_buffer_size_(fixed_buffer_size) {} - -inline const char *stream_line_reader::ptr() const { - if (glowable_buffer_.empty()) { - return fixed_buffer_; - } else { - return glowable_buffer_.data(); - } -} - -inline size_t stream_line_reader::size() const { - if (glowable_buffer_.empty()) { - return fixed_buffer_used_size_; - } else { - return glowable_buffer_.size(); - } -} - -inline bool stream_line_reader::end_with_crlf() const { - auto end = ptr() + size(); - return size() >= 2 && end[-2] == '\r' && end[-1] == '\n'; -} - -inline bool stream_line_reader::getline() { - fixed_buffer_used_size_ = 0; - glowable_buffer_.clear(); - - for (size_t i = 0;; i++) { - char byte; - auto n = strm_.read(&byte, 1); - - if (n < 0) { - return false; - } else if (n == 0) { - if (i == 0) { - return false; - } else { - break; - } - } - - append(byte); - - if (byte == '\n') { break; } - } - - return true; -} - -inline void stream_line_reader::append(char c) { - if (fixed_buffer_used_size_ < fixed_buffer_size_ - 1) { - fixed_buffer_[fixed_buffer_used_size_++] = c; - fixed_buffer_[fixed_buffer_used_size_] = '\0'; - } else { - if (glowable_buffer_.empty()) { - assert(fixed_buffer_[fixed_buffer_used_size_] == '\0'); - glowable_buffer_.assign(fixed_buffer_, fixed_buffer_used_size_); - } - glowable_buffer_ += c; - } -} - -inline mmap::mmap(const char *path) -#if defined(_WIN32) - : hFile_(NULL), hMapping_(NULL) -#else - : fd_(-1) -#endif - , - size_(0), addr_(nullptr) { - open(path); -} - -inline mmap::~mmap() { close(); } - -inline bool mmap::open(const char *path) { - close(); - -#if defined(_WIN32) - hFile_ = ::CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, - OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); - - if (hFile_ == INVALID_HANDLE_VALUE) { return false; } - - size_ = ::GetFileSize(hFile_, NULL); - - hMapping_ = ::CreateFileMapping(hFile_, NULL, PAGE_READONLY, 0, 0, NULL); - - if (hMapping_ == NULL) { - close(); - return false; - } - - addr_ = ::MapViewOfFile(hMapping_, FILE_MAP_READ, 0, 0, 0); -#else - fd_ = ::open(path, O_RDONLY); - if (fd_ == -1) { return false; } - - struct stat sb; - if (fstat(fd_, &sb) == -1) { - close(); - return false; - } - size_ = static_cast(sb.st_size); - - addr_ = ::mmap(NULL, size_, PROT_READ, MAP_PRIVATE, fd_, 0); -#endif - - if (addr_ == nullptr) { - close(); - return false; - } - - return true; -} - -inline bool mmap::is_open() const { return addr_ != nullptr; } - -inline size_t mmap::size() const { return size_; } - -inline const char *mmap::data() const { - return static_cast(addr_); -} - -inline void mmap::close() { -#if defined(_WIN32) - if (addr_) { - ::UnmapViewOfFile(addr_); - addr_ = nullptr; - } - - if (hMapping_) { - ::CloseHandle(hMapping_); - hMapping_ = NULL; - } - - if (hFile_ != INVALID_HANDLE_VALUE) { - ::CloseHandle(hFile_); - hFile_ = INVALID_HANDLE_VALUE; - } -#else - if (addr_ != nullptr) { - munmap(addr_, size_); - addr_ = nullptr; - } - - if (fd_ != -1) { - ::close(fd_); - fd_ = -1; - } -#endif - size_ = 0; -} -inline int close_socket(socket_t sock) { -#ifdef _WIN32 - return closesocket(sock); -#else - return close(sock); -#endif -} - -template inline ssize_t handle_EINTR(T fn) { - ssize_t res = 0; - while (true) { - res = fn(); - if (res < 0 && errno == EINTR) { continue; } - break; - } - return res; -} - -inline ssize_t read_socket(socket_t sock, void *ptr, size_t size, int flags) { - return handle_EINTR([&]() { - return recv(sock, -#ifdef _WIN32 - static_cast(ptr), static_cast(size), -#else - ptr, size, -#endif - flags); - }); -} - -inline ssize_t send_socket(socket_t sock, const void *ptr, size_t size, - int flags) { - return handle_EINTR([&]() { - return send(sock, -#ifdef _WIN32 - static_cast(ptr), static_cast(size), -#else - ptr, size, -#endif - flags); - }); -} - -inline ssize_t select_read(socket_t sock, time_t sec, time_t usec) { -#ifdef CPPHTTPLIB_USE_POLL - struct pollfd pfd_read; - pfd_read.fd = sock; - pfd_read.events = POLLIN; - - auto timeout = static_cast(sec * 1000 + usec / 1000); - - return handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); }); -#else -#ifndef _WIN32 - if (sock >= FD_SETSIZE) { return -1; } -#endif - - fd_set fds; - FD_ZERO(&fds); - FD_SET(sock, &fds); - - timeval tv; - tv.tv_sec = static_cast(sec); - tv.tv_usec = static_cast(usec); - - return handle_EINTR([&]() { - return select(static_cast(sock + 1), &fds, nullptr, nullptr, &tv); - }); -#endif -} - -inline ssize_t select_write(socket_t sock, time_t sec, time_t usec) { -#ifdef CPPHTTPLIB_USE_POLL - struct pollfd pfd_read; - pfd_read.fd = sock; - pfd_read.events = POLLOUT; - - auto timeout = static_cast(sec * 1000 + usec / 1000); - - return handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); }); -#else -#ifndef _WIN32 - if (sock >= FD_SETSIZE) { return -1; } -#endif - - fd_set fds; - FD_ZERO(&fds); - FD_SET(sock, &fds); - - timeval tv; - tv.tv_sec = static_cast(sec); - tv.tv_usec = static_cast(usec); - - return handle_EINTR([&]() { - return select(static_cast(sock + 1), nullptr, &fds, nullptr, &tv); - }); -#endif -} - -inline Error wait_until_socket_is_ready(socket_t sock, time_t sec, - time_t usec) { -#ifdef CPPHTTPLIB_USE_POLL - struct pollfd pfd_read; - pfd_read.fd = sock; - pfd_read.events = POLLIN | POLLOUT; - - auto timeout = static_cast(sec * 1000 + usec / 1000); - - auto poll_res = handle_EINTR([&]() { return poll(&pfd_read, 1, timeout); }); - - if (poll_res == 0) { return Error::ConnectionTimeout; } - - if (poll_res > 0 && pfd_read.revents & (POLLIN | POLLOUT)) { - auto error = 0; - socklen_t len = sizeof(error); - auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR, - reinterpret_cast(&error), &len); - auto successful = res >= 0 && !error; - return successful ? Error::Success : Error::Connection; - } - - return Error::Connection; -#else -#ifndef _WIN32 - if (sock >= FD_SETSIZE) { return Error::Connection; } -#endif - - fd_set fdsr; - FD_ZERO(&fdsr); - FD_SET(sock, &fdsr); - - auto fdsw = fdsr; - auto fdse = fdsr; - - timeval tv; - tv.tv_sec = static_cast(sec); - tv.tv_usec = static_cast(usec); - - auto ret = handle_EINTR([&]() { - return select(static_cast(sock + 1), &fdsr, &fdsw, &fdse, &tv); - }); - - if (ret == 0) { return Error::ConnectionTimeout; } - - if (ret > 0 && (FD_ISSET(sock, &fdsr) || FD_ISSET(sock, &fdsw))) { - auto error = 0; - socklen_t len = sizeof(error); - auto res = getsockopt(sock, SOL_SOCKET, SO_ERROR, - reinterpret_cast(&error), &len); - auto successful = res >= 0 && !error; - return successful ? Error::Success : Error::Connection; - } - return Error::Connection; -#endif -} - -inline bool is_socket_alive(socket_t sock) { - const auto val = detail::select_read(sock, 0, 0); - if (val == 0) { - return true; - } else if (val < 0 && errno == EBADF) { - return false; - } - char buf[1]; - return detail::read_socket(sock, &buf[0], sizeof(buf), MSG_PEEK) > 0; -} - -class SocketStream : public Stream { -public: - SocketStream(socket_t sock, time_t read_timeout_sec, time_t read_timeout_usec, - time_t write_timeout_sec, time_t write_timeout_usec); - ~SocketStream() override; - - bool is_readable() const override; - bool is_writable() const override; - ssize_t read(char *ptr, size_t size) override; - ssize_t write(const char *ptr, size_t size) override; - void get_remote_ip_and_port(std::string &ip, int &port) const override; - void get_local_ip_and_port(std::string &ip, int &port) const override; - socket_t socket() const override; - -private: - socket_t sock_; - time_t read_timeout_sec_; - time_t read_timeout_usec_; - time_t write_timeout_sec_; - time_t write_timeout_usec_; - - std::vector read_buff_; - size_t read_buff_off_ = 0; - size_t read_buff_content_size_ = 0; - - static const size_t read_buff_size_ = 1024l * 4; -}; - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -class SSLSocketStream : public Stream { -public: - SSLSocketStream(socket_t sock, SSL *ssl, time_t read_timeout_sec, - time_t read_timeout_usec, time_t write_timeout_sec, - time_t write_timeout_usec); - ~SSLSocketStream() override; - - bool is_readable() const override; - bool is_writable() const override; - ssize_t read(char *ptr, size_t size) override; - ssize_t write(const char *ptr, size_t size) override; - void get_remote_ip_and_port(std::string &ip, int &port) const override; - void get_local_ip_and_port(std::string &ip, int &port) const override; - socket_t socket() const override; - -private: - socket_t sock_; - SSL *ssl_; - time_t read_timeout_sec_; - time_t read_timeout_usec_; - time_t write_timeout_sec_; - time_t write_timeout_usec_; -}; -#endif - -inline bool keep_alive(socket_t sock, time_t keep_alive_timeout_sec) { - using namespace std::chrono; - auto start = steady_clock::now(); - while (true) { - auto val = select_read(sock, 0, 10000); - if (val < 0) { - return false; - } else if (val == 0) { - auto current = steady_clock::now(); - auto duration = duration_cast(current - start); - auto timeout = keep_alive_timeout_sec * 1000; - if (duration.count() > timeout) { return false; } - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - } else { - return true; - } - } -} - -template -inline bool -process_server_socket_core(const std::atomic &svr_sock, socket_t sock, - size_t keep_alive_max_count, - time_t keep_alive_timeout_sec, T callback) { - assert(keep_alive_max_count > 0); - auto ret = false; - auto count = keep_alive_max_count; - while (svr_sock != INVALID_SOCKET && count > 0 && - keep_alive(sock, keep_alive_timeout_sec)) { - auto close_connection = count == 1; - auto connection_closed = false; - ret = callback(close_connection, connection_closed); - if (!ret || connection_closed) { break; } - count--; - } - return ret; -} - -template -inline bool -process_server_socket(const std::atomic &svr_sock, socket_t sock, - size_t keep_alive_max_count, - time_t keep_alive_timeout_sec, time_t read_timeout_sec, - time_t read_timeout_usec, time_t write_timeout_sec, - time_t write_timeout_usec, T callback) { - return process_server_socket_core( - svr_sock, sock, keep_alive_max_count, keep_alive_timeout_sec, - [&](bool close_connection, bool &connection_closed) { - SocketStream strm(sock, read_timeout_sec, read_timeout_usec, - write_timeout_sec, write_timeout_usec); - return callback(strm, close_connection, connection_closed); - }); -} - -inline bool process_client_socket(socket_t sock, time_t read_timeout_sec, - time_t read_timeout_usec, - time_t write_timeout_sec, - time_t write_timeout_usec, - std::function callback) { - SocketStream strm(sock, read_timeout_sec, read_timeout_usec, - write_timeout_sec, write_timeout_usec); - return callback(strm); -} - -inline int shutdown_socket(socket_t sock) { -#ifdef _WIN32 - return shutdown(sock, SD_BOTH); -#else - return shutdown(sock, SHUT_RDWR); -#endif -} - -template -socket_t create_socket(const std::string &host, const std::string &ip, int port, - int address_family, int socket_flags, bool tcp_nodelay, - SocketOptions socket_options, - BindOrConnect bind_or_connect) { - // Get address info - const char *node = nullptr; - struct addrinfo hints; - struct addrinfo *result; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = 0; - - if (!ip.empty()) { - node = ip.c_str(); - // Ask getaddrinfo to convert IP in c-string to address - hints.ai_family = AF_UNSPEC; - hints.ai_flags = AI_NUMERICHOST; - } else { - if (!host.empty()) { node = host.c_str(); } - hints.ai_family = address_family; - hints.ai_flags = socket_flags; - } - -#ifndef _WIN32 - if (hints.ai_family == AF_UNIX) { - const auto addrlen = host.length(); - if (addrlen > sizeof(sockaddr_un::sun_path)) { return INVALID_SOCKET; } - - auto sock = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol); - if (sock != INVALID_SOCKET) { - sockaddr_un addr{}; - addr.sun_family = AF_UNIX; - std::copy(host.begin(), host.end(), addr.sun_path); - - hints.ai_addr = reinterpret_cast(&addr); - hints.ai_addrlen = static_cast( - sizeof(addr) - sizeof(addr.sun_path) + addrlen); - - fcntl(sock, F_SETFD, FD_CLOEXEC); - if (socket_options) { socket_options(sock); } - - if (!bind_or_connect(sock, hints)) { - close_socket(sock); - sock = INVALID_SOCKET; - } - } - return sock; - } -#endif - - auto service = std::to_string(port); - - if (getaddrinfo(node, service.c_str(), &hints, &result)) { -#if defined __linux__ && !defined __ANDROID__ - res_init(); -#endif - return INVALID_SOCKET; - } - - for (auto rp = result; rp; rp = rp->ai_next) { - // Create a socket -#ifdef _WIN32 - auto sock = - WSASocketW(rp->ai_family, rp->ai_socktype, rp->ai_protocol, nullptr, 0, - WSA_FLAG_NO_HANDLE_INHERIT | WSA_FLAG_OVERLAPPED); - /** - * Since the WSA_FLAG_NO_HANDLE_INHERIT is only supported on Windows 7 SP1 - * and above the socket creation fails on older Windows Systems. - * - * Let's try to create a socket the old way in this case. - * - * Reference: - * https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketa - * - * WSA_FLAG_NO_HANDLE_INHERIT: - * This flag is supported on Windows 7 with SP1, Windows Server 2008 R2 with - * SP1, and later - * - */ - if (sock == INVALID_SOCKET) { - sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); - } -#else - auto sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); -#endif - if (sock == INVALID_SOCKET) { continue; } - -#ifndef _WIN32 - if (fcntl(sock, F_SETFD, FD_CLOEXEC) == -1) { - close_socket(sock); - continue; - } -#endif - - if (tcp_nodelay) { - auto yes = 1; -#ifdef _WIN32 - setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, - reinterpret_cast(&yes), sizeof(yes)); -#else - setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, - reinterpret_cast(&yes), sizeof(yes)); -#endif - } - - if (socket_options) { socket_options(sock); } - - if (rp->ai_family == AF_INET6) { - auto no = 0; -#ifdef _WIN32 - setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, - reinterpret_cast(&no), sizeof(no)); -#else - setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, - reinterpret_cast(&no), sizeof(no)); -#endif - } - - // bind or connect - if (bind_or_connect(sock, *rp)) { - freeaddrinfo(result); - return sock; - } - - close_socket(sock); - } - - freeaddrinfo(result); - return INVALID_SOCKET; -} - -inline void set_nonblocking(socket_t sock, bool nonblocking) { -#ifdef _WIN32 - auto flags = nonblocking ? 1UL : 0UL; - ioctlsocket(sock, FIONBIO, &flags); -#else - auto flags = fcntl(sock, F_GETFL, 0); - fcntl(sock, F_SETFL, - nonblocking ? (flags | O_NONBLOCK) : (flags & (~O_NONBLOCK))); -#endif -} - -inline bool is_connection_error() { -#ifdef _WIN32 - return WSAGetLastError() != WSAEWOULDBLOCK; -#else - return errno != EINPROGRESS; -#endif -} - -inline bool bind_ip_address(socket_t sock, const std::string &host) { - struct addrinfo hints; - struct addrinfo *result; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = 0; - - if (getaddrinfo(host.c_str(), "0", &hints, &result)) { return false; } - - auto ret = false; - for (auto rp = result; rp; rp = rp->ai_next) { - const auto &ai = *rp; - if (!::bind(sock, ai.ai_addr, static_cast(ai.ai_addrlen))) { - ret = true; - break; - } - } - - freeaddrinfo(result); - return ret; -} - -#if !defined _WIN32 && !defined ANDROID && !defined _AIX && !defined __MVS__ -#define USE_IF2IP -#endif - -#ifdef USE_IF2IP -inline std::string if2ip(int address_family, const std::string &ifn) { - struct ifaddrs *ifap; - getifaddrs(&ifap); - std::string addr_candidate; - for (auto ifa = ifap; ifa; ifa = ifa->ifa_next) { - if (ifa->ifa_addr && ifn == ifa->ifa_name && - (AF_UNSPEC == address_family || - ifa->ifa_addr->sa_family == address_family)) { - if (ifa->ifa_addr->sa_family == AF_INET) { - auto sa = reinterpret_cast(ifa->ifa_addr); - char buf[INET_ADDRSTRLEN]; - if (inet_ntop(AF_INET, &sa->sin_addr, buf, INET_ADDRSTRLEN)) { - freeifaddrs(ifap); - return std::string(buf, INET_ADDRSTRLEN); - } - } else if (ifa->ifa_addr->sa_family == AF_INET6) { - auto sa = reinterpret_cast(ifa->ifa_addr); - if (!IN6_IS_ADDR_LINKLOCAL(&sa->sin6_addr)) { - char buf[INET6_ADDRSTRLEN] = {}; - if (inet_ntop(AF_INET6, &sa->sin6_addr, buf, INET6_ADDRSTRLEN)) { - // equivalent to mac's IN6_IS_ADDR_UNIQUE_LOCAL - auto s6_addr_head = sa->sin6_addr.s6_addr[0]; - if (s6_addr_head == 0xfc || s6_addr_head == 0xfd) { - addr_candidate = std::string(buf, INET6_ADDRSTRLEN); - } else { - freeifaddrs(ifap); - return std::string(buf, INET6_ADDRSTRLEN); - } - } - } - } - } - } - freeifaddrs(ifap); - return addr_candidate; -} -#endif - -inline socket_t create_client_socket( - const std::string &host, const std::string &ip, int port, - int address_family, bool tcp_nodelay, SocketOptions socket_options, - time_t connection_timeout_sec, time_t connection_timeout_usec, - time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, - time_t write_timeout_usec, const std::string &intf, Error &error) { - auto sock = create_socket( - host, ip, port, address_family, 0, tcp_nodelay, std::move(socket_options), - [&](socket_t sock2, struct addrinfo &ai) -> bool { - if (!intf.empty()) { -#ifdef USE_IF2IP - auto ip_from_if = if2ip(address_family, intf); - if (ip_from_if.empty()) { ip_from_if = intf; } - if (!bind_ip_address(sock2, ip_from_if)) { - error = Error::BindIPAddress; - return false; - } -#endif - } - - set_nonblocking(sock2, true); - - auto ret = - ::connect(sock2, ai.ai_addr, static_cast(ai.ai_addrlen)); - - if (ret < 0) { - if (is_connection_error()) { - error = Error::Connection; - return false; - } - error = wait_until_socket_is_ready(sock2, connection_timeout_sec, - connection_timeout_usec); - if (error != Error::Success) { return false; } - } - - set_nonblocking(sock2, false); - - { -#ifdef _WIN32 - auto timeout = static_cast(read_timeout_sec * 1000 + - read_timeout_usec / 1000); - setsockopt(sock2, SOL_SOCKET, SO_RCVTIMEO, - reinterpret_cast(&timeout), sizeof(timeout)); -#else - timeval tv; - tv.tv_sec = static_cast(read_timeout_sec); - tv.tv_usec = static_cast(read_timeout_usec); - setsockopt(sock2, SOL_SOCKET, SO_RCVTIMEO, - reinterpret_cast(&tv), sizeof(tv)); -#endif - } - { - -#ifdef _WIN32 - auto timeout = static_cast(write_timeout_sec * 1000 + - write_timeout_usec / 1000); - setsockopt(sock2, SOL_SOCKET, SO_SNDTIMEO, - reinterpret_cast(&timeout), sizeof(timeout)); -#else - timeval tv; - tv.tv_sec = static_cast(write_timeout_sec); - tv.tv_usec = static_cast(write_timeout_usec); - setsockopt(sock2, SOL_SOCKET, SO_SNDTIMEO, - reinterpret_cast(&tv), sizeof(tv)); -#endif - } - - error = Error::Success; - return true; - }); - - if (sock != INVALID_SOCKET) { - error = Error::Success; - } else { - if (error == Error::Success) { error = Error::Connection; } - } - - return sock; -} - -inline bool get_ip_and_port(const struct sockaddr_storage &addr, - socklen_t addr_len, std::string &ip, int &port) { - if (addr.ss_family == AF_INET) { - port = ntohs(reinterpret_cast(&addr)->sin_port); - } else if (addr.ss_family == AF_INET6) { - port = - ntohs(reinterpret_cast(&addr)->sin6_port); - } else { - return false; - } - - std::array ipstr{}; - if (getnameinfo(reinterpret_cast(&addr), addr_len, - ipstr.data(), static_cast(ipstr.size()), nullptr, - 0, NI_NUMERICHOST)) { - return false; - } - - ip = ipstr.data(); - return true; -} - -inline void get_local_ip_and_port(socket_t sock, std::string &ip, int &port) { - struct sockaddr_storage addr; - socklen_t addr_len = sizeof(addr); - if (!getsockname(sock, reinterpret_cast(&addr), - &addr_len)) { - get_ip_and_port(addr, addr_len, ip, port); - } -} - -inline void get_remote_ip_and_port(socket_t sock, std::string &ip, int &port) { - struct sockaddr_storage addr; - socklen_t addr_len = sizeof(addr); - - if (!getpeername(sock, reinterpret_cast(&addr), - &addr_len)) { -#ifndef _WIN32 - if (addr.ss_family == AF_UNIX) { -#if defined(__linux__) - struct ucred ucred; - socklen_t len = sizeof(ucred); - if (getsockopt(sock, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == 0) { - port = ucred.pid; - } -#elif defined(SOL_LOCAL) && defined(SO_PEERPID) // __APPLE__ - pid_t pid; - socklen_t len = sizeof(pid); - if (getsockopt(sock, SOL_LOCAL, SO_PEERPID, &pid, &len) == 0) { - port = pid; - } -#endif - return; - } -#endif - get_ip_and_port(addr, addr_len, ip, port); - } -} - -inline constexpr unsigned int str2tag_core(const char *s, size_t l, - unsigned int h) { - return (l == 0) - ? h - : str2tag_core( - s + 1, l - 1, - // Unsets the 6 high bits of h, therefore no overflow happens - (((std::numeric_limits::max)() >> 6) & - h * 33) ^ - static_cast(*s)); -} - -inline unsigned int str2tag(const std::string &s) { - return str2tag_core(s.data(), s.size(), 0); -} - -namespace udl { - -inline constexpr unsigned int operator"" _t(const char *s, size_t l) { - return str2tag_core(s, l, 0); -} - -} // namespace udl - -inline std::string -find_content_type(const std::string &path, - const std::map &user_data, - const std::string &default_content_type) { - auto ext = file_extension(path); - - auto it = user_data.find(ext); - if (it != user_data.end()) { return it->second; } - - using udl::operator""_t; - - switch (str2tag(ext)) { - default: return default_content_type; - - case "css"_t: return "text/css"; - case "csv"_t: return "text/csv"; - case "htm"_t: - case "html"_t: return "text/html"; - case "js"_t: - case "mjs"_t: return "text/javascript"; - case "txt"_t: return "text/plain"; - case "vtt"_t: return "text/vtt"; - - case "apng"_t: return "image/apng"; - case "avif"_t: return "image/avif"; - case "bmp"_t: return "image/bmp"; - case "gif"_t: return "image/gif"; - case "png"_t: return "image/png"; - case "svg"_t: return "image/svg+xml"; - case "webp"_t: return "image/webp"; - case "ico"_t: return "image/x-icon"; - case "tif"_t: return "image/tiff"; - case "tiff"_t: return "image/tiff"; - case "jpg"_t: - case "jpeg"_t: return "image/jpeg"; - - case "mp4"_t: return "video/mp4"; - case "mpeg"_t: return "video/mpeg"; - case "webm"_t: return "video/webm"; - - case "mp3"_t: return "audio/mp3"; - case "mpga"_t: return "audio/mpeg"; - case "weba"_t: return "audio/webm"; - case "wav"_t: return "audio/wave"; - - case "otf"_t: return "font/otf"; - case "ttf"_t: return "font/ttf"; - case "woff"_t: return "font/woff"; - case "woff2"_t: return "font/woff2"; - - case "7z"_t: return "application/x-7z-compressed"; - case "atom"_t: return "application/atom+xml"; - case "pdf"_t: return "application/pdf"; - case "json"_t: return "application/json"; - case "rss"_t: return "application/rss+xml"; - case "tar"_t: return "application/x-tar"; - case "xht"_t: - case "xhtml"_t: return "application/xhtml+xml"; - case "xslt"_t: return "application/xslt+xml"; - case "xml"_t: return "application/xml"; - case "gz"_t: return "application/gzip"; - case "zip"_t: return "application/zip"; - case "wasm"_t: return "application/wasm"; - } -} - -inline bool can_compress_content_type(const std::string &content_type) { - using udl::operator""_t; - - auto tag = str2tag(content_type); - - switch (tag) { - case "image/svg+xml"_t: - case "application/javascript"_t: - case "application/json"_t: - case "application/xml"_t: - case "application/protobuf"_t: - case "application/xhtml+xml"_t: return true; - - default: - return !content_type.rfind("text/", 0) && tag != "text/event-stream"_t; - } -} - -inline EncodingType encoding_type(const Request &req, const Response &res) { - auto ret = - detail::can_compress_content_type(res.get_header_value("Content-Type")); - if (!ret) { return EncodingType::None; } - - const auto &s = req.get_header_value("Accept-Encoding"); - (void)(s); - -#ifdef CPPHTTPLIB_BROTLI_SUPPORT - // TODO: 'Accept-Encoding' has br, not br;q=0 - ret = s.find("br") != std::string::npos; - if (ret) { return EncodingType::Brotli; } -#endif - -#ifdef CPPHTTPLIB_ZLIB_SUPPORT - // TODO: 'Accept-Encoding' has gzip, not gzip;q=0 - ret = s.find("gzip") != std::string::npos; - if (ret) { return EncodingType::Gzip; } -#endif - - return EncodingType::None; -} - -inline bool nocompressor::compress(const char *data, size_t data_length, - bool /*last*/, Callback callback) { - if (!data_length) { return true; } - return callback(data, data_length); -} - -#ifdef CPPHTTPLIB_ZLIB_SUPPORT -inline gzip_compressor::gzip_compressor() { - std::memset(&strm_, 0, sizeof(strm_)); - strm_.zalloc = Z_NULL; - strm_.zfree = Z_NULL; - strm_.opaque = Z_NULL; - - is_valid_ = deflateInit2(&strm_, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 31, 8, - Z_DEFAULT_STRATEGY) == Z_OK; -} - -inline gzip_compressor::~gzip_compressor() { deflateEnd(&strm_); } - -inline bool gzip_compressor::compress(const char *data, size_t data_length, - bool last, Callback callback) { - assert(is_valid_); - - do { - constexpr size_t max_avail_in = - (std::numeric_limits::max)(); - - strm_.avail_in = static_cast( - (std::min)(data_length, max_avail_in)); - strm_.next_in = const_cast(reinterpret_cast(data)); - - data_length -= strm_.avail_in; - data += strm_.avail_in; - - auto flush = (last && data_length == 0) ? Z_FINISH : Z_NO_FLUSH; - auto ret = Z_OK; - - std::array buff{}; - do { - strm_.avail_out = static_cast(buff.size()); - strm_.next_out = reinterpret_cast(buff.data()); - - ret = deflate(&strm_, flush); - if (ret == Z_STREAM_ERROR) { return false; } - - if (!callback(buff.data(), buff.size() - strm_.avail_out)) { - return false; - } - } while (strm_.avail_out == 0); - - assert((flush == Z_FINISH && ret == Z_STREAM_END) || - (flush == Z_NO_FLUSH && ret == Z_OK)); - assert(strm_.avail_in == 0); - } while (data_length > 0); - - return true; -} - -inline gzip_decompressor::gzip_decompressor() { - std::memset(&strm_, 0, sizeof(strm_)); - strm_.zalloc = Z_NULL; - strm_.zfree = Z_NULL; - strm_.opaque = Z_NULL; - - // 15 is the value of wbits, which should be at the maximum possible value - // to ensure that any gzip stream can be decoded. The offset of 32 specifies - // that the stream type should be automatically detected either gzip or - // deflate. - is_valid_ = inflateInit2(&strm_, 32 + 15) == Z_OK; -} - -inline gzip_decompressor::~gzip_decompressor() { inflateEnd(&strm_); } - -inline bool gzip_decompressor::is_valid() const { return is_valid_; } - -inline bool gzip_decompressor::decompress(const char *data, size_t data_length, - Callback callback) { - assert(is_valid_); - - auto ret = Z_OK; - - do { - constexpr size_t max_avail_in = - (std::numeric_limits::max)(); - - strm_.avail_in = static_cast( - (std::min)(data_length, max_avail_in)); - strm_.next_in = const_cast(reinterpret_cast(data)); - - data_length -= strm_.avail_in; - data += strm_.avail_in; - - std::array buff{}; - while (strm_.avail_in > 0 && ret == Z_OK) { - strm_.avail_out = static_cast(buff.size()); - strm_.next_out = reinterpret_cast(buff.data()); - - ret = inflate(&strm_, Z_NO_FLUSH); - - assert(ret != Z_STREAM_ERROR); - switch (ret) { - case Z_NEED_DICT: - case Z_DATA_ERROR: - case Z_MEM_ERROR: inflateEnd(&strm_); return false; - } - - if (!callback(buff.data(), buff.size() - strm_.avail_out)) { - return false; - } - } - - if (ret != Z_OK && ret != Z_STREAM_END) { return false; } - - } while (data_length > 0); - - return true; -} -#endif - -#ifdef CPPHTTPLIB_BROTLI_SUPPORT -inline brotli_compressor::brotli_compressor() { - state_ = BrotliEncoderCreateInstance(nullptr, nullptr, nullptr); -} - -inline brotli_compressor::~brotli_compressor() { - BrotliEncoderDestroyInstance(state_); -} - -inline bool brotli_compressor::compress(const char *data, size_t data_length, - bool last, Callback callback) { - std::array buff{}; - - auto operation = last ? BROTLI_OPERATION_FINISH : BROTLI_OPERATION_PROCESS; - auto available_in = data_length; - auto next_in = reinterpret_cast(data); - - for (;;) { - if (last) { - if (BrotliEncoderIsFinished(state_)) { break; } - } else { - if (!available_in) { break; } - } - - auto available_out = buff.size(); - auto next_out = buff.data(); - - if (!BrotliEncoderCompressStream(state_, operation, &available_in, &next_in, - &available_out, &next_out, nullptr)) { - return false; - } - - auto output_bytes = buff.size() - available_out; - if (output_bytes) { - callback(reinterpret_cast(buff.data()), output_bytes); - } - } - - return true; -} - -inline brotli_decompressor::brotli_decompressor() { - decoder_s = BrotliDecoderCreateInstance(0, 0, 0); - decoder_r = decoder_s ? BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT - : BROTLI_DECODER_RESULT_ERROR; -} - -inline brotli_decompressor::~brotli_decompressor() { - if (decoder_s) { BrotliDecoderDestroyInstance(decoder_s); } -} - -inline bool brotli_decompressor::is_valid() const { return decoder_s; } - -inline bool brotli_decompressor::decompress(const char *data, - size_t data_length, - Callback callback) { - if (decoder_r == BROTLI_DECODER_RESULT_SUCCESS || - decoder_r == BROTLI_DECODER_RESULT_ERROR) { - return 0; - } - - auto next_in = reinterpret_cast(data); - size_t avail_in = data_length; - size_t total_out; - - decoder_r = BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT; - - std::array buff{}; - while (decoder_r == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT) { - char *next_out = buff.data(); - size_t avail_out = buff.size(); - - decoder_r = BrotliDecoderDecompressStream( - decoder_s, &avail_in, &next_in, &avail_out, - reinterpret_cast(&next_out), &total_out); - - if (decoder_r == BROTLI_DECODER_RESULT_ERROR) { return false; } - - if (!callback(buff.data(), buff.size() - avail_out)) { return false; } - } - - return decoder_r == BROTLI_DECODER_RESULT_SUCCESS || - decoder_r == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT; -} -#endif - -inline bool has_header(const Headers &headers, const std::string &key) { - return headers.find(key) != headers.end(); -} - -inline const char *get_header_value(const Headers &headers, - const std::string &key, size_t id, - const char *def) { - auto rng = headers.equal_range(key); - auto it = rng.first; - std::advance(it, static_cast(id)); - if (it != rng.second) { return it->second.c_str(); } - return def; -} - -inline bool compare_case_ignore(const std::string &a, const std::string &b) { - if (a.size() != b.size()) { return false; } - for (size_t i = 0; i < b.size(); i++) { - if (::tolower(a[i]) != ::tolower(b[i])) { return false; } - } - return true; -} - -template -inline bool parse_header(const char *beg, const char *end, T fn) { - // Skip trailing spaces and tabs. - while (beg < end && is_space_or_tab(end[-1])) { - end--; - } - - auto p = beg; - while (p < end && *p != ':') { - p++; - } - - if (p == end) { return false; } - - auto key_end = p; - - if (*p++ != ':') { return false; } - - while (p < end && is_space_or_tab(*p)) { - p++; - } - - if (p < end) { - auto key_len = key_end - beg; - if (!key_len) { return false; } - - auto key = std::string(beg, key_end); - auto val = compare_case_ignore(key, "Location") - ? std::string(p, end) - : decode_url(std::string(p, end), false); - fn(std::move(key), std::move(val)); - return true; - } - - return false; -} - -inline bool read_headers(Stream &strm, Headers &headers) { - const auto bufsiz = 2048; - char buf[bufsiz]; - stream_line_reader line_reader(strm, buf, bufsiz); - - for (;;) { - if (!line_reader.getline()) { return false; } - - // Check if the line ends with CRLF. - auto line_terminator_len = 2; - if (line_reader.end_with_crlf()) { - // Blank line indicates end of headers. - if (line_reader.size() == 2) { break; } -#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR - } else { - // Blank line indicates end of headers. - if (line_reader.size() == 1) { break; } - line_terminator_len = 1; - } -#else - } else { - continue; // Skip invalid line. - } -#endif - - if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; } - - // Exclude line terminator - auto end = line_reader.ptr() + line_reader.size() - line_terminator_len; - - parse_header(line_reader.ptr(), end, - [&](std::string &&key, std::string &&val) { - headers.emplace(std::move(key), std::move(val)); - }); - } - - return true; -} - -inline bool read_content_with_length(Stream &strm, uint64_t len, - Progress progress, - ContentReceiverWithProgress out) { - char buf[CPPHTTPLIB_RECV_BUFSIZ]; - - uint64_t r = 0; - while (r < len) { - auto read_len = static_cast(len - r); - auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ)); - if (n <= 0) { return false; } - - if (!out(buf, static_cast(n), r, len)) { return false; } - r += static_cast(n); - - if (progress) { - if (!progress(r, len)) { return false; } - } - } - - return true; -} - -inline void skip_content_with_length(Stream &strm, uint64_t len) { - char buf[CPPHTTPLIB_RECV_BUFSIZ]; - uint64_t r = 0; - while (r < len) { - auto read_len = static_cast(len - r); - auto n = strm.read(buf, (std::min)(read_len, CPPHTTPLIB_RECV_BUFSIZ)); - if (n <= 0) { return; } - r += static_cast(n); - } -} - -inline bool read_content_without_length(Stream &strm, - ContentReceiverWithProgress out) { - char buf[CPPHTTPLIB_RECV_BUFSIZ]; - uint64_t r = 0; - for (;;) { - auto n = strm.read(buf, CPPHTTPLIB_RECV_BUFSIZ); - if (n <= 0) { return true; } - - if (!out(buf, static_cast(n), r, 0)) { return false; } - r += static_cast(n); - } - - return true; -} - -template -inline bool read_content_chunked(Stream &strm, T &x, - ContentReceiverWithProgress out) { - const auto bufsiz = 16; - char buf[bufsiz]; - - stream_line_reader line_reader(strm, buf, bufsiz); - - if (!line_reader.getline()) { return false; } - - unsigned long chunk_len; - while (true) { - char *end_ptr; - - chunk_len = std::strtoul(line_reader.ptr(), &end_ptr, 16); - - if (end_ptr == line_reader.ptr()) { return false; } - if (chunk_len == ULONG_MAX) { return false; } - - if (chunk_len == 0) { break; } - - if (!read_content_with_length(strm, chunk_len, nullptr, out)) { - return false; - } - - if (!line_reader.getline()) { return false; } - - if (strcmp(line_reader.ptr(), "\r\n") != 0) { return false; } - - if (!line_reader.getline()) { return false; } - } - - assert(chunk_len == 0); - - // Trailer - if (!line_reader.getline()) { return false; } - - while (strcmp(line_reader.ptr(), "\r\n") != 0) { - if (line_reader.size() > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; } - - // Exclude line terminator - constexpr auto line_terminator_len = 2; - auto end = line_reader.ptr() + line_reader.size() - line_terminator_len; - - parse_header(line_reader.ptr(), end, - [&](std::string &&key, std::string &&val) { - x.headers.emplace(std::move(key), std::move(val)); - }); - - if (!line_reader.getline()) { return false; } - } - - return true; -} - -inline bool is_chunked_transfer_encoding(const Headers &headers) { - return compare_case_ignore( - get_header_value(headers, "Transfer-Encoding", 0, ""), "chunked"); -} - -template -bool prepare_content_receiver(T &x, int &status, - ContentReceiverWithProgress receiver, - bool decompress, U callback) { - if (decompress) { - std::string encoding = x.get_header_value("Content-Encoding"); - std::unique_ptr decompressor; - - if (encoding == "gzip" || encoding == "deflate") { -#ifdef CPPHTTPLIB_ZLIB_SUPPORT - decompressor = detail::make_unique(); -#else - status = StatusCode::UnsupportedMediaType_415; - return false; -#endif - } else if (encoding.find("br") != std::string::npos) { -#ifdef CPPHTTPLIB_BROTLI_SUPPORT - decompressor = detail::make_unique(); -#else - status = StatusCode::UnsupportedMediaType_415; - return false; -#endif - } - - if (decompressor) { - if (decompressor->is_valid()) { - ContentReceiverWithProgress out = [&](const char *buf, size_t n, - uint64_t off, uint64_t len) { - return decompressor->decompress(buf, n, - [&](const char *buf2, size_t n2) { - return receiver(buf2, n2, off, len); - }); - }; - return callback(std::move(out)); - } else { - status = StatusCode::InternalServerError_500; - return false; - } - } - } - - ContentReceiverWithProgress out = [&](const char *buf, size_t n, uint64_t off, - uint64_t len) { - return receiver(buf, n, off, len); - }; - return callback(std::move(out)); -} - -template -bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status, - Progress progress, ContentReceiverWithProgress receiver, - bool decompress) { - return prepare_content_receiver( - x, status, std::move(receiver), decompress, - [&](const ContentReceiverWithProgress &out) { - auto ret = true; - auto exceed_payload_max_length = false; - - if (is_chunked_transfer_encoding(x.headers)) { - ret = read_content_chunked(strm, x, out); - } else if (!has_header(x.headers, "Content-Length")) { - ret = read_content_without_length(strm, out); - } else { - auto len = get_header_value_u64(x.headers, "Content-Length", 0, 0); - if (len > payload_max_length) { - exceed_payload_max_length = true; - skip_content_with_length(strm, len); - ret = false; - } else if (len > 0) { - ret = read_content_with_length(strm, len, std::move(progress), out); - } - } - - if (!ret) { - status = exceed_payload_max_length ? StatusCode::PayloadTooLarge_413 - : StatusCode::BadRequest_400; - } - return ret; - }); -} // namespace detail - -inline ssize_t write_headers(Stream &strm, const Headers &headers) { - ssize_t write_len = 0; - for (const auto &x : headers) { - auto len = - strm.write_format("%s: %s\r\n", x.first.c_str(), x.second.c_str()); - if (len < 0) { return len; } - write_len += len; - } - auto len = strm.write("\r\n"); - if (len < 0) { return len; } - write_len += len; - return write_len; -} - -inline bool write_data(Stream &strm, const char *d, size_t l) { - size_t offset = 0; - while (offset < l) { - auto length = strm.write(d + offset, l - offset); - if (length < 0) { return false; } - offset += static_cast(length); - } - return true; -} - -template -inline bool write_content(Stream &strm, const ContentProvider &content_provider, - size_t offset, size_t length, T is_shutting_down, - Error &error) { - size_t end_offset = offset + length; - auto ok = true; - DataSink data_sink; - - data_sink.write = [&](const char *d, size_t l) -> bool { - if (ok) { - if (strm.is_writable() && write_data(strm, d, l)) { - offset += l; - } else { - ok = false; - } - } - return ok; - }; - - data_sink.is_writable = [&]() -> bool { return strm.is_writable(); }; - - while (offset < end_offset && !is_shutting_down()) { - if (!strm.is_writable()) { - error = Error::Write; - return false; - } else if (!content_provider(offset, end_offset - offset, data_sink)) { - error = Error::Canceled; - return false; - } else if (!ok) { - error = Error::Write; - return false; - } - } - - error = Error::Success; - return true; -} - -template -inline bool write_content(Stream &strm, const ContentProvider &content_provider, - size_t offset, size_t length, - const T &is_shutting_down) { - auto error = Error::Success; - return write_content(strm, content_provider, offset, length, is_shutting_down, - error); -} - -template -inline bool -write_content_without_length(Stream &strm, - const ContentProvider &content_provider, - const T &is_shutting_down) { - size_t offset = 0; - auto data_available = true; - auto ok = true; - DataSink data_sink; - - data_sink.write = [&](const char *d, size_t l) -> bool { - if (ok) { - offset += l; - if (!strm.is_writable() || !write_data(strm, d, l)) { ok = false; } - } - return ok; - }; - - data_sink.is_writable = [&]() -> bool { return strm.is_writable(); }; - - data_sink.done = [&](void) { data_available = false; }; - - while (data_available && !is_shutting_down()) { - if (!strm.is_writable()) { - return false; - } else if (!content_provider(offset, 0, data_sink)) { - return false; - } else if (!ok) { - return false; - } - } - return true; -} - -template -inline bool -write_content_chunked(Stream &strm, const ContentProvider &content_provider, - const T &is_shutting_down, U &compressor, Error &error) { - size_t offset = 0; - auto data_available = true; - auto ok = true; - DataSink data_sink; - - data_sink.write = [&](const char *d, size_t l) -> bool { - if (ok) { - data_available = l > 0; - offset += l; - - std::string payload; - if (compressor.compress(d, l, false, - [&](const char *data, size_t data_len) { - payload.append(data, data_len); - return true; - })) { - if (!payload.empty()) { - // Emit chunked response header and footer for each chunk - auto chunk = - from_i_to_hex(payload.size()) + "\r\n" + payload + "\r\n"; - if (!strm.is_writable() || - !write_data(strm, chunk.data(), chunk.size())) { - ok = false; - } - } - } else { - ok = false; - } - } - return ok; - }; - - data_sink.is_writable = [&]() -> bool { return strm.is_writable(); }; - - auto done_with_trailer = [&](const Headers *trailer) { - if (!ok) { return; } - - data_available = false; - - std::string payload; - if (!compressor.compress(nullptr, 0, true, - [&](const char *data, size_t data_len) { - payload.append(data, data_len); - return true; - })) { - ok = false; - return; - } - - if (!payload.empty()) { - // Emit chunked response header and footer for each chunk - auto chunk = from_i_to_hex(payload.size()) + "\r\n" + payload + "\r\n"; - if (!strm.is_writable() || - !write_data(strm, chunk.data(), chunk.size())) { - ok = false; - return; - } - } - - static const std::string done_marker("0\r\n"); - if (!write_data(strm, done_marker.data(), done_marker.size())) { - ok = false; - } - - // Trailer - if (trailer) { - for (const auto &kv : *trailer) { - std::string field_line = kv.first + ": " + kv.second + "\r\n"; - if (!write_data(strm, field_line.data(), field_line.size())) { - ok = false; - } - } - } - - static const std::string crlf("\r\n"); - if (!write_data(strm, crlf.data(), crlf.size())) { ok = false; } - }; - - data_sink.done = [&](void) { done_with_trailer(nullptr); }; - - data_sink.done_with_trailer = [&](const Headers &trailer) { - done_with_trailer(&trailer); - }; - - while (data_available && !is_shutting_down()) { - if (!strm.is_writable()) { - error = Error::Write; - return false; - } else if (!content_provider(offset, 0, data_sink)) { - error = Error::Canceled; - return false; - } else if (!ok) { - error = Error::Write; - return false; - } - } - - error = Error::Success; - return true; -} - -template -inline bool write_content_chunked(Stream &strm, - const ContentProvider &content_provider, - const T &is_shutting_down, U &compressor) { - auto error = Error::Success; - return write_content_chunked(strm, content_provider, is_shutting_down, - compressor, error); -} - -template -inline bool redirect(T &cli, Request &req, Response &res, - const std::string &path, const std::string &location, - Error &error) { - Request new_req = req; - new_req.path = path; - new_req.redirect_count_ -= 1; - - if (res.status == StatusCode::SeeOther_303 && - (req.method != "GET" && req.method != "HEAD")) { - new_req.method = "GET"; - new_req.body.clear(); - new_req.headers.clear(); - } - - Response new_res; - - auto ret = cli.send(new_req, new_res, error); - if (ret) { - req = new_req; - res = new_res; - - if (res.location.empty()) { res.location = location; } - } - return ret; -} - -inline std::string params_to_query_str(const Params ¶ms) { - std::string query; - - for (auto it = params.begin(); it != params.end(); ++it) { - if (it != params.begin()) { query += "&"; } - query += it->first; - query += "="; - query += encode_query_param(it->second); - } - return query; -} - -inline void parse_query_text(const std::string &s, Params ¶ms) { - std::set cache; - split(s.data(), s.data() + s.size(), '&', [&](const char *b, const char *e) { - std::string kv(b, e); - if (cache.find(kv) != cache.end()) { return; } - cache.insert(kv); - - std::string key; - std::string val; - split(b, e, '=', [&](const char *b2, const char *e2) { - if (key.empty()) { - key.assign(b2, e2); - } else { - val.assign(b2, e2); - } - }); - - if (!key.empty()) { - params.emplace(decode_url(key, true), decode_url(val, true)); - } - }); -} - -inline bool parse_multipart_boundary(const std::string &content_type, - std::string &boundary) { - auto boundary_keyword = "boundary="; - auto pos = content_type.find(boundary_keyword); - if (pos == std::string::npos) { return false; } - auto end = content_type.find(';', pos); - auto beg = pos + strlen(boundary_keyword); - boundary = trim_double_quotes_copy(content_type.substr(beg, end - beg)); - return !boundary.empty(); -} - -inline void parse_disposition_params(const std::string &s, Params ¶ms) { - std::set cache; - split(s.data(), s.data() + s.size(), ';', [&](const char *b, const char *e) { - std::string kv(b, e); - if (cache.find(kv) != cache.end()) { return; } - cache.insert(kv); - - std::string key; - std::string val; - split(b, e, '=', [&](const char *b2, const char *e2) { - if (key.empty()) { - key.assign(b2, e2); - } else { - val.assign(b2, e2); - } - }); - - if (!key.empty()) { - params.emplace(trim_double_quotes_copy((key)), - trim_double_quotes_copy((val))); - } - }); -} - -#ifdef CPPHTTPLIB_NO_EXCEPTIONS -inline bool parse_range_header(const std::string &s, Ranges &ranges) { -#else -inline bool parse_range_header(const std::string &s, Ranges &ranges) try { -#endif - static auto re_first_range = std::regex(R"(bytes=(\d*-\d*(?:,\s*\d*-\d*)*))"); - std::smatch m; - if (std::regex_match(s, m, re_first_range)) { - auto pos = static_cast(m.position(1)); - auto len = static_cast(m.length(1)); - auto all_valid_ranges = true; - split(&s[pos], &s[pos + len], ',', [&](const char *b, const char *e) { - if (!all_valid_ranges) { return; } - static auto re_another_range = std::regex(R"(\s*(\d*)-(\d*))"); - std::cmatch cm; - if (std::regex_match(b, e, cm, re_another_range)) { - ssize_t first = -1; - if (!cm.str(1).empty()) { - first = static_cast(std::stoll(cm.str(1))); - } - - ssize_t last = -1; - if (!cm.str(2).empty()) { - last = static_cast(std::stoll(cm.str(2))); - } - - if (first != -1 && last != -1 && first > last) { - all_valid_ranges = false; - return; - } - ranges.emplace_back(std::make_pair(first, last)); - } - }); - return all_valid_ranges; - } - return false; -#ifdef CPPHTTPLIB_NO_EXCEPTIONS -} -#else -} catch (...) { return false; } -#endif - -class MultipartFormDataParser { -public: - MultipartFormDataParser() = default; - - void set_boundary(std::string &&boundary) { - boundary_ = boundary; - dash_boundary_crlf_ = dash_ + boundary_ + crlf_; - crlf_dash_boundary_ = crlf_ + dash_ + boundary_; - } - - bool is_valid() const { return is_valid_; } - - bool parse(const char *buf, size_t n, const ContentReceiver &content_callback, - const MultipartContentHeader &header_callback) { - - buf_append(buf, n); - - while (buf_size() > 0) { - switch (state_) { - case 0: { // Initial boundary - buf_erase(buf_find(dash_boundary_crlf_)); - if (dash_boundary_crlf_.size() > buf_size()) { return true; } - if (!buf_start_with(dash_boundary_crlf_)) { return false; } - buf_erase(dash_boundary_crlf_.size()); - state_ = 1; - break; - } - case 1: { // New entry - clear_file_info(); - state_ = 2; - break; - } - case 2: { // Headers - auto pos = buf_find(crlf_); - if (pos > CPPHTTPLIB_HEADER_MAX_LENGTH) { return false; } - while (pos < buf_size()) { - // Empty line - if (pos == 0) { - if (!header_callback(file_)) { - is_valid_ = false; - return false; - } - buf_erase(crlf_.size()); - state_ = 3; - break; - } - - const auto header = buf_head(pos); - - if (!parse_header(header.data(), header.data() + header.size(), - [&](std::string &&, std::string &&) {})) { - is_valid_ = false; - return false; - } - - static const std::string header_content_type = "Content-Type:"; - - if (start_with_case_ignore(header, header_content_type)) { - file_.content_type = - trim_copy(header.substr(header_content_type.size())); - } else { - static const std::regex re_content_disposition( - R"~(^Content-Disposition:\s*form-data;\s*(.*)$)~", - std::regex_constants::icase); - - std::smatch m; - if (std::regex_match(header, m, re_content_disposition)) { - Params params; - parse_disposition_params(m[1], params); - - auto it = params.find("name"); - if (it != params.end()) { - file_.name = it->second; - } else { - is_valid_ = false; - return false; - } - - it = params.find("filename"); - if (it != params.end()) { file_.filename = it->second; } - - it = params.find("filename*"); - if (it != params.end()) { - // Only allow UTF-8 enconnding... - static const std::regex re_rfc5987_encoding( - R"~(^UTF-8''(.+?)$)~", std::regex_constants::icase); - - std::smatch m2; - if (std::regex_match(it->second, m2, re_rfc5987_encoding)) { - file_.filename = decode_url(m2[1], false); // override... - } else { - is_valid_ = false; - return false; - } - } - } - } - buf_erase(pos + crlf_.size()); - pos = buf_find(crlf_); - } - if (state_ != 3) { return true; } - break; - } - case 3: { // Body - if (crlf_dash_boundary_.size() > buf_size()) { return true; } - auto pos = buf_find(crlf_dash_boundary_); - if (pos < buf_size()) { - if (!content_callback(buf_data(), pos)) { - is_valid_ = false; - return false; - } - buf_erase(pos + crlf_dash_boundary_.size()); - state_ = 4; - } else { - auto len = buf_size() - crlf_dash_boundary_.size(); - if (len > 0) { - if (!content_callback(buf_data(), len)) { - is_valid_ = false; - return false; - } - buf_erase(len); - } - return true; - } - break; - } - case 4: { // Boundary - if (crlf_.size() > buf_size()) { return true; } - if (buf_start_with(crlf_)) { - buf_erase(crlf_.size()); - state_ = 1; - } else { - if (dash_.size() > buf_size()) { return true; } - if (buf_start_with(dash_)) { - buf_erase(dash_.size()); - is_valid_ = true; - buf_erase(buf_size()); // Remove epilogue - } else { - return true; - } - } - break; - } - } - } - - return true; - } - -private: - void clear_file_info() { - file_.name.clear(); - file_.filename.clear(); - file_.content_type.clear(); - } - - bool start_with_case_ignore(const std::string &a, - const std::string &b) const { - if (a.size() < b.size()) { return false; } - for (size_t i = 0; i < b.size(); i++) { - if (::tolower(a[i]) != ::tolower(b[i])) { return false; } - } - return true; - } - - const std::string dash_ = "--"; - const std::string crlf_ = "\r\n"; - std::string boundary_; - std::string dash_boundary_crlf_; - std::string crlf_dash_boundary_; - - size_t state_ = 0; - bool is_valid_ = false; - MultipartFormData file_; - - // Buffer - bool start_with(const std::string &a, size_t spos, size_t epos, - const std::string &b) const { - if (epos - spos < b.size()) { return false; } - for (size_t i = 0; i < b.size(); i++) { - if (a[i + spos] != b[i]) { return false; } - } - return true; - } - - size_t buf_size() const { return buf_epos_ - buf_spos_; } - - const char *buf_data() const { return &buf_[buf_spos_]; } - - std::string buf_head(size_t l) const { return buf_.substr(buf_spos_, l); } - - bool buf_start_with(const std::string &s) const { - return start_with(buf_, buf_spos_, buf_epos_, s); - } - - size_t buf_find(const std::string &s) const { - auto c = s.front(); - - size_t off = buf_spos_; - while (off < buf_epos_) { - auto pos = off; - while (true) { - if (pos == buf_epos_) { return buf_size(); } - if (buf_[pos] == c) { break; } - pos++; - } - - auto remaining_size = buf_epos_ - pos; - if (s.size() > remaining_size) { return buf_size(); } - - if (start_with(buf_, pos, buf_epos_, s)) { return pos - buf_spos_; } - - off = pos + 1; - } - - return buf_size(); - } - - void buf_append(const char *data, size_t n) { - auto remaining_size = buf_size(); - if (remaining_size > 0 && buf_spos_ > 0) { - for (size_t i = 0; i < remaining_size; i++) { - buf_[i] = buf_[buf_spos_ + i]; - } - } - buf_spos_ = 0; - buf_epos_ = remaining_size; - - if (remaining_size + n > buf_.size()) { buf_.resize(remaining_size + n); } - - for (size_t i = 0; i < n; i++) { - buf_[buf_epos_ + i] = data[i]; - } - buf_epos_ += n; - } - - void buf_erase(size_t size) { buf_spos_ += size; } - - std::string buf_; - size_t buf_spos_ = 0; - size_t buf_epos_ = 0; -}; - -inline std::string to_lower(const char *beg, const char *end) { - std::string out; - auto it = beg; - while (it != end) { - out += static_cast(::tolower(*it)); - it++; - } - return out; -} - -inline std::string make_multipart_data_boundary() { - static const char data[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; - - // std::random_device might actually be deterministic on some - // platforms, but due to lack of support in the c++ standard library, - // doing better requires either some ugly hacks or breaking portability. - std::random_device seed_gen; - - // Request 128 bits of entropy for initialization - std::seed_seq seed_sequence{seed_gen(), seed_gen(), seed_gen(), seed_gen()}; - std::mt19937 engine(seed_sequence); - - std::string result = "--cpp-httplib-multipart-data-"; - - for (auto i = 0; i < 16; i++) { - result += data[engine() % (sizeof(data) - 1)]; - } - - return result; -} - -inline bool is_multipart_boundary_chars_valid(const std::string &boundary) { - auto valid = true; - for (size_t i = 0; i < boundary.size(); i++) { - auto c = boundary[i]; - if (!std::isalnum(c) && c != '-' && c != '_') { - valid = false; - break; - } - } - return valid; -} - -template -inline std::string -serialize_multipart_formdata_item_begin(const T &item, - const std::string &boundary) { - std::string body = "--" + boundary + "\r\n"; - body += "Content-Disposition: form-data; name=\"" + item.name + "\""; - if (!item.filename.empty()) { - body += "; filename=\"" + item.filename + "\""; - } - body += "\r\n"; - if (!item.content_type.empty()) { - body += "Content-Type: " + item.content_type + "\r\n"; - } - body += "\r\n"; - - return body; -} - -inline std::string serialize_multipart_formdata_item_end() { return "\r\n"; } - -inline std::string -serialize_multipart_formdata_finish(const std::string &boundary) { - return "--" + boundary + "--\r\n"; -} - -inline std::string -serialize_multipart_formdata_get_content_type(const std::string &boundary) { - return "multipart/form-data; boundary=" + boundary; -} - -inline std::string -serialize_multipart_formdata(const MultipartFormDataItems &items, - const std::string &boundary, bool finish = true) { - std::string body; - - for (const auto &item : items) { - body += serialize_multipart_formdata_item_begin(item, boundary); - body += item.content + serialize_multipart_formdata_item_end(); - } - - if (finish) { body += serialize_multipart_formdata_finish(boundary); } - - return body; -} - -inline std::pair -get_range_offset_and_length(const Request &req, size_t content_length, - size_t index) { - auto r = req.ranges[index]; - - if (r.first == -1 && r.second == -1) { - return std::make_pair(0, content_length); - } - - auto slen = static_cast(content_length); - - if (r.first == -1) { - r.first = (std::max)(static_cast(0), slen - r.second); - r.second = slen - 1; - } - - if (r.second == -1) { r.second = slen - 1; } - return std::make_pair(r.first, static_cast(r.second - r.first) + 1); -} - -inline std::string -make_content_range_header_field(const std::pair &range, - size_t content_length) { - std::string field = "bytes "; - if (range.first != -1) { field += std::to_string(range.first); } - field += "-"; - if (range.second != -1) { field += std::to_string(range.second); } - field += "/"; - field += std::to_string(content_length); - return field; -} - -template -bool process_multipart_ranges_data(const Request &req, Response &res, - const std::string &boundary, - const std::string &content_type, - SToken stoken, CToken ctoken, - Content content) { - for (size_t i = 0; i < req.ranges.size(); i++) { - ctoken("--"); - stoken(boundary); - ctoken("\r\n"); - if (!content_type.empty()) { - ctoken("Content-Type: "); - stoken(content_type); - ctoken("\r\n"); - } - - ctoken("Content-Range: "); - const auto &range = req.ranges[i]; - stoken(make_content_range_header_field(range, res.content_length_)); - ctoken("\r\n"); - ctoken("\r\n"); - - auto offsets = get_range_offset_and_length(req, res.content_length_, i); - auto offset = offsets.first; - auto length = offsets.second; - if (!content(offset, length)) { return false; } - ctoken("\r\n"); - } - - ctoken("--"); - stoken(boundary); - ctoken("--"); - - return true; -} - -inline bool make_multipart_ranges_data(const Request &req, Response &res, - const std::string &boundary, - const std::string &content_type, - std::string &data) { - return process_multipart_ranges_data( - req, res, boundary, content_type, - [&](const std::string &token) { data += token; }, - [&](const std::string &token) { data += token; }, - [&](size_t offset, size_t length) { - if (offset < res.body.size()) { - data += res.body.substr(offset, length); - return true; - } - return false; - }); -} - -inline size_t -get_multipart_ranges_data_length(const Request &req, Response &res, - const std::string &boundary, - const std::string &content_type) { - size_t data_length = 0; - - process_multipart_ranges_data( - req, res, boundary, content_type, - [&](const std::string &token) { data_length += token.size(); }, - [&](const std::string &token) { data_length += token.size(); }, - [&](size_t /*offset*/, size_t length) { - data_length += length; - return true; - }); - - return data_length; -} - -template -inline bool write_multipart_ranges_data(Stream &strm, const Request &req, - Response &res, - const std::string &boundary, - const std::string &content_type, - const T &is_shutting_down) { - return process_multipart_ranges_data( - req, res, boundary, content_type, - [&](const std::string &token) { strm.write(token); }, - [&](const std::string &token) { strm.write(token); }, - [&](size_t offset, size_t length) { - return write_content(strm, res.content_provider_, offset, length, - is_shutting_down); - }); -} - -inline std::pair -get_range_offset_and_length(const Request &req, const Response &res, - size_t index) { - auto r = req.ranges[index]; - - if (r.second == -1) { - r.second = static_cast(res.content_length_) - 1; - } - - return std::make_pair(r.first, r.second - r.first + 1); -} - -inline bool expect_content(const Request &req) { - if (req.method == "POST" || req.method == "PUT" || req.method == "PATCH" || - req.method == "PRI" || req.method == "DELETE") { - return true; - } - // TODO: check if Content-Length is set - return false; -} - -inline bool has_crlf(const std::string &s) { - auto p = s.c_str(); - while (*p) { - if (*p == '\r' || *p == '\n') { return true; } - p++; - } - return false; -} - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline std::string message_digest(const std::string &s, const EVP_MD *algo) { - auto context = std::unique_ptr( - EVP_MD_CTX_new(), EVP_MD_CTX_free); - - unsigned int hash_length = 0; - unsigned char hash[EVP_MAX_MD_SIZE]; - - EVP_DigestInit_ex(context.get(), algo, nullptr); - EVP_DigestUpdate(context.get(), s.c_str(), s.size()); - EVP_DigestFinal_ex(context.get(), hash, &hash_length); - - std::stringstream ss; - for (auto i = 0u; i < hash_length; ++i) { - ss << std::hex << std::setw(2) << std::setfill('0') - << static_cast(hash[i]); - } - - return ss.str(); -} - -inline std::string MD5(const std::string &s) { - return message_digest(s, EVP_md5()); -} - -inline std::string SHA_256(const std::string &s) { - return message_digest(s, EVP_sha256()); -} - -inline std::string SHA_512(const std::string &s) { - return message_digest(s, EVP_sha512()); -} -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -#ifdef _WIN32 -// NOTE: This code came up with the following stackoverflow post: -// https://stackoverflow.com/questions/9507184/can-openssl-on-windows-use-the-system-certificate-store -inline bool load_system_certs_on_windows(X509_STORE *store) { - auto hStore = CertOpenSystemStoreW((HCRYPTPROV_LEGACY)NULL, L"ROOT"); - if (!hStore) { return false; } - - auto result = false; - PCCERT_CONTEXT pContext = NULL; - while ((pContext = CertEnumCertificatesInStore(hStore, pContext)) != - nullptr) { - auto encoded_cert = - static_cast(pContext->pbCertEncoded); - - auto x509 = d2i_X509(NULL, &encoded_cert, pContext->cbCertEncoded); - if (x509) { - X509_STORE_add_cert(store, x509); - X509_free(x509); - result = true; - } - } - - CertFreeCertificateContext(pContext); - CertCloseStore(hStore, 0); - - return result; -} -#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__) -#if TARGET_OS_OSX -template -using CFObjectPtr = - std::unique_ptr::type, void (*)(CFTypeRef)>; - -inline void cf_object_ptr_deleter(CFTypeRef obj) { - if (obj) { CFRelease(obj); } -} - -inline bool retrieve_certs_from_keychain(CFObjectPtr &certs) { - CFStringRef keys[] = {kSecClass, kSecMatchLimit, kSecReturnRef}; - CFTypeRef values[] = {kSecClassCertificate, kSecMatchLimitAll, - kCFBooleanTrue}; - - CFObjectPtr query( - CFDictionaryCreate(nullptr, reinterpret_cast(keys), values, - sizeof(keys) / sizeof(keys[0]), - &kCFTypeDictionaryKeyCallBacks, - &kCFTypeDictionaryValueCallBacks), - cf_object_ptr_deleter); - - if (!query) { return false; } - - CFTypeRef security_items = nullptr; - if (SecItemCopyMatching(query.get(), &security_items) != errSecSuccess || - CFArrayGetTypeID() != CFGetTypeID(security_items)) { - return false; - } - - certs.reset(reinterpret_cast(security_items)); - return true; -} - -inline bool retrieve_root_certs_from_keychain(CFObjectPtr &certs) { - CFArrayRef root_security_items = nullptr; - if (SecTrustCopyAnchorCertificates(&root_security_items) != errSecSuccess) { - return false; - } - - certs.reset(root_security_items); - return true; -} - -inline bool add_certs_to_x509_store(CFArrayRef certs, X509_STORE *store) { - auto result = false; - for (auto i = 0; i < CFArrayGetCount(certs); ++i) { - const auto cert = reinterpret_cast( - CFArrayGetValueAtIndex(certs, i)); - - if (SecCertificateGetTypeID() != CFGetTypeID(cert)) { continue; } - - CFDataRef cert_data = nullptr; - if (SecItemExport(cert, kSecFormatX509Cert, 0, nullptr, &cert_data) != - errSecSuccess) { - continue; - } - - CFObjectPtr cert_data_ptr(cert_data, cf_object_ptr_deleter); - - auto encoded_cert = static_cast( - CFDataGetBytePtr(cert_data_ptr.get())); - - auto x509 = - d2i_X509(NULL, &encoded_cert, CFDataGetLength(cert_data_ptr.get())); - - if (x509) { - X509_STORE_add_cert(store, x509); - X509_free(x509); - result = true; - } - } - - return result; -} - -inline bool load_system_certs_on_macos(X509_STORE *store) { - auto result = false; - CFObjectPtr certs(nullptr, cf_object_ptr_deleter); - if (retrieve_certs_from_keychain(certs) && certs) { - result = add_certs_to_x509_store(certs.get(), store); - } - - if (retrieve_root_certs_from_keychain(certs) && certs) { - result = add_certs_to_x509_store(certs.get(), store) || result; - } - - return result; -} -#endif // TARGET_OS_OSX -#endif // _WIN32 -#endif // CPPHTTPLIB_OPENSSL_SUPPORT - -#ifdef _WIN32 -class WSInit { -public: - WSInit() { - WSADATA wsaData; - if (WSAStartup(0x0002, &wsaData) == 0) is_valid_ = true; - } - - ~WSInit() { - if (is_valid_) WSACleanup(); - } - - bool is_valid_ = false; -}; - -static WSInit wsinit_; -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline std::pair make_digest_authentication_header( - const Request &req, const std::map &auth, - size_t cnonce_count, const std::string &cnonce, const std::string &username, - const std::string &password, bool is_proxy = false) { - std::string nc; - { - std::stringstream ss; - ss << std::setfill('0') << std::setw(8) << std::hex << cnonce_count; - nc = ss.str(); - } - - std::string qop; - if (auth.find("qop") != auth.end()) { - qop = auth.at("qop"); - if (qop.find("auth-int") != std::string::npos) { - qop = "auth-int"; - } else if (qop.find("auth") != std::string::npos) { - qop = "auth"; - } else { - qop.clear(); - } - } - - std::string algo = "MD5"; - if (auth.find("algorithm") != auth.end()) { algo = auth.at("algorithm"); } - - std::string response; - { - auto H = algo == "SHA-256" ? detail::SHA_256 - : algo == "SHA-512" ? detail::SHA_512 - : detail::MD5; - - auto A1 = username + ":" + auth.at("realm") + ":" + password; - - auto A2 = req.method + ":" + req.path; - if (qop == "auth-int") { A2 += ":" + H(req.body); } - - if (qop.empty()) { - response = H(H(A1) + ":" + auth.at("nonce") + ":" + H(A2)); - } else { - response = H(H(A1) + ":" + auth.at("nonce") + ":" + nc + ":" + cnonce + - ":" + qop + ":" + H(A2)); - } - } - - auto opaque = (auth.find("opaque") != auth.end()) ? auth.at("opaque") : ""; - - auto field = "Digest username=\"" + username + "\", realm=\"" + - auth.at("realm") + "\", nonce=\"" + auth.at("nonce") + - "\", uri=\"" + req.path + "\", algorithm=" + algo + - (qop.empty() ? ", response=\"" - : ", qop=" + qop + ", nc=" + nc + ", cnonce=\"" + - cnonce + "\", response=\"") + - response + "\"" + - (opaque.empty() ? "" : ", opaque=\"" + opaque + "\""); - - auto key = is_proxy ? "Proxy-Authorization" : "Authorization"; - return std::make_pair(key, field); -} -#endif - -inline bool parse_www_authenticate(const Response &res, - std::map &auth, - bool is_proxy) { - auto auth_key = is_proxy ? "Proxy-Authenticate" : "WWW-Authenticate"; - if (res.has_header(auth_key)) { - static auto re = std::regex(R"~((?:(?:,\s*)?(.+?)=(?:"(.*?)"|([^,]*))))~"); - auto s = res.get_header_value(auth_key); - auto pos = s.find(' '); - if (pos != std::string::npos) { - auto type = s.substr(0, pos); - if (type == "Basic") { - return false; - } else if (type == "Digest") { - s = s.substr(pos + 1); - auto beg = std::sregex_iterator(s.begin(), s.end(), re); - for (auto i = beg; i != std::sregex_iterator(); ++i) { - const auto &m = *i; - auto key = s.substr(static_cast(m.position(1)), - static_cast(m.length(1))); - auto val = m.length(2) > 0 - ? s.substr(static_cast(m.position(2)), - static_cast(m.length(2))) - : s.substr(static_cast(m.position(3)), - static_cast(m.length(3))); - auth[key] = val; - } - return true; - } - } - } - return false; -} - -// https://stackoverflow.com/questions/440133/how-do-i-create-a-random-alpha-numeric-string-in-c/440240#answer-440240 -inline std::string random_string(size_t length) { - auto randchar = []() -> char { - const char charset[] = "0123456789" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz"; - const size_t max_index = (sizeof(charset) - 1); - return charset[static_cast(std::rand()) % max_index]; - }; - std::string str(length, 0); - std::generate_n(str.begin(), length, randchar); - return str; -} - -class ContentProviderAdapter { -public: - explicit ContentProviderAdapter( - ContentProviderWithoutLength &&content_provider) - : content_provider_(content_provider) {} - - bool operator()(size_t offset, size_t, DataSink &sink) { - return content_provider_(offset, sink); - } - -private: - ContentProviderWithoutLength content_provider_; -}; - -} // namespace detail - -inline std::string hosted_at(const std::string &hostname) { - std::vector addrs; - hosted_at(hostname, addrs); - if (addrs.empty()) { return std::string(); } - return addrs[0]; -} - -inline void hosted_at(const std::string &hostname, - std::vector &addrs) { - struct addrinfo hints; - struct addrinfo *result; - - memset(&hints, 0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = 0; - - if (getaddrinfo(hostname.c_str(), nullptr, &hints, &result)) { -#if defined __linux__ && !defined __ANDROID__ - res_init(); -#endif - return; - } - - for (auto rp = result; rp; rp = rp->ai_next) { - const auto &addr = - *reinterpret_cast(rp->ai_addr); - std::string ip; - auto dummy = -1; - if (detail::get_ip_and_port(addr, sizeof(struct sockaddr_storage), ip, - dummy)) { - addrs.push_back(ip); - } - } - - freeaddrinfo(result); -} - -inline std::string append_query_params(const std::string &path, - const Params ¶ms) { - std::string path_with_query = path; - const static std::regex re("[^?]+\\?.*"); - auto delm = std::regex_match(path, re) ? '&' : '?'; - path_with_query += delm + detail::params_to_query_str(params); - return path_with_query; -} - -// Header utilities -inline std::pair make_range_header(Ranges ranges) { - std::string field = "bytes="; - auto i = 0; - for (auto r : ranges) { - if (i != 0) { field += ", "; } - if (r.first != -1) { field += std::to_string(r.first); } - field += '-'; - if (r.second != -1) { field += std::to_string(r.second); } - i++; - } - return std::make_pair("Range", std::move(field)); -} - -inline std::pair -make_basic_authentication_header(const std::string &username, - const std::string &password, bool is_proxy) { - auto field = "Basic " + detail::base64_encode(username + ":" + password); - auto key = is_proxy ? "Proxy-Authorization" : "Authorization"; - return std::make_pair(key, std::move(field)); -} - -inline std::pair -make_bearer_token_authentication_header(const std::string &token, - bool is_proxy = false) { - auto field = "Bearer " + token; - auto key = is_proxy ? "Proxy-Authorization" : "Authorization"; - return std::make_pair(key, std::move(field)); -} - -// Request implementation -inline bool Request::has_header(const std::string &key) const { - return detail::has_header(headers, key); -} - -inline std::string Request::get_header_value(const std::string &key, - size_t id) const { - return detail::get_header_value(headers, key, id, ""); -} - -inline size_t Request::get_header_value_count(const std::string &key) const { - auto r = headers.equal_range(key); - return static_cast(std::distance(r.first, r.second)); -} - -inline void Request::set_header(const std::string &key, - const std::string &val) { - if (!detail::has_crlf(key) && !detail::has_crlf(val)) { - headers.emplace(key, val); - } -} - -inline bool Request::has_param(const std::string &key) const { - return params.find(key) != params.end(); -} - -inline std::string Request::get_param_value(const std::string &key, - size_t id) const { - auto rng = params.equal_range(key); - auto it = rng.first; - std::advance(it, static_cast(id)); - if (it != rng.second) { return it->second; } - return std::string(); -} - -inline size_t Request::get_param_value_count(const std::string &key) const { - auto r = params.equal_range(key); - return static_cast(std::distance(r.first, r.second)); -} - -inline bool Request::is_multipart_form_data() const { - const auto &content_type = get_header_value("Content-Type"); - return !content_type.rfind("multipart/form-data", 0); -} - -inline bool Request::has_file(const std::string &key) const { - return files.find(key) != files.end(); -} - -inline MultipartFormData Request::get_file_value(const std::string &key) const { - auto it = files.find(key); - if (it != files.end()) { return it->second; } - return MultipartFormData(); -} - -inline std::vector -Request::get_file_values(const std::string &key) const { - std::vector values; - auto rng = files.equal_range(key); - for (auto it = rng.first; it != rng.second; it++) { - values.push_back(it->second); - } - return values; -} - -// Response implementation -inline bool Response::has_header(const std::string &key) const { - return headers.find(key) != headers.end(); -} - -inline std::string Response::get_header_value(const std::string &key, - size_t id) const { - return detail::get_header_value(headers, key, id, ""); -} - -inline size_t Response::get_header_value_count(const std::string &key) const { - auto r = headers.equal_range(key); - return static_cast(std::distance(r.first, r.second)); -} - -inline void Response::set_header(const std::string &key, - const std::string &val) { - if (!detail::has_crlf(key) && !detail::has_crlf(val)) { - headers.emplace(key, val); - } -} - -inline void Response::set_redirect(const std::string &url, int stat) { - if (!detail::has_crlf(url)) { - set_header("Location", url); - if (300 <= stat && stat < 400) { - this->status = stat; - } else { - this->status = StatusCode::Found_302; - } - } -} - -inline void Response::set_content(const char *s, size_t n, - const std::string &content_type) { - body.assign(s, n); - - auto rng = headers.equal_range("Content-Type"); - headers.erase(rng.first, rng.second); - set_header("Content-Type", content_type); -} - -inline void Response::set_content(const std::string &s, - const std::string &content_type) { - set_content(s.data(), s.size(), content_type); -} - -inline void Response::set_content_provider( - size_t in_length, const std::string &content_type, ContentProvider provider, - ContentProviderResourceReleaser resource_releaser) { - set_header("Content-Type", content_type); - content_length_ = in_length; - if (in_length > 0) { content_provider_ = std::move(provider); } - content_provider_resource_releaser_ = resource_releaser; - is_chunked_content_provider_ = false; -} - -inline void Response::set_content_provider( - const std::string &content_type, ContentProviderWithoutLength provider, - ContentProviderResourceReleaser resource_releaser) { - set_header("Content-Type", content_type); - content_length_ = 0; - content_provider_ = detail::ContentProviderAdapter(std::move(provider)); - content_provider_resource_releaser_ = resource_releaser; - is_chunked_content_provider_ = false; -} - -inline void Response::set_chunked_content_provider( - const std::string &content_type, ContentProviderWithoutLength provider, - ContentProviderResourceReleaser resource_releaser) { - set_header("Content-Type", content_type); - content_length_ = 0; - content_provider_ = detail::ContentProviderAdapter(std::move(provider)); - content_provider_resource_releaser_ = resource_releaser; - is_chunked_content_provider_ = true; -} - -// Result implementation -inline bool Result::has_request_header(const std::string &key) const { - return request_headers_.find(key) != request_headers_.end(); -} - -inline std::string Result::get_request_header_value(const std::string &key, - size_t id) const { - return detail::get_header_value(request_headers_, key, id, ""); -} - -inline size_t -Result::get_request_header_value_count(const std::string &key) const { - auto r = request_headers_.equal_range(key); - return static_cast(std::distance(r.first, r.second)); -} - -// Stream implementation -inline ssize_t Stream::write(const char *ptr) { - return write(ptr, strlen(ptr)); -} - -inline ssize_t Stream::write(const std::string &s) { - return write(s.data(), s.size()); -} - -namespace detail { - -// Socket stream implementation -inline SocketStream::SocketStream(socket_t sock, time_t read_timeout_sec, - time_t read_timeout_usec, - time_t write_timeout_sec, - time_t write_timeout_usec) - : sock_(sock), read_timeout_sec_(read_timeout_sec), - read_timeout_usec_(read_timeout_usec), - write_timeout_sec_(write_timeout_sec), - write_timeout_usec_(write_timeout_usec), read_buff_(read_buff_size_, 0) {} - -inline SocketStream::~SocketStream() = default; - -inline bool SocketStream::is_readable() const { - return select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0; -} - -inline bool SocketStream::is_writable() const { - return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 && - is_socket_alive(sock_); -} - -inline ssize_t SocketStream::read(char *ptr, size_t size) { -#ifdef _WIN32 - size = - (std::min)(size, static_cast((std::numeric_limits::max)())); -#else - size = (std::min)(size, - static_cast((std::numeric_limits::max)())); -#endif - - if (read_buff_off_ < read_buff_content_size_) { - auto remaining_size = read_buff_content_size_ - read_buff_off_; - if (size <= remaining_size) { - memcpy(ptr, read_buff_.data() + read_buff_off_, size); - read_buff_off_ += size; - return static_cast(size); - } else { - memcpy(ptr, read_buff_.data() + read_buff_off_, remaining_size); - read_buff_off_ += remaining_size; - return static_cast(remaining_size); - } - } - - if (!is_readable()) { return -1; } - - read_buff_off_ = 0; - read_buff_content_size_ = 0; - - if (size < read_buff_size_) { - auto n = read_socket(sock_, read_buff_.data(), read_buff_size_, - CPPHTTPLIB_RECV_FLAGS); - if (n <= 0) { - return n; - } else if (n <= static_cast(size)) { - memcpy(ptr, read_buff_.data(), static_cast(n)); - return n; - } else { - memcpy(ptr, read_buff_.data(), size); - read_buff_off_ = size; - read_buff_content_size_ = static_cast(n); - return static_cast(size); - } - } else { - return read_socket(sock_, ptr, size, CPPHTTPLIB_RECV_FLAGS); - } -} - -inline ssize_t SocketStream::write(const char *ptr, size_t size) { - if (!is_writable()) { return -1; } - -#if defined(_WIN32) && !defined(_WIN64) - size = - (std::min)(size, static_cast((std::numeric_limits::max)())); -#endif - - return send_socket(sock_, ptr, size, CPPHTTPLIB_SEND_FLAGS); -} - -inline void SocketStream::get_remote_ip_and_port(std::string &ip, - int &port) const { - return detail::get_remote_ip_and_port(sock_, ip, port); -} - -inline void SocketStream::get_local_ip_and_port(std::string &ip, - int &port) const { - return detail::get_local_ip_and_port(sock_, ip, port); -} - -inline socket_t SocketStream::socket() const { return sock_; } - -// Buffer stream implementation -inline bool BufferStream::is_readable() const { return true; } - -inline bool BufferStream::is_writable() const { return true; } - -inline ssize_t BufferStream::read(char *ptr, size_t size) { -#if defined(_MSC_VER) && _MSC_VER < 1910 - auto len_read = buffer._Copy_s(ptr, size, size, position); -#else - auto len_read = buffer.copy(ptr, size, position); -#endif - position += static_cast(len_read); - return static_cast(len_read); -} - -inline ssize_t BufferStream::write(const char *ptr, size_t size) { - buffer.append(ptr, size); - return static_cast(size); -} - -inline void BufferStream::get_remote_ip_and_port(std::string & /*ip*/, - int & /*port*/) const {} - -inline void BufferStream::get_local_ip_and_port(std::string & /*ip*/, - int & /*port*/) const {} - -inline socket_t BufferStream::socket() const { return 0; } - -inline const std::string &BufferStream::get_buffer() const { return buffer; } - -inline PathParamsMatcher::PathParamsMatcher(const std::string &pattern) { - // One past the last ending position of a path param substring - std::size_t last_param_end = 0; - -#ifndef CPPHTTPLIB_NO_EXCEPTIONS - // Needed to ensure that parameter names are unique during matcher - // construction - // If exceptions are disabled, only last duplicate path - // parameter will be set - std::unordered_set param_name_set; -#endif - - while (true) { - const auto marker_pos = pattern.find(marker, last_param_end); - if (marker_pos == std::string::npos) { break; } - - static_fragments_.push_back( - pattern.substr(last_param_end, marker_pos - last_param_end)); - - const auto param_name_start = marker_pos + 1; - - auto sep_pos = pattern.find(separator, param_name_start); - if (sep_pos == std::string::npos) { sep_pos = pattern.length(); } - - auto param_name = - pattern.substr(param_name_start, sep_pos - param_name_start); - -#ifndef CPPHTTPLIB_NO_EXCEPTIONS - if (param_name_set.find(param_name) != param_name_set.cend()) { - std::string msg = "Encountered path parameter '" + param_name + - "' multiple times in route pattern '" + pattern + "'."; - throw std::invalid_argument(msg); - } -#endif - - param_names_.push_back(std::move(param_name)); - - last_param_end = sep_pos + 1; - } - - if (last_param_end < pattern.length()) { - static_fragments_.push_back(pattern.substr(last_param_end)); - } -} - -inline bool PathParamsMatcher::match(Request &request) const { - request.matches = std::smatch(); - request.path_params.clear(); - request.path_params.reserve(param_names_.size()); - - // One past the position at which the path matched the pattern last time - std::size_t starting_pos = 0; - for (size_t i = 0; i < static_fragments_.size(); ++i) { - const auto &fragment = static_fragments_[i]; - - if (starting_pos + fragment.length() > request.path.length()) { - return false; - } - - // Avoid unnecessary allocation by using strncmp instead of substr + - // comparison - if (std::strncmp(request.path.c_str() + starting_pos, fragment.c_str(), - fragment.length()) != 0) { - return false; - } - - starting_pos += fragment.length(); - - // Should only happen when we have a static fragment after a param - // Example: '/users/:id/subscriptions' - // The 'subscriptions' fragment here does not have a corresponding param - if (i >= param_names_.size()) { continue; } - - auto sep_pos = request.path.find(separator, starting_pos); - if (sep_pos == std::string::npos) { sep_pos = request.path.length(); } - - const auto ¶m_name = param_names_[i]; - - request.path_params.emplace( - param_name, request.path.substr(starting_pos, sep_pos - starting_pos)); - - // Mark everythin up to '/' as matched - starting_pos = sep_pos + 1; - } - // Returns false if the path is longer than the pattern - return starting_pos >= request.path.length(); -} - -inline bool RegexMatcher::match(Request &request) const { - request.path_params.clear(); - return std::regex_match(request.path, request.matches, regex_); -} - -} // namespace detail - -// HTTP server implementation -inline Server::Server() - : new_task_queue( - [] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }) { -#ifndef _WIN32 - signal(SIGPIPE, SIG_IGN); -#endif -} - -inline Server::~Server() = default; - -inline std::unique_ptr -Server::make_matcher(const std::string &pattern) { - if (pattern.find("/:") != std::string::npos) { - return detail::make_unique(pattern); - } else { - return detail::make_unique(pattern); - } -} - -inline Server &Server::Get(const std::string &pattern, Handler handler) { - get_handlers_.emplace_back(make_matcher(pattern), std::move(handler)); - return *this; -} - -inline Server &Server::Post(const std::string &pattern, Handler handler) { - post_handlers_.emplace_back(make_matcher(pattern), std::move(handler)); - return *this; -} - -inline Server &Server::Post(const std::string &pattern, - HandlerWithContentReader handler) { - post_handlers_for_content_reader_.emplace_back(make_matcher(pattern), - std::move(handler)); - return *this; -} - -inline Server &Server::Put(const std::string &pattern, Handler handler) { - put_handlers_.emplace_back(make_matcher(pattern), std::move(handler)); - return *this; -} - -inline Server &Server::Put(const std::string &pattern, - HandlerWithContentReader handler) { - put_handlers_for_content_reader_.emplace_back(make_matcher(pattern), - std::move(handler)); - return *this; -} - -inline Server &Server::Patch(const std::string &pattern, Handler handler) { - patch_handlers_.emplace_back(make_matcher(pattern), std::move(handler)); - return *this; -} - -inline Server &Server::Patch(const std::string &pattern, - HandlerWithContentReader handler) { - patch_handlers_for_content_reader_.emplace_back(make_matcher(pattern), - std::move(handler)); - return *this; -} - -inline Server &Server::Delete(const std::string &pattern, Handler handler) { - delete_handlers_.emplace_back(make_matcher(pattern), std::move(handler)); - return *this; -} - -inline Server &Server::Delete(const std::string &pattern, - HandlerWithContentReader handler) { - delete_handlers_for_content_reader_.emplace_back(make_matcher(pattern), - std::move(handler)); - return *this; -} - -inline Server &Server::Options(const std::string &pattern, Handler handler) { - options_handlers_.emplace_back(make_matcher(pattern), std::move(handler)); - return *this; -} - -inline bool Server::set_base_dir(const std::string &dir, - const std::string &mount_point) { - return set_mount_point(mount_point, dir); -} - -inline bool Server::set_mount_point(const std::string &mount_point, - const std::string &dir, Headers headers) { - if (detail::is_dir(dir)) { - std::string mnt = !mount_point.empty() ? mount_point : "/"; - if (!mnt.empty() && mnt[0] == '/') { - base_dirs_.push_back({mnt, dir, std::move(headers)}); - return true; - } - } - return false; -} - -inline bool Server::remove_mount_point(const std::string &mount_point) { - for (auto it = base_dirs_.begin(); it != base_dirs_.end(); ++it) { - if (it->mount_point == mount_point) { - base_dirs_.erase(it); - return true; - } - } - return false; -} - -inline Server & -Server::set_file_extension_and_mimetype_mapping(const std::string &ext, - const std::string &mime) { - file_extension_and_mimetype_map_[ext] = mime; - return *this; -} - -inline Server &Server::set_default_file_mimetype(const std::string &mime) { - default_file_mimetype_ = mime; - return *this; -} - -inline Server &Server::set_file_request_handler(Handler handler) { - file_request_handler_ = std::move(handler); - return *this; -} - -inline Server &Server::set_error_handler(HandlerWithResponse handler) { - error_handler_ = std::move(handler); - return *this; -} - -inline Server &Server::set_error_handler(Handler handler) { - error_handler_ = [handler](const Request &req, Response &res) { - handler(req, res); - return HandlerResponse::Handled; - }; - return *this; -} - -inline Server &Server::set_exception_handler(ExceptionHandler handler) { - exception_handler_ = std::move(handler); - return *this; -} - -inline Server &Server::set_pre_routing_handler(HandlerWithResponse handler) { - pre_routing_handler_ = std::move(handler); - return *this; -} - -inline Server &Server::set_post_routing_handler(Handler handler) { - post_routing_handler_ = std::move(handler); - return *this; -} - -inline Server &Server::set_logger(Logger logger) { - logger_ = std::move(logger); - return *this; -} - -inline Server & -Server::set_expect_100_continue_handler(Expect100ContinueHandler handler) { - expect_100_continue_handler_ = std::move(handler); - return *this; -} - -inline Server &Server::set_address_family(int family) { - address_family_ = family; - return *this; -} - -inline Server &Server::set_tcp_nodelay(bool on) { - tcp_nodelay_ = on; - return *this; -} - -inline Server &Server::set_socket_options(SocketOptions socket_options) { - socket_options_ = std::move(socket_options); - return *this; -} - -inline Server &Server::set_default_headers(Headers headers) { - default_headers_ = std::move(headers); - return *this; -} - -inline Server &Server::set_header_writer( - std::function const &writer) { - header_writer_ = writer; - return *this; -} - -inline Server &Server::set_keep_alive_max_count(size_t count) { - keep_alive_max_count_ = count; - return *this; -} - -inline Server &Server::set_keep_alive_timeout(time_t sec) { - keep_alive_timeout_sec_ = sec; - return *this; -} - -inline Server &Server::set_read_timeout(time_t sec, time_t usec) { - read_timeout_sec_ = sec; - read_timeout_usec_ = usec; - return *this; -} - -inline Server &Server::set_write_timeout(time_t sec, time_t usec) { - write_timeout_sec_ = sec; - write_timeout_usec_ = usec; - return *this; -} - -inline Server &Server::set_idle_interval(time_t sec, time_t usec) { - idle_interval_sec_ = sec; - idle_interval_usec_ = usec; - return *this; -} - -inline Server &Server::set_payload_max_length(size_t length) { - payload_max_length_ = length; - return *this; -} - -inline bool Server::bind_to_port(const std::string &host, int port, - int socket_flags) { - return bind_internal(host, port, socket_flags) >= 0; -} -inline int Server::bind_to_any_port(const std::string &host, int socket_flags) { - return bind_internal(host, 0, socket_flags); -} - -inline bool Server::listen_after_bind() { - auto se = detail::scope_exit([&]() { done_ = true; }); - return listen_internal(); -} - -inline bool Server::listen(const std::string &host, int port, - int socket_flags) { - auto se = detail::scope_exit([&]() { done_ = true; }); - return bind_to_port(host, port, socket_flags) && listen_internal(); -} - -inline bool Server::is_running() const { return is_running_; } - -inline void Server::wait_until_ready() const { - while (!is_running() && !done_) { - std::this_thread::sleep_for(std::chrono::milliseconds{1}); - } -} - -inline void Server::stop() { - if (is_running_) { - assert(svr_sock_ != INVALID_SOCKET); - std::atomic sock(svr_sock_.exchange(INVALID_SOCKET)); - detail::shutdown_socket(sock); - detail::close_socket(sock); - } -} - -inline bool Server::parse_request_line(const char *s, Request &req) const { - auto len = strlen(s); - if (len < 2 || s[len - 2] != '\r' || s[len - 1] != '\n') { return false; } - len -= 2; - - { - size_t count = 0; - - detail::split(s, s + len, ' ', [&](const char *b, const char *e) { - switch (count) { - case 0: req.method = std::string(b, e); break; - case 1: req.target = std::string(b, e); break; - case 2: req.version = std::string(b, e); break; - default: break; - } - count++; - }); - - if (count != 3) { return false; } - } - - static const std::set methods{ - "GET", "HEAD", "POST", "PUT", "DELETE", - "CONNECT", "OPTIONS", "TRACE", "PATCH", "PRI"}; - - if (methods.find(req.method) == methods.end()) { return false; } - - if (req.version != "HTTP/1.1" && req.version != "HTTP/1.0") { return false; } - - { - // Skip URL fragment - for (size_t i = 0; i < req.target.size(); i++) { - if (req.target[i] == '#') { - req.target.erase(i); - break; - } - } - - size_t count = 0; - - detail::split(req.target.data(), req.target.data() + req.target.size(), '?', - 2, [&](const char *b, const char *e) { - switch (count) { - case 0: - req.path = detail::decode_url(std::string(b, e), false); - break; - case 1: { - if (e - b > 0) { - detail::parse_query_text(std::string(b, e), req.params); - } - break; - } - default: break; - } - count++; - }); - - if (count > 2) { return false; } - } - - return true; -} - -inline bool Server::write_response(Stream &strm, bool close_connection, - const Request &req, Response &res) { - return write_response_core(strm, close_connection, req, res, false); -} - -inline bool Server::write_response_with_content(Stream &strm, - bool close_connection, - const Request &req, - Response &res) { - return write_response_core(strm, close_connection, req, res, true); -} - -inline bool Server::write_response_core(Stream &strm, bool close_connection, - const Request &req, Response &res, - bool need_apply_ranges) { - assert(res.status != -1); - - if (400 <= res.status && error_handler_ && - error_handler_(req, res) == HandlerResponse::Handled) { - need_apply_ranges = true; - } - - std::string content_type; - std::string boundary; - if (need_apply_ranges) { apply_ranges(req, res, content_type, boundary); } - - // Prepare additional headers - if (close_connection || req.get_header_value("Connection") == "close") { - res.set_header("Connection", "close"); - } else { - std::stringstream ss; - ss << "timeout=" << keep_alive_timeout_sec_ - << ", max=" << keep_alive_max_count_; - res.set_header("Keep-Alive", ss.str()); - } - - if (!res.has_header("Content-Type") && - (!res.body.empty() || res.content_length_ > 0 || res.content_provider_)) { - res.set_header("Content-Type", "text/plain"); - } - - if (!res.has_header("Content-Length") && res.body.empty() && - !res.content_length_ && !res.content_provider_) { - res.set_header("Content-Length", "0"); - } - - if (!res.has_header("Accept-Ranges") && req.method == "HEAD") { - res.set_header("Accept-Ranges", "bytes"); - } - - if (post_routing_handler_) { post_routing_handler_(req, res); } - - // Response line and headers - { - detail::BufferStream bstrm; - - if (!bstrm.write_format("HTTP/1.1 %d %s\r\n", res.status, - status_message(res.status))) { - return false; - } - - if (!header_writer_(bstrm, res.headers)) { return false; } - - // Flush buffer - auto &data = bstrm.get_buffer(); - detail::write_data(strm, data.data(), data.size()); - } - - // Body - auto ret = true; - if (req.method != "HEAD") { - if (!res.body.empty()) { - if (!detail::write_data(strm, res.body.data(), res.body.size())) { - ret = false; - } - } else if (res.content_provider_) { - if (write_content_with_provider(strm, req, res, boundary, content_type)) { - res.content_provider_success_ = true; - } else { - res.content_provider_success_ = false; - ret = false; - } - } - } - - // Log - if (logger_) { logger_(req, res); } - - return ret; -} - -inline bool -Server::write_content_with_provider(Stream &strm, const Request &req, - Response &res, const std::string &boundary, - const std::string &content_type) { - auto is_shutting_down = [this]() { - return this->svr_sock_ == INVALID_SOCKET; - }; - - if (res.content_length_ > 0) { - if (req.ranges.empty()) { - return detail::write_content(strm, res.content_provider_, 0, - res.content_length_, is_shutting_down); - } else if (req.ranges.size() == 1) { - auto offsets = - detail::get_range_offset_and_length(req, res.content_length_, 0); - auto offset = offsets.first; - auto length = offsets.second; - return detail::write_content(strm, res.content_provider_, offset, length, - is_shutting_down); - } else { - return detail::write_multipart_ranges_data( - strm, req, res, boundary, content_type, is_shutting_down); - } - } else { - if (res.is_chunked_content_provider_) { - auto type = detail::encoding_type(req, res); - - std::unique_ptr compressor; - if (type == detail::EncodingType::Gzip) { -#ifdef CPPHTTPLIB_ZLIB_SUPPORT - compressor = detail::make_unique(); -#endif - } else if (type == detail::EncodingType::Brotli) { -#ifdef CPPHTTPLIB_BROTLI_SUPPORT - compressor = detail::make_unique(); -#endif - } else { - compressor = detail::make_unique(); - } - assert(compressor != nullptr); - - return detail::write_content_chunked(strm, res.content_provider_, - is_shutting_down, *compressor); - } else { - return detail::write_content_without_length(strm, res.content_provider_, - is_shutting_down); - } - } -} - -inline bool Server::read_content(Stream &strm, Request &req, Response &res) { - MultipartFormDataMap::iterator cur; - auto file_count = 0; - if (read_content_core( - strm, req, res, - // Regular - [&](const char *buf, size_t n) { - if (req.body.size() + n > req.body.max_size()) { return false; } - req.body.append(buf, n); - return true; - }, - // Multipart - [&](const MultipartFormData &file) { - if (file_count++ == CPPHTTPLIB_MULTIPART_FORM_DATA_FILE_MAX_COUNT) { - return false; - } - cur = req.files.emplace(file.name, file); - return true; - }, - [&](const char *buf, size_t n) { - auto &content = cur->second.content; - if (content.size() + n > content.max_size()) { return false; } - content.append(buf, n); - return true; - })) { - const auto &content_type = req.get_header_value("Content-Type"); - if (!content_type.find("application/x-www-form-urlencoded")) { - if (req.body.size() > CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH) { - res.status = StatusCode::PayloadTooLarge_413; // NOTE: should be 414? - return false; - } - detail::parse_query_text(req.body, req.params); - } - return true; - } - return false; -} - -inline bool Server::read_content_with_content_receiver( - Stream &strm, Request &req, Response &res, ContentReceiver receiver, - MultipartContentHeader multipart_header, - ContentReceiver multipart_receiver) { - return read_content_core(strm, req, res, std::move(receiver), - std::move(multipart_header), - std::move(multipart_receiver)); -} - -inline bool -Server::read_content_core(Stream &strm, Request &req, Response &res, - ContentReceiver receiver, - MultipartContentHeader multipart_header, - ContentReceiver multipart_receiver) const { - detail::MultipartFormDataParser multipart_form_data_parser; - ContentReceiverWithProgress out; - - if (req.is_multipart_form_data()) { - const auto &content_type = req.get_header_value("Content-Type"); - std::string boundary; - if (!detail::parse_multipart_boundary(content_type, boundary)) { - res.status = StatusCode::BadRequest_400; - return false; - } - - multipart_form_data_parser.set_boundary(std::move(boundary)); - out = [&](const char *buf, size_t n, uint64_t /*off*/, uint64_t /*len*/) { - /* For debug - size_t pos = 0; - while (pos < n) { - auto read_size = (std::min)(1, n - pos); - auto ret = multipart_form_data_parser.parse( - buf + pos, read_size, multipart_receiver, multipart_header); - if (!ret) { return false; } - pos += read_size; - } - return true; - */ - return multipart_form_data_parser.parse(buf, n, multipart_receiver, - multipart_header); - }; - } else { - out = [receiver](const char *buf, size_t n, uint64_t /*off*/, - uint64_t /*len*/) { return receiver(buf, n); }; - } - - if (req.method == "DELETE" && !req.has_header("Content-Length")) { - return true; - } - - if (!detail::read_content(strm, req, payload_max_length_, res.status, nullptr, - out, true)) { - return false; - } - - if (req.is_multipart_form_data()) { - if (!multipart_form_data_parser.is_valid()) { - res.status = StatusCode::BadRequest_400; - return false; - } - } - - return true; -} - -inline bool Server::handle_file_request(const Request &req, Response &res, - bool head) { - for (const auto &entry : base_dirs_) { - // Prefix match - if (!req.path.compare(0, entry.mount_point.size(), entry.mount_point)) { - std::string sub_path = "/" + req.path.substr(entry.mount_point.size()); - if (detail::is_valid_path(sub_path)) { - auto path = entry.base_dir + sub_path; - if (path.back() == '/') { path += "index.html"; } - - if (detail::is_file(path)) { - for (const auto &kv : entry.headers) { - res.set_header(kv.first, kv.second); - } - - auto mm = std::make_shared(path.c_str()); - if (!mm->is_open()) { return false; } - - res.set_content_provider( - mm->size(), - detail::find_content_type(path, file_extension_and_mimetype_map_, - default_file_mimetype_), - [mm](size_t offset, size_t length, DataSink &sink) -> bool { - sink.write(mm->data() + offset, length); - return true; - }); - - if (!head && file_request_handler_) { - file_request_handler_(req, res); - } - - return true; - } - } - } - } - return false; -} - -inline socket_t -Server::create_server_socket(const std::string &host, int port, - int socket_flags, - SocketOptions socket_options) const { - return detail::create_socket( - host, std::string(), port, address_family_, socket_flags, tcp_nodelay_, - std::move(socket_options), - [](socket_t sock, struct addrinfo &ai) -> bool { - if (::bind(sock, ai.ai_addr, static_cast(ai.ai_addrlen))) { - return false; - } - if (::listen(sock, CPPHTTPLIB_LISTEN_BACKLOG)) { return false; } - return true; - }); -} - -inline int Server::bind_internal(const std::string &host, int port, - int socket_flags) { - if (!is_valid()) { return -1; } - - svr_sock_ = create_server_socket(host, port, socket_flags, socket_options_); - if (svr_sock_ == INVALID_SOCKET) { return -1; } - - if (port == 0) { - struct sockaddr_storage addr; - socklen_t addr_len = sizeof(addr); - if (getsockname(svr_sock_, reinterpret_cast(&addr), - &addr_len) == -1) { - return -1; - } - if (addr.ss_family == AF_INET) { - return ntohs(reinterpret_cast(&addr)->sin_port); - } else if (addr.ss_family == AF_INET6) { - return ntohs(reinterpret_cast(&addr)->sin6_port); - } else { - return -1; - } - } else { - return port; - } -} - -inline bool Server::listen_internal() { - auto ret = true; - is_running_ = true; - auto se = detail::scope_exit([&]() { is_running_ = false; }); - - { - std::unique_ptr task_queue(new_task_queue()); - - while (svr_sock_ != INVALID_SOCKET) { -#ifndef _WIN32 - if (idle_interval_sec_ > 0 || idle_interval_usec_ > 0) { -#endif - auto val = detail::select_read(svr_sock_, idle_interval_sec_, - idle_interval_usec_); - if (val == 0) { // Timeout - task_queue->on_idle(); - continue; - } -#ifndef _WIN32 - } -#endif - socket_t sock = accept(svr_sock_, nullptr, nullptr); - - if (sock == INVALID_SOCKET) { - if (errno == EMFILE) { - // The per-process limit of open file descriptors has been reached. - // Try to accept new connections after a short sleep. - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - continue; - } else if (errno == EINTR || errno == EAGAIN) { - continue; - } - if (svr_sock_ != INVALID_SOCKET) { - detail::close_socket(svr_sock_); - ret = false; - } else { - ; // The server socket was closed by user. - } - break; - } - - { -#ifdef _WIN32 - auto timeout = static_cast(read_timeout_sec_ * 1000 + - read_timeout_usec_ / 1000); - setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, - reinterpret_cast(&timeout), sizeof(timeout)); -#else - timeval tv; - tv.tv_sec = static_cast(read_timeout_sec_); - tv.tv_usec = static_cast(read_timeout_usec_); - setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, - reinterpret_cast(&tv), sizeof(tv)); -#endif - } - { - -#ifdef _WIN32 - auto timeout = static_cast(write_timeout_sec_ * 1000 + - write_timeout_usec_ / 1000); - setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, - reinterpret_cast(&timeout), sizeof(timeout)); -#else - timeval tv; - tv.tv_sec = static_cast(write_timeout_sec_); - tv.tv_usec = static_cast(write_timeout_usec_); - setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, - reinterpret_cast(&tv), sizeof(tv)); -#endif - } - - if (!task_queue->enqueue( - [this, sock]() { process_and_close_socket(sock); })) { - detail::shutdown_socket(sock); - detail::close_socket(sock); - } - } - - task_queue->shutdown(); - } - - return ret; -} - -inline bool Server::routing(Request &req, Response &res, Stream &strm) { - if (pre_routing_handler_ && - pre_routing_handler_(req, res) == HandlerResponse::Handled) { - return true; - } - - // File handler - auto is_head_request = req.method == "HEAD"; - if ((req.method == "GET" || is_head_request) && - handle_file_request(req, res, is_head_request)) { - return true; - } - - if (detail::expect_content(req)) { - // Content reader handler - { - ContentReader reader( - [&](ContentReceiver receiver) { - return read_content_with_content_receiver( - strm, req, res, std::move(receiver), nullptr, nullptr); - }, - [&](MultipartContentHeader header, ContentReceiver receiver) { - return read_content_with_content_receiver(strm, req, res, nullptr, - std::move(header), - std::move(receiver)); - }); - - if (req.method == "POST") { - if (dispatch_request_for_content_reader( - req, res, std::move(reader), - post_handlers_for_content_reader_)) { - return true; - } - } else if (req.method == "PUT") { - if (dispatch_request_for_content_reader( - req, res, std::move(reader), - put_handlers_for_content_reader_)) { - return true; - } - } else if (req.method == "PATCH") { - if (dispatch_request_for_content_reader( - req, res, std::move(reader), - patch_handlers_for_content_reader_)) { - return true; - } - } else if (req.method == "DELETE") { - if (dispatch_request_for_content_reader( - req, res, std::move(reader), - delete_handlers_for_content_reader_)) { - return true; - } - } - } - - // Read content into `req.body` - if (!read_content(strm, req, res)) { return false; } - } - - // Regular handler - if (req.method == "GET" || req.method == "HEAD") { - return dispatch_request(req, res, get_handlers_); - } else if (req.method == "POST") { - return dispatch_request(req, res, post_handlers_); - } else if (req.method == "PUT") { - return dispatch_request(req, res, put_handlers_); - } else if (req.method == "DELETE") { - return dispatch_request(req, res, delete_handlers_); - } else if (req.method == "OPTIONS") { - return dispatch_request(req, res, options_handlers_); - } else if (req.method == "PATCH") { - return dispatch_request(req, res, patch_handlers_); - } - - res.status = StatusCode::BadRequest_400; - return false; -} - -inline bool Server::dispatch_request(Request &req, Response &res, - const Handlers &handlers) const { - for (const auto &x : handlers) { - const auto &matcher = x.first; - const auto &handler = x.second; - - if (matcher->match(req)) { - handler(req, res); - return true; - } - } - return false; -} - -inline void Server::apply_ranges(const Request &req, Response &res, - std::string &content_type, - std::string &boundary) const { - if (req.ranges.size() > 1) { - boundary = detail::make_multipart_data_boundary(); - - auto it = res.headers.find("Content-Type"); - if (it != res.headers.end()) { - content_type = it->second; - res.headers.erase(it); - } - - res.set_header("Content-Type", - "multipart/byteranges; boundary=" + boundary); - } - - auto type = detail::encoding_type(req, res); - - if (res.body.empty()) { - if (res.content_length_ > 0) { - size_t length = 0; - if (req.ranges.empty()) { - length = res.content_length_; - } else if (req.ranges.size() == 1) { - auto offsets = - detail::get_range_offset_and_length(req, res.content_length_, 0); - length = offsets.second; - - auto content_range = detail::make_content_range_header_field( - req.ranges[0], res.content_length_); - res.set_header("Content-Range", content_range); - } else { - length = detail::get_multipart_ranges_data_length(req, res, boundary, - content_type); - } - res.set_header("Content-Length", std::to_string(length)); - } else { - if (res.content_provider_) { - if (res.is_chunked_content_provider_) { - res.set_header("Transfer-Encoding", "chunked"); - if (type == detail::EncodingType::Gzip) { - res.set_header("Content-Encoding", "gzip"); - } else if (type == detail::EncodingType::Brotli) { - res.set_header("Content-Encoding", "br"); - } - } - } - } - } else { - if (req.ranges.empty()) { - ; - } else if (req.ranges.size() == 1) { - auto content_range = detail::make_content_range_header_field( - req.ranges[0], res.body.size()); - res.set_header("Content-Range", content_range); - - auto offsets = - detail::get_range_offset_and_length(req, res.body.size(), 0); - auto offset = offsets.first; - auto length = offsets.second; - - if (offset < res.body.size()) { - res.body = res.body.substr(offset, length); - } else { - res.body.clear(); - res.status = StatusCode::RangeNotSatisfiable_416; - } - } else { - std::string data; - if (detail::make_multipart_ranges_data(req, res, boundary, content_type, - data)) { - res.body.swap(data); - } else { - res.body.clear(); - res.status = StatusCode::RangeNotSatisfiable_416; - } - } - - if (type != detail::EncodingType::None) { - std::unique_ptr compressor; - std::string content_encoding; - - if (type == detail::EncodingType::Gzip) { -#ifdef CPPHTTPLIB_ZLIB_SUPPORT - compressor = detail::make_unique(); - content_encoding = "gzip"; -#endif - } else if (type == detail::EncodingType::Brotli) { -#ifdef CPPHTTPLIB_BROTLI_SUPPORT - compressor = detail::make_unique(); - content_encoding = "br"; -#endif - } - - if (compressor) { - std::string compressed; - if (compressor->compress(res.body.data(), res.body.size(), true, - [&](const char *data, size_t data_len) { - compressed.append(data, data_len); - return true; - })) { - res.body.swap(compressed); - res.set_header("Content-Encoding", content_encoding); - } - } - } - - auto length = std::to_string(res.body.size()); - res.set_header("Content-Length", length); - } -} - -inline bool Server::dispatch_request_for_content_reader( - Request &req, Response &res, ContentReader content_reader, - const HandlersForContentReader &handlers) const { - for (const auto &x : handlers) { - const auto &matcher = x.first; - const auto &handler = x.second; - - if (matcher->match(req)) { - handler(req, res, content_reader); - return true; - } - } - return false; -} - -inline bool -Server::process_request(Stream &strm, bool close_connection, - bool &connection_closed, - const std::function &setup_request) { - std::array buf{}; - - detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); - - // Connection has been closed on client - if (!line_reader.getline()) { return false; } - - Request req; - - Response res; - res.version = "HTTP/1.1"; - res.headers = default_headers_; - -#ifdef _WIN32 - // TODO: Increase FD_SETSIZE statically (libzmq), dynamically (MySQL). -#else -#ifndef CPPHTTPLIB_USE_POLL - // Socket file descriptor exceeded FD_SETSIZE... - if (strm.socket() >= FD_SETSIZE) { - Headers dummy; - detail::read_headers(strm, dummy); - res.status = StatusCode::InternalServerError_500; - return write_response(strm, close_connection, req, res); - } -#endif -#endif - - // Check if the request URI doesn't exceed the limit - if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) { - Headers dummy; - detail::read_headers(strm, dummy); - res.status = StatusCode::UriTooLong_414; - return write_response(strm, close_connection, req, res); - } - - // Request line and headers - if (!parse_request_line(line_reader.ptr(), req) || - !detail::read_headers(strm, req.headers)) { - res.status = StatusCode::BadRequest_400; - return write_response(strm, close_connection, req, res); - } - - if (req.get_header_value("Connection") == "close") { - connection_closed = true; - } - - if (req.version == "HTTP/1.0" && - req.get_header_value("Connection") != "Keep-Alive") { - connection_closed = true; - } - - strm.get_remote_ip_and_port(req.remote_addr, req.remote_port); - req.set_header("REMOTE_ADDR", req.remote_addr); - req.set_header("REMOTE_PORT", std::to_string(req.remote_port)); - - strm.get_local_ip_and_port(req.local_addr, req.local_port); - req.set_header("LOCAL_ADDR", req.local_addr); - req.set_header("LOCAL_PORT", std::to_string(req.local_port)); - - if (req.has_header("Range")) { - const auto &range_header_value = req.get_header_value("Range"); - if (!detail::parse_range_header(range_header_value, req.ranges)) { - res.status = StatusCode::RangeNotSatisfiable_416; - return write_response(strm, close_connection, req, res); - } - } - - if (setup_request) { setup_request(req); } - - if (req.get_header_value("Expect") == "100-continue") { - int status = StatusCode::Continue_100; - if (expect_100_continue_handler_) { - status = expect_100_continue_handler_(req, res); - } - switch (status) { - case StatusCode::Continue_100: - case StatusCode::ExpectationFailed_417: - strm.write_format("HTTP/1.1 %d %s\r\n\r\n", status, - status_message(status)); - break; - default: return write_response(strm, close_connection, req, res); - } - } - - // Rounting - auto routed = false; -#ifdef CPPHTTPLIB_NO_EXCEPTIONS - routed = routing(req, res, strm); -#else - try { - routed = routing(req, res, strm); - } catch (std::exception &e) { - if (exception_handler_) { - auto ep = std::current_exception(); - exception_handler_(req, res, ep); - routed = true; - } else { - res.status = StatusCode::InternalServerError_500; - std::string val; - auto s = e.what(); - for (size_t i = 0; s[i]; i++) { - switch (s[i]) { - case '\r': val += "\\r"; break; - case '\n': val += "\\n"; break; - default: val += s[i]; break; - } - } - res.set_header("EXCEPTION_WHAT", val); - } - } catch (...) { - if (exception_handler_) { - auto ep = std::current_exception(); - exception_handler_(req, res, ep); - routed = true; - } else { - res.status = StatusCode::InternalServerError_500; - res.set_header("EXCEPTION_WHAT", "UNKNOWN"); - } - } -#endif - - if (routed) { - if (res.status == -1) { - res.status = req.ranges.empty() ? StatusCode::OK_200 - : StatusCode::PartialContent_206; - } - return write_response_with_content(strm, close_connection, req, res); - } else { - if (res.status == -1) { res.status = StatusCode::NotFound_404; } - return write_response(strm, close_connection, req, res); - } -} - -inline bool Server::is_valid() const { return true; } - -inline bool Server::process_and_close_socket(socket_t sock) { - auto ret = detail::process_server_socket( - svr_sock_, sock, keep_alive_max_count_, keep_alive_timeout_sec_, - read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, - write_timeout_usec_, - [this](Stream &strm, bool close_connection, bool &connection_closed) { - return process_request(strm, close_connection, connection_closed, - nullptr); - }); - - detail::shutdown_socket(sock); - detail::close_socket(sock); - return ret; -} - -// HTTP client implementation -inline ClientImpl::ClientImpl(const std::string &host) - : ClientImpl(host, 80, std::string(), std::string()) {} - -inline ClientImpl::ClientImpl(const std::string &host, int port) - : ClientImpl(host, port, std::string(), std::string()) {} - -inline ClientImpl::ClientImpl(const std::string &host, int port, - const std::string &client_cert_path, - const std::string &client_key_path) - : host_(host), port_(port), - host_and_port_(adjust_host_string(host) + ":" + std::to_string(port)), - client_cert_path_(client_cert_path), client_key_path_(client_key_path) {} - -inline ClientImpl::~ClientImpl() { - std::lock_guard guard(socket_mutex_); - shutdown_socket(socket_); - close_socket(socket_); -} - -inline bool ClientImpl::is_valid() const { return true; } - -inline void ClientImpl::copy_settings(const ClientImpl &rhs) { - client_cert_path_ = rhs.client_cert_path_; - client_key_path_ = rhs.client_key_path_; - connection_timeout_sec_ = rhs.connection_timeout_sec_; - read_timeout_sec_ = rhs.read_timeout_sec_; - read_timeout_usec_ = rhs.read_timeout_usec_; - write_timeout_sec_ = rhs.write_timeout_sec_; - write_timeout_usec_ = rhs.write_timeout_usec_; - basic_auth_username_ = rhs.basic_auth_username_; - basic_auth_password_ = rhs.basic_auth_password_; - bearer_token_auth_token_ = rhs.bearer_token_auth_token_; -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - digest_auth_username_ = rhs.digest_auth_username_; - digest_auth_password_ = rhs.digest_auth_password_; -#endif - keep_alive_ = rhs.keep_alive_; - follow_location_ = rhs.follow_location_; - url_encode_ = rhs.url_encode_; - address_family_ = rhs.address_family_; - tcp_nodelay_ = rhs.tcp_nodelay_; - socket_options_ = rhs.socket_options_; - compress_ = rhs.compress_; - decompress_ = rhs.decompress_; - interface_ = rhs.interface_; - proxy_host_ = rhs.proxy_host_; - proxy_port_ = rhs.proxy_port_; - proxy_basic_auth_username_ = rhs.proxy_basic_auth_username_; - proxy_basic_auth_password_ = rhs.proxy_basic_auth_password_; - proxy_bearer_token_auth_token_ = rhs.proxy_bearer_token_auth_token_; -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - proxy_digest_auth_username_ = rhs.proxy_digest_auth_username_; - proxy_digest_auth_password_ = rhs.proxy_digest_auth_password_; -#endif -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - ca_cert_file_path_ = rhs.ca_cert_file_path_; - ca_cert_dir_path_ = rhs.ca_cert_dir_path_; - ca_cert_store_ = rhs.ca_cert_store_; -#endif -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - server_certificate_verification_ = rhs.server_certificate_verification_; -#endif - logger_ = rhs.logger_; -} - -inline socket_t ClientImpl::create_client_socket(Error &error) const { - if (!proxy_host_.empty() && proxy_port_ != -1) { - return detail::create_client_socket( - proxy_host_, std::string(), proxy_port_, address_family_, tcp_nodelay_, - socket_options_, connection_timeout_sec_, connection_timeout_usec_, - read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, - write_timeout_usec_, interface_, error); - } - - // Check is custom IP specified for host_ - std::string ip; - auto it = addr_map_.find(host_); - if (it != addr_map_.end()) { ip = it->second; } - - return detail::create_client_socket( - host_, ip, port_, address_family_, tcp_nodelay_, socket_options_, - connection_timeout_sec_, connection_timeout_usec_, read_timeout_sec_, - read_timeout_usec_, write_timeout_sec_, write_timeout_usec_, interface_, - error); -} - -inline bool ClientImpl::create_and_connect_socket(Socket &socket, - Error &error) { - auto sock = create_client_socket(error); - if (sock == INVALID_SOCKET) { return false; } - socket.sock = sock; - return true; -} - -inline void ClientImpl::shutdown_ssl(Socket & /*socket*/, - bool /*shutdown_gracefully*/) { - // If there are any requests in flight from threads other than us, then it's - // a thread-unsafe race because individual ssl* objects are not thread-safe. - assert(socket_requests_in_flight_ == 0 || - socket_requests_are_from_thread_ == std::this_thread::get_id()); -} - -inline void ClientImpl::shutdown_socket(Socket &socket) const { - if (socket.sock == INVALID_SOCKET) { return; } - detail::shutdown_socket(socket.sock); -} - -inline void ClientImpl::close_socket(Socket &socket) { - // If there are requests in flight in another thread, usually closing - // the socket will be fine and they will simply receive an error when - // using the closed socket, but it is still a bug since rarely the OS - // may reassign the socket id to be used for a new socket, and then - // suddenly they will be operating on a live socket that is different - // than the one they intended! - assert(socket_requests_in_flight_ == 0 || - socket_requests_are_from_thread_ == std::this_thread::get_id()); - - // It is also a bug if this happens while SSL is still active -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - assert(socket.ssl == nullptr); -#endif - if (socket.sock == INVALID_SOCKET) { return; } - detail::close_socket(socket.sock); - socket.sock = INVALID_SOCKET; -} - -inline bool ClientImpl::read_response_line(Stream &strm, const Request &req, - Response &res) const { - std::array buf{}; - - detail::stream_line_reader line_reader(strm, buf.data(), buf.size()); - - if (!line_reader.getline()) { return false; } - -#ifdef CPPHTTPLIB_ALLOW_LF_AS_LINE_TERMINATOR - const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r?\n"); -#else - const static std::regex re("(HTTP/1\\.[01]) (\\d{3})(?: (.*?))?\r\n"); -#endif - - std::cmatch m; - if (!std::regex_match(line_reader.ptr(), m, re)) { - return req.method == "CONNECT"; - } - res.version = std::string(m[1]); - res.status = std::stoi(std::string(m[2])); - res.reason = std::string(m[3]); - - // Ignore '100 Continue' - while (res.status == StatusCode::Continue_100) { - if (!line_reader.getline()) { return false; } // CRLF - if (!line_reader.getline()) { return false; } // next response line - - if (!std::regex_match(line_reader.ptr(), m, re)) { return false; } - res.version = std::string(m[1]); - res.status = std::stoi(std::string(m[2])); - res.reason = std::string(m[3]); - } - - return true; -} - -inline bool ClientImpl::send(Request &req, Response &res, Error &error) { - std::lock_guard request_mutex_guard(request_mutex_); - auto ret = send_(req, res, error); - if (error == Error::SSLPeerCouldBeClosed_) { - assert(!ret); - ret = send_(req, res, error); - } - return ret; -} - -inline bool ClientImpl::send_(Request &req, Response &res, Error &error) { - { - std::lock_guard guard(socket_mutex_); - - // Set this to false immediately - if it ever gets set to true by the end of - // the request, we know another thread instructed us to close the socket. - socket_should_be_closed_when_request_is_done_ = false; - - auto is_alive = false; - if (socket_.is_open()) { - is_alive = detail::is_socket_alive(socket_.sock); - if (!is_alive) { - // Attempt to avoid sigpipe by shutting down nongracefully if it seems - // like the other side has already closed the connection Also, there - // cannot be any requests in flight from other threads since we locked - // request_mutex_, so safe to close everything immediately - const bool shutdown_gracefully = false; - shutdown_ssl(socket_, shutdown_gracefully); - shutdown_socket(socket_); - close_socket(socket_); - } - } - - if (!is_alive) { - if (!create_and_connect_socket(socket_, error)) { return false; } - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - // TODO: refactoring - if (is_ssl()) { - auto &scli = static_cast(*this); - if (!proxy_host_.empty() && proxy_port_ != -1) { - auto success = false; - if (!scli.connect_with_proxy(socket_, res, success, error)) { - return success; - } - } - - if (!scli.initialize_ssl(socket_, error)) { return false; } - } -#endif - } - - // Mark the current socket as being in use so that it cannot be closed by - // anyone else while this request is ongoing, even though we will be - // releasing the mutex. - if (socket_requests_in_flight_ > 1) { - assert(socket_requests_are_from_thread_ == std::this_thread::get_id()); - } - socket_requests_in_flight_ += 1; - socket_requests_are_from_thread_ = std::this_thread::get_id(); - } - - for (const auto &header : default_headers_) { - if (req.headers.find(header.first) == req.headers.end()) { - req.headers.insert(header); - } - } - - auto ret = false; - auto close_connection = !keep_alive_; - - auto se = detail::scope_exit([&]() { - // Briefly lock mutex in order to mark that a request is no longer ongoing - std::lock_guard guard(socket_mutex_); - socket_requests_in_flight_ -= 1; - if (socket_requests_in_flight_ <= 0) { - assert(socket_requests_in_flight_ == 0); - socket_requests_are_from_thread_ = std::thread::id(); - } - - if (socket_should_be_closed_when_request_is_done_ || close_connection || - !ret) { - shutdown_ssl(socket_, true); - shutdown_socket(socket_); - close_socket(socket_); - } - }); - - ret = process_socket(socket_, [&](Stream &strm) { - return handle_request(strm, req, res, close_connection, error); - }); - - if (!ret) { - if (error == Error::Success) { error = Error::Unknown; } - } - - return ret; -} - -inline Result ClientImpl::send(const Request &req) { - auto req2 = req; - return send_(std::move(req2)); -} - -inline Result ClientImpl::send_(Request &&req) { - auto res = detail::make_unique(); - auto error = Error::Success; - auto ret = send(req, *res, error); - return Result{ret ? std::move(res) : nullptr, error, std::move(req.headers)}; -} - -inline bool ClientImpl::handle_request(Stream &strm, Request &req, - Response &res, bool close_connection, - Error &error) { - if (req.path.empty()) { - error = Error::Connection; - return false; - } - - auto req_save = req; - - bool ret; - - if (!is_ssl() && !proxy_host_.empty() && proxy_port_ != -1) { - auto req2 = req; - req2.path = "http://" + host_and_port_ + req.path; - ret = process_request(strm, req2, res, close_connection, error); - req = req2; - req.path = req_save.path; - } else { - ret = process_request(strm, req, res, close_connection, error); - } - - if (!ret) { return false; } - - if (res.get_header_value("Connection") == "close" || - (res.version == "HTTP/1.0" && res.reason != "Connection established")) { - // TODO this requires a not-entirely-obvious chain of calls to be correct - // for this to be safe. - - // This is safe to call because handle_request is only called by send_ - // which locks the request mutex during the process. It would be a bug - // to call it from a different thread since it's a thread-safety issue - // to do these things to the socket if another thread is using the socket. - std::lock_guard guard(socket_mutex_); - shutdown_ssl(socket_, true); - shutdown_socket(socket_); - close_socket(socket_); - } - - if (300 < res.status && res.status < 400 && follow_location_) { - req = req_save; - ret = redirect(req, res, error); - } - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - if ((res.status == StatusCode::Unauthorized_401 || - res.status == StatusCode::ProxyAuthenticationRequired_407) && - req.authorization_count_ < 5) { - auto is_proxy = res.status == StatusCode::ProxyAuthenticationRequired_407; - const auto &username = - is_proxy ? proxy_digest_auth_username_ : digest_auth_username_; - const auto &password = - is_proxy ? proxy_digest_auth_password_ : digest_auth_password_; - - if (!username.empty() && !password.empty()) { - std::map auth; - if (detail::parse_www_authenticate(res, auth, is_proxy)) { - Request new_req = req; - new_req.authorization_count_ += 1; - new_req.headers.erase(is_proxy ? "Proxy-Authorization" - : "Authorization"); - new_req.headers.insert(detail::make_digest_authentication_header( - req, auth, new_req.authorization_count_, detail::random_string(10), - username, password, is_proxy)); - - Response new_res; - - ret = send(new_req, new_res, error); - if (ret) { res = new_res; } - } - } - } -#endif - - return ret; -} - -inline bool ClientImpl::redirect(Request &req, Response &res, Error &error) { - if (req.redirect_count_ == 0) { - error = Error::ExceedRedirectCount; - return false; - } - - auto location = res.get_header_value("location"); - if (location.empty()) { return false; } - - const static std::regex re( - R"((?:(https?):)?(?://(?:\[([\d:]+)\]|([^:/?#]+))(?::(\d+))?)?([^?#]*)(\?[^#]*)?(?:#.*)?)"); - - std::smatch m; - if (!std::regex_match(location, m, re)) { return false; } - - auto scheme = is_ssl() ? "https" : "http"; - - auto next_scheme = m[1].str(); - auto next_host = m[2].str(); - if (next_host.empty()) { next_host = m[3].str(); } - auto port_str = m[4].str(); - auto next_path = m[5].str(); - auto next_query = m[6].str(); - - auto next_port = port_; - if (!port_str.empty()) { - next_port = std::stoi(port_str); - } else if (!next_scheme.empty()) { - next_port = next_scheme == "https" ? 443 : 80; - } - - if (next_scheme.empty()) { next_scheme = scheme; } - if (next_host.empty()) { next_host = host_; } - if (next_path.empty()) { next_path = "/"; } - - auto path = detail::decode_url(next_path, true) + next_query; - - if (next_scheme == scheme && next_host == host_ && next_port == port_) { - return detail::redirect(*this, req, res, path, location, error); - } else { - if (next_scheme == "https") { -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - SSLClient cli(next_host, next_port); - cli.copy_settings(*this); - if (ca_cert_store_) { cli.set_ca_cert_store(ca_cert_store_); } - return detail::redirect(cli, req, res, path, location, error); -#else - return false; -#endif - } else { - ClientImpl cli(next_host, next_port); - cli.copy_settings(*this); - return detail::redirect(cli, req, res, path, location, error); - } - } -} - -inline bool ClientImpl::write_content_with_provider(Stream &strm, - const Request &req, - Error &error) const { - auto is_shutting_down = []() { return false; }; - - if (req.is_chunked_content_provider_) { - // TODO: Brotli support - std::unique_ptr compressor; -#ifdef CPPHTTPLIB_ZLIB_SUPPORT - if (compress_) { - compressor = detail::make_unique(); - } else -#endif - { - compressor = detail::make_unique(); - } - - return detail::write_content_chunked(strm, req.content_provider_, - is_shutting_down, *compressor, error); - } else { - return detail::write_content(strm, req.content_provider_, 0, - req.content_length_, is_shutting_down, error); - } -} - -inline bool ClientImpl::write_request(Stream &strm, Request &req, - bool close_connection, Error &error) { - // Prepare additional headers - if (close_connection) { - if (!req.has_header("Connection")) { - req.set_header("Connection", "close"); - } - } - - if (!req.has_header("Host")) { - if (is_ssl()) { - if (port_ == 443) { - req.set_header("Host", host_); - } else { - req.set_header("Host", host_and_port_); - } - } else { - if (port_ == 80) { - req.set_header("Host", host_); - } else { - req.set_header("Host", host_and_port_); - } - } - } - - if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); } - -#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT - if (!req.has_header("User-Agent")) { - auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION; - req.set_header("User-Agent", agent); - } -#endif - - if (req.body.empty()) { - if (req.content_provider_) { - if (!req.is_chunked_content_provider_) { - if (!req.has_header("Content-Length")) { - auto length = std::to_string(req.content_length_); - req.set_header("Content-Length", length); - } - } - } else { - if (req.method == "POST" || req.method == "PUT" || - req.method == "PATCH") { - req.set_header("Content-Length", "0"); - } - } - } else { - if (!req.has_header("Content-Type")) { - req.set_header("Content-Type", "text/plain"); - } - - if (!req.has_header("Content-Length")) { - auto length = std::to_string(req.body.size()); - req.set_header("Content-Length", length); - } - } - - if (!basic_auth_password_.empty() || !basic_auth_username_.empty()) { - if (!req.has_header("Authorization")) { - req.headers.insert(make_basic_authentication_header( - basic_auth_username_, basic_auth_password_, false)); - } - } - - if (!proxy_basic_auth_username_.empty() && - !proxy_basic_auth_password_.empty()) { - if (!req.has_header("Proxy-Authorization")) { - req.headers.insert(make_basic_authentication_header( - proxy_basic_auth_username_, proxy_basic_auth_password_, true)); - } - } - - if (!bearer_token_auth_token_.empty()) { - if (!req.has_header("Authorization")) { - req.headers.insert(make_bearer_token_authentication_header( - bearer_token_auth_token_, false)); - } - } - - if (!proxy_bearer_token_auth_token_.empty()) { - if (!req.has_header("Proxy-Authorization")) { - req.headers.insert(make_bearer_token_authentication_header( - proxy_bearer_token_auth_token_, true)); - } - } - - // Request line and headers - { - detail::BufferStream bstrm; - - const auto &path = url_encode_ ? detail::encode_url(req.path) : req.path; - bstrm.write_format("%s %s HTTP/1.1\r\n", req.method.c_str(), path.c_str()); - - header_writer_(bstrm, req.headers); - - // Flush buffer - auto &data = bstrm.get_buffer(); - if (!detail::write_data(strm, data.data(), data.size())) { - error = Error::Write; - return false; - } - } - - // Body - if (req.body.empty()) { - return write_content_with_provider(strm, req, error); - } - - if (!detail::write_data(strm, req.body.data(), req.body.size())) { - error = Error::Write; - return false; - } - - return true; -} - -inline std::unique_ptr ClientImpl::send_with_content_provider( - Request &req, const char *body, size_t content_length, - ContentProvider content_provider, - ContentProviderWithoutLength content_provider_without_length, - const std::string &content_type, Error &error) { - if (!content_type.empty()) { req.set_header("Content-Type", content_type); } - -#ifdef CPPHTTPLIB_ZLIB_SUPPORT - if (compress_) { req.set_header("Content-Encoding", "gzip"); } -#endif - -#ifdef CPPHTTPLIB_ZLIB_SUPPORT - if (compress_ && !content_provider_without_length) { - // TODO: Brotli support - detail::gzip_compressor compressor; - - if (content_provider) { - auto ok = true; - size_t offset = 0; - DataSink data_sink; - - data_sink.write = [&](const char *data, size_t data_len) -> bool { - if (ok) { - auto last = offset + data_len == content_length; - - auto ret = compressor.compress( - data, data_len, last, - [&](const char *compressed_data, size_t compressed_data_len) { - req.body.append(compressed_data, compressed_data_len); - return true; - }); - - if (ret) { - offset += data_len; - } else { - ok = false; - } - } - return ok; - }; - - while (ok && offset < content_length) { - if (!content_provider(offset, content_length - offset, data_sink)) { - error = Error::Canceled; - return nullptr; - } - } - } else { - if (!compressor.compress(body, content_length, true, - [&](const char *data, size_t data_len) { - req.body.append(data, data_len); - return true; - })) { - error = Error::Compression; - return nullptr; - } - } - } else -#endif - { - if (content_provider) { - req.content_length_ = content_length; - req.content_provider_ = std::move(content_provider); - req.is_chunked_content_provider_ = false; - } else if (content_provider_without_length) { - req.content_length_ = 0; - req.content_provider_ = detail::ContentProviderAdapter( - std::move(content_provider_without_length)); - req.is_chunked_content_provider_ = true; - req.set_header("Transfer-Encoding", "chunked"); - } else { - req.body.assign(body, content_length); - } - } - - auto res = detail::make_unique(); - return send(req, *res, error) ? std::move(res) : nullptr; -} - -inline Result ClientImpl::send_with_content_provider( - const std::string &method, const std::string &path, const Headers &headers, - const char *body, size_t content_length, ContentProvider content_provider, - ContentProviderWithoutLength content_provider_without_length, - const std::string &content_type) { - Request req; - req.method = method; - req.headers = headers; - req.path = path; - - auto error = Error::Success; - - auto res = send_with_content_provider( - req, body, content_length, std::move(content_provider), - std::move(content_provider_without_length), content_type, error); - - return Result{std::move(res), error, std::move(req.headers)}; -} - -inline std::string -ClientImpl::adjust_host_string(const std::string &host) const { - if (host.find(':') != std::string::npos) { return "[" + host + "]"; } - return host; -} - -inline bool ClientImpl::process_request(Stream &strm, Request &req, - Response &res, bool close_connection, - Error &error) { - // Send request - if (!write_request(strm, req, close_connection, error)) { return false; } - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - if (is_ssl()) { - auto is_proxy_enabled = !proxy_host_.empty() && proxy_port_ != -1; - if (!is_proxy_enabled) { - char buf[1]; - if (SSL_peek(socket_.ssl, buf, 1) == 0 && - SSL_get_error(socket_.ssl, 0) == SSL_ERROR_ZERO_RETURN) { - error = Error::SSLPeerCouldBeClosed_; - return false; - } - } - } -#endif - - // Receive response and headers - if (!read_response_line(strm, req, res) || - !detail::read_headers(strm, res.headers)) { - error = Error::Read; - return false; - } - - // Body - if ((res.status != StatusCode::NoContent_204) && req.method != "HEAD" && - req.method != "CONNECT") { - auto redirect = 300 < res.status && res.status < 400 && follow_location_; - - if (req.response_handler && !redirect) { - if (!req.response_handler(res)) { - error = Error::Canceled; - return false; - } - } - - auto out = - req.content_receiver - ? static_cast( - [&](const char *buf, size_t n, uint64_t off, uint64_t len) { - if (redirect) { return true; } - auto ret = req.content_receiver(buf, n, off, len); - if (!ret) { error = Error::Canceled; } - return ret; - }) - : static_cast( - [&](const char *buf, size_t n, uint64_t /*off*/, - uint64_t /*len*/) { - if (res.body.size() + n > res.body.max_size()) { - return false; - } - res.body.append(buf, n); - return true; - }); - - auto progress = [&](uint64_t current, uint64_t total) { - if (!req.progress || redirect) { return true; } - auto ret = req.progress(current, total); - if (!ret) { error = Error::Canceled; } - return ret; - }; - - int dummy_status; - if (!detail::read_content(strm, res, (std::numeric_limits::max)(), - dummy_status, std::move(progress), std::move(out), - decompress_)) { - if (error != Error::Canceled) { error = Error::Read; } - return false; - } - } - - // Log - if (logger_) { logger_(req, res); } - - return true; -} - -inline ContentProviderWithoutLength ClientImpl::get_multipart_content_provider( - const std::string &boundary, const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items) const { - size_t cur_item = 0; - size_t cur_start = 0; - // cur_item and cur_start are copied to within the std::function and maintain - // state between successive calls - return [&, cur_item, cur_start](size_t offset, - DataSink &sink) mutable -> bool { - if (!offset && !items.empty()) { - sink.os << detail::serialize_multipart_formdata(items, boundary, false); - return true; - } else if (cur_item < provider_items.size()) { - if (!cur_start) { - const auto &begin = detail::serialize_multipart_formdata_item_begin( - provider_items[cur_item], boundary); - offset += begin.size(); - cur_start = offset; - sink.os << begin; - } - - DataSink cur_sink; - auto has_data = true; - cur_sink.write = sink.write; - cur_sink.done = [&]() { has_data = false; }; - - if (!provider_items[cur_item].provider(offset - cur_start, cur_sink)) { - return false; - } - - if (!has_data) { - sink.os << detail::serialize_multipart_formdata_item_end(); - cur_item++; - cur_start = 0; - } - return true; - } else { - sink.os << detail::serialize_multipart_formdata_finish(boundary); - sink.done(); - return true; - } - }; -} - -inline bool -ClientImpl::process_socket(const Socket &socket, - std::function callback) { - return detail::process_client_socket( - socket.sock, read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, - write_timeout_usec_, std::move(callback)); -} - -inline bool ClientImpl::is_ssl() const { return false; } - -inline Result ClientImpl::Get(const std::string &path) { - return Get(path, Headers(), Progress()); -} - -inline Result ClientImpl::Get(const std::string &path, Progress progress) { - return Get(path, Headers(), std::move(progress)); -} - -inline Result ClientImpl::Get(const std::string &path, const Headers &headers) { - return Get(path, headers, Progress()); -} - -inline Result ClientImpl::Get(const std::string &path, const Headers &headers, - Progress progress) { - Request req; - req.method = "GET"; - req.path = path; - req.headers = headers; - req.progress = std::move(progress); - - return send_(std::move(req)); -} - -inline Result ClientImpl::Get(const std::string &path, - ContentReceiver content_receiver) { - return Get(path, Headers(), nullptr, std::move(content_receiver), nullptr); -} - -inline Result ClientImpl::Get(const std::string &path, - ContentReceiver content_receiver, - Progress progress) { - return Get(path, Headers(), nullptr, std::move(content_receiver), - std::move(progress)); -} - -inline Result ClientImpl::Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver) { - return Get(path, headers, nullptr, std::move(content_receiver), nullptr); -} - -inline Result ClientImpl::Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver, - Progress progress) { - return Get(path, headers, nullptr, std::move(content_receiver), - std::move(progress)); -} - -inline Result ClientImpl::Get(const std::string &path, - ResponseHandler response_handler, - ContentReceiver content_receiver) { - return Get(path, Headers(), std::move(response_handler), - std::move(content_receiver), nullptr); -} - -inline Result ClientImpl::Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver) { - return Get(path, headers, std::move(response_handler), - std::move(content_receiver), nullptr); -} - -inline Result ClientImpl::Get(const std::string &path, - ResponseHandler response_handler, - ContentReceiver content_receiver, - Progress progress) { - return Get(path, Headers(), std::move(response_handler), - std::move(content_receiver), std::move(progress)); -} - -inline Result ClientImpl::Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver, - Progress progress) { - Request req; - req.method = "GET"; - req.path = path; - req.headers = headers; - req.response_handler = std::move(response_handler); - req.content_receiver = - [content_receiver](const char *data, size_t data_length, - uint64_t /*offset*/, uint64_t /*total_length*/) { - return content_receiver(data, data_length); - }; - req.progress = std::move(progress); - - return send_(std::move(req)); -} - -inline Result ClientImpl::Get(const std::string &path, const Params ¶ms, - const Headers &headers, Progress progress) { - if (params.empty()) { return Get(path, headers); } - - std::string path_with_query = append_query_params(path, params); - return Get(path_with_query, headers, progress); -} - -inline Result ClientImpl::Get(const std::string &path, const Params ¶ms, - const Headers &headers, - ContentReceiver content_receiver, - Progress progress) { - return Get(path, params, headers, nullptr, content_receiver, progress); -} - -inline Result ClientImpl::Get(const std::string &path, const Params ¶ms, - const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver, - Progress progress) { - if (params.empty()) { - return Get(path, headers, response_handler, content_receiver, progress); - } - - std::string path_with_query = append_query_params(path, params); - return Get(path_with_query, headers, response_handler, content_receiver, - progress); -} - -inline Result ClientImpl::Head(const std::string &path) { - return Head(path, Headers()); -} - -inline Result ClientImpl::Head(const std::string &path, - const Headers &headers) { - Request req; - req.method = "HEAD"; - req.headers = headers; - req.path = path; - - return send_(std::move(req)); -} - -inline Result ClientImpl::Post(const std::string &path) { - return Post(path, std::string(), std::string()); -} - -inline Result ClientImpl::Post(const std::string &path, - const Headers &headers) { - return Post(path, headers, nullptr, 0, std::string()); -} - -inline Result ClientImpl::Post(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return Post(path, Headers(), body, content_length, content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type) { - return send_with_content_provider("POST", path, headers, body, content_length, - nullptr, nullptr, content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const std::string &body, - const std::string &content_type) { - return Post(path, Headers(), body, content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const Headers &headers, - const std::string &body, - const std::string &content_type) { - return send_with_content_provider("POST", path, headers, body.data(), - body.size(), nullptr, nullptr, - content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const Params ¶ms) { - return Post(path, Headers(), params); -} - -inline Result ClientImpl::Post(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return Post(path, Headers(), content_length, std::move(content_provider), - content_type); -} - -inline Result ClientImpl::Post(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return Post(path, Headers(), std::move(content_provider), content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const Headers &headers, - size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return send_with_content_provider("POST", path, headers, nullptr, - content_length, std::move(content_provider), - nullptr, content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return send_with_content_provider("POST", path, headers, nullptr, 0, nullptr, - std::move(content_provider), content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const Headers &headers, - const Params ¶ms) { - auto query = detail::params_to_query_str(params); - return Post(path, headers, query, "application/x-www-form-urlencoded"); -} - -inline Result ClientImpl::Post(const std::string &path, - const MultipartFormDataItems &items) { - return Post(path, Headers(), items); -} - -inline Result ClientImpl::Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items) { - const auto &boundary = detail::make_multipart_data_boundary(); - const auto &content_type = - detail::serialize_multipart_formdata_get_content_type(boundary); - const auto &body = detail::serialize_multipart_formdata(items, boundary); - return Post(path, headers, body, content_type); -} - -inline Result ClientImpl::Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const std::string &boundary) { - if (!detail::is_multipart_boundary_chars_valid(boundary)) { - return Result{nullptr, Error::UnsupportedMultipartBoundaryChars}; - } - - const auto &content_type = - detail::serialize_multipart_formdata_get_content_type(boundary); - const auto &body = detail::serialize_multipart_formdata(items, boundary); - return Post(path, headers, body, content_type); -} - -inline Result -ClientImpl::Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items) { - const auto &boundary = detail::make_multipart_data_boundary(); - const auto &content_type = - detail::serialize_multipart_formdata_get_content_type(boundary); - return send_with_content_provider( - "POST", path, headers, nullptr, 0, nullptr, - get_multipart_content_provider(boundary, items, provider_items), - content_type); -} - -inline Result ClientImpl::Put(const std::string &path) { - return Put(path, std::string(), std::string()); -} - -inline Result ClientImpl::Put(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return Put(path, Headers(), body, content_length, content_type); -} - -inline Result ClientImpl::Put(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type) { - return send_with_content_provider("PUT", path, headers, body, content_length, - nullptr, nullptr, content_type); -} - -inline Result ClientImpl::Put(const std::string &path, const std::string &body, - const std::string &content_type) { - return Put(path, Headers(), body, content_type); -} - -inline Result ClientImpl::Put(const std::string &path, const Headers &headers, - const std::string &body, - const std::string &content_type) { - return send_with_content_provider("PUT", path, headers, body.data(), - body.size(), nullptr, nullptr, - content_type); -} - -inline Result ClientImpl::Put(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return Put(path, Headers(), content_length, std::move(content_provider), - content_type); -} - -inline Result ClientImpl::Put(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return Put(path, Headers(), std::move(content_provider), content_type); -} - -inline Result ClientImpl::Put(const std::string &path, const Headers &headers, - size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return send_with_content_provider("PUT", path, headers, nullptr, - content_length, std::move(content_provider), - nullptr, content_type); -} - -inline Result ClientImpl::Put(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return send_with_content_provider("PUT", path, headers, nullptr, 0, nullptr, - std::move(content_provider), content_type); -} - -inline Result ClientImpl::Put(const std::string &path, const Params ¶ms) { - return Put(path, Headers(), params); -} - -inline Result ClientImpl::Put(const std::string &path, const Headers &headers, - const Params ¶ms) { - auto query = detail::params_to_query_str(params); - return Put(path, headers, query, "application/x-www-form-urlencoded"); -} - -inline Result ClientImpl::Put(const std::string &path, - const MultipartFormDataItems &items) { - return Put(path, Headers(), items); -} - -inline Result ClientImpl::Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items) { - const auto &boundary = detail::make_multipart_data_boundary(); - const auto &content_type = - detail::serialize_multipart_formdata_get_content_type(boundary); - const auto &body = detail::serialize_multipart_formdata(items, boundary); - return Put(path, headers, body, content_type); -} - -inline Result ClientImpl::Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const std::string &boundary) { - if (!detail::is_multipart_boundary_chars_valid(boundary)) { - return Result{nullptr, Error::UnsupportedMultipartBoundaryChars}; - } - - const auto &content_type = - detail::serialize_multipart_formdata_get_content_type(boundary); - const auto &body = detail::serialize_multipart_formdata(items, boundary); - return Put(path, headers, body, content_type); -} - -inline Result -ClientImpl::Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items) { - const auto &boundary = detail::make_multipart_data_boundary(); - const auto &content_type = - detail::serialize_multipart_formdata_get_content_type(boundary); - return send_with_content_provider( - "PUT", path, headers, nullptr, 0, nullptr, - get_multipart_content_provider(boundary, items, provider_items), - content_type); -} -inline Result ClientImpl::Patch(const std::string &path) { - return Patch(path, std::string(), std::string()); -} - -inline Result ClientImpl::Patch(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return Patch(path, Headers(), body, content_length, content_type); -} - -inline Result ClientImpl::Patch(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type) { - return send_with_content_provider("PATCH", path, headers, body, - content_length, nullptr, nullptr, - content_type); -} - -inline Result ClientImpl::Patch(const std::string &path, - const std::string &body, - const std::string &content_type) { - return Patch(path, Headers(), body, content_type); -} - -inline Result ClientImpl::Patch(const std::string &path, const Headers &headers, - const std::string &body, - const std::string &content_type) { - return send_with_content_provider("PATCH", path, headers, body.data(), - body.size(), nullptr, nullptr, - content_type); -} - -inline Result ClientImpl::Patch(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return Patch(path, Headers(), content_length, std::move(content_provider), - content_type); -} - -inline Result ClientImpl::Patch(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return Patch(path, Headers(), std::move(content_provider), content_type); -} - -inline Result ClientImpl::Patch(const std::string &path, const Headers &headers, - size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return send_with_content_provider("PATCH", path, headers, nullptr, - content_length, std::move(content_provider), - nullptr, content_type); -} - -inline Result ClientImpl::Patch(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return send_with_content_provider("PATCH", path, headers, nullptr, 0, nullptr, - std::move(content_provider), content_type); -} - -inline Result ClientImpl::Delete(const std::string &path) { - return Delete(path, Headers(), std::string(), std::string()); -} - -inline Result ClientImpl::Delete(const std::string &path, - const Headers &headers) { - return Delete(path, headers, std::string(), std::string()); -} - -inline Result ClientImpl::Delete(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return Delete(path, Headers(), body, content_length, content_type); -} - -inline Result ClientImpl::Delete(const std::string &path, - const Headers &headers, const char *body, - size_t content_length, - const std::string &content_type) { - Request req; - req.method = "DELETE"; - req.headers = headers; - req.path = path; - - if (!content_type.empty()) { req.set_header("Content-Type", content_type); } - req.body.assign(body, content_length); - - return send_(std::move(req)); -} - -inline Result ClientImpl::Delete(const std::string &path, - const std::string &body, - const std::string &content_type) { - return Delete(path, Headers(), body.data(), body.size(), content_type); -} - -inline Result ClientImpl::Delete(const std::string &path, - const Headers &headers, - const std::string &body, - const std::string &content_type) { - return Delete(path, headers, body.data(), body.size(), content_type); -} - -inline Result ClientImpl::Options(const std::string &path) { - return Options(path, Headers()); -} - -inline Result ClientImpl::Options(const std::string &path, - const Headers &headers) { - Request req; - req.method = "OPTIONS"; - req.headers = headers; - req.path = path; - - return send_(std::move(req)); -} - -inline void ClientImpl::stop() { - std::lock_guard guard(socket_mutex_); - - // If there is anything ongoing right now, the ONLY thread-safe thing we can - // do is to shutdown_socket, so that threads using this socket suddenly - // discover they can't read/write any more and error out. Everything else - // (closing the socket, shutting ssl down) is unsafe because these actions are - // not thread-safe. - if (socket_requests_in_flight_ > 0) { - shutdown_socket(socket_); - - // Aside from that, we set a flag for the socket to be closed when we're - // done. - socket_should_be_closed_when_request_is_done_ = true; - return; - } - - // Otherwise, still holding the mutex, we can shut everything down ourselves - shutdown_ssl(socket_, true); - shutdown_socket(socket_); - close_socket(socket_); -} - -inline std::string ClientImpl::host() const { return host_; } - -inline int ClientImpl::port() const { return port_; } - -inline size_t ClientImpl::is_socket_open() const { - std::lock_guard guard(socket_mutex_); - return socket_.is_open(); -} - -inline socket_t ClientImpl::socket() const { return socket_.sock; } - -inline void ClientImpl::set_connection_timeout(time_t sec, time_t usec) { - connection_timeout_sec_ = sec; - connection_timeout_usec_ = usec; -} - -inline void ClientImpl::set_read_timeout(time_t sec, time_t usec) { - read_timeout_sec_ = sec; - read_timeout_usec_ = usec; -} - -inline void ClientImpl::set_write_timeout(time_t sec, time_t usec) { - write_timeout_sec_ = sec; - write_timeout_usec_ = usec; -} - -inline void ClientImpl::set_basic_auth(const std::string &username, - const std::string &password) { - basic_auth_username_ = username; - basic_auth_password_ = password; -} - -inline void ClientImpl::set_bearer_token_auth(const std::string &token) { - bearer_token_auth_token_ = token; -} - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline void ClientImpl::set_digest_auth(const std::string &username, - const std::string &password) { - digest_auth_username_ = username; - digest_auth_password_ = password; -} -#endif - -inline void ClientImpl::set_keep_alive(bool on) { keep_alive_ = on; } - -inline void ClientImpl::set_follow_location(bool on) { follow_location_ = on; } - -inline void ClientImpl::set_url_encode(bool on) { url_encode_ = on; } - -inline void -ClientImpl::set_hostname_addr_map(std::map addr_map) { - addr_map_ = std::move(addr_map); -} - -inline void ClientImpl::set_default_headers(Headers headers) { - default_headers_ = std::move(headers); -} - -inline void ClientImpl::set_header_writer( - std::function const &writer) { - header_writer_ = writer; -} - -inline void ClientImpl::set_address_family(int family) { - address_family_ = family; -} - -inline void ClientImpl::set_tcp_nodelay(bool on) { tcp_nodelay_ = on; } - -inline void ClientImpl::set_socket_options(SocketOptions socket_options) { - socket_options_ = std::move(socket_options); -} - -inline void ClientImpl::set_compress(bool on) { compress_ = on; } - -inline void ClientImpl::set_decompress(bool on) { decompress_ = on; } - -inline void ClientImpl::set_interface(const std::string &intf) { - interface_ = intf; -} - -inline void ClientImpl::set_proxy(const std::string &host, int port) { - proxy_host_ = host; - proxy_port_ = port; -} - -inline void ClientImpl::set_proxy_basic_auth(const std::string &username, - const std::string &password) { - proxy_basic_auth_username_ = username; - proxy_basic_auth_password_ = password; -} - -inline void ClientImpl::set_proxy_bearer_token_auth(const std::string &token) { - proxy_bearer_token_auth_token_ = token; -} - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline void ClientImpl::set_proxy_digest_auth(const std::string &username, - const std::string &password) { - proxy_digest_auth_username_ = username; - proxy_digest_auth_password_ = password; -} - -inline void ClientImpl::set_ca_cert_path(const std::string &ca_cert_file_path, - const std::string &ca_cert_dir_path) { - ca_cert_file_path_ = ca_cert_file_path; - ca_cert_dir_path_ = ca_cert_dir_path; -} - -inline void ClientImpl::set_ca_cert_store(X509_STORE *ca_cert_store) { - if (ca_cert_store && ca_cert_store != ca_cert_store_) { - ca_cert_store_ = ca_cert_store; - } -} - -inline X509_STORE *ClientImpl::create_ca_cert_store(const char *ca_cert, - std::size_t size) const { - auto mem = BIO_new_mem_buf(ca_cert, static_cast(size)); - if (!mem) { return nullptr; } - - auto inf = PEM_X509_INFO_read_bio(mem, nullptr, nullptr, nullptr); - if (!inf) { - BIO_free_all(mem); - return nullptr; - } - - auto cts = X509_STORE_new(); - if (cts) { - for (auto i = 0; i < static_cast(sk_X509_INFO_num(inf)); i++) { - auto itmp = sk_X509_INFO_value(inf, i); - if (!itmp) { continue; } - - if (itmp->x509) { X509_STORE_add_cert(cts, itmp->x509); } - if (itmp->crl) { X509_STORE_add_crl(cts, itmp->crl); } - } - } - - sk_X509_INFO_pop_free(inf, X509_INFO_free); - BIO_free_all(mem); - return cts; -} - -inline void ClientImpl::enable_server_certificate_verification(bool enabled) { - server_certificate_verification_ = enabled; -} -#endif - -inline void ClientImpl::set_logger(Logger logger) { - logger_ = std::move(logger); -} - -/* - * SSL Implementation - */ -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -namespace detail { - -template -inline SSL *ssl_new(socket_t sock, SSL_CTX *ctx, std::mutex &ctx_mutex, - U SSL_connect_or_accept, V setup) { - SSL *ssl = nullptr; - { - std::lock_guard guard(ctx_mutex); - ssl = SSL_new(ctx); - } - - if (ssl) { - set_nonblocking(sock, true); - auto bio = BIO_new_socket(static_cast(sock), BIO_NOCLOSE); - BIO_set_nbio(bio, 1); - SSL_set_bio(ssl, bio, bio); - - if (!setup(ssl) || SSL_connect_or_accept(ssl) != 1) { - SSL_shutdown(ssl); - { - std::lock_guard guard(ctx_mutex); - SSL_free(ssl); - } - set_nonblocking(sock, false); - return nullptr; - } - BIO_set_nbio(bio, 0); - set_nonblocking(sock, false); - } - - return ssl; -} - -inline void ssl_delete(std::mutex &ctx_mutex, SSL *ssl, - bool shutdown_gracefully) { - // sometimes we may want to skip this to try to avoid SIGPIPE if we know - // the remote has closed the network connection - // Note that it is not always possible to avoid SIGPIPE, this is merely a - // best-efforts. - if (shutdown_gracefully) { SSL_shutdown(ssl); } - - std::lock_guard guard(ctx_mutex); - SSL_free(ssl); -} - -template -bool ssl_connect_or_accept_nonblocking(socket_t sock, SSL *ssl, - U ssl_connect_or_accept, - time_t timeout_sec, - time_t timeout_usec) { - auto res = 0; - while ((res = ssl_connect_or_accept(ssl)) != 1) { - auto err = SSL_get_error(ssl, res); - switch (err) { - case SSL_ERROR_WANT_READ: - if (select_read(sock, timeout_sec, timeout_usec) > 0) { continue; } - break; - case SSL_ERROR_WANT_WRITE: - if (select_write(sock, timeout_sec, timeout_usec) > 0) { continue; } - break; - default: break; - } - return false; - } - return true; -} - -template -inline bool process_server_socket_ssl( - const std::atomic &svr_sock, SSL *ssl, socket_t sock, - size_t keep_alive_max_count, time_t keep_alive_timeout_sec, - time_t read_timeout_sec, time_t read_timeout_usec, time_t write_timeout_sec, - time_t write_timeout_usec, T callback) { - return process_server_socket_core( - svr_sock, sock, keep_alive_max_count, keep_alive_timeout_sec, - [&](bool close_connection, bool &connection_closed) { - SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec, - write_timeout_sec, write_timeout_usec); - return callback(strm, close_connection, connection_closed); - }); -} - -template -inline bool -process_client_socket_ssl(SSL *ssl, socket_t sock, time_t read_timeout_sec, - time_t read_timeout_usec, time_t write_timeout_sec, - time_t write_timeout_usec, T callback) { - SSLSocketStream strm(sock, ssl, read_timeout_sec, read_timeout_usec, - write_timeout_sec, write_timeout_usec); - return callback(strm); -} - -class SSLInit { -public: - SSLInit() { - OPENSSL_init_ssl( - OPENSSL_INIT_LOAD_SSL_STRINGS | OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); - } -}; - -// SSL socket stream implementation -inline SSLSocketStream::SSLSocketStream(socket_t sock, SSL *ssl, - time_t read_timeout_sec, - time_t read_timeout_usec, - time_t write_timeout_sec, - time_t write_timeout_usec) - : sock_(sock), ssl_(ssl), read_timeout_sec_(read_timeout_sec), - read_timeout_usec_(read_timeout_usec), - write_timeout_sec_(write_timeout_sec), - write_timeout_usec_(write_timeout_usec) { - SSL_clear_mode(ssl, SSL_MODE_AUTO_RETRY); -} - -inline SSLSocketStream::~SSLSocketStream() = default; - -inline bool SSLSocketStream::is_readable() const { - return detail::select_read(sock_, read_timeout_sec_, read_timeout_usec_) > 0; -} - -inline bool SSLSocketStream::is_writable() const { - return select_write(sock_, write_timeout_sec_, write_timeout_usec_) > 0 && - is_socket_alive(sock_); -} - -inline ssize_t SSLSocketStream::read(char *ptr, size_t size) { - if (SSL_pending(ssl_) > 0) { - return SSL_read(ssl_, ptr, static_cast(size)); - } else if (is_readable()) { - auto ret = SSL_read(ssl_, ptr, static_cast(size)); - if (ret < 0) { - auto err = SSL_get_error(ssl_, ret); - auto n = 1000; -#ifdef _WIN32 - while (--n >= 0 && (err == SSL_ERROR_WANT_READ || - (err == SSL_ERROR_SYSCALL && - WSAGetLastError() == WSAETIMEDOUT))) { -#else - while (--n >= 0 && err == SSL_ERROR_WANT_READ) { -#endif - if (SSL_pending(ssl_) > 0) { - return SSL_read(ssl_, ptr, static_cast(size)); - } else if (is_readable()) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - ret = SSL_read(ssl_, ptr, static_cast(size)); - if (ret >= 0) { return ret; } - err = SSL_get_error(ssl_, ret); - } else { - return -1; - } - } - } - return ret; - } - return -1; -} - -inline ssize_t SSLSocketStream::write(const char *ptr, size_t size) { - if (is_writable()) { - auto handle_size = static_cast( - std::min(size, (std::numeric_limits::max)())); - - auto ret = SSL_write(ssl_, ptr, static_cast(handle_size)); - if (ret < 0) { - auto err = SSL_get_error(ssl_, ret); - auto n = 1000; -#ifdef _WIN32 - while (--n >= 0 && (err == SSL_ERROR_WANT_WRITE || - (err == SSL_ERROR_SYSCALL && - WSAGetLastError() == WSAETIMEDOUT))) { -#else - while (--n >= 0 && err == SSL_ERROR_WANT_WRITE) { -#endif - if (is_writable()) { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); - ret = SSL_write(ssl_, ptr, static_cast(handle_size)); - if (ret >= 0) { return ret; } - err = SSL_get_error(ssl_, ret); - } else { - return -1; - } - } - } - return ret; - } - return -1; -} - -inline void SSLSocketStream::get_remote_ip_and_port(std::string &ip, - int &port) const { - detail::get_remote_ip_and_port(sock_, ip, port); -} - -inline void SSLSocketStream::get_local_ip_and_port(std::string &ip, - int &port) const { - detail::get_local_ip_and_port(sock_, ip, port); -} - -inline socket_t SSLSocketStream::socket() const { return sock_; } - -static SSLInit sslinit_; - -} // namespace detail - -// SSL HTTP server implementation -inline SSLServer::SSLServer(const char *cert_path, const char *private_key_path, - const char *client_ca_cert_file_path, - const char *client_ca_cert_dir_path, - const char *private_key_password) { - ctx_ = SSL_CTX_new(TLS_server_method()); - - if (ctx_) { - SSL_CTX_set_options(ctx_, - SSL_OP_NO_COMPRESSION | - SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION); - - SSL_CTX_set_min_proto_version(ctx_, TLS1_1_VERSION); - - // add default password callback before opening encrypted private key - if (private_key_password != nullptr && (private_key_password[0] != '\0')) { - SSL_CTX_set_default_passwd_cb_userdata( - ctx_, - reinterpret_cast(const_cast(private_key_password))); - } - - if (SSL_CTX_use_certificate_chain_file(ctx_, cert_path) != 1 || - SSL_CTX_use_PrivateKey_file(ctx_, private_key_path, SSL_FILETYPE_PEM) != - 1) { - SSL_CTX_free(ctx_); - ctx_ = nullptr; - } else if (client_ca_cert_file_path || client_ca_cert_dir_path) { - SSL_CTX_load_verify_locations(ctx_, client_ca_cert_file_path, - client_ca_cert_dir_path); - - SSL_CTX_set_verify( - ctx_, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr); - } - } -} - -inline SSLServer::SSLServer(X509 *cert, EVP_PKEY *private_key, - X509_STORE *client_ca_cert_store) { - ctx_ = SSL_CTX_new(TLS_server_method()); - - if (ctx_) { - SSL_CTX_set_options(ctx_, - SSL_OP_NO_COMPRESSION | - SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION); - - SSL_CTX_set_min_proto_version(ctx_, TLS1_1_VERSION); - - if (SSL_CTX_use_certificate(ctx_, cert) != 1 || - SSL_CTX_use_PrivateKey(ctx_, private_key) != 1) { - SSL_CTX_free(ctx_); - ctx_ = nullptr; - } else if (client_ca_cert_store) { - SSL_CTX_set_cert_store(ctx_, client_ca_cert_store); - - SSL_CTX_set_verify( - ctx_, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, nullptr); - } - } -} - -inline SSLServer::SSLServer( - const std::function &setup_ssl_ctx_callback) { - ctx_ = SSL_CTX_new(TLS_method()); - if (ctx_) { - if (!setup_ssl_ctx_callback(*ctx_)) { - SSL_CTX_free(ctx_); - ctx_ = nullptr; - } - } -} - -inline SSLServer::~SSLServer() { - if (ctx_) { SSL_CTX_free(ctx_); } -} - -inline bool SSLServer::is_valid() const { return ctx_; } - -inline SSL_CTX *SSLServer::ssl_context() const { return ctx_; } - -inline bool SSLServer::process_and_close_socket(socket_t sock) { - auto ssl = detail::ssl_new( - sock, ctx_, ctx_mutex_, - [&](SSL *ssl2) { - return detail::ssl_connect_or_accept_nonblocking( - sock, ssl2, SSL_accept, read_timeout_sec_, read_timeout_usec_); - }, - [](SSL * /*ssl2*/) { return true; }); - - auto ret = false; - if (ssl) { - ret = detail::process_server_socket_ssl( - svr_sock_, ssl, sock, keep_alive_max_count_, keep_alive_timeout_sec_, - read_timeout_sec_, read_timeout_usec_, write_timeout_sec_, - write_timeout_usec_, - [this, ssl](Stream &strm, bool close_connection, - bool &connection_closed) { - return process_request(strm, close_connection, connection_closed, - [&](Request &req) { req.ssl = ssl; }); - }); - - // Shutdown gracefully if the result seemed successful, non-gracefully if - // the connection appeared to be closed. - const bool shutdown_gracefully = ret; - detail::ssl_delete(ctx_mutex_, ssl, shutdown_gracefully); - } - - detail::shutdown_socket(sock); - detail::close_socket(sock); - return ret; -} - -// SSL HTTP client implementation -inline SSLClient::SSLClient(const std::string &host) - : SSLClient(host, 443, std::string(), std::string()) {} - -inline SSLClient::SSLClient(const std::string &host, int port) - : SSLClient(host, port, std::string(), std::string()) {} - -inline SSLClient::SSLClient(const std::string &host, int port, - const std::string &client_cert_path, - const std::string &client_key_path) - : ClientImpl(host, port, client_cert_path, client_key_path) { - ctx_ = SSL_CTX_new(TLS_client_method()); - - detail::split(&host_[0], &host_[host_.size()], '.', - [&](const char *b, const char *e) { - host_components_.emplace_back(b, e); - }); - - if (!client_cert_path.empty() && !client_key_path.empty()) { - if (SSL_CTX_use_certificate_file(ctx_, client_cert_path.c_str(), - SSL_FILETYPE_PEM) != 1 || - SSL_CTX_use_PrivateKey_file(ctx_, client_key_path.c_str(), - SSL_FILETYPE_PEM) != 1) { - SSL_CTX_free(ctx_); - ctx_ = nullptr; - } - } -} - -inline SSLClient::SSLClient(const std::string &host, int port, - X509 *client_cert, EVP_PKEY *client_key) - : ClientImpl(host, port) { - ctx_ = SSL_CTX_new(TLS_client_method()); - - detail::split(&host_[0], &host_[host_.size()], '.', - [&](const char *b, const char *e) { - host_components_.emplace_back(b, e); - }); - - if (client_cert != nullptr && client_key != nullptr) { - if (SSL_CTX_use_certificate(ctx_, client_cert) != 1 || - SSL_CTX_use_PrivateKey(ctx_, client_key) != 1) { - SSL_CTX_free(ctx_); - ctx_ = nullptr; - } - } -} - -inline SSLClient::~SSLClient() { - if (ctx_) { SSL_CTX_free(ctx_); } - // Make sure to shut down SSL since shutdown_ssl will resolve to the - // base function rather than the derived function once we get to the - // base class destructor, and won't free the SSL (causing a leak). - shutdown_ssl_impl(socket_, true); -} - -inline bool SSLClient::is_valid() const { return ctx_; } - -inline void SSLClient::set_ca_cert_store(X509_STORE *ca_cert_store) { - if (ca_cert_store) { - if (ctx_) { - if (SSL_CTX_get_cert_store(ctx_) != ca_cert_store) { - // Free memory allocated for old cert and use new store `ca_cert_store` - SSL_CTX_set_cert_store(ctx_, ca_cert_store); - } - } else { - X509_STORE_free(ca_cert_store); - } - } -} - -inline void SSLClient::load_ca_cert_store(const char *ca_cert, - std::size_t size) { - set_ca_cert_store(ClientImpl::create_ca_cert_store(ca_cert, size)); -} - -inline long SSLClient::get_openssl_verify_result() const { - return verify_result_; -} - -inline SSL_CTX *SSLClient::ssl_context() const { return ctx_; } - -inline bool SSLClient::create_and_connect_socket(Socket &socket, Error &error) { - return is_valid() && ClientImpl::create_and_connect_socket(socket, error); -} - -// Assumes that socket_mutex_ is locked and that there are no requests in flight -inline bool SSLClient::connect_with_proxy(Socket &socket, Response &res, - bool &success, Error &error) { - success = true; - Response proxy_res; - if (!detail::process_client_socket( - socket.sock, read_timeout_sec_, read_timeout_usec_, - write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) { - Request req2; - req2.method = "CONNECT"; - req2.path = host_and_port_; - return process_request(strm, req2, proxy_res, false, error); - })) { - // Thread-safe to close everything because we are assuming there are no - // requests in flight - shutdown_ssl(socket, true); - shutdown_socket(socket); - close_socket(socket); - success = false; - return false; - } - - if (proxy_res.status == StatusCode::ProxyAuthenticationRequired_407) { - if (!proxy_digest_auth_username_.empty() && - !proxy_digest_auth_password_.empty()) { - std::map auth; - if (detail::parse_www_authenticate(proxy_res, auth, true)) { - proxy_res = Response(); - if (!detail::process_client_socket( - socket.sock, read_timeout_sec_, read_timeout_usec_, - write_timeout_sec_, write_timeout_usec_, [&](Stream &strm) { - Request req3; - req3.method = "CONNECT"; - req3.path = host_and_port_; - req3.headers.insert(detail::make_digest_authentication_header( - req3, auth, 1, detail::random_string(10), - proxy_digest_auth_username_, proxy_digest_auth_password_, - true)); - return process_request(strm, req3, proxy_res, false, error); - })) { - // Thread-safe to close everything because we are assuming there are - // no requests in flight - shutdown_ssl(socket, true); - shutdown_socket(socket); - close_socket(socket); - success = false; - return false; - } - } - } - } - - // If status code is not 200, proxy request is failed. - // Set error to ProxyConnection and return proxy response - // as the response of the request - if (proxy_res.status != StatusCode::OK_200) { - error = Error::ProxyConnection; - res = std::move(proxy_res); - // Thread-safe to close everything because we are assuming there are - // no requests in flight - shutdown_ssl(socket, true); - shutdown_socket(socket); - close_socket(socket); - return false; - } - - return true; -} - -inline bool SSLClient::load_certs() { - auto ret = true; - - std::call_once(initialize_cert_, [&]() { - std::lock_guard guard(ctx_mutex_); - if (!ca_cert_file_path_.empty()) { - if (!SSL_CTX_load_verify_locations(ctx_, ca_cert_file_path_.c_str(), - nullptr)) { - ret = false; - } - } else if (!ca_cert_dir_path_.empty()) { - if (!SSL_CTX_load_verify_locations(ctx_, nullptr, - ca_cert_dir_path_.c_str())) { - ret = false; - } - } else { - auto loaded = false; -#ifdef _WIN32 - loaded = - detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_)); -#elif defined(CPPHTTPLIB_USE_CERTS_FROM_MACOSX_KEYCHAIN) && defined(__APPLE__) -#if TARGET_OS_OSX - loaded = detail::load_system_certs_on_macos(SSL_CTX_get_cert_store(ctx_)); -#endif // TARGET_OS_OSX -#endif // _WIN32 - if (!loaded) { SSL_CTX_set_default_verify_paths(ctx_); } - } - }); - - return ret; -} - -inline bool SSLClient::initialize_ssl(Socket &socket, Error &error) { - auto ssl = detail::ssl_new( - socket.sock, ctx_, ctx_mutex_, - [&](SSL *ssl2) { - if (server_certificate_verification_) { - if (!load_certs()) { - error = Error::SSLLoadingCerts; - return false; - } - SSL_set_verify(ssl2, SSL_VERIFY_NONE, nullptr); - } - - if (!detail::ssl_connect_or_accept_nonblocking( - socket.sock, ssl2, SSL_connect, connection_timeout_sec_, - connection_timeout_usec_)) { - error = Error::SSLConnection; - return false; - } - - if (server_certificate_verification_) { - verify_result_ = SSL_get_verify_result(ssl2); - - if (verify_result_ != X509_V_OK) { - error = Error::SSLServerVerification; - return false; - } - - auto server_cert = SSL_get1_peer_certificate(ssl2); - - if (server_cert == nullptr) { - error = Error::SSLServerVerification; - return false; - } - - if (!verify_host(server_cert)) { - X509_free(server_cert); - error = Error::SSLServerVerification; - return false; - } - X509_free(server_cert); - } - - return true; - }, - [&](SSL *ssl2) { - // NOTE: Direct call instead of using the OpenSSL macro to suppress - // -Wold-style-cast warning - // SSL_set_tlsext_host_name(ssl2, host_.c_str()); - SSL_ctrl(ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name, - static_cast(const_cast(host_.c_str()))); - return true; - }); - - if (ssl) { - socket.ssl = ssl; - return true; - } - - shutdown_socket(socket); - close_socket(socket); - return false; -} - -inline void SSLClient::shutdown_ssl(Socket &socket, bool shutdown_gracefully) { - shutdown_ssl_impl(socket, shutdown_gracefully); -} - -inline void SSLClient::shutdown_ssl_impl(Socket &socket, - bool shutdown_gracefully) { - if (socket.sock == INVALID_SOCKET) { - assert(socket.ssl == nullptr); - return; - } - if (socket.ssl) { - detail::ssl_delete(ctx_mutex_, socket.ssl, shutdown_gracefully); - socket.ssl = nullptr; - } - assert(socket.ssl == nullptr); -} - -inline bool -SSLClient::process_socket(const Socket &socket, - std::function callback) { - assert(socket.ssl); - return detail::process_client_socket_ssl( - socket.ssl, socket.sock, read_timeout_sec_, read_timeout_usec_, - write_timeout_sec_, write_timeout_usec_, std::move(callback)); -} - -inline bool SSLClient::is_ssl() const { return true; } - -inline bool SSLClient::verify_host(X509 *server_cert) const { - /* Quote from RFC2818 section 3.1 "Server Identity" - - If a subjectAltName extension of type dNSName is present, that MUST - be used as the identity. Otherwise, the (most specific) Common Name - field in the Subject field of the certificate MUST be used. Although - the use of the Common Name is existing practice, it is deprecated and - Certification Authorities are encouraged to use the dNSName instead. - - Matching is performed using the matching rules specified by - [RFC2459]. If more than one identity of a given type is present in - the certificate (e.g., more than one dNSName name, a match in any one - of the set is considered acceptable.) Names may contain the wildcard - character * which is considered to match any single domain name - component or component fragment. E.g., *.a.com matches foo.a.com but - not bar.foo.a.com. f*.com matches foo.com but not bar.com. - - In some cases, the URI is specified as an IP address rather than a - hostname. In this case, the iPAddress subjectAltName must be present - in the certificate and must exactly match the IP in the URI. - - */ - return verify_host_with_subject_alt_name(server_cert) || - verify_host_with_common_name(server_cert); -} - -inline bool -SSLClient::verify_host_with_subject_alt_name(X509 *server_cert) const { - auto ret = false; - - auto type = GEN_DNS; - - struct in6_addr addr6 {}; - struct in_addr addr {}; - size_t addr_len = 0; - -#ifndef __MINGW32__ - if (inet_pton(AF_INET6, host_.c_str(), &addr6)) { - type = GEN_IPADD; - addr_len = sizeof(struct in6_addr); - } else if (inet_pton(AF_INET, host_.c_str(), &addr)) { - type = GEN_IPADD; - addr_len = sizeof(struct in_addr); - } -#endif - - auto alt_names = static_cast( - X509_get_ext_d2i(server_cert, NID_subject_alt_name, nullptr, nullptr)); - - if (alt_names) { - auto dsn_matched = false; - auto ip_matched = false; - - auto count = sk_GENERAL_NAME_num(alt_names); - - for (decltype(count) i = 0; i < count && !dsn_matched; i++) { - auto val = sk_GENERAL_NAME_value(alt_names, i); - if (val->type == type) { - auto name = - reinterpret_cast(ASN1_STRING_get0_data(val->d.ia5)); - auto name_len = static_cast(ASN1_STRING_length(val->d.ia5)); - - switch (type) { - case GEN_DNS: dsn_matched = check_host_name(name, name_len); break; - - case GEN_IPADD: - if (!memcmp(&addr6, name, addr_len) || - !memcmp(&addr, name, addr_len)) { - ip_matched = true; - } - break; - } - } - } - - if (dsn_matched || ip_matched) { ret = true; } - } - - GENERAL_NAMES_free(const_cast( - reinterpret_cast(alt_names))); - return ret; -} - -inline bool SSLClient::verify_host_with_common_name(X509 *server_cert) const { - const auto subject_name = X509_get_subject_name(server_cert); - - if (subject_name != nullptr) { - char name[BUFSIZ]; - auto name_len = X509_NAME_get_text_by_NID(subject_name, NID_commonName, - name, sizeof(name)); - - if (name_len != -1) { - return check_host_name(name, static_cast(name_len)); - } - } - - return false; -} - -inline bool SSLClient::check_host_name(const char *pattern, - size_t pattern_len) const { - if (host_.size() == pattern_len && host_ == pattern) { return true; } - - // Wildcard match - // https://bugs.launchpad.net/ubuntu/+source/firefox-3.0/+bug/376484 - std::vector pattern_components; - detail::split(&pattern[0], &pattern[pattern_len], '.', - [&](const char *b, const char *e) { - pattern_components.emplace_back(b, e); - }); - - if (host_components_.size() != pattern_components.size()) { return false; } - - auto itr = pattern_components.begin(); - for (const auto &h : host_components_) { - auto &p = *itr; - if (p != h && p != "*") { - auto partial_match = (p.size() > 0 && p[p.size() - 1] == '*' && - !p.compare(0, p.size() - 1, h)); - if (!partial_match) { return false; } - } - ++itr; - } - - return true; -} -#endif - -// Universal client implementation -inline Client::Client(const std::string &scheme_host_port) - : Client(scheme_host_port, std::string(), std::string()) {} - -inline Client::Client(const std::string &scheme_host_port, - const std::string &client_cert_path, - const std::string &client_key_path) { - const static std::regex re( - R"((?:([a-z]+):\/\/)?(?:\[([\d:]+)\]|([^:/?#]+))(?::(\d+))?)"); - - std::smatch m; - if (std::regex_match(scheme_host_port, m, re)) { - auto scheme = m[1].str(); - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - if (!scheme.empty() && (scheme != "http" && scheme != "https")) { -#else - if (!scheme.empty() && scheme != "http") { -#endif -#ifndef CPPHTTPLIB_NO_EXCEPTIONS - std::string msg = "'" + scheme + "' scheme is not supported."; - throw std::invalid_argument(msg); -#endif - return; - } - - auto is_ssl = scheme == "https"; - - auto host = m[2].str(); - if (host.empty()) { host = m[3].str(); } - - auto port_str = m[4].str(); - auto port = !port_str.empty() ? std::stoi(port_str) : (is_ssl ? 443 : 80); - - if (is_ssl) { -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT - cli_ = detail::make_unique(host, port, client_cert_path, - client_key_path); - is_ssl_ = is_ssl; -#endif - } else { - cli_ = detail::make_unique(host, port, client_cert_path, - client_key_path); - } - } else { - cli_ = detail::make_unique(scheme_host_port, 80, - client_cert_path, client_key_path); - } -} - -inline Client::Client(const std::string &host, int port) - : cli_(detail::make_unique(host, port)) {} - -inline Client::Client(const std::string &host, int port, - const std::string &client_cert_path, - const std::string &client_key_path) - : cli_(detail::make_unique(host, port, client_cert_path, - client_key_path)) {} - -inline Client::~Client() = default; - -inline bool Client::is_valid() const { - return cli_ != nullptr && cli_->is_valid(); -} - -inline Result Client::Get(const std::string &path) { return cli_->Get(path); } -inline Result Client::Get(const std::string &path, const Headers &headers) { - return cli_->Get(path, headers); -} -inline Result Client::Get(const std::string &path, Progress progress) { - return cli_->Get(path, std::move(progress)); -} -inline Result Client::Get(const std::string &path, const Headers &headers, - Progress progress) { - return cli_->Get(path, headers, std::move(progress)); -} -inline Result Client::Get(const std::string &path, - ContentReceiver content_receiver) { - return cli_->Get(path, std::move(content_receiver)); -} -inline Result Client::Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver) { - return cli_->Get(path, headers, std::move(content_receiver)); -} -inline Result Client::Get(const std::string &path, - ContentReceiver content_receiver, Progress progress) { - return cli_->Get(path, std::move(content_receiver), std::move(progress)); -} -inline Result Client::Get(const std::string &path, const Headers &headers, - ContentReceiver content_receiver, Progress progress) { - return cli_->Get(path, headers, std::move(content_receiver), - std::move(progress)); -} -inline Result Client::Get(const std::string &path, - ResponseHandler response_handler, - ContentReceiver content_receiver) { - return cli_->Get(path, std::move(response_handler), - std::move(content_receiver)); -} -inline Result Client::Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver) { - return cli_->Get(path, headers, std::move(response_handler), - std::move(content_receiver)); -} -inline Result Client::Get(const std::string &path, - ResponseHandler response_handler, - ContentReceiver content_receiver, Progress progress) { - return cli_->Get(path, std::move(response_handler), - std::move(content_receiver), std::move(progress)); -} -inline Result Client::Get(const std::string &path, const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver, Progress progress) { - return cli_->Get(path, headers, std::move(response_handler), - std::move(content_receiver), std::move(progress)); -} -inline Result Client::Get(const std::string &path, const Params ¶ms, - const Headers &headers, Progress progress) { - return cli_->Get(path, params, headers, progress); -} -inline Result Client::Get(const std::string &path, const Params ¶ms, - const Headers &headers, - ContentReceiver content_receiver, Progress progress) { - return cli_->Get(path, params, headers, content_receiver, progress); -} -inline Result Client::Get(const std::string &path, const Params ¶ms, - const Headers &headers, - ResponseHandler response_handler, - ContentReceiver content_receiver, Progress progress) { - return cli_->Get(path, params, headers, response_handler, content_receiver, - progress); -} - -inline Result Client::Head(const std::string &path) { return cli_->Head(path); } -inline Result Client::Head(const std::string &path, const Headers &headers) { - return cli_->Head(path, headers); -} - -inline Result Client::Post(const std::string &path) { return cli_->Post(path); } -inline Result Client::Post(const std::string &path, const Headers &headers) { - return cli_->Post(path, headers); -} -inline Result Client::Post(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return cli_->Post(path, body, content_length, content_type); -} -inline Result Client::Post(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type) { - return cli_->Post(path, headers, body, content_length, content_type); -} -inline Result Client::Post(const std::string &path, const std::string &body, - const std::string &content_type) { - return cli_->Post(path, body, content_type); -} -inline Result Client::Post(const std::string &path, const Headers &headers, - const std::string &body, - const std::string &content_type) { - return cli_->Post(path, headers, body, content_type); -} -inline Result Client::Post(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return cli_->Post(path, content_length, std::move(content_provider), - content_type); -} -inline Result Client::Post(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return cli_->Post(path, std::move(content_provider), content_type); -} -inline Result Client::Post(const std::string &path, const Headers &headers, - size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return cli_->Post(path, headers, content_length, std::move(content_provider), - content_type); -} -inline Result Client::Post(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return cli_->Post(path, headers, std::move(content_provider), content_type); -} -inline Result Client::Post(const std::string &path, const Params ¶ms) { - return cli_->Post(path, params); -} -inline Result Client::Post(const std::string &path, const Headers &headers, - const Params ¶ms) { - return cli_->Post(path, headers, params); -} -inline Result Client::Post(const std::string &path, - const MultipartFormDataItems &items) { - return cli_->Post(path, items); -} -inline Result Client::Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items) { - return cli_->Post(path, headers, items); -} -inline Result Client::Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const std::string &boundary) { - return cli_->Post(path, headers, items, boundary); -} -inline Result -Client::Post(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items) { - return cli_->Post(path, headers, items, provider_items); -} -inline Result Client::Put(const std::string &path) { return cli_->Put(path); } -inline Result Client::Put(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return cli_->Put(path, body, content_length, content_type); -} -inline Result Client::Put(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type) { - return cli_->Put(path, headers, body, content_length, content_type); -} -inline Result Client::Put(const std::string &path, const std::string &body, - const std::string &content_type) { - return cli_->Put(path, body, content_type); -} -inline Result Client::Put(const std::string &path, const Headers &headers, - const std::string &body, - const std::string &content_type) { - return cli_->Put(path, headers, body, content_type); -} -inline Result Client::Put(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return cli_->Put(path, content_length, std::move(content_provider), - content_type); -} -inline Result Client::Put(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return cli_->Put(path, std::move(content_provider), content_type); -} -inline Result Client::Put(const std::string &path, const Headers &headers, - size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return cli_->Put(path, headers, content_length, std::move(content_provider), - content_type); -} -inline Result Client::Put(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return cli_->Put(path, headers, std::move(content_provider), content_type); -} -inline Result Client::Put(const std::string &path, const Params ¶ms) { - return cli_->Put(path, params); -} -inline Result Client::Put(const std::string &path, const Headers &headers, - const Params ¶ms) { - return cli_->Put(path, headers, params); -} -inline Result Client::Put(const std::string &path, - const MultipartFormDataItems &items) { - return cli_->Put(path, items); -} -inline Result Client::Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items) { - return cli_->Put(path, headers, items); -} -inline Result Client::Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const std::string &boundary) { - return cli_->Put(path, headers, items, boundary); -} -inline Result -Client::Put(const std::string &path, const Headers &headers, - const MultipartFormDataItems &items, - const MultipartFormDataProviderItems &provider_items) { - return cli_->Put(path, headers, items, provider_items); -} -inline Result Client::Patch(const std::string &path) { - return cli_->Patch(path); -} -inline Result Client::Patch(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return cli_->Patch(path, body, content_length, content_type); -} -inline Result Client::Patch(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type) { - return cli_->Patch(path, headers, body, content_length, content_type); -} -inline Result Client::Patch(const std::string &path, const std::string &body, - const std::string &content_type) { - return cli_->Patch(path, body, content_type); -} -inline Result Client::Patch(const std::string &path, const Headers &headers, - const std::string &body, - const std::string &content_type) { - return cli_->Patch(path, headers, body, content_type); -} -inline Result Client::Patch(const std::string &path, size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return cli_->Patch(path, content_length, std::move(content_provider), - content_type); -} -inline Result Client::Patch(const std::string &path, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return cli_->Patch(path, std::move(content_provider), content_type); -} -inline Result Client::Patch(const std::string &path, const Headers &headers, - size_t content_length, - ContentProvider content_provider, - const std::string &content_type) { - return cli_->Patch(path, headers, content_length, std::move(content_provider), - content_type); -} -inline Result Client::Patch(const std::string &path, const Headers &headers, - ContentProviderWithoutLength content_provider, - const std::string &content_type) { - return cli_->Patch(path, headers, std::move(content_provider), content_type); -} -inline Result Client::Delete(const std::string &path) { - return cli_->Delete(path); -} -inline Result Client::Delete(const std::string &path, const Headers &headers) { - return cli_->Delete(path, headers); -} -inline Result Client::Delete(const std::string &path, const char *body, - size_t content_length, - const std::string &content_type) { - return cli_->Delete(path, body, content_length, content_type); -} -inline Result Client::Delete(const std::string &path, const Headers &headers, - const char *body, size_t content_length, - const std::string &content_type) { - return cli_->Delete(path, headers, body, content_length, content_type); -} -inline Result Client::Delete(const std::string &path, const std::string &body, - const std::string &content_type) { - return cli_->Delete(path, body, content_type); -} -inline Result Client::Delete(const std::string &path, const Headers &headers, - const std::string &body, - const std::string &content_type) { - return cli_->Delete(path, headers, body, content_type); -} -inline Result Client::Options(const std::string &path) { - return cli_->Options(path); -} -inline Result Client::Options(const std::string &path, const Headers &headers) { - return cli_->Options(path, headers); -} - -inline bool Client::send(Request &req, Response &res, Error &error) { - return cli_->send(req, res, error); -} - -inline Result Client::send(const Request &req) { return cli_->send(req); } - -inline void Client::stop() { cli_->stop(); } - -inline std::string Client::host() const { return cli_->host(); } - -inline int Client::port() const { return cli_->port(); } - -inline size_t Client::is_socket_open() const { return cli_->is_socket_open(); } - -inline socket_t Client::socket() const { return cli_->socket(); } - -inline void -Client::set_hostname_addr_map(std::map addr_map) { - cli_->set_hostname_addr_map(std::move(addr_map)); -} - -inline void Client::set_default_headers(Headers headers) { - cli_->set_default_headers(std::move(headers)); -} - -inline void Client::set_header_writer( - std::function const &writer) { - cli_->set_header_writer(writer); -} - -inline void Client::set_address_family(int family) { - cli_->set_address_family(family); -} - -inline void Client::set_tcp_nodelay(bool on) { cli_->set_tcp_nodelay(on); } - -inline void Client::set_socket_options(SocketOptions socket_options) { - cli_->set_socket_options(std::move(socket_options)); -} - -inline void Client::set_connection_timeout(time_t sec, time_t usec) { - cli_->set_connection_timeout(sec, usec); -} - -inline void Client::set_read_timeout(time_t sec, time_t usec) { - cli_->set_read_timeout(sec, usec); -} - -inline void Client::set_write_timeout(time_t sec, time_t usec) { - cli_->set_write_timeout(sec, usec); -} - -inline void Client::set_basic_auth(const std::string &username, - const std::string &password) { - cli_->set_basic_auth(username, password); -} -inline void Client::set_bearer_token_auth(const std::string &token) { - cli_->set_bearer_token_auth(token); -} -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline void Client::set_digest_auth(const std::string &username, - const std::string &password) { - cli_->set_digest_auth(username, password); -} -#endif - -inline void Client::set_keep_alive(bool on) { cli_->set_keep_alive(on); } -inline void Client::set_follow_location(bool on) { - cli_->set_follow_location(on); -} - -inline void Client::set_url_encode(bool on) { cli_->set_url_encode(on); } - -inline void Client::set_compress(bool on) { cli_->set_compress(on); } - -inline void Client::set_decompress(bool on) { cli_->set_decompress(on); } - -inline void Client::set_interface(const std::string &intf) { - cli_->set_interface(intf); -} - -inline void Client::set_proxy(const std::string &host, int port) { - cli_->set_proxy(host, port); -} -inline void Client::set_proxy_basic_auth(const std::string &username, - const std::string &password) { - cli_->set_proxy_basic_auth(username, password); -} -inline void Client::set_proxy_bearer_token_auth(const std::string &token) { - cli_->set_proxy_bearer_token_auth(token); -} -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline void Client::set_proxy_digest_auth(const std::string &username, - const std::string &password) { - cli_->set_proxy_digest_auth(username, password); -} -#endif - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline void Client::enable_server_certificate_verification(bool enabled) { - cli_->enable_server_certificate_verification(enabled); -} -#endif - -inline void Client::set_logger(Logger logger) { - cli_->set_logger(std::move(logger)); -} - -#ifdef CPPHTTPLIB_OPENSSL_SUPPORT -inline void Client::set_ca_cert_path(const std::string &ca_cert_file_path, - const std::string &ca_cert_dir_path) { - cli_->set_ca_cert_path(ca_cert_file_path, ca_cert_dir_path); -} - -inline void Client::set_ca_cert_store(X509_STORE *ca_cert_store) { - if (is_ssl_) { - static_cast(*cli_).set_ca_cert_store(ca_cert_store); - } else { - cli_->set_ca_cert_store(ca_cert_store); - } -} - -inline void Client::load_ca_cert_store(const char *ca_cert, std::size_t size) { - set_ca_cert_store(cli_->create_ca_cert_store(ca_cert, size)); -} - -inline long Client::get_openssl_verify_result() const { - if (is_ssl_) { - return static_cast(*cli_).get_openssl_verify_result(); - } - return -1; // NOTE: -1 doesn't match any of X509_V_ERR_??? -} - -inline SSL_CTX *Client::ssl_context() const { - if (is_ssl_) { return static_cast(*cli_).ssl_context(); } - return nullptr; -} -#endif - -// ---------------------------------------------------------------------------- - -} // namespace httplib - -#if defined(_WIN32) && defined(CPPHTTPLIB_USE_POLL) -#undef poll -#endif - -#endif // CPPHTTPLIB_HTTPLIB_H diff --git a/ai_matrix/framework/EngineManager.cpp b/ai_matrix/framework/EngineManager.cpp index f0c1d7d..f19cbbc 100644 --- a/ai_matrix/framework/EngineManager.cpp +++ b/ai_matrix/framework/EngineManager.cpp @@ -104,11 +104,10 @@ namespace ai_matrix //检查是否有重复engine std::string engine_unique = engine_name + "_" + std::to_string(engine_id); -// printf(engine_unique.c_str()); + printf(engine_unique.c_str()); auto iter = engine_map_.find(engine_unique); if (iter != engine_map_.end()) { - LogWarn << "重复engine :" << engine_unique; continue; } diff --git a/ai_matrix/myutils/myutils.h b/ai_matrix/myutils/myutils.h index a92174d..d145748 100644 --- a/ai_matrix/myutils/myutils.h +++ b/ai_matrix/myutils/myutils.h @@ -55,6 +55,7 @@ namespace ai_matrix std::string get_date(); //获取时间 std::string get_time(); + //时间戳转化为时间 毫秒级 std::string Stamp2Time(long long timestamp, bool has_msec = false); diff --git a/config.yaml b/config.yaml index 97cf359..f388b67 100644 --- a/config.yaml +++ b/config.yaml @@ -1,26 +1,19 @@ -#acl参数 -stop_delay_count: 64 -stop_by_vari: 0 -gc_acl_path: ./config/acl.json -gc_init_deviceid: "ALL" #例: 0; 0,1; 2,3; ALL - -method_setting: ./modeltest/model +gc_init_deviceid: "ALL" #例: 0; 0,1; 2,3; ALL #识别数据来源参数配置 gc_data_source: "camera" #[camera, images] camera: - camera_0: - #url: "rtsp://admin:sgt12345@10.27.119.13:554/h264/ch1/main/av_stream" - # url: "./videos/km70.mp4" - url: "./vedio/buertai2.mp4" - skipInterval: 3 - target: "NUM" - use: true - direction: 0 #行驶方向 0-自动识别 1-向左 2-向右 (与“首位信息”成对存在,形成例如向左就编号在前,向右就属性在前的对应) - left_first: 0 # 0-向左编号在前 1-向左属性在前 (向右行驶的情况:2-向右编号在前 3-向右属性在前) - right_first: 3 # (向左行驶的情况:0-向左编号在前 1-向左属性在前) 2-向右编号在前 3-向右属性在前 - identify_areas: "120, 0, 1800, 1080" #(ltx,lty,rbx,rby) - classid_minheight: "1:90, 2:120, 3:120, 9:240, 10:240, 18:120" #大框的最小高度(为屏蔽远股道识别到的信息) + #url: "rtsp://admin:sgt12345@10.27.119.13:554/h264/ch1/main/av_stream" + # url: "./videos/km70.mp4" + url: "./videos/06-29_96.mp4" + skipInterval: 3 + target: "NUM" + use: true + direction: 0 #行驶方向 0-自动识别 1-向左 2-向右 (与“首位信息”成对存在,形成例如向左就编号在前,向右就属性在前的对应) + left_first: 0 # 0-向左编号在前 1-向左属性在前 (向右行驶的情况:2-向右编号在前 3-向右属性在前) + right_first: 3 # (向左行驶的情况:0-向左编号在前 1-向左属性在前) 2-向右编号在前 3-向右属性在前 + identify_areas: "120, 0, 1800, 1080" #(ltx,lty,rbx,rby) + classid_minheight: "1:90, 2:120, 3:120, 9:240, 10:240, 18:120" #大框的最小高度(为屏蔽远股道识别到的信息) images: images_0: url: "./images" @@ -116,8 +109,11 @@ model: nms_threshold: 0.3 gc_http_open: 0 -username: "guest_01" -password: "d55b0f642e817eea24725d2f2a31dd08" # 神东 +# gc_http_url: "http://192.168.2.211:20004/api/train-carriage/identification/video-save" +# gc_gettoken_url: "http://192.168.2.211:20004/api/blade-auth/oauth/token" +# gc_image_srv: "http://192.168.2.211:9010/" +username: "" +password: "" gc_http_url: "http://192.168.2.121:8081" gc_gettoken_url: "http://192.168.0.121:20004/api/blade-auth/oauth/token" gc_image_srv: "http://192.168.0.121:9010/" @@ -158,7 +154,7 @@ gc_mysql_passwd: "123456" gc_mysql_db: "test1" gc_mysql_port: "http://192.168.2.115:9000" -gc_push_direction: 1 #(1:识别向左行驶的列车,2:识别向右行驶的列车,0:识别双方向。 注:如果方向不对,服务器会正常识别只是不推送给web) +gc_push_direction: 2 #(1:识别向左行驶的列车,2:识别向右行驶的列车,0:识别双方向。 注:如果方向不对,服务器会正常识别只是不推送给web) gc_space_minrbx_imgpercent: 0 #间隔框最低点不应小于画面某个高度值(该值为画面百分比) [主要为屏蔽远股道间隔框,若不需要屏蔽则配置为0] diff --git a/nvidia_ascend_engine/common/AppCommon.h b/nvidia_ascend_engine/common/AppCommon.h index 2cdea93..3c20bd9 100644 --- a/nvidia_ascend_engine/common/AppCommon.h +++ b/nvidia_ascend_engine/common/AppCommon.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include #include @@ -459,10 +459,10 @@ typedef struct std::shared_ptr pSrcData; // Smart pointer of data(源数据) 推理时,RGB数据会拷贝一份,源数据不变用于传送到后处理引擎画框,另一份数据用于resize成640x640并归一化到0-1 uint64_t i64TimeStamp = 0; //帧数据时间戳 Step1Location step1Location; //step2 use - int iTargetType; //目标类别 (0:车号; 1:属性; 2:车头; 3:定检期; 4:集装箱) + int iTargetType; //目标类别 (0:车号; 1:属性; 2:车头; 3:定检期; 4:集装箱) int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号) int iCarXH = 0; //当前大框所属车厢 - + } InferenceData; @@ -491,7 +491,7 @@ typedef struct std::shared_ptr pData = nullptr; // Smart pointer of data uint64_t i64TimeStamp = 0; //帧数据时间戳 bool bHostMemory = false; //数据解码后内存是否在Host侧 - std::string strPicFilePath; + std::string strPicFilePath; std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD) std::string strTrainName; //车次 (格式:HH-MM-SS) bool bIsEnd = false; //列车结束标识 @@ -756,7 +756,7 @@ typedef struct std::string strTrainDate; //过车日期 (格式:YYYY-MM-DD) std::string strTrainName; //车次 (格式:HH-MM-SS) std::string strContainerNo; //集装箱号 - std::string strBestImg; //集装箱最优图 + std::string strBestImg; //集装箱最优图 float fScoreSum = 0; //集装箱最优图总得分, 取最优帧用 uint64_t i64TimeStamp = 0; //集装箱最优图时间戳 Step1Location step1Location; //原图上大框坐标 @@ -832,30 +832,30 @@ typedef struct imganalyse { // from file /////////下述设定取自csv文件 - int nType; //算法目的 0:动态检测 1:车厢划分 - int nAreaX1; //算法监测区域 开始位置x坐标 - int nAreaY1; //算法监测区域 开始位置y坐标 - int nAreaX2; //算法监测区域 结束位置x坐标 - int nAreaY2; //算法监测区域 结束位置y坐标 - int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算 - bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true:以匹配度不同作为判定条件 - bool bOn; //是否启用改区域匹配监测(该算法是否有效) false:不启用(无效) true:启用(有效) - double dSameThresholdVal; //判定匹配相同的阈值 - double dDiffThresholdVal; //判定匹配不同的阈值 - int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车) - int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义) - int templemethod; //模型比对模式 - int histmethod; //直方图比对模式 - int specmethod; //自定义比对模式 - int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选) - std::string baseImagePath; //基准图片路径 + int nType; //算法目的 0:动态检测 1:车厢划分 + int nAreaX1; //算法监测区域 开始位置x坐标 + int nAreaY1; //算法监测区域 开始位置y坐标 + int nAreaX2; //算法监测区域 结束位置x坐标 + int nAreaY2; //算法监测区域 结束位置y坐标 + int bOrLevel; //算法结果融合等级 相同值进行与运算 不同值进行或运算 + bool bDiff; //是否以不同作为判断条件 false:以匹配度相同作为判定条件 true:以匹配度不同作为判定条件 + bool bOn; //是否启用改区域匹配监测(该算法是否有效) false:不启用(无效) true:启用(有效) + double dSameThresholdVal; //判定匹配相同的阈值 + double dDiffThresholdVal; //判定匹配不同的阈值 + int nPauseMaxCoumt; //判定为停车的最大计量(超过设定值判定为停车) + int npicimprovetype; //图像改善处理(包含 灰度化/均衡化直方图/gamma变换/自定义) + int templemethod; //模型比对模式 + int histmethod; //直方图比对模式 + int specmethod; //自定义比对模式 + int compmethod; //对比类型(模型比对/模型比对/自定义比对,可多选) + std::string baseImagePath; //基准图片路径 /////////下述设定为处理识别变量 - double dComparePoint; //比对值 + double dComparePoint; //比对值 double dPreComparePoint; //比对值 - bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化 - bool bPreChanged; //上一帧与基准图对比值 + bool bChanged; //与基准图对比值 是否发生变化 true:发生变化 false:没有发生变化 + bool bPreChanged; //上一帧与基准图对比值 bool fluctuationFlag; //最近100帧的最大值与最小值的波动标志 - int nSameCount; //比对值没有发生变化的计数 + int nSameCount; //比对值没有发生变化的计数 int iIndex; //第几个配置项 }AnalyseInfo; @@ -866,25 +866,25 @@ typedef struct trainpartion { std::string strTrainDate; std::string strTrainName; - int nindex; //车厢顺位 - uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间 - uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间 - float fspeed; //当节车厢的车速 - int startframe; //当节车厢出现的开始帧帧号 - int endframe; //当节车厢出现的结束帧帧号 + int nindex; //车厢顺位 + uint64_t i64StartTimeStamp; //当节车厢出现的开始帧时间 + uint64_t i64EndTimeStamp; //当节车厢出现的结束帧时间 + float fspeed; //当节车厢的车速 + int startframe; //当节车厢出现的开始帧帧号 + int endframe; //当节车厢出现的结束帧帧号 int modelSpaceFrame; - bool bfuncconfirmed; //是否算法划分完成 true:是 false:否 - bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否 - float fLTX; //车钩开始位置X值 - float fLTY; //车钩开始位置y值 - float fRBX; //车钩结束位置X值 - float fRBY; //车钩结束位置y值 + bool bfuncconfirmed; //是否算法划分完成 true:是 false:否 + bool bmodelconfirmed; //是否根据第一次识别结果确认完成 true:是 false:否 + float fLTX; //车钩开始位置X值 + float fLTY; //车钩开始位置y值 + float fRBX; //车钩结束位置X值 + float fRBY; //车钩结束位置y值 bool bIsEnd = false; //是否最后一节 int nStatus; //方向(0:未知,1:向左行驶,2:向右行驶) int iRate; //帧率 }PartionInfo; -typedef struct +typedef struct { std::shared_ptr processData; std::string strAllClassType; @@ -895,7 +895,8 @@ typedef struct { int iBigClassId = -1; //大框id (给第二步用 1-属性 23456-编号) uint32_t iFrameId = 0; //帧号 - float fCenterX; //第一步识别目标中心点X坐标 + float fCenterX; //第一步识别目标中心点X坐标 + float fTargetWidth; // 第一步识别目标X坐标宽度 } CalculateInfo; diff --git a/nvidia_ascend_engine/common_engine/ControlEngine/ControlEngine.cpp b/nvidia_ascend_engine/common_engine/ControlEngine/ControlEngine.cpp deleted file mode 100644 index 5977885..0000000 --- a/nvidia_ascend_engine/common_engine/ControlEngine/ControlEngine.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "ControlEngine.h" - - -using namespace ai_matrix; - -ControlEngine::ControlEngine() {} - -ControlEngine::~ControlEngine() {} - -APP_ERROR ControlEngine::Init() -{ - bUseEngine_ = true; - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 - if (!dataSourceConfig_.bUse) - { - bUseEngine_ = false; - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - bHwDecode_ = MyYaml::GetIns()->GetBoolValue("gc_hardware_decode");//硬解码 - - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - strPort2_ = engineName_ + "_" + std::to_string(engineId_) + "_2"; - bCommandFlag_ = (MyYaml::GetIns()->GetStringValue("gc_run_mode") == "command"); - bCollectDataFlag_ = MyYaml::GetIns()->GetBoolValue("gc_collect_data_flag"); - strCollectDataSavePath_ = MyYaml::GetIns()->GetPathValue("gc_collect_data_savepath"); - bPushActualFlag_ = MyYaml::GetIns()->GetBoolValue("gc_push_actual_flag"); - - LogInfo << "ControlEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR ControlEngine::DeInit() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - LogInfo << "ControlEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* 获取检测状态 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void ControlEngine::GetDetectState() -{ - // 1.一直识别模式 - if (!bCommandFlag_) - { - iStepInter_ = 1; - return; - } - - //2.命令触发识别模式 - int iRet = APP_ERR_OK; - std::shared_ptr pVoidData1 = nullptr; - iRet = inputQueMap_[strPort1_]->pop(pVoidData1); - if (nullptr != pVoidData1) - { - std::shared_ptr pstrCommand = std::static_pointer_cast(pVoidData1); - LogDebug << "recv Command:" << *pstrCommand; - - if ((*pstrCommand) == "start") - { - iStepInter_ = 1; - } - else if ((*pstrCommand) == "end") - { - if (iStepInter_ == 1) - { - iStepInter_ = 2; - } - else - { - LogError << "command:end is worng"; - } - } - } - - //未接受到新命令,按上次命令结果返回 -} - -APP_ERROR ControlEngine::Process() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - int iRet = APP_ERR_OK; - while (!isStop_) - { - //获取识别状态 - GetDetectState(); - - //pop端口0,解码后数据 - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } - - std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); - - //1. 识别处理 - if (iStepInter_ != 0) - { - pProcessData->iStatus = TRAINSTATUS_RUN; - pProcessData->bIsEnd = ((iStepInter_ == 2) ? true : false); - - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData)); - if (iStepInter_ == 2) - { - iStepInter_ = 0; - } - } - - //2.图片采集 - if (bCollectDataFlag_) - { - //组织数据 push端口0 存图 - std::shared_ptr pSaveImgData = std::make_shared(); - pSaveImgData->iFrameId = pProcessData->iFrameId; //帧号 - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pProcessData->iDataSource + 1); - pSaveImgData->strImgPath = strCollectDataSavePath_ + szCameraNo; - pSaveImgData->strImgName = std::to_string(pSaveImgData->iFrameId); - pSaveImgData->strImgName += "_"; - pSaveImgData->strImgName += std::to_string(pProcessData->i64TimeStamp); - pSaveImgData->strImgName += ".jpg"; - iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast(pSaveImgData)); - continue; - } - - //3.直播推流 - if(bPushActualFlag_) - { - //发送推流Egnine - //iRet = outputQueMap_[strPort2_]->push(std::static_pointer_cast(pProcessData)); - } - } - return APP_ERR_OK; -} diff --git a/nvidia_ascend_engine/common_engine/ControlEngine/ControlEngine.h b/nvidia_ascend_engine/common_engine/ControlEngine/ControlEngine.h deleted file mode 100644 index ccdfff8..0000000 --- a/nvidia_ascend_engine/common_engine/ControlEngine/ControlEngine.h +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 控制识别Engine - * */ - -#ifndef CONTROLENGINE_H -#define CONTROLENGINE_H - -#include "AppCommon.h" -#include "MyYaml.h" -#include "myutils.h" -#include "EngineBase.h" -#include "EngineFactory.h" - -class ControlEngine : public ai_matrix::EngineBase -{ -public: - ControlEngine(); - ~ControlEngine(); - - APP_ERROR Init() override; - APP_ERROR DeInit() override; - APP_ERROR Process() override; - -private: - //获取检测状态 - void GetDetectState(); - - bool bUseEngine_; - ai_matrix::DataSourceConfig dataSourceConfig_; - std::string save_path_; - std::string strPort0_; - std::string strPort1_; - std::string strPort2_; - bool bCommandFlag_; //命令触发识别模式 - bool bHwDecode_; - bool bCollectDataFlag_; - std::string strCollectDataSavePath_; - bool bPushActualFlag_; //是否实时推流-用于直播 - int iStepInter_ = 0; //(0:不识别; 1:开始识别; 2:结束识别) -}; - -ENGINE_REGIST(ControlEngine) - -#endif diff --git a/nvidia_ascend_engine/common_engine/ControlEngine/SubControlEngine.cpp b/nvidia_ascend_engine/common_engine/ControlEngine/SubControlEngine.cpp deleted file mode 100644 index 72658f7..0000000 --- a/nvidia_ascend_engine/common_engine/ControlEngine/SubControlEngine.cpp +++ /dev/null @@ -1,192 +0,0 @@ -#include "SubControlEngine.h" - - -using namespace ai_matrix; - -SubControlEngine::SubControlEngine() {} - -SubControlEngine::~SubControlEngine() {} - -APP_ERROR SubControlEngine::Init() -{ - bUseEngine_ = true; - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 - if (!dataSourceConfig_.bUse) - { - bUseEngine_ = false; - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - bHwDecode_ = MyYaml::GetIns()->GetBoolValue("gc_hardware_decode");//硬解码 - - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - strPort2_ = engineName_ + "_" + std::to_string(engineId_) + "_2"; - bCollectDataFlag_ = MyYaml::GetIns()->GetBoolValue("gc_collect_data_flag"); - bPushActualFlag_ = MyYaml::GetIns()->GetBoolValue("gc_push_actual_flag"); - strCollectDataSavePath_ = MyYaml::GetIns()->GetPathValue("gc_collect_data_savepath"); - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - - LogInfo << "SubControlEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR SubControlEngine::DeInit() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - LogInfo << "SubControlEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* 参数初始化(列车结束时需调用) -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SubControlEngine::InitParam() -{ - iPushDataNO_ = 1; - moveData_.i64TimeStamp = 0; - moveData_.bHasTrain = false; - moveData_.bIsEnd = false; - moveData_.strTrainDate = ""; - moveData_.strTrainName = ""; - moveData_.iFrameId = 1; -} - -APP_ERROR SubControlEngine::Process() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - int iRet = APP_ERR_OK; - while (!isStop_) - { - //pop端口0,解码后数据 - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } - - //获取主摄像头检测的状态 - std::shared_ptr pVoidData1 = nullptr; - iRet = inputQueMap_[strPort1_]->pop(pVoidData1); - if (nullptr != pVoidData1) - { - std::shared_ptr pMoveData = std::static_pointer_cast(pVoidData1); - moveData_ = *pMoveData; - LogDebug << "engineId:" << engineId_ << " trainname:" << moveData_.strTrainName - << " MoveData frameid:" << moveData_.iFrameId << " direction:" << moveData_.iDirection - << " IsEnd:" << moveData_.bIsEnd; - } - - std::shared_ptr pProcessDataTemp = std::static_pointer_cast(pVoidData0); - queueProcessData_.push(pProcessDataTemp); - - //1. 无车丢弃多余的数据,(只保留2s,50个数据) - if (!moveData_.bHasTrain) - { - while (queueProcessData_.size() > 50) - { - queueProcessData_.pop(); - } - continue; - } - - //2. 有车获取解码数据处理 - if (queueProcessData_.empty()) - { - continue; - } - std::shared_ptr pProcessData = queueProcessData_.front(); - queueProcessData_.pop(); - - bool bContinueFlag = false; - while (!moveData_.bIsEnd && pProcessData->i64TimeStamp < moveData_.i64TimeStamp) //获取和来车时间最接近的数据 - { - if (queueProcessData_.empty()) - { - bContinueFlag = true; - LogWarn << "engineId:" << engineId_ << " no fit data oldFrameTimeStamp:" << pProcessData->i64TimeStamp << " rePush."; - queueProcessData_.push(pProcessData); - break; - } - - if (queueProcessData_.front()->i64TimeStamp > moveData_.i64TimeStamp) - { - if (moveData_.i64TimeStamp - pProcessData->i64TimeStamp > queueProcessData_.front()->i64TimeStamp - moveData_.i64TimeStamp) - { - LogDebug << "oldFrameTimeStamp: " << pProcessData->i64TimeStamp << " newFrameTimeStamp:" << queueProcessData_.front()->i64TimeStamp; - pProcessData = queueProcessData_.front(); - queueProcessData_.pop(); - } - break; - } - pProcessData = queueProcessData_.front(); - queueProcessData_.pop(); - } - if (bContinueFlag) - { - continue; - } - - //3.构造过车存图数据,重置帧号 push 过车存图 - std::shared_ptr pSaveImgData = std::make_shared(); - pSaveImgData->iFrameId = iPushDataNO_ * dataSourceConfig_.iSkipInterval; //帧号 - pSaveImgData->pData = pProcessData->pData; - pSaveImgData->iSize = pProcessData->iSize; - pSaveImgData->iWidth = pProcessData->iWidth; - pSaveImgData->iHeight = pProcessData->iHeight; - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pProcessData->iDataSource + 1); - pSaveImgData->strImgPath = strResultPath_ + moveData_.strTrainDate + "/" + moveData_.strTrainName + "/" + szCameraNo; - pSaveImgData->strImgName = std::to_string(pSaveImgData->iFrameId) + ".jpg"; - pSaveImgData->bIsEnd = moveData_.bIsEnd; - pSaveImgData->bSaveToFtp = true; - pSaveImgData->i64TimeStamp = pProcessData->i64TimeStamp; - pSaveImgData->iDirection = moveData_.iDirection; - - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pSaveImgData)); - iPushDataNO_++; - if ((moveData_.bIsEnd) && (moveData_.iFrameId <= pSaveImgData->iFrameId)) - { - InitParam(); - } - - //4.图片采集 - if (bCollectDataFlag_) - { - //组织数据 push端口0 存图 - std::shared_ptr pSaveImgData = std::make_shared(); - pSaveImgData->iFrameId = pProcessData->iFrameId; //帧号 - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pProcessData->iDataSource + 1); - pSaveImgData->strImgPath = strCollectDataSavePath_ + szCameraNo; - pSaveImgData->strImgName = std::to_string(pSaveImgData->iFrameId); - pSaveImgData->strImgName += "_"; - pSaveImgData->strImgName += std::to_string(pProcessData->i64TimeStamp); - pSaveImgData->strImgName += ".jpg"; - iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast(pSaveImgData)); - } - - //5.直播推流 - if(bPushActualFlag_) - { - //发送推流Egnine - //iRet = outputQueMap_[strPort2_]->push(std::static_pointer_cast(pProcessData)); - } - } - return APP_ERR_OK; -} diff --git a/nvidia_ascend_engine/common_engine/ControlEngine/SubControlEngine.h b/nvidia_ascend_engine/common_engine/ControlEngine/SubControlEngine.h deleted file mode 100644 index a54a340..0000000 --- a/nvidia_ascend_engine/common_engine/ControlEngine/SubControlEngine.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 子控制识别Engine(辅助摄像头的控制识别) - * */ - -#ifndef SUBCONTROLENGINE_H -#define SUBCONTROLENGINE_H - -#include "AppCommon.h" -#include "MyYaml.h" -#include "myutils.h" -#include "EngineBase.h" -#include "EngineFactory.h" - -class SubControlEngine : public ai_matrix::EngineBase -{ -public: - SubControlEngine(); - ~SubControlEngine(); - - APP_ERROR Init() override; - APP_ERROR DeInit() override; - APP_ERROR Process() override; - -private: - //参数初始化 - void InitParam(); - - bool bUseEngine_; - bool bHwDecode_; - ai_matrix::DataSourceConfig dataSourceConfig_; - std::string save_path_; - std::string strPort0_; - std::string strPort1_; - std::string strPort2_; - bool bCollectDataFlag_; - bool bPushActualFlag_; //是否实时推流-用于直播 - std::string strCollectDataSavePath_; - std::string strResultPath_; - - uint32_t iPushDataNO_ = 1; //发送数据编号 - - MoveData moveData_; - std::queue> queueProcessData_; -}; - -ENGINE_REGIST(SubControlEngine) - -#endif diff --git a/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.cpp b/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.cpp index b06c319..8e38767 100644 --- a/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.cpp +++ b/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.cpp @@ -1,374 +1 @@ -#include "DataDealEngine.h" - -using namespace ai_matrix; - -extern std::atomic_uint64_t g_i64ReRunTimeStamp; -extern std::atomic_uint32_t g_iReRunOrigFrameId; -extern std::atomic_uint32_t g_iReRunFrameId; - -DataDealEngine::DataDealEngine() {} - -DataDealEngine::~DataDealEngine() {} - -APP_ERROR DataDealEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - strPort2_ = engineName_ + "_" + std::to_string(engineId_) + "_2"; - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - iPushDirection_ = MyYaml::GetIns()->GetIntValue("gc_push_direction"); - - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 - iIntervalTime_ = (dataSourceConfig_.iSkipInterval - 1) * 40 * 1000; - mapUseDataSouceCfg_ = MyYaml::GetIns()->GetUseDataSourceConfig(); - - std::string delimiter(","); - for (auto iter = mapUseDataSouceCfg_.begin(); iter!=mapUseDataSouceCfg_.end(); iter++) - { - int iSourceId = iter->first; - std::vector vecSplit = MyUtils::getins()->split(iter->second.strTarget, delimiter); - - std::vector vecPushPorts; - for (auto iter = vecSplit.begin(); iter != vecSplit.end(); iter++) - { - if (*iter == "NUM") - { - vecPushPorts.push_back(strPort0_); - } - else if (*iter == "CHKDATE") - { - vecPushPorts.push_back(strPort1_); - } - else if(*iter == "CONTAINER" || *iter == "CONTAINER_T") - { - vecPushPorts.push_back(strPort2_); - } - } - mapSourcePushPort_[iSourceId] = vecPushPorts; - } - - InitParam(); - LogInfo << "engineId_:" << engineId_ << " DataDealEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR DataDealEngine::DeInit() -{ - - LogInfo << "engineId_:" << engineId_ << " DataDealEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* 参数初始化(列车结束时需调用) -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void DataDealEngine::InitParam() -{ - iOrigDataNO_ = 1; - strDataDir_ = ""; - moveData_.i64TimeStamp = 0; - moveData_.bHasTrain = false; - moveData_.bIsEnd = false; - iDataNO_ = 1; - strTrainDate_ = ""; - strTrainName_ = ""; - iDirection_ = DIRECTION_UNKNOWN; - bNotPushFlag_ = false; -} - -/** -* 图片数据解码 -* inParam : RawData &rawData :图片数据 -* outParam: std::shared_ptr pDecodedData :解码数据 -* return : true(编码成功)/false(编码失败) -*/ -bool DataDealEngine::GetJpegdOut(std::shared_ptr pDecodedData, RawData &rawData) -{ - return true; -} - -/** -* 读取图片和文本 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -bool DataDealEngine::ReadFileInfo(Json::Value &jvFrameInfo, RawData &rawData, std::string &strFileName, std::string &strImgName) -{ - //图片或文件不存在时,休眠10ms直接return,重新获取。 - if (access(strFileName.c_str(), F_OK) != 0 || access(strImgName.c_str(), F_OK) != 0) - { - LogWarn << "txt:" << strFileName << " or image:" << strImgName << " no exist"; - return false; - } - - if (!MyUtils::getins()->ReadJsonInfo(jvFrameInfo, strFileName)) - { - LogError << "Failed to read txt:" << strFileName; - return false; - } - - //读取图片内容 - // int iRet = ReadFile(strImgName, rawData); - // if (iRet != APP_ERR_OK) - // { - // LogError << "Failed to read image:" << strImgName; - // return false; - // } - - return true; -} - -/** -* push数据到队列,队列满时则休眠一段时间再push。 -* inParam : const std::string strPort push的端口 - : const std::shared_ptr &pProcessData push的数据 -* outParam: N/A -* return : N/A -*/ -void DataDealEngine::PushData(const std::string &strPort, const std::shared_ptr &pProcessData) -{ - while (true) - { - int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pProcessData)); - if (iRet != 0) - { - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet; - if (iRet == 2) - { - usleep(10000); // 10ms - continue; - } - } - break; - } -} - -/** -* 构造处理数据并push -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void DataDealEngine::MakeProcessData() -{ - int iRet = APP_ERR_OK; - uint64_t i64TimeStampTemp = 0; - - bool bIsEndByStop = false; - uint64_t i64ReRunTimeStamp = 0; - uint32_t iReRunOrigFrameId = 0; - uint32_t iReRunFrameId = 0; - if (g_iReRunOrigFrameId != 0) - { - LogDebug << "g_i64ReRunTimeStamp:" << g_i64ReRunTimeStamp << " g_iReRunOrigFrameId:" << g_iReRunOrigFrameId - << " g_iReRunFrameId:" << g_iReRunFrameId; - i64ReRunTimeStamp = g_i64ReRunTimeStamp; - iReRunOrigFrameId = g_iReRunOrigFrameId; - iReRunFrameId = g_iReRunFrameId; - g_i64ReRunTimeStamp = 0; - g_iReRunOrigFrameId = 0; - g_iReRunFrameId = 0; - bIsEndByStop = true; - } - - for (auto iter = mapUseDataSouceCfg_.begin(); iter!=mapUseDataSouceCfg_.end(); iter++) - { - int iSourceId = iter->first; - char szCameraNo[5] = {0}; - sprintf(szCameraNo, "%03d/", iSourceId + 1); - uint32_t iOrigFrameId = iOrigDataNO_ * dataSourceConfig_.iSkipInterval; - uint32_t iFrameId = iDataNO_ * dataSourceConfig_.iSkipInterval; - bool bIsEndFlag = (moveData_.bIsEnd && moveData_.iFrameId == iOrigFrameId); - if (bIsEndByStop) - { - bIsEndFlag = true; - iOrigFrameId = iReRunOrigFrameId; - iFrameId = iReRunFrameId; - } - -// LogInfo << "sourceid:" << iSourceId << " MakeProcessData origtime:" << moveData_.strTrainName << " iOrigFrameId:" << iOrigFrameId -// << " time:" << strTrainName_ << " iFrameId:" << iFrameId << " bIsEndFlag:" << bIsEndFlag; - - std::string strImgName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId); - strImgName += (iter->second.iRotate != 0) ? "_rotate.jpg" : ".jpg"; - std::string strFileName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId) + ".txt"; - - //摄像头读取失败后重试2000次。 - Json::Value jvFrameInfo; - RawData rawData; - bool bRet = false; - int iNoDataCnt = 0; - while (!isStop_ && iNoDataCnt < 30) - { - bRet = ReadFileInfo(jvFrameInfo, rawData, strFileName, strImgName); - if (bRet) - { - break; - } - usleep(500 * 1000); // 500ms - iNoDataCnt++; - } - - //组织数据 - std::shared_ptr pProcessData = std::make_shared(); - pProcessData->iDataSource = iSourceId; - pProcessData->iFrameId = iFrameId; - pProcessData->strPicFilePath = strImgName; - pProcessData->i64TimeStamp = i64TimeStampTemp; - pProcessData->strOrigTrainDate = moveData_.strTrainDate; - pProcessData->strOrigTrainName = moveData_.strTrainName; - pProcessData->iOrigFrameId = iOrigFrameId; - pProcessData->strTrainDate = strTrainDate_; - pProcessData->strTrainName = strTrainName_; - pProcessData->iStatus = TRAINSTATUS_RUN; - pProcessData->bIsEnd = bIsEndFlag; - pProcessData->iDataNO = iDataNO_; - - if (bRet) - { - i64TimeStampTemp = jvFrameInfo["timeStamp"].asUInt64(); - pProcessData->i64TimeStamp = i64TimeStampTemp; - pProcessData->iWidth = jvFrameInfo["width"].asInt(); - pProcessData->iHeight = jvFrameInfo["height"].asInt(); - pProcessData->iDirection = jvFrameInfo["direction"].asInt(); - pProcessData->iRate = jvFrameInfo["rate"].asInt(); - pProcessData->nMonitorState = jvFrameInfo["moveType"].asInt(); - - cv::Mat cvframe = cv::imread(pProcessData->strPicFilePath); - int iBufferSize = pProcessData->iWidth * pProcessData->iHeight * 3; - void* pBGRBufferobj = nullptr; - pBGRBufferobj = new uint8_t[iBufferSize]; - memcpy(pBGRBufferobj, cvframe.data, iBufferSize); - pProcessData->pData.reset(pBGRBufferobj, [](void* data){if(data) {delete[] data; data = nullptr;}}); - pProcessData->iSize = iBufferSize; - } - - std::vector vecPushPorts = mapSourcePushPort_[iSourceId]; - for (int iPort = 0; iPort < vecPushPorts.size(); iPort++) - { - if (iPort == vecPushPorts.size() - 1) - { - iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pProcessData), true); -// PushData(vecPushPorts[iPort], pProcessData); - continue; - } - std::shared_ptr pNewProcessData = std::make_shared(); - *pNewProcessData = *pProcessData; - iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pNewProcessData), true); -// PushData(vecPushPorts[iPort], pNewProcessData); - } - - } - - iOrigDataNO_++; - iDataNO_++; - //每组处理数据需间隔一定时间 - usleep(iIntervalTime_); - - if (bIsEndByStop) - { - iDataNO_ = 1; - iOrigDataNO_ = iReRunOrigFrameId / dataSourceConfig_.iSkipInterval; - std::string strDateTime = MyUtils::getins()->GetDateTimeByMilliSeconds(i64ReRunTimeStamp); - strTrainDate_ = strDateTime.substr(0, 10); - strTrainName_ = strDateTime.substr(11, strDateTime.length()); - std::string strTrainPath = strResultPath_ + strTrainDate_ + "/" + strTrainName_ + "/"; - MyUtils::getins()->CreateDirPath(strTrainPath); - LogDebug << "rerun traindate:" << strTrainDate_ << " trainname:" << strTrainName_; - } -} - -APP_ERROR DataDealEngine::Process() -{ - int iRet = APP_ERR_OK; - //return APP_ERR_OK; - while (!isStop_) - { - //获取主摄像头检测的状态 - std::shared_ptr pVoidData0 = nullptr; - iRet = inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr != pVoidData0) - { - std::shared_ptr pMoveData = std::static_pointer_cast(pVoidData0); - moveData_ = *pMoveData; - LogDebug << "traindate:" << moveData_.strTrainDate << " trainname:" << moveData_.strTrainName - << " MoveData frameid:" << moveData_.iFrameId << " IsEnd:" << moveData_.bIsEnd; - } - - if (!moveData_.bHasTrain) - { - usleep(1000); //1ms - continue; - } - - //第一个数据,休眠1s,等待图片存入本地 - if (iOrigDataNO_ == 1) - { - usleep(1000000); //1s - } - - if (strDataDir_.empty()) - { - strDataDir_ = strResultPath_ + moveData_.strTrainDate + "/" + moveData_.strTrainName + "/"; - strTrainDate_ = moveData_.strTrainDate; - strTrainName_ = moveData_.strTrainName; - } - - //如果设置了方向,则方向不对直接过滤,但结束帧不能过滤,需流转到后面Engine,保证后面处理正确。 - if (iDirection_ == DIRECTION_UNKNOWN) - { - std::string strFilePath = strResultPath_ + strTrainDate_ + "/" + strTrainName_ + "/" + "direction.txt"; - Json::Value jvDirectionInfo; - if (MyUtils::getins()->ReadJsonInfo(jvDirectionInfo, strFilePath, 0)) - { - iDirection_ = jvDirectionInfo["direction"].asInt(); - } - } - - if (!moveData_.bIsEnd) - { - if (iDirection_ == DIRECTION_UNKNOWN || iDirection_ == iPushDirection_ || iPushDirection_ == DIRECTION_UNKNOWN) - { - MakeProcessData(); - } - else - { - LogDebug << "traindate:" << strTrainDate_ << " trainname:" << strTrainName_ << " iOrigDataNO_:" << iOrigDataNO_ << " continue."; - bNotPushFlag_ = true; - usleep(iIntervalTime_); //每组处理数据需间隔一定时间 - continue; - } - } - else - { - if (bNotPushFlag_) - { - iOrigDataNO_ = moveData_.iFrameId / dataSourceConfig_.iSkipInterval; - iDataNO_ = moveData_.iFrameId / dataSourceConfig_.iSkipInterval; - } - - if (iOrigDataNO_ * dataSourceConfig_.iSkipInterval > moveData_.iFrameId) - { - LogDebug << "dealFrameid:" << iOrigDataNO_ * dataSourceConfig_.iSkipInterval << " moveFrameid:" << moveData_.iFrameId; - iOrigDataNO_ = moveData_.iFrameId / dataSourceConfig_.iSkipInterval; - MakeProcessData(); - } - else - { - while (!isStop_ && iOrigDataNO_ * dataSourceConfig_.iSkipInterval <= moveData_.iFrameId) - { - //继续处理 - MakeProcessData(); - } - } - - InitParam(); - } - } - return APP_ERR_OK; -} - +#include "DataDealEngine.h" using namespace ai_matrix; extern std::atomic_uint64_t g_i64ReRunTimeStamp; extern std::atomic_uint32_t g_iReRunOrigFrameId; extern std::atomic_uint32_t g_iReRunFrameId; DataDealEngine::DataDealEngine() {} DataDealEngine::~DataDealEngine() {} APP_ERROR DataDealEngine::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; strPort2_ = engineName_ + "_" + std::to_string(engineId_) + "_2"; strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); iPushDirection_ = MyYaml::GetIns()->GetIntValue("gc_push_direction"); dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 iIntervalTime_ = (dataSourceConfig_.iSkipInterval - 1) * 40 * 1000; mapUseDataSouceCfg_ = MyYaml::GetIns()->GetUseDataSourceConfig(); std::string delimiter(","); for (auto iter = mapUseDataSouceCfg_.begin(); iter!=mapUseDataSouceCfg_.end(); iter++) { int iSourceId = iter->first; std::vector vecSplit = MyUtils::getins()->split(iter->second.strTarget, delimiter); std::vector vecPushPorts; for (auto iter = vecSplit.begin(); iter != vecSplit.end(); iter++) { if (*iter == "NUM") { vecPushPorts.push_back(strPort0_); } else if (*iter == "CHKDATE") { vecPushPorts.push_back(strPort1_); } else if(*iter == "CONTAINER" || *iter == "CONTAINER_T") { vecPushPorts.push_back(strPort2_); } } mapSourcePushPort_[iSourceId] = vecPushPorts; } InitParam(); LogInfo << "engineId_:" << engineId_ << " DataDealEngine Init ok"; return APP_ERR_OK; } APP_ERROR DataDealEngine::DeInit() { LogInfo << "engineId_:" << engineId_ << " DataDealEngine DeInit ok"; return APP_ERR_OK; } /** * 参数初始化(列车结束时需调用) * inParam : N/A * outParam: N/A * return : N/A */ void DataDealEngine::InitParam() { iOrigDataNO_ = 1; strDataDir_ = ""; moveData_.i64TimeStamp = 0; moveData_.bHasTrain = false; moveData_.bIsEnd = false; iDataNO_ = 1; strTrainDate_ = ""; strTrainName_ = ""; iDirection_ = DIRECTION_UNKNOWN; bNotPushFlag_ = false; } /** * 图片数据解码 * inParam : RawData &rawData :图片数据 * outParam: std::shared_ptr pDecodedData :解码数据 * return : true(编码成功)/false(编码失败) */ bool DataDealEngine::GetJpegdOut(std::shared_ptr pDecodedData, RawData &rawData) { return true; } /** * 读取图片和文本 * inParam : N/A * outParam: N/A * return : N/A */ bool DataDealEngine::ReadFileInfo(Json::Value &jvFrameInfo, RawData &rawData, std::string &strFileName, std::string &strImgName) { //图片或文件不存在时,休眠10ms直接return,重新获取。 if (access(strFileName.c_str(), F_OK) != 0 || access(strImgName.c_str(), F_OK) != 0) { LogWarn << "txt:" << strFileName << " or image:" << strImgName << " no exist"; return false; } if (!MyUtils::getins()->ReadJsonInfo(jvFrameInfo, strFileName)) { LogError << "Failed to read txt:" << strFileName; return false; } //读取图片内容 // int iRet = ReadFile(strImgName, rawData); // if (iRet != APP_ERR_OK) // { // LogError << "Failed to read image:" << strImgName; // return false; // } return true; } /** * push数据到队列,队列满时则休眠一段时间再push。 * inParam : const std::string strPort push的端口 : const std::shared_ptr &pProcessData push的数据 * outParam: N/A * return : N/A */ void DataDealEngine::PushData(const std::string &strPort, const std::shared_ptr &pProcessData) { while (true) { int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pProcessData)); if (iRet != 0) { LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet; if (iRet == 2) { usleep(10000); // 10ms continue; } } break; } } /** * 构造处理数据并push * inParam : N/A * outParam: N/A * return : N/A */ void DataDealEngine::MakeProcessData() { int iRet = APP_ERR_OK; uint64_t i64TimeStampTemp = 0; bool bIsEndByStop = false; uint64_t i64ReRunTimeStamp = 0; uint32_t iReRunOrigFrameId = 0; uint32_t iReRunFrameId = 0; if (g_iReRunOrigFrameId != 0) { LogDebug << "g_i64ReRunTimeStamp:" << g_i64ReRunTimeStamp << " g_iReRunOrigFrameId:" << g_iReRunOrigFrameId << " g_iReRunFrameId:" << g_iReRunFrameId; i64ReRunTimeStamp = g_i64ReRunTimeStamp; iReRunOrigFrameId = g_iReRunOrigFrameId; iReRunFrameId = g_iReRunFrameId; g_i64ReRunTimeStamp = 0; g_iReRunOrigFrameId = 0; g_iReRunFrameId = 0; bIsEndByStop = true; } for (auto iter = mapUseDataSouceCfg_.begin(); iter!=mapUseDataSouceCfg_.end(); iter++) { int iSourceId = iter->first; char szCameraNo[5] = {0}; sprintf(szCameraNo, "%03d/", iSourceId + 1); uint32_t iOrigFrameId = iOrigDataNO_ * dataSourceConfig_.iSkipInterval; uint32_t iFrameId = iDataNO_ * dataSourceConfig_.iSkipInterval; bool bIsEndFlag = (moveData_.bIsEnd && moveData_.iFrameId == iOrigFrameId); if (bIsEndByStop) { bIsEndFlag = true; iOrigFrameId = iReRunOrigFrameId; iFrameId = iReRunFrameId; } LogInfo << "sourceid:" << iSourceId << " MakeProcessData origtime:" << moveData_.strTrainName << " iOrigFrameId:" << iOrigFrameId << " time:" << strTrainName_ << " iFrameId:" << iFrameId << " bIsEndFlag:" << bIsEndFlag; std::string strImgName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId); strImgName += (iter->second.iRotate != 0) ? "_rotate.jpg" : ".jpg"; std::string strFileName = strDataDir_ + szCameraNo + std::to_string(iOrigFrameId) + ".txt"; //摄像头读取失败后重试30次。 Json::Value jvFrameInfo; RawData rawData; bool bRet = false; int iNoDataCnt = 0; while (!isStop_ && iNoDataCnt < 30) { bRet = ReadFileInfo(jvFrameInfo, rawData, strFileName, strImgName); if (bRet) { break; } usleep(500 * 1000); // 500ms iNoDataCnt++; } //组织数据 std::shared_ptr pProcessData = std::make_shared(); pProcessData->iDataSource = iSourceId; pProcessData->iFrameId = iFrameId; pProcessData->strPicFilePath = strImgName; pProcessData->i64TimeStamp = i64TimeStampTemp; pProcessData->strOrigTrainDate = moveData_.strTrainDate; pProcessData->strOrigTrainName = moveData_.strTrainName; pProcessData->iOrigFrameId = iOrigFrameId; pProcessData->strTrainDate = strTrainDate_; pProcessData->strTrainName = strTrainName_; pProcessData->iStatus = TRAINSTATUS_RUN; pProcessData->bIsEnd = bIsEndFlag; pProcessData->iDataNO = iDataNO_; // pProcessData->nMonitorState = moveData_.nMonitorState; pProcessData->nMonitorState = jvFrameInfo["moveType"].asInt(); if (bRet) { i64TimeStampTemp = jvFrameInfo["timeStamp"].asUInt64(); pProcessData->i64TimeStamp = i64TimeStampTemp; pProcessData->iWidth = jvFrameInfo["width"].asInt(); pProcessData->iHeight = jvFrameInfo["height"].asInt(); pProcessData->iDirection = jvFrameInfo["direction"].asInt(); pProcessData->iRate = jvFrameInfo["rate"].asInt(); cv::Mat cvframe = cv::imread(pProcessData->strPicFilePath); int iBufferSize = pProcessData->iWidth * pProcessData->iHeight * 3; void* pBGRBufferobj = nullptr; pBGRBufferobj = new uint8_t[iBufferSize]; memcpy(pBGRBufferobj, cvframe.data, iBufferSize); pProcessData->pData.reset(pBGRBufferobj, [](void* data){if(data) {delete[] data; data = nullptr;}}); pProcessData->iSize = iBufferSize; } std::vector vecPushPorts = mapSourcePushPort_[iSourceId]; for (int iPort = 0; iPort < vecPushPorts.size(); iPort++) { if (iPort == vecPushPorts.size() - 1) { //iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pProcessData)); PushData(vecPushPorts[iPort], pProcessData); continue; } std::shared_ptr pNewProcessData = std::make_shared(); *pNewProcessData = *pProcessData; //iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pNewProcessData)); PushData(vecPushPorts[iPort], pNewProcessData); } } iOrigDataNO_++; iDataNO_++; //每组处理数据需间隔一定时间 usleep(iIntervalTime_); if (bIsEndByStop) { iDataNO_ = 1; iOrigDataNO_ = iReRunOrigFrameId / dataSourceConfig_.iSkipInterval; std::string strDateTime = MyUtils::getins()->GetDateTimeByMilliSeconds(i64ReRunTimeStamp); strTrainDate_ = strDateTime.substr(0, 10); strTrainName_ = strDateTime.substr(11, strDateTime.length()); std::string strTrainPath = strResultPath_ + strTrainDate_ + "/" + strTrainName_ + "/"; MyUtils::getins()->CreateDirPath(strTrainPath); LogDebug << "rerun traindate:" << strTrainDate_ << " trainname:" << strTrainName_; } } APP_ERROR DataDealEngine::Process() { int iRet = APP_ERR_OK; //return APP_ERR_OK; while (!isStop_) { //获取主摄像头检测的状态 std::shared_ptr pVoidData0 = nullptr; iRet = inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr != pVoidData0) { std::shared_ptr pMoveData = std::static_pointer_cast(pVoidData0); // queuwMoveData_.push(*pMoveData); moveData_ = *pMoveData; LogDebug << "traindate:" << moveData_.strTrainDate << " trainname:" << moveData_.strTrainName << " MoveData frameid:" << moveData_.iFrameId << " IsEnd:" << moveData_.bIsEnd; } // LogDebug << "【帧号】" << (iDataNO_ * dataSourceConfig_.iSkipInterval); // if (queuwMoveData_.size() > 0 && (iDataNO_ * dataSourceConfig_.iSkipInterval) >= queuwMoveData_.front().iFrameId) // { // moveData_ = queuwMoveData_.front(); // queuwMoveData_.pop(); // LogDebug << "!!!--- moveDate 更新"; // } if (!moveData_.bHasTrain) { usleep(1000); //1ms continue; } //第一个数据,休眠1s,等待图片存入本地 if (iOrigDataNO_ == 1) { usleep(1000 * 1000); //1s } if (strDataDir_.empty()) { strDataDir_ = strResultPath_ + moveData_.strTrainDate + "/" + moveData_.strTrainName + "/"; strTrainDate_ = moveData_.strTrainDate; strTrainName_ = moveData_.strTrainName; } //如果设置了方向,则方向不对直接过滤,但结束帧不能过滤,需流转到后面Engine,保证后面处理正确。 if (iDirection_ == DIRECTION_UNKNOWN) { std::string strFilePath = strResultPath_ + strTrainDate_ + "/" + strTrainName_ + "/" + "direction.txt"; Json::Value jvDirectionInfo; if (MyUtils::getins()->ReadJsonInfo(jvDirectionInfo, strFilePath, 0)) { iDirection_ = jvDirectionInfo["direction"].asInt(); } } if (!moveData_.bIsEnd) { if (iDirection_ == DIRECTION_UNKNOWN || iDirection_ == iPushDirection_ || iPushDirection_ == DIRECTION_UNKNOWN) { MakeProcessData(); } else { LogDebug << "traindate:" << strTrainDate_ << " trainname:" << strTrainName_ << " iOrigDataNO_:" << iOrigDataNO_ << " continue."; bNotPushFlag_ = true; usleep(iIntervalTime_); //每组处理数据需间隔一定时间 continue; } } else { if (bNotPushFlag_) { iOrigDataNO_ = moveData_.iFrameId / dataSourceConfig_.iSkipInterval; iDataNO_ = moveData_.iFrameId / dataSourceConfig_.iSkipInterval; } if (iOrigDataNO_ * dataSourceConfig_.iSkipInterval > moveData_.iFrameId) { LogDebug << "dealFrameid:" << iOrigDataNO_ * dataSourceConfig_.iSkipInterval << " moveFrameid:" << moveData_.iFrameId; iOrigDataNO_ = moveData_.iFrameId / dataSourceConfig_.iSkipInterval; MakeProcessData(); } else { while (!isStop_ && iOrigDataNO_ * dataSourceConfig_.iSkipInterval <= moveData_.iFrameId) { //继续处理 MakeProcessData(); } } InitParam(); } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.h b/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.h index f192bea..e46f98d 100644 --- a/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.h +++ b/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealEngine.h @@ -50,6 +50,7 @@ private: std::map> mapSourcePushPort_; MoveData moveData_; + std::queue queuwMoveData_; std::string strDataDir_; uint32_t iOrigDataNO_; //原过车数据个数 diff --git a/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealTwoEngine.cpp b/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealTwoEngine.cpp index eb58eb8..0623e2b 100644 --- a/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealTwoEngine.cpp +++ b/nvidia_ascend_engine/common_engine/DataDealEngine/DataDealTwoEngine.cpp @@ -407,6 +407,31 @@ int DataDealTwoEngine::GetPostData(std::shared_ptr pProcessData, Js return pPostData->vecPostSubData.size(); } +/** +* push数据到队列,队列满时则休眠一段时间再push。 +* inParam : const std::string strPort push的端口 + : const std::shared_ptr &pProcessData push的数据 +* outParam: N/A +* return : N/A +*/ +void DataDealTwoEngine::PushData(const std::string &strPort, const std::shared_ptr &pProcessData) +{ + while (true) + { + int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pProcessData)); + if (iRet != 0) + { + LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet; + if (iRet == 2) + { + usleep(10000); // 10ms + continue; + } + } + break; + } +} + /** * 构造处理数据并push * inParam : N/A @@ -490,14 +515,14 @@ void DataDealTwoEngine::MakeProcessData(std::shared_ptr pTrainRange) { if (iPort == vecPushPorts.size() - 1) { - iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pProcessData), true); -// PushData(vecPushPorts[iPort], pProcessData); + //iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pProcessData), true); + PushData(vecPushPorts[iPort], pProcessData); continue; } std::shared_ptr pNewProcessData = std::make_shared(); *pNewProcessData = *pProcessData; - iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pNewProcessData), true); -// PushData(vecPushPorts[iPort], pNewProcessData); + //iRet = outputQueMap_[vecPushPorts[iPort]]->push(std::static_pointer_cast(pNewProcessData), true); + PushData(vecPushPorts[iPort], pNewProcessData); } } @@ -593,7 +618,7 @@ APP_ERROR DataDealTwoEngine::Process() //处理当车厢的每帧信息 MakeProcessData(pTrainRange); // push结果汇总 - iRet = outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_9"]->push(std::static_pointer_cast(pTrainRange), true); + iRet = outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_9"]->push(std::static_pointer_cast(pTrainRange)); iTrainIndex_++; if (pTrainRange->bIsEnd) diff --git a/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.cpp b/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.cpp index c2e7f69..dc11273 100644 --- a/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.cpp +++ b/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.cpp @@ -1,386 +1 @@ -#include "CameraEngine.h" -#include "myutils.h" - -using namespace ai_matrix; - -namespace { - const int LOW_THRESHOLD = 128; - const int MAX_THRESHOLD = 4096; - const uint16_t DELAY_TIME = 20000; -} - -CameraEngine::CameraEngine() {} - -CameraEngine::~CameraEngine() {} - -APP_ERROR CameraEngine::Init() { - bUseEngine_ = true; - bHwDecode_ = MyYaml::GetIns()->GetBoolValue("gc_hardware_decode"); - - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 - if (MyYaml::GetIns()->GetStringValue("gc_data_source") != "camera" || !dataSourceConfig_.bUse) { - bUseEngine_ = false; - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - nDelayTime = MyYaml::GetIns()->GetIntValue("gc_load_delay"); - - LogInfo << "engineId_:" << engineId_ << " CameraEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR CameraEngine::DeInit() { - if (!bUseEngine_) { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - ResetCamera(); - LogInfo << "engineId_:" << engineId_ << " CameraEngine DeInit ok"; - return APP_ERR_OK; -} - -void CameraEngine::ResetCamera() { - if (pFormatCtx_ != nullptr) { - // clear th cache of the queue - avformat_close_input(&pFormatCtx_); - pFormatCtx_ = nullptr; - } -} - -APP_ERROR CameraEngine::ConnectCamera() { - pFormatCtx_ = CreateFormatContext(); // create context - if (pFormatCtx_ == nullptr) { - LogError << "engineId_:" << engineId_ << " pFormatCtx_ null!"; - return APP_ERR_COMM_FAILURE; - } - - //0-代表输入 - av_dump_format(pFormatCtx_, 0, dataSourceConfig_.strUrl.c_str(), 0); - - // get stream infomation - int iRet = APP_ERR_OK; - iRet = GetStreamInfo(); - if (iRet != APP_ERR_OK) { - LogError << "engineId_:" << engineId_ << " Stream Info Check failed, iRet = " << iRet; - return APP_ERR_COMM_FAILURE; - } - - return APP_ERR_OK; -} - -APP_ERROR CameraEngine::GetStreamInfo() { - if (pFormatCtx_ != nullptr) { - iVideoStream_ = -1; - iAudioStream_ = -1; - //frameInfo_.iFrameId = 0; //帧号从0开始 - - for (unsigned int i = 0; i < pFormatCtx_->nb_streams; i++) { - AVStream *inStream = pFormatCtx_->streams[i]; - if (inStream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { - iVideoStream_ = i; - frameInfo_.iHeight = inStream->codecpar->height; - frameInfo_.iWidth = inStream->codecpar->width; - - //获取帧率,帧率的打印都在流中的两个成员.且应取平均帧率为先,为{x,0}或者{0,1}则取实时帧率 - if (inStream->avg_frame_rate.den == 0 || - (inStream->avg_frame_rate.num == 0 && inStream->avg_frame_rate.den == 1)) { - frameInfo_.iRate = inStream->r_frame_rate.num / inStream->r_frame_rate.den; - } else { - frameInfo_.iRate = inStream->avg_frame_rate.num / inStream->avg_frame_rate.den; - } - LogDebug << "engineId_:" << engineId_ << " width:" << frameInfo_.iWidth << " height:" - << frameInfo_.iHeight - << " rate:" << frameInfo_.iRate << " iVideoStream_:" << iVideoStream_; - } else if (inStream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { - iAudioStream_ = i; - LogDebug << "engineId_:" << engineId_ << " iAudioStream_:" << iAudioStream_; - } - } - - if (iVideoStream_ == -1) { - LogError << "engineId_:" << engineId_ << " Didn't find a video stream!"; - return APP_ERR_COMM_FAILURE; - } - - if (frameInfo_.iHeight < LOW_THRESHOLD || frameInfo_.iWidth < LOW_THRESHOLD || - frameInfo_.iHeight > MAX_THRESHOLD || frameInfo_.iWidth > MAX_THRESHOLD) { - LogError << "engineId_:" << engineId_ << " Size of frame is not supported in DVPP Video Decode!"; - return APP_ERR_COMM_FAILURE; - } - - AVCodecID codecId = pFormatCtx_->streams[iVideoStream_]->codecpar->codec_id; - if (codecId == AV_CODEC_ID_H264) { - int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile; - if (profile == FF_PROFILE_H264_BASELINE) { - frameInfo_.format = H264_BASELINE_LEVEL; - } else if (profile == FF_PROFILE_H264_MAIN) { - frameInfo_.format = H264_MAIN_LEVEL; - } else if (profile == FF_PROFILE_H264_HIGH) { - frameInfo_.format = H264_HIGH_LEVEL; - } else { - LogError << "engineId_:" << engineId_ << " not support h264 profile"; - return APP_ERR_COMM_FAILURE; - } - } else if (codecId == AV_CODEC_ID_H265) { - int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile; - if (profile == FF_PROFILE_HEVC_MAIN) { - frameInfo_.format = H265_MAIN_LEVEL; - } else { - LogError << "engineId_:" << engineId_ << " not support h265 profile"; - return APP_ERR_COMM_FAILURE; - } - } else { - LogError << "engineId_:" << engineId_ << " Error unsupported format" << codecId; - return APP_ERR_COMM_FAILURE; - } - } - return APP_ERR_OK; -} - -AVFormatContext *CameraEngine::CreateFormatContext() { - // create message for stream pull - AVFormatContext *pFormatContext = nullptr; - AVDictionary *pOptions = nullptr; - - // formatContext = avformat_alloc_context(); - if (dataSourceConfig_.strUrl.find("rtsp:") != std::string::npos) // rtsp - { - av_dict_set(&pOptions, "rtsp_transport", "tcp", 0); // 指定其传输方式为TCP - av_dict_set(&pOptions, "stimeout", "3000000", 0); // 设置超时3秒 - - } - - av_register_all(); //注册所有支持的格式(这里一定注册这些,否则会因为协议解析问题报错!!!) - avcodec_register_all(); //注册编解码器 - avformat_network_init(); //注册网格格式,如果为本地文件则可以去掉该代码 - - int iRet = avformat_open_input(&pFormatContext, dataSourceConfig_.strUrl.c_str(), nullptr, &pOptions); - if (nullptr != pOptions) { - av_dict_free(&pOptions); - } - if (iRet != 0) { - LogError << "engineId_:" << engineId_ << " Couldn't open input stream " << dataSourceConfig_.strUrl.c_str() - << ", iRet=" << iRet; - return nullptr; - } - - // pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; - // pFormatContext->pb->flags |= AVIO_FLAG_NONBLOCK; - // av_dict_set(&pFormatContext->interrupt_callback.callback, "timeout", "3000", 0); - // iRet = avio_open2(&pFormatContext->pb, dataSourceConfig_.strUrl.c_str(), AVIO_FLAG_READ, NULL, NULL) < 0; - // { - // // 处理错误 - // LogError << "engineId_:" << engineId_ << "avio_open2 iRet=" << iRet; - // return nullptr; - // } - - iRet = avformat_find_stream_info(pFormatContext, nullptr); - if (iRet != 0) { - LogError << "engineId_:" << engineId_ << " Couldn't find stream information, iRet = " << iRet; - return nullptr; - } - return pFormatContext; -} - -//av_read_frame的中断回调函数 -int CameraEngine::InterruptCallback(void *pData) { - TimeoutContext *pTimeOutCtx = (TimeoutContext *) pData; - LogDebug << "InterruptCallback i64Timeout:" << pTimeOutCtx->i64Timeout; - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count() >= pTimeOutCtx->i64Timeout - ? AVERROR_EXIT - : 0; -} - -APP_ERROR CameraEngine::Process() { - int iRet = APP_ERR_OK; - if (!bUseEngine_) { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - if (bHwDecode_) { - iRet = ConnectCamera(); - if (iRet == APP_ERR_OK) { - LogInfo << "engineId_:" << engineId_ << " Start the stream......"; - bReconnectFlag_ = false; - } else { - ResetCamera(); - bReconnectFlag_ = true; - } - - // Pull data cyclically - AVPacket pkt; - while (!isStop_) { - //重连相机 - if (bReconnectFlag_) { - iRet = ConnectCamera(); - if (iRet == APP_ERR_OK) { - LogInfo << "engineId_:" << engineId_ << " Start the stream......"; - bReconnectFlag_ = false; - } else { -// outputQueMap_[strPort1_]->push(std::static_pointer_cast(std::make_shared("摄像头连接失败!"))); - ResetCamera(); - std::this_thread::sleep_for(std::chrono::seconds(3)); //3秒后重连 - continue; - } - } - - //设置av_read_frame中断函数 (中断函数中超过1s,则中断处理) - TimeoutContext timeoutCtx = {std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count() + 1000}; - pFormatCtx_->interrupt_callback.callback = InterruptCallback; - pFormatCtx_->interrupt_callback.opaque = &timeoutCtx; - - av_init_packet(&pkt); //init pkt - - iRet = av_read_frame(pFormatCtx_, &pkt); //需要一直读取,否则获取到的是历史数据 - - //校验是否存取到结尾 - if (iRet == AVERROR_EOF) { - LogInfo << "CameraEngine--av_read_frame--end!"; - // break; - } - - if (iRet != 0) { - outputQueMap_[strPort1_]->push( - std::static_pointer_cast(std::make_shared("图像读取失败!"))); - LogError << "engineId_:" << engineId_ << " Read frame failed, reconnect iRet:" << iRet; - av_packet_unref(&pkt); - - //重连相机 - ResetCamera(); - - bReconnectFlag_ = true; - continue; - } else if (pkt.stream_index == iVideoStream_) //只解码视频流 - { -// LogDebug << "iRet:" << iRet << " pkt.size:" << pkt.size; - if (pkt.size <= 0) { - LogError << "engineId_:" << engineId_ << " Invalid pkt.size: " << pkt.size; - av_packet_unref(&pkt); - continue; - } - if (dataSourceConfig_.strUrl.find(".mp4") != std::string::npos) { - const char szStartCode[4] = {0, 0, 0, 1}; - if (bIsAvc_ || memcmp(szStartCode, pkt.data, 4) != 0) { // is avc1 code, have no start code of H264 - int iLen = 0; - uint8_t *p = pkt.data; - bIsAvc_ = true; - do { // add start_code for each NAL, one frame may have multi NALs. - iLen = ntohl(*((long *) p)); - memcpy(p, szStartCode, 4); - p += 4; - p += iLen; - if (p >= pkt.data + pkt.size) { - break; - } - } while (1); - } - } - - void *pH264Buffer = nullptr; - pH264Buffer = new uint8_t[pkt.size]; - memcpy(pH264Buffer, pkt.data, pkt.size); - //组织数据 - std::shared_ptr pProcessData = std::make_shared(); - pProcessData->iWidth = frameInfo_.iWidth; - pProcessData->iHeight = frameInfo_.iHeight; - pProcessData->iRate = frameInfo_.iRate; - pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis(); - pProcessData->iDataSource = engineId_; - pProcessData->iSize = pkt.size; - pProcessData->pData.reset(pH264Buffer, [](void *data) { - if (data) { - delete[] data; - data = nullptr; - } - }); //智能指针管理内存 - - //push端口0,视频解码 - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData), true); - if (iRet != APP_ERR_OK) { - LogError << "engineId_:" << engineId_ << "push the h264 frame data failed..."; - } - } else if (pkt.stream_index == iAudioStream_) { - //音频流不处理。 - } else { - LogError << "engineId_:" << engineId_ << " stream err stream_index:" << pkt.stream_index; - } - av_packet_unref(&pkt); //unref - - if (dataSourceConfig_.strUrl.find("rtsp:") == std::string::npos) // 如果不是rtsp,定时发送 - { - usleep(DELAY_TIME); // delay 40ms - } - } - } else { - //从摄像头RTSP拉流 - const std::string videoStreamAddress = std::string("rtspsrc location=") + dataSourceConfig_.strUrl.c_str() + " latency=10 ! \ - rtph264depay ! h264parse ! nvv4l2decoder enable-max-performance=1 enable-frame-type-reporting=1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink"; - - VideoCapture capture_video; - while (!capture_video.open(videoStreamAddress)) { //, cv::CAP_FFMPEG - LogInfo << "Restart Opening video stream or file ..." << std::endl; - sleep(1); - } - LogInfo << "Opening video stream or file Success:" << engineId_; - - int frameW = capture_video.get(3); - int frameH = capture_video.get(4); - int frameRate = capture_video.get(5); - usleep(nDelayTime * 1000 * 1000); - int nFrameid = 0; - bool breadend = false; - cv::Mat frame(frameH, frameW, CV_8UC3); - - while (!isStop_) { - std::shared_ptr pBGRFrameData = std::make_shared(); - std::shared_ptr pProcessData = std::make_shared(); - if (!capture_video.read(frame)) { - capture_video.release(); - while (!capture_video.open(videoStreamAddress)) { //, cv::CAP_FFMPEG - LogInfo << "Restart Opening video stream or file ..." << std::endl; - sleep(1); - } - continue; - } - unsigned int resizepBGRBuffer_Size = IMAGE_WIDTH * IMAGE_HEIGHT * 3; - - cv::Mat mtInImage, mtOutImage; - cv::resize(frame, mtInImage, cv::Size(IMAGE_WIDTH, IMAGE_HEIGHT)); - cv::cvtColor(mtInImage, mtOutImage, cv::COLOR_BGR2RGB); - - void *resizeBGRBufferobj = nullptr; - resizeBGRBufferobj = new uint8_t[resizepBGRBuffer_Size]; - memcpy(resizeBGRBufferobj, mtOutImage.data, resizepBGRBuffer_Size); - - pBGRFrameData->iDataSource = engineId_; - pBGRFrameData->iFrameId = nFrameid++; - pBGRFrameData->iSize = resizepBGRBuffer_Size; - pBGRFrameData->frameInfo.iWidth = IMAGE_WIDTH; - pBGRFrameData->frameInfo.iHeight = IMAGE_HEIGHT; - pBGRFrameData->frameInfo.iRate = frameRate; - pProcessData->pVoidData = std::static_pointer_cast(pBGRFrameData); - pProcessData->pData.reset(resizeBGRBufferobj, [](void *data) { - if (data) { - delete[] data; - data = nullptr; - } - }); - if (nFrameid >= 0xFFFFFFFF) { nFrameid = 0; } - pBGRFrameData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis(); - pProcessData->iWidth = pBGRFrameData->frameInfo.iWidth; - pProcessData->iHeight = pBGRFrameData->frameInfo.iHeight; - pProcessData->iHeight = pBGRFrameData->frameInfo.iRate; - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData), true); - } - } - - return APP_ERR_OK; -} - +#include "CameraEngine.h" #include "myutils.h" using namespace ai_matrix; namespace { const int LOW_THRESHOLD = 128; const int MAX_THRESHOLD = 4096; const uint16_t DELAY_TIME = 20000; } CameraEngine::CameraEngine() {} CameraEngine::~CameraEngine() {} APP_ERROR CameraEngine::Init() { bUseEngine_ = true; bHwDecode_ = MyYaml::GetIns()->GetBoolValue("gc_hardware_decode"); dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 if (MyYaml::GetIns()->GetStringValue("gc_data_source") != "camera" || !dataSourceConfig_.bUse) { bUseEngine_ = false; LogWarn << "engineId_:" << engineId_ << " not use engine"; return APP_ERR_OK; } strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; nDelayTime = MyYaml::GetIns()->GetIntValue("gc_load_delay"); LogInfo << "engineId_:" << engineId_ << " CameraEngine Init ok"; return APP_ERR_OK; } APP_ERROR CameraEngine::DeInit() { if (!bUseEngine_) { LogWarn << "engineId_:" << engineId_ << " not use engine"; return APP_ERR_OK; } ResetCamera(); LogInfo << "engineId_:" << engineId_ << " CameraEngine DeInit ok"; return APP_ERR_OK; } void CameraEngine::ResetCamera() { if (pFormatCtx_ != nullptr) { // clear th cache of the queue avformat_close_input(&pFormatCtx_); pFormatCtx_ = nullptr; } } APP_ERROR CameraEngine::ConnectCamera() { pFormatCtx_ = CreateFormatContext(); // create context if (pFormatCtx_ == nullptr) { LogError << "engineId_:" << engineId_ << " pFormatCtx_ null!"; return APP_ERR_COMM_FAILURE; } //0-代表输入 av_dump_format(pFormatCtx_, 0, dataSourceConfig_.strUrl.c_str(), 0); // get stream infomation int iRet = APP_ERR_OK; iRet = GetStreamInfo(); if (iRet != APP_ERR_OK) { LogError << "engineId_:" << engineId_ << " Stream Info Check failed, iRet = " << iRet; return APP_ERR_COMM_FAILURE; } return APP_ERR_OK; } APP_ERROR CameraEngine::GetStreamInfo() { if (pFormatCtx_ != nullptr) { iVideoStream_ = -1; iAudioStream_ = -1; //frameInfo_.iFrameId = 0; //帧号从0开始 for (unsigned int i = 0; i < pFormatCtx_->nb_streams; i++) { AVStream *inStream = pFormatCtx_->streams[i]; if (inStream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { iVideoStream_ = i; frameInfo_.iHeight = inStream->codecpar->height; frameInfo_.iWidth = inStream->codecpar->width; //获取帧率,帧率的打印都在流中的两个成员.且应取平均帧率为先,为{x,0}或者{0,1}则取实时帧率 if (inStream->avg_frame_rate.den == 0 || (inStream->avg_frame_rate.num == 0 && inStream->avg_frame_rate.den == 1)) { frameInfo_.iRate = inStream->r_frame_rate.num / inStream->r_frame_rate.den; } else { frameInfo_.iRate = inStream->avg_frame_rate.num / inStream->avg_frame_rate.den; } LogDebug << "engineId_:" << engineId_ << " width:" << frameInfo_.iWidth << " height:" << frameInfo_.iHeight << " rate:" << frameInfo_.iRate << " iVideoStream_:" << iVideoStream_; } else if (inStream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { iAudioStream_ = i; LogDebug << "engineId_:" << engineId_ << " iAudioStream_:" << iAudioStream_; } } if (iVideoStream_ == -1) { LogError << "engineId_:" << engineId_ << " Didn't find a video stream!"; return APP_ERR_COMM_FAILURE; } if (frameInfo_.iHeight < LOW_THRESHOLD || frameInfo_.iWidth < LOW_THRESHOLD || frameInfo_.iHeight > MAX_THRESHOLD || frameInfo_.iWidth > MAX_THRESHOLD) { LogError << "engineId_:" << engineId_ << " Size of frame is not supported in DVPP Video Decode!"; return APP_ERR_COMM_FAILURE; } AVCodecID codecId = pFormatCtx_->streams[iVideoStream_]->codecpar->codec_id; if (codecId == AV_CODEC_ID_H264) { int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile; if (profile == FF_PROFILE_H264_BASELINE) { frameInfo_.format = H264_BASELINE_LEVEL; } else if (profile == FF_PROFILE_H264_MAIN) { frameInfo_.format = H264_MAIN_LEVEL; } else if (profile == FF_PROFILE_H264_HIGH) { frameInfo_.format = H264_HIGH_LEVEL; } else { LogError << "engineId_:" << engineId_ << " not support h264 profile"; return APP_ERR_COMM_FAILURE; } } else if (codecId == AV_CODEC_ID_H265) { int profile = pFormatCtx_->streams[iVideoStream_]->codecpar->profile; if (profile == FF_PROFILE_HEVC_MAIN) { frameInfo_.format = H265_MAIN_LEVEL; } else { LogError << "engineId_:" << engineId_ << " not support h265 profile"; return APP_ERR_COMM_FAILURE; } } else { LogError << "engineId_:" << engineId_ << " Error unsupported format" << codecId; return APP_ERR_COMM_FAILURE; } } return APP_ERR_OK; } AVFormatContext *CameraEngine::CreateFormatContext() { // create message for stream pull AVFormatContext *pFormatContext = nullptr; AVDictionary *pOptions = nullptr; // formatContext = avformat_alloc_context(); if (dataSourceConfig_.strUrl.find("rtsp:") != std::string::npos) // rtsp { av_dict_set(&pOptions, "rtsp_transport", "tcp", 0); // 指定其传输方式为TCP // av_dict_set(&pOptions, "stimeout", "3000000", 0); // 设置超时3秒 // av_dict_set(&pOptions, "rw_timeout", "3000", 0); //单位:ms av_dict_set(&pOptions, "timeout", "3000000", 0); //设置超时时间为3秒 } //av_register_all(); //注册所有支持的格式(这里一定注册这些,否则会因为协议解析问题报错!!!) //avcodec_register_all(); //注册编解码器 //avformat_network_init(); //注册网格格式,如果为本地文件则可以去掉该代码 int iRet = avformat_open_input(&pFormatContext, dataSourceConfig_.strUrl.c_str(), nullptr, &pOptions); if (nullptr != pOptions) { av_dict_free(&pOptions); } if (iRet != 0) { LogError << "engineId_:" << engineId_ << " Couldn't open input stream " << dataSourceConfig_.strUrl.c_str() << ", iRet=" << iRet; return nullptr; } // pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; // pFormatContext->pb->flags |= AVIO_FLAG_NONBLOCK; // av_dict_set(&pFormatContext->interrupt_callback.callback, "timeout", "3000", 0); // iRet = avio_open2(&pFormatContext->pb, dataSourceConfig_.strUrl.c_str(), AVIO_FLAG_READ, NULL, NULL) < 0; // { // // 处理错误 // LogError << "engineId_:" << engineId_ << "avio_open2 iRet=" << iRet; // return nullptr; // } iRet = avformat_find_stream_info(pFormatContext, nullptr); if (iRet != 0) { LogError << "engineId_:" << engineId_ << " Couldn't find stream information, iRet = " << iRet; return nullptr; } return pFormatContext; } //av_read_frame的中断回调函数 // int CameraEngine::InterruptCallback(void *pData) // { // TimeoutContext* pTimeOutCtx = (TimeoutContext*)pData; // LogDebug << "InterruptCallback i64Timeout:" << pTimeOutCtx->i64Timeout; // return std::chrono::duration_cast( // std::chrono::system_clock::now().time_since_epoch()) // .count() >= pTimeOutCtx->i64Timeout // ? AVERROR_EXIT // : 0; // } APP_ERROR CameraEngine::Process() { int iRet = APP_ERR_OK; if (!bUseEngine_) { LogWarn << "engineId_:" << engineId_ << " not use engine"; return APP_ERR_OK; } if (bHwDecode_) { iRet = ConnectCamera(); if (iRet == APP_ERR_OK) { LogInfo << "engineId_:" << engineId_ << " Start the stream......"; bReconnectFlag_ = false; } else { ResetCamera(); bReconnectFlag_ = true; } // Pull data cyclically AVPacket pkt; while (!isStop_) { //重连相机 if (bReconnectFlag_) { iRet = ConnectCamera(); if (iRet == APP_ERR_OK) { LogInfo << "engineId_:" << engineId_ << " Start the stream......"; bReconnectFlag_ = false; this->bCameraError_ = false; } else { if (!this->bCameraError_) { outputQueMap_[strPort1_]->push( std::static_pointer_cast( std::make_shared("摄像头连接失败!"))); this->bCameraError_ = true; } ResetCamera(); std::this_thread::sleep_for(std::chrono::seconds(3)); //3秒后重连 continue; } } //设置av_read_frame中断函数 (中断函数中超过1s,则中断处理) // TimeoutContext timeoutCtx = { std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count() + 1000 }; // pFormatCtx_->interrupt_callback.callback = &CameraEngine::InterruptCallback; // pFormatCtx_->interrupt_callback.opaque = &timeoutCtx; av_init_packet(&pkt); //init pkt iRet = av_read_frame(pFormatCtx_, &pkt); //需要一直读取,否则获取到的是历史数据 if (iRet != 0) { outputQueMap_[strPort1_]->push(std::static_pointer_cast(std::make_shared("图像读取失败!"))); LogError << "engineId_:" << engineId_ << " Read frame failed, reconnect iRet:" << iRet; av_packet_unref(&pkt); //重连相机 ResetCamera(); bReconnectFlag_ = true; continue; } else if (pkt.stream_index == iVideoStream_) //只解码视频流 { // LogDebug << "iRet:" << iRet << " pkt.size:" << pkt.size; if (pkt.size <= 0) { LogError << "engineId_:" << engineId_ << " Invalid pkt.size: " << pkt.size; av_packet_unref(&pkt); continue; } if (dataSourceConfig_.strUrl.find(".mp4") != std::string::npos) { const char szStartCode[4] = {0, 0, 0, 1}; if (bIsAvc_ || memcmp(szStartCode, pkt.data, 4) != 0) { // is avc1 code, have no start code of H264 int iLen = 0; uint8_t *p = pkt.data; bIsAvc_ = true; do { // add start_code for each NAL, one frame may have multi NALs. iLen = ntohl(*((long *)p)); memcpy(p, szStartCode, 4); p += 4; p += iLen; if (p >= pkt.data + pkt.size) { break; } } while (1); } } void* pH264Buffer = nullptr; pH264Buffer = new uint8_t[pkt.size]; memcpy(pH264Buffer, pkt.data, pkt.size); //组织数据 std::shared_ptr pProcessData = std::make_shared(); pProcessData->iWidth = frameInfo_.iWidth; pProcessData->iHeight = frameInfo_.iHeight; pProcessData->iRate = frameInfo_.iRate; pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis(); pProcessData->iDataSource = engineId_; pProcessData->iSize = pkt.size; pProcessData->pData.reset(pH264Buffer, [](void* data){if(data) {delete[] data; data = nullptr;}}); //智能指针管理内存 //push端口0,视频解码 iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData)); if (iRet != APP_ERR_OK) { LogError << "engineId_:" << engineId_ << "push the h264 frame data failed..."; } } else if (pkt.stream_index == iAudioStream_) { //音频流不处理。 } else { LogError << "engineId_:" << engineId_ << " stream err stream_index:" << pkt.stream_index; } av_packet_unref(&pkt); //unref if (dataSourceConfig_.strUrl.find("rtsp:") == std::string::npos) // 如果不是rtsp,定时发送 { usleep(DELAY_TIME); // delay 40ms } } } else { //从摄像头RTSP拉流 const std::string videoStreamAddress = std::string("rtspsrc location=") + dataSourceConfig_.strUrl.c_str() + " latency=10 ! \ rtph264depay ! h264parse ! nvv4l2decoder enable-max-performance=1 enable-frame-type-reporting=1 ! nvvidconv ! video/x-raw, format=(string)BGRx ! videoconvert ! appsink"; VideoCapture capture_video; while(!capture_video.open(videoStreamAddress)){ //, cv::CAP_FFMPEG LogInfo<<"Restart Opening video stream or file ..."< pBGRFrameData = std::make_shared(); std::shared_ptr pProcessData = std::make_shared(); if(!capture_video.read(frame)) { capture_video.release(); while(!capture_video.open(videoStreamAddress)){ //, cv::CAP_FFMPEG LogInfo<<"Restart Opening video stream or file ..."<iDataSource = engineId_; pBGRFrameData->iFrameId = nFrameid++; pBGRFrameData->iSize = resizepBGRBuffer_Size; pBGRFrameData->frameInfo.iWidth = IMAGE_WIDTH; pBGRFrameData->frameInfo.iHeight = IMAGE_HEIGHT; pBGRFrameData->frameInfo.iRate = frameRate; pProcessData->pVoidData = std::static_pointer_cast(pBGRFrameData); pProcessData->pData.reset(resizeBGRBufferobj, [](void* data){if(data) {delete[] data; data = nullptr;}}); if (nFrameid >= 0xFFFFFFFF) {nFrameid = 0;} pBGRFrameData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis(); pProcessData->iWidth = pBGRFrameData->frameInfo.iWidth; pProcessData->iHeight = pBGRFrameData->frameInfo.iHeight; pProcessData->iHeight = pBGRFrameData->frameInfo.iRate; iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData)); } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.h b/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.h index 0c11c59..d3a880f 100644 --- a/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.h +++ b/nvidia_ascend_engine/common_engine/DataSourceEngine/CameraEngine.h @@ -9,7 +9,7 @@ #include "AppCommon.h" - //编译器这部分代码按C语言(而不是C++)的方式进行编译 +//编译器这部分代码按C语言(而不是C++)的方式进行编译 #ifdef __cplusplus extern "C" { @@ -50,7 +50,7 @@ protected: APP_ERROR GetStreamInfo(); APP_ERROR ConnectCamera(); //连接相机 void ResetCamera(); //复位相机连接 - static int InterruptCallback(void *pData); + //static int InterruptCallback(void *pData); private: AVFormatContext *pFormatCtx_ = nullptr; @@ -65,6 +65,8 @@ private: int nDelayTime; bool bIsAvc_ = false; int iAudioStream_ = -1; + + bool bCameraError_ = false; }; ENGINE_REGIST(CameraEngine) diff --git a/nvidia_ascend_engine/common_engine/DataSourceEngine/ReadImgEngine.cpp b/nvidia_ascend_engine/common_engine/DataSourceEngine/ReadImgEngine.cpp deleted file mode 100644 index 0cf315b..0000000 --- a/nvidia_ascend_engine/common_engine/DataSourceEngine/ReadImgEngine.cpp +++ /dev/null @@ -1,160 +0,0 @@ -#include "ReadImgEngine.h" -#include -#include -#include -#include -#include -#include "myutils.h" - -using namespace ai_matrix; - -namespace -{ - //按照文件名排序 - bool CompareFileName(const std::string &sParam1, const std::string &sParam2) - { - int iPos1 = sParam1.find("."); - int iPos11 = sParam1.find_last_of("/"); - int iPos2 = sParam2.find("."); - int iPos22 = sParam2.find_last_of("/"); - std::string sFileName1 = sParam1.substr(iPos11+1, iPos1-iPos11-1); - std::string sFileName2 = sParam2.substr(iPos22+1, iPos2-iPos22-1); - return (atoi(sFileName1.c_str()) < atoi(sFileName2.c_str())); - } -} - -ReadImgEngine::ReadImgEngine() {} - -ReadImgEngine::~ReadImgEngine() {} - -APP_ERROR ReadImgEngine::Init() -{ - bUseEngine_ = true; - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 - if (MyYaml::GetIns()->GetStringValue("gc_data_source") != "images" || !dataSourceConfig_.bUse) - { - bUseEngine_ = false; - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - LogInfo << "engineId_:" << engineId_ << " ReadImgEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR ReadImgEngine::DeInit() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - LogInfo << "engineId_:" << engineId_ << " ReadImgEngine DeInit ok"; - return APP_ERR_OK; -} - -void ReadImgEngine::RecursionReadDir(const std::string &strDir) -{ - boost::filesystem::directory_iterator end_itr; - for (boost::filesystem::directory_iterator itr(strDir); itr != end_itr; ++itr) - { - if (boost::filesystem::is_directory(*itr)) //文件夹 - { - RecursionReadDir(itr->path().string()); - } - else - { - std::string strExt = itr->path().extension().string(); - if (strExt.compare(".jpg") == 0) - { - vecFiles_.push_back(itr->path().string()); //保存绝对路径 - } - } - } -} - -std::string ReadImgEngine::GetFileName(const std::string &strParam) -{ - int iPos = strParam.find("."); - int iPos1 = strParam.find_last_of("/"); - return strParam.substr(iPos1 + 1, iPos - iPos1 - 1); -} - -APP_ERROR ReadImgEngine::Process() -{ - - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - int iRet = APP_ERR_OK; - RecursionReadDir(dataSourceConfig_.strUrl); //递归读取文件夹 - if (vecFiles_.size() == 0) - { - LogError << "engineId_:" << engineId_ << " no file"; - return APP_ERR_COMM_FAILURE; - } - std::sort(vecFiles_.begin(), vecFiles_.end(), CompareFileName); - LogInfo << "engineId_:" << engineId_ << " vecFiles_ size: " << vecFiles_.size(); - - int iFileIndex = 0; //文件序号 - while (!isStop_) - { - - std::string strFilePath = vecFiles_.at(iFileIndex); - cv::Mat matBGR = cv::imread(strFilePath); - - //组织数据 - std::shared_ptr pProcessData = std::make_shared(); - pProcessData->iWidth = matBGR.cols; - pProcessData->iHeight = matBGR.rows; - pProcessData->iRate = 25; - pProcessData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis(); - pProcessData->iDataSource = engineId_; - - uint32_t iBGRSize = pProcessData->iWidth * pProcessData->iHeight * 3; - void *pBGRBuffer = nullptr; - pBGRBuffer = new uint8_t[iBGRSize]; - memcpy(pBGRBuffer, matBGR.data, iBGRSize); - pProcessData->pData.reset(pBGRBuffer, [](void *data){if(data) {delete[] data; data = nullptr;} }); // 智能指针管理内存 - pProcessData->iSize = iBGRSize; - - // //读取文件内容 - // RawData rawData; - // iRet = ReadFile(strFilePath, rawData); - // if (iRet != APP_ERR_OK) - // { - // LogError << "engineId_:" << engineId_ << " Failed to read image on " << strFilePath << ", iRet = " << iRet << "."; - // return iRet; - // } - - // //组织数据 - // std::shared_ptr pFrameData = std::make_shared(); - // pFrameData->iDataSource = engineId_; - // pFrameData->iFrameId = iFileIndex + 1; - // pFrameData->iSize = rawData.lenOfByte; - // pFrameData->pData = rawData.data; - // pFrameData->i64TimeStamp = MyUtils::getins()->GetCurrentTimeMillis(); - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData)); - - iFileIndex = (iFileIndex + 1) % vecFiles_.size(); - if (iFileIndex == 0) - { - LogInfo << "engineId_:" << engineId_ << " read images finish "; - while (!isStop_) - { - usleep(100000); //100ms - } - - //break; //只发布一遍 - } - //模拟1秒25帧 - usleep(40000); //40ms - } - return APP_ERR_OK; -} - diff --git a/nvidia_ascend_engine/common_engine/DataSourceEngine/ReadImgEngine.h b/nvidia_ascend_engine/common_engine/DataSourceEngine/ReadImgEngine.h deleted file mode 100644 index 3f3953e..0000000 --- a/nvidia_ascend_engine/common_engine/DataSourceEngine/ReadImgEngine.h +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 读取图片解码引擎 - * */ - -#ifndef READIMGENGINE_H -#define READIMGENGINE_H - -#include "AppCommon.h" - -#include "EngineBase.h" -#include "EngineFactory.h" -#include "MyYaml.h" - - -class ReadImgEngine : public ai_matrix::EngineBase -{ -public: - ReadImgEngine(); - ~ReadImgEngine(); - - APP_ERROR Init() override; - APP_ERROR DeInit() override; - APP_ERROR Process() override; - -protected: - void RecursionReadDir(const std::string &dir); //递归读取文件夹 - -private: - std::string GetFileName(const std::string &strParam); - - bool bUseEngine_; - ai_matrix::DataSourceConfig dataSourceConfig_; - std::vector vecFiles_; //文件名集合 - uint64_t frameid_; //帧号 - uint64_t timestamp_; //时间戳 - std::string strPort0_; - -}; - -ENGINE_REGIST(ReadImgEngine) - -#endif diff --git a/nvidia_ascend_engine/common_engine/DataUploadEngine/DeviceStatusUpSerEngine.cpp b/nvidia_ascend_engine/common_engine/DataUploadEngine/DeviceStatusUpSerEngine.cpp index 79ed3bc..698ae91 100644 --- a/nvidia_ascend_engine/common_engine/DataUploadEngine/DeviceStatusUpSerEngine.cpp +++ b/nvidia_ascend_engine/common_engine/DataUploadEngine/DeviceStatusUpSerEngine.cpp @@ -1,269 +1 @@ -/* - * @Author: your name - * @Date: 2023-07-20 17:15:33 - * @LastEditors: your name - * @LastEditTime: 2023-07-23 20:09:39 - * @Description: file content - * @FilePath: /shigetai_lirs/nvidia_ascend_engine/common_engine/DataUploadEngine/DeviceStatusUpSerEngine.cpp - * - * Copyright © 2022 - */ -#include "DeviceStatusUpSerEngine.h" -#include "myutils.h" - - -DeviceStatusUpSerEngine::DeviceStatusUpSerEngine() {} -DeviceStatusUpSerEngine::~DeviceStatusUpSerEngine() {} - -APP_ERROR DeviceStatusUpSerEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strGetTokenURL_ = MyYaml::GetIns()->GetStringValue("gc_gettoken_url"); - strURL_ = MyYaml::GetIns()->GetStringValue("gc_device_status_url"); - strPoundNo_ = MyYaml::GetIns()->GetStringValue("atlas_poundno"); - LogInfo << "DeviceStatusUpSerEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR DeviceStatusUpSerEngine::DeInit() -{ - LogDebug << "curl_easy_cleanup"; - curl_easy_cleanup(pCurl_); - - /* 这个处理移动到main中, 防止多线程调用 - LogDebug << "内存清理"; - curl_global_cleanup(); - */ - LogInfo << "DeviceStatusUpSerEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* libcurl回调函数 -* inParam : void *pBuffer 回调内容地址 - : size_t size 回调单个数据大小 - : size_t nmemb 回调数据个数 -* outParam: std::string &strResp 返回内容 -* return : 回调数据大小 -*/ -size_t DeviceStatusUpSerEngine::WriteCallBack(void *pBuffer, size_t size, size_t nmemb, std::string &strResp) -{ - size_t sizes = size * nmemb; - std::string strTemp((char*)pBuffer, sizes); - strResp += strTemp; - return sizes; -} - -/** -* 调用http接口获取token -* inParam : -* outParam: std::string &strBladeAuth 返回的token信息 -* return : true:成功; false:失败 -*/ -bool DeviceStatusUpSerEngine::GetToken(std::string &strBladeAuth) -{ - //1. 获得curl操作符 - if (nullptr == pCurl_) - { - LogDebug<<"pCurl_ is null, invoke curl_easy_init"; - pCurl_ = curl_easy_init(); - if (nullptr == pCurl_) - { - LogError << "curl_easy_init failed !"; - return false; - } - } - - //2. 设置head, 和表单 - //设置head信息 - struct curl_slist *pHeaderList = nullptr; - pHeaderList = curl_slist_append(pHeaderList, "Authorization:Basic Y2xpZW50X2VudGVycHJpc2U6Y2xpZW50X2VudGVycHJpc2Vfc2VjcmV0"); - - //设置表单信息 - curl_mime *pMultipart = curl_mime_init(pCurl_); - curl_mimepart *pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "username"); - curl_mime_data(pPart, "guest_01", CURL_ZERO_TERMINATED); - pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "password"); - curl_mime_data(pPart, "d55b0f642e817eea24725d2f2a31dd08", CURL_ZERO_TERMINATED); - pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "tenantId"); - curl_mime_data(pPart, "000000", CURL_ZERO_TERMINATED); - pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "grant_type"); - curl_mime_data(pPart, "password", CURL_ZERO_TERMINATED); - - curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) - curl_easy_setopt(pCurl_, CURLOPT_URL, strGetTokenURL_.c_str()); //设置url - curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 - curl_easy_setopt(pCurl_, CURLOPT_MIMEPOST, pMultipart); //设置表单 - //curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strBody.c_str()); //设置post内容 - //curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) - curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 - std::string strResponse; - curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 - - //3. 执行http请求 - CURLcode res = curl_easy_perform(pCurl_); - curl_slist_free_all(pHeaderList); //清除headerlist - curl_mime_free(pMultipart); //清除curl_mime - curl_easy_reset(pCurl_); //重置curl - if (res != CURLE_OK) - { - LogError << " curl_easy_perform fail:" << curl_easy_strerror(res); - return false; - } - - //4. 执行成功解析响应内容 - Json::CharReaderBuilder readerBuilder; - std::shared_ptr reader(readerBuilder.newCharReader()); - Json::Value jvResponse; - JSONCPP_STRING errs; - if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) - { - LogError << " response content fail " << strResponse; - return false; - } - LogDebug << "GetToken resp:" << strResponse; - - strBladeAuth += jvResponse["token_type"].asString(); - strBladeAuth += " "; - strBladeAuth += jvResponse["access_token"].asString(); - return true; -} - -/** -* 列车信息提交http接口 -* inParam : Json::Value &jvRequest 提交内容 -* outParam: -* return : true:提交成功; false:提交失败 -*/ -bool DeviceStatusUpSerEngine::ResultToHttpSrv(Json::Value &jvRequest) -{ - //获取token - std::string strBladeAuth("blade-auth:"); - if (!GetToken(strBladeAuth)) - { - LogError << " GetToken fail "; - return false; - } - LogDebug << "strBladeAuth:" << strBladeAuth; - - //1. 获得curl操作符 - if (nullptr == pCurl_) - { - LogDebug<<"pCurl_ is null, invoke curl_easy_init"; - pCurl_ = curl_easy_init(); - if (nullptr == pCurl_) - { - LogError << "curl_easy_init failed !"; - return false; - } - } - - //2. 设置http请求信息 - Json::StreamWriterBuilder jswBuilder; - std::string strRequest = Json::writeString(jswBuilder, jvRequest); - LogDebug << "to http:" << strRequest; - std::string strResponse; - struct curl_slist *pHeaderList = nullptr; - pHeaderList = curl_slist_append(pHeaderList, "Accept:application/json"); - pHeaderList = curl_slist_append(pHeaderList, "Content-Type:application/json"); - pHeaderList = curl_slist_append(pHeaderList, "charset:utf-8"); - pHeaderList = curl_slist_append(pHeaderList, strBladeAuth.c_str()); - curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) - curl_easy_setopt(pCurl_, CURLOPT_URL, strURL_.c_str()); //设置url - curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 - curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strRequest.c_str()); //设置post内容 - curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) - curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 - curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 - - //3. 执行http请求 - CURLcode res = curl_easy_perform(pCurl_); - curl_slist_free_all(pHeaderList); //清除headerlist - curl_easy_reset(pCurl_); //重置curl - if (res != CURLE_OK) - { - LogError << jvRequest.toStyledString() - << " curl_easy_perform fail:" << curl_easy_strerror(res); - return false; - } - - //4. 执行成功解析响应内容 - LogDebug << "设备异常上传结果:" << strResponse; - Json::CharReaderBuilder readerBuilder; - std::shared_ptr reader(readerBuilder.newCharReader()); - Json::Value jvResponse; - JSONCPP_STRING errs; - if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) - { - LogError << jvRequest.toStyledString() - << " response content fail " << strResponse; - return false; - } - - if (!jvResponse["success"].asBool()) - { - LogError << jvRequest.toStyledString() - << " response fail:" << strResponse; - return false; - } - - LogInfo << jvRequest.toStyledString() - << " post success"; - return true; -} - - -APP_ERROR DeviceStatusUpSerEngine::Process() -{ - int iRet = APP_ERR_OK; - if (0 == MyYaml::GetIns()->GetIntValue("gc_device_status_open")) - { - LogDebug << " gc_device_status_open value is 0"; - return APP_ERR_OK; - } - - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - - //无数据大于1分钟 - iNoDataCnt_++; - if (iNoDataCnt_ > (60 * 1000)) - { - iNoDataCnt_ = 0; - } - continue; - } - iNoDataCnt_ = 0; - - std::shared_ptr pWarn = std::static_pointer_cast(pVoidData0); - - ai_matrix::DataSourceConfig dataSourceConfig = MyYaml::GetIns()->GetDataSourceConfigById(0); //获取摄像机参数 - - //组装post信息 - Json::Value jvRequest; - jvRequest["tainsModule"] = "2"; // 传输模块:0=装车模块,1=超偏载模块,2=车号识别模块,3=web 模块 - jvRequest["networkStatus"] = "异常"; //网络状态: 正常/异常 - jvRequest["devName"] = "摄像头";// 设备名称 - jvRequest["devSn"] = strPoundNo_+"股道";// 设备编码 - jvRequest["cpuData"] = "";// CPU 情况 - jvRequest["memoryUsage"] = "";// 内存使用情况 - jvRequest["devRunningStatus"] = "异常";// 设备运行状态:正常/异常 - jvRequest["devCheckResult"] = *pWarn;// 检测结果 - jvRequest["devIp"] = dataSourceConfig.strUrl;// 设备 IP - jvRequest["devAccount"] = "";// 设备账号 - if (!ResultToHttpSrv(jvRequest)) - { - LogError << "摄像头异常状态上传服务器失败!"; - } - } - return APP_ERR_OK; -} +/* * @Author: your name * @Date: 2023-07-20 17:15:33 * @LastEditors: your name * @LastEditTime: 2023-07-23 20:09:39 * @Description: file content * @FilePath: /shigetai_lirs/nvidia_ascend_engine/common_engine/DataUploadEngine/DeviceStatusUpSerEngine.cpp * * Copyright © 2022 */ #include "DeviceStatusUpSerEngine.h" #include "myutils.h" DeviceStatusUpSerEngine::DeviceStatusUpSerEngine() {} DeviceStatusUpSerEngine::~DeviceStatusUpSerEngine() {} APP_ERROR DeviceStatusUpSerEngine::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strGetTokenURL_ = MyYaml::GetIns()->GetStringValue("gc_gettoken_url"); strURL_ = MyYaml::GetIns()->GetStringValue("gc_device_status_url"); strPoundNo_ = MyYaml::GetIns()->GetStringValue("atlas_poundno"); LogInfo << "DeviceStatusUpSerEngine Init ok"; return APP_ERR_OK; } APP_ERROR DeviceStatusUpSerEngine::DeInit() { LogDebug << "curl_easy_cleanup"; curl_easy_cleanup(pCurl_); /* 这个处理移动到main中, 防止多线程调用 LogDebug << "内存清理"; curl_global_cleanup(); */ LogInfo << "DeviceStatusUpSerEngine DeInit ok"; return APP_ERR_OK; } /** * libcurl回调函数 * inParam : void *pBuffer 回调内容地址 : size_t size 回调单个数据大小 : size_t nmemb 回调数据个数 * outParam: std::string &strResp 返回内容 * return : 回调数据大小 */ size_t DeviceStatusUpSerEngine::WriteCallBack(void *pBuffer, size_t size, size_t nmemb, std::string &strResp) { size_t sizes = size * nmemb; std::string strTemp((char*)pBuffer, sizes); strResp += strTemp; return sizes; } /** * 调用http接口获取token * inParam : * outParam: std::string &strBladeAuth 返回的token信息 * return : true:成功; false:失败 */ bool DeviceStatusUpSerEngine::GetToken(std::string &strBladeAuth) { //1. 获得curl操作符 if (nullptr == pCurl_) { LogDebug<<"pCurl_ is null, invoke curl_easy_init"; pCurl_ = curl_easy_init(); if (nullptr == pCurl_) { LogError << "curl_easy_init failed !"; return false; } } //2. 设置head, 和表单 //设置head信息 struct curl_slist *pHeaderList = nullptr; pHeaderList = curl_slist_append(pHeaderList, "Authorization:Basic Y2xpZW50X2VudGVycHJpc2U6Y2xpZW50X2VudGVycHJpc2Vfc2VjcmV0"); //设置表单信息 curl_mime *pMultipart = curl_mime_init(pCurl_); curl_mimepart *pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "username"); curl_mime_data(pPart, "guest_01", CURL_ZERO_TERMINATED); pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "password"); curl_mime_data(pPart, "d55b0f642e817eea24725d2f2a31dd08", CURL_ZERO_TERMINATED); pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "tenantId"); curl_mime_data(pPart, "000000", CURL_ZERO_TERMINATED); pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "grant_type"); curl_mime_data(pPart, "password", CURL_ZERO_TERMINATED); curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) curl_easy_setopt(pCurl_, CURLOPT_URL, strGetTokenURL_.c_str()); //设置url curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 curl_easy_setopt(pCurl_, CURLOPT_MIMEPOST, pMultipart); //设置表单 //curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strBody.c_str()); //设置post内容 //curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 std::string strResponse; curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 //3. 执行http请求 CURLcode res = curl_easy_perform(pCurl_); curl_slist_free_all(pHeaderList); //清除headerlist curl_mime_free(pMultipart); //清除curl_mime curl_easy_reset(pCurl_); //重置curl if (res != CURLE_OK) { LogError << " curl_easy_perform fail:" << curl_easy_strerror(res); return false; } //4. 执行成功解析响应内容 Json::CharReaderBuilder readerBuilder; std::shared_ptr reader(readerBuilder.newCharReader()); Json::Value jvResponse; JSONCPP_STRING errs; if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) { LogError << " response content fail " << strResponse; return false; } LogDebug << "GetToken resp:" << strResponse; strBladeAuth += jvResponse["token_type"].asString(); strBladeAuth += " "; strBladeAuth += jvResponse["access_token"].asString(); return true; } /** * 列车信息提交http接口 * inParam : Json::Value &jvRequest 提交内容 * outParam: * return : true:提交成功; false:提交失败 */ bool DeviceStatusUpSerEngine::ResultToHttpSrv(Json::Value &jvRequest) { //获取token std::string strBladeAuth("blade-auth:"); if (!GetToken(strBladeAuth)) { LogError << " GetToken fail "; return false; } LogDebug << "strBladeAuth:" << strBladeAuth; //1. 获得curl操作符 if (nullptr == pCurl_) { LogDebug<<"pCurl_ is null, invoke curl_easy_init"; pCurl_ = curl_easy_init(); if (nullptr == pCurl_) { LogError << "curl_easy_init failed !"; return false; } } //2. 设置http请求信息 Json::StreamWriterBuilder jswBuilder; std::string strRequest = Json::writeString(jswBuilder, jvRequest); LogDebug << "to http:" << strRequest; std::string strResponse; struct curl_slist *pHeaderList = nullptr; pHeaderList = curl_slist_append(pHeaderList, "Accept:application/json"); pHeaderList = curl_slist_append(pHeaderList, "Content-Type:application/json"); pHeaderList = curl_slist_append(pHeaderList, "charset:utf-8"); pHeaderList = curl_slist_append(pHeaderList, strBladeAuth.c_str()); curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) curl_easy_setopt(pCurl_, CURLOPT_URL, strURL_.c_str()); //设置url curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strRequest.c_str()); //设置post内容 curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 //3. 执行http请求 CURLcode res = curl_easy_perform(pCurl_); curl_slist_free_all(pHeaderList); //清除headerlist curl_easy_reset(pCurl_); //重置curl if (res != CURLE_OK) { LogError << jvRequest.toStyledString() << " curl_easy_perform fail:" << curl_easy_strerror(res); return false; } //4. 执行成功解析响应内容 LogDebug << "设备异常上传结果:" << strResponse; Json::CharReaderBuilder readerBuilder; std::shared_ptr reader(readerBuilder.newCharReader()); Json::Value jvResponse; JSONCPP_STRING errs; if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) { LogError << jvRequest.toStyledString() << " response content fail " << strResponse; return false; } if (!jvResponse["success"].asBool()) { LogError << jvRequest.toStyledString() << " response fail:" << strResponse; return false; } LogInfo << jvRequest.toStyledString() << " post success"; return true; } APP_ERROR DeviceStatusUpSerEngine::Process() { int iRet = APP_ERR_OK; if (0 == MyYaml::GetIns()->GetIntValue("gc_http_open")) { LogDebug << " gc_http_open value is 0"; return APP_ERR_OK; } while (!isStop_) { std::shared_ptr pVoidData0 = nullptr; inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); //1ms //无数据大于1分钟 iNoDataCnt_++; if (iNoDataCnt_ > (60 * 1000)) { iNoDataCnt_ = 0; } continue; } iNoDataCnt_ = 0; std::shared_ptr pWarn = std::static_pointer_cast(pVoidData0); ai_matrix::DataSourceConfig dataSourceConfig = MyYaml::GetIns()->GetDataSourceConfigById(0); //获取摄像机参数 //组装post信息 Json::Value jvRequest; jvRequest["tainsModule"] = "2"; // 传输模块:0=装车模块,1=超偏载模块,2=车号识别模块,3=web 模块 jvRequest["networkStatus"] = "异常"; //网络状态: 正常/异常 jvRequest["devName"] = "摄像头";// 设备名称 jvRequest["devSn"] = strPoundNo_+"股道";// 设备编码 jvRequest["cpuData"] = "";// CPU 情况 jvRequest["memoryUsage"] = "";// 内存使用情况 jvRequest["devRunningStatus"] = "异常";// 设备运行状态:正常/异常 jvRequest["devCheckResult"] = *pWarn;// 检测结果 jvRequest["devIp"] = dataSourceConfig.strUrl;// 设备 IP jvRequest["devAccount"] = "";// 设备账号 if (!ResultToHttpSrv(jvRequest)) { LogError << "摄像头异常状态上传服务器失败!"; } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/DataUploadEngine/ResultToHttpSrvEngine.cpp b/nvidia_ascend_engine/common_engine/DataUploadEngine/ResultToHttpSrvEngine.cpp index 85daa6b..e1289fa 100644 --- a/nvidia_ascend_engine/common_engine/DataUploadEngine/ResultToHttpSrvEngine.cpp +++ b/nvidia_ascend_engine/common_engine/DataUploadEngine/ResultToHttpSrvEngine.cpp @@ -1,445 +1 @@ -#include "ResultToHttpSrvEngine.h" -#include "myutils.h" - - -ResultToHttpSrvEngine::ResultToHttpSrvEngine() {} -ResultToHttpSrvEngine::~ResultToHttpSrvEngine() {} - -APP_ERROR ResultToHttpSrvEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strUsername_ = MyYaml::GetIns()->GetStringValue("username"); - strPassword_ = MyYaml::GetIns()->GetStringValue("password"); - strURL_ = MyYaml::GetIns()->GetStringValue("gc_http_url"); - strGetTokenURL_ = MyYaml::GetIns()->GetStringValue("gc_gettoken_url"); - strImageSrv_ = MyYaml::GetIns()->GetPathValue("gc_image_srv"); - strPoundNo_ = MyYaml::GetIns()->GetStringValue("atlas_poundno"); - strFailSavePath_ = MyYaml::GetIns()->GetPathValue("gc_result_path") + "httpfailcontent.csv"; - strFailSaveBakPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path") + "httpfailcontent_bak.csv"; - LogInfo << "ResultToHttpSrvEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR ResultToHttpSrvEngine::DeInit() -{ - LogDebug << "curl_easy_cleanup"; - curl_easy_cleanup(pCurl_); - - /* 这个处理移动到main中, 防止多线程调用 - LogDebug << "内存清理"; - curl_global_cleanup(); - */ - LogInfo << "ResultToHttpSrvEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* libcurl回调函数 -* inParam : void *pBuffer 回调内容地址 - : size_t size 回调单个数据大小 - : size_t nmemb 回调数据个数 -* outParam: std::string &strResp 返回内容 -* return : 回调数据大小 -*/ -size_t ResultToHttpSrvEngine::WriteCallBack(void *pBuffer, size_t size, size_t nmemb, std::string &strResp) -{ - size_t sizes = size * nmemb; - std::string strTemp((char*)pBuffer, sizes); - strResp += strTemp; - return sizes; -} - -/** -* 调用http接口获取token -* inParam : -* outParam: std::string &strBladeAuth 返回的token信息 -* return : true:成功; false:失败 -*/ -bool ResultToHttpSrvEngine::GetToken(std::string &strBladeAuth) -{ - //1. 获得curl操作符 - if (nullptr == pCurl_) - { - LogDebug<<"pCurl_ is null, invoke curl_easy_init"; - pCurl_ = curl_easy_init(); - if (nullptr == pCurl_) - { - LogError << "curl_easy_init failed !"; - return false; - } - } - - //2. 设置head, 和表单 - //设置head信息 - struct curl_slist *pHeaderList = nullptr; - pHeaderList = curl_slist_append(pHeaderList, "Authorization:Basic Y2xpZW50X2VudGVycHJpc2U6Y2xpZW50X2VudGVycHJpc2Vfc2VjcmV0"); - - //设置表单信息 - curl_mime *pMultipart = curl_mime_init(pCurl_); - curl_mimepart *pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "username"); - curl_mime_data(pPart, strUsername_.c_str(), CURL_ZERO_TERMINATED); - pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "password"); - curl_mime_data(pPart, strPassword_.c_str(), CURL_ZERO_TERMINATED); - pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "tenantId"); - curl_mime_data(pPart, "000000", CURL_ZERO_TERMINATED); - pPart = curl_mime_addpart(pMultipart); - curl_mime_name(pPart, "grant_type"); - curl_mime_data(pPart, "password", CURL_ZERO_TERMINATED); - - curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) - curl_easy_setopt(pCurl_, CURLOPT_URL, strGetTokenURL_.c_str()); //设置url - curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 - curl_easy_setopt(pCurl_, CURLOPT_MIMEPOST, pMultipart); //设置表单 - //curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strBody.c_str()); //设置post内容 - //curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) - curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 - std::string strResponse; - curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 - - //3. 执行http请求 - CURLcode res = curl_easy_perform(pCurl_); - curl_slist_free_all(pHeaderList); //清除headerlist - curl_mime_free(pMultipart); //清除curl_mime - curl_easy_reset(pCurl_); //重置curl - if (res != CURLE_OK) - { - LogError << " curl_easy_perform fail:" << curl_easy_strerror(res); - return false; - } - - //4. 执行成功解析响应内容 - Json::CharReaderBuilder readerBuilder; - std::shared_ptr reader(readerBuilder.newCharReader()); - Json::Value jvResponse; - JSONCPP_STRING errs; - if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) - { - LogError << " response content fail " << strResponse; - return false; - } - LogDebug << "GetToken resp:" << strResponse; - - strBladeAuth += jvResponse["token_type"].asString(); - strBladeAuth += " "; - strBladeAuth += jvResponse["access_token"].asString(); - return true; -} - -/** -* 列车信息提交http接口 -* inParam : Json::Value &jvRequest 提交内容 -* outParam: -* return : true:提交成功; false:提交失败 -*/ -bool ResultToHttpSrvEngine::ResultToHttpSrv(Json::Value &jvRequest) -{ - //获取token - std::string strBladeAuth("blade-auth:"); - if (!GetToken(strBladeAuth)) - { - LogError << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() << " GetToken fail "; - return false; - } - LogDebug << "strBladeAuth:" << strBladeAuth; - - //1. 获得curl操作符 - if (nullptr == pCurl_) - { - LogDebug<<"pCurl_ is null, invoke curl_easy_init"; - pCurl_ = curl_easy_init(); - if (nullptr == pCurl_) - { - LogError << "curl_easy_init failed !"; - return false; - } - } - - //2. 设置http请求信息 - Json::StreamWriterBuilder jswBuilder; - std::string strRequest = Json::writeString(jswBuilder, jvRequest); - LogDebug << "to http:" << strRequest; - std::string strResponse; - struct curl_slist *pHeaderList = nullptr; - pHeaderList = curl_slist_append(pHeaderList, "Accept:application/json"); - pHeaderList = curl_slist_append(pHeaderList, "Content-Type:application/json"); - pHeaderList = curl_slist_append(pHeaderList, "charset:utf-8"); - pHeaderList = curl_slist_append(pHeaderList, strBladeAuth.c_str()); - curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) - curl_easy_setopt(pCurl_, CURLOPT_URL, strURL_.c_str()); //设置url - curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 - curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strRequest.c_str()); //设置post内容 - curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) - curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 - curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 - - //3. 执行http请求 - CURLcode res = curl_easy_perform(pCurl_); - curl_slist_free_all(pHeaderList); //清除headerlist - curl_easy_reset(pCurl_); //重置curl - if (res != CURLE_OK) - { - LogError << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() - << " curl_easy_perform fail:" << curl_easy_strerror(res); - return false; - } - - //4. 执行成功解析响应内容 - LogInfo << "http resp:" << strResponse; - Json::CharReaderBuilder readerBuilder; - std::shared_ptr reader(readerBuilder.newCharReader()); - Json::Value jvResponse; - JSONCPP_STRING errs; - if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) - { - LogError << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() - << " response content fail " << strResponse; - return false; - } - - if (!jvResponse["success"].asBool()) - { - LogError << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() - << " response fail"; - return false; - } - - LogInfo << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() - << " post success"; - return true; -} - -/** -* 处理上传失败的信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void ResultToHttpSrvEngine::DealHttpFailInfo() -{ - //队列有待处理数据,则先不处理异常数据。 - if (inputQueMap_[strPort0_]->getSize() > 0) - { - LogDebug << "have new data to process"; - return; - } - - //文件不存在不处理 - if (access(strFailSavePath_.c_str(), F_OK) == -1) - { - LogDebug << "no exit file:" << strFailSavePath_; - return; - } - - bool bAllSucc = true; - std::ifstream inFile(strFailSavePath_.c_str(), std::ios::in); - if (!inFile.is_open()) - { - LogError << strFailSavePath_ << " open fail"; - return; - } - - int iDealCnt = 0; - std::string strLine; - while (getline(inFile, strLine)) - { - Json::CharReaderBuilder jsrBuilder; - std::shared_ptr reader(jsrBuilder.newCharReader()); - Json::Value jvRequest; - JSONCPP_STRING errs; - if (!reader->parse(strLine.data(), strLine.data() + strLine.size(), &jvRequest, &errs)) - { - LogError << "json parse fail content:" << strLine; - return; - } - - /* - 新数据到达后,异常数据还未开始处理,则直接关闭文件返回。先处理正常数据。 - 新数据到达后,异常数据处理中,则把异常未处理的数据全部当处理失败写入新文件中。先处理正常数据。 - */ - if (inputQueMap_[strPort0_]->getSize() > 0) - { - LogDebug << "Abnormal data processing, have new data to process"; - if (0 == iDealCnt) - { - LogDebug << "Abnormal data processing not start"; - inFile.close(); - return; - } - SaveHttpFailInfo(jvRequest, strFailSaveBakPath_); - bAllSucc = false; - continue; - } - - iDealCnt++; - - if (!ResultToHttpSrv(jvRequest)) - { - LogError << "re http post err:" << strLine; - //SaveHttpFailInfo(jvRequest, strFailSaveBakPath_); -// bAllSucc = false; - continue; - } - } - inFile.close(); - - if(bAllSucc) - { - //都处理成功,文件删除 - remove(strFailSavePath_.c_str()); - } - else - { - //部分处理成功,重命名后再次被处理 - rename(strFailSaveBakPath_.c_str(), strFailSavePath_.c_str()); - } -} - -/** -* 保存http上传失败的信息 -* inParam : Json::Value &jvRequest http失败信息 -* : std::string &strFilePath 保存路径 -* outParam: N/A -* return : true(成功);false(失败) -*/ -bool ResultToHttpSrvEngine::SaveHttpFailInfo(Json::Value &jvRequest, std::string &strFilePath) -{ - std::ofstream outFile; - outFile.open(strFilePath, std::ios::app); - if (!outFile.is_open()) - { - LogError << strFilePath << " open fail"; - return false; - } - - Json::StreamWriterBuilder jswBuilder; - jswBuilder["indentation"] = ""; - std::string strRequest = Json::writeString(jswBuilder, jvRequest); - - outFile << strRequest << std::endl; - outFile.close(); - return true; -} - - -APP_ERROR ResultToHttpSrvEngine::Process() -{ - int iRet = APP_ERR_OK; - if (0 == MyYaml::GetIns()->GetIntValue("gc_http_open")) - { - LogDebug << " gc_http_open value is 0"; - return APP_ERR_OK; - } - - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - - //无数据大于1分钟 - iNoDataCnt_++; - if (iNoDataCnt_ > (60 * 1000)) - { - DealHttpFailInfo(); - iNoDataCnt_ = 0; - } - continue; - } - iNoDataCnt_ = 0; - - std::shared_ptr pTrain = std::static_pointer_cast(pVoidData0); - - ai_matrix::DataSourceConfig dataSourceConfig = MyYaml::GetIns()->GetDataSourceConfigById(pTrain->trainNum.iDataSource); //获取摄像机参数 - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pTrain->trainNum.iDataSource + 1); - - char szNumImgPath[64] = {0}; //车号最优图片路径 - if (!pTrain->trainNum.strBestImg.empty()) - { - sprintf(szNumImgPath, "/%03d/%s", pTrain->trainNum.iDataSource + 1, pTrain->trainNum.strBestImg.c_str()); - } - - char szProImgPath[64] = {0}; //属性最优图片路径 - if (!pTrain->trainPro.strBestImg.empty()) - { - sprintf(szProImgPath, "/%03d/%s", pTrain->trainPro.iDataSource + 1, pTrain->trainPro.strBestImg.c_str()); - } - - // char szChkDateImgPath[64] = {0}; //定检期最优图片路径 - // if (!pTrain->chkDate.strBestImg.empty()) - // { - // sprintf(szChkDateImgPath, "%03d/%s", pTrain->chkDate.iDataSource + 1, pTrain->chkDate.strBestImg.c_str()); - // } - - // char szContainer1ImgPath[64] = {0}; //集装箱1最优图片路径 - // if (!pTrain->container1.strBestImg.empty()) - // { - // sprintf(szContainer1ImgPath, "%03d/%s", pTrain->container1.iDataSource + 1, pTrain->container1.strBestImg.c_str()); - // } - - // char szContainer2ImgPath[64] = {0}; //集装箱2最优图片路径 - // if (!pTrain->container2.strBestImg.empty()) - // { - // sprintf(szContainer2ImgPath, "%03d/%s", pTrain->container2.iDataSource + 1, pTrain->container2.strBestImg.c_str()); - // } - - std::string strTime = pTrain->strTrainName; - strTime = MyUtils::getins()->replace_all_distinct(strTime, std::string("-"), std::string(":")); - int iCategory = 0; - if (pTrain->trainNum.iTrainTypeId == 3) - { - iCategory = 0; - } - else if(pTrain->trainNum.iTrainTypeId == 2) - { - iCategory = 1; - } - else if (pTrain->trainNum.iTrainTypeId == 6) - { - iCategory = 2; - } - else if (pTrain->trainNum.iTrainTypeId == 0) - { - iCategory = 3; - } - - //组装post信息 - Json::Value jvRequest; - Json::Value jvSubObj; - jvSubObj["poundNo"] = strPoundNo_; // 股道号 - jvRequest["trainParams"] = jvSubObj; - jvRequest["carriageType"] = pTrain->trainNum.strTrainType; // 车型 - jvRequest["carriageNumber"] = pTrain->trainNum.strTrainNum; // 车厢号 - jvRequest["carriageOrder"] = pTrain->iCarXH; // 车节号 - jvRequest["cameraNumber"] = szCameraNo; // 摄像头编号 - jvRequest["carriageTareweight"] = pTrain->trainPro.strSelf; // 皮重 - jvRequest["carriageLoad"] = pTrain->trainPro.strLoad; // 载重 - jvRequest["carriageVolume"] = pTrain->trainPro.strVolume; // 容积 - jvRequest["carriageChangelength"] = pTrain->trainPro.strChange; // 换长 - jvRequest["proImageName"] = strImageSrv_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szProImgPath; // 属性图片 - jvRequest["numImageName"] = strImageSrv_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szNumImgPath; // 车号图片 - jvRequest["comeTime"] = pTrain->strTrainDate + " " + strTime; // 来车时间 - jvRequest["carriageCategory"] = iCategory; // 车厢类别:0敞车,1:漏洞矿车,2:平车,3:车头 - jvRequest["isTheLast"] = pTrain->bIsEnd ? 1 : 0; // 是否最后一节: 0:否,1:是 - jvRequest["startFrame"] = pTrain->iStartFrameId; //车厢开始帧 - jvRequest["endFrame"] = pTrain->iEndFrameId; //车厢结束帧 - jvRequest["skipFrame"] = dataSourceConfig.iSkipInterval; - jvRequest["collectTime"] = MyUtils::getins()->Stamp2Time(pTrain->i64EndTimeStamp, true);//车厢切分的时间 //跳帧 - if (!ResultToHttpSrv(jvRequest)) - { -// SaveHttpFailInfo(jvRequest, strFailSavePath_); - } - - //列车结束后再次处理失败的信息 - if (pTrain->bIsEnd) - { - DealHttpFailInfo(); - } - } - return APP_ERR_OK; -} +#include "ResultToHttpSrvEngine.h" #include "myutils.h" ResultToHttpSrvEngine::ResultToHttpSrvEngine() {} ResultToHttpSrvEngine::~ResultToHttpSrvEngine() {} APP_ERROR ResultToHttpSrvEngine::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strUsername_ = MyYaml::GetIns()->GetStringValue("username"); strPassword_ = MyYaml::GetIns()->GetStringValue("password"); strURL_ = MyYaml::GetIns()->GetStringValue("gc_http_url"); strGetTokenURL_ = MyYaml::GetIns()->GetStringValue("gc_gettoken_url"); strImageSrv_ = MyYaml::GetIns()->GetPathValue("gc_image_srv"); strPoundNo_ = MyYaml::GetIns()->GetStringValue("atlas_poundno"); strFailSavePath_ = MyYaml::GetIns()->GetPathValue("gc_result_path") + "httpfailcontent.csv"; strFailSaveBakPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path") + "httpfailcontent_bak.csv"; LogInfo << "ResultToHttpSrvEngine Init ok"; return APP_ERR_OK; } APP_ERROR ResultToHttpSrvEngine::DeInit() { LogDebug << "curl_easy_cleanup"; curl_easy_cleanup(pCurl_); /* 这个处理移动到main中, 防止多线程调用 LogDebug << "内存清理"; curl_global_cleanup(); */ LogInfo << "ResultToHttpSrvEngine DeInit ok"; return APP_ERR_OK; } /** * libcurl回调函数 * inParam : void *pBuffer 回调内容地址 : size_t size 回调单个数据大小 : size_t nmemb 回调数据个数 * outParam: std::string &strResp 返回内容 * return : 回调数据大小 */ size_t ResultToHttpSrvEngine::WriteCallBack(void *pBuffer, size_t size, size_t nmemb, std::string &strResp) { size_t sizes = size * nmemb; std::string strTemp((char*)pBuffer, sizes); strResp += strTemp; return sizes; } /** * 调用http接口获取token * inParam : * outParam: std::string &strBladeAuth 返回的token信息 * return : true:成功; false:失败 */ bool ResultToHttpSrvEngine::GetToken(std::string &strBladeAuth) { //1. 获得curl操作符 if (nullptr == pCurl_) { LogDebug<<"pCurl_ is null, invoke curl_easy_init"; pCurl_ = curl_easy_init(); if (nullptr == pCurl_) { LogError << "curl_easy_init failed !"; return false; } } //2. 设置head, 和表单 //设置head信息 struct curl_slist *pHeaderList = nullptr; pHeaderList = curl_slist_append(pHeaderList, "Authorization:Basic Y2xpZW50X2VudGVycHJpc2U6Y2xpZW50X2VudGVycHJpc2Vfc2VjcmV0"); //设置表单信息 curl_mime *pMultipart = curl_mime_init(pCurl_); curl_mimepart *pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "username"); curl_mime_data(pPart, strUsername_.c_str(), CURL_ZERO_TERMINATED); pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "password"); curl_mime_data(pPart, strPassword_.c_str(), CURL_ZERO_TERMINATED); pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "tenantId"); curl_mime_data(pPart, "000000", CURL_ZERO_TERMINATED); pPart = curl_mime_addpart(pMultipart); curl_mime_name(pPart, "grant_type"); curl_mime_data(pPart, "password", CURL_ZERO_TERMINATED); curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) curl_easy_setopt(pCurl_, CURLOPT_URL, strGetTokenURL_.c_str()); //设置url curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 curl_easy_setopt(pCurl_, CURLOPT_MIMEPOST, pMultipart); //设置表单 //curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strBody.c_str()); //设置post内容 //curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 std::string strResponse; curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 //3. 执行http请求 CURLcode res = curl_easy_perform(pCurl_); curl_slist_free_all(pHeaderList); //清除headerlist curl_mime_free(pMultipart); //清除curl_mime curl_easy_reset(pCurl_); //重置curl if (res != CURLE_OK) { LogError << " curl_easy_perform fail:" << curl_easy_strerror(res); return false; } //4. 执行成功解析响应内容 Json::CharReaderBuilder readerBuilder; std::shared_ptr reader(readerBuilder.newCharReader()); Json::Value jvResponse; JSONCPP_STRING errs; if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) { LogError << " response content fail " << strResponse; return false; } LogDebug << "GetToken resp:" << strResponse; strBladeAuth += jvResponse["token_type"].asString(); strBladeAuth += " "; strBladeAuth += jvResponse["access_token"].asString(); return true; } /** * 列车信息提交http接口 * inParam : Json::Value &jvRequest 提交内容 * outParam: * return : true:提交成功; false:提交失败 */ bool ResultToHttpSrvEngine::ResultToHttpSrv(Json::Value &jvRequest) { //获取token std::string strBladeAuth("blade-auth:"); if (!GetToken(strBladeAuth)) { LogError << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() << " GetToken fail "; return false; } LogDebug << "strBladeAuth:" << strBladeAuth; //1. 获得curl操作符 if (nullptr == pCurl_) { LogDebug<<"pCurl_ is null, invoke curl_easy_init"; pCurl_ = curl_easy_init(); if (nullptr == pCurl_) { LogError << "curl_easy_init failed !"; return false; } } //2. 设置http请求信息 Json::StreamWriterBuilder jswBuilder; std::string strRequest = Json::writeString(jswBuilder, jvRequest); LogDebug << "to http:" << strRequest; std::string strResponse; struct curl_slist *pHeaderList = nullptr; pHeaderList = curl_slist_append(pHeaderList, "Accept:application/json"); pHeaderList = curl_slist_append(pHeaderList, "Content-Type:application/json"); pHeaderList = curl_slist_append(pHeaderList, "charset:utf-8"); pHeaderList = curl_slist_append(pHeaderList, strBladeAuth.c_str()); curl_easy_setopt(pCurl_, CURLOPT_CONNECTTIMEOUT, 1); //连接超时(1s连接不上服务器返回超时) curl_easy_setopt(pCurl_, CURLOPT_TIMEOUT, 1); // 设置超时时间为1秒 curl_easy_setopt(pCurl_, CURLOPT_URL, strURL_.c_str()); //设置url curl_easy_setopt(pCurl_, CURLOPT_HTTPHEADER, pHeaderList); //设置报文头 curl_easy_setopt(pCurl_, CURLOPT_POSTFIELDS, strRequest.c_str()); //设置post内容 curl_easy_setopt(pCurl_, CURLOPT_POST, 1); //设置操作为POST(为非0表示post) curl_easy_setopt(pCurl_, CURLOPT_WRITEFUNCTION, WriteCallBack); //设置回调函数 curl_easy_setopt(pCurl_, CURLOPT_WRITEDATA, &strResponse); //设置回调参数 //3. 执行http请求 CURLcode res = curl_easy_perform(pCurl_); curl_slist_free_all(pHeaderList); //清除headerlist curl_easy_reset(pCurl_); //重置curl if (res != CURLE_OK) { LogError << "comeTime:" << jvRequest["comeTime"].asString() << " 车节号:" << jvRequest["carriageOrder"].asInt() << " 识别结果上传失败:" << curl_easy_strerror(res); return false; } //4. 执行成功解析响应内容 LogInfo << "http resp:" << strResponse; Json::CharReaderBuilder readerBuilder; std::shared_ptr reader(readerBuilder.newCharReader()); Json::Value jvResponse; JSONCPP_STRING errs; if (!reader->parse(strResponse.data(), strResponse.data() + strResponse.size(), &jvResponse, &errs)) { LogError << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() << " response content fail " << strResponse; return false; } if (!jvResponse["success"].asBool()) { LogError << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() << " response fail"; return false; } LogInfo << "comeTime:" << jvRequest["comeTime"].asString() << " carriageOrder:" << jvRequest["carriageOrder"].asInt() << " post success"; return true; } /** * 处理上传失败的信息 * inParam : N/A * outParam: N/A * return : N/A */ void ResultToHttpSrvEngine::DealHttpFailInfo() { //队列有待处理数据,则先不处理异常数据。 if (inputQueMap_[strPort0_]->getSize() > 0) { LogDebug << "have new data to process"; return; } //文件不存在不处理 if (access(strFailSavePath_.c_str(), F_OK) == -1) { LogDebug << "no exit file:" << strFailSavePath_; return; } bool bAllSucc = true; std::ifstream inFile(strFailSavePath_.c_str(), std::ios::in); if (!inFile.is_open()) { LogError << strFailSavePath_ << " open fail"; return; } int iDealCnt = 0; std::string strLine; while (getline(inFile, strLine)) { Json::CharReaderBuilder jsrBuilder; std::shared_ptr reader(jsrBuilder.newCharReader()); Json::Value jvRequest; JSONCPP_STRING errs; if (!reader->parse(strLine.data(), strLine.data() + strLine.size(), &jvRequest, &errs)) { LogError << "json parse fail content:" << strLine; return; } /* 新数据到达后,异常数据还未开始处理,则直接关闭文件返回。先处理正常数据。 新数据到达后,异常数据处理中,则把异常未处理的数据全部当处理失败写入新文件中。先处理正常数据。 */ if (inputQueMap_[strPort0_]->getSize() > 0) { LogDebug << "Abnormal data processing, have new data to process"; if (0 == iDealCnt) { LogDebug << "Abnormal data processing not start"; inFile.close(); return; } SaveHttpFailInfo(jvRequest, strFailSaveBakPath_); bAllSucc = false; continue; } iDealCnt++; if (!ResultToHttpSrv(jvRequest)) { LogError << "re http post err:" << strLine; //SaveHttpFailInfo(jvRequest, strFailSaveBakPath_); // bAllSucc = false; continue; } } inFile.close(); if(bAllSucc) { //都处理成功,文件删除 remove(strFailSavePath_.c_str()); } else { //部分处理成功,重命名后再次被处理 rename(strFailSaveBakPath_.c_str(), strFailSavePath_.c_str()); } } /** * 保存http上传失败的信息 * inParam : Json::Value &jvRequest http失败信息 * : std::string &strFilePath 保存路径 * outParam: N/A * return : true(成功);false(失败) */ bool ResultToHttpSrvEngine::SaveHttpFailInfo(Json::Value &jvRequest, std::string &strFilePath) { std::ofstream outFile; outFile.open(strFilePath, std::ios::app); if (!outFile.is_open()) { LogError << strFilePath << " open fail"; return false; } Json::StreamWriterBuilder jswBuilder; jswBuilder["indentation"] = ""; std::string strRequest = Json::writeString(jswBuilder, jvRequest); outFile << strRequest << std::endl; outFile.close(); return true; } APP_ERROR ResultToHttpSrvEngine::Process() { int iRet = APP_ERR_OK; if (0 == MyYaml::GetIns()->GetIntValue("gc_http_open")) { LogDebug << " gc_http_open value is 0"; return APP_ERR_OK; } while (!isStop_) { std::shared_ptr pVoidData0 = nullptr; inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); //1ms //无数据大于1分钟 iNoDataCnt_++; if (iNoDataCnt_ > (60 * 1000)) { DealHttpFailInfo(); iNoDataCnt_ = 0; } continue; } iNoDataCnt_ = 0; std::shared_ptr pTrain = std::static_pointer_cast(pVoidData0); ai_matrix::DataSourceConfig dataSourceConfig = MyYaml::GetIns()->GetDataSourceConfigById(pTrain->trainNum.iDataSource); //获取摄像机参数 char szCameraNo[4] = {0}; sprintf(szCameraNo, "%03d", pTrain->trainNum.iDataSource + 1); char szNumImgPath[64] = {0}; //车号最优图片路径 if (!pTrain->trainNum.strBestImg.empty()) { sprintf(szNumImgPath, "/%03d/%s", pTrain->trainNum.iDataSource + 1, pTrain->trainNum.strBestImg.c_str()); } char szProImgPath[64] = {0}; //属性最优图片路径 if (!pTrain->trainPro.strBestImg.empty()) { sprintf(szProImgPath, "/%03d/%s", pTrain->trainPro.iDataSource + 1, pTrain->trainPro.strBestImg.c_str()); } // char szChkDateImgPath[64] = {0}; //定检期最优图片路径 // if (!pTrain->chkDate.strBestImg.empty()) // { // sprintf(szChkDateImgPath, "%03d/%s", pTrain->chkDate.iDataSource + 1, pTrain->chkDate.strBestImg.c_str()); // } // char szContainer1ImgPath[64] = {0}; //集装箱1最优图片路径 // if (!pTrain->container1.strBestImg.empty()) // { // sprintf(szContainer1ImgPath, "%03d/%s", pTrain->container1.iDataSource + 1, pTrain->container1.strBestImg.c_str()); // } // char szContainer2ImgPath[64] = {0}; //集装箱2最优图片路径 // if (!pTrain->container2.strBestImg.empty()) // { // sprintf(szContainer2ImgPath, "%03d/%s", pTrain->container2.iDataSource + 1, pTrain->container2.strBestImg.c_str()); // } std::string strTime = pTrain->strTrainName; strTime = MyUtils::getins()->replace_all_distinct(strTime, std::string("-"), std::string(":")); int iCategory = 0; if (pTrain->trainNum.iTrainTypeId == 3) { iCategory = 0; } else if(pTrain->trainNum.iTrainTypeId == 2) { iCategory = 1; } else if (pTrain->trainNum.iTrainTypeId == 6) { iCategory = 2; } else if (pTrain->trainNum.iTrainTypeId == 0) { iCategory = 3; } //组装post信息 Json::Value jvRequest; Json::Value jvSubObj; jvSubObj["poundNo"] = strPoundNo_; // 股道号 jvRequest["trainParams"] = jvSubObj; jvRequest["carriageType"] = pTrain->trainNum.strTrainType; // 车型 jvRequest["carriageNumber"] = pTrain->trainNum.strTrainNum; // 车厢号 jvRequest["carriageOrder"] = pTrain->iCarXH; // 车节号 jvRequest["cameraNumber"] = szCameraNo; // 摄像头编号 jvRequest["carriageTareweight"] = pTrain->trainPro.strSelf; // 皮重 jvRequest["carriageLoad"] = pTrain->trainPro.strLoad; // 载重 jvRequest["carriageVolume"] = pTrain->trainPro.strVolume; // 容积 jvRequest["carriageChangelength"] = pTrain->trainPro.strChange; // 换长 jvRequest["proImageName"] = strImageSrv_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szProImgPath; // 属性图片 jvRequest["numImageName"] = strImageSrv_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szNumImgPath; // 车号图片 jvRequest["comeTime"] = pTrain->strTrainDate + " " + strTime; // 来车时间 jvRequest["carriageCategory"] = iCategory; // 车厢类别:0敞车,1:漏洞矿车,2:平车,3:车头 jvRequest["isTheLast"] = pTrain->bIsEnd ? 1 : 0; // 是否最后一节: 0:否,1:是 jvRequest["startFrame"] = pTrain->iStartFrameId; //车厢开始帧 jvRequest["endFrame"] = pTrain->iEndFrameId; //车厢结束帧 jvRequest["skipFrame"] = dataSourceConfig.iSkipInterval; jvRequest["collectTime"] = MyUtils::getins()->Stamp2Time(pTrain->i64EndTimeStamp, true);//车厢切分的时间 //跳帧 if (!ResultToHttpSrv(jvRequest)) { // SaveHttpFailInfo(jvRequest, strFailSavePath_); } //列车结束后再次处理失败的信息 if (pTrain->bIsEnd) { DealHttpFailInfo(); } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.cpp b/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.cpp index e291ee3..7fe8970 100644 --- a/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.cpp +++ b/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.cpp @@ -1,187 +1 @@ -#include "DeleteExpiredFolderEngine.h" - -using namespace ai_matrix; - -DeleteExpiredFolderEngine::DeleteExpiredFolderEngine() {} - -DeleteExpiredFolderEngine::~DeleteExpiredFolderEngine() {} - -APP_ERROR DeleteExpiredFolderEngine::Init() -{ - iDaysNumber_ = MyYaml::GetIns()->GetIntValue("gc_days_for_result_expire_folder"); - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - - LogInfo << "DeleteExpiredFolderEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR DeleteExpiredFolderEngine::DeInit() -{ - LogInfo << "DeleteExpiredFolderEngine DeInit ok"; - return APP_ERR_OK; -} - -APP_ERROR DeleteExpiredFolderEngine::Process() -{ - int iRet = APP_ERR_OK; - while (!isStop_) - { - std::string strTrainDate_temp = MyUtils::getins()->GetDate(); - - DeletePreviousFolder(strResultPath_, strTrainDate_temp, iDaysNumber_); - - usleep(1000*1000*3600*24); //每二十四小时执行一次 - } - - return APP_ERR_OK; -} - -void DeleteExpiredFolderEngine::DeletePreviousFolder(std::string path, const std::string &date, int n_days) -{ - // 1 computer date - std::string previous_date = getDateBeforeNDays(date, n_days); - if (!previous_date.empty()) - LogDebug << "Date before " << n_days << " days from " << date << " is: " << previous_date; - - - // 2 - std::vector subfolders; - GetSubfolderNames(path, subfolders); - // for (const auto &it : subfolders) - // std::cout << it.year << "." << it.month << "." << it.day << std::endl; - - // 3 delete - if (path.back() != '/') - path += "/"; - Date reference_date = StrToDate(previous_date); // 给定的参考日期 - DeleteEarlierDatesFolder(path, subfolders, reference_date); -} - -// 获取某月有多少天 -int DeleteExpiredFolderEngine::DaysInMonth(int year, int month) -{ - int max_days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; - if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) - { - max_days[2] = 29; // 闰年2月有29天 - } - return max_days[month]; -} - -// 解析字符串为日期结构体 -Date DeleteExpiredFolderEngine::StrToDate(const std::string &date_str) -{ - std::istringstream iss(date_str); - int year, month, day; - char dash; - - if (!(iss >> year >> dash && dash == '-' && - iss >> month >> dash && dash == '-' && - iss >> day)) - { - LogError << ("Invalid date format") << ":" << date_str; - } - return {year, month, day}; -} - -// 减去指定天数 -void DeleteExpiredFolderEngine::SubtractDays(Date &date, int n_days) -{ - while (n_days > 0) - { - date.day--; - n_days--; - if (date.day == 0) - { - if (--date.month == 0) - { - --date.year; - date.month = 12; - } - int max_days = DaysInMonth(date.year, date.month); - date.day = max_days; - } - } -} - -// 格式化日期结构体为字符串 -std::string DeleteExpiredFolderEngine::DateToStr(const Date &date) -{ - std::ostringstream oss; - oss << date.year << "-" << std::setfill('0') << std::setw(2) << date.month << "-" << std::setw(2) << date.day; - return oss.str(); -} - -// 主要功能函数,接收一个日期字符串和一个整数n,返回n天前的日期字符串 -std::string DeleteExpiredFolderEngine::getDateBeforeNDays(const std::string &input_date, int n_days) -{ - try - { - Date date = StrToDate(input_date); - SubtractDays(date, n_days); - return DateToStr(date); - } - catch (const std::exception &e) - { - LogError << "Error: " << e.what(); - return ""; - } -} - -void DeleteExpiredFolderEngine::GetSubfolderNames(std::string &directory, std::vector &folder_names) -{ - if (directory.back() != '/') - directory += "/"; - DIR *dir; - struct dirent *ent; - if ((dir = opendir(directory.c_str())) != nullptr) - { - while ((ent = readdir(dir)) != nullptr) - { - // 排除"."和".." - if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && ent->d_name != "best") - { - folder_names.push_back(StrToDate(ent->d_name)); - } - } - closedir(dir); - } - else - { - LogError << "Unable to open directory: " << directory; - } -} - -void DeleteExpiredFolderEngine::DeleteFolder(const std::string directory) -{ - std::string command = "rm -rf " + directory; - int result = system(command.c_str()); - - if (result != 0) - LogError << "Failed to remove directory recursively: " << directory; - else - LogError << "delete folder successfully : " << directory; -} - -// 删除向量中小于指定日期的所有元素 -void DeleteExpiredFolderEngine::DeleteEarlierDatesFolder(std::string &path, std::vector &subfolders, const Date &reference_date) -{ - if (path.back() != '/') - path += "/"; - for (const Date &cur : subfolders) - { - // bool flag = false; - if (cur.year < reference_date.year) - { - DeleteFolder(path + DateToStr(cur)); - } - else if (cur.year == reference_date.year && cur.month < reference_date.month) - { - DeleteFolder(path + DateToStr(cur)); - } - else if (cur.year == reference_date.year && cur.month == reference_date.month && cur.day < reference_date.day) - { - DeleteFolder(path + DateToStr(cur)); - } - } -} \ No newline at end of file +#include "DeleteExpiredFolderEngine.h" using namespace ai_matrix; DeleteExpiredFolderEngine::DeleteExpiredFolderEngine() {} DeleteExpiredFolderEngine::~DeleteExpiredFolderEngine() {} APP_ERROR DeleteExpiredFolderEngine::Init() { iDaysNumber_ = MyYaml::GetIns()->GetIntValue("gc_days_for_result_expire_folder"); strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); strLogBakPath_ = MyYaml::GetIns()->GetPathValue("gc_log_logfile_bakpath"); LogInfo << "DeleteExpiredFolderEngine Init ok"; return APP_ERR_OK; } APP_ERROR DeleteExpiredFolderEngine::DeInit() { LogInfo << "DeleteExpiredFolderEngine DeInit ok"; return APP_ERR_OK; } APP_ERROR DeleteExpiredFolderEngine::Process() { int iRet = APP_ERR_OK; while (!isStop_) { std::string strTrainDate_temp = MyUtils::getins()->GetDate(); DeletePreviousFolder(strResultPath_, strTrainDate_temp, iDaysNumber_); // DeletePreviousFolder(strLogBakPath_, strTrainDate_temp, iDaysNumber_); usleep(1000*1000*10); //每10秒执行一次 } return APP_ERR_OK; } void DeleteExpiredFolderEngine::DeletePreviousFolder(std::string path, const std::string &date, int n_days) { // 1 computer date std::string previous_date = getDateBeforeNDays(date, n_days); if (!previous_date.empty()) std::cout << "Date before " << n_days << " days from " << date << " is: " << previous_date << std::endl; // 2 std::vector subfolders; GetSubfolderNames(path, subfolders); // for (const auto &it : subfolders) // std::cout << it.year << "." << it.month << "." << it.day << std::endl; // 3 delete if (path.back() != '/') path += "/"; Date reference_date = StrToDate(previous_date); // 给定的参考日期 DeleteEarlierDatesFolder(path, subfolders, reference_date); } // 获取某月有多少天 int DeleteExpiredFolderEngine::DaysInMonth(int year, int month) { int max_days[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) { max_days[2] = 29; // 闰年2月有29天 } return max_days[month]; } // 解析字符串为日期结构体 Date DeleteExpiredFolderEngine::StrToDate(const std::string &date_str) { std::istringstream iss(date_str); int year, month, day; char dash; if (!(iss >> year >> dash && dash == '-' && iss >> month >> dash && dash == '-' && iss >> day)) { LogError << ("Invalid date format") << ":" << date_str; } return {year, month, day}; } // 减去指定天数 void DeleteExpiredFolderEngine::SubtractDays(Date &date, int n_days) { while (n_days > 0) { date.day--; n_days--; if (date.day == 0) { if (--date.month == 0) { --date.year; date.month = 12; } int max_days = DaysInMonth(date.year, date.month); date.day = max_days; } } } // 格式化日期结构体为字符串 std::string DeleteExpiredFolderEngine::DateToStr(const Date &date) { std::ostringstream oss; oss << date.year << "-" << std::setfill('0') << std::setw(2) << date.month << "-" << std::setw(2) << date.day; return oss.str(); } // 主要功能函数,接收一个日期字符串和一个整数n,返回n天前的日期字符串 std::string DeleteExpiredFolderEngine::getDateBeforeNDays(const std::string &input_date, int n_days) { try { Date date = StrToDate(input_date); SubtractDays(date, n_days); return DateToStr(date); } catch (const std::exception &e) { LogError << "Error: " << e.what(); return ""; } } void DeleteExpiredFolderEngine::GetSubfolderNames(std::string &directory, std::vector &folder_names) { if (directory.back() != '/') directory += "/"; DIR *dir; struct dirent *ent; if ((dir = opendir(directory.c_str())) != nullptr) { while ((ent = readdir(dir)) != nullptr) { // 排除"."和".." if (ent->d_type == DT_DIR && ent->d_name[0] != '.' && ent->d_name != "best") { folder_names.push_back(StrToDate(ent->d_name)); } } closedir(dir); } else { LogError << "Unable to open directory: " << directory; } } void DeleteExpiredFolderEngine::DeleteFolder(const std::string directory) { std::string command = "rm -rf " + directory; int result = system(command.c_str()); if (result != 0) std::cout << "Failed to remove directory recursively: " << directory << std::endl; else std::cout << "delete folder successfully : " << directory << std::endl; } // 删除向量中小于指定日期的所有元素 void DeleteExpiredFolderEngine::DeleteEarlierDatesFolder(std::string &path, std::vector &subfolders, const Date &reference_date) { if (path.back() != '/') path += "/"; for (const Date &cur : subfolders) { // bool flag = false; if (cur.year < reference_date.year) { DeleteFolder(path + DateToStr(cur)); } else if (cur.year == reference_date.year && cur.month < reference_date.month) { DeleteFolder(path + DateToStr(cur)); } else if (cur.year == reference_date.year && cur.month == reference_date.month && cur.day < reference_date.day) { DeleteFolder(path + DateToStr(cur)); } } } // void DeleteExpiredFolderEngine::PushData(const std::string &strPort, const std::shared_ptr &pSaveImgData) // { // while (true) // { // int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pSaveImgData)); // if (iRet != 0) // { // LogDebug << "sourceid:" << pSaveImgData->iDataSource << " frameid:" << pSaveImgData->iFrameId << " push fail iRet:" << iRet; // if (iRet == 2) // { // usleep(10000); // 10ms // continue; // } // } // break; // } // } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.h b/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.h index 8c808e0..fa4597c 100644 --- a/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.h +++ b/nvidia_ascend_engine/common_engine/DeleteExpiredFolderEngine/DeleteExpiredFolderEngine.h @@ -48,6 +48,7 @@ private: private: std::string strResultPath_; + std::string strLogBakPath_; int iDaysNumber_; }; diff --git a/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.cpp b/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.cpp index 6f7100d..f480688 100644 --- a/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.cpp +++ b/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.cpp @@ -1,1069 +1 @@ -#include "FilterTrainStepOneEngine.h" -#include "myutils.h" - -using namespace ai_matrix; - -namespace -{ - //按照x坐标排列 - bool CompareX(const PostSubData &a, const PostSubData &b) - { - return a.step1Location.fLTX < b.step1Location.fLTX; - } -} - -extern std::atomic_uint64_t g_i64ReRunTimeStamp; -extern std::atomic_uint32_t g_iReRunOrigFrameId; -extern std::atomic_uint32_t g_iReRunFrameId; -extern std::atomic_uint32_t g_iReRunOrigChkDateFid; -extern std::atomic_uint32_t g_iReRunOrigContainerFid; - -FilterTrainStepOneEngine::FilterTrainStepOneEngine() {} - -FilterTrainStepOneEngine::~FilterTrainStepOneEngine() {} - -APP_ERROR FilterTrainStepOneEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - iChkStopPX_ = MyYaml::GetIns()->GetIntValue("gc_chkstop_px"); - iChkStopCount_ = MyYaml::GetIns()->GetIntValue("gc_chkstop_count"); - iPartitionFrameNum_ = MyYaml::GetIns()->GetIntValue("partition_frame_span"); - iPlitFrameSpanPX_ = MyYaml::GetIns()->GetIntValue("gc_split_frame_span_px"); - iPushDirection_ = MyYaml::GetIns()->GetIntValue("gc_push_direction"); - - //获取主摄像头信息 - mainCfg_ = MyYaml::GetIns()->GetDataSourceConfigById(0); - - std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); - for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) - { - this->rightFirst_ = iter->second.iRightFirst; - this->leftFirst_ = iter->second.iLeftFirst; - if (iter->second.strTarget.find("NUM") != std::string::npos) - { - LogDebug << "DataSource:" << iter->first << " deal NUM"; - mapHeadContinueCnt_[iter->first] = 0; - mapProContinueCnt_[iter->first] = 0; - mapNumContinueCnt_[iter->first] = 0; - mapSpaceContinueCnt_[iter->first] = 0; - mapTrainSpaceContinueCnt_[iter->first] = 0; - mapDataSourceIsEnd_[iter->first] = false; - - PostData postDataTemp; - mapPostDataFrist_[iter->first] = postDataTemp; - std::map> mapStep1InfoTemp; //[key-目标框id, 目标框坐标集合] - mapMapStep1Info_[iter->first] = mapStep1InfoTemp; - } - } - - mapTargetStr_.insert(std::make_pair(NUM, "NUM")); - mapTargetStr_.insert(std::make_pair(PRO, "PRO")); - mapTargetStr_.insert(std::make_pair(HEAD, "HEAD")); - mapTargetStr_.insert(std::make_pair(SPACE, "SPACE"));//SPACE - mapTargetStr_.insert(std::make_pair(TRAINSPACE, "SPACE"));//SPACE - - InitParam(); - LogInfo << "FilterTrainStepOneEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR FilterTrainStepOneEngine::DeInit() -{ - LogInfo << "FilterTrainStepOneEngine DeInit ok"; - return APP_ERR_OK; -} - - -/** -* 参数初始化(列车结束时需调用) -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void FilterTrainStepOneEngine::InitParam() -{ - mapProcessDataPre_.clear(); - for (auto iter = mapHeadContinueCnt_.begin(); iter != mapHeadContinueCnt_.end(); iter++) - { - iter->second = 0; - } - for (auto iter = mapProContinueCnt_.begin(); iter != mapProContinueCnt_.end(); iter++) - { - iter->second = 0; - } - for (auto iter = mapNumContinueCnt_.begin(); iter != mapNumContinueCnt_.end(); iter++) - { - iter->second = 0; - } - for (auto iter = mapSpaceContinueCnt_.begin(); iter != mapSpaceContinueCnt_.end(); iter++) - { - iter->second = 0; - } - for (auto iter = mapTrainSpaceContinueCnt_.begin(); iter != mapTrainSpaceContinueCnt_.end(); iter++) - { - iter->second = 0; - } - for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) - { - iter->second = false; - } - for (auto iter = mapPostDataFrist_.begin(); iter != mapPostDataFrist_.end(); iter++) - { - iter->second.vecPostSubData.clear(); - } - for (auto iter = mapMapStep1Info_.begin(); iter != mapMapStep1Info_.end(); iter++) - { - iter->second.clear(); - } - iDirection_ = DIRECTION_UNKNOWN; - iNotChgCount_ = 0; - - while (!stackBackInfo_.empty()) - { - stackBackInfo_.pop(); - } - while (!quePostData_.empty()) - { - quePostData_.pop(); - } - iTrainStatus_ = TRAINSTATUS_RUN; - - mapCalDirection_.clear(); -} - -/** -* push数据到队列,队列满时则休眠一段时间再push -* inParam : const std::string strPort push的端口 - : const std::shared_ptr &pProcessData push的数据 -* outParam: N/A -* return : N/A -*/ -void FilterTrainStepOneEngine::PushData(const std::string &strPort, const std::shared_ptr &pProcessData) -{ - while (true) - { - int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pProcessData)); - if (iRet != 0) - { - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet; - if (iRet == 2) - { - usleep(10000); // 10ms - continue; - } - } - break; - } -} - -void FilterTrainStepOneEngine::AddBackInfo(std::shared_ptr pProcessData) -{ - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - std::sort(pPostData->vecPostSubData.begin(), pPostData->vecPostSubData.end(), CompareX); - - std::string strAllClassType; - for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) - { - if (strAllClassType.find(mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]) != std::string::npos) - { - continue; - } - strAllClassType += mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]; - } - - if (strAllClassType.empty()) - { - return; - } - LogDebug << "frameId:" << pProcessData->iFrameId << " addbackinfo strAllClassType:" << strAllClassType; - - TrainBackInfo trainBackInfo; - trainBackInfo.processData = pProcessData; - trainBackInfo.strAllClassType = strAllClassType; - if (stackBackInfo_.empty()) - { - stackBackInfo_.push(trainBackInfo); - LogDebug << "frameId:" << pProcessData->iFrameId << " push strAllClassType:" << strAllClassType - << " stacksize:" << stackBackInfo_.size(); - } - else - { - TrainBackInfo trainBackInfoTop = stackBackInfo_.top(); - - if (trainBackInfoTop.strAllClassType != trainBackInfo.strAllClassType) - { - if (iDirection_ == DIRECTION_RIGHT - && this->rightFirst_ == RIGHT_RUN_AND_PRO_FIRST - && ((trainBackInfo.strAllClassType == "SPACE" - && (trainBackInfoTop.strAllClassType == "PROSPACE" || trainBackInfoTop.strAllClassType == "SPACEPRO")) - || (trainBackInfo.strAllClassType == "NUM" - && (trainBackInfoTop.strAllClassType == "NUMSPACE" || trainBackInfoTop.strAllClassType == "SPACENUM")))) - { - return; - } - if (iDirection_ == DIRECTION_RIGHT - && this->rightFirst_ == RIGHT_RUN_AND_NUM_FIRST - && ((trainBackInfo.strAllClassType == "SPACE" - && (trainBackInfoTop.strAllClassType == "NUMSPACE" || trainBackInfoTop.strAllClassType == "SPACENUM")) - || (trainBackInfo.strAllClassType == "PRO" - && (trainBackInfoTop.strAllClassType == "PROSPACE" || trainBackInfoTop.strAllClassType == "SPACEPRO")))) - { - return; - } - - if (iDirection_ == DIRECTION_LEFT - && this->rightFirst_ == RIGHT_RUN_AND_NUM_FIRST - && ((trainBackInfo.strAllClassType == "SPACE" - && (trainBackInfoTop.strAllClassType == "NUMSPACE" || trainBackInfoTop.strAllClassType == "SPACENUM")) - || (trainBackInfo.strAllClassType == "PRO" - && (trainBackInfoTop.strAllClassType == "PROSPACE" || trainBackInfoTop.strAllClassType == "SPACEPRO")))) - { - return; - } - if (iDirection_ == DIRECTION_LEFT - && this->rightFirst_ == RIGHT_RUN_AND_PRO_FIRST - && ((trainBackInfo.strAllClassType == "SPACE" - && (trainBackInfoTop.strAllClassType == "PROSPACE" || trainBackInfoTop.strAllClassType == "SPACEPRO")) - || (trainBackInfo.strAllClassType == "NUM" - && (trainBackInfoTop.strAllClassType == "NUMSPACE" || trainBackInfoTop.strAllClassType == "SPACENUM")))) - { - return; - } - stackBackInfo_.push(trainBackInfo); - LogDebug << "frameId:" << pProcessData->iFrameId << " push strAllClassType:" << strAllClassType - << " stacksize:" << stackBackInfo_.size(); - } - } -} - -bool FilterTrainStepOneEngine::IsEndDealBackInfo(std::shared_ptr pProcessData) -{ - if (stackBackInfo_.empty()) - { - return true; - } - - bool bPopFlag = false; - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - if (pPostData->vecPostSubData.size() == 0) return false; - - /* - 处理倒车数据时,数据需设置为倒车,主要是保证这样的数据后面Engine不处理,防止切分车厢出错。 - - 类型不相等时,就pop,当pop后,还剩一个数据时,则表示已经回到了刚开始倒车的地方。(只剩一个数据的逻辑在上方) - - 处理最后一个时,不能只判断下类型相同就弹出。需要控制下位置。(要么类型相同位置合适,要么类型不相同) - 正向为向左行驶,则当前数据的位置尽量小于等于栈中最后一个元素的位置。 - 正向为向右行驶,则当前数据的位置尽量大于等于栈中最后一个元素的位置。 - */ - std::sort(pPostData->vecPostSubData.begin(), pPostData->vecPostSubData.end(), CompareX); - - std::string strAllClassType; - for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) - { - if (strAllClassType.find(mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]) != std::string::npos) - { - continue; - } - strAllClassType += mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]; - } - if (strAllClassType.empty()) - { - return false; - } - - if (stackBackInfo_.size() == 1) - { - TrainBackInfo trainBackInfoLast = stackBackInfo_.top(); - std::shared_ptr pPostDataBack = std::static_pointer_cast(trainBackInfoLast.processData->pVoidData); - std::sort(pPostDataBack->vecPostSubData.begin(), pPostDataBack->vecPostSubData.end(), CompareX); - - for (size_t i = 0; i < pPostDataBack->vecPostSubData.size(); i++) - { - int bFlag = -1; - for (size_t j = 0; j < pPostData->vecPostSubData.size(); j++) - { - if (pPostDataBack->vecPostSubData[i].iBigClassId == pPostData->vecPostSubData[j].iBigClassId) - { - if (pPostData->vecPostSubData[j].step1Location.fLTX < 1 || pPostDataBack->vecPostSubData[i].step1Location.fLTX < 1) - { - LogDebug << "大框X坐标小于1,判定为异常大框。过滤!!"; - break; - } - bFlag = (pPostDataBack->vecPostSubData[i].step1Location.fLTX <= pPostData->vecPostSubData[j].step1Location.fLTX) ? 1 : 0; - LogDebug << "帧:" << pProcessData->iFrameId << " 倒车前帧:" << pPostDataBack->iFrameId << " 恢复到原位:" << bFlag - << " 当前框位置:" << pPostData->vecPostSubData[i].step1Location.fLTX - << " 倒车前位置:" << pPostDataBack->vecPostSubData[i].step1Location.fLTX << "方向:" << iDirection_; - } - } - - if ((iDirection_ == DIRECTION_LEFT && bFlag == 0) || - (iDirection_ == DIRECTION_RIGHT && bFlag == 1)) - { - bPopFlag = true; - break; - } - } - - if (bPopFlag) - { - LogDebug << "frameId:" << pProcessData->iFrameId << " 恢复倒车前的位置:" << bPopFlag; - stackBackInfo_.pop(); - } - } - else - { - TrainBackInfo trainBackInfoTop_bak = stackBackInfo_.top(); - stackBackInfo_.pop(); - TrainBackInfo trainBackInfoTop = stackBackInfo_.top(); - - if (trainBackInfoTop.strAllClassType != strAllClassType) - { - stackBackInfo_.push(trainBackInfoTop_bak); - LogDebug << "帧:" << pProcessData->iFrameId << " 倒车信息:" << stackBackInfo_.size() - << " 顶部倒车信息:" << trainBackInfoTop.strAllClassType << " 本次识别信息:" << strAllClassType; - } - else - { -// bPopFlag = true; - LogDebug << "帧:" << pProcessData->iFrameId << " 倒车信息:" << stackBackInfo_.size() - << " 顶部倒车信息:" << trainBackInfoTop.strAllClassType << " 本次识别信息:" << strAllClassType - << " 删除倒车信息:" << trainBackInfoTop_bak.strAllClassType; - } - - -// if(bPopFlag) -// { -// stackBackInfo_.pop(); -// bPopFlag = false; -// } - } - - return stackBackInfo_.empty() ? true : false; -} - -/** -* 校验火车是否停止 -* inParam : std::shared_ptr pProcessData :待处理数据 -* outParam: N/A -* return : true:停止; false:非停止 1(正常行驶) 2(停车) 3(倒车) -*/ -int FilterTrainStepOneEngine::GetTrainStatus(std::shared_ptr pProcessData) -{ - if (iDirection_ == DIRECTION_UNKNOWN) - { - LogDebug << " frameId:" << pProcessData->iFrameId << " 未判断出行车方向,暂定认为火车正常行驶中"; - return TRAINSTATUS_RUN; - } - - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - pPostData->iFrameId = pProcessData->iFrameId; - - // 1. 无框时,返回之前的列车状态 - if (pPostData->vecPostSubData.size() == 0) - { - return iTrainStatus_; - } - - quePostData_.push(*pPostData.get()); - - if (quePostData_.size() < 3) - { - return TRAINSTATUS_RUN; - } - - PostData postDataFront = quePostData_.front(); - //iNotChgCount_大于0表示有可能停车,此时pop队列数据要多留存几个。用最开始的数据来判断是否真正停车,如果每次只用上上帧判断当列车超级慢时可能判断为停车。 - int iSizeTemp = iNotChgCount_ > 0 ? 10 : 2; - while (quePostData_.size() > iSizeTemp) - { - quePostData_.pop(); - } - LogDebug << "frameId:" << pProcessData->iFrameId << " 判断运动状态队列 第一帧:" << postDataFront.iFrameId << " 队列size:" << quePostData_.size() << " iSizeTemp:" << iSizeTemp; - - bool bSameFlag = false; - int iDiffValue = iChkStopPX_; - for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) - { - PostSubData postSubDataBack = pPostData->vecPostSubData[i]; - for (size_t j = 0; j < postDataFront.vecPostSubData.size(); j++) - { - PostSubData postSubDataFront = postDataFront.vecPostSubData[j]; - /* - 使用iBigClassId,可能出现平车只有间隔大框,且间隔大框可以一会是平车间隔,一会是通用间隔。导致类别不一样 - 使用iTargetType,可能出现平车只有间隔大框,且间隔大框可以一会是平车间隔,一会是通用间隔。导致像素差判断不准。 - */ - if (postSubDataFront.iTargetType != postSubDataBack.iTargetType) - { - LogDebug << "判断前后帧识别的是否一致 上一个:" << postSubDataFront.iTargetType << " 当前:" << postSubDataBack.iTargetType; - continue; - } - - // if (postSubDataFront.iTargetType == SPACE && postSubDataFront.iBigClassId != postSubDataBack.iBigClassId) - // { - // iDiffValue = 50; - // } - - bSameFlag = true; - int iCenterBack = postSubDataBack.step1Location.fLTX + (postSubDataBack.step1Location.fRBX - postSubDataBack.step1Location.fLTX) / 2; - int iCenterFront = postSubDataFront.step1Location.fLTX + (postSubDataFront.step1Location.fRBX - postSubDataFront.step1Location.fLTX) / 2; - - //位置比较大于10个像素,则表示有移动。再判断时正向移动,还是倒车 - LogDebug << "frameId:" << pProcessData->iFrameId << " " << iCenterBack << "-" << iCenterFront - << "=" << abs(iCenterBack - iCenterFront) << " 预期判定移动的差值为iDiffValue:" << iDiffValue; - if (abs(iCenterBack - iCenterFront) > iDiffValue) - { - iNotChgCount_ = 0; - /* - iCenterBack > iCenterFront 表示向右行驶,且原方向为向左行驶 - iCenterBack < iCenterFront 表示向左行驶,且原方向为向右行驶 - 以上2种表示倒车。 - */ - if ((iCenterBack > iCenterFront && iDirection_ == DIRECTION_LEFT) || - (iCenterBack < iCenterFront && iDirection_ == DIRECTION_RIGHT)) - { - if (this->iPartitionFrameNum_ < (pProcessData->iFrameId - postDataFront.iFrameId) - && this->iPlitFrameSpanPX_ < abs(iCenterBack - iCenterFront)) - { - return TRAINSTATUS_RUN; - } - LogDebug << "frameId:" << pProcessData->iFrameId << " 检测到火车倒车"; - return TRAINSTATUS_BACK; - } - else - { - LogDebug << "frameId:" << pProcessData->iFrameId << " 正常行驶"; - return TRAINSTATUS_RUN; - } - } - /* - 小于10个像素表示可能停车,累计未变化次数。 - 累计变化次数超过10次,返回停车 - 累计变化次数未超过10次,返回之前行驶状态 - */ - else - { - iNotChgCount_++; - LogDebug << " frameId:" << pProcessData->iFrameId - << " 大框移动范围小 判断停车计数:" << iNotChgCount_ << "/" << iChkStopCount_; - if (iNotChgCount_ > iChkStopCount_) - { - LogDebug << "frameId:" << pProcessData->iFrameId << " 检测到火车停车"; - return TRAINSTATUS_STOP; - } - else - { -// LogDebug << "frameId:" << pProcessData->iFrameId << " iTrainStatus_:" << iTrainStatus_; - return iTrainStatus_; - } - } - } - } - - /* - 未找到相同的框,说明是老框消失掉了,新框出现了。 - 按新框出现的位置判断是向左行驶,还是向右行驶。 - */ - LogDebug << "frameId:" << pProcessData->iFrameId << " bSameFlag:" << bSameFlag; - if (!bSameFlag) - { - std::sort(pPostData->vecPostSubData.begin(), pPostData->vecPostSubData.end(), CompareX); - Step1Location step1Location = pPostData->vecPostSubData.front().step1Location; - if (iDirection_ == DIRECTION_LEFT) - { - step1Location = pPostData->vecPostSubData.back().step1Location; - } - LogDebug << "frameId:" << pProcessData->iFrameId << " fLTX:" << step1Location.fLTX << " fRBX:" << step1Location.fRBX; - - iNotChgCount_ = 0; - int iCenter = step1Location.fLTX + (step1Location.fRBX - step1Location.fLTX) / 2; - int iValue = pProcessData->iWidth / 2; - if ((iCenter > iValue && iDirection_ == DIRECTION_RIGHT) || - (iCenter < iValue && iDirection_ == DIRECTION_LEFT)) - { - /* - 针对有效帧较少时,和上上帧比较没有同类型大框,且当前帧已行驶到画面中心导致误判的情况, - 增加和上帧同类型大框的比较处理。 - */ - PostData postDataMiddle = quePostData_.front(); - for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) - { - PostSubData postSubDataBack = pPostData->vecPostSubData[i]; - for (size_t j = 0; j < postDataMiddle.vecPostSubData.size(); j++) - { - PostSubData postSubDataMiddle = postDataMiddle.vecPostSubData[j]; - if (postSubDataMiddle.iTargetType != postSubDataBack.iTargetType) - { - continue; - } - int iCenterBack = postSubDataBack.step1Location.fLTX + (postSubDataBack.step1Location.fRBX - postSubDataBack.step1Location.fLTX) / 2; - int iCenterMiddle = postSubDataMiddle.step1Location.fLTX + (postSubDataMiddle.step1Location.fRBX - postSubDataMiddle.step1Location.fLTX) / 2; - - // 位置比较大于10个像素,则表示有移动。再判断时正向移动,还是倒车 - LogDebug << "frameId:" << pProcessData->iFrameId << " " << iCenterBack << "-" << iCenterMiddle - << "=" << abs(iCenterBack - iCenterMiddle) << " middle cmp iDiffValue:" << iDiffValue; - if (abs(iCenterBack - iCenterMiddle) > iDiffValue) - { - if ((iCenterBack > iCenterMiddle && iDirection_ == DIRECTION_LEFT) || - (iCenterBack < iCenterMiddle && iDirection_ == DIRECTION_RIGHT)) - { - LogDebug << "frameId:" << pProcessData->iFrameId << " back2 back2"; - return TRAINSTATUS_BACK; - } - else - { - LogDebug << "frameId:" << pProcessData->iFrameId << " run"; - return TRAINSTATUS_RUN; - } - } - } - } - -// LogDebug << "frameId:" << pProcessData->iFrameId << " back2"; - return iTrainStatus_; - } - } - LogDebug << "frameId:" << pProcessData->iFrameId << " iNotChgCount_:" << iNotChgCount_ << " run run"; - return TRAINSTATUS_RUN; -} - -/** -* 设置行车方向 -* inParam : std::vector &vecLocation :大框坐标集合 - : std::shared_ptr pProcessData :待处理数据 -* outParam: N/A -* return : N/A -*/ -void FilterTrainStepOneEngine::SetDirection(std::vector &vecLocation, std::shared_ptr pProcessData) -{ - if (vecLocation.size() < 1) - { - return; - } - Step1Location slFront = vecLocation.front(); - Step1Location slBack = vecLocation.back(); - /* - 移动距离小于50个像素,则判断最后一个框的出现的位置 - */ - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " slFront:" << slFront.fLTX << " slBack:" << slBack.fLTX; - if (fabs(slBack.fLTX - slFront.fLTX) < 50) - { - float fTempX1 = pProcessData->iWidth / 5; //5分之1的X坐标 - float fTempX2 = pProcessData->iWidth / 5 * 4; //5分之4的X坐标 - - if (slBack.fLTX < fTempX1) - { - iDirection_ = DIRECTION_LEFT; - } - else if (slBack.fRBX > fTempX2) - { - iDirection_ = DIRECTION_RIGHT; - } - } - else - { - //行驶方向 左 - if ((slBack.fLTX - slFront.fLTX) < 0) - { - iDirection_ = DIRECTION_LEFT; - } - //行驶方向 右 - else if ((slBack.fLTX - slFront.fLTX) > 0) - { - iDirection_ = DIRECTION_RIGHT; - } - } - - //未判断出移动方向,清除数后重新计算。 - if (iDirection_ == DIRECTION_UNKNOWN) - { - auto iterMapStep1Info = mapMapStep1Info_.find(pProcessData->iDataSource); - iterMapStep1Info->second.clear(); - } - else - { - if (MyYaml::GetIns()->GetDataSourceConfigById(pProcessData->iDataSource).iLeftFirst != mainCfg_.iLeftFirst) - { - LogDebug << "before sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; - iDirection_ = (iDirection_ == DIRECTION_LEFT) ? DIRECTION_RIGHT : DIRECTION_LEFT; - LogDebug << "after sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; - } - } -} - -/** -* 计算行车方向新 -* inParam : std::shared_ptr pProcessData :待处理数据 -* outParam: N/A -* return : N/A -*/ -void FilterTrainStepOneEngine::CalculateDirectionNew(std::shared_ptr pProcessData) -{ - /* - 连续3帧同目标识别框信息 - 判断位置差异是否超过10px(判停车参数),且两两之间都是线性。如果符合则计算方向。 - 上述条件不符合则剔除第一个元素,再次累计连续3帧处理。 - */ - auto iterMap = mapCalDirection_.find(pProcessData->iDataSource); - if (iterMap == mapCalDirection_.end()) - { - std::map> mapTemp; - mapCalDirection_.insert(std::make_pair(pProcessData->iDataSource, mapTemp)); - iterMap = mapCalDirection_.find(pProcessData->iDataSource); - } - - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - for (auto iter = pPostData->vecPostSubData.begin(); iter != pPostData->vecPostSubData.end(); iter++) - { - CalculateInfo calInfo; - calInfo.iFrameId = pProcessData->iFrameId; - calInfo.iBigClassId = iter->iCarXH; - calInfo.fCenterX = iter->step1Location.fLTX + (iter->step1Location.fRBX - iter->step1Location.fLTX) / 2; - - auto iterSubMap = iterMap->second.find(iter->iBigClassId); - if (iterSubMap == iterMap->second.end()) - { - std::vector vecTemp; - iterMap->second.insert(std::make_pair(iter->iBigClassId, vecTemp)); - iterSubMap = iterMap->second.find(iter->iBigClassId); - } - iterSubMap->second.emplace_back(calInfo); - - if (iterSubMap->second.size() > 2) - { - LogDebug << "souceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId - << " last:" << iterSubMap->second.at(2).iFrameId << " " << iterSubMap->second.at(2).fCenterX - << " mid:" << iterSubMap->second.at(1).iFrameId << " " << iterSubMap->second.at(1).fCenterX - << " pre:" << iterSubMap->second.at(0).iFrameId << " " << iterSubMap->second.at(0).fCenterX; - //如果帧号连续,且移动位置大于15px,则计算方向 - if (iterSubMap->second.at(2).iFrameId - iterSubMap->second.at(1).iFrameId != mainCfg_.iSkipInterval || - iterSubMap->second.at(1).iFrameId - iterSubMap->second.at(0).iFrameId != mainCfg_.iSkipInterval) - { - iterSubMap->second.erase(iterSubMap->second.begin()); - continue; - } - - int iLast = iterSubMap->second.at(2).fCenterX; - int iMid = iterSubMap->second.at(1).fCenterX; - int iPre = iterSubMap->second.at(0).fCenterX; - if (abs(iPre - iLast) <= iChkStopPX_) - { - iterSubMap->second.erase(iterSubMap->second.begin()); - continue; - } - if (iPre <= iMid && iMid <= iLast) - { - iDirection_ = DIRECTION_RIGHT; - } - else if (iPre >= iMid && iMid >= iLast) - { - iDirection_ = DIRECTION_LEFT; - } - else - { - iterSubMap->second.erase(iterSubMap->second.begin()); - continue; - } - - LogDebug << "souceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " iDirection_:" << iDirection_; - } - } - - //主相机的对侧相机需反向设置方向 - if (iDirection_ != DIRECTION_UNKNOWN && MyYaml::GetIns()->GetDataSourceConfigById(pProcessData->iDataSource).iLeftFirst != mainCfg_.iLeftFirst) - { - LogDebug << "before sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; - iDirection_ = (iDirection_ == DIRECTION_LEFT) ? DIRECTION_RIGHT : DIRECTION_LEFT; - LogDebug << "after sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; - } -} - -/** -* 计算行车方向 -* inParam : std::shared_ptr pProcessData :待处理数据 -* outParam: N/A -* return : N/A -*/ -void FilterTrainStepOneEngine::CalculateDirection(std::shared_ptr pProcessData) -{ - auto iterPostDataFrist = mapPostDataFrist_.find(pProcessData->iDataSource); - auto iterMapStep1Info = mapMapStep1Info_.find(pProcessData->iDataSource); - /* - 1帧暂时最多识别3个大框。[(车头、间隔、车号); (车号、间隔、属性)] - 因间隔大框不是很准确,暂时把间隔大框剔除后,计算方向。 - 剔除间隔后,大框的可能情况为(车头; 车号; 属性; 车头&车号; 车号&属性) - */ - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - PostData postDataTemp = *pPostData; - for (auto iter = postDataTemp.vecPostSubData.begin(); iter != postDataTemp.vecPostSubData.end();) - { - if (iter->iTargetType == SPACE) - { - iter = postDataTemp.vecPostSubData.erase(iter); - continue; - } - auto iterMap = iterMapStep1Info->second.find(iter->iTargetType); - if (iterMap != iterMapStep1Info->second.end()) - { - iterMap->second.emplace_back(iter->step1Location); - } - else - { - std::vector vecTemp; - vecTemp.emplace_back(iter->step1Location); - iterMapStep1Info->second.insert(std::pair>(iter->iTargetType, vecTemp)); - } - - iter++; - } - - //记录第一次识别到大框的信息 - if (iterPostDataFrist->second.vecPostSubData.size() == 0) - { - iterPostDataFrist->second = postDataTemp; - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId - << " size:" << iterPostDataFrist->second.vecPostSubData.size(); - } - - //无框时,不计算方向 - if (iterPostDataFrist->second.vecPostSubData.size() == 0) - { - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " no find data"; - return; - } - //框的个数和类型没有变化时,不计算方向 - if (iterPostDataFrist->second.vecPostSubData.size() - postDataTemp.vecPostSubData.size() == 0) - { - std::sort(iterPostDataFrist->second.vecPostSubData.begin(), iterPostDataFrist->second.vecPostSubData.end(), CompareX); - std::sort(postDataTemp.vecPostSubData.begin(), postDataTemp.vecPostSubData.end(), CompareX); - bool bFlag = true; - for (int i = 0; i < iterPostDataFrist->second.vecPostSubData.size(); i++) - { - if (iterPostDataFrist->second.vecPostSubData[i].iTargetType != postDataTemp.vecPostSubData[i].iTargetType) - { - bFlag = false; - break; - } - } - if (bFlag) - { - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " datasize and datatype equal"; - return; - } - } - - auto iter = iterMapStep1Info->second.begin(); - int iMaxSize = iter->second.size(); - int iMaxSizeKey = iter->first; - int iMinSize = iter->second.size(); - int iMinSizeKey = iter->first; - while (iter != iterMapStep1Info->second.end()) - { - if (iter->second.size() > iMaxSize) - { - iMaxSize = iter->second.size(); - iMaxSizeKey = iter->first; - } - if (iter->second.size() < iMinSize) - { - iMinSize = iter->second.size(); - iMinSizeKey = iter->first; - } - iter++; - } - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId - << " iMaxSize:" << iMaxSize << " iMaxSizeKey:" << iMaxSizeKey - << " iMinSize:" << iMinSize << " iMinSizeKey:" << iMinSizeKey; - - /* - 第一次识别为1个框,后续变化为无框或2个框,使用框个数多的数据计算方向 - 第一次识别为2个框,后续变化为1个框,使用个数多的数据计算方向。 - 后续变化为0个框,使用个数少的数据计算方向。 - */ - if (iterPostDataFrist->second.vecPostSubData.size() == 1) - { - SetDirection(iterMapStep1Info->second[iMaxSizeKey], pProcessData); - } - else if (iterPostDataFrist->second.vecPostSubData.size() == 2) - { - if (postDataTemp.vecPostSubData.size() == 1) - { - SetDirection(iterMapStep1Info->second[iMinSizeKey], pProcessData); - } - else if (postDataTemp.vecPostSubData.size() == 0) - { - SetDirection(iterMapStep1Info->second[iMaxSizeKey], pProcessData); - } - } - LogDebug<< "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " 行车方向:" << iDirection_; -} - -void FilterTrainStepOneEngine::sendComeTrain(const std::string strTrainDate, const std::string strTrainName, const int iDirection) { - std::string message = "{\"cometime\":\"" + strTrainDate + " " + strTrainName + "\",\"type\":\"1\",\"direction\":" + to_string(iDirection == iPushDirection_ ? 1:-1) + "}"; - LogWarn << message; - outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_1"]->push(std::static_pointer_cast(std::make_shared(message))); -} - -/** -* 根据当前帧数据,处理上一帧数据 -* inParam : std::shared_ptr pProcessData :当前帧数据 -* outParam: N/A -* return : N/A -*/ -void FilterTrainStepOneEngine::DealProcessDataPre(std::shared_ptr pProcessData) -{ - /* - 目标框是否是连续识别,只识别到一帧的目标框认为误识别,过滤掉。 - 判断上一帧,当前帧 是否有框 - 上一帧有框,当前帧有框,说明连续识别,正常处理。 - 上一帧有框,当前帧无框,则非连续识别,过滤大框 - 上一帧无框,当前帧有框,则连续识别个数置零。 - 上一帧无框,当前帧无框,则连续识别个数置零。 - */ - auto iterProcessData = mapProcessDataPre_.find(pProcessData->iDataSource); - if (iterProcessData == mapProcessDataPre_.end() || nullptr == iterProcessData->second) - { - return; - } - - auto iterHeadContinueCnt = mapHeadContinueCnt_.find(pProcessData->iDataSource); - auto iterProContinueCnt = mapProContinueCnt_.find(pProcessData->iDataSource); - auto iterNumContinueCnt = mapNumContinueCnt_.find(pProcessData->iDataSource); - auto iterSpaceContinueCnt = mapSpaceContinueCnt_.find(pProcessData->iDataSource); - auto iterTranSpaceContinueCnt = mapTrainSpaceContinueCnt_.find(pProcessData->iDataSource); - - //获取当前帧识别情况 - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - for (int i = 0; i < pPostData->vecPostSubData.size(); i++) - { - if (pPostData->vecPostSubData[i].iTargetType == HEAD) - { - iterHeadContinueCnt->second++; - } - else if (pPostData->vecPostSubData[i].iTargetType == PRO) - { - iterProContinueCnt->second++; - } - else if (pPostData->vecPostSubData[i].iTargetType == NUM) - { - iterNumContinueCnt->second++; - } - else if (pPostData->vecPostSubData[i].iTargetType == SPACE) - { - iterSpaceContinueCnt->second++; - } - else if (pPostData->vecPostSubData[i].iTargetType == TRAINSPACE) - { - iterTranSpaceContinueCnt->second++; - } - } - //LogDebug << "engineId:" << engineId_ << " frameId:" << pProcessData->iFrameId << " " << iProContinueCnt_ << " " << iNumContinueCnt_; - - //获取上一帧识别情况 - std::shared_ptr pPostDataPre = std::static_pointer_cast(iterProcessData->second->pVoidData); - bool bPreHaveHead = false; - bool bPreHavePro = false; - bool bPreHaveNum = false; - bool bPreHaveSpace = false; - bool bPreHaveTrainSpace = false; - for (int iPre = 0; iPre < pPostDataPre->vecPostSubData.size(); iPre++) - { - if (pPostDataPre->vecPostSubData[iPre].iTargetType == HEAD) - { - iterHeadContinueCnt->second++; - bPreHaveHead = true; - } - else if (pPostDataPre->vecPostSubData[iPre].iTargetType == PRO) - { - iterProContinueCnt->second++; - bPreHavePro = true; - } - else if (pPostDataPre->vecPostSubData[iPre].iTargetType == NUM) - { - iterNumContinueCnt->second++; - bPreHaveNum = true; - } - else if (pPostDataPre->vecPostSubData[iPre].iTargetType == SPACE) - { - iterSpaceContinueCnt->second++; - bPreHaveSpace = true; - } - else if (pPostDataPre->vecPostSubData[iPre].iTargetType == TRAINSPACE) - { - iterTranSpaceContinueCnt->second++; - bPreHaveTrainSpace = true; - } - } - - //前一帧无大框连续识别次数置零 - iterHeadContinueCnt->second = bPreHaveHead ? iterHeadContinueCnt->second : 0; - iterProContinueCnt->second = bPreHavePro ? iterProContinueCnt->second : 0; - iterNumContinueCnt->second = bPreHaveNum ? iterNumContinueCnt->second : 0; - iterSpaceContinueCnt->second = bPreHaveSpace ? iterSpaceContinueCnt->second : 0; - iterTranSpaceContinueCnt->second = bPreHaveTrainSpace ? iterTranSpaceContinueCnt->second : 0; - - //非连续识别的情况,认为误识别,剔除误识别的大框信息 - for (std::vector::iterator it = pPostDataPre->vecPostSubData.begin(); it != pPostDataPre->vecPostSubData.end();) - { - if (iterHeadContinueCnt->second < 2 && it->iTargetType == HEAD) - { - LogDebug << " frameId:" << iterProcessData->second->iFrameId << " Head 框因非连续识别而过滤"; - it = pPostDataPre->vecPostSubData.erase(it); - continue; - } - if (iterProContinueCnt->second < 2 && it->iTargetType == PRO) - { - LogDebug << " frameId:" << iterProcessData->second->iFrameId << " PRO 框因非连续识别而过滤"; - it = pPostDataPre->vecPostSubData.erase(it); - continue; - } - if (iterNumContinueCnt->second < 2 && it->iTargetType == NUM) - { - LogDebug << " frameId:" << iterProcessData->second->iFrameId << " NUM 框因非连续识别而过滤"; - it = pPostDataPre->vecPostSubData.erase(it); - continue; - } - if (iterSpaceContinueCnt->second < 2 && it->iTargetType == SPACE) - { - LogDebug << " frameId:" << iterProcessData->second->iFrameId << " SPACE 框因非连续识别而过滤"; - it = pPostDataPre->vecPostSubData.erase(it); - continue; - } - if (iterTranSpaceContinueCnt->second < 2 && it->iTargetType == TRAINSPACE) - { - LogDebug << " frameId:" << iterProcessData->second->iFrameId << " TRAINSPACE 框因非连续识别而过滤"; - it = pPostDataPre->vecPostSubData.erase(it); - continue; - } - it++; - } - - //判定行驶方向, 记录Direction文件信息 - if (iDirection_ == DIRECTION_UNKNOWN) - { - iDirection_ = iterProcessData->second->iDirection; - - LogInfo << "方向:" << (iDirection_ == DIRECTION_LEFT ? "左" : (iDirection_ == DIRECTION_RIGHT ? "右" : "未判断出来")); - if (iDirection_ == DIRECTION_UNKNOWN) - { - //CalculateDirection(iterProcessData->second); - CalculateDirectionNew(iterProcessData->second); - if (iDirection_ != DIRECTION_UNKNOWN) this->sendComeTrain(pProcessData->strTrainDate, pProcessData->strTrainName, iDirection_); - } - - if (iDirection_ != DIRECTION_UNKNOWN) - { - auto iterPostDataFrist = mapPostDataFrist_.find(pProcessData->iDataSource); - Json::Value jvDirectionInfo; - jvDirectionInfo["direction"] = iDirection_; - jvDirectionInfo["firstStep1Cnt"] = iterPostDataFrist->second.vecPostSubData.size(); - jvDirectionInfo["frameid"] = iterProcessData->second->iFrameId; - jvDirectionInfo["sourceid"] = iterProcessData->second->iDataSource; - std::string strFilePath = strResultPath_ + pProcessData->strTrainDate + "/" + pProcessData->strTrainName + "/" + "direction.txt"; - MyUtils::getins()->WriteJsonInfo(jvDirectionInfo, strFilePath); - } - } - - //主摄像头校验是否停车 - int iTrainStatusTemp = iTrainStatus_; - if (iterProcessData->second->iDataSource == 0) - { - iTrainStatus_ = GetTrainStatus(iterProcessData->second); - iTrainStatusTemp = iTrainStatus_; - - if (iTrainStatus_ == TRAINSTATUS_STOP) - { - //停车 - } - else if (iTrainStatus_ == TRAINSTATUS_BACK) - { - //倒车 - AddBackInfo(iterProcessData->second); - iTrainStatusTemp = TRAINSTATUS_STOP; - } - else if(iTrainStatus_ == TRAINSTATUS_RUN) - { - /* - 正向行驶需先把倒车产生的倒车数据处理完毕,即使车辆回到原倒车点,再开始识别行驶数据 - */ - if(!IsEndDealBackInfo(iterProcessData->second)) - { - iTrainStatusTemp = TRAINSTATUS_STOP; - } - } - } - LogDebug << "数据源:" << iterProcessData->second->iDataSource << " 帧:" << iterProcessData->second->iFrameId - << " 火车实时运行状态:" << iTrainStatus_ << "(0无车,1运行,2停车,3倒车) iTrainStatusTemp:" << iTrainStatusTemp; - iterProcessData->second->iStatus = iTrainStatusTemp; - - // this->sendComeTrain(pProcessData->strTrainDate, pProcessData->strTrainName, iDirection_); - - outputQueMap_[strPort0_]->push(std::static_pointer_cast(iterProcessData->second), true); - //上一帧,push端口0 -// PushData(strPort0_, iterProcessData->second); -} - - -APP_ERROR FilterTrainStepOneEngine::Process() -{ - int iRet = APP_ERR_OK; - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } - - std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - - // //停止后再次行驶,把队列中多余的数据丢弃。 - // if (iReRunOrigFrameId_ != 0 && pProcessData->iOrigFrameId > iReRunOrigFrameId_ && !pProcessData->bIsEnd) - // { - // LogDebug << "reRunOrigFrameId:" << iReRunOrigFrameId_ << " origFrameId:" << pProcessData->iOrigFrameId; - // continue; - // } - - if (pProcessData->bIsEnd) - { - mapDataSourceIsEnd_[pProcessData->iDataSource] = pProcessData->bIsEnd; - } - - //1帧暂时最多识别4个大框。[(车头、车厢间隔、间隔、车号); (车号、车厢间隔、间隔、属性)] - if (pPostData->vecPostSubData.size() > 4) - { - LogError << "sourceid:" << pProcessData->iDataSource << " frameId:" << pProcessData->iFrameId << " vecpostsubdata size:" << pPostData->vecPostSubData.size(); - pPostData->vecPostSubData.clear(); - } - - //按指定识别区域过滤误识别信息--过滤逻辑迁移至TrainStepOneEngine中。 - - //根据当前帧数据,处理上一帧数据 - DealProcessDataPre(pProcessData); - mapProcessDataPre_[pProcessData->iDataSource] = pProcessData; - if (pProcessData->bIsEnd) - { - //结束帧,push端口0 - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " isEnd:" << pProcessData->bIsEnd; -// PushData(strPort0_, pProcessData); - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData), true); - } - - //3. 全部结束,初始化相关参数 - bool bAllEnd = true; - for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) - { - bAllEnd = bAllEnd && iter->second; - } - if (bAllEnd) - { - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " bAllEnd"; - InitParam(); - } - } - return APP_ERR_OK; -} +#include "FilterTrainStepOneEngine.h" #include "myutils.h" #include using namespace ai_matrix; namespace { //按照x坐标排列 bool CompareX(const PostSubData &a, const PostSubData &b) { return a.step1Location.fLTX < b.step1Location.fLTX; } } extern std::atomic_uint64_t g_i64ReRunTimeStamp; extern std::atomic_uint32_t g_iReRunOrigFrameId; extern std::atomic_uint32_t g_iReRunFrameId; extern std::atomic_uint32_t g_iReRunOrigChkDateFid; extern std::atomic_uint32_t g_iReRunOrigContainerFid; FilterTrainStepOneEngine::FilterTrainStepOneEngine() {} FilterTrainStepOneEngine::~FilterTrainStepOneEngine() {} APP_ERROR FilterTrainStepOneEngine::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); iChkStopPX_ = MyYaml::GetIns()->GetIntValue("gc_chkstop_px"); iChkStopCount_ = MyYaml::GetIns()->GetIntValue("gc_chkstop_count"); iPartitionFrameNum_ = MyYaml::GetIns()->GetIntValue("partition_frame_span"); iPlitFrameSpanPX_ = MyYaml::GetIns()->GetIntValue("gc_split_frame_span_px"); iPushDirection_ = MyYaml::GetIns()->GetIntValue("gc_push_direction"); //获取主摄像头信息 mainCfg_ = MyYaml::GetIns()->GetDataSourceConfigById(0); std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) { this->rightFirst_ = iter->second.iRightFirst; this->leftFirst_ = iter->second.iLeftFirst; if (iter->second.strTarget.find("NUM") != std::string::npos) { LogDebug << "DataSource:" << iter->first << " deal NUM"; mapHeadContinueCnt_[iter->first] = 0; mapProContinueCnt_[iter->first] = 0; mapNumContinueCnt_[iter->first] = 0; mapSpaceContinueCnt_[iter->first] = 0; mapTrainSpaceContinueCnt_[iter->first] = 0; mapDataSourceIsEnd_[iter->first] = false; PostData postDataTemp; mapPostDataFrist_[iter->first] = postDataTemp; std::map> mapStep1InfoTemp; //[key-目标框id, 目标框坐标集合] mapMapStep1Info_[iter->first] = mapStep1InfoTemp; } } mapTargetStr_.insert(std::make_pair(NUM, "NUM")); mapTargetStr_.insert(std::make_pair(PRO, "PRO")); mapTargetStr_.insert(std::make_pair(HEAD, "HEAD")); mapTargetStr_.insert(std::make_pair(SPACE, "SPACE"));//SPACE mapTargetStr_.insert(std::make_pair(TRAINSPACE, "SPACE"));//SPACE InitParam(); LogInfo << "FilterTrainStepOneEngine Init ok"; return APP_ERR_OK; } APP_ERROR FilterTrainStepOneEngine::DeInit() { LogInfo << "FilterTrainStepOneEngine DeInit ok"; return APP_ERR_OK; } /** * 参数初始化(列车结束时需调用) * inParam : N/A * outParam: N/A * return : N/A */ void FilterTrainStepOneEngine::InitParam() { mapProcessDataPre_.clear(); for (auto iter = mapHeadContinueCnt_.begin(); iter != mapHeadContinueCnt_.end(); iter++) { iter->second = 0; } for (auto iter = mapProContinueCnt_.begin(); iter != mapProContinueCnt_.end(); iter++) { iter->second = 0; } for (auto iter = mapNumContinueCnt_.begin(); iter != mapNumContinueCnt_.end(); iter++) { iter->second = 0; } for (auto iter = mapSpaceContinueCnt_.begin(); iter != mapSpaceContinueCnt_.end(); iter++) { iter->second = 0; } for (auto iter = mapTrainSpaceContinueCnt_.begin(); iter != mapTrainSpaceContinueCnt_.end(); iter++) { iter->second = 0; } for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) { iter->second = false; } for (auto iter = mapPostDataFrist_.begin(); iter != mapPostDataFrist_.end(); iter++) { iter->second.vecPostSubData.clear(); } for (auto iter = mapMapStep1Info_.begin(); iter != mapMapStep1Info_.end(); iter++) { iter->second.clear(); } iDirection_ = DIRECTION_UNKNOWN; iNotChgCount_ = 0; while (!stackBackInfo_.empty()) { stackBackInfo_.pop(); } while (!quePostData_.empty()) { quePostData_.pop(); } iTrainStatus_ = TRAINSTATUS_RUN; mapCalDirection_.clear(); } /** * push数据到队列,队列满时则休眠一段时间再push * inParam : const std::string strPort push的端口 : const std::shared_ptr &pProcessData push的数据 * outParam: N/A * return : N/A */ void FilterTrainStepOneEngine::PushData(const std::string &strPort, const std::shared_ptr &pProcessData) { while (true) { int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pProcessData)); if (iRet != 0) { LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet; if (iRet == 2) { usleep(10000); // 10ms continue; } } break; } } void FilterTrainStepOneEngine::AddBackInfo(std::shared_ptr pProcessData) { std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); std::sort(pPostData->vecPostSubData.begin(), pPostData->vecPostSubData.end(), CompareX); std::string strAllClassType; for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) { if (strAllClassType.find(mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]) != std::string::npos) { continue; } strAllClassType += mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]; } if (strAllClassType.empty()) { return; } LogDebug << "frameId:" << pProcessData->iFrameId << " addbackinfo strAllClassType:" << strAllClassType; TrainBackInfo trainBackInfo; trainBackInfo.processData = pProcessData; trainBackInfo.strAllClassType = strAllClassType; if (stackBackInfo_.empty()) { stackBackInfo_.push(trainBackInfo); LogDebug << "frameId:" << pProcessData->iFrameId << " push strAllClassType:" << strAllClassType << " stacksize:" << stackBackInfo_.size(); } else { TrainBackInfo trainBackInfoTop = stackBackInfo_.top(); if (trainBackInfoTop.strAllClassType != trainBackInfo.strAllClassType) { if (((iDirection_ == DIRECTION_RIGHT && this->rightFirst_ == RIGHT_RUN_AND_PRO_FIRST) || (iDirection_ == DIRECTION_LEFT && this->leftFirst_ == LEFT_RUN_AND_PRO_FIRST)) && ((trainBackInfo.strAllClassType == "SPACE" && (trainBackInfoTop.strAllClassType == "PROSPACE" || trainBackInfoTop.strAllClassType == "SPACEPRO")) || (trainBackInfo.strAllClassType == "NUM" && (trainBackInfoTop.strAllClassType == "NUMSPACE" || trainBackInfoTop.strAllClassType == "SPACENUM")) || ((trainBackInfo.strAllClassType == "PROSPACE" || trainBackInfo.strAllClassType == "SPACEPRO") && trainBackInfoTop.strAllClassType == "PRO"))) { return; } if (((iDirection_ == DIRECTION_RIGHT && this->rightFirst_ == RIGHT_RUN_AND_NUM_FIRST) || (iDirection_ == DIRECTION_LEFT && this->leftFirst_ == LEFT_RUN_AND_NUM_FIRST)) && ((trainBackInfo.strAllClassType == "SPACE" && (trainBackInfoTop.strAllClassType == "NUMSPACE" || trainBackInfoTop.strAllClassType == "SPACENUM")) || (trainBackInfo.strAllClassType == "PRO" && (trainBackInfoTop.strAllClassType == "PROSPACE" || trainBackInfoTop.strAllClassType == "SPACEPRO")) || ((trainBackInfo.strAllClassType == "NUMSPACE" || trainBackInfo.strAllClassType == "SPACENUM") && trainBackInfoTop.strAllClassType == "NUM"))) { return; } stackBackInfo_.push(trainBackInfo); LogDebug << "frameId:" << pProcessData->iFrameId << " push strAllClassType:" << strAllClassType << " stacksize:" << stackBackInfo_.size(); } } } bool FilterTrainStepOneEngine::IsEndDealBackInfo(std::shared_ptr pProcessData) { if (stackBackInfo_.empty()) { return true; } bool bPopFlag = false; std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); if (pPostData->vecPostSubData.size() == 0) return false; /* 处理倒车数据时,数据需设置为倒车,主要是保证这样的数据后面Engine不处理,防止切分车厢出错。 类型不相等时,就pop,当pop后,还剩一个数据时,则表示已经回到了刚开始倒车的地方。(只剩一个数据的逻辑在上方) 处理最后一个时,不能只判断下类型相同就弹出。需要控制下位置。(要么类型相同位置合适,要么类型不相同) 正向为向左行驶,则当前数据的位置尽量小于等于栈中最后一个元素的位置。 正向为向右行驶,则当前数据的位置尽量大于等于栈中最后一个元素的位置。 */ std::sort(pPostData->vecPostSubData.begin(), pPostData->vecPostSubData.end(), CompareX); std::string strAllClassType; for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) { if (strAllClassType.find(mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]) != std::string::npos) { continue; } strAllClassType += mapTargetStr_[pPostData->vecPostSubData[i].iTargetType]; } if (strAllClassType.empty()) { return false; } if (stackBackInfo_.size() == 1) { TrainBackInfo trainBackInfoLast = stackBackInfo_.top(); std::shared_ptr pPostDataBack = std::static_pointer_cast(trainBackInfoLast.processData->pVoidData); std::sort(pPostDataBack->vecPostSubData.begin(), pPostDataBack->vecPostSubData.end(), CompareX); for (size_t i = 0; i < pPostDataBack->vecPostSubData.size(); i++) { int bFlag = -1; for (size_t j = 0; j < pPostData->vecPostSubData.size(); j++) { if (pPostDataBack->vecPostSubData[i].iBigClassId == pPostData->vecPostSubData[j].iBigClassId) { if (pPostData->vecPostSubData[j].step1Location.fLTX < 1 || pPostDataBack->vecPostSubData[i].step1Location.fLTX < 1) { LogDebug << "大框X坐标小于1,判定为异常大框。过滤!!"; break; } bFlag = (pPostDataBack->vecPostSubData[i].step1Location.fLTX <= pPostData->vecPostSubData[j].step1Location.fLTX) ? 1 : 0; LogDebug << "帧:" << pProcessData->iFrameId << " 倒车前帧:" << pPostDataBack->iFrameId << " 恢复到原位:" << bFlag << " 当前框位置:" << pPostData->vecPostSubData[i].step1Location.fLTX << " 倒车前位置:" << pPostDataBack->vecPostSubData[i].step1Location.fLTX << "方向:" << iDirection_; } } if ((iDirection_ == DIRECTION_LEFT && bFlag == 0) || (iDirection_ == DIRECTION_RIGHT && bFlag == 1)) { bPopFlag = true; break; } } if (bPopFlag) { LogDebug << "frameId:" << pProcessData->iFrameId << " 恢复倒车前的位置:" << bPopFlag; stackBackInfo_.pop(); } } else { TrainBackInfo trainBackInfoTop_bak = stackBackInfo_.top(); stackBackInfo_.pop(); TrainBackInfo trainBackInfoTop = stackBackInfo_.top(); if (trainBackInfoTop.strAllClassType != strAllClassType) { stackBackInfo_.push(trainBackInfoTop_bak); LogDebug << "帧:" << pProcessData->iFrameId << " 倒车信息:" << stackBackInfo_.size() << " 顶部倒车信息:" << trainBackInfoTop.strAllClassType << " 本次识别信息:" << strAllClassType; } else { // bPopFlag = true; LogDebug << "帧:" << pProcessData->iFrameId << " 倒车信息:" << stackBackInfo_.size() << " 顶部倒车信息:" << trainBackInfoTop.strAllClassType << " 本次识别信息:" << strAllClassType << " 删除倒车信息:" << trainBackInfoTop_bak.strAllClassType; } // if(bPopFlag) // { // stackBackInfo_.pop(); // bPopFlag = false; // } } return stackBackInfo_.empty() ? true : false; } /** * 校验火车是否停止 * inParam : std::shared_ptr pProcessData :待处理数据 * outParam: N/A * return : true:停止; false:非停止 1(正常行驶) 2(停车) 3(倒车) */ int FilterTrainStepOneEngine::GetTrainStatus(std::shared_ptr pProcessData) { if (iDirection_ == DIRECTION_UNKNOWN) { LogDebug << " frameId:" << pProcessData->iFrameId << " 未判断出行车方向,暂定认为火车正常行驶中"; return TRAINSTATUS_RUN; } std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); pPostData->iFrameId = pProcessData->iFrameId; // 1. 无框时,返回之前的列车状态 if (pPostData->vecPostSubData.size() == 0) { return iTrainStatus_; } quePostData_.push(*pPostData.get()); if (quePostData_.size() < 3) { return TRAINSTATUS_RUN; } PostData postDataFront = quePostData_.front(); //iNotChgCount_大于0表示有可能停车,此时pop队列数据要多留存几个。用最开始的数据来判断是否真正停车,如果每次只用上上帧判断当列车超级慢时可能判断为停车。 int iSizeTemp = iNotChgCount_ > 0 ? 10 : 2; while (quePostData_.size() > iSizeTemp) { quePostData_.pop(); } // LogDebug << "frameId:" << pProcessData->iFrameId << " 判断运动状态队列 第一帧:" << postDataFront.iFrameId << " 队列size:" << quePostData_.size() << " iSizeTemp:" << iSizeTemp; bool bSameFlag = false; int iDiffValue = iChkStopPX_; for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) { PostSubData postSubDataBack = pPostData->vecPostSubData[i]; for (size_t j = 0; j < postDataFront.vecPostSubData.size(); j++) { PostSubData postSubDataFront = postDataFront.vecPostSubData[j]; /* 使用iBigClassId,可能出现平车只有间隔大框,且间隔大框可以一会是平车间隔,一会是通用间隔。导致类别不一样 使用iTargetType,可能出现平车只有间隔大框,且间隔大框可以一会是平车间隔,一会是通用间隔。导致像素差判断不准。 */ if (postSubDataFront.iTargetType != postSubDataBack.iTargetType) { LogDebug << "判断前后帧识别的是否一致 上一个:" << postSubDataFront.iTargetType << " 当前:" << postSubDataBack.iTargetType; continue; } // if (postSubDataFront.iTargetType == SPACE && postSubDataFront.iBigClassId != postSubDataBack.iBigClassId) // { // iDiffValue = 50; // } bSameFlag = true; int iCenterBack = postSubDataBack.step1Location.fLTX + (postSubDataBack.step1Location.fRBX - postSubDataBack.step1Location.fLTX) / 2; int iCenterFront = postSubDataFront.step1Location.fLTX + (postSubDataFront.step1Location.fRBX - postSubDataFront.step1Location.fLTX) / 2; //位置比较大于10个像素,则表示有移动。再判断时正向移动,还是倒车 // LogDebug << "frameId:" << pProcessData->iFrameId << " " << iCenterBack << "-" << iCenterFront // << "=" << abs(iCenterBack - iCenterFront) << " 预期判定移动的差值为iDiffValue:" << iDiffValue; if (abs(iCenterBack - iCenterFront) > iDiffValue) { iNotChgCount_ = 0; /* iCenterBack > iCenterFront 表示向右行驶,且原方向为向左行驶 iCenterBack < iCenterFront 表示向左行驶,且原方向为向右行驶 以上2种表示倒车。 */ if ((iCenterBack > iCenterFront && iDirection_ == DIRECTION_LEFT) || (iCenterBack < iCenterFront && iDirection_ == DIRECTION_RIGHT)) { if (this->iPartitionFrameNum_ < (pProcessData->iFrameId - postDataFront.iFrameId) && this->iPlitFrameSpanPX_ < abs(iCenterBack - iCenterFront)) { return TRAINSTATUS_RUN; } LogDebug << "frameId:" << pProcessData->iFrameId << " 检测到火车倒车"; return TRAINSTATUS_BACK; } else { LogDebug << "frameId:" << pProcessData->iFrameId << " 正常行驶"; return TRAINSTATUS_RUN; } } /* 小于10个像素表示可能停车,累计未变化次数。 累计变化次数超过10次,返回停车 累计变化次数未超过10次,返回之前行驶状态 */ else { iNotChgCount_++; LogDebug << " frameId:" << pProcessData->iFrameId << " 大框移动范围小(" << abs(iCenterBack - iCenterFront) << ") 判断停车计数:" << iNotChgCount_ << "/" << iChkStopCount_; if (iNotChgCount_ > iChkStopCount_) { LogDebug << "frameId:" << pProcessData->iFrameId << " 检测到火车停车"; return TRAINSTATUS_STOP; } else { // LogDebug << "frameId:" << pProcessData->iFrameId << " iTrainStatus_:" << iTrainStatus_; return iTrainStatus_; } } } } /* 未找到相同的框,说明是老框消失掉了,新框出现了。 按新框出现的位置判断是向左行驶,还是向右行驶。 */ LogDebug << "frameId:" << pProcessData->iFrameId << " bSameFlag:" << bSameFlag; if (!bSameFlag) { std::sort(pPostData->vecPostSubData.begin(), pPostData->vecPostSubData.end(), CompareX); Step1Location step1Location = pPostData->vecPostSubData.front().step1Location; if (iDirection_ == DIRECTION_LEFT) { step1Location = pPostData->vecPostSubData.back().step1Location; } LogDebug << "frameId:" << pProcessData->iFrameId << " fLTX:" << step1Location.fLTX << " fRBX:" << step1Location.fRBX; iNotChgCount_ = 0; int iCenter = step1Location.fLTX + (step1Location.fRBX - step1Location.fLTX) / 2; int iValue = pProcessData->iWidth / 2; if ((iCenter > iValue && iDirection_ == DIRECTION_RIGHT) || (iCenter < iValue && iDirection_ == DIRECTION_LEFT)) { /* 针对有效帧较少时,和上上帧比较没有同类型大框,且当前帧已行驶到画面中心导致误判的情况, 增加和上帧同类型大框的比较处理。 */ PostData postDataMiddle = quePostData_.front(); for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) { PostSubData postSubDataBack = pPostData->vecPostSubData[i]; for (size_t j = 0; j < postDataMiddle.vecPostSubData.size(); j++) { PostSubData postSubDataMiddle = postDataMiddle.vecPostSubData[j]; if (postSubDataMiddle.iTargetType != postSubDataBack.iTargetType) { continue; } int iCenterBack = postSubDataBack.step1Location.fLTX + (postSubDataBack.step1Location.fRBX - postSubDataBack.step1Location.fLTX) / 2; int iCenterMiddle = postSubDataMiddle.step1Location.fLTX + (postSubDataMiddle.step1Location.fRBX - postSubDataMiddle.step1Location.fLTX) / 2; // 位置比较大于10个像素,则表示有移动。再判断时正向移动,还是倒车 LogDebug << "frameId:" << pProcessData->iFrameId << " " << iCenterBack << "-" << iCenterMiddle << "=" << abs(iCenterBack - iCenterMiddle) << " 移动差值 iDiffValue:" << iDiffValue; if (abs(iCenterBack - iCenterMiddle) > iDiffValue) { if ((iCenterBack > iCenterMiddle && iDirection_ == DIRECTION_LEFT) || (iCenterBack < iCenterMiddle && iDirection_ == DIRECTION_RIGHT)) { LogDebug << "frameId:" << pProcessData->iFrameId << " 检测到火车倒车"; return TRAINSTATUS_BACK; } else { LogDebug << "frameId:" << pProcessData->iFrameId << " 正常行驶"; return TRAINSTATUS_RUN; } } } } // LogDebug << "frameId:" << pProcessData->iFrameId << " back2"; return iTrainStatus_; } } // LogDebug << "frameId:" << pProcessData->iFrameId << " iNotChgCount_:" << iNotChgCount_ << " run run"; return TRAINSTATUS_RUN; } /** * 设置行车方向 * inParam : std::vector &vecLocation :大框坐标集合 : std::shared_ptr pProcessData :待处理数据 * outParam: N/A * return : N/A */ void FilterTrainStepOneEngine::SetDirection(std::vector &vecLocation, std::shared_ptr pProcessData) { if (vecLocation.size() < 1) { return; } Step1Location slFront = vecLocation.front(); Step1Location slBack = vecLocation.back(); /* 移动距离小于50个像素,则判断最后一个框的出现的位置 */ LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " slFront:" << slFront.fLTX << " slBack:" << slBack.fLTX; if (fabs(slBack.fLTX - slFront.fLTX) < 50) { float fTempX1 = pProcessData->iWidth / 5; //5分之1的X坐标 float fTempX2 = pProcessData->iWidth / 5 * 4; //5分之4的X坐标 if (slBack.fLTX < fTempX1) { iDirection_ = DIRECTION_LEFT; } else if (slBack.fRBX > fTempX2) { iDirection_ = DIRECTION_RIGHT; } } else { //行驶方向 左 if ((slBack.fLTX - slFront.fLTX) < 0) { iDirection_ = DIRECTION_LEFT; } //行驶方向 右 else if ((slBack.fLTX - slFront.fLTX) > 0) { iDirection_ = DIRECTION_RIGHT; } } //未判断出移动方向,清除数后重新计算。 if (iDirection_ == DIRECTION_UNKNOWN) { auto iterMapStep1Info = mapMapStep1Info_.find(pProcessData->iDataSource); iterMapStep1Info->second.clear(); } else { if (MyYaml::GetIns()->GetDataSourceConfigById(pProcessData->iDataSource).iLeftFirst != mainCfg_.iLeftFirst) { LogDebug << "before sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; iDirection_ = (iDirection_ == DIRECTION_LEFT) ? DIRECTION_RIGHT : DIRECTION_LEFT; LogDebug << "after sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; } } } /** * 计算行车方向新 * inParam : std::shared_ptr pProcessData :待处理数据 * outParam: N/A * return : N/A */ void FilterTrainStepOneEngine::CalculateDirectionNew(std::shared_ptr pProcessData) { /* 连续3帧同目标识别框信息 判断位置差异是否超过10px(判停车参数),且两两之间都是线性。如果符合则计算方向。 上述条件不符合则剔除第一个元素,再次累计连续3帧处理。 */ auto iterMap = mapCalDirection_.find(pProcessData->iDataSource); if (iterMap == mapCalDirection_.end()) { std::map> mapTemp; mapCalDirection_.insert(std::make_pair(pProcessData->iDataSource, mapTemp)); iterMap = mapCalDirection_.find(pProcessData->iDataSource); } std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); for (auto iter = pPostData->vecPostSubData.begin(); iter != pPostData->vecPostSubData.end(); iter++) { CalculateInfo calInfo; calInfo.iFrameId = pProcessData->iFrameId; calInfo.iBigClassId = iter->iBigClassId; calInfo.fCenterX = iter->step1Location.fLTX + (iter->step1Location.fRBX - iter->step1Location.fLTX) / 2; calInfo.fTargetWidth = iter->step1Location.fRBX - iter->step1Location.fLTX; auto iterSubMap = iterMap->second.find(iter->iBigClassId); if (iterSubMap == iterMap->second.end()) { std::vector vecTemp; iterMap->second.insert(std::make_pair(iter->iBigClassId, vecTemp)); iterSubMap = iterMap->second.find(iter->iBigClassId); } iterSubMap->second.emplace_back(calInfo); if (iterSubMap->second.size() > 2) { LogDebug << "souceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " last:" << iterSubMap->second.at(2).iFrameId << " " << iterSubMap->second.at(2).fCenterX << " mid:" << iterSubMap->second.at(1).iFrameId << " " << iterSubMap->second.at(1).fCenterX << " pre:" << iterSubMap->second.at(0).iFrameId << " " << iterSubMap->second.at(0).fCenterX; //如果帧号连续,且移动位置大于15px,则计算方向 if (iterSubMap->second.at(2).iFrameId - iterSubMap->second.at(1).iFrameId != mainCfg_.iSkipInterval || iterSubMap->second.at(1).iFrameId - iterSubMap->second.at(0).iFrameId != mainCfg_.iSkipInterval) { iterSubMap->second.erase(iterSubMap->second.begin()); continue; } if (abs(iterSubMap->second.at(0).fTargetWidth - iterSubMap->second.at(2).fTargetWidth) >= 1.5*iChkStopPX_) { iterSubMap->second.erase(iterSubMap->second.begin()); continue; } int iLast = iterSubMap->second.at(2).fCenterX; int iMid = iterSubMap->second.at(1).fCenterX; int iPre = iterSubMap->second.at(0).fCenterX; if (abs(iPre - iLast) <= iChkStopPX_) { iterSubMap->second.erase(iterSubMap->second.begin()); continue; } if (iPre <= iMid && iMid <= iLast) { iDirection_ = DIRECTION_RIGHT; } else if (iPre >= iMid && iMid >= iLast) { iDirection_ = DIRECTION_LEFT; } else { iterSubMap->second.erase(iterSubMap->second.begin()); continue; } LogDebug << "souceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " iDirection_:" << iDirection_; } } //主相机的对侧相机需反向设置方向 if (iDirection_ != DIRECTION_UNKNOWN && MyYaml::GetIns()->GetDataSourceConfigById(pProcessData->iDataSource).iLeftFirst != mainCfg_.iLeftFirst) { LogDebug << "before sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; iDirection_ = (iDirection_ == DIRECTION_LEFT) ? DIRECTION_RIGHT : DIRECTION_LEFT; LogDebug << "after sourceid:" << pProcessData->iDataSource << "frameid:" << pProcessData->iFrameId << " direction:" << iDirection_; } } /** * 计算行车方向 * inParam : std::shared_ptr pProcessData :待处理数据 * outParam: N/A * return : N/A */ void FilterTrainStepOneEngine::CalculateDirection(std::shared_ptr pProcessData) { auto iterPostDataFrist = mapPostDataFrist_.find(pProcessData->iDataSource); auto iterMapStep1Info = mapMapStep1Info_.find(pProcessData->iDataSource); /* 1帧暂时最多识别3个大框。[(车头、间隔、车号); (车号、间隔、属性)] 因间隔大框不是很准确,暂时把间隔大框剔除后,计算方向。 剔除间隔后,大框的可能情况为(车头; 车号; 属性; 车头&车号; 车号&属性) */ std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); PostData postDataTemp = *pPostData; for (auto iter = postDataTemp.vecPostSubData.begin(); iter != postDataTemp.vecPostSubData.end();) { if (iter->iTargetType == SPACE) { iter = postDataTemp.vecPostSubData.erase(iter); continue; } auto iterMap = iterMapStep1Info->second.find(iter->iTargetType); if (iterMap != iterMapStep1Info->second.end()) { iterMap->second.emplace_back(iter->step1Location); } else { std::vector vecTemp; vecTemp.emplace_back(iter->step1Location); iterMapStep1Info->second.insert(std::pair>(iter->iTargetType, vecTemp)); } iter++; } //记录第一次识别到大框的信息 if (iterPostDataFrist->second.vecPostSubData.size() == 0) { iterPostDataFrist->second = postDataTemp; LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " size:" << iterPostDataFrist->second.vecPostSubData.size(); } //无框时,不计算方向 if (iterPostDataFrist->second.vecPostSubData.size() == 0) { LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " no find data"; return; } //框的个数和类型没有变化时,不计算方向 if (iterPostDataFrist->second.vecPostSubData.size() - postDataTemp.vecPostSubData.size() == 0) { std::sort(iterPostDataFrist->second.vecPostSubData.begin(), iterPostDataFrist->second.vecPostSubData.end(), CompareX); std::sort(postDataTemp.vecPostSubData.begin(), postDataTemp.vecPostSubData.end(), CompareX); bool bFlag = true; for (int i = 0; i < iterPostDataFrist->second.vecPostSubData.size(); i++) { if (iterPostDataFrist->second.vecPostSubData[i].iTargetType != postDataTemp.vecPostSubData[i].iTargetType) { bFlag = false; break; } } if (bFlag) { LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " datasize and datatype equal"; return; } } auto iter = iterMapStep1Info->second.begin(); int iMaxSize = iter->second.size(); int iMaxSizeKey = iter->first; int iMinSize = iter->second.size(); int iMinSizeKey = iter->first; while (iter != iterMapStep1Info->second.end()) { if (iter->second.size() > iMaxSize) { iMaxSize = iter->second.size(); iMaxSizeKey = iter->first; } if (iter->second.size() < iMinSize) { iMinSize = iter->second.size(); iMinSizeKey = iter->first; } iter++; } LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " iMaxSize:" << iMaxSize << " iMaxSizeKey:" << iMaxSizeKey << " iMinSize:" << iMinSize << " iMinSizeKey:" << iMinSizeKey; /* 第一次识别为1个框,后续变化为无框或2个框,使用框个数多的数据计算方向 第一次识别为2个框,后续变化为1个框,使用个数多的数据计算方向。 后续变化为0个框,使用个数少的数据计算方向。 */ if (iterPostDataFrist->second.vecPostSubData.size() == 1) { SetDirection(iterMapStep1Info->second[iMaxSizeKey], pProcessData); } else if (iterPostDataFrist->second.vecPostSubData.size() == 2) { if (postDataTemp.vecPostSubData.size() == 1) { SetDirection(iterMapStep1Info->second[iMinSizeKey], pProcessData); } else if (postDataTemp.vecPostSubData.size() == 0) { SetDirection(iterMapStep1Info->second[iMaxSizeKey], pProcessData); } } LogDebug<< "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " 行车方向:" << iDirection_; } void FilterTrainStepOneEngine::sendComeTrain(const std::string strTrainDate, const std::string strTrainName, const int iDirection) { std::string message = "{\"cometime\":\"" + strTrainDate + " " + strTrainName + "\",\"type\":\"1\",\"direction\":" + to_string(iDirection == iPushDirection_ ? 1:-1) + "}"; LogWarn << message; outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_1"]->push(std::static_pointer_cast(std::make_shared(message))); } /** * 根据当前帧数据,处理上一帧数据 * inParam : std::shared_ptr pProcessData :当前帧数据 * outParam: N/A * return : N/A */ void FilterTrainStepOneEngine::DealProcessDataPre(std::shared_ptr pProcessData) { /* 目标框是否是连续识别,只识别到一帧的目标框认为误识别,过滤掉。 判断上一帧,当前帧 是否有框 上一帧有框,当前帧有框,说明连续识别,正常处理。 上一帧有框,当前帧无框,则非连续识别,过滤大框 上一帧无框,当前帧有框,则连续识别个数置零。 上一帧无框,当前帧无框,则连续识别个数置零。 */ auto iterProcessData = mapProcessDataPre_.find(pProcessData->iDataSource); if (iterProcessData == mapProcessDataPre_.end() || nullptr == iterProcessData->second) { return; } auto iterHeadContinueCnt = mapHeadContinueCnt_.find(pProcessData->iDataSource); auto iterProContinueCnt = mapProContinueCnt_.find(pProcessData->iDataSource); auto iterNumContinueCnt = mapNumContinueCnt_.find(pProcessData->iDataSource); auto iterSpaceContinueCnt = mapSpaceContinueCnt_.find(pProcessData->iDataSource); auto iterTranSpaceContinueCnt = mapTrainSpaceContinueCnt_.find(pProcessData->iDataSource); //获取当前帧识别情况 std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); for (int i = 0; i < pPostData->vecPostSubData.size(); i++) { if (pPostData->vecPostSubData[i].iTargetType == HEAD) { iterHeadContinueCnt->second++; } else if (pPostData->vecPostSubData[i].iTargetType == PRO) { iterProContinueCnt->second++; } else if (pPostData->vecPostSubData[i].iTargetType == NUM) { iterNumContinueCnt->second++; } else if (pPostData->vecPostSubData[i].iTargetType == SPACE) { iterSpaceContinueCnt->second++; } else if (pPostData->vecPostSubData[i].iTargetType == TRAINSPACE) { iterTranSpaceContinueCnt->second++; } } //LogDebug << "engineId:" << engineId_ << " frameId:" << pProcessData->iFrameId << " " << iProContinueCnt_ << " " << iNumContinueCnt_; //获取上一帧识别情况 std::shared_ptr pPostDataPre = std::static_pointer_cast(iterProcessData->second->pVoidData); bool bPreHaveHead = false; bool bPreHavePro = false; bool bPreHaveNum = false; bool bPreHaveSpace = false; bool bPreHaveTrainSpace = false; for (int iPre = 0; iPre < pPostDataPre->vecPostSubData.size(); iPre++) { if (pPostDataPre->vecPostSubData[iPre].iTargetType == HEAD) { iterHeadContinueCnt->second++; bPreHaveHead = true; } else if (pPostDataPre->vecPostSubData[iPre].iTargetType == PRO) { iterProContinueCnt->second++; bPreHavePro = true; } else if (pPostDataPre->vecPostSubData[iPre].iTargetType == NUM) { iterNumContinueCnt->second++; bPreHaveNum = true; } else if (pPostDataPre->vecPostSubData[iPre].iTargetType == SPACE) { iterSpaceContinueCnt->second++; bPreHaveSpace = true; } else if (pPostDataPre->vecPostSubData[iPre].iTargetType == TRAINSPACE) { iterTranSpaceContinueCnt->second++; bPreHaveTrainSpace = true; } } //前一帧无大框连续识别次数置零 iterHeadContinueCnt->second = bPreHaveHead ? iterHeadContinueCnt->second : 0; iterProContinueCnt->second = bPreHavePro ? iterProContinueCnt->second : 0; iterNumContinueCnt->second = bPreHaveNum ? iterNumContinueCnt->second : 0; iterSpaceContinueCnt->second = bPreHaveSpace ? iterSpaceContinueCnt->second : 0; iterTranSpaceContinueCnt->second = bPreHaveTrainSpace ? iterTranSpaceContinueCnt->second : 0; //非连续识别的情况,认为误识别,剔除误识别的大框信息 for (std::vector::iterator it = pPostDataPre->vecPostSubData.begin(); it != pPostDataPre->vecPostSubData.end();) { if (iterHeadContinueCnt->second < 2 && it->iTargetType == HEAD) { LogDebug << " frameId:" << iterProcessData->second->iFrameId << " Head 框因非连续识别而过滤"; it = pPostDataPre->vecPostSubData.erase(it); continue; } if (iterProContinueCnt->second < 2 && it->iTargetType == PRO) { LogDebug << " frameId:" << iterProcessData->second->iFrameId << " PRO 框因非连续识别而过滤"; it = pPostDataPre->vecPostSubData.erase(it); continue; } if (iterNumContinueCnt->second < 2 && it->iTargetType == NUM) { LogDebug << " frameId:" << iterProcessData->second->iFrameId << " NUM 框因非连续识别而过滤"; it = pPostDataPre->vecPostSubData.erase(it); continue; } if (iterSpaceContinueCnt->second < 2 && it->iTargetType == SPACE) { LogDebug << " frameId:" << iterProcessData->second->iFrameId << " SPACE 框因非连续识别而过滤"; it = pPostDataPre->vecPostSubData.erase(it); continue; } if (iterTranSpaceContinueCnt->second < 2 && it->iTargetType == TRAINSPACE) { LogDebug << " frameId:" << iterProcessData->second->iFrameId << " TRAINSPACE 框因非连续识别而过滤"; it = pPostDataPre->vecPostSubData.erase(it); continue; } it++; } //判定行驶方向, 记录Direction文件信息 if (iDirection_ == DIRECTION_UNKNOWN) { iDirection_ = iterProcessData->second->iDirection; LogInfo << "方向:" << (iDirection_ == DIRECTION_LEFT ? "左" : (iDirection_ == DIRECTION_RIGHT ? "右" : "未判断出来")); if (iDirection_ == DIRECTION_UNKNOWN) { //CalculateDirection(iterProcessData->second); CalculateDirectionNew(iterProcessData->second); if (iDirection_ != DIRECTION_UNKNOWN) this->sendComeTrain(pProcessData->strTrainDate, pProcessData->strTrainName, iDirection_); } if (iDirection_ != DIRECTION_UNKNOWN) { auto iterPostDataFrist = mapPostDataFrist_.find(pProcessData->iDataSource); Json::Value jvDirectionInfo; jvDirectionInfo["direction"] = iDirection_; jvDirectionInfo["firstStep1Cnt"] = iterPostDataFrist->second.vecPostSubData.size(); jvDirectionInfo["frameid"] = iterProcessData->second->iFrameId; jvDirectionInfo["sourceid"] = iterProcessData->second->iDataSource; std::string strFilePath = strResultPath_ + pProcessData->strTrainDate + "/" + pProcessData->strTrainName + "/" + "direction.txt"; MyUtils::getins()->WriteJsonInfo(jvDirectionInfo, strFilePath); } } //主摄像头校验是否停车 int iTrainStatusTemp = iTrainStatus_; if (iterProcessData->second->iDataSource == 0) { iTrainStatus_ = GetTrainStatus(iterProcessData->second); iTrainStatusTemp = iTrainStatus_; if (iTrainStatus_ == TRAINSTATUS_STOP) { //停车 } else if (iTrainStatus_ == TRAINSTATUS_BACK) { //倒车 AddBackInfo(iterProcessData->second); iTrainStatusTemp = TRAINSTATUS_STOP; } else if(iTrainStatus_ == TRAINSTATUS_RUN) { /* 正向行驶需先把倒车产生的倒车数据处理完毕,即使车辆回到原倒车点,再开始识别行驶数据 */ if(!IsEndDealBackInfo(iterProcessData->second)) { iTrainStatusTemp = TRAINSTATUS_STOP; } } } LogDebug << "数据源:" << iterProcessData->second->iDataSource << " 帧:" << iterProcessData->second->iFrameId << " 火车实时运行状态:" << iTrainStatus_ << "(0无车,1运行,2停车,3倒车) iTrainStatusTemp:" << iTrainStatusTemp; iterProcessData->second->iStatus = iTrainStatusTemp; // this->sendComeTrain(pProcessData->strTrainDate, pProcessData->strTrainName, iDirection_); //上一帧,push端口0 PushData(strPort0_, iterProcessData->second); } APP_ERROR FilterTrainStepOneEngine::Process() { int iRet = APP_ERR_OK; while (!isStop_) { std::shared_ptr pVoidData0 = nullptr; inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); //1ms continue; } std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); // //停止后再次行驶,把队列中多余的数据丢弃。 // if (iReRunOrigFrameId_ != 0 && pProcessData->iOrigFrameId > iReRunOrigFrameId_ && !pProcessData->bIsEnd) // { // LogDebug << "reRunOrigFrameId:" << iReRunOrigFrameId_ << " origFrameId:" << pProcessData->iOrigFrameId; // continue; // } if (pProcessData->bIsEnd) { mapDataSourceIsEnd_[pProcessData->iDataSource] = pProcessData->bIsEnd; } //1帧暂时最多识别4个大框。[(车头、车厢间隔、间隔、车号); (车号、车厢间隔、间隔、属性)] if (pPostData->vecPostSubData.size() > 4) { LogError << "sourceid:" << pProcessData->iDataSource << " frameId:" << pProcessData->iFrameId << " vecpostsubdata size:" << pPostData->vecPostSubData.size(); pPostData->vecPostSubData.clear(); } //按指定识别区域过滤误识别信息--过滤逻辑迁移至TrainStepOneEngine中。 //根据当前帧数据,处理上一帧数据 DealProcessDataPre(pProcessData); mapProcessDataPre_[pProcessData->iDataSource] = pProcessData; if (pProcessData->bIsEnd) { //结束帧,push端口0 LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " isEnd:" << pProcessData->bIsEnd; PushData(strPort0_, pProcessData); } //3. 全部结束,初始化相关参数 bool bAllEnd = true; for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) { bAllEnd = bAllEnd && iter->second; } if (bAllEnd) { LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " bAllEnd"; InitParam(); } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.h b/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.h index 0db6e51..432b8b3 100644 --- a/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.h +++ b/nvidia_ascend_engine/common_engine/FilterEngine/FilterTrainStepOneEngine.h @@ -62,7 +62,7 @@ private: int rightFirst_; // 向右行驶的在前大框类型 int leftFirst_; // 向左行驶的在前大框类型 int iPartitionFrameNum_; //满足跨车厢的帧间隔 - int iPlitFrameSpanPX_; //相连帧 同种大框的跨度最大值 + int iPlitFrameSpanPX_; //相连帧 同种大框的跨度最大值 std::map mapPostDataFrist_; //[key-数据源id, value-第一步识别信息] std::map>> mapMapStep1Info_; //[key-数据源id, value-[key-识别目标, value-识别框集合]] diff --git a/nvidia_ascend_engine/common_engine/GrpcEngine/GrpcEngine.cpp b/nvidia_ascend_engine/common_engine/GrpcEngine/GrpcEngine.cpp deleted file mode 100644 index 2c14191..0000000 --- a/nvidia_ascend_engine/common_engine/GrpcEngine/GrpcEngine.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* - * @Author: 张威 - * @Date: 2022-01-27 10:27:26 - * @LastEditors: your name - * @LastEditTime: 2022-02-22 15:01:51 - * @Description: gRPC接口 - * @FilePath: \lirs\code\GrpcEngine\GrpcEngine.cpp - * - * Copyright © 2022 - */ -#include "GrpcEngine.h" - -using namespace ai_matrix; - -GrpcEngine::GrpcEngine() {} - -GrpcEngine::~GrpcEngine() {} - -APP_ERROR GrpcEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - - LogInfo << "GrpcEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR GrpcEngine::DeInit() -{ - LogInfo << "GrpcEngine DeInit ok"; - return APP_ERR_OK; -} - -APP_ERROR GrpcEngine::Process() -{ - int ret = APP_ERR_OK; - while (!isStop_) - { - usleep(1000); - } - return APP_ERR_OK; -} - -/** - * 函数可以重复进入,阻塞不会影响其他请求到来 - * */ - -/** - * 识别状态控制-来车 - * @description: - * @param {ServerContext} *context - * @param {Request} *request - * @param {Reply} *reply - * @return {*} - */ -Status GrpcEngine::Come(ServerContext *context, const Request *request, Reply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现 - std::shared_ptr pstrCommand = std::make_shared("start"); - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pstrCommand)); - return Status::OK; -} - -/** - * 识别状态控制-车走 - * @description: - * @param {ServerContext} *context - * @param {Request} *request - * @param {Reply} *reply - * @return {*} - */ -Status GrpcEngine::Leave(ServerContext *context, const Request *request, Reply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现 - std::shared_ptr pstrCommand = std::make_shared("end"); - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pstrCommand)); - - return Status::OK; -} - -/** - * 识别状态控制-停车 - * @description: - * @param {ServerContext} *context - * @param {Request} *request - * @param {Reply} *reply - * @return {*} - */ -Status GrpcEngine::TemporaryStop(ServerContext *context, const Request *request, Reply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现 - - return Status::OK; -} - -/** - * 识别状态控制-倒车 - * @description: - * @param {ServerContext} *context - * @param {Request} *request - * @param {Reply} *reply - * @return {*} - */ -Status GrpcEngine::Reversing(ServerContext *context, const Request *request, Reply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现 - std::shared_ptr pstrCommand = std::make_shared("back"); - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pstrCommand)); - - return Status::OK; -} - -/** - * 查看“工作站设置” - * @description: - * @param {ServerContext} *context - * @param {QueryWorkstationRequest} *request - * @param {QueryWorkstationReply} *reply - * @return {*} - */ -Status GrpcEngine::QueryWorkstation(ServerContext *context, const QueryWorkstationRequest *request, QueryWorkstationReply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现看后续是否要改 - - try - { - reply->set_name_no(MyYaml::GetIns()->GetStringValue("atlas_poundno")); - } - catch(const std::exception& e) - { - reply->set_error_msg("查询失败!配置参数读取异常!"); - } - - return Status::OK; -} - -/** - * 修改“工作站设置” - * @description: - * @param {ServerContext} *context - * @param {UpdateWorkstationRequest} *request - * @param {UpdateWorkstationReply} *reply - * @return {*} - */ -Status GrpcEngine::UpdateWorkstation(ServerContext *context, const UpdateWorkstationRequest *request, UpdateWorkstationReply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现 - - return Status::OK; -} - -/** - * 查询摄像头配置 - * @description: - * @param {ServerContext} *context - * @param {QueryCameraRequest} *request - * @param {QueryCameraReply} *reply - * @return {*} - */ -Status GrpcEngine::QueryCamera(ServerContext *context, const QueryCameraRequest *request, QueryCameraReply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现看后续是否要改 - ai_matrix::DataSourceConfig dataSourceConfig_; - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(request->channel_id()); //获取摄像机参数 - - reply->set_channel_id(request->channel_id()); - reply->set_use(dataSourceConfig_.bUse); - reply->set_url(dataSourceConfig_.strUrl); - reply->set_skipinterval(dataSourceConfig_.iSkipInterval); - reply->set_direction(dataSourceConfig_.iDirection); - reply->set_left_first(dataSourceConfig_.iLeftFirst); - reply->set_right_first(dataSourceConfig_.iRightFirst); - - return Status::OK; -} - -/** - * 修改摄像头配置 - * @description: - * @param {ServerContext} *context - * @param {UpdateCameraRequest} *request - * @param {UpdateCameraReply} *reply - * @return {*} - */ -Status GrpcEngine::UpdateCamera(ServerContext *context, const UpdateCameraRequest *request, UpdateCameraReply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现 - - - return Status::OK; -} - -/** - * 查询FTP的配置 - * @description: - * @param {ServerContext} *context - * @param {QueryFTPRequest} *request - * @param {QueryFTPReply} *reply - * @return {*} - */ -Status GrpcEngine::QueryFTP(ServerContext *context, const QueryFTPRequest *request, QueryFTPReply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现看后续是否需要改动 - try - { - reply->set_open(MyYaml::GetIns()->GetIntValue("gc_ftp_open")); - reply->set_username(MyYaml::GetIns()->GetStringValue("gc_ftp_username")); - reply->set_password(MyYaml::GetIns()->GetStringValue("gc_ftp_password")); - reply->set_ip(MyYaml::GetIns()->GetStringValue("gc_ftp_ip")); - reply->set_port(MyYaml::GetIns()->GetIntValue("gc_ftp_port")); - reply->set_image_path(MyYaml::GetIns()->GetStringValue("gc_ftp_image_path")); - reply->set_quit_time(MyYaml::GetIns()->GetIntValue("gc_ftp_quit_time")); - } - catch (const std::exception& e) - { - reply->set_error_msg("查询失败!配置参数读取异常!"); - } - - return Status::OK; -} - -/** - * 修改FTP的配置 - * @description: - * @param {ServerContext} *context - * @param {UpdateFTPRequest} *request - * @param {UpdateFTPReply} *reply - * @return {*} - */ -Status GrpcEngine::UpdateFTP(ServerContext *context, const UpdateFTPRequest *request, UpdateFTPReply *reply) -{ - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - //TODO(zhangwei):具体实现 - - - return Status::OK; -} - -/** - * 重启识别程序 - * @description: - * @param {ServerContext} *context - * @param {Request} *request - * @param {Reply} *reply - * @return {*} - */ -Status GrpcEngine::RebootAI(ServerContext *context, const Request *request, Reply *reply) -{ - LogInfo << "Restart >>> head:" << request->head(); - - //验证请求头 - if (request->head() != this->HEAD) - { - reply->set_error_msg(" head: \"" + std::to_string(request->head()) + "\" permission denied !"); - return Status::OK; - } - - pthread_t id; - int ret = pthread_create(&id, NULL, system_restart, NULL); - - if (ret != 0) - { - reply->set_error_msg("小站重启失败!"); - } - - return Status::OK; -} - -// 线程的运行函数 -void* GrpcEngine::system_restart(void* args) -{ - - sleep(2); - - system("reboot"); - return 0; -} \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/GrpcEngine/GrpcEngine.h b/nvidia_ascend_engine/common_engine/GrpcEngine/GrpcEngine.h deleted file mode 100644 index 55d7c99..0000000 --- a/nvidia_ascend_engine/common_engine/GrpcEngine/GrpcEngine.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * @Author: your name - * @Date: 2022-01-27 10:27:26 - * @LastEditors: your name - * @LastEditTime: 2022-02-17 10:40:16 - * @Description: file content - * @FilePath: \lirs\code\GrpcEngine\GrpcEngine.h - * - * Copyright © 2022 - */ -/** - * grpc微服务接口 - * */ - -#ifndef GRPC_ENGINE_H -#define GRPC_ENGINE_H - -#include -#include -#include - -#include "grpcservice.grpc.pb.h" - -#include "AppCommon.h" - -using grpc::Server; -using grpc::ServerBuilder; -using grpc::ServerContext; -using grpc::Status; -using grpc::StatusCode; - -using MatrixAi::Train; -using MatrixAi::Request; -using MatrixAi::Reply; -using MatrixAi::QueryWorkstationRequest; -using MatrixAi::QueryWorkstationReply; -using MatrixAi::UpdateWorkstationRequest; -using MatrixAi::UpdateWorkstationReply; -using MatrixAi::QueryCameraRequest; -using MatrixAi::QueryCameraReply; -using MatrixAi::UpdateCameraRequest; -using MatrixAi::UpdateCameraReply; -using MatrixAi::QueryFTPRequest; -using MatrixAi::QueryFTPReply; -using MatrixAi::UpdateFTPRequest; -using MatrixAi::UpdateFTPReply; - -#include "EngineBase.h" -#include "EngineFactory.h" -#include "MyYaml.h" - -class GrpcEngine : public ai_matrix::EngineBase, public Train::Service -{ -public: - GrpcEngine(); - ~GrpcEngine(); - - APP_ERROR Init() override; - APP_ERROR DeInit() override; - APP_ERROR Process() override; - - //识别状态控制-来车 - Status Come(ServerContext *context, const Request *request,Reply *reply); - - //识别状态控制-车走 - Status Leave(ServerContext *context, const Request *request, Reply *reply); - - //识别状态控制-停车 - Status TemporaryStop(ServerContext *context, const Request *request,Reply *reply); - - //识别状态控制-倒车 - Status Reversing(ServerContext *context, const Request *request, Reply *reply); - - //查看“工作站设置” - Status QueryWorkstation(ServerContext *context, const QueryWorkstationRequest *request, QueryWorkstationReply *reply); - - //修改“工作站设置” - Status UpdateWorkstation(ServerContext *context, const UpdateWorkstationRequest *request, UpdateWorkstationReply *reply); - - //查询摄像头配置 - Status QueryCamera(ServerContext *context, const QueryCameraRequest *request, QueryCameraReply *reply); - - //修改摄像头配置 - Status UpdateCamera(ServerContext *context, const UpdateCameraRequest *request, UpdateCameraReply *reply); - - //查询FTP的配置 - Status QueryFTP(ServerContext *context, const QueryFTPRequest *request, QueryFTPReply *reply); - - //修改FTP的配置 - Status UpdateFTP(ServerContext *context, const UpdateFTPRequest *request, UpdateFTPReply *reply); - - //重启识别程序 - Status RebootAI(ServerContext *context, const Request *request, Reply *reply); -private: - std::string strPort0_; - - //接口调用必须的命令标志 - const int HEAD = 0x7d; - - // 线程的运行函数 - static void* system_restart(void* args); -}; - -ENGINE_REGIST(GrpcEngine) - -#endif \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.grpc.pb.cpp b/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.grpc.pb.cpp deleted file mode 100644 index 5a37c56..0000000 --- a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.grpc.pb.cpp +++ /dev/null @@ -1,506 +0,0 @@ -// Generated by the gRPC C++ plugin. -// If you make any local change, they will be lost. -// source: grpcservice.proto - -#include "grpcservice.pb.h" -#include "grpcservice.grpc.pb.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -namespace MatrixAi { - -static const char* Train_method_names[] = { - "/MatrixAi.Train/Come", - "/MatrixAi.Train/Leave", - "/MatrixAi.Train/TemporaryStop", - "/MatrixAi.Train/Reversing", - "/MatrixAi.Train/QueryWorkstation", - "/MatrixAi.Train/UpdateWorkstation", - "/MatrixAi.Train/QueryCamera", - "/MatrixAi.Train/UpdateCamera", - "/MatrixAi.Train/QueryFTP", - "/MatrixAi.Train/UpdateFTP", - "/MatrixAi.Train/RebootAI", -}; - -std::unique_ptr< Train::Stub> Train::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) { - (void)options; - std::unique_ptr< Train::Stub> stub(new Train::Stub(channel)); - return stub; -} - -Train::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel) - : channel_(channel), rpcmethod_Come_(Train_method_names[0], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_Leave_(Train_method_names[1], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_TemporaryStop_(Train_method_names[2], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_Reversing_(Train_method_names[3], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_QueryWorkstation_(Train_method_names[4], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_UpdateWorkstation_(Train_method_names[5], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_QueryCamera_(Train_method_names[6], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_UpdateCamera_(Train_method_names[7], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_QueryFTP_(Train_method_names[8], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_UpdateFTP_(Train_method_names[9], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - , rpcmethod_RebootAI_(Train_method_names[10], ::grpc::internal::RpcMethod::NORMAL_RPC, channel) - {} - -::grpc::Status Train::Stub::Come(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_Come_, context, request, response); -} - -void Train::Stub::experimental_async::Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Come_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Come_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::PrepareAsyncComeRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::Reply, ::MatrixAi::Request, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_Come_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::AsyncComeRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncComeRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::Leave(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_Leave_, context, request, response); -} - -void Train::Stub::experimental_async::Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Leave_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Leave_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::PrepareAsyncLeaveRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::Reply, ::MatrixAi::Request, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_Leave_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::AsyncLeaveRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncLeaveRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_TemporaryStop_, context, request, response); -} - -void Train::Stub::experimental_async::TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_TemporaryStop_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_TemporaryStop_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::PrepareAsyncTemporaryStopRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::Reply, ::MatrixAi::Request, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_TemporaryStop_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::AsyncTemporaryStopRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncTemporaryStopRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_Reversing_, context, request, response); -} - -void Train::Stub::experimental_async::Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Reversing_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_Reversing_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::PrepareAsyncReversingRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::Reply, ::MatrixAi::Request, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_Reversing_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::AsyncReversingRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncReversingRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::MatrixAi::QueryWorkstationReply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_QueryWorkstation_, context, request, response); -} - -void Train::Stub::experimental_async::QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_QueryWorkstation_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_QueryWorkstation_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>* Train::Stub::PrepareAsyncQueryWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::QueryWorkstationReply, ::MatrixAi::QueryWorkstationRequest, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_QueryWorkstation_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>* Train::Stub::AsyncQueryWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncQueryWorkstationRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::MatrixAi::UpdateWorkstationReply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_UpdateWorkstation_, context, request, response); -} - -void Train::Stub::experimental_async::UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_UpdateWorkstation_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_UpdateWorkstation_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>* Train::Stub::PrepareAsyncUpdateWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::UpdateWorkstationReply, ::MatrixAi::UpdateWorkstationRequest, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_UpdateWorkstation_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>* Train::Stub::AsyncUpdateWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncUpdateWorkstationRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::MatrixAi::QueryCameraReply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_QueryCamera_, context, request, response); -} - -void Train::Stub::experimental_async::QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_QueryCamera_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_QueryCamera_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>* Train::Stub::PrepareAsyncQueryCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::QueryCameraReply, ::MatrixAi::QueryCameraRequest, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_QueryCamera_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>* Train::Stub::AsyncQueryCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncQueryCameraRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::MatrixAi::UpdateCameraReply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_UpdateCamera_, context, request, response); -} - -void Train::Stub::experimental_async::UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_UpdateCamera_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_UpdateCamera_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>* Train::Stub::PrepareAsyncUpdateCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::UpdateCameraReply, ::MatrixAi::UpdateCameraRequest, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_UpdateCamera_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>* Train::Stub::AsyncUpdateCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncUpdateCameraRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::MatrixAi::QueryFTPReply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_QueryFTP_, context, request, response); -} - -void Train::Stub::experimental_async::QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_QueryFTP_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_QueryFTP_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>* Train::Stub::PrepareAsyncQueryFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::QueryFTPReply, ::MatrixAi::QueryFTPRequest, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_QueryFTP_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>* Train::Stub::AsyncQueryFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncQueryFTPRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::MatrixAi::UpdateFTPReply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_UpdateFTP_, context, request, response); -} - -void Train::Stub::experimental_async::UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_UpdateFTP_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_UpdateFTP_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>* Train::Stub::PrepareAsyncUpdateFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::UpdateFTPReply, ::MatrixAi::UpdateFTPRequest, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_UpdateFTP_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>* Train::Stub::AsyncUpdateFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncUpdateFTPRaw(context, request, cq); - result->StartCall(); - return result; -} - -::grpc::Status Train::Stub::RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) { - return ::grpc::internal::BlockingUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), rpcmethod_RebootAI_, context, request, response); -} - -void Train::Stub::experimental_async::RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function f) { - ::grpc::internal::CallbackUnaryCall< ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_RebootAI_, context, request, response, std::move(f)); -} - -void Train::Stub::experimental_async::RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) { - ::grpc::internal::ClientCallbackUnaryFactory::Create< ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(stub_->channel_.get(), stub_->rpcmethod_RebootAI_, context, request, response, reactor); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::PrepareAsyncRebootAIRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return ::grpc::internal::ClientAsyncResponseReaderHelper::Create< ::MatrixAi::Reply, ::MatrixAi::Request, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>(channel_.get(), cq, rpcmethod_RebootAI_, context, request); -} - -::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* Train::Stub::AsyncRebootAIRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - auto* result = - this->PrepareAsyncRebootAIRaw(context, request, cq); - result->StartCall(); - return result; -} - -Train::Service::Service() { - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[0], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::Request* req, - ::MatrixAi::Reply* resp) { - return service->Come(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[1], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::Request* req, - ::MatrixAi::Reply* resp) { - return service->Leave(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[2], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::Request* req, - ::MatrixAi::Reply* resp) { - return service->TemporaryStop(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[3], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::Request* req, - ::MatrixAi::Reply* resp) { - return service->Reversing(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[4], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::QueryWorkstationRequest* req, - ::MatrixAi::QueryWorkstationReply* resp) { - return service->QueryWorkstation(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[5], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::UpdateWorkstationRequest* req, - ::MatrixAi::UpdateWorkstationReply* resp) { - return service->UpdateWorkstation(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[6], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::QueryCameraRequest* req, - ::MatrixAi::QueryCameraReply* resp) { - return service->QueryCamera(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[7], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::UpdateCameraRequest* req, - ::MatrixAi::UpdateCameraReply* resp) { - return service->UpdateCamera(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[8], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::QueryFTPRequest* req, - ::MatrixAi::QueryFTPReply* resp) { - return service->QueryFTP(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[9], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::UpdateFTPRequest* req, - ::MatrixAi::UpdateFTPReply* resp) { - return service->UpdateFTP(ctx, req, resp); - }, this))); - AddMethod(new ::grpc::internal::RpcServiceMethod( - Train_method_names[10], - ::grpc::internal::RpcMethod::NORMAL_RPC, - new ::grpc::internal::RpcMethodHandler< Train::Service, ::MatrixAi::Request, ::MatrixAi::Reply, ::grpc::protobuf::MessageLite, ::grpc::protobuf::MessageLite>( - [](Train::Service* service, - ::grpc::ServerContext* ctx, - const ::MatrixAi::Request* req, - ::MatrixAi::Reply* resp) { - return service->RebootAI(ctx, req, resp); - }, this))); -} - -Train::Service::~Service() { -} - -::grpc::Status Train::Service::Come(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::Leave(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::TemporaryStop(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::Reversing(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::QueryWorkstation(::grpc::ServerContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::UpdateWorkstation(::grpc::ServerContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::QueryCamera(::grpc::ServerContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::UpdateCamera(::grpc::ServerContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::QueryFTP(::grpc::ServerContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::UpdateFTP(::grpc::ServerContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - -::grpc::Status Train::Service::RebootAI(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { - (void) context; - (void) request; - (void) response; - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); -} - - -} // namespace MatrixAi - diff --git a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.grpc.pb.h b/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.grpc.pb.h deleted file mode 100644 index 5103f35..0000000 --- a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.grpc.pb.h +++ /dev/null @@ -1,2335 +0,0 @@ -// Generated by the gRPC C++ plugin. -// If you make any local change, they will be lost. -// source: grpcservice.proto -#ifndef GRPC_grpcservice_2eproto__INCLUDED -#define GRPC_grpcservice_2eproto__INCLUDED - -#include "grpcservice.pb.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace MatrixAi { - -class Train final { - public: - static constexpr char const* service_full_name() { - return "MatrixAi.Train"; - } - class StubInterface { - public: - virtual ~StubInterface() {} - // 识别状态控制-来车 - virtual ::grpc::Status Come(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> AsyncCome(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(AsyncComeRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> PrepareAsyncCome(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(PrepareAsyncComeRaw(context, request, cq)); - } - // 识别状态控制-车走 - virtual ::grpc::Status Leave(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> AsyncLeave(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(AsyncLeaveRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> PrepareAsyncLeave(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(PrepareAsyncLeaveRaw(context, request, cq)); - } - // 识别状态控制-停车 - virtual ::grpc::Status TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> AsyncTemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(AsyncTemporaryStopRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> PrepareAsyncTemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(PrepareAsyncTemporaryStopRaw(context, request, cq)); - } - // 识别状态控制-倒车 - virtual ::grpc::Status Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> AsyncReversing(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(AsyncReversingRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> PrepareAsyncReversing(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(PrepareAsyncReversingRaw(context, request, cq)); - } - // 查看“工作站设置” - virtual ::grpc::Status QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::MatrixAi::QueryWorkstationReply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryWorkstationReply>> AsyncQueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryWorkstationReply>>(AsyncQueryWorkstationRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryWorkstationReply>> PrepareAsyncQueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryWorkstationReply>>(PrepareAsyncQueryWorkstationRaw(context, request, cq)); - } - // 修改“工作站设置” - virtual ::grpc::Status UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::MatrixAi::UpdateWorkstationReply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateWorkstationReply>> AsyncUpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateWorkstationReply>>(AsyncUpdateWorkstationRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateWorkstationReply>> PrepareAsyncUpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateWorkstationReply>>(PrepareAsyncUpdateWorkstationRaw(context, request, cq)); - } - // 查询摄像头配置 - virtual ::grpc::Status QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::MatrixAi::QueryCameraReply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryCameraReply>> AsyncQueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryCameraReply>>(AsyncQueryCameraRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryCameraReply>> PrepareAsyncQueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryCameraReply>>(PrepareAsyncQueryCameraRaw(context, request, cq)); - } - // 修改摄像头配置 - virtual ::grpc::Status UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::MatrixAi::UpdateCameraReply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateCameraReply>> AsyncUpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateCameraReply>>(AsyncUpdateCameraRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateCameraReply>> PrepareAsyncUpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateCameraReply>>(PrepareAsyncUpdateCameraRaw(context, request, cq)); - } - // 查询FTP的配置 - virtual ::grpc::Status QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::MatrixAi::QueryFTPReply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryFTPReply>> AsyncQueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryFTPReply>>(AsyncQueryFTPRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryFTPReply>> PrepareAsyncQueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryFTPReply>>(PrepareAsyncQueryFTPRaw(context, request, cq)); - } - // 修改FTP的配置 - virtual ::grpc::Status UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::MatrixAi::UpdateFTPReply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateFTPReply>> AsyncUpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateFTPReply>>(AsyncUpdateFTPRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateFTPReply>> PrepareAsyncUpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateFTPReply>>(PrepareAsyncUpdateFTPRaw(context, request, cq)); - } - // 重启识别程序 - virtual ::grpc::Status RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) = 0; - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> AsyncRebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(AsyncRebootAIRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>> PrepareAsyncRebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>>(PrepareAsyncRebootAIRaw(context, request, cq)); - } - class experimental_async_interface { - public: - virtual ~experimental_async_interface() {} - // 识别状态控制-来车 - virtual void Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 识别状态控制-车走 - virtual void Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 识别状态控制-停车 - virtual void TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 识别状态控制-倒车 - virtual void Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 查看“工作站设置” - virtual void QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 修改“工作站设置” - virtual void UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 查询摄像头配置 - virtual void QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 修改摄像头配置 - virtual void UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 查询FTP的配置 - virtual void QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 修改FTP的配置 - virtual void UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - // 重启识别程序 - virtual void RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) = 0; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual void RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) = 0; - #else - virtual void RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) = 0; - #endif - }; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - typedef class experimental_async_interface async_interface; - #endif - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - async_interface* async() { return experimental_async(); } - #endif - virtual class experimental_async_interface* experimental_async() { return nullptr; } - private: - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* AsyncComeRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* PrepareAsyncComeRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* AsyncLeaveRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* PrepareAsyncLeaveRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* AsyncTemporaryStopRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* PrepareAsyncTemporaryStopRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* AsyncReversingRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* PrepareAsyncReversingRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryWorkstationReply>* AsyncQueryWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryWorkstationReply>* PrepareAsyncQueryWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateWorkstationReply>* AsyncUpdateWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateWorkstationReply>* PrepareAsyncUpdateWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryCameraReply>* AsyncQueryCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryCameraReply>* PrepareAsyncQueryCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateCameraReply>* AsyncUpdateCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateCameraReply>* PrepareAsyncUpdateCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryFTPReply>* AsyncQueryFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::QueryFTPReply>* PrepareAsyncQueryFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateFTPReply>* AsyncUpdateFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::UpdateFTPReply>* PrepareAsyncUpdateFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* AsyncRebootAIRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - virtual ::grpc::ClientAsyncResponseReaderInterface< ::MatrixAi::Reply>* PrepareAsyncRebootAIRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) = 0; - }; - class Stub final : public StubInterface { - public: - Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel); - ::grpc::Status Come(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> AsyncCome(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(AsyncComeRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> PrepareAsyncCome(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(PrepareAsyncComeRaw(context, request, cq)); - } - ::grpc::Status Leave(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> AsyncLeave(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(AsyncLeaveRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> PrepareAsyncLeave(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(PrepareAsyncLeaveRaw(context, request, cq)); - } - ::grpc::Status TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> AsyncTemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(AsyncTemporaryStopRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> PrepareAsyncTemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(PrepareAsyncTemporaryStopRaw(context, request, cq)); - } - ::grpc::Status Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> AsyncReversing(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(AsyncReversingRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> PrepareAsyncReversing(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(PrepareAsyncReversingRaw(context, request, cq)); - } - ::grpc::Status QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::MatrixAi::QueryWorkstationReply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>> AsyncQueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>>(AsyncQueryWorkstationRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>> PrepareAsyncQueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>>(PrepareAsyncQueryWorkstationRaw(context, request, cq)); - } - ::grpc::Status UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::MatrixAi::UpdateWorkstationReply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>> AsyncUpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>>(AsyncUpdateWorkstationRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>> PrepareAsyncUpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>>(PrepareAsyncUpdateWorkstationRaw(context, request, cq)); - } - ::grpc::Status QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::MatrixAi::QueryCameraReply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>> AsyncQueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>>(AsyncQueryCameraRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>> PrepareAsyncQueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>>(PrepareAsyncQueryCameraRaw(context, request, cq)); - } - ::grpc::Status UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::MatrixAi::UpdateCameraReply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>> AsyncUpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>>(AsyncUpdateCameraRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>> PrepareAsyncUpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>>(PrepareAsyncUpdateCameraRaw(context, request, cq)); - } - ::grpc::Status QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::MatrixAi::QueryFTPReply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>> AsyncQueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>>(AsyncQueryFTPRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>> PrepareAsyncQueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>>(PrepareAsyncQueryFTPRaw(context, request, cq)); - } - ::grpc::Status UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::MatrixAi::UpdateFTPReply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>> AsyncUpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>>(AsyncUpdateFTPRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>> PrepareAsyncUpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>>(PrepareAsyncUpdateFTPRaw(context, request, cq)); - } - ::grpc::Status RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::MatrixAi::Reply* response) override; - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> AsyncRebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(AsyncRebootAIRaw(context, request, cq)); - } - std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>> PrepareAsyncRebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) { - return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>>(PrepareAsyncRebootAIRaw(context, request, cq)); - } - class experimental_async final : - public StubInterface::experimental_async_interface { - public: - void Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void Come(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void Leave(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void TemporaryStop(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void Reversing(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void QueryWorkstation(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void UpdateWorkstation(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void QueryCamera(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void UpdateCamera(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void QueryFTP(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void UpdateFTP(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - void RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, std::function) override; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - void RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::ClientUnaryReactor* reactor) override; - #else - void RebootAI(::grpc::ClientContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response, ::grpc::experimental::ClientUnaryReactor* reactor) override; - #endif - private: - friend class Stub; - explicit experimental_async(Stub* stub): stub_(stub) { } - Stub* stub() { return stub_; } - Stub* stub_; - }; - class experimental_async_interface* experimental_async() override { return &async_stub_; } - - private: - std::shared_ptr< ::grpc::ChannelInterface> channel_; - class experimental_async async_stub_{this}; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* AsyncComeRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* PrepareAsyncComeRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* AsyncLeaveRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* PrepareAsyncLeaveRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* AsyncTemporaryStopRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* PrepareAsyncTemporaryStopRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* AsyncReversingRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* PrepareAsyncReversingRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>* AsyncQueryWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryWorkstationReply>* PrepareAsyncQueryWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryWorkstationRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>* AsyncUpdateWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateWorkstationReply>* PrepareAsyncUpdateWorkstationRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateWorkstationRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>* AsyncQueryCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryCameraReply>* PrepareAsyncQueryCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryCameraRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>* AsyncUpdateCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateCameraReply>* PrepareAsyncUpdateCameraRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateCameraRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>* AsyncQueryFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::QueryFTPReply>* PrepareAsyncQueryFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::QueryFTPRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>* AsyncUpdateFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::UpdateFTPReply>* PrepareAsyncUpdateFTPRaw(::grpc::ClientContext* context, const ::MatrixAi::UpdateFTPRequest& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* AsyncRebootAIRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - ::grpc::ClientAsyncResponseReader< ::MatrixAi::Reply>* PrepareAsyncRebootAIRaw(::grpc::ClientContext* context, const ::MatrixAi::Request& request, ::grpc::CompletionQueue* cq) override; - const ::grpc::internal::RpcMethod rpcmethod_Come_; - const ::grpc::internal::RpcMethod rpcmethod_Leave_; - const ::grpc::internal::RpcMethod rpcmethod_TemporaryStop_; - const ::grpc::internal::RpcMethod rpcmethod_Reversing_; - const ::grpc::internal::RpcMethod rpcmethod_QueryWorkstation_; - const ::grpc::internal::RpcMethod rpcmethod_UpdateWorkstation_; - const ::grpc::internal::RpcMethod rpcmethod_QueryCamera_; - const ::grpc::internal::RpcMethod rpcmethod_UpdateCamera_; - const ::grpc::internal::RpcMethod rpcmethod_QueryFTP_; - const ::grpc::internal::RpcMethod rpcmethod_UpdateFTP_; - const ::grpc::internal::RpcMethod rpcmethod_RebootAI_; - }; - static std::unique_ptr NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions()); - - class Service : public ::grpc::Service { - public: - Service(); - virtual ~Service(); - // 识别状态控制-来车 - virtual ::grpc::Status Come(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response); - // 识别状态控制-车走 - virtual ::grpc::Status Leave(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response); - // 识别状态控制-停车 - virtual ::grpc::Status TemporaryStop(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response); - // 识别状态控制-倒车 - virtual ::grpc::Status Reversing(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response); - // 查看“工作站设置” - virtual ::grpc::Status QueryWorkstation(::grpc::ServerContext* context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response); - // 修改“工作站设置” - virtual ::grpc::Status UpdateWorkstation(::grpc::ServerContext* context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response); - // 查询摄像头配置 - virtual ::grpc::Status QueryCamera(::grpc::ServerContext* context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response); - // 修改摄像头配置 - virtual ::grpc::Status UpdateCamera(::grpc::ServerContext* context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response); - // 查询FTP的配置 - virtual ::grpc::Status QueryFTP(::grpc::ServerContext* context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response); - // 修改FTP的配置 - virtual ::grpc::Status UpdateFTP(::grpc::ServerContext* context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response); - // 重启识别程序 - virtual ::grpc::Status RebootAI(::grpc::ServerContext* context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response); - }; - template - class WithAsyncMethod_Come : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_Come() { - ::grpc::Service::MarkMethodAsync(0); - } - ~WithAsyncMethod_Come() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Come(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestCome(::grpc::ServerContext* context, ::MatrixAi::Request* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::Reply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_Leave : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_Leave() { - ::grpc::Service::MarkMethodAsync(1); - } - ~WithAsyncMethod_Leave() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Leave(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestLeave(::grpc::ServerContext* context, ::MatrixAi::Request* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::Reply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(1, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_TemporaryStop : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_TemporaryStop() { - ::grpc::Service::MarkMethodAsync(2); - } - ~WithAsyncMethod_TemporaryStop() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status TemporaryStop(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestTemporaryStop(::grpc::ServerContext* context, ::MatrixAi::Request* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::Reply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(2, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_Reversing : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_Reversing() { - ::grpc::Service::MarkMethodAsync(3); - } - ~WithAsyncMethod_Reversing() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Reversing(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestReversing(::grpc::ServerContext* context, ::MatrixAi::Request* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::Reply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(3, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_QueryWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_QueryWorkstation() { - ::grpc::Service::MarkMethodAsync(4); - } - ~WithAsyncMethod_QueryWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestQueryWorkstation(::grpc::ServerContext* context, ::MatrixAi::QueryWorkstationRequest* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::QueryWorkstationReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(4, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_UpdateWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_UpdateWorkstation() { - ::grpc::Service::MarkMethodAsync(5); - } - ~WithAsyncMethod_UpdateWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestUpdateWorkstation(::grpc::ServerContext* context, ::MatrixAi::UpdateWorkstationRequest* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::UpdateWorkstationReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(5, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_QueryCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_QueryCamera() { - ::grpc::Service::MarkMethodAsync(6); - } - ~WithAsyncMethod_QueryCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestQueryCamera(::grpc::ServerContext* context, ::MatrixAi::QueryCameraRequest* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::QueryCameraReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(6, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_UpdateCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_UpdateCamera() { - ::grpc::Service::MarkMethodAsync(7); - } - ~WithAsyncMethod_UpdateCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestUpdateCamera(::grpc::ServerContext* context, ::MatrixAi::UpdateCameraRequest* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::UpdateCameraReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(7, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_QueryFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_QueryFTP() { - ::grpc::Service::MarkMethodAsync(8); - } - ~WithAsyncMethod_QueryFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestQueryFTP(::grpc::ServerContext* context, ::MatrixAi::QueryFTPRequest* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::QueryFTPReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(8, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_UpdateFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_UpdateFTP() { - ::grpc::Service::MarkMethodAsync(9); - } - ~WithAsyncMethod_UpdateFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestUpdateFTP(::grpc::ServerContext* context, ::MatrixAi::UpdateFTPRequest* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::UpdateFTPReply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(9, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithAsyncMethod_RebootAI : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithAsyncMethod_RebootAI() { - ::grpc::Service::MarkMethodAsync(10); - } - ~WithAsyncMethod_RebootAI() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status RebootAI(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestRebootAI(::grpc::ServerContext* context, ::MatrixAi::Request* request, ::grpc::ServerAsyncResponseWriter< ::MatrixAi::Reply>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(10, context, request, response, new_call_cq, notification_cq, tag); - } - }; - typedef WithAsyncMethod_Come > > > > > > > > > > AsyncService; - template - class ExperimentalWithCallbackMethod_Come : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_Come() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(0, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { return this->Come(context, request, response); }));} - void SetMessageAllocatorFor_Come( - ::grpc::experimental::MessageAllocator< ::MatrixAi::Request, ::MatrixAi::Reply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(0); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(0); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_Come() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Come(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* Come( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* Come( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_Leave : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_Leave() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(1, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { return this->Leave(context, request, response); }));} - void SetMessageAllocatorFor_Leave( - ::grpc::experimental::MessageAllocator< ::MatrixAi::Request, ::MatrixAi::Reply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(1); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(1); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_Leave() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Leave(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* Leave( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* Leave( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_TemporaryStop : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_TemporaryStop() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(2, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { return this->TemporaryStop(context, request, response); }));} - void SetMessageAllocatorFor_TemporaryStop( - ::grpc::experimental::MessageAllocator< ::MatrixAi::Request, ::MatrixAi::Reply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(2); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(2); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_TemporaryStop() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status TemporaryStop(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* TemporaryStop( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* TemporaryStop( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_Reversing : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_Reversing() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(3, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { return this->Reversing(context, request, response); }));} - void SetMessageAllocatorFor_Reversing( - ::grpc::experimental::MessageAllocator< ::MatrixAi::Request, ::MatrixAi::Reply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(3); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(3); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_Reversing() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Reversing(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* Reversing( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* Reversing( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_QueryWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_QueryWorkstation() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(4, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::QueryWorkstationRequest* request, ::MatrixAi::QueryWorkstationReply* response) { return this->QueryWorkstation(context, request, response); }));} - void SetMessageAllocatorFor_QueryWorkstation( - ::grpc::experimental::MessageAllocator< ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(4); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(4); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_QueryWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* QueryWorkstation( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* QueryWorkstation( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_UpdateWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_UpdateWorkstation() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(5, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::UpdateWorkstationRequest* request, ::MatrixAi::UpdateWorkstationReply* response) { return this->UpdateWorkstation(context, request, response); }));} - void SetMessageAllocatorFor_UpdateWorkstation( - ::grpc::experimental::MessageAllocator< ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(5); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(5); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_UpdateWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* UpdateWorkstation( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* UpdateWorkstation( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_QueryCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_QueryCamera() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(6, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::QueryCameraRequest* request, ::MatrixAi::QueryCameraReply* response) { return this->QueryCamera(context, request, response); }));} - void SetMessageAllocatorFor_QueryCamera( - ::grpc::experimental::MessageAllocator< ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(6); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(6); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_QueryCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* QueryCamera( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* QueryCamera( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_UpdateCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_UpdateCamera() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(7, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::UpdateCameraRequest* request, ::MatrixAi::UpdateCameraReply* response) { return this->UpdateCamera(context, request, response); }));} - void SetMessageAllocatorFor_UpdateCamera( - ::grpc::experimental::MessageAllocator< ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(7); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(7); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_UpdateCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* UpdateCamera( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* UpdateCamera( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_QueryFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_QueryFTP() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(8, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::QueryFTPRequest* request, ::MatrixAi::QueryFTPReply* response) { return this->QueryFTP(context, request, response); }));} - void SetMessageAllocatorFor_QueryFTP( - ::grpc::experimental::MessageAllocator< ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(8); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(8); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_QueryFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* QueryFTP( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* QueryFTP( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_UpdateFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_UpdateFTP() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(9, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::UpdateFTPRequest* request, ::MatrixAi::UpdateFTPReply* response) { return this->UpdateFTP(context, request, response); }));} - void SetMessageAllocatorFor_UpdateFTP( - ::grpc::experimental::MessageAllocator< ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(9); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(9); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_UpdateFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* UpdateFTP( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* UpdateFTP( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithCallbackMethod_RebootAI : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithCallbackMethod_RebootAI() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodCallback(10, - new ::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::MatrixAi::Request* request, ::MatrixAi::Reply* response) { return this->RebootAI(context, request, response); }));} - void SetMessageAllocatorFor_RebootAI( - ::grpc::experimental::MessageAllocator< ::MatrixAi::Request, ::MatrixAi::Reply>* allocator) { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::GetHandler(10); - #else - ::grpc::internal::MethodHandler* const handler = ::grpc::Service::experimental().GetHandler(10); - #endif - static_cast<::grpc::internal::CallbackUnaryHandler< ::MatrixAi::Request, ::MatrixAi::Reply>*>(handler) - ->SetMessageAllocator(allocator); - } - ~ExperimentalWithCallbackMethod_RebootAI() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status RebootAI(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* RebootAI( - ::grpc::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* RebootAI( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) - #endif - { return nullptr; } - }; - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - typedef ExperimentalWithCallbackMethod_Come > > > > > > > > > > CallbackService; - #endif - - typedef ExperimentalWithCallbackMethod_Come > > > > > > > > > > ExperimentalCallbackService; - template - class WithGenericMethod_Come : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_Come() { - ::grpc::Service::MarkMethodGeneric(0); - } - ~WithGenericMethod_Come() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Come(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_Leave : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_Leave() { - ::grpc::Service::MarkMethodGeneric(1); - } - ~WithGenericMethod_Leave() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Leave(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_TemporaryStop : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_TemporaryStop() { - ::grpc::Service::MarkMethodGeneric(2); - } - ~WithGenericMethod_TemporaryStop() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status TemporaryStop(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_Reversing : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_Reversing() { - ::grpc::Service::MarkMethodGeneric(3); - } - ~WithGenericMethod_Reversing() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Reversing(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_QueryWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_QueryWorkstation() { - ::grpc::Service::MarkMethodGeneric(4); - } - ~WithGenericMethod_QueryWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_UpdateWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_UpdateWorkstation() { - ::grpc::Service::MarkMethodGeneric(5); - } - ~WithGenericMethod_UpdateWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_QueryCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_QueryCamera() { - ::grpc::Service::MarkMethodGeneric(6); - } - ~WithGenericMethod_QueryCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_UpdateCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_UpdateCamera() { - ::grpc::Service::MarkMethodGeneric(7); - } - ~WithGenericMethod_UpdateCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_QueryFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_QueryFTP() { - ::grpc::Service::MarkMethodGeneric(8); - } - ~WithGenericMethod_QueryFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_UpdateFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_UpdateFTP() { - ::grpc::Service::MarkMethodGeneric(9); - } - ~WithGenericMethod_UpdateFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithGenericMethod_RebootAI : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithGenericMethod_RebootAI() { - ::grpc::Service::MarkMethodGeneric(10); - } - ~WithGenericMethod_RebootAI() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status RebootAI(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - }; - template - class WithRawMethod_Come : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_Come() { - ::grpc::Service::MarkMethodRaw(0); - } - ~WithRawMethod_Come() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Come(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestCome(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_Leave : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_Leave() { - ::grpc::Service::MarkMethodRaw(1); - } - ~WithRawMethod_Leave() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Leave(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestLeave(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(1, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_TemporaryStop : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_TemporaryStop() { - ::grpc::Service::MarkMethodRaw(2); - } - ~WithRawMethod_TemporaryStop() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status TemporaryStop(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestTemporaryStop(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(2, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_Reversing : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_Reversing() { - ::grpc::Service::MarkMethodRaw(3); - } - ~WithRawMethod_Reversing() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Reversing(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestReversing(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(3, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_QueryWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_QueryWorkstation() { - ::grpc::Service::MarkMethodRaw(4); - } - ~WithRawMethod_QueryWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestQueryWorkstation(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(4, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_UpdateWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_UpdateWorkstation() { - ::grpc::Service::MarkMethodRaw(5); - } - ~WithRawMethod_UpdateWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestUpdateWorkstation(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(5, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_QueryCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_QueryCamera() { - ::grpc::Service::MarkMethodRaw(6); - } - ~WithRawMethod_QueryCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestQueryCamera(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(6, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_UpdateCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_UpdateCamera() { - ::grpc::Service::MarkMethodRaw(7); - } - ~WithRawMethod_UpdateCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestUpdateCamera(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(7, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_QueryFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_QueryFTP() { - ::grpc::Service::MarkMethodRaw(8); - } - ~WithRawMethod_QueryFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestQueryFTP(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(8, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_UpdateFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_UpdateFTP() { - ::grpc::Service::MarkMethodRaw(9); - } - ~WithRawMethod_UpdateFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestUpdateFTP(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(9, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class WithRawMethod_RebootAI : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithRawMethod_RebootAI() { - ::grpc::Service::MarkMethodRaw(10); - } - ~WithRawMethod_RebootAI() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status RebootAI(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - void RequestRebootAI(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { - ::grpc::Service::RequestAsyncUnary(10, context, request, response, new_call_cq, notification_cq, tag); - } - }; - template - class ExperimentalWithRawCallbackMethod_Come : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_Come() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(0, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->Come(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_Come() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Come(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* Come( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* Come( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_Leave : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_Leave() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(1, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->Leave(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_Leave() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Leave(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* Leave( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* Leave( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_TemporaryStop : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_TemporaryStop() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(2, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->TemporaryStop(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_TemporaryStop() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status TemporaryStop(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* TemporaryStop( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* TemporaryStop( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_Reversing : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_Reversing() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(3, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->Reversing(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_Reversing() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status Reversing(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* Reversing( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* Reversing( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_QueryWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_QueryWorkstation() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(4, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->QueryWorkstation(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_QueryWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* QueryWorkstation( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* QueryWorkstation( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_UpdateWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_UpdateWorkstation() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(5, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->UpdateWorkstation(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_UpdateWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* UpdateWorkstation( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* UpdateWorkstation( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_QueryCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_QueryCamera() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(6, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->QueryCamera(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_QueryCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* QueryCamera( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* QueryCamera( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_UpdateCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_UpdateCamera() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(7, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->UpdateCamera(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_UpdateCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* UpdateCamera( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* UpdateCamera( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_QueryFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_QueryFTP() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(8, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->QueryFTP(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_QueryFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status QueryFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* QueryFTP( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* QueryFTP( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_UpdateFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_UpdateFTP() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(9, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->UpdateFTP(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_UpdateFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status UpdateFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* UpdateFTP( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* UpdateFTP( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class ExperimentalWithRawCallbackMethod_RebootAI : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - ExperimentalWithRawCallbackMethod_RebootAI() { - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::Service:: - #else - ::grpc::Service::experimental(). - #endif - MarkMethodRawCallback(10, - new ::grpc::internal::CallbackUnaryHandler< ::grpc::ByteBuffer, ::grpc::ByteBuffer>( - [this]( - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - ::grpc::CallbackServerContext* - #else - ::grpc::experimental::CallbackServerContext* - #endif - context, const ::grpc::ByteBuffer* request, ::grpc::ByteBuffer* response) { return this->RebootAI(context, request, response); })); - } - ~ExperimentalWithRawCallbackMethod_RebootAI() override { - BaseClassMustBeDerivedFromService(this); - } - // disable synchronous version of this method - ::grpc::Status RebootAI(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - #ifdef GRPC_CALLBACK_API_NONEXPERIMENTAL - virtual ::grpc::ServerUnaryReactor* RebootAI( - ::grpc::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #else - virtual ::grpc::experimental::ServerUnaryReactor* RebootAI( - ::grpc::experimental::CallbackServerContext* /*context*/, const ::grpc::ByteBuffer* /*request*/, ::grpc::ByteBuffer* /*response*/) - #endif - { return nullptr; } - }; - template - class WithStreamedUnaryMethod_Come : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_Come() { - ::grpc::Service::MarkMethodStreamed(0, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::Request, ::MatrixAi::Reply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::Request, ::MatrixAi::Reply>* streamer) { - return this->StreamedCome(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_Come() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status Come(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedCome(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::Request,::MatrixAi::Reply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_Leave : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_Leave() { - ::grpc::Service::MarkMethodStreamed(1, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::Request, ::MatrixAi::Reply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::Request, ::MatrixAi::Reply>* streamer) { - return this->StreamedLeave(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_Leave() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status Leave(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedLeave(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::Request,::MatrixAi::Reply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_TemporaryStop : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_TemporaryStop() { - ::grpc::Service::MarkMethodStreamed(2, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::Request, ::MatrixAi::Reply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::Request, ::MatrixAi::Reply>* streamer) { - return this->StreamedTemporaryStop(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_TemporaryStop() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status TemporaryStop(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedTemporaryStop(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::Request,::MatrixAi::Reply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_Reversing : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_Reversing() { - ::grpc::Service::MarkMethodStreamed(3, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::Request, ::MatrixAi::Reply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::Request, ::MatrixAi::Reply>* streamer) { - return this->StreamedReversing(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_Reversing() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status Reversing(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedReversing(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::Request,::MatrixAi::Reply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_QueryWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_QueryWorkstation() { - ::grpc::Service::MarkMethodStreamed(4, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::QueryWorkstationRequest, ::MatrixAi::QueryWorkstationReply>* streamer) { - return this->StreamedQueryWorkstation(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_QueryWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status QueryWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryWorkstationRequest* /*request*/, ::MatrixAi::QueryWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedQueryWorkstation(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::QueryWorkstationRequest,::MatrixAi::QueryWorkstationReply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_UpdateWorkstation : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_UpdateWorkstation() { - ::grpc::Service::MarkMethodStreamed(5, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::UpdateWorkstationRequest, ::MatrixAi::UpdateWorkstationReply>* streamer) { - return this->StreamedUpdateWorkstation(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_UpdateWorkstation() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status UpdateWorkstation(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateWorkstationRequest* /*request*/, ::MatrixAi::UpdateWorkstationReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedUpdateWorkstation(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::UpdateWorkstationRequest,::MatrixAi::UpdateWorkstationReply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_QueryCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_QueryCamera() { - ::grpc::Service::MarkMethodStreamed(6, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::QueryCameraRequest, ::MatrixAi::QueryCameraReply>* streamer) { - return this->StreamedQueryCamera(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_QueryCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status QueryCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryCameraRequest* /*request*/, ::MatrixAi::QueryCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedQueryCamera(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::QueryCameraRequest,::MatrixAi::QueryCameraReply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_UpdateCamera : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_UpdateCamera() { - ::grpc::Service::MarkMethodStreamed(7, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::UpdateCameraRequest, ::MatrixAi::UpdateCameraReply>* streamer) { - return this->StreamedUpdateCamera(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_UpdateCamera() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status UpdateCamera(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateCameraRequest* /*request*/, ::MatrixAi::UpdateCameraReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedUpdateCamera(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::UpdateCameraRequest,::MatrixAi::UpdateCameraReply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_QueryFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_QueryFTP() { - ::grpc::Service::MarkMethodStreamed(8, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::QueryFTPRequest, ::MatrixAi::QueryFTPReply>* streamer) { - return this->StreamedQueryFTP(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_QueryFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status QueryFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::QueryFTPRequest* /*request*/, ::MatrixAi::QueryFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedQueryFTP(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::QueryFTPRequest,::MatrixAi::QueryFTPReply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_UpdateFTP : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_UpdateFTP() { - ::grpc::Service::MarkMethodStreamed(9, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::UpdateFTPRequest, ::MatrixAi::UpdateFTPReply>* streamer) { - return this->StreamedUpdateFTP(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_UpdateFTP() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status UpdateFTP(::grpc::ServerContext* /*context*/, const ::MatrixAi::UpdateFTPRequest* /*request*/, ::MatrixAi::UpdateFTPReply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedUpdateFTP(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::UpdateFTPRequest,::MatrixAi::UpdateFTPReply>* server_unary_streamer) = 0; - }; - template - class WithStreamedUnaryMethod_RebootAI : public BaseClass { - private: - void BaseClassMustBeDerivedFromService(const Service* /*service*/) {} - public: - WithStreamedUnaryMethod_RebootAI() { - ::grpc::Service::MarkMethodStreamed(10, - new ::grpc::internal::StreamedUnaryHandler< - ::MatrixAi::Request, ::MatrixAi::Reply>( - [this](::grpc::ServerContext* context, - ::grpc::ServerUnaryStreamer< - ::MatrixAi::Request, ::MatrixAi::Reply>* streamer) { - return this->StreamedRebootAI(context, - streamer); - })); - } - ~WithStreamedUnaryMethod_RebootAI() override { - BaseClassMustBeDerivedFromService(this); - } - // disable regular version of this method - ::grpc::Status RebootAI(::grpc::ServerContext* /*context*/, const ::MatrixAi::Request* /*request*/, ::MatrixAi::Reply* /*response*/) override { - abort(); - return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); - } - // replace default version of method with streamed unary - virtual ::grpc::Status StreamedRebootAI(::grpc::ServerContext* context, ::grpc::ServerUnaryStreamer< ::MatrixAi::Request,::MatrixAi::Reply>* server_unary_streamer) = 0; - }; - typedef WithStreamedUnaryMethod_Come > > > > > > > > > > StreamedUnaryService; - typedef Service SplitStreamedService; - typedef WithStreamedUnaryMethod_Come > > > > > > > > > > StreamedService; -}; - -} // namespace MatrixAi - - -#endif // GRPC_grpcservice_2eproto__INCLUDED diff --git a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.pb.cpp b/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.pb.cpp deleted file mode 100644 index 2497009..0000000 --- a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.pb.cpp +++ /dev/null @@ -1,4457 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: grpcservice.proto - -#include "grpcservice.pb.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -// @@protoc_insertion_point(includes) -#include -namespace MatrixAi { -class RequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _Request_default_instance_; -class ReplyDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _Reply_default_instance_; -class QueryWorkstationRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _QueryWorkstationRequest_default_instance_; -class QueryWorkstationReplyDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _QueryWorkstationReply_default_instance_; -class UpdateWorkstationRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _UpdateWorkstationRequest_default_instance_; -class UpdateWorkstationReplyDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _UpdateWorkstationReply_default_instance_; -class QueryCameraRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _QueryCameraRequest_default_instance_; -class QueryCameraReplyDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _QueryCameraReply_default_instance_; -class UpdateCameraRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _UpdateCameraRequest_default_instance_; -class UpdateCameraReplyDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _UpdateCameraReply_default_instance_; -class QueryFTPRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _QueryFTPRequest_default_instance_; -class QueryFTPReplyDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _QueryFTPReply_default_instance_; -class UpdateFTPRequestDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _UpdateFTPRequest_default_instance_; -class UpdateFTPReplyDefaultTypeInternal { - public: - ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; -} _UpdateFTPReply_default_instance_; -} // namespace MatrixAi -static void InitDefaultsscc_info_QueryCameraReply_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_QueryCameraReply_default_instance_; - new (ptr) ::MatrixAi::QueryCameraReply(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::QueryCameraReply::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_QueryCameraReply_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_QueryCameraReply_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_QueryCameraRequest_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_QueryCameraRequest_default_instance_; - new (ptr) ::MatrixAi::QueryCameraRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::QueryCameraRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_QueryCameraRequest_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_QueryCameraRequest_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_QueryFTPReply_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_QueryFTPReply_default_instance_; - new (ptr) ::MatrixAi::QueryFTPReply(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::QueryFTPReply::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_QueryFTPReply_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_QueryFTPReply_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_QueryFTPRequest_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_QueryFTPRequest_default_instance_; - new (ptr) ::MatrixAi::QueryFTPRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::QueryFTPRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_QueryFTPRequest_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_QueryFTPRequest_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_QueryWorkstationReply_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_QueryWorkstationReply_default_instance_; - new (ptr) ::MatrixAi::QueryWorkstationReply(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::QueryWorkstationReply::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_QueryWorkstationReply_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_QueryWorkstationReply_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_QueryWorkstationRequest_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_QueryWorkstationRequest_default_instance_; - new (ptr) ::MatrixAi::QueryWorkstationRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::QueryWorkstationRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_QueryWorkstationRequest_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_QueryWorkstationRequest_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_Reply_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_Reply_default_instance_; - new (ptr) ::MatrixAi::Reply(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::Reply::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_Reply_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_Reply_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_Request_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_Request_default_instance_; - new (ptr) ::MatrixAi::Request(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::Request::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_Request_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_Request_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_UpdateCameraReply_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_UpdateCameraReply_default_instance_; - new (ptr) ::MatrixAi::UpdateCameraReply(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::UpdateCameraReply::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_UpdateCameraReply_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_UpdateCameraReply_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_UpdateCameraRequest_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_UpdateCameraRequest_default_instance_; - new (ptr) ::MatrixAi::UpdateCameraRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::UpdateCameraRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_UpdateCameraRequest_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_UpdateCameraRequest_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_UpdateFTPReply_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_UpdateFTPReply_default_instance_; - new (ptr) ::MatrixAi::UpdateFTPReply(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::UpdateFTPReply::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_UpdateFTPReply_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_UpdateFTPReply_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_UpdateFTPRequest_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_UpdateFTPRequest_default_instance_; - new (ptr) ::MatrixAi::UpdateFTPRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::UpdateFTPRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_UpdateFTPRequest_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_UpdateFTPRequest_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_UpdateWorkstationReply_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_UpdateWorkstationReply_default_instance_; - new (ptr) ::MatrixAi::UpdateWorkstationReply(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::UpdateWorkstationReply::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_UpdateWorkstationReply_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_UpdateWorkstationReply_grpcservice_2eproto}, {}}; - -static void InitDefaultsscc_info_UpdateWorkstationRequest_grpcservice_2eproto() { - GOOGLE_PROTOBUF_VERIFY_VERSION; - - { - void* ptr = &::MatrixAi::_UpdateWorkstationRequest_default_instance_; - new (ptr) ::MatrixAi::UpdateWorkstationRequest(); - ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); - } - ::MatrixAi::UpdateWorkstationRequest::InitAsDefaultInstance(); -} - -::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_UpdateWorkstationRequest_grpcservice_2eproto = - {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_UpdateWorkstationRequest_grpcservice_2eproto}, {}}; - -static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_grpcservice_2eproto[14]; -static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_grpcservice_2eproto = nullptr; -static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_grpcservice_2eproto = nullptr; - -const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_grpcservice_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::Request, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::Request, head_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::Reply, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::Reply, error_msg_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryWorkstationRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryWorkstationRequest, head_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryWorkstationReply, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryWorkstationReply, name_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryWorkstationReply, name_no_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryWorkstationReply, error_msg_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateWorkstationRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateWorkstationRequest, head_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateWorkstationRequest, name_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateWorkstationRequest, name_no_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateWorkstationReply, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateWorkstationReply, error_msg_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraRequest, head_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraRequest, channel_id_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, channel_id_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, use_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, url_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, skipinterval_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, direction_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, left_first_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, right_first_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryCameraReply, error_msg_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, head_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, channel_id_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, use_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, url_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, skipinterval_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, direction_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, left_first_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraRequest, right_first_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraReply, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraReply, channel_id_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateCameraReply, error_msg_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPRequest, head_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, open_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, username_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, password_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, ip_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, port_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, image_path_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, quit_time_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::QueryFTPReply, error_msg_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, head_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, open_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, username_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, password_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, ip_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, port_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, image_path_), - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPRequest, quit_time_), - ~0u, // no _has_bits_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPReply, _internal_metadata_), - ~0u, // no _extensions_ - ~0u, // no _oneof_case_ - ~0u, // no _weak_field_map_ - PROTOBUF_FIELD_OFFSET(::MatrixAi::UpdateFTPReply, error_msg_), -}; -static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { - { 0, -1, sizeof(::MatrixAi::Request)}, - { 6, -1, sizeof(::MatrixAi::Reply)}, - { 12, -1, sizeof(::MatrixAi::QueryWorkstationRequest)}, - { 18, -1, sizeof(::MatrixAi::QueryWorkstationReply)}, - { 26, -1, sizeof(::MatrixAi::UpdateWorkstationRequest)}, - { 34, -1, sizeof(::MatrixAi::UpdateWorkstationReply)}, - { 40, -1, sizeof(::MatrixAi::QueryCameraRequest)}, - { 47, -1, sizeof(::MatrixAi::QueryCameraReply)}, - { 60, -1, sizeof(::MatrixAi::UpdateCameraRequest)}, - { 73, -1, sizeof(::MatrixAi::UpdateCameraReply)}, - { 80, -1, sizeof(::MatrixAi::QueryFTPRequest)}, - { 86, -1, sizeof(::MatrixAi::QueryFTPReply)}, - { 99, -1, sizeof(::MatrixAi::UpdateFTPRequest)}, - { 112, -1, sizeof(::MatrixAi::UpdateFTPReply)}, -}; - -static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = { - reinterpret_cast(&::MatrixAi::_Request_default_instance_), - reinterpret_cast(&::MatrixAi::_Reply_default_instance_), - reinterpret_cast(&::MatrixAi::_QueryWorkstationRequest_default_instance_), - reinterpret_cast(&::MatrixAi::_QueryWorkstationReply_default_instance_), - reinterpret_cast(&::MatrixAi::_UpdateWorkstationRequest_default_instance_), - reinterpret_cast(&::MatrixAi::_UpdateWorkstationReply_default_instance_), - reinterpret_cast(&::MatrixAi::_QueryCameraRequest_default_instance_), - reinterpret_cast(&::MatrixAi::_QueryCameraReply_default_instance_), - reinterpret_cast(&::MatrixAi::_UpdateCameraRequest_default_instance_), - reinterpret_cast(&::MatrixAi::_UpdateCameraReply_default_instance_), - reinterpret_cast(&::MatrixAi::_QueryFTPRequest_default_instance_), - reinterpret_cast(&::MatrixAi::_QueryFTPReply_default_instance_), - reinterpret_cast(&::MatrixAi::_UpdateFTPRequest_default_instance_), - reinterpret_cast(&::MatrixAi::_UpdateFTPReply_default_instance_), -}; - -const char descriptor_table_protodef_grpcservice_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = - "\n\021grpcservice.proto\022\010MatrixAi\"\027\n\007Request" - "\022\014\n\004head\030\001 \001(\r\"\032\n\005Reply\022\021\n\terror_msg\030\001 \001" - "(\t\"\'\n\027QueryWorkstationRequest\022\014\n\004head\030\001 " - "\001(\r\"I\n\025QueryWorkstationReply\022\014\n\004name\030\001 \001" - "(\t\022\017\n\007name_no\030\002 \001(\t\022\021\n\terror_msg\030\003 \001(\t\"G" - "\n\030UpdateWorkstationRequest\022\014\n\004head\030\001 \001(\r" - "\022\014\n\004name\030\002 \001(\t\022\017\n\007name_no\030\003 \001(\t\"+\n\026Updat" - "eWorkstationReply\022\021\n\terror_msg\030\001 \001(\t\"6\n\022" - "QueryCameraRequest\022\014\n\004head\030\001 \001(\r\022\022\n\nchan" - "nel_id\030\002 \001(\r\"\245\001\n\020QueryCameraReply\022\022\n\ncha" - "nnel_id\030\001 \001(\r\022\013\n\003use\030\002 \001(\010\022\013\n\003url\030\003 \001(\t\022" - "\024\n\014skipinterval\030\004 \001(\r\022\021\n\tdirection\030\005 \001(\r" - "\022\022\n\nleft_first\030\006 \001(\r\022\023\n\013right_first\030\007 \001(" - "\r\022\021\n\terror_msg\030\010 \001(\t\"\243\001\n\023UpdateCameraReq" - "uest\022\014\n\004head\030\001 \001(\r\022\022\n\nchannel_id\030\002 \001(\r\022\013" - "\n\003use\030\003 \001(\010\022\013\n\003url\030\004 \001(\t\022\024\n\014skipinterval" - "\030\005 \001(\r\022\021\n\tdirection\030\006 \001(\r\022\022\n\nleft_first\030" - "\007 \001(\r\022\023\n\013right_first\030\010 \001(\r\":\n\021UpdateCame" - "raReply\022\022\n\nchannel_id\030\001 \001(\r\022\021\n\terror_msg" - "\030\002 \001(\t\"\037\n\017QueryFTPRequest\022\014\n\004head\030\001 \001(\r\"" - "\225\001\n\rQueryFTPReply\022\014\n\004open\030\001 \001(\r\022\020\n\010usern" - "ame\030\002 \001(\t\022\020\n\010password\030\003 \001(\t\022\n\n\002ip\030\004 \001(\t\022" - "\014\n\004port\030\005 \001(\r\022\022\n\nimage_path\030\006 \001(\t\022\021\n\tqui" - "t_time\030\007 \001(\r\022\021\n\terror_msg\030\010 \001(\t\"\223\001\n\020Upda" - "teFTPRequest\022\014\n\004head\030\001 \001(\r\022\014\n\004open\030\002 \001(\r" - "\022\020\n\010username\030\003 \001(\t\022\020\n\010password\030\004 \001(\t\022\n\n\002" - "ip\030\005 \001(\t\022\014\n\004port\030\006 \001(\r\022\022\n\nimage_path\030\007 \001" - "(\t\022\021\n\tquit_time\030\010 \001(\r\"#\n\016UpdateFTPReply\022" - "\021\n\terror_msg\030\001 \001(\t2\327\005\n\005Train\022,\n\004Come\022\021.M" - "atrixAi.Request\032\017.MatrixAi.Reply\"\000\022-\n\005Le" - "ave\022\021.MatrixAi.Request\032\017.MatrixAi.Reply\"" - "\000\0225\n\rTemporaryStop\022\021.MatrixAi.Request\032\017." - "MatrixAi.Reply\"\000\0221\n\tReversing\022\021.MatrixAi" - ".Request\032\017.MatrixAi.Reply\"\000\022X\n\020QueryWork" - "station\022!.MatrixAi.QueryWorkstationReque" - "st\032\037.MatrixAi.QueryWorkstationReply\"\000\022[\n" - "\021UpdateWorkstation\022\".MatrixAi.UpdateWork" - "stationRequest\032 .MatrixAi.UpdateWorkstat" - "ionReply\"\000\022I\n\013QueryCamera\022\034.MatrixAi.Que" - "ryCameraRequest\032\032.MatrixAi.QueryCameraRe" - "ply\"\000\022L\n\014UpdateCamera\022\035.MatrixAi.UpdateC" - "ameraRequest\032\033.MatrixAi.UpdateCameraRepl" - "y\"\000\022@\n\010QueryFTP\022\031.MatrixAi.QueryFTPReque" - "st\032\027.MatrixAi.QueryFTPReply\"\000\022C\n\tUpdateF" - "TP\022\032.MatrixAi.UpdateFTPRequest\032\030.MatrixA" - "i.UpdateFTPReply\"\000\0220\n\010RebootAI\022\021.MatrixA" - "i.Request\032\017.MatrixAi.Reply\"\000B&\n\025com.matr" - "ix.train.grpcB\013GrpcServiceP\001b\006proto3" - ; -static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_grpcservice_2eproto_deps[1] = { -}; -static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_grpcservice_2eproto_sccs[14] = { - &scc_info_QueryCameraReply_grpcservice_2eproto.base, - &scc_info_QueryCameraRequest_grpcservice_2eproto.base, - &scc_info_QueryFTPReply_grpcservice_2eproto.base, - &scc_info_QueryFTPRequest_grpcservice_2eproto.base, - &scc_info_QueryWorkstationReply_grpcservice_2eproto.base, - &scc_info_QueryWorkstationRequest_grpcservice_2eproto.base, - &scc_info_Reply_grpcservice_2eproto.base, - &scc_info_Request_grpcservice_2eproto.base, - &scc_info_UpdateCameraReply_grpcservice_2eproto.base, - &scc_info_UpdateCameraRequest_grpcservice_2eproto.base, - &scc_info_UpdateFTPReply_grpcservice_2eproto.base, - &scc_info_UpdateFTPRequest_grpcservice_2eproto.base, - &scc_info_UpdateWorkstationReply_grpcservice_2eproto.base, - &scc_info_UpdateWorkstationRequest_grpcservice_2eproto.base, -}; -static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_grpcservice_2eproto_once; -const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_grpcservice_2eproto = { - false, false, descriptor_table_protodef_grpcservice_2eproto, "grpcservice.proto", 1916, - &descriptor_table_grpcservice_2eproto_once, descriptor_table_grpcservice_2eproto_sccs, descriptor_table_grpcservice_2eproto_deps, 14, 0, - schemas, file_default_instances, TableStruct_grpcservice_2eproto::offsets, - file_level_metadata_grpcservice_2eproto, 14, file_level_enum_descriptors_grpcservice_2eproto, file_level_service_descriptors_grpcservice_2eproto, -}; - -// Force running AddDescriptors() at dynamic initialization time. -static bool dynamic_init_dummy_grpcservice_2eproto = (static_cast(::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_grpcservice_2eproto)), true); -namespace MatrixAi { - -// =================================================================== - -void Request::InitAsDefaultInstance() { -} -class Request::_Internal { - public: -}; - -Request::Request(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.Request) -} -Request::Request(const Request& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - head_ = from.head_; - // @@protoc_insertion_point(copy_constructor:MatrixAi.Request) -} - -void Request::SharedCtor() { - head_ = 0u; -} - -Request::~Request() { - // @@protoc_insertion_point(destructor:MatrixAi.Request) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void Request::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); -} - -void Request::ArenaDtor(void* object) { - Request* _this = reinterpret_cast< Request* >(object); - (void)_this; -} -void Request::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void Request::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const Request& Request::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_Request_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void Request::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.Request) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - head_ = 0u; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* Request::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 head = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - head_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* Request::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.Request) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_head(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.Request) - return target; -} - -size_t Request::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.Request) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_head()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void Request::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.Request) - GOOGLE_DCHECK_NE(&from, this); - const Request* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.Request) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.Request) - MergeFrom(*source); - } -} - -void Request::MergeFrom(const Request& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.Request) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.head() != 0) { - _internal_set_head(from._internal_head()); - } -} - -void Request::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.Request) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void Request::CopyFrom(const Request& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.Request) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool Request::IsInitialized() const { - return true; -} - -void Request::InternalSwap(Request* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - swap(head_, other->head_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata Request::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void Reply::InitAsDefaultInstance() { -} -class Reply::_Internal { - public: -}; - -Reply::Reply(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.Reply) -} -Reply::Reply(const Reply& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_error_msg().empty()) { - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_msg(), - GetArena()); - } - // @@protoc_insertion_point(copy_constructor:MatrixAi.Reply) -} - -void Reply::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_Reply_grpcservice_2eproto.base); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -Reply::~Reply() { - // @@protoc_insertion_point(destructor:MatrixAi.Reply) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void Reply::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - error_msg_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void Reply::ArenaDtor(void* object) { - Reply* _this = reinterpret_cast< Reply* >(object); - (void)_this; -} -void Reply::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void Reply::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const Reply& Reply::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_Reply_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void Reply::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.Reply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* Reply::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // string error_msg = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - auto str = _internal_mutable_error_msg(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.Reply.error_msg")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* Reply::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.Reply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // string error_msg = 1; - if (this->error_msg().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_msg().data(), static_cast(this->_internal_error_msg().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.Reply.error_msg"); - target = stream->WriteStringMaybeAliased( - 1, this->_internal_error_msg(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.Reply) - return target; -} - -size_t Reply::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.Reply) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string error_msg = 1; - if (this->error_msg().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_msg()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void Reply::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.Reply) - GOOGLE_DCHECK_NE(&from, this); - const Reply* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.Reply) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.Reply) - MergeFrom(*source); - } -} - -void Reply::MergeFrom(const Reply& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.Reply) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.error_msg().size() > 0) { - _internal_set_error_msg(from._internal_error_msg()); - } -} - -void Reply::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.Reply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void Reply::CopyFrom(const Reply& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.Reply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool Reply::IsInitialized() const { - return true; -} - -void Reply::InternalSwap(Reply* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - error_msg_.Swap(&other->error_msg_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} - -::PROTOBUF_NAMESPACE_ID::Metadata Reply::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void QueryWorkstationRequest::InitAsDefaultInstance() { -} -class QueryWorkstationRequest::_Internal { - public: -}; - -QueryWorkstationRequest::QueryWorkstationRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.QueryWorkstationRequest) -} -QueryWorkstationRequest::QueryWorkstationRequest(const QueryWorkstationRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - head_ = from.head_; - // @@protoc_insertion_point(copy_constructor:MatrixAi.QueryWorkstationRequest) -} - -void QueryWorkstationRequest::SharedCtor() { - head_ = 0u; -} - -QueryWorkstationRequest::~QueryWorkstationRequest() { - // @@protoc_insertion_point(destructor:MatrixAi.QueryWorkstationRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void QueryWorkstationRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); -} - -void QueryWorkstationRequest::ArenaDtor(void* object) { - QueryWorkstationRequest* _this = reinterpret_cast< QueryWorkstationRequest* >(object); - (void)_this; -} -void QueryWorkstationRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void QueryWorkstationRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const QueryWorkstationRequest& QueryWorkstationRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_QueryWorkstationRequest_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void QueryWorkstationRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.QueryWorkstationRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - head_ = 0u; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* QueryWorkstationRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 head = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - head_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* QueryWorkstationRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.QueryWorkstationRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_head(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.QueryWorkstationRequest) - return target; -} - -size_t QueryWorkstationRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.QueryWorkstationRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_head()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void QueryWorkstationRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.QueryWorkstationRequest) - GOOGLE_DCHECK_NE(&from, this); - const QueryWorkstationRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.QueryWorkstationRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.QueryWorkstationRequest) - MergeFrom(*source); - } -} - -void QueryWorkstationRequest::MergeFrom(const QueryWorkstationRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.QueryWorkstationRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.head() != 0) { - _internal_set_head(from._internal_head()); - } -} - -void QueryWorkstationRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.QueryWorkstationRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void QueryWorkstationRequest::CopyFrom(const QueryWorkstationRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.QueryWorkstationRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool QueryWorkstationRequest::IsInitialized() const { - return true; -} - -void QueryWorkstationRequest::InternalSwap(QueryWorkstationRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - swap(head_, other->head_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata QueryWorkstationRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void QueryWorkstationReply::InitAsDefaultInstance() { -} -class QueryWorkstationReply::_Internal { - public: -}; - -QueryWorkstationReply::QueryWorkstationReply(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.QueryWorkstationReply) -} -QueryWorkstationReply::QueryWorkstationReply(const QueryWorkstationReply& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_name().empty()) { - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(), - GetArena()); - } - name_no_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_name_no().empty()) { - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name_no(), - GetArena()); - } - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_error_msg().empty()) { - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_msg(), - GetArena()); - } - // @@protoc_insertion_point(copy_constructor:MatrixAi.QueryWorkstationReply) -} - -void QueryWorkstationReply::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_QueryWorkstationReply_grpcservice_2eproto.base); - name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - name_no_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -QueryWorkstationReply::~QueryWorkstationReply() { - // @@protoc_insertion_point(destructor:MatrixAi.QueryWorkstationReply) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void QueryWorkstationReply::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - name_no_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - error_msg_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void QueryWorkstationReply::ArenaDtor(void* object) { - QueryWorkstationReply* _this = reinterpret_cast< QueryWorkstationReply* >(object); - (void)_this; -} -void QueryWorkstationReply::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void QueryWorkstationReply::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const QueryWorkstationReply& QueryWorkstationReply::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_QueryWorkstationReply_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void QueryWorkstationReply::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.QueryWorkstationReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - name_no_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* QueryWorkstationReply::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // string name = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - auto str = _internal_mutable_name(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryWorkstationReply.name")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string name_no = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - auto str = _internal_mutable_name_no(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryWorkstationReply.name_no")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string error_msg = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - auto str = _internal_mutable_error_msg(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryWorkstationReply.error_msg")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* QueryWorkstationReply::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.QueryWorkstationReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // string name = 1; - if (this->name().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_name().data(), static_cast(this->_internal_name().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryWorkstationReply.name"); - target = stream->WriteStringMaybeAliased( - 1, this->_internal_name(), target); - } - - // string name_no = 2; - if (this->name_no().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_name_no().data(), static_cast(this->_internal_name_no().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryWorkstationReply.name_no"); - target = stream->WriteStringMaybeAliased( - 2, this->_internal_name_no(), target); - } - - // string error_msg = 3; - if (this->error_msg().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_msg().data(), static_cast(this->_internal_error_msg().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryWorkstationReply.error_msg"); - target = stream->WriteStringMaybeAliased( - 3, this->_internal_error_msg(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.QueryWorkstationReply) - return target; -} - -size_t QueryWorkstationReply::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.QueryWorkstationReply) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string name = 1; - if (this->name().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_name()); - } - - // string name_no = 2; - if (this->name_no().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_name_no()); - } - - // string error_msg = 3; - if (this->error_msg().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_msg()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void QueryWorkstationReply::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.QueryWorkstationReply) - GOOGLE_DCHECK_NE(&from, this); - const QueryWorkstationReply* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.QueryWorkstationReply) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.QueryWorkstationReply) - MergeFrom(*source); - } -} - -void QueryWorkstationReply::MergeFrom(const QueryWorkstationReply& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.QueryWorkstationReply) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.name().size() > 0) { - _internal_set_name(from._internal_name()); - } - if (from.name_no().size() > 0) { - _internal_set_name_no(from._internal_name_no()); - } - if (from.error_msg().size() > 0) { - _internal_set_error_msg(from._internal_error_msg()); - } -} - -void QueryWorkstationReply::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.QueryWorkstationReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void QueryWorkstationReply::CopyFrom(const QueryWorkstationReply& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.QueryWorkstationReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool QueryWorkstationReply::IsInitialized() const { - return true; -} - -void QueryWorkstationReply::InternalSwap(QueryWorkstationReply* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - name_no_.Swap(&other->name_no_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - error_msg_.Swap(&other->error_msg_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} - -::PROTOBUF_NAMESPACE_ID::Metadata QueryWorkstationReply::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void UpdateWorkstationRequest::InitAsDefaultInstance() { -} -class UpdateWorkstationRequest::_Internal { - public: -}; - -UpdateWorkstationRequest::UpdateWorkstationRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.UpdateWorkstationRequest) -} -UpdateWorkstationRequest::UpdateWorkstationRequest(const UpdateWorkstationRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_name().empty()) { - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(), - GetArena()); - } - name_no_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_name_no().empty()) { - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name_no(), - GetArena()); - } - head_ = from.head_; - // @@protoc_insertion_point(copy_constructor:MatrixAi.UpdateWorkstationRequest) -} - -void UpdateWorkstationRequest::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_UpdateWorkstationRequest_grpcservice_2eproto.base); - name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - name_no_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - head_ = 0u; -} - -UpdateWorkstationRequest::~UpdateWorkstationRequest() { - // @@protoc_insertion_point(destructor:MatrixAi.UpdateWorkstationRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void UpdateWorkstationRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - name_no_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void UpdateWorkstationRequest::ArenaDtor(void* object) { - UpdateWorkstationRequest* _this = reinterpret_cast< UpdateWorkstationRequest* >(object); - (void)_this; -} -void UpdateWorkstationRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void UpdateWorkstationRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const UpdateWorkstationRequest& UpdateWorkstationRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_UpdateWorkstationRequest_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void UpdateWorkstationRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.UpdateWorkstationRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - name_no_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - head_ = 0u; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* UpdateWorkstationRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 head = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - head_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string name = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - auto str = _internal_mutable_name(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateWorkstationRequest.name")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string name_no = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - auto str = _internal_mutable_name_no(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateWorkstationRequest.name_no")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* UpdateWorkstationRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.UpdateWorkstationRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_head(), target); - } - - // string name = 2; - if (this->name().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_name().data(), static_cast(this->_internal_name().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateWorkstationRequest.name"); - target = stream->WriteStringMaybeAliased( - 2, this->_internal_name(), target); - } - - // string name_no = 3; - if (this->name_no().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_name_no().data(), static_cast(this->_internal_name_no().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateWorkstationRequest.name_no"); - target = stream->WriteStringMaybeAliased( - 3, this->_internal_name_no(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.UpdateWorkstationRequest) - return target; -} - -size_t UpdateWorkstationRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.UpdateWorkstationRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string name = 2; - if (this->name().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_name()); - } - - // string name_no = 3; - if (this->name_no().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_name_no()); - } - - // uint32 head = 1; - if (this->head() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_head()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void UpdateWorkstationRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.UpdateWorkstationRequest) - GOOGLE_DCHECK_NE(&from, this); - const UpdateWorkstationRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.UpdateWorkstationRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.UpdateWorkstationRequest) - MergeFrom(*source); - } -} - -void UpdateWorkstationRequest::MergeFrom(const UpdateWorkstationRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.UpdateWorkstationRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.name().size() > 0) { - _internal_set_name(from._internal_name()); - } - if (from.name_no().size() > 0) { - _internal_set_name_no(from._internal_name_no()); - } - if (from.head() != 0) { - _internal_set_head(from._internal_head()); - } -} - -void UpdateWorkstationRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.UpdateWorkstationRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void UpdateWorkstationRequest::CopyFrom(const UpdateWorkstationRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.UpdateWorkstationRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool UpdateWorkstationRequest::IsInitialized() const { - return true; -} - -void UpdateWorkstationRequest::InternalSwap(UpdateWorkstationRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - name_no_.Swap(&other->name_no_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - swap(head_, other->head_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata UpdateWorkstationRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void UpdateWorkstationReply::InitAsDefaultInstance() { -} -class UpdateWorkstationReply::_Internal { - public: -}; - -UpdateWorkstationReply::UpdateWorkstationReply(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.UpdateWorkstationReply) -} -UpdateWorkstationReply::UpdateWorkstationReply(const UpdateWorkstationReply& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_error_msg().empty()) { - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_msg(), - GetArena()); - } - // @@protoc_insertion_point(copy_constructor:MatrixAi.UpdateWorkstationReply) -} - -void UpdateWorkstationReply::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_UpdateWorkstationReply_grpcservice_2eproto.base); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -UpdateWorkstationReply::~UpdateWorkstationReply() { - // @@protoc_insertion_point(destructor:MatrixAi.UpdateWorkstationReply) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void UpdateWorkstationReply::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - error_msg_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void UpdateWorkstationReply::ArenaDtor(void* object) { - UpdateWorkstationReply* _this = reinterpret_cast< UpdateWorkstationReply* >(object); - (void)_this; -} -void UpdateWorkstationReply::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void UpdateWorkstationReply::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const UpdateWorkstationReply& UpdateWorkstationReply::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_UpdateWorkstationReply_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void UpdateWorkstationReply::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.UpdateWorkstationReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* UpdateWorkstationReply::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // string error_msg = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - auto str = _internal_mutable_error_msg(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateWorkstationReply.error_msg")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* UpdateWorkstationReply::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.UpdateWorkstationReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // string error_msg = 1; - if (this->error_msg().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_msg().data(), static_cast(this->_internal_error_msg().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateWorkstationReply.error_msg"); - target = stream->WriteStringMaybeAliased( - 1, this->_internal_error_msg(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.UpdateWorkstationReply) - return target; -} - -size_t UpdateWorkstationReply::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.UpdateWorkstationReply) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string error_msg = 1; - if (this->error_msg().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_msg()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void UpdateWorkstationReply::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.UpdateWorkstationReply) - GOOGLE_DCHECK_NE(&from, this); - const UpdateWorkstationReply* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.UpdateWorkstationReply) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.UpdateWorkstationReply) - MergeFrom(*source); - } -} - -void UpdateWorkstationReply::MergeFrom(const UpdateWorkstationReply& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.UpdateWorkstationReply) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.error_msg().size() > 0) { - _internal_set_error_msg(from._internal_error_msg()); - } -} - -void UpdateWorkstationReply::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.UpdateWorkstationReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void UpdateWorkstationReply::CopyFrom(const UpdateWorkstationReply& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.UpdateWorkstationReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool UpdateWorkstationReply::IsInitialized() const { - return true; -} - -void UpdateWorkstationReply::InternalSwap(UpdateWorkstationReply* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - error_msg_.Swap(&other->error_msg_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} - -::PROTOBUF_NAMESPACE_ID::Metadata UpdateWorkstationReply::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void QueryCameraRequest::InitAsDefaultInstance() { -} -class QueryCameraRequest::_Internal { - public: -}; - -QueryCameraRequest::QueryCameraRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.QueryCameraRequest) -} -QueryCameraRequest::QueryCameraRequest(const QueryCameraRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::memcpy(&head_, &from.head_, - static_cast(reinterpret_cast(&channel_id_) - - reinterpret_cast(&head_)) + sizeof(channel_id_)); - // @@protoc_insertion_point(copy_constructor:MatrixAi.QueryCameraRequest) -} - -void QueryCameraRequest::SharedCtor() { - ::memset(&head_, 0, static_cast( - reinterpret_cast(&channel_id_) - - reinterpret_cast(&head_)) + sizeof(channel_id_)); -} - -QueryCameraRequest::~QueryCameraRequest() { - // @@protoc_insertion_point(destructor:MatrixAi.QueryCameraRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void QueryCameraRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); -} - -void QueryCameraRequest::ArenaDtor(void* object) { - QueryCameraRequest* _this = reinterpret_cast< QueryCameraRequest* >(object); - (void)_this; -} -void QueryCameraRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void QueryCameraRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const QueryCameraRequest& QueryCameraRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_QueryCameraRequest_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void QueryCameraRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.QueryCameraRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - ::memset(&head_, 0, static_cast( - reinterpret_cast(&channel_id_) - - reinterpret_cast(&head_)) + sizeof(channel_id_)); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* QueryCameraRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 head = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - head_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 channel_id = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) { - channel_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* QueryCameraRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.QueryCameraRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_head(), target); - } - - // uint32 channel_id = 2; - if (this->channel_id() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(2, this->_internal_channel_id(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.QueryCameraRequest) - return target; -} - -size_t QueryCameraRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.QueryCameraRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_head()); - } - - // uint32 channel_id = 2; - if (this->channel_id() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_channel_id()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void QueryCameraRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.QueryCameraRequest) - GOOGLE_DCHECK_NE(&from, this); - const QueryCameraRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.QueryCameraRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.QueryCameraRequest) - MergeFrom(*source); - } -} - -void QueryCameraRequest::MergeFrom(const QueryCameraRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.QueryCameraRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.head() != 0) { - _internal_set_head(from._internal_head()); - } - if (from.channel_id() != 0) { - _internal_set_channel_id(from._internal_channel_id()); - } -} - -void QueryCameraRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.QueryCameraRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void QueryCameraRequest::CopyFrom(const QueryCameraRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.QueryCameraRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool QueryCameraRequest::IsInitialized() const { - return true; -} - -void QueryCameraRequest::InternalSwap(QueryCameraRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(QueryCameraRequest, channel_id_) - + sizeof(QueryCameraRequest::channel_id_) - - PROTOBUF_FIELD_OFFSET(QueryCameraRequest, head_)>( - reinterpret_cast(&head_), - reinterpret_cast(&other->head_)); -} - -::PROTOBUF_NAMESPACE_ID::Metadata QueryCameraRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void QueryCameraReply::InitAsDefaultInstance() { -} -class QueryCameraReply::_Internal { - public: -}; - -QueryCameraReply::QueryCameraReply(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.QueryCameraReply) -} -QueryCameraReply::QueryCameraReply(const QueryCameraReply& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_url().empty()) { - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_url(), - GetArena()); - } - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_error_msg().empty()) { - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_msg(), - GetArena()); - } - ::memcpy(&channel_id_, &from.channel_id_, - static_cast(reinterpret_cast(&right_first_) - - reinterpret_cast(&channel_id_)) + sizeof(right_first_)); - // @@protoc_insertion_point(copy_constructor:MatrixAi.QueryCameraReply) -} - -void QueryCameraReply::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_QueryCameraReply_grpcservice_2eproto.base); - url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ::memset(&channel_id_, 0, static_cast( - reinterpret_cast(&right_first_) - - reinterpret_cast(&channel_id_)) + sizeof(right_first_)); -} - -QueryCameraReply::~QueryCameraReply() { - // @@protoc_insertion_point(destructor:MatrixAi.QueryCameraReply) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void QueryCameraReply::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - error_msg_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void QueryCameraReply::ArenaDtor(void* object) { - QueryCameraReply* _this = reinterpret_cast< QueryCameraReply* >(object); - (void)_this; -} -void QueryCameraReply::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void QueryCameraReply::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const QueryCameraReply& QueryCameraReply::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_QueryCameraReply_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void QueryCameraReply::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.QueryCameraReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::memset(&channel_id_, 0, static_cast( - reinterpret_cast(&right_first_) - - reinterpret_cast(&channel_id_)) + sizeof(right_first_)); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* QueryCameraReply::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 channel_id = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - channel_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // bool use = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) { - use_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string url = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - auto str = _internal_mutable_url(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryCameraReply.url")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 skipinterval = 4; - case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 32)) { - skipinterval_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 direction = 5; - case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 40)) { - direction_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 left_first = 6; - case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 48)) { - left_first_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 right_first = 7; - case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 56)) { - right_first_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string error_msg = 8; - case 8: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 66)) { - auto str = _internal_mutable_error_msg(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryCameraReply.error_msg")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* QueryCameraReply::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.QueryCameraReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 channel_id = 1; - if (this->channel_id() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_channel_id(), target); - } - - // bool use = 2; - if (this->use() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBoolToArray(2, this->_internal_use(), target); - } - - // string url = 3; - if (this->url().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_url().data(), static_cast(this->_internal_url().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryCameraReply.url"); - target = stream->WriteStringMaybeAliased( - 3, this->_internal_url(), target); - } - - // uint32 skipinterval = 4; - if (this->skipinterval() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(4, this->_internal_skipinterval(), target); - } - - // uint32 direction = 5; - if (this->direction() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(5, this->_internal_direction(), target); - } - - // uint32 left_first = 6; - if (this->left_first() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(6, this->_internal_left_first(), target); - } - - // uint32 right_first = 7; - if (this->right_first() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(7, this->_internal_right_first(), target); - } - - // string error_msg = 8; - if (this->error_msg().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_msg().data(), static_cast(this->_internal_error_msg().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryCameraReply.error_msg"); - target = stream->WriteStringMaybeAliased( - 8, this->_internal_error_msg(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.QueryCameraReply) - return target; -} - -size_t QueryCameraReply::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.QueryCameraReply) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string url = 3; - if (this->url().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_url()); - } - - // string error_msg = 8; - if (this->error_msg().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_msg()); - } - - // uint32 channel_id = 1; - if (this->channel_id() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_channel_id()); - } - - // bool use = 2; - if (this->use() != 0) { - total_size += 1 + 1; - } - - // uint32 skipinterval = 4; - if (this->skipinterval() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_skipinterval()); - } - - // uint32 direction = 5; - if (this->direction() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_direction()); - } - - // uint32 left_first = 6; - if (this->left_first() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_left_first()); - } - - // uint32 right_first = 7; - if (this->right_first() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_right_first()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void QueryCameraReply::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.QueryCameraReply) - GOOGLE_DCHECK_NE(&from, this); - const QueryCameraReply* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.QueryCameraReply) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.QueryCameraReply) - MergeFrom(*source); - } -} - -void QueryCameraReply::MergeFrom(const QueryCameraReply& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.QueryCameraReply) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.url().size() > 0) { - _internal_set_url(from._internal_url()); - } - if (from.error_msg().size() > 0) { - _internal_set_error_msg(from._internal_error_msg()); - } - if (from.channel_id() != 0) { - _internal_set_channel_id(from._internal_channel_id()); - } - if (from.use() != 0) { - _internal_set_use(from._internal_use()); - } - if (from.skipinterval() != 0) { - _internal_set_skipinterval(from._internal_skipinterval()); - } - if (from.direction() != 0) { - _internal_set_direction(from._internal_direction()); - } - if (from.left_first() != 0) { - _internal_set_left_first(from._internal_left_first()); - } - if (from.right_first() != 0) { - _internal_set_right_first(from._internal_right_first()); - } -} - -void QueryCameraReply::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.QueryCameraReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void QueryCameraReply::CopyFrom(const QueryCameraReply& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.QueryCameraReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool QueryCameraReply::IsInitialized() const { - return true; -} - -void QueryCameraReply::InternalSwap(QueryCameraReply* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - url_.Swap(&other->url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - error_msg_.Swap(&other->error_msg_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(QueryCameraReply, right_first_) - + sizeof(QueryCameraReply::right_first_) - - PROTOBUF_FIELD_OFFSET(QueryCameraReply, channel_id_)>( - reinterpret_cast(&channel_id_), - reinterpret_cast(&other->channel_id_)); -} - -::PROTOBUF_NAMESPACE_ID::Metadata QueryCameraReply::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void UpdateCameraRequest::InitAsDefaultInstance() { -} -class UpdateCameraRequest::_Internal { - public: -}; - -UpdateCameraRequest::UpdateCameraRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.UpdateCameraRequest) -} -UpdateCameraRequest::UpdateCameraRequest(const UpdateCameraRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_url().empty()) { - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_url(), - GetArena()); - } - ::memcpy(&head_, &from.head_, - static_cast(reinterpret_cast(&right_first_) - - reinterpret_cast(&head_)) + sizeof(right_first_)); - // @@protoc_insertion_point(copy_constructor:MatrixAi.UpdateCameraRequest) -} - -void UpdateCameraRequest::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_UpdateCameraRequest_grpcservice_2eproto.base); - url_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ::memset(&head_, 0, static_cast( - reinterpret_cast(&right_first_) - - reinterpret_cast(&head_)) + sizeof(right_first_)); -} - -UpdateCameraRequest::~UpdateCameraRequest() { - // @@protoc_insertion_point(destructor:MatrixAi.UpdateCameraRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void UpdateCameraRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - url_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void UpdateCameraRequest::ArenaDtor(void* object) { - UpdateCameraRequest* _this = reinterpret_cast< UpdateCameraRequest* >(object); - (void)_this; -} -void UpdateCameraRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void UpdateCameraRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const UpdateCameraRequest& UpdateCameraRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_UpdateCameraRequest_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void UpdateCameraRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.UpdateCameraRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::memset(&head_, 0, static_cast( - reinterpret_cast(&right_first_) - - reinterpret_cast(&head_)) + sizeof(right_first_)); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* UpdateCameraRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 head = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - head_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 channel_id = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) { - channel_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // bool use = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 24)) { - use_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string url = 4; - case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - auto str = _internal_mutable_url(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateCameraRequest.url")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 skipinterval = 5; - case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 40)) { - skipinterval_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 direction = 6; - case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 48)) { - direction_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 left_first = 7; - case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 56)) { - left_first_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 right_first = 8; - case 8: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 64)) { - right_first_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* UpdateCameraRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.UpdateCameraRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_head(), target); - } - - // uint32 channel_id = 2; - if (this->channel_id() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(2, this->_internal_channel_id(), target); - } - - // bool use = 3; - if (this->use() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteBoolToArray(3, this->_internal_use(), target); - } - - // string url = 4; - if (this->url().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_url().data(), static_cast(this->_internal_url().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateCameraRequest.url"); - target = stream->WriteStringMaybeAliased( - 4, this->_internal_url(), target); - } - - // uint32 skipinterval = 5; - if (this->skipinterval() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(5, this->_internal_skipinterval(), target); - } - - // uint32 direction = 6; - if (this->direction() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(6, this->_internal_direction(), target); - } - - // uint32 left_first = 7; - if (this->left_first() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(7, this->_internal_left_first(), target); - } - - // uint32 right_first = 8; - if (this->right_first() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(8, this->_internal_right_first(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.UpdateCameraRequest) - return target; -} - -size_t UpdateCameraRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.UpdateCameraRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string url = 4; - if (this->url().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_url()); - } - - // uint32 head = 1; - if (this->head() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_head()); - } - - // uint32 channel_id = 2; - if (this->channel_id() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_channel_id()); - } - - // bool use = 3; - if (this->use() != 0) { - total_size += 1 + 1; - } - - // uint32 skipinterval = 5; - if (this->skipinterval() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_skipinterval()); - } - - // uint32 direction = 6; - if (this->direction() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_direction()); - } - - // uint32 left_first = 7; - if (this->left_first() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_left_first()); - } - - // uint32 right_first = 8; - if (this->right_first() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_right_first()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void UpdateCameraRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.UpdateCameraRequest) - GOOGLE_DCHECK_NE(&from, this); - const UpdateCameraRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.UpdateCameraRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.UpdateCameraRequest) - MergeFrom(*source); - } -} - -void UpdateCameraRequest::MergeFrom(const UpdateCameraRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.UpdateCameraRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.url().size() > 0) { - _internal_set_url(from._internal_url()); - } - if (from.head() != 0) { - _internal_set_head(from._internal_head()); - } - if (from.channel_id() != 0) { - _internal_set_channel_id(from._internal_channel_id()); - } - if (from.use() != 0) { - _internal_set_use(from._internal_use()); - } - if (from.skipinterval() != 0) { - _internal_set_skipinterval(from._internal_skipinterval()); - } - if (from.direction() != 0) { - _internal_set_direction(from._internal_direction()); - } - if (from.left_first() != 0) { - _internal_set_left_first(from._internal_left_first()); - } - if (from.right_first() != 0) { - _internal_set_right_first(from._internal_right_first()); - } -} - -void UpdateCameraRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.UpdateCameraRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void UpdateCameraRequest::CopyFrom(const UpdateCameraRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.UpdateCameraRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool UpdateCameraRequest::IsInitialized() const { - return true; -} - -void UpdateCameraRequest::InternalSwap(UpdateCameraRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - url_.Swap(&other->url_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(UpdateCameraRequest, right_first_) - + sizeof(UpdateCameraRequest::right_first_) - - PROTOBUF_FIELD_OFFSET(UpdateCameraRequest, head_)>( - reinterpret_cast(&head_), - reinterpret_cast(&other->head_)); -} - -::PROTOBUF_NAMESPACE_ID::Metadata UpdateCameraRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void UpdateCameraReply::InitAsDefaultInstance() { -} -class UpdateCameraReply::_Internal { - public: -}; - -UpdateCameraReply::UpdateCameraReply(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.UpdateCameraReply) -} -UpdateCameraReply::UpdateCameraReply(const UpdateCameraReply& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_error_msg().empty()) { - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_msg(), - GetArena()); - } - channel_id_ = from.channel_id_; - // @@protoc_insertion_point(copy_constructor:MatrixAi.UpdateCameraReply) -} - -void UpdateCameraReply::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_UpdateCameraReply_grpcservice_2eproto.base); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - channel_id_ = 0u; -} - -UpdateCameraReply::~UpdateCameraReply() { - // @@protoc_insertion_point(destructor:MatrixAi.UpdateCameraReply) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void UpdateCameraReply::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - error_msg_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void UpdateCameraReply::ArenaDtor(void* object) { - UpdateCameraReply* _this = reinterpret_cast< UpdateCameraReply* >(object); - (void)_this; -} -void UpdateCameraReply::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void UpdateCameraReply::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const UpdateCameraReply& UpdateCameraReply::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_UpdateCameraReply_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void UpdateCameraReply::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.UpdateCameraReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - channel_id_ = 0u; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* UpdateCameraReply::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 channel_id = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - channel_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string error_msg = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - auto str = _internal_mutable_error_msg(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateCameraReply.error_msg")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* UpdateCameraReply::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.UpdateCameraReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 channel_id = 1; - if (this->channel_id() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_channel_id(), target); - } - - // string error_msg = 2; - if (this->error_msg().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_msg().data(), static_cast(this->_internal_error_msg().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateCameraReply.error_msg"); - target = stream->WriteStringMaybeAliased( - 2, this->_internal_error_msg(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.UpdateCameraReply) - return target; -} - -size_t UpdateCameraReply::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.UpdateCameraReply) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string error_msg = 2; - if (this->error_msg().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_msg()); - } - - // uint32 channel_id = 1; - if (this->channel_id() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_channel_id()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void UpdateCameraReply::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.UpdateCameraReply) - GOOGLE_DCHECK_NE(&from, this); - const UpdateCameraReply* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.UpdateCameraReply) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.UpdateCameraReply) - MergeFrom(*source); - } -} - -void UpdateCameraReply::MergeFrom(const UpdateCameraReply& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.UpdateCameraReply) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.error_msg().size() > 0) { - _internal_set_error_msg(from._internal_error_msg()); - } - if (from.channel_id() != 0) { - _internal_set_channel_id(from._internal_channel_id()); - } -} - -void UpdateCameraReply::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.UpdateCameraReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void UpdateCameraReply::CopyFrom(const UpdateCameraReply& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.UpdateCameraReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool UpdateCameraReply::IsInitialized() const { - return true; -} - -void UpdateCameraReply::InternalSwap(UpdateCameraReply* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - error_msg_.Swap(&other->error_msg_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - swap(channel_id_, other->channel_id_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata UpdateCameraReply::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void QueryFTPRequest::InitAsDefaultInstance() { -} -class QueryFTPRequest::_Internal { - public: -}; - -QueryFTPRequest::QueryFTPRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.QueryFTPRequest) -} -QueryFTPRequest::QueryFTPRequest(const QueryFTPRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - head_ = from.head_; - // @@protoc_insertion_point(copy_constructor:MatrixAi.QueryFTPRequest) -} - -void QueryFTPRequest::SharedCtor() { - head_ = 0u; -} - -QueryFTPRequest::~QueryFTPRequest() { - // @@protoc_insertion_point(destructor:MatrixAi.QueryFTPRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void QueryFTPRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); -} - -void QueryFTPRequest::ArenaDtor(void* object) { - QueryFTPRequest* _this = reinterpret_cast< QueryFTPRequest* >(object); - (void)_this; -} -void QueryFTPRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void QueryFTPRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const QueryFTPRequest& QueryFTPRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_QueryFTPRequest_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void QueryFTPRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.QueryFTPRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - head_ = 0u; - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* QueryFTPRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 head = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - head_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* QueryFTPRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.QueryFTPRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_head(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.QueryFTPRequest) - return target; -} - -size_t QueryFTPRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.QueryFTPRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_head()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void QueryFTPRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.QueryFTPRequest) - GOOGLE_DCHECK_NE(&from, this); - const QueryFTPRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.QueryFTPRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.QueryFTPRequest) - MergeFrom(*source); - } -} - -void QueryFTPRequest::MergeFrom(const QueryFTPRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.QueryFTPRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.head() != 0) { - _internal_set_head(from._internal_head()); - } -} - -void QueryFTPRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.QueryFTPRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void QueryFTPRequest::CopyFrom(const QueryFTPRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.QueryFTPRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool QueryFTPRequest::IsInitialized() const { - return true; -} - -void QueryFTPRequest::InternalSwap(QueryFTPRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - swap(head_, other->head_); -} - -::PROTOBUF_NAMESPACE_ID::Metadata QueryFTPRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void QueryFTPReply::InitAsDefaultInstance() { -} -class QueryFTPReply::_Internal { - public: -}; - -QueryFTPReply::QueryFTPReply(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.QueryFTPReply) -} -QueryFTPReply::QueryFTPReply(const QueryFTPReply& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - username_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_username().empty()) { - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_username(), - GetArena()); - } - password_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_password().empty()) { - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_password(), - GetArena()); - } - ip_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_ip().empty()) { - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_ip(), - GetArena()); - } - image_path_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_image_path().empty()) { - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_image_path(), - GetArena()); - } - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_error_msg().empty()) { - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_msg(), - GetArena()); - } - ::memcpy(&open_, &from.open_, - static_cast(reinterpret_cast(&quit_time_) - - reinterpret_cast(&open_)) + sizeof(quit_time_)); - // @@protoc_insertion_point(copy_constructor:MatrixAi.QueryFTPReply) -} - -void QueryFTPReply::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_QueryFTPReply_grpcservice_2eproto.base); - username_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - password_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ip_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - image_path_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ::memset(&open_, 0, static_cast( - reinterpret_cast(&quit_time_) - - reinterpret_cast(&open_)) + sizeof(quit_time_)); -} - -QueryFTPReply::~QueryFTPReply() { - // @@protoc_insertion_point(destructor:MatrixAi.QueryFTPReply) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void QueryFTPReply::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - username_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - password_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ip_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - image_path_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - error_msg_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void QueryFTPReply::ArenaDtor(void* object) { - QueryFTPReply* _this = reinterpret_cast< QueryFTPReply* >(object); - (void)_this; -} -void QueryFTPReply::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void QueryFTPReply::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const QueryFTPReply& QueryFTPReply::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_QueryFTPReply_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void QueryFTPReply::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.QueryFTPReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - username_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - password_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ip_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - image_path_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::memset(&open_, 0, static_cast( - reinterpret_cast(&quit_time_) - - reinterpret_cast(&open_)) + sizeof(quit_time_)); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* QueryFTPReply::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 open = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - open_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string username = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { - auto str = _internal_mutable_username(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryFTPReply.username")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string password = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - auto str = _internal_mutable_password(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryFTPReply.password")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string ip = 4; - case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - auto str = _internal_mutable_ip(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryFTPReply.ip")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 port = 5; - case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 40)) { - port_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string image_path = 6; - case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 50)) { - auto str = _internal_mutable_image_path(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryFTPReply.image_path")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 quit_time = 7; - case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 56)) { - quit_time_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string error_msg = 8; - case 8: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 66)) { - auto str = _internal_mutable_error_msg(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.QueryFTPReply.error_msg")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* QueryFTPReply::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.QueryFTPReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 open = 1; - if (this->open() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_open(), target); - } - - // string username = 2; - if (this->username().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_username().data(), static_cast(this->_internal_username().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryFTPReply.username"); - target = stream->WriteStringMaybeAliased( - 2, this->_internal_username(), target); - } - - // string password = 3; - if (this->password().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_password().data(), static_cast(this->_internal_password().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryFTPReply.password"); - target = stream->WriteStringMaybeAliased( - 3, this->_internal_password(), target); - } - - // string ip = 4; - if (this->ip().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_ip().data(), static_cast(this->_internal_ip().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryFTPReply.ip"); - target = stream->WriteStringMaybeAliased( - 4, this->_internal_ip(), target); - } - - // uint32 port = 5; - if (this->port() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(5, this->_internal_port(), target); - } - - // string image_path = 6; - if (this->image_path().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_image_path().data(), static_cast(this->_internal_image_path().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryFTPReply.image_path"); - target = stream->WriteStringMaybeAliased( - 6, this->_internal_image_path(), target); - } - - // uint32 quit_time = 7; - if (this->quit_time() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(7, this->_internal_quit_time(), target); - } - - // string error_msg = 8; - if (this->error_msg().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_msg().data(), static_cast(this->_internal_error_msg().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.QueryFTPReply.error_msg"); - target = stream->WriteStringMaybeAliased( - 8, this->_internal_error_msg(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.QueryFTPReply) - return target; -} - -size_t QueryFTPReply::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.QueryFTPReply) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string username = 2; - if (this->username().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_username()); - } - - // string password = 3; - if (this->password().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_password()); - } - - // string ip = 4; - if (this->ip().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_ip()); - } - - // string image_path = 6; - if (this->image_path().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_image_path()); - } - - // string error_msg = 8; - if (this->error_msg().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_msg()); - } - - // uint32 open = 1; - if (this->open() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_open()); - } - - // uint32 port = 5; - if (this->port() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_port()); - } - - // uint32 quit_time = 7; - if (this->quit_time() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_quit_time()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void QueryFTPReply::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.QueryFTPReply) - GOOGLE_DCHECK_NE(&from, this); - const QueryFTPReply* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.QueryFTPReply) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.QueryFTPReply) - MergeFrom(*source); - } -} - -void QueryFTPReply::MergeFrom(const QueryFTPReply& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.QueryFTPReply) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.username().size() > 0) { - _internal_set_username(from._internal_username()); - } - if (from.password().size() > 0) { - _internal_set_password(from._internal_password()); - } - if (from.ip().size() > 0) { - _internal_set_ip(from._internal_ip()); - } - if (from.image_path().size() > 0) { - _internal_set_image_path(from._internal_image_path()); - } - if (from.error_msg().size() > 0) { - _internal_set_error_msg(from._internal_error_msg()); - } - if (from.open() != 0) { - _internal_set_open(from._internal_open()); - } - if (from.port() != 0) { - _internal_set_port(from._internal_port()); - } - if (from.quit_time() != 0) { - _internal_set_quit_time(from._internal_quit_time()); - } -} - -void QueryFTPReply::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.QueryFTPReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void QueryFTPReply::CopyFrom(const QueryFTPReply& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.QueryFTPReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool QueryFTPReply::IsInitialized() const { - return true; -} - -void QueryFTPReply::InternalSwap(QueryFTPReply* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - username_.Swap(&other->username_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - password_.Swap(&other->password_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ip_.Swap(&other->ip_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - image_path_.Swap(&other->image_path_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - error_msg_.Swap(&other->error_msg_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(QueryFTPReply, quit_time_) - + sizeof(QueryFTPReply::quit_time_) - - PROTOBUF_FIELD_OFFSET(QueryFTPReply, open_)>( - reinterpret_cast(&open_), - reinterpret_cast(&other->open_)); -} - -::PROTOBUF_NAMESPACE_ID::Metadata QueryFTPReply::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void UpdateFTPRequest::InitAsDefaultInstance() { -} -class UpdateFTPRequest::_Internal { - public: -}; - -UpdateFTPRequest::UpdateFTPRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.UpdateFTPRequest) -} -UpdateFTPRequest::UpdateFTPRequest(const UpdateFTPRequest& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - username_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_username().empty()) { - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_username(), - GetArena()); - } - password_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_password().empty()) { - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_password(), - GetArena()); - } - ip_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_ip().empty()) { - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_ip(), - GetArena()); - } - image_path_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_image_path().empty()) { - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_image_path(), - GetArena()); - } - ::memcpy(&head_, &from.head_, - static_cast(reinterpret_cast(&quit_time_) - - reinterpret_cast(&head_)) + sizeof(quit_time_)); - // @@protoc_insertion_point(copy_constructor:MatrixAi.UpdateFTPRequest) -} - -void UpdateFTPRequest::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_UpdateFTPRequest_grpcservice_2eproto.base); - username_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - password_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ip_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - image_path_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ::memset(&head_, 0, static_cast( - reinterpret_cast(&quit_time_) - - reinterpret_cast(&head_)) + sizeof(quit_time_)); -} - -UpdateFTPRequest::~UpdateFTPRequest() { - // @@protoc_insertion_point(destructor:MatrixAi.UpdateFTPRequest) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void UpdateFTPRequest::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - username_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - password_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - ip_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - image_path_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void UpdateFTPRequest::ArenaDtor(void* object) { - UpdateFTPRequest* _this = reinterpret_cast< UpdateFTPRequest* >(object); - (void)_this; -} -void UpdateFTPRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void UpdateFTPRequest::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const UpdateFTPRequest& UpdateFTPRequest::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_UpdateFTPRequest_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void UpdateFTPRequest::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.UpdateFTPRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - username_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - password_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ip_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - image_path_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::memset(&head_, 0, static_cast( - reinterpret_cast(&quit_time_) - - reinterpret_cast(&head_)) + sizeof(quit_time_)); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* UpdateFTPRequest::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // uint32 head = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { - head_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 open = 2; - case 2: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16)) { - open_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string username = 3; - case 3: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { - auto str = _internal_mutable_username(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateFTPRequest.username")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string password = 4; - case 4: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 34)) { - auto str = _internal_mutable_password(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateFTPRequest.password")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string ip = 5; - case 5: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 42)) { - auto str = _internal_mutable_ip(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateFTPRequest.ip")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 port = 6; - case 6: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 48)) { - port_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - // string image_path = 7; - case 7: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 58)) { - auto str = _internal_mutable_image_path(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateFTPRequest.image_path")); - CHK_(ptr); - } else goto handle_unusual; - continue; - // uint32 quit_time = 8; - case 8: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 64)) { - quit_time_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* UpdateFTPRequest::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.UpdateFTPRequest) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // uint32 head = 1; - if (this->head() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(1, this->_internal_head(), target); - } - - // uint32 open = 2; - if (this->open() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(2, this->_internal_open(), target); - } - - // string username = 3; - if (this->username().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_username().data(), static_cast(this->_internal_username().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateFTPRequest.username"); - target = stream->WriteStringMaybeAliased( - 3, this->_internal_username(), target); - } - - // string password = 4; - if (this->password().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_password().data(), static_cast(this->_internal_password().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateFTPRequest.password"); - target = stream->WriteStringMaybeAliased( - 4, this->_internal_password(), target); - } - - // string ip = 5; - if (this->ip().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_ip().data(), static_cast(this->_internal_ip().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateFTPRequest.ip"); - target = stream->WriteStringMaybeAliased( - 5, this->_internal_ip(), target); - } - - // uint32 port = 6; - if (this->port() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(6, this->_internal_port(), target); - } - - // string image_path = 7; - if (this->image_path().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_image_path().data(), static_cast(this->_internal_image_path().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateFTPRequest.image_path"); - target = stream->WriteStringMaybeAliased( - 7, this->_internal_image_path(), target); - } - - // uint32 quit_time = 8; - if (this->quit_time() != 0) { - target = stream->EnsureSpace(target); - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(8, this->_internal_quit_time(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.UpdateFTPRequest) - return target; -} - -size_t UpdateFTPRequest::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.UpdateFTPRequest) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string username = 3; - if (this->username().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_username()); - } - - // string password = 4; - if (this->password().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_password()); - } - - // string ip = 5; - if (this->ip().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_ip()); - } - - // string image_path = 7; - if (this->image_path().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_image_path()); - } - - // uint32 head = 1; - if (this->head() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_head()); - } - - // uint32 open = 2; - if (this->open() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_open()); - } - - // uint32 port = 6; - if (this->port() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_port()); - } - - // uint32 quit_time = 8; - if (this->quit_time() != 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( - this->_internal_quit_time()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void UpdateFTPRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.UpdateFTPRequest) - GOOGLE_DCHECK_NE(&from, this); - const UpdateFTPRequest* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.UpdateFTPRequest) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.UpdateFTPRequest) - MergeFrom(*source); - } -} - -void UpdateFTPRequest::MergeFrom(const UpdateFTPRequest& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.UpdateFTPRequest) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.username().size() > 0) { - _internal_set_username(from._internal_username()); - } - if (from.password().size() > 0) { - _internal_set_password(from._internal_password()); - } - if (from.ip().size() > 0) { - _internal_set_ip(from._internal_ip()); - } - if (from.image_path().size() > 0) { - _internal_set_image_path(from._internal_image_path()); - } - if (from.head() != 0) { - _internal_set_head(from._internal_head()); - } - if (from.open() != 0) { - _internal_set_open(from._internal_open()); - } - if (from.port() != 0) { - _internal_set_port(from._internal_port()); - } - if (from.quit_time() != 0) { - _internal_set_quit_time(from._internal_quit_time()); - } -} - -void UpdateFTPRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.UpdateFTPRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void UpdateFTPRequest::CopyFrom(const UpdateFTPRequest& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.UpdateFTPRequest) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool UpdateFTPRequest::IsInitialized() const { - return true; -} - -void UpdateFTPRequest::InternalSwap(UpdateFTPRequest* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - username_.Swap(&other->username_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - password_.Swap(&other->password_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ip_.Swap(&other->ip_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - image_path_.Swap(&other->image_path_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - ::PROTOBUF_NAMESPACE_ID::internal::memswap< - PROTOBUF_FIELD_OFFSET(UpdateFTPRequest, quit_time_) - + sizeof(UpdateFTPRequest::quit_time_) - - PROTOBUF_FIELD_OFFSET(UpdateFTPRequest, head_)>( - reinterpret_cast(&head_), - reinterpret_cast(&other->head_)); -} - -::PROTOBUF_NAMESPACE_ID::Metadata UpdateFTPRequest::GetMetadata() const { - return GetMetadataStatic(); -} - - -// =================================================================== - -void UpdateFTPReply::InitAsDefaultInstance() { -} -class UpdateFTPReply::_Internal { - public: -}; - -UpdateFTPReply::UpdateFTPReply(::PROTOBUF_NAMESPACE_ID::Arena* arena) - : ::PROTOBUF_NAMESPACE_ID::Message(arena) { - SharedCtor(); - RegisterArenaDtor(arena); - // @@protoc_insertion_point(arena_constructor:MatrixAi.UpdateFTPReply) -} -UpdateFTPReply::UpdateFTPReply(const UpdateFTPReply& from) - : ::PROTOBUF_NAMESPACE_ID::Message() { - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); - if (!from._internal_error_msg().empty()) { - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_error_msg(), - GetArena()); - } - // @@protoc_insertion_point(copy_constructor:MatrixAi.UpdateFTPReply) -} - -void UpdateFTPReply::SharedCtor() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_UpdateFTPReply_grpcservice_2eproto.base); - error_msg_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -UpdateFTPReply::~UpdateFTPReply() { - // @@protoc_insertion_point(destructor:MatrixAi.UpdateFTPReply) - SharedDtor(); - _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -void UpdateFTPReply::SharedDtor() { - GOOGLE_DCHECK(GetArena() == nullptr); - error_msg_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); -} - -void UpdateFTPReply::ArenaDtor(void* object) { - UpdateFTPReply* _this = reinterpret_cast< UpdateFTPReply* >(object); - (void)_this; -} -void UpdateFTPReply::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { -} -void UpdateFTPReply::SetCachedSize(int size) const { - _cached_size_.Set(size); -} -const UpdateFTPReply& UpdateFTPReply::default_instance() { - ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_UpdateFTPReply_grpcservice_2eproto.base); - return *internal_default_instance(); -} - - -void UpdateFTPReply::Clear() { -// @@protoc_insertion_point(message_clear_start:MatrixAi.UpdateFTPReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); - _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); -} - -const char* UpdateFTPReply::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { -#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure - ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; - while (!ctx->Done(&ptr)) { - ::PROTOBUF_NAMESPACE_ID::uint32 tag; - ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); - CHK_(ptr); - switch (tag >> 3) { - // string error_msg = 1; - case 1: - if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { - auto str = _internal_mutable_error_msg(); - ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); - CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "MatrixAi.UpdateFTPReply.error_msg")); - CHK_(ptr); - } else goto handle_unusual; - continue; - default: { - handle_unusual: - if ((tag & 7) == 4 || tag == 0) { - ctx->SetLastTag(tag); - goto success; - } - ptr = UnknownFieldParse(tag, - _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), - ptr, ctx); - CHK_(ptr != nullptr); - continue; - } - } // switch - } // while -success: - return ptr; -failure: - ptr = nullptr; - goto success; -#undef CHK_ -} - -::PROTOBUF_NAMESPACE_ID::uint8* UpdateFTPReply::_InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { - // @@protoc_insertion_point(serialize_to_array_start:MatrixAi.UpdateFTPReply) - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - // string error_msg = 1; - if (this->error_msg().size() > 0) { - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( - this->_internal_error_msg().data(), static_cast(this->_internal_error_msg().length()), - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, - "MatrixAi.UpdateFTPReply.error_msg"); - target = stream->WriteStringMaybeAliased( - 1, this->_internal_error_msg(), target); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::InternalSerializeUnknownFieldsToArray( - _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); - } - // @@protoc_insertion_point(serialize_to_array_end:MatrixAi.UpdateFTPReply) - return target; -} - -size_t UpdateFTPReply::ByteSizeLong() const { -// @@protoc_insertion_point(message_byte_size_start:MatrixAi.UpdateFTPReply) - size_t total_size = 0; - - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - // Prevent compiler warnings about cached_has_bits being unused - (void) cached_has_bits; - - // string error_msg = 1; - if (this->error_msg().size() > 0) { - total_size += 1 + - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( - this->_internal_error_msg()); - } - - if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { - return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( - _internal_metadata_, total_size, &_cached_size_); - } - int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); - SetCachedSize(cached_size); - return total_size; -} - -void UpdateFTPReply::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_merge_from_start:MatrixAi.UpdateFTPReply) - GOOGLE_DCHECK_NE(&from, this); - const UpdateFTPReply* source = - ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( - &from); - if (source == nullptr) { - // @@protoc_insertion_point(generalized_merge_from_cast_fail:MatrixAi.UpdateFTPReply) - ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); - } else { - // @@protoc_insertion_point(generalized_merge_from_cast_success:MatrixAi.UpdateFTPReply) - MergeFrom(*source); - } -} - -void UpdateFTPReply::MergeFrom(const UpdateFTPReply& from) { -// @@protoc_insertion_point(class_specific_merge_from_start:MatrixAi.UpdateFTPReply) - GOOGLE_DCHECK_NE(&from, this); - _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); - ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; - (void) cached_has_bits; - - if (from.error_msg().size() > 0) { - _internal_set_error_msg(from._internal_error_msg()); - } -} - -void UpdateFTPReply::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { -// @@protoc_insertion_point(generalized_copy_from_start:MatrixAi.UpdateFTPReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -void UpdateFTPReply::CopyFrom(const UpdateFTPReply& from) { -// @@protoc_insertion_point(class_specific_copy_from_start:MatrixAi.UpdateFTPReply) - if (&from == this) return; - Clear(); - MergeFrom(from); -} - -bool UpdateFTPReply::IsInitialized() const { - return true; -} - -void UpdateFTPReply::InternalSwap(UpdateFTPReply* other) { - using std::swap; - _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); - error_msg_.Swap(&other->error_msg_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} - -::PROTOBUF_NAMESPACE_ID::Metadata UpdateFTPReply::GetMetadata() const { - return GetMetadataStatic(); -} - - -// @@protoc_insertion_point(namespace_scope) -} // namespace MatrixAi -PROTOBUF_NAMESPACE_OPEN -template<> PROTOBUF_NOINLINE ::MatrixAi::Request* Arena::CreateMaybeMessage< ::MatrixAi::Request >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::Request >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::Reply* Arena::CreateMaybeMessage< ::MatrixAi::Reply >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::Reply >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::QueryWorkstationRequest* Arena::CreateMaybeMessage< ::MatrixAi::QueryWorkstationRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::QueryWorkstationRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::QueryWorkstationReply* Arena::CreateMaybeMessage< ::MatrixAi::QueryWorkstationReply >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::QueryWorkstationReply >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::UpdateWorkstationRequest* Arena::CreateMaybeMessage< ::MatrixAi::UpdateWorkstationRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::UpdateWorkstationRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::UpdateWorkstationReply* Arena::CreateMaybeMessage< ::MatrixAi::UpdateWorkstationReply >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::UpdateWorkstationReply >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::QueryCameraRequest* Arena::CreateMaybeMessage< ::MatrixAi::QueryCameraRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::QueryCameraRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::QueryCameraReply* Arena::CreateMaybeMessage< ::MatrixAi::QueryCameraReply >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::QueryCameraReply >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::UpdateCameraRequest* Arena::CreateMaybeMessage< ::MatrixAi::UpdateCameraRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::UpdateCameraRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::UpdateCameraReply* Arena::CreateMaybeMessage< ::MatrixAi::UpdateCameraReply >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::UpdateCameraReply >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::QueryFTPRequest* Arena::CreateMaybeMessage< ::MatrixAi::QueryFTPRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::QueryFTPRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::QueryFTPReply* Arena::CreateMaybeMessage< ::MatrixAi::QueryFTPReply >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::QueryFTPReply >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::UpdateFTPRequest* Arena::CreateMaybeMessage< ::MatrixAi::UpdateFTPRequest >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::UpdateFTPRequest >(arena); -} -template<> PROTOBUF_NOINLINE ::MatrixAi::UpdateFTPReply* Arena::CreateMaybeMessage< ::MatrixAi::UpdateFTPReply >(Arena* arena) { - return Arena::CreateMessageInternal< ::MatrixAi::UpdateFTPReply >(arena); -} -PROTOBUF_NAMESPACE_CLOSE - -// @@protoc_insertion_point(global_scope) -#include diff --git a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.pb.h b/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.pb.h deleted file mode 100644 index 5956383..0000000 --- a/nvidia_ascend_engine/common_engine/GrpcEngine/grpcservice.pb.h +++ /dev/null @@ -1,4500 +0,0 @@ -// Generated by the protocol buffer compiler. DO NOT EDIT! -// source: grpcservice.proto - -#ifndef GOOGLE_PROTOBUF_INCLUDED_grpcservice_2eproto -#define GOOGLE_PROTOBUF_INCLUDED_grpcservice_2eproto - -#include -#include - -#include -#if PROTOBUF_VERSION < 3013000 -#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 3013000 < 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include // IWYU pragma: export -#include // IWYU pragma: export -#include -// @@protoc_insertion_point(includes) -#include -#define PROTOBUF_INTERNAL_EXPORT_grpcservice_2eproto -PROTOBUF_NAMESPACE_OPEN -namespace internal { -class AnyMetadata; -} // namespace internal -PROTOBUF_NAMESPACE_CLOSE - -// Internal implementation detail -- do not use these members. -struct TableStruct_grpcservice_2eproto { - static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] - PROTOBUF_SECTION_VARIABLE(protodesc_cold); - static const ::PROTOBUF_NAMESPACE_ID::internal::AuxiliaryParseTableField aux[] - PROTOBUF_SECTION_VARIABLE(protodesc_cold); - static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[14] - PROTOBUF_SECTION_VARIABLE(protodesc_cold); - static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; - static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; - static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[]; -}; -extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_grpcservice_2eproto; -namespace MatrixAi { -class QueryCameraReply; -class QueryCameraReplyDefaultTypeInternal; -extern QueryCameraReplyDefaultTypeInternal _QueryCameraReply_default_instance_; -class QueryCameraRequest; -class QueryCameraRequestDefaultTypeInternal; -extern QueryCameraRequestDefaultTypeInternal _QueryCameraRequest_default_instance_; -class QueryFTPReply; -class QueryFTPReplyDefaultTypeInternal; -extern QueryFTPReplyDefaultTypeInternal _QueryFTPReply_default_instance_; -class QueryFTPRequest; -class QueryFTPRequestDefaultTypeInternal; -extern QueryFTPRequestDefaultTypeInternal _QueryFTPRequest_default_instance_; -class QueryWorkstationReply; -class QueryWorkstationReplyDefaultTypeInternal; -extern QueryWorkstationReplyDefaultTypeInternal _QueryWorkstationReply_default_instance_; -class QueryWorkstationRequest; -class QueryWorkstationRequestDefaultTypeInternal; -extern QueryWorkstationRequestDefaultTypeInternal _QueryWorkstationRequest_default_instance_; -class Reply; -class ReplyDefaultTypeInternal; -extern ReplyDefaultTypeInternal _Reply_default_instance_; -class Request; -class RequestDefaultTypeInternal; -extern RequestDefaultTypeInternal _Request_default_instance_; -class UpdateCameraReply; -class UpdateCameraReplyDefaultTypeInternal; -extern UpdateCameraReplyDefaultTypeInternal _UpdateCameraReply_default_instance_; -class UpdateCameraRequest; -class UpdateCameraRequestDefaultTypeInternal; -extern UpdateCameraRequestDefaultTypeInternal _UpdateCameraRequest_default_instance_; -class UpdateFTPReply; -class UpdateFTPReplyDefaultTypeInternal; -extern UpdateFTPReplyDefaultTypeInternal _UpdateFTPReply_default_instance_; -class UpdateFTPRequest; -class UpdateFTPRequestDefaultTypeInternal; -extern UpdateFTPRequestDefaultTypeInternal _UpdateFTPRequest_default_instance_; -class UpdateWorkstationReply; -class UpdateWorkstationReplyDefaultTypeInternal; -extern UpdateWorkstationReplyDefaultTypeInternal _UpdateWorkstationReply_default_instance_; -class UpdateWorkstationRequest; -class UpdateWorkstationRequestDefaultTypeInternal; -extern UpdateWorkstationRequestDefaultTypeInternal _UpdateWorkstationRequest_default_instance_; -} // namespace MatrixAi -PROTOBUF_NAMESPACE_OPEN -template<> ::MatrixAi::QueryCameraReply* Arena::CreateMaybeMessage<::MatrixAi::QueryCameraReply>(Arena*); -template<> ::MatrixAi::QueryCameraRequest* Arena::CreateMaybeMessage<::MatrixAi::QueryCameraRequest>(Arena*); -template<> ::MatrixAi::QueryFTPReply* Arena::CreateMaybeMessage<::MatrixAi::QueryFTPReply>(Arena*); -template<> ::MatrixAi::QueryFTPRequest* Arena::CreateMaybeMessage<::MatrixAi::QueryFTPRequest>(Arena*); -template<> ::MatrixAi::QueryWorkstationReply* Arena::CreateMaybeMessage<::MatrixAi::QueryWorkstationReply>(Arena*); -template<> ::MatrixAi::QueryWorkstationRequest* Arena::CreateMaybeMessage<::MatrixAi::QueryWorkstationRequest>(Arena*); -template<> ::MatrixAi::Reply* Arena::CreateMaybeMessage<::MatrixAi::Reply>(Arena*); -template<> ::MatrixAi::Request* Arena::CreateMaybeMessage<::MatrixAi::Request>(Arena*); -template<> ::MatrixAi::UpdateCameraReply* Arena::CreateMaybeMessage<::MatrixAi::UpdateCameraReply>(Arena*); -template<> ::MatrixAi::UpdateCameraRequest* Arena::CreateMaybeMessage<::MatrixAi::UpdateCameraRequest>(Arena*); -template<> ::MatrixAi::UpdateFTPReply* Arena::CreateMaybeMessage<::MatrixAi::UpdateFTPReply>(Arena*); -template<> ::MatrixAi::UpdateFTPRequest* Arena::CreateMaybeMessage<::MatrixAi::UpdateFTPRequest>(Arena*); -template<> ::MatrixAi::UpdateWorkstationReply* Arena::CreateMaybeMessage<::MatrixAi::UpdateWorkstationReply>(Arena*); -template<> ::MatrixAi::UpdateWorkstationRequest* Arena::CreateMaybeMessage<::MatrixAi::UpdateWorkstationRequest>(Arena*); -PROTOBUF_NAMESPACE_CLOSE -namespace MatrixAi { - -// =================================================================== - -class Request PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.Request) */ { - public: - inline Request() : Request(nullptr) {} - virtual ~Request(); - - Request(const Request& from); - Request(Request&& from) noexcept - : Request() { - *this = ::std::move(from); - } - - inline Request& operator=(const Request& from) { - CopyFrom(from); - return *this; - } - inline Request& operator=(Request&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const Request& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const Request* internal_default_instance() { - return reinterpret_cast( - &_Request_default_instance_); - } - static constexpr int kIndexInFileMessages = - 0; - - friend void swap(Request& a, Request& b) { - a.Swap(&b); - } - inline void Swap(Request* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(Request* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline Request* New() const final { - return CreateMaybeMessage(nullptr); - } - - Request* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const Request& from); - void MergeFrom(const Request& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(Request* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.Request"; - } - protected: - explicit Request(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kHeadFieldNumber = 1, - }; - // uint32 head = 1; - void clear_head(); - ::PROTOBUF_NAMESPACE_ID::uint32 head() const; - void set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_head() const; - void _internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.Request) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::uint32 head_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class Reply PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.Reply) */ { - public: - inline Reply() : Reply(nullptr) {} - virtual ~Reply(); - - Reply(const Reply& from); - Reply(Reply&& from) noexcept - : Reply() { - *this = ::std::move(from); - } - - inline Reply& operator=(const Reply& from) { - CopyFrom(from); - return *this; - } - inline Reply& operator=(Reply&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const Reply& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const Reply* internal_default_instance() { - return reinterpret_cast( - &_Reply_default_instance_); - } - static constexpr int kIndexInFileMessages = - 1; - - friend void swap(Reply& a, Reply& b) { - a.Swap(&b); - } - inline void Swap(Reply* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(Reply* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline Reply* New() const final { - return CreateMaybeMessage(nullptr); - } - - Reply* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const Reply& from); - void MergeFrom(const Reply& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(Reply* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.Reply"; - } - protected: - explicit Reply(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kErrorMsgFieldNumber = 1, - }; - // string error_msg = 1; - void clear_error_msg(); - const std::string& error_msg() const; - void set_error_msg(const std::string& value); - void set_error_msg(std::string&& value); - void set_error_msg(const char* value); - void set_error_msg(const char* value, size_t size); - std::string* mutable_error_msg(); - std::string* release_error_msg(); - void set_allocated_error_msg(std::string* error_msg); - private: - const std::string& _internal_error_msg() const; - void _internal_set_error_msg(const std::string& value); - std::string* _internal_mutable_error_msg(); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.Reply) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_msg_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class QueryWorkstationRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.QueryWorkstationRequest) */ { - public: - inline QueryWorkstationRequest() : QueryWorkstationRequest(nullptr) {} - virtual ~QueryWorkstationRequest(); - - QueryWorkstationRequest(const QueryWorkstationRequest& from); - QueryWorkstationRequest(QueryWorkstationRequest&& from) noexcept - : QueryWorkstationRequest() { - *this = ::std::move(from); - } - - inline QueryWorkstationRequest& operator=(const QueryWorkstationRequest& from) { - CopyFrom(from); - return *this; - } - inline QueryWorkstationRequest& operator=(QueryWorkstationRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const QueryWorkstationRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const QueryWorkstationRequest* internal_default_instance() { - return reinterpret_cast( - &_QueryWorkstationRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 2; - - friend void swap(QueryWorkstationRequest& a, QueryWorkstationRequest& b) { - a.Swap(&b); - } - inline void Swap(QueryWorkstationRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(QueryWorkstationRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline QueryWorkstationRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - QueryWorkstationRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const QueryWorkstationRequest& from); - void MergeFrom(const QueryWorkstationRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(QueryWorkstationRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.QueryWorkstationRequest"; - } - protected: - explicit QueryWorkstationRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kHeadFieldNumber = 1, - }; - // uint32 head = 1; - void clear_head(); - ::PROTOBUF_NAMESPACE_ID::uint32 head() const; - void set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_head() const; - void _internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.QueryWorkstationRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::uint32 head_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class QueryWorkstationReply PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.QueryWorkstationReply) */ { - public: - inline QueryWorkstationReply() : QueryWorkstationReply(nullptr) {} - virtual ~QueryWorkstationReply(); - - QueryWorkstationReply(const QueryWorkstationReply& from); - QueryWorkstationReply(QueryWorkstationReply&& from) noexcept - : QueryWorkstationReply() { - *this = ::std::move(from); - } - - inline QueryWorkstationReply& operator=(const QueryWorkstationReply& from) { - CopyFrom(from); - return *this; - } - inline QueryWorkstationReply& operator=(QueryWorkstationReply&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const QueryWorkstationReply& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const QueryWorkstationReply* internal_default_instance() { - return reinterpret_cast( - &_QueryWorkstationReply_default_instance_); - } - static constexpr int kIndexInFileMessages = - 3; - - friend void swap(QueryWorkstationReply& a, QueryWorkstationReply& b) { - a.Swap(&b); - } - inline void Swap(QueryWorkstationReply* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(QueryWorkstationReply* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline QueryWorkstationReply* New() const final { - return CreateMaybeMessage(nullptr); - } - - QueryWorkstationReply* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const QueryWorkstationReply& from); - void MergeFrom(const QueryWorkstationReply& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(QueryWorkstationReply* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.QueryWorkstationReply"; - } - protected: - explicit QueryWorkstationReply(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kNameFieldNumber = 1, - kNameNoFieldNumber = 2, - kErrorMsgFieldNumber = 3, - }; - // string name = 1; - void clear_name(); - const std::string& name() const; - void set_name(const std::string& value); - void set_name(std::string&& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - std::string* mutable_name(); - std::string* release_name(); - void set_allocated_name(std::string* name); - private: - const std::string& _internal_name() const; - void _internal_set_name(const std::string& value); - std::string* _internal_mutable_name(); - public: - - // string name_no = 2; - void clear_name_no(); - const std::string& name_no() const; - void set_name_no(const std::string& value); - void set_name_no(std::string&& value); - void set_name_no(const char* value); - void set_name_no(const char* value, size_t size); - std::string* mutable_name_no(); - std::string* release_name_no(); - void set_allocated_name_no(std::string* name_no); - private: - const std::string& _internal_name_no() const; - void _internal_set_name_no(const std::string& value); - std::string* _internal_mutable_name_no(); - public: - - // string error_msg = 3; - void clear_error_msg(); - const std::string& error_msg() const; - void set_error_msg(const std::string& value); - void set_error_msg(std::string&& value); - void set_error_msg(const char* value); - void set_error_msg(const char* value, size_t size); - std::string* mutable_error_msg(); - std::string* release_error_msg(); - void set_allocated_error_msg(std::string* error_msg); - private: - const std::string& _internal_error_msg() const; - void _internal_set_error_msg(const std::string& value); - std::string* _internal_mutable_error_msg(); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.QueryWorkstationReply) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_no_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_msg_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class UpdateWorkstationRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.UpdateWorkstationRequest) */ { - public: - inline UpdateWorkstationRequest() : UpdateWorkstationRequest(nullptr) {} - virtual ~UpdateWorkstationRequest(); - - UpdateWorkstationRequest(const UpdateWorkstationRequest& from); - UpdateWorkstationRequest(UpdateWorkstationRequest&& from) noexcept - : UpdateWorkstationRequest() { - *this = ::std::move(from); - } - - inline UpdateWorkstationRequest& operator=(const UpdateWorkstationRequest& from) { - CopyFrom(from); - return *this; - } - inline UpdateWorkstationRequest& operator=(UpdateWorkstationRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const UpdateWorkstationRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const UpdateWorkstationRequest* internal_default_instance() { - return reinterpret_cast( - &_UpdateWorkstationRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 4; - - friend void swap(UpdateWorkstationRequest& a, UpdateWorkstationRequest& b) { - a.Swap(&b); - } - inline void Swap(UpdateWorkstationRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(UpdateWorkstationRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline UpdateWorkstationRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - UpdateWorkstationRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const UpdateWorkstationRequest& from); - void MergeFrom(const UpdateWorkstationRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(UpdateWorkstationRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.UpdateWorkstationRequest"; - } - protected: - explicit UpdateWorkstationRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kNameFieldNumber = 2, - kNameNoFieldNumber = 3, - kHeadFieldNumber = 1, - }; - // string name = 2; - void clear_name(); - const std::string& name() const; - void set_name(const std::string& value); - void set_name(std::string&& value); - void set_name(const char* value); - void set_name(const char* value, size_t size); - std::string* mutable_name(); - std::string* release_name(); - void set_allocated_name(std::string* name); - private: - const std::string& _internal_name() const; - void _internal_set_name(const std::string& value); - std::string* _internal_mutable_name(); - public: - - // string name_no = 3; - void clear_name_no(); - const std::string& name_no() const; - void set_name_no(const std::string& value); - void set_name_no(std::string&& value); - void set_name_no(const char* value); - void set_name_no(const char* value, size_t size); - std::string* mutable_name_no(); - std::string* release_name_no(); - void set_allocated_name_no(std::string* name_no); - private: - const std::string& _internal_name_no() const; - void _internal_set_name_no(const std::string& value); - std::string* _internal_mutable_name_no(); - public: - - // uint32 head = 1; - void clear_head(); - ::PROTOBUF_NAMESPACE_ID::uint32 head() const; - void set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_head() const; - void _internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.UpdateWorkstationRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_no_; - ::PROTOBUF_NAMESPACE_ID::uint32 head_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class UpdateWorkstationReply PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.UpdateWorkstationReply) */ { - public: - inline UpdateWorkstationReply() : UpdateWorkstationReply(nullptr) {} - virtual ~UpdateWorkstationReply(); - - UpdateWorkstationReply(const UpdateWorkstationReply& from); - UpdateWorkstationReply(UpdateWorkstationReply&& from) noexcept - : UpdateWorkstationReply() { - *this = ::std::move(from); - } - - inline UpdateWorkstationReply& operator=(const UpdateWorkstationReply& from) { - CopyFrom(from); - return *this; - } - inline UpdateWorkstationReply& operator=(UpdateWorkstationReply&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const UpdateWorkstationReply& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const UpdateWorkstationReply* internal_default_instance() { - return reinterpret_cast( - &_UpdateWorkstationReply_default_instance_); - } - static constexpr int kIndexInFileMessages = - 5; - - friend void swap(UpdateWorkstationReply& a, UpdateWorkstationReply& b) { - a.Swap(&b); - } - inline void Swap(UpdateWorkstationReply* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(UpdateWorkstationReply* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline UpdateWorkstationReply* New() const final { - return CreateMaybeMessage(nullptr); - } - - UpdateWorkstationReply* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const UpdateWorkstationReply& from); - void MergeFrom(const UpdateWorkstationReply& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(UpdateWorkstationReply* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.UpdateWorkstationReply"; - } - protected: - explicit UpdateWorkstationReply(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kErrorMsgFieldNumber = 1, - }; - // string error_msg = 1; - void clear_error_msg(); - const std::string& error_msg() const; - void set_error_msg(const std::string& value); - void set_error_msg(std::string&& value); - void set_error_msg(const char* value); - void set_error_msg(const char* value, size_t size); - std::string* mutable_error_msg(); - std::string* release_error_msg(); - void set_allocated_error_msg(std::string* error_msg); - private: - const std::string& _internal_error_msg() const; - void _internal_set_error_msg(const std::string& value); - std::string* _internal_mutable_error_msg(); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.UpdateWorkstationReply) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_msg_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class QueryCameraRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.QueryCameraRequest) */ { - public: - inline QueryCameraRequest() : QueryCameraRequest(nullptr) {} - virtual ~QueryCameraRequest(); - - QueryCameraRequest(const QueryCameraRequest& from); - QueryCameraRequest(QueryCameraRequest&& from) noexcept - : QueryCameraRequest() { - *this = ::std::move(from); - } - - inline QueryCameraRequest& operator=(const QueryCameraRequest& from) { - CopyFrom(from); - return *this; - } - inline QueryCameraRequest& operator=(QueryCameraRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const QueryCameraRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const QueryCameraRequest* internal_default_instance() { - return reinterpret_cast( - &_QueryCameraRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 6; - - friend void swap(QueryCameraRequest& a, QueryCameraRequest& b) { - a.Swap(&b); - } - inline void Swap(QueryCameraRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(QueryCameraRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline QueryCameraRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - QueryCameraRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const QueryCameraRequest& from); - void MergeFrom(const QueryCameraRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(QueryCameraRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.QueryCameraRequest"; - } - protected: - explicit QueryCameraRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kHeadFieldNumber = 1, - kChannelIdFieldNumber = 2, - }; - // uint32 head = 1; - void clear_head(); - ::PROTOBUF_NAMESPACE_ID::uint32 head() const; - void set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_head() const; - void _internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 channel_id = 2; - void clear_channel_id(); - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id() const; - void set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_channel_id() const; - void _internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.QueryCameraRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::uint32 head_; - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class QueryCameraReply PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.QueryCameraReply) */ { - public: - inline QueryCameraReply() : QueryCameraReply(nullptr) {} - virtual ~QueryCameraReply(); - - QueryCameraReply(const QueryCameraReply& from); - QueryCameraReply(QueryCameraReply&& from) noexcept - : QueryCameraReply() { - *this = ::std::move(from); - } - - inline QueryCameraReply& operator=(const QueryCameraReply& from) { - CopyFrom(from); - return *this; - } - inline QueryCameraReply& operator=(QueryCameraReply&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const QueryCameraReply& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const QueryCameraReply* internal_default_instance() { - return reinterpret_cast( - &_QueryCameraReply_default_instance_); - } - static constexpr int kIndexInFileMessages = - 7; - - friend void swap(QueryCameraReply& a, QueryCameraReply& b) { - a.Swap(&b); - } - inline void Swap(QueryCameraReply* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(QueryCameraReply* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline QueryCameraReply* New() const final { - return CreateMaybeMessage(nullptr); - } - - QueryCameraReply* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const QueryCameraReply& from); - void MergeFrom(const QueryCameraReply& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(QueryCameraReply* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.QueryCameraReply"; - } - protected: - explicit QueryCameraReply(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kUrlFieldNumber = 3, - kErrorMsgFieldNumber = 8, - kChannelIdFieldNumber = 1, - kUseFieldNumber = 2, - kSkipintervalFieldNumber = 4, - kDirectionFieldNumber = 5, - kLeftFirstFieldNumber = 6, - kRightFirstFieldNumber = 7, - }; - // string url = 3; - void clear_url(); - const std::string& url() const; - void set_url(const std::string& value); - void set_url(std::string&& value); - void set_url(const char* value); - void set_url(const char* value, size_t size); - std::string* mutable_url(); - std::string* release_url(); - void set_allocated_url(std::string* url); - private: - const std::string& _internal_url() const; - void _internal_set_url(const std::string& value); - std::string* _internal_mutable_url(); - public: - - // string error_msg = 8; - void clear_error_msg(); - const std::string& error_msg() const; - void set_error_msg(const std::string& value); - void set_error_msg(std::string&& value); - void set_error_msg(const char* value); - void set_error_msg(const char* value, size_t size); - std::string* mutable_error_msg(); - std::string* release_error_msg(); - void set_allocated_error_msg(std::string* error_msg); - private: - const std::string& _internal_error_msg() const; - void _internal_set_error_msg(const std::string& value); - std::string* _internal_mutable_error_msg(); - public: - - // uint32 channel_id = 1; - void clear_channel_id(); - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id() const; - void set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_channel_id() const; - void _internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // bool use = 2; - void clear_use(); - bool use() const; - void set_use(bool value); - private: - bool _internal_use() const; - void _internal_set_use(bool value); - public: - - // uint32 skipinterval = 4; - void clear_skipinterval(); - ::PROTOBUF_NAMESPACE_ID::uint32 skipinterval() const; - void set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_skipinterval() const; - void _internal_set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 direction = 5; - void clear_direction(); - ::PROTOBUF_NAMESPACE_ID::uint32 direction() const; - void set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_direction() const; - void _internal_set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 left_first = 6; - void clear_left_first(); - ::PROTOBUF_NAMESPACE_ID::uint32 left_first() const; - void set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_left_first() const; - void _internal_set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 right_first = 7; - void clear_right_first(); - ::PROTOBUF_NAMESPACE_ID::uint32 right_first() const; - void set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_right_first() const; - void _internal_set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.QueryCameraReply) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr url_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_msg_; - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id_; - bool use_; - ::PROTOBUF_NAMESPACE_ID::uint32 skipinterval_; - ::PROTOBUF_NAMESPACE_ID::uint32 direction_; - ::PROTOBUF_NAMESPACE_ID::uint32 left_first_; - ::PROTOBUF_NAMESPACE_ID::uint32 right_first_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class UpdateCameraRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.UpdateCameraRequest) */ { - public: - inline UpdateCameraRequest() : UpdateCameraRequest(nullptr) {} - virtual ~UpdateCameraRequest(); - - UpdateCameraRequest(const UpdateCameraRequest& from); - UpdateCameraRequest(UpdateCameraRequest&& from) noexcept - : UpdateCameraRequest() { - *this = ::std::move(from); - } - - inline UpdateCameraRequest& operator=(const UpdateCameraRequest& from) { - CopyFrom(from); - return *this; - } - inline UpdateCameraRequest& operator=(UpdateCameraRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const UpdateCameraRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const UpdateCameraRequest* internal_default_instance() { - return reinterpret_cast( - &_UpdateCameraRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 8; - - friend void swap(UpdateCameraRequest& a, UpdateCameraRequest& b) { - a.Swap(&b); - } - inline void Swap(UpdateCameraRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(UpdateCameraRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline UpdateCameraRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - UpdateCameraRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const UpdateCameraRequest& from); - void MergeFrom(const UpdateCameraRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(UpdateCameraRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.UpdateCameraRequest"; - } - protected: - explicit UpdateCameraRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kUrlFieldNumber = 4, - kHeadFieldNumber = 1, - kChannelIdFieldNumber = 2, - kUseFieldNumber = 3, - kSkipintervalFieldNumber = 5, - kDirectionFieldNumber = 6, - kLeftFirstFieldNumber = 7, - kRightFirstFieldNumber = 8, - }; - // string url = 4; - void clear_url(); - const std::string& url() const; - void set_url(const std::string& value); - void set_url(std::string&& value); - void set_url(const char* value); - void set_url(const char* value, size_t size); - std::string* mutable_url(); - std::string* release_url(); - void set_allocated_url(std::string* url); - private: - const std::string& _internal_url() const; - void _internal_set_url(const std::string& value); - std::string* _internal_mutable_url(); - public: - - // uint32 head = 1; - void clear_head(); - ::PROTOBUF_NAMESPACE_ID::uint32 head() const; - void set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_head() const; - void _internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 channel_id = 2; - void clear_channel_id(); - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id() const; - void set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_channel_id() const; - void _internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // bool use = 3; - void clear_use(); - bool use() const; - void set_use(bool value); - private: - bool _internal_use() const; - void _internal_set_use(bool value); - public: - - // uint32 skipinterval = 5; - void clear_skipinterval(); - ::PROTOBUF_NAMESPACE_ID::uint32 skipinterval() const; - void set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_skipinterval() const; - void _internal_set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 direction = 6; - void clear_direction(); - ::PROTOBUF_NAMESPACE_ID::uint32 direction() const; - void set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_direction() const; - void _internal_set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 left_first = 7; - void clear_left_first(); - ::PROTOBUF_NAMESPACE_ID::uint32 left_first() const; - void set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_left_first() const; - void _internal_set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 right_first = 8; - void clear_right_first(); - ::PROTOBUF_NAMESPACE_ID::uint32 right_first() const; - void set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_right_first() const; - void _internal_set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.UpdateCameraRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr url_; - ::PROTOBUF_NAMESPACE_ID::uint32 head_; - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id_; - bool use_; - ::PROTOBUF_NAMESPACE_ID::uint32 skipinterval_; - ::PROTOBUF_NAMESPACE_ID::uint32 direction_; - ::PROTOBUF_NAMESPACE_ID::uint32 left_first_; - ::PROTOBUF_NAMESPACE_ID::uint32 right_first_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class UpdateCameraReply PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.UpdateCameraReply) */ { - public: - inline UpdateCameraReply() : UpdateCameraReply(nullptr) {} - virtual ~UpdateCameraReply(); - - UpdateCameraReply(const UpdateCameraReply& from); - UpdateCameraReply(UpdateCameraReply&& from) noexcept - : UpdateCameraReply() { - *this = ::std::move(from); - } - - inline UpdateCameraReply& operator=(const UpdateCameraReply& from) { - CopyFrom(from); - return *this; - } - inline UpdateCameraReply& operator=(UpdateCameraReply&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const UpdateCameraReply& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const UpdateCameraReply* internal_default_instance() { - return reinterpret_cast( - &_UpdateCameraReply_default_instance_); - } - static constexpr int kIndexInFileMessages = - 9; - - friend void swap(UpdateCameraReply& a, UpdateCameraReply& b) { - a.Swap(&b); - } - inline void Swap(UpdateCameraReply* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(UpdateCameraReply* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline UpdateCameraReply* New() const final { - return CreateMaybeMessage(nullptr); - } - - UpdateCameraReply* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const UpdateCameraReply& from); - void MergeFrom(const UpdateCameraReply& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(UpdateCameraReply* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.UpdateCameraReply"; - } - protected: - explicit UpdateCameraReply(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kErrorMsgFieldNumber = 2, - kChannelIdFieldNumber = 1, - }; - // string error_msg = 2; - void clear_error_msg(); - const std::string& error_msg() const; - void set_error_msg(const std::string& value); - void set_error_msg(std::string&& value); - void set_error_msg(const char* value); - void set_error_msg(const char* value, size_t size); - std::string* mutable_error_msg(); - std::string* release_error_msg(); - void set_allocated_error_msg(std::string* error_msg); - private: - const std::string& _internal_error_msg() const; - void _internal_set_error_msg(const std::string& value); - std::string* _internal_mutable_error_msg(); - public: - - // uint32 channel_id = 1; - void clear_channel_id(); - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id() const; - void set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_channel_id() const; - void _internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.UpdateCameraReply) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_msg_; - ::PROTOBUF_NAMESPACE_ID::uint32 channel_id_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class QueryFTPRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.QueryFTPRequest) */ { - public: - inline QueryFTPRequest() : QueryFTPRequest(nullptr) {} - virtual ~QueryFTPRequest(); - - QueryFTPRequest(const QueryFTPRequest& from); - QueryFTPRequest(QueryFTPRequest&& from) noexcept - : QueryFTPRequest() { - *this = ::std::move(from); - } - - inline QueryFTPRequest& operator=(const QueryFTPRequest& from) { - CopyFrom(from); - return *this; - } - inline QueryFTPRequest& operator=(QueryFTPRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const QueryFTPRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const QueryFTPRequest* internal_default_instance() { - return reinterpret_cast( - &_QueryFTPRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 10; - - friend void swap(QueryFTPRequest& a, QueryFTPRequest& b) { - a.Swap(&b); - } - inline void Swap(QueryFTPRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(QueryFTPRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline QueryFTPRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - QueryFTPRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const QueryFTPRequest& from); - void MergeFrom(const QueryFTPRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(QueryFTPRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.QueryFTPRequest"; - } - protected: - explicit QueryFTPRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kHeadFieldNumber = 1, - }; - // uint32 head = 1; - void clear_head(); - ::PROTOBUF_NAMESPACE_ID::uint32 head() const; - void set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_head() const; - void _internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.QueryFTPRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::uint32 head_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class QueryFTPReply PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.QueryFTPReply) */ { - public: - inline QueryFTPReply() : QueryFTPReply(nullptr) {} - virtual ~QueryFTPReply(); - - QueryFTPReply(const QueryFTPReply& from); - QueryFTPReply(QueryFTPReply&& from) noexcept - : QueryFTPReply() { - *this = ::std::move(from); - } - - inline QueryFTPReply& operator=(const QueryFTPReply& from) { - CopyFrom(from); - return *this; - } - inline QueryFTPReply& operator=(QueryFTPReply&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const QueryFTPReply& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const QueryFTPReply* internal_default_instance() { - return reinterpret_cast( - &_QueryFTPReply_default_instance_); - } - static constexpr int kIndexInFileMessages = - 11; - - friend void swap(QueryFTPReply& a, QueryFTPReply& b) { - a.Swap(&b); - } - inline void Swap(QueryFTPReply* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(QueryFTPReply* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline QueryFTPReply* New() const final { - return CreateMaybeMessage(nullptr); - } - - QueryFTPReply* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const QueryFTPReply& from); - void MergeFrom(const QueryFTPReply& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(QueryFTPReply* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.QueryFTPReply"; - } - protected: - explicit QueryFTPReply(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kUsernameFieldNumber = 2, - kPasswordFieldNumber = 3, - kIpFieldNumber = 4, - kImagePathFieldNumber = 6, - kErrorMsgFieldNumber = 8, - kOpenFieldNumber = 1, - kPortFieldNumber = 5, - kQuitTimeFieldNumber = 7, - }; - // string username = 2; - void clear_username(); - const std::string& username() const; - void set_username(const std::string& value); - void set_username(std::string&& value); - void set_username(const char* value); - void set_username(const char* value, size_t size); - std::string* mutable_username(); - std::string* release_username(); - void set_allocated_username(std::string* username); - private: - const std::string& _internal_username() const; - void _internal_set_username(const std::string& value); - std::string* _internal_mutable_username(); - public: - - // string password = 3; - void clear_password(); - const std::string& password() const; - void set_password(const std::string& value); - void set_password(std::string&& value); - void set_password(const char* value); - void set_password(const char* value, size_t size); - std::string* mutable_password(); - std::string* release_password(); - void set_allocated_password(std::string* password); - private: - const std::string& _internal_password() const; - void _internal_set_password(const std::string& value); - std::string* _internal_mutable_password(); - public: - - // string ip = 4; - void clear_ip(); - const std::string& ip() const; - void set_ip(const std::string& value); - void set_ip(std::string&& value); - void set_ip(const char* value); - void set_ip(const char* value, size_t size); - std::string* mutable_ip(); - std::string* release_ip(); - void set_allocated_ip(std::string* ip); - private: - const std::string& _internal_ip() const; - void _internal_set_ip(const std::string& value); - std::string* _internal_mutable_ip(); - public: - - // string image_path = 6; - void clear_image_path(); - const std::string& image_path() const; - void set_image_path(const std::string& value); - void set_image_path(std::string&& value); - void set_image_path(const char* value); - void set_image_path(const char* value, size_t size); - std::string* mutable_image_path(); - std::string* release_image_path(); - void set_allocated_image_path(std::string* image_path); - private: - const std::string& _internal_image_path() const; - void _internal_set_image_path(const std::string& value); - std::string* _internal_mutable_image_path(); - public: - - // string error_msg = 8; - void clear_error_msg(); - const std::string& error_msg() const; - void set_error_msg(const std::string& value); - void set_error_msg(std::string&& value); - void set_error_msg(const char* value); - void set_error_msg(const char* value, size_t size); - std::string* mutable_error_msg(); - std::string* release_error_msg(); - void set_allocated_error_msg(std::string* error_msg); - private: - const std::string& _internal_error_msg() const; - void _internal_set_error_msg(const std::string& value); - std::string* _internal_mutable_error_msg(); - public: - - // uint32 open = 1; - void clear_open(); - ::PROTOBUF_NAMESPACE_ID::uint32 open() const; - void set_open(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_open() const; - void _internal_set_open(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 port = 5; - void clear_port(); - ::PROTOBUF_NAMESPACE_ID::uint32 port() const; - void set_port(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_port() const; - void _internal_set_port(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 quit_time = 7; - void clear_quit_time(); - ::PROTOBUF_NAMESPACE_ID::uint32 quit_time() const; - void set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_quit_time() const; - void _internal_set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.QueryFTPReply) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr username_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr password_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr ip_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr image_path_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_msg_; - ::PROTOBUF_NAMESPACE_ID::uint32 open_; - ::PROTOBUF_NAMESPACE_ID::uint32 port_; - ::PROTOBUF_NAMESPACE_ID::uint32 quit_time_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class UpdateFTPRequest PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.UpdateFTPRequest) */ { - public: - inline UpdateFTPRequest() : UpdateFTPRequest(nullptr) {} - virtual ~UpdateFTPRequest(); - - UpdateFTPRequest(const UpdateFTPRequest& from); - UpdateFTPRequest(UpdateFTPRequest&& from) noexcept - : UpdateFTPRequest() { - *this = ::std::move(from); - } - - inline UpdateFTPRequest& operator=(const UpdateFTPRequest& from) { - CopyFrom(from); - return *this; - } - inline UpdateFTPRequest& operator=(UpdateFTPRequest&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const UpdateFTPRequest& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const UpdateFTPRequest* internal_default_instance() { - return reinterpret_cast( - &_UpdateFTPRequest_default_instance_); - } - static constexpr int kIndexInFileMessages = - 12; - - friend void swap(UpdateFTPRequest& a, UpdateFTPRequest& b) { - a.Swap(&b); - } - inline void Swap(UpdateFTPRequest* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(UpdateFTPRequest* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline UpdateFTPRequest* New() const final { - return CreateMaybeMessage(nullptr); - } - - UpdateFTPRequest* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const UpdateFTPRequest& from); - void MergeFrom(const UpdateFTPRequest& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(UpdateFTPRequest* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.UpdateFTPRequest"; - } - protected: - explicit UpdateFTPRequest(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kUsernameFieldNumber = 3, - kPasswordFieldNumber = 4, - kIpFieldNumber = 5, - kImagePathFieldNumber = 7, - kHeadFieldNumber = 1, - kOpenFieldNumber = 2, - kPortFieldNumber = 6, - kQuitTimeFieldNumber = 8, - }; - // string username = 3; - void clear_username(); - const std::string& username() const; - void set_username(const std::string& value); - void set_username(std::string&& value); - void set_username(const char* value); - void set_username(const char* value, size_t size); - std::string* mutable_username(); - std::string* release_username(); - void set_allocated_username(std::string* username); - private: - const std::string& _internal_username() const; - void _internal_set_username(const std::string& value); - std::string* _internal_mutable_username(); - public: - - // string password = 4; - void clear_password(); - const std::string& password() const; - void set_password(const std::string& value); - void set_password(std::string&& value); - void set_password(const char* value); - void set_password(const char* value, size_t size); - std::string* mutable_password(); - std::string* release_password(); - void set_allocated_password(std::string* password); - private: - const std::string& _internal_password() const; - void _internal_set_password(const std::string& value); - std::string* _internal_mutable_password(); - public: - - // string ip = 5; - void clear_ip(); - const std::string& ip() const; - void set_ip(const std::string& value); - void set_ip(std::string&& value); - void set_ip(const char* value); - void set_ip(const char* value, size_t size); - std::string* mutable_ip(); - std::string* release_ip(); - void set_allocated_ip(std::string* ip); - private: - const std::string& _internal_ip() const; - void _internal_set_ip(const std::string& value); - std::string* _internal_mutable_ip(); - public: - - // string image_path = 7; - void clear_image_path(); - const std::string& image_path() const; - void set_image_path(const std::string& value); - void set_image_path(std::string&& value); - void set_image_path(const char* value); - void set_image_path(const char* value, size_t size); - std::string* mutable_image_path(); - std::string* release_image_path(); - void set_allocated_image_path(std::string* image_path); - private: - const std::string& _internal_image_path() const; - void _internal_set_image_path(const std::string& value); - std::string* _internal_mutable_image_path(); - public: - - // uint32 head = 1; - void clear_head(); - ::PROTOBUF_NAMESPACE_ID::uint32 head() const; - void set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_head() const; - void _internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 open = 2; - void clear_open(); - ::PROTOBUF_NAMESPACE_ID::uint32 open() const; - void set_open(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_open() const; - void _internal_set_open(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 port = 6; - void clear_port(); - ::PROTOBUF_NAMESPACE_ID::uint32 port() const; - void set_port(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_port() const; - void _internal_set_port(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // uint32 quit_time = 8; - void clear_quit_time(); - ::PROTOBUF_NAMESPACE_ID::uint32 quit_time() const; - void set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value); - private: - ::PROTOBUF_NAMESPACE_ID::uint32 _internal_quit_time() const; - void _internal_set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.UpdateFTPRequest) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr username_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr password_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr ip_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr image_path_; - ::PROTOBUF_NAMESPACE_ID::uint32 head_; - ::PROTOBUF_NAMESPACE_ID::uint32 open_; - ::PROTOBUF_NAMESPACE_ID::uint32 port_; - ::PROTOBUF_NAMESPACE_ID::uint32 quit_time_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// ------------------------------------------------------------------- - -class UpdateFTPReply PROTOBUF_FINAL : - public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:MatrixAi.UpdateFTPReply) */ { - public: - inline UpdateFTPReply() : UpdateFTPReply(nullptr) {} - virtual ~UpdateFTPReply(); - - UpdateFTPReply(const UpdateFTPReply& from); - UpdateFTPReply(UpdateFTPReply&& from) noexcept - : UpdateFTPReply() { - *this = ::std::move(from); - } - - inline UpdateFTPReply& operator=(const UpdateFTPReply& from) { - CopyFrom(from); - return *this; - } - inline UpdateFTPReply& operator=(UpdateFTPReply&& from) noexcept { - if (GetArena() == from.GetArena()) { - if (this != &from) InternalSwap(&from); - } else { - CopyFrom(from); - } - return *this; - } - - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { - return GetDescriptor(); - } - static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { - return GetMetadataStatic().descriptor; - } - static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { - return GetMetadataStatic().reflection; - } - static const UpdateFTPReply& default_instance(); - - static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY - static inline const UpdateFTPReply* internal_default_instance() { - return reinterpret_cast( - &_UpdateFTPReply_default_instance_); - } - static constexpr int kIndexInFileMessages = - 13; - - friend void swap(UpdateFTPReply& a, UpdateFTPReply& b) { - a.Swap(&b); - } - inline void Swap(UpdateFTPReply* other) { - if (other == this) return; - if (GetArena() == other->GetArena()) { - InternalSwap(other); - } else { - ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); - } - } - void UnsafeArenaSwap(UpdateFTPReply* other) { - if (other == this) return; - GOOGLE_DCHECK(GetArena() == other->GetArena()); - InternalSwap(other); - } - - // implements Message ---------------------------------------------- - - inline UpdateFTPReply* New() const final { - return CreateMaybeMessage(nullptr); - } - - UpdateFTPReply* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { - return CreateMaybeMessage(arena); - } - void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; - void CopyFrom(const UpdateFTPReply& from); - void MergeFrom(const UpdateFTPReply& from); - PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; - bool IsInitialized() const final; - - size_t ByteSizeLong() const final; - const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; - ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( - ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; - int GetCachedSize() const final { return _cached_size_.Get(); } - - private: - inline void SharedCtor(); - inline void SharedDtor(); - void SetCachedSize(int size) const final; - void InternalSwap(UpdateFTPReply* other); - friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; - static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { - return "MatrixAi.UpdateFTPReply"; - } - protected: - explicit UpdateFTPReply(::PROTOBUF_NAMESPACE_ID::Arena* arena); - private: - static void ArenaDtor(void* object); - inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); - public: - - ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; - private: - static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { - ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_grpcservice_2eproto); - return ::descriptor_table_grpcservice_2eproto.file_level_metadata[kIndexInFileMessages]; - } - - public: - - // nested types ---------------------------------------------------- - - // accessors ------------------------------------------------------- - - enum : int { - kErrorMsgFieldNumber = 1, - }; - // string error_msg = 1; - void clear_error_msg(); - const std::string& error_msg() const; - void set_error_msg(const std::string& value); - void set_error_msg(std::string&& value); - void set_error_msg(const char* value); - void set_error_msg(const char* value, size_t size); - std::string* mutable_error_msg(); - std::string* release_error_msg(); - void set_allocated_error_msg(std::string* error_msg); - private: - const std::string& _internal_error_msg() const; - void _internal_set_error_msg(const std::string& value); - std::string* _internal_mutable_error_msg(); - public: - - // @@protoc_insertion_point(class_scope:MatrixAi.UpdateFTPReply) - private: - class _Internal; - - template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; - typedef void InternalArenaConstructable_; - typedef void DestructorSkippable_; - ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr error_msg_; - mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; - friend struct ::TableStruct_grpcservice_2eproto; -}; -// =================================================================== - - -// =================================================================== - -#ifdef __GNUC__ - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstrict-aliasing" -#endif // __GNUC__ -// Request - -// uint32 head = 1; -inline void Request::clear_head() { - head_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 Request::_internal_head() const { - return head_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 Request::head() const { - // @@protoc_insertion_point(field_get:MatrixAi.Request.head) - return _internal_head(); -} -inline void Request::_internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - head_ = value; -} -inline void Request::set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_head(value); - // @@protoc_insertion_point(field_set:MatrixAi.Request.head) -} - -// ------------------------------------------------------------------- - -// Reply - -// string error_msg = 1; -inline void Reply::clear_error_msg() { - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& Reply::error_msg() const { - // @@protoc_insertion_point(field_get:MatrixAi.Reply.error_msg) - return _internal_error_msg(); -} -inline void Reply::set_error_msg(const std::string& value) { - _internal_set_error_msg(value); - // @@protoc_insertion_point(field_set:MatrixAi.Reply.error_msg) -} -inline std::string* Reply::mutable_error_msg() { - // @@protoc_insertion_point(field_mutable:MatrixAi.Reply.error_msg) - return _internal_mutable_error_msg(); -} -inline const std::string& Reply::_internal_error_msg() const { - return error_msg_.Get(); -} -inline void Reply::_internal_set_error_msg(const std::string& value) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void Reply::set_error_msg(std::string&& value) { - - error_msg_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.Reply.error_msg) -} -inline void Reply::set_error_msg(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.Reply.error_msg) -} -inline void Reply::set_error_msg(const char* value, - size_t size) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.Reply.error_msg) -} -inline std::string* Reply::_internal_mutable_error_msg() { - - return error_msg_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* Reply::release_error_msg() { - // @@protoc_insertion_point(field_release:MatrixAi.Reply.error_msg) - return error_msg_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void Reply::set_allocated_error_msg(std::string* error_msg) { - if (error_msg != nullptr) { - - } else { - - } - error_msg_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_msg, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.Reply.error_msg) -} - -// ------------------------------------------------------------------- - -// QueryWorkstationRequest - -// uint32 head = 1; -inline void QueryWorkstationRequest::clear_head() { - head_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryWorkstationRequest::_internal_head() const { - return head_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryWorkstationRequest::head() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryWorkstationRequest.head) - return _internal_head(); -} -inline void QueryWorkstationRequest::_internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - head_ = value; -} -inline void QueryWorkstationRequest::set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_head(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryWorkstationRequest.head) -} - -// ------------------------------------------------------------------- - -// QueryWorkstationReply - -// string name = 1; -inline void QueryWorkstationReply::clear_name() { - name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryWorkstationReply::name() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryWorkstationReply.name) - return _internal_name(); -} -inline void QueryWorkstationReply::set_name(const std::string& value) { - _internal_set_name(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryWorkstationReply.name) -} -inline std::string* QueryWorkstationReply::mutable_name() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryWorkstationReply.name) - return _internal_mutable_name(); -} -inline const std::string& QueryWorkstationReply::_internal_name() const { - return name_.Get(); -} -inline void QueryWorkstationReply::_internal_set_name(const std::string& value) { - - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryWorkstationReply::set_name(std::string&& value) { - - name_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryWorkstationReply.name) -} -inline void QueryWorkstationReply::set_name(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryWorkstationReply.name) -} -inline void QueryWorkstationReply::set_name(const char* value, - size_t size) { - - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryWorkstationReply.name) -} -inline std::string* QueryWorkstationReply::_internal_mutable_name() { - - return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryWorkstationReply::release_name() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryWorkstationReply.name) - return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryWorkstationReply::set_allocated_name(std::string* name) { - if (name != nullptr) { - - } else { - - } - name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryWorkstationReply.name) -} - -// string name_no = 2; -inline void QueryWorkstationReply::clear_name_no() { - name_no_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryWorkstationReply::name_no() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryWorkstationReply.name_no) - return _internal_name_no(); -} -inline void QueryWorkstationReply::set_name_no(const std::string& value) { - _internal_set_name_no(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryWorkstationReply.name_no) -} -inline std::string* QueryWorkstationReply::mutable_name_no() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryWorkstationReply.name_no) - return _internal_mutable_name_no(); -} -inline const std::string& QueryWorkstationReply::_internal_name_no() const { - return name_no_.Get(); -} -inline void QueryWorkstationReply::_internal_set_name_no(const std::string& value) { - - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryWorkstationReply::set_name_no(std::string&& value) { - - name_no_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryWorkstationReply.name_no) -} -inline void QueryWorkstationReply::set_name_no(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryWorkstationReply.name_no) -} -inline void QueryWorkstationReply::set_name_no(const char* value, - size_t size) { - - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryWorkstationReply.name_no) -} -inline std::string* QueryWorkstationReply::_internal_mutable_name_no() { - - return name_no_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryWorkstationReply::release_name_no() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryWorkstationReply.name_no) - return name_no_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryWorkstationReply::set_allocated_name_no(std::string* name_no) { - if (name_no != nullptr) { - - } else { - - } - name_no_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_no, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryWorkstationReply.name_no) -} - -// string error_msg = 3; -inline void QueryWorkstationReply::clear_error_msg() { - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryWorkstationReply::error_msg() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryWorkstationReply.error_msg) - return _internal_error_msg(); -} -inline void QueryWorkstationReply::set_error_msg(const std::string& value) { - _internal_set_error_msg(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryWorkstationReply.error_msg) -} -inline std::string* QueryWorkstationReply::mutable_error_msg() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryWorkstationReply.error_msg) - return _internal_mutable_error_msg(); -} -inline const std::string& QueryWorkstationReply::_internal_error_msg() const { - return error_msg_.Get(); -} -inline void QueryWorkstationReply::_internal_set_error_msg(const std::string& value) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryWorkstationReply::set_error_msg(std::string&& value) { - - error_msg_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryWorkstationReply.error_msg) -} -inline void QueryWorkstationReply::set_error_msg(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryWorkstationReply.error_msg) -} -inline void QueryWorkstationReply::set_error_msg(const char* value, - size_t size) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryWorkstationReply.error_msg) -} -inline std::string* QueryWorkstationReply::_internal_mutable_error_msg() { - - return error_msg_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryWorkstationReply::release_error_msg() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryWorkstationReply.error_msg) - return error_msg_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryWorkstationReply::set_allocated_error_msg(std::string* error_msg) { - if (error_msg != nullptr) { - - } else { - - } - error_msg_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_msg, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryWorkstationReply.error_msg) -} - -// ------------------------------------------------------------------- - -// UpdateWorkstationRequest - -// uint32 head = 1; -inline void UpdateWorkstationRequest::clear_head() { - head_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateWorkstationRequest::_internal_head() const { - return head_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateWorkstationRequest::head() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateWorkstationRequest.head) - return _internal_head(); -} -inline void UpdateWorkstationRequest::_internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - head_ = value; -} -inline void UpdateWorkstationRequest::set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_head(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateWorkstationRequest.head) -} - -// string name = 2; -inline void UpdateWorkstationRequest::clear_name() { - name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateWorkstationRequest::name() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateWorkstationRequest.name) - return _internal_name(); -} -inline void UpdateWorkstationRequest::set_name(const std::string& value) { - _internal_set_name(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateWorkstationRequest.name) -} -inline std::string* UpdateWorkstationRequest::mutable_name() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateWorkstationRequest.name) - return _internal_mutable_name(); -} -inline const std::string& UpdateWorkstationRequest::_internal_name() const { - return name_.Get(); -} -inline void UpdateWorkstationRequest::_internal_set_name(const std::string& value) { - - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateWorkstationRequest::set_name(std::string&& value) { - - name_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateWorkstationRequest.name) -} -inline void UpdateWorkstationRequest::set_name(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateWorkstationRequest.name) -} -inline void UpdateWorkstationRequest::set_name(const char* value, - size_t size) { - - name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateWorkstationRequest.name) -} -inline std::string* UpdateWorkstationRequest::_internal_mutable_name() { - - return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateWorkstationRequest::release_name() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateWorkstationRequest.name) - return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateWorkstationRequest::set_allocated_name(std::string* name) { - if (name != nullptr) { - - } else { - - } - name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateWorkstationRequest.name) -} - -// string name_no = 3; -inline void UpdateWorkstationRequest::clear_name_no() { - name_no_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateWorkstationRequest::name_no() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateWorkstationRequest.name_no) - return _internal_name_no(); -} -inline void UpdateWorkstationRequest::set_name_no(const std::string& value) { - _internal_set_name_no(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateWorkstationRequest.name_no) -} -inline std::string* UpdateWorkstationRequest::mutable_name_no() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateWorkstationRequest.name_no) - return _internal_mutable_name_no(); -} -inline const std::string& UpdateWorkstationRequest::_internal_name_no() const { - return name_no_.Get(); -} -inline void UpdateWorkstationRequest::_internal_set_name_no(const std::string& value) { - - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateWorkstationRequest::set_name_no(std::string&& value) { - - name_no_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateWorkstationRequest.name_no) -} -inline void UpdateWorkstationRequest::set_name_no(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateWorkstationRequest.name_no) -} -inline void UpdateWorkstationRequest::set_name_no(const char* value, - size_t size) { - - name_no_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateWorkstationRequest.name_no) -} -inline std::string* UpdateWorkstationRequest::_internal_mutable_name_no() { - - return name_no_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateWorkstationRequest::release_name_no() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateWorkstationRequest.name_no) - return name_no_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateWorkstationRequest::set_allocated_name_no(std::string* name_no) { - if (name_no != nullptr) { - - } else { - - } - name_no_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name_no, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateWorkstationRequest.name_no) -} - -// ------------------------------------------------------------------- - -// UpdateWorkstationReply - -// string error_msg = 1; -inline void UpdateWorkstationReply::clear_error_msg() { - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateWorkstationReply::error_msg() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateWorkstationReply.error_msg) - return _internal_error_msg(); -} -inline void UpdateWorkstationReply::set_error_msg(const std::string& value) { - _internal_set_error_msg(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateWorkstationReply.error_msg) -} -inline std::string* UpdateWorkstationReply::mutable_error_msg() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateWorkstationReply.error_msg) - return _internal_mutable_error_msg(); -} -inline const std::string& UpdateWorkstationReply::_internal_error_msg() const { - return error_msg_.Get(); -} -inline void UpdateWorkstationReply::_internal_set_error_msg(const std::string& value) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateWorkstationReply::set_error_msg(std::string&& value) { - - error_msg_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateWorkstationReply.error_msg) -} -inline void UpdateWorkstationReply::set_error_msg(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateWorkstationReply.error_msg) -} -inline void UpdateWorkstationReply::set_error_msg(const char* value, - size_t size) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateWorkstationReply.error_msg) -} -inline std::string* UpdateWorkstationReply::_internal_mutable_error_msg() { - - return error_msg_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateWorkstationReply::release_error_msg() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateWorkstationReply.error_msg) - return error_msg_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateWorkstationReply::set_allocated_error_msg(std::string* error_msg) { - if (error_msg != nullptr) { - - } else { - - } - error_msg_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_msg, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateWorkstationReply.error_msg) -} - -// ------------------------------------------------------------------- - -// QueryCameraRequest - -// uint32 head = 1; -inline void QueryCameraRequest::clear_head() { - head_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraRequest::_internal_head() const { - return head_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraRequest::head() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraRequest.head) - return _internal_head(); -} -inline void QueryCameraRequest::_internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - head_ = value; -} -inline void QueryCameraRequest::set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_head(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraRequest.head) -} - -// uint32 channel_id = 2; -inline void QueryCameraRequest::clear_channel_id() { - channel_id_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraRequest::_internal_channel_id() const { - return channel_id_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraRequest::channel_id() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraRequest.channel_id) - return _internal_channel_id(); -} -inline void QueryCameraRequest::_internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - channel_id_ = value; -} -inline void QueryCameraRequest::set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_channel_id(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraRequest.channel_id) -} - -// ------------------------------------------------------------------- - -// QueryCameraReply - -// uint32 channel_id = 1; -inline void QueryCameraReply::clear_channel_id() { - channel_id_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::_internal_channel_id() const { - return channel_id_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::channel_id() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.channel_id) - return _internal_channel_id(); -} -inline void QueryCameraReply::_internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - channel_id_ = value; -} -inline void QueryCameraReply::set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_channel_id(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.channel_id) -} - -// bool use = 2; -inline void QueryCameraReply::clear_use() { - use_ = false; -} -inline bool QueryCameraReply::_internal_use() const { - return use_; -} -inline bool QueryCameraReply::use() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.use) - return _internal_use(); -} -inline void QueryCameraReply::_internal_set_use(bool value) { - - use_ = value; -} -inline void QueryCameraReply::set_use(bool value) { - _internal_set_use(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.use) -} - -// string url = 3; -inline void QueryCameraReply::clear_url() { - url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryCameraReply::url() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.url) - return _internal_url(); -} -inline void QueryCameraReply::set_url(const std::string& value) { - _internal_set_url(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.url) -} -inline std::string* QueryCameraReply::mutable_url() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryCameraReply.url) - return _internal_mutable_url(); -} -inline const std::string& QueryCameraReply::_internal_url() const { - return url_.Get(); -} -inline void QueryCameraReply::_internal_set_url(const std::string& value) { - - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryCameraReply::set_url(std::string&& value) { - - url_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryCameraReply.url) -} -inline void QueryCameraReply::set_url(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryCameraReply.url) -} -inline void QueryCameraReply::set_url(const char* value, - size_t size) { - - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryCameraReply.url) -} -inline std::string* QueryCameraReply::_internal_mutable_url() { - - return url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryCameraReply::release_url() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryCameraReply.url) - return url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryCameraReply::set_allocated_url(std::string* url) { - if (url != nullptr) { - - } else { - - } - url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), url, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryCameraReply.url) -} - -// uint32 skipinterval = 4; -inline void QueryCameraReply::clear_skipinterval() { - skipinterval_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::_internal_skipinterval() const { - return skipinterval_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::skipinterval() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.skipinterval) - return _internal_skipinterval(); -} -inline void QueryCameraReply::_internal_set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - skipinterval_ = value; -} -inline void QueryCameraReply::set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_skipinterval(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.skipinterval) -} - -// uint32 direction = 5; -inline void QueryCameraReply::clear_direction() { - direction_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::_internal_direction() const { - return direction_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::direction() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.direction) - return _internal_direction(); -} -inline void QueryCameraReply::_internal_set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - direction_ = value; -} -inline void QueryCameraReply::set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_direction(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.direction) -} - -// uint32 left_first = 6; -inline void QueryCameraReply::clear_left_first() { - left_first_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::_internal_left_first() const { - return left_first_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::left_first() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.left_first) - return _internal_left_first(); -} -inline void QueryCameraReply::_internal_set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - left_first_ = value; -} -inline void QueryCameraReply::set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_left_first(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.left_first) -} - -// uint32 right_first = 7; -inline void QueryCameraReply::clear_right_first() { - right_first_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::_internal_right_first() const { - return right_first_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryCameraReply::right_first() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.right_first) - return _internal_right_first(); -} -inline void QueryCameraReply::_internal_set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - right_first_ = value; -} -inline void QueryCameraReply::set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_right_first(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.right_first) -} - -// string error_msg = 8; -inline void QueryCameraReply::clear_error_msg() { - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryCameraReply::error_msg() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryCameraReply.error_msg) - return _internal_error_msg(); -} -inline void QueryCameraReply::set_error_msg(const std::string& value) { - _internal_set_error_msg(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryCameraReply.error_msg) -} -inline std::string* QueryCameraReply::mutable_error_msg() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryCameraReply.error_msg) - return _internal_mutable_error_msg(); -} -inline const std::string& QueryCameraReply::_internal_error_msg() const { - return error_msg_.Get(); -} -inline void QueryCameraReply::_internal_set_error_msg(const std::string& value) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryCameraReply::set_error_msg(std::string&& value) { - - error_msg_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryCameraReply.error_msg) -} -inline void QueryCameraReply::set_error_msg(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryCameraReply.error_msg) -} -inline void QueryCameraReply::set_error_msg(const char* value, - size_t size) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryCameraReply.error_msg) -} -inline std::string* QueryCameraReply::_internal_mutable_error_msg() { - - return error_msg_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryCameraReply::release_error_msg() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryCameraReply.error_msg) - return error_msg_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryCameraReply::set_allocated_error_msg(std::string* error_msg) { - if (error_msg != nullptr) { - - } else { - - } - error_msg_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_msg, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryCameraReply.error_msg) -} - -// ------------------------------------------------------------------- - -// UpdateCameraRequest - -// uint32 head = 1; -inline void UpdateCameraRequest::clear_head() { - head_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::_internal_head() const { - return head_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::head() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.head) - return _internal_head(); -} -inline void UpdateCameraRequest::_internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - head_ = value; -} -inline void UpdateCameraRequest::set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_head(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.head) -} - -// uint32 channel_id = 2; -inline void UpdateCameraRequest::clear_channel_id() { - channel_id_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::_internal_channel_id() const { - return channel_id_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::channel_id() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.channel_id) - return _internal_channel_id(); -} -inline void UpdateCameraRequest::_internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - channel_id_ = value; -} -inline void UpdateCameraRequest::set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_channel_id(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.channel_id) -} - -// bool use = 3; -inline void UpdateCameraRequest::clear_use() { - use_ = false; -} -inline bool UpdateCameraRequest::_internal_use() const { - return use_; -} -inline bool UpdateCameraRequest::use() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.use) - return _internal_use(); -} -inline void UpdateCameraRequest::_internal_set_use(bool value) { - - use_ = value; -} -inline void UpdateCameraRequest::set_use(bool value) { - _internal_set_use(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.use) -} - -// string url = 4; -inline void UpdateCameraRequest::clear_url() { - url_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateCameraRequest::url() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.url) - return _internal_url(); -} -inline void UpdateCameraRequest::set_url(const std::string& value) { - _internal_set_url(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.url) -} -inline std::string* UpdateCameraRequest::mutable_url() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateCameraRequest.url) - return _internal_mutable_url(); -} -inline const std::string& UpdateCameraRequest::_internal_url() const { - return url_.Get(); -} -inline void UpdateCameraRequest::_internal_set_url(const std::string& value) { - - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateCameraRequest::set_url(std::string&& value) { - - url_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateCameraRequest.url) -} -inline void UpdateCameraRequest::set_url(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateCameraRequest.url) -} -inline void UpdateCameraRequest::set_url(const char* value, - size_t size) { - - url_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateCameraRequest.url) -} -inline std::string* UpdateCameraRequest::_internal_mutable_url() { - - return url_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateCameraRequest::release_url() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateCameraRequest.url) - return url_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateCameraRequest::set_allocated_url(std::string* url) { - if (url != nullptr) { - - } else { - - } - url_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), url, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateCameraRequest.url) -} - -// uint32 skipinterval = 5; -inline void UpdateCameraRequest::clear_skipinterval() { - skipinterval_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::_internal_skipinterval() const { - return skipinterval_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::skipinterval() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.skipinterval) - return _internal_skipinterval(); -} -inline void UpdateCameraRequest::_internal_set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - skipinterval_ = value; -} -inline void UpdateCameraRequest::set_skipinterval(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_skipinterval(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.skipinterval) -} - -// uint32 direction = 6; -inline void UpdateCameraRequest::clear_direction() { - direction_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::_internal_direction() const { - return direction_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::direction() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.direction) - return _internal_direction(); -} -inline void UpdateCameraRequest::_internal_set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - direction_ = value; -} -inline void UpdateCameraRequest::set_direction(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_direction(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.direction) -} - -// uint32 left_first = 7; -inline void UpdateCameraRequest::clear_left_first() { - left_first_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::_internal_left_first() const { - return left_first_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::left_first() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.left_first) - return _internal_left_first(); -} -inline void UpdateCameraRequest::_internal_set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - left_first_ = value; -} -inline void UpdateCameraRequest::set_left_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_left_first(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.left_first) -} - -// uint32 right_first = 8; -inline void UpdateCameraRequest::clear_right_first() { - right_first_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::_internal_right_first() const { - return right_first_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraRequest::right_first() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraRequest.right_first) - return _internal_right_first(); -} -inline void UpdateCameraRequest::_internal_set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - right_first_ = value; -} -inline void UpdateCameraRequest::set_right_first(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_right_first(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraRequest.right_first) -} - -// ------------------------------------------------------------------- - -// UpdateCameraReply - -// uint32 channel_id = 1; -inline void UpdateCameraReply::clear_channel_id() { - channel_id_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraReply::_internal_channel_id() const { - return channel_id_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateCameraReply::channel_id() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraReply.channel_id) - return _internal_channel_id(); -} -inline void UpdateCameraReply::_internal_set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - channel_id_ = value; -} -inline void UpdateCameraReply::set_channel_id(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_channel_id(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraReply.channel_id) -} - -// string error_msg = 2; -inline void UpdateCameraReply::clear_error_msg() { - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateCameraReply::error_msg() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateCameraReply.error_msg) - return _internal_error_msg(); -} -inline void UpdateCameraReply::set_error_msg(const std::string& value) { - _internal_set_error_msg(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateCameraReply.error_msg) -} -inline std::string* UpdateCameraReply::mutable_error_msg() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateCameraReply.error_msg) - return _internal_mutable_error_msg(); -} -inline const std::string& UpdateCameraReply::_internal_error_msg() const { - return error_msg_.Get(); -} -inline void UpdateCameraReply::_internal_set_error_msg(const std::string& value) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateCameraReply::set_error_msg(std::string&& value) { - - error_msg_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateCameraReply.error_msg) -} -inline void UpdateCameraReply::set_error_msg(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateCameraReply.error_msg) -} -inline void UpdateCameraReply::set_error_msg(const char* value, - size_t size) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateCameraReply.error_msg) -} -inline std::string* UpdateCameraReply::_internal_mutable_error_msg() { - - return error_msg_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateCameraReply::release_error_msg() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateCameraReply.error_msg) - return error_msg_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateCameraReply::set_allocated_error_msg(std::string* error_msg) { - if (error_msg != nullptr) { - - } else { - - } - error_msg_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_msg, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateCameraReply.error_msg) -} - -// ------------------------------------------------------------------- - -// QueryFTPRequest - -// uint32 head = 1; -inline void QueryFTPRequest::clear_head() { - head_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPRequest::_internal_head() const { - return head_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPRequest::head() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPRequest.head) - return _internal_head(); -} -inline void QueryFTPRequest::_internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - head_ = value; -} -inline void QueryFTPRequest::set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_head(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPRequest.head) -} - -// ------------------------------------------------------------------- - -// QueryFTPReply - -// uint32 open = 1; -inline void QueryFTPReply::clear_open() { - open_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPReply::_internal_open() const { - return open_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPReply::open() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.open) - return _internal_open(); -} -inline void QueryFTPReply::_internal_set_open(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - open_ = value; -} -inline void QueryFTPReply::set_open(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_open(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.open) -} - -// string username = 2; -inline void QueryFTPReply::clear_username() { - username_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryFTPReply::username() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.username) - return _internal_username(); -} -inline void QueryFTPReply::set_username(const std::string& value) { - _internal_set_username(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.username) -} -inline std::string* QueryFTPReply::mutable_username() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryFTPReply.username) - return _internal_mutable_username(); -} -inline const std::string& QueryFTPReply::_internal_username() const { - return username_.Get(); -} -inline void QueryFTPReply::_internal_set_username(const std::string& value) { - - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryFTPReply::set_username(std::string&& value) { - - username_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryFTPReply.username) -} -inline void QueryFTPReply::set_username(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryFTPReply.username) -} -inline void QueryFTPReply::set_username(const char* value, - size_t size) { - - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryFTPReply.username) -} -inline std::string* QueryFTPReply::_internal_mutable_username() { - - return username_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryFTPReply::release_username() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryFTPReply.username) - return username_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryFTPReply::set_allocated_username(std::string* username) { - if (username != nullptr) { - - } else { - - } - username_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), username, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryFTPReply.username) -} - -// string password = 3; -inline void QueryFTPReply::clear_password() { - password_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryFTPReply::password() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.password) - return _internal_password(); -} -inline void QueryFTPReply::set_password(const std::string& value) { - _internal_set_password(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.password) -} -inline std::string* QueryFTPReply::mutable_password() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryFTPReply.password) - return _internal_mutable_password(); -} -inline const std::string& QueryFTPReply::_internal_password() const { - return password_.Get(); -} -inline void QueryFTPReply::_internal_set_password(const std::string& value) { - - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryFTPReply::set_password(std::string&& value) { - - password_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryFTPReply.password) -} -inline void QueryFTPReply::set_password(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryFTPReply.password) -} -inline void QueryFTPReply::set_password(const char* value, - size_t size) { - - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryFTPReply.password) -} -inline std::string* QueryFTPReply::_internal_mutable_password() { - - return password_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryFTPReply::release_password() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryFTPReply.password) - return password_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryFTPReply::set_allocated_password(std::string* password) { - if (password != nullptr) { - - } else { - - } - password_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), password, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryFTPReply.password) -} - -// string ip = 4; -inline void QueryFTPReply::clear_ip() { - ip_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryFTPReply::ip() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.ip) - return _internal_ip(); -} -inline void QueryFTPReply::set_ip(const std::string& value) { - _internal_set_ip(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.ip) -} -inline std::string* QueryFTPReply::mutable_ip() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryFTPReply.ip) - return _internal_mutable_ip(); -} -inline const std::string& QueryFTPReply::_internal_ip() const { - return ip_.Get(); -} -inline void QueryFTPReply::_internal_set_ip(const std::string& value) { - - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryFTPReply::set_ip(std::string&& value) { - - ip_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryFTPReply.ip) -} -inline void QueryFTPReply::set_ip(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryFTPReply.ip) -} -inline void QueryFTPReply::set_ip(const char* value, - size_t size) { - - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryFTPReply.ip) -} -inline std::string* QueryFTPReply::_internal_mutable_ip() { - - return ip_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryFTPReply::release_ip() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryFTPReply.ip) - return ip_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryFTPReply::set_allocated_ip(std::string* ip) { - if (ip != nullptr) { - - } else { - - } - ip_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ip, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryFTPReply.ip) -} - -// uint32 port = 5; -inline void QueryFTPReply::clear_port() { - port_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPReply::_internal_port() const { - return port_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPReply::port() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.port) - return _internal_port(); -} -inline void QueryFTPReply::_internal_set_port(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - port_ = value; -} -inline void QueryFTPReply::set_port(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_port(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.port) -} - -// string image_path = 6; -inline void QueryFTPReply::clear_image_path() { - image_path_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryFTPReply::image_path() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.image_path) - return _internal_image_path(); -} -inline void QueryFTPReply::set_image_path(const std::string& value) { - _internal_set_image_path(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.image_path) -} -inline std::string* QueryFTPReply::mutable_image_path() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryFTPReply.image_path) - return _internal_mutable_image_path(); -} -inline const std::string& QueryFTPReply::_internal_image_path() const { - return image_path_.Get(); -} -inline void QueryFTPReply::_internal_set_image_path(const std::string& value) { - - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryFTPReply::set_image_path(std::string&& value) { - - image_path_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryFTPReply.image_path) -} -inline void QueryFTPReply::set_image_path(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryFTPReply.image_path) -} -inline void QueryFTPReply::set_image_path(const char* value, - size_t size) { - - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryFTPReply.image_path) -} -inline std::string* QueryFTPReply::_internal_mutable_image_path() { - - return image_path_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryFTPReply::release_image_path() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryFTPReply.image_path) - return image_path_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryFTPReply::set_allocated_image_path(std::string* image_path) { - if (image_path != nullptr) { - - } else { - - } - image_path_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), image_path, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryFTPReply.image_path) -} - -// uint32 quit_time = 7; -inline void QueryFTPReply::clear_quit_time() { - quit_time_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPReply::_internal_quit_time() const { - return quit_time_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 QueryFTPReply::quit_time() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.quit_time) - return _internal_quit_time(); -} -inline void QueryFTPReply::_internal_set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - quit_time_ = value; -} -inline void QueryFTPReply::set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_quit_time(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.quit_time) -} - -// string error_msg = 8; -inline void QueryFTPReply::clear_error_msg() { - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& QueryFTPReply::error_msg() const { - // @@protoc_insertion_point(field_get:MatrixAi.QueryFTPReply.error_msg) - return _internal_error_msg(); -} -inline void QueryFTPReply::set_error_msg(const std::string& value) { - _internal_set_error_msg(value); - // @@protoc_insertion_point(field_set:MatrixAi.QueryFTPReply.error_msg) -} -inline std::string* QueryFTPReply::mutable_error_msg() { - // @@protoc_insertion_point(field_mutable:MatrixAi.QueryFTPReply.error_msg) - return _internal_mutable_error_msg(); -} -inline const std::string& QueryFTPReply::_internal_error_msg() const { - return error_msg_.Get(); -} -inline void QueryFTPReply::_internal_set_error_msg(const std::string& value) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void QueryFTPReply::set_error_msg(std::string&& value) { - - error_msg_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.QueryFTPReply.error_msg) -} -inline void QueryFTPReply::set_error_msg(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.QueryFTPReply.error_msg) -} -inline void QueryFTPReply::set_error_msg(const char* value, - size_t size) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.QueryFTPReply.error_msg) -} -inline std::string* QueryFTPReply::_internal_mutable_error_msg() { - - return error_msg_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* QueryFTPReply::release_error_msg() { - // @@protoc_insertion_point(field_release:MatrixAi.QueryFTPReply.error_msg) - return error_msg_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void QueryFTPReply::set_allocated_error_msg(std::string* error_msg) { - if (error_msg != nullptr) { - - } else { - - } - error_msg_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_msg, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.QueryFTPReply.error_msg) -} - -// ------------------------------------------------------------------- - -// UpdateFTPRequest - -// uint32 head = 1; -inline void UpdateFTPRequest::clear_head() { - head_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::_internal_head() const { - return head_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::head() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.head) - return _internal_head(); -} -inline void UpdateFTPRequest::_internal_set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - head_ = value; -} -inline void UpdateFTPRequest::set_head(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_head(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.head) -} - -// uint32 open = 2; -inline void UpdateFTPRequest::clear_open() { - open_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::_internal_open() const { - return open_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::open() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.open) - return _internal_open(); -} -inline void UpdateFTPRequest::_internal_set_open(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - open_ = value; -} -inline void UpdateFTPRequest::set_open(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_open(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.open) -} - -// string username = 3; -inline void UpdateFTPRequest::clear_username() { - username_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateFTPRequest::username() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.username) - return _internal_username(); -} -inline void UpdateFTPRequest::set_username(const std::string& value) { - _internal_set_username(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.username) -} -inline std::string* UpdateFTPRequest::mutable_username() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateFTPRequest.username) - return _internal_mutable_username(); -} -inline const std::string& UpdateFTPRequest::_internal_username() const { - return username_.Get(); -} -inline void UpdateFTPRequest::_internal_set_username(const std::string& value) { - - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateFTPRequest::set_username(std::string&& value) { - - username_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateFTPRequest.username) -} -inline void UpdateFTPRequest::set_username(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateFTPRequest.username) -} -inline void UpdateFTPRequest::set_username(const char* value, - size_t size) { - - username_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateFTPRequest.username) -} -inline std::string* UpdateFTPRequest::_internal_mutable_username() { - - return username_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateFTPRequest::release_username() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateFTPRequest.username) - return username_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateFTPRequest::set_allocated_username(std::string* username) { - if (username != nullptr) { - - } else { - - } - username_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), username, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateFTPRequest.username) -} - -// string password = 4; -inline void UpdateFTPRequest::clear_password() { - password_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateFTPRequest::password() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.password) - return _internal_password(); -} -inline void UpdateFTPRequest::set_password(const std::string& value) { - _internal_set_password(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.password) -} -inline std::string* UpdateFTPRequest::mutable_password() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateFTPRequest.password) - return _internal_mutable_password(); -} -inline const std::string& UpdateFTPRequest::_internal_password() const { - return password_.Get(); -} -inline void UpdateFTPRequest::_internal_set_password(const std::string& value) { - - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateFTPRequest::set_password(std::string&& value) { - - password_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateFTPRequest.password) -} -inline void UpdateFTPRequest::set_password(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateFTPRequest.password) -} -inline void UpdateFTPRequest::set_password(const char* value, - size_t size) { - - password_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateFTPRequest.password) -} -inline std::string* UpdateFTPRequest::_internal_mutable_password() { - - return password_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateFTPRequest::release_password() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateFTPRequest.password) - return password_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateFTPRequest::set_allocated_password(std::string* password) { - if (password != nullptr) { - - } else { - - } - password_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), password, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateFTPRequest.password) -} - -// string ip = 5; -inline void UpdateFTPRequest::clear_ip() { - ip_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateFTPRequest::ip() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.ip) - return _internal_ip(); -} -inline void UpdateFTPRequest::set_ip(const std::string& value) { - _internal_set_ip(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.ip) -} -inline std::string* UpdateFTPRequest::mutable_ip() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateFTPRequest.ip) - return _internal_mutable_ip(); -} -inline const std::string& UpdateFTPRequest::_internal_ip() const { - return ip_.Get(); -} -inline void UpdateFTPRequest::_internal_set_ip(const std::string& value) { - - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateFTPRequest::set_ip(std::string&& value) { - - ip_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateFTPRequest.ip) -} -inline void UpdateFTPRequest::set_ip(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateFTPRequest.ip) -} -inline void UpdateFTPRequest::set_ip(const char* value, - size_t size) { - - ip_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateFTPRequest.ip) -} -inline std::string* UpdateFTPRequest::_internal_mutable_ip() { - - return ip_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateFTPRequest::release_ip() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateFTPRequest.ip) - return ip_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateFTPRequest::set_allocated_ip(std::string* ip) { - if (ip != nullptr) { - - } else { - - } - ip_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ip, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateFTPRequest.ip) -} - -// uint32 port = 6; -inline void UpdateFTPRequest::clear_port() { - port_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::_internal_port() const { - return port_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::port() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.port) - return _internal_port(); -} -inline void UpdateFTPRequest::_internal_set_port(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - port_ = value; -} -inline void UpdateFTPRequest::set_port(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_port(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.port) -} - -// string image_path = 7; -inline void UpdateFTPRequest::clear_image_path() { - image_path_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateFTPRequest::image_path() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.image_path) - return _internal_image_path(); -} -inline void UpdateFTPRequest::set_image_path(const std::string& value) { - _internal_set_image_path(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.image_path) -} -inline std::string* UpdateFTPRequest::mutable_image_path() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateFTPRequest.image_path) - return _internal_mutable_image_path(); -} -inline const std::string& UpdateFTPRequest::_internal_image_path() const { - return image_path_.Get(); -} -inline void UpdateFTPRequest::_internal_set_image_path(const std::string& value) { - - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateFTPRequest::set_image_path(std::string&& value) { - - image_path_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateFTPRequest.image_path) -} -inline void UpdateFTPRequest::set_image_path(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateFTPRequest.image_path) -} -inline void UpdateFTPRequest::set_image_path(const char* value, - size_t size) { - - image_path_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateFTPRequest.image_path) -} -inline std::string* UpdateFTPRequest::_internal_mutable_image_path() { - - return image_path_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateFTPRequest::release_image_path() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateFTPRequest.image_path) - return image_path_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateFTPRequest::set_allocated_image_path(std::string* image_path) { - if (image_path != nullptr) { - - } else { - - } - image_path_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), image_path, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateFTPRequest.image_path) -} - -// uint32 quit_time = 8; -inline void UpdateFTPRequest::clear_quit_time() { - quit_time_ = 0u; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::_internal_quit_time() const { - return quit_time_; -} -inline ::PROTOBUF_NAMESPACE_ID::uint32 UpdateFTPRequest::quit_time() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPRequest.quit_time) - return _internal_quit_time(); -} -inline void UpdateFTPRequest::_internal_set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value) { - - quit_time_ = value; -} -inline void UpdateFTPRequest::set_quit_time(::PROTOBUF_NAMESPACE_ID::uint32 value) { - _internal_set_quit_time(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPRequest.quit_time) -} - -// ------------------------------------------------------------------- - -// UpdateFTPReply - -// string error_msg = 1; -inline void UpdateFTPReply::clear_error_msg() { - error_msg_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline const std::string& UpdateFTPReply::error_msg() const { - // @@protoc_insertion_point(field_get:MatrixAi.UpdateFTPReply.error_msg) - return _internal_error_msg(); -} -inline void UpdateFTPReply::set_error_msg(const std::string& value) { - _internal_set_error_msg(value); - // @@protoc_insertion_point(field_set:MatrixAi.UpdateFTPReply.error_msg) -} -inline std::string* UpdateFTPReply::mutable_error_msg() { - // @@protoc_insertion_point(field_mutable:MatrixAi.UpdateFTPReply.error_msg) - return _internal_mutable_error_msg(); -} -inline const std::string& UpdateFTPReply::_internal_error_msg() const { - return error_msg_.Get(); -} -inline void UpdateFTPReply::_internal_set_error_msg(const std::string& value) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); -} -inline void UpdateFTPReply::set_error_msg(std::string&& value) { - - error_msg_.Set( - &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); - // @@protoc_insertion_point(field_set_rvalue:MatrixAi.UpdateFTPReply.error_msg) -} -inline void UpdateFTPReply::set_error_msg(const char* value) { - GOOGLE_DCHECK(value != nullptr); - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), - GetArena()); - // @@protoc_insertion_point(field_set_char:MatrixAi.UpdateFTPReply.error_msg) -} -inline void UpdateFTPReply::set_error_msg(const char* value, - size_t size) { - - error_msg_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( - reinterpret_cast(value), size), GetArena()); - // @@protoc_insertion_point(field_set_pointer:MatrixAi.UpdateFTPReply.error_msg) -} -inline std::string* UpdateFTPReply::_internal_mutable_error_msg() { - - return error_msg_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline std::string* UpdateFTPReply::release_error_msg() { - // @@protoc_insertion_point(field_release:MatrixAi.UpdateFTPReply.error_msg) - return error_msg_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); -} -inline void UpdateFTPReply::set_allocated_error_msg(std::string* error_msg) { - if (error_msg != nullptr) { - - } else { - - } - error_msg_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), error_msg, - GetArena()); - // @@protoc_insertion_point(field_set_allocated:MatrixAi.UpdateFTPReply.error_msg) -} - -#ifdef __GNUC__ - #pragma GCC diagnostic pop -#endif // __GNUC__ -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - -// ------------------------------------------------------------------- - - -// @@protoc_insertion_point(namespace_scope) - -} // namespace MatrixAi - -// @@protoc_insertion_point(global_scope) - -#include -#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_grpcservice_2eproto diff --git a/nvidia_ascend_engine/common_engine/MergerEngine/MergerAllEngine.cpp b/nvidia_ascend_engine/common_engine/MergerEngine/MergerAllEngine.cpp index a898f66..79a9fec 100644 --- a/nvidia_ascend_engine/common_engine/MergerEngine/MergerAllEngine.cpp +++ b/nvidia_ascend_engine/common_engine/MergerEngine/MergerAllEngine.cpp @@ -149,7 +149,7 @@ void MergerAllEngine::PushData(std::shared_ptr pTrain) pTrain->bMergerFlag = true; std::shared_ptr pTrainToCsv = std::make_shared(); *pTrainToCsv = *pTrain; - + if (bUploadFlag_) { queTrain_.push(pTrain); @@ -267,7 +267,7 @@ APP_ERROR MergerAllEngine::Process() } int iHaveDataCnt = QueueHaveDataCount(); - //识别目标信息个数和获取信息个数相等,则合并信息推送web + //识别目标信息个数和获取信息个数相等,则合并信息推送web if (iHaveDataCnt == iPopPortCnt_) { std::shared_ptr pTrain = nullptr; @@ -315,7 +315,7 @@ APP_ERROR MergerAllEngine::Process() pTrain->container1 = pTrainContainer->container1; pTrain->container2 = pTrainContainer->container2; } - + //车头在前为第0节; 车头在后为最后一节+1 if(pTrain->trainNum.iTrainTypeId == 0 && iTrainIndex_ == 1) { @@ -328,7 +328,9 @@ APP_ERROR MergerAllEngine::Process() 特殊处理:针对车头在后的且当前为最后一节,且未识别到车型,则默认设置为车头。 防止车尾间隔误识别,多切分车型,且web端无法过滤的问题。 */ - if (!bHeadFrontFlag_ && pTrain->bIsEnd && pTrain->trainNum.iTrainTypeId == -1) + if (!bHeadFrontFlag_ + && pTrain->bIsEnd + && pTrain->trainNum.iTrainTypeId == -1) { LogDebug << "cometime:" << pTrain->strTrainDate << " " << pTrain->strTrainName << " iCarXH:" << pTrain->iCarXH << " num:" << pTrain->trainNum.strTrainNum; @@ -346,6 +348,8 @@ APP_ERROR MergerAllEngine::Process() } } + // if (pTrain->trainPro.strLoad.size() > 2 && pTrain->trainPro.strLoad[0] != '1') pTrain->trainPro.strLoad = ""; + PushData(pTrain); //最后一节处理后,初始化参数 diff --git a/nvidia_ascend_engine/common_engine/SaveEngine/LocalDataMoveEngine.cpp b/nvidia_ascend_engine/common_engine/SaveEngine/LocalDataMoveEngine.cpp index 441df47..d161a54 100644 --- a/nvidia_ascend_engine/common_engine/SaveEngine/LocalDataMoveEngine.cpp +++ b/nvidia_ascend_engine/common_engine/SaveEngine/LocalDataMoveEngine.cpp @@ -109,7 +109,7 @@ APP_ERROR LocalDataMoveEngine::Process() pFtpData->strFtpFilePath = strImgPath; pFtpData->strFtpFileName = strImgName; pFtpData->bIsEnd = pProcessData->bIsEnd; - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pFtpData), true); + iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pFtpData), false); } } } diff --git a/nvidia_ascend_engine/common_engine/SaveEngine/SaveCsvEngine.cpp b/nvidia_ascend_engine/common_engine/SaveEngine/SaveCsvEngine.cpp index 9e59e37..8e64d87 100644 --- a/nvidia_ascend_engine/common_engine/SaveEngine/SaveCsvEngine.cpp +++ b/nvidia_ascend_engine/common_engine/SaveEngine/SaveCsvEngine.cpp @@ -1,497 +1 @@ -#include "SaveCsvEngine.h" - -using namespace ai_matrix; - -SaveCsvEngine::SaveCsvEngine() {} - -SaveCsvEngine::~SaveCsvEngine() {} - -APP_ERROR SaveCsvEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - strPort2_ = engineName_ + "_" + std::to_string(engineId_) + "_2"; - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - strPoundNo_ = MyYaml::GetIns()->GetStringValue("atlas_poundno"); - - LogInfo << "SaveCsvEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR SaveCsvEngine::DeInit() -{ - LogInfo << "SaveCsvEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* 保存合并后车厢的最优结果到CSV中 (该文件支持其web导入) -* inParam : std::shared_ptr pTrain :列车信息 -* outParam: -* return : true/false -*/ -bool SaveCsvEngine::SaveMergerCsv(std::shared_ptr pTrain) -{ - //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/) - std::string strTrainPath = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + "/"; - if (!MyUtils::getins()->CreateDirPath(strTrainPath)) - { - LogError << "iCarXH:" << pTrain->iCarXH << " train savecsv err"; - return false; - } - - //2. 保存csv - std::string strCsvName = pTrain->strTrainDate + pTrain->strTrainName + std::string(".csv"); - strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); - std::string strCsvPath = strTrainPath + strCsvName; - - bool bIsExsit = false; - if (access(strCsvPath.c_str(), F_OK) != -1) - { - bIsExsit = true; - } - - try - { - // 写文件 - std::ofstream outFile; - outFile.open(strCsvPath, std::ios::app); // 打开模式可省略 - - if (!bIsExsit) - { - outFile << "poundno" << ',' - << "year" << ',' - << "time" << ',' - << "direction" << ',' - << "speed" << ',' - << "typeId" << ',' - << "skipInterval" << ',' - << "carxh" << ',' - << "type" << ',' - << "num" << ',' - << "load" << ',' - << "self" << ',' - << "volume" << ',' - << "volumesurface" << ',' - << "change" << ',' - << "numImgPath" << ',' - << "proImgPath" << ',' - << "videoStart" << ',' - << "videoEnd" << ',' - << "containerNo1" << ',' - << "containerNo2" << ',' - << "inspection" << ',' - << "inspectionImg" << ',' - << "containerImg_1" << ',' - << "containerImg_2" << ',' - << "startTime" << ',' - << "endTime" - << std::endl; - } - - std::string strTime = pTrain->strTrainName; - strTime = MyUtils::getins()->replace_all_distinct(strTime, std::string("-"), std::string(":")); - ai_matrix::DataSourceConfig dataSourceConfig = MyYaml::GetIns()->GetDataSourceConfigById(pTrain->trainNum.iDataSource); //获取摄像机参数 - - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pTrain->trainNum.iDataSource + 1); - - char szNumImgPath[64] = {0}; //车号最优图片路径 - if (!pTrain->trainNum.strBestImg.empty()) - { - sprintf(szNumImgPath, "%03d/%s", pTrain->trainNum.iDataSource + 1, pTrain->trainNum.strBestImg.c_str()); - } - - char szProImgPath[64] = {0}; //属性最优图片路径 - if (!pTrain->trainPro.strBestImg.empty()) - { - sprintf(szProImgPath, "%03d/%s", pTrain->trainPro.iDataSource + 1, pTrain->trainPro.strBestImg.c_str()); - } - - char szChkDateImgPath[64] = {0}; //定检期最优图片路径 - if (!pTrain->chkDate.strBestImg.empty()) - { - sprintf(szChkDateImgPath, "%03d/%s", pTrain->chkDate.iDataSource + 1, pTrain->chkDate.strBestImg.c_str()); - } - - char szContainer1ImgPath[64] = {0}; //集装箱1最优图片路径 - if (!pTrain->container1.strBestImg.empty()) - { - sprintf(szContainer1ImgPath, "%03d/%s", pTrain->container1.iDataSource + 1, pTrain->container1.strBestImg.c_str()); - } - - char szContainer2ImgPath[64] = {0}; //集装箱2最优图片路径 - if (!pTrain->container2.strBestImg.empty()) - { - sprintf(szContainer2ImgPath, "%03d/%s", pTrain->container2.iDataSource + 1, pTrain->container2.strBestImg.c_str()); - } - - outFile << strPoundNo_ << ',' - << pTrain->strTrainDate << ',' - << strTime << ',' - << pTrain->iDirection << ',' - << 0.0 << ',' - << pTrain->trainNum.iTrainTypeId << ',' - << dataSourceConfig.iSkipInterval << ',' - << pTrain->iCarXH << ',' - << pTrain->trainNum.strTrainType << ',' - << pTrain->trainNum.strTrainNum << ',' - << pTrain->trainPro.strLoad << ',' - << pTrain->trainPro.strSelf << ',' - << pTrain->trainPro.strVolume << ',' - << pTrain->trainPro.strVolumeSurface << ',' //容量记表 - << pTrain->trainPro.strChange << ',' - << szNumImgPath << ',' - << szProImgPath << ',' - << pTrain->iStartFrameId << ',' - << pTrain->iEndFrameId << ',' - << pTrain->container1.strContainerNo << ',' - << pTrain->container2.strContainerNo << ',' - << pTrain->chkDate.strChkDate1DeadLine << ',' - << szChkDateImgPath << ',' - << szContainer1ImgPath << ',' - << szContainer2ImgPath << ',' - << MyUtils::getins()->Stamp2Time(pTrain->i64StartTimeStamp, true) << ',' - << MyUtils::getins()->Stamp2Time(pTrain->i64EndTimeStamp, true) - << std::endl; - - outFile.close(); - } - catch (const std::exception &) - { - LogError << "strCsvPath:" << strCsvPath << " train savecsv fail!"; - return false; - } - return true; -} - -/** -* 保存车厢的最优结果到CSV中 -* inParam : std::shared_ptr pTrain :列车信息 -* outParam: -* return : true/false -*/ -bool SaveCsvEngine::SaveTrainCsv(std::shared_ptr pTrain) -{ - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pTrain->iDataSource + 1); - std::string strTrainPath = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + "/" + - szCameraNo + "/"; - - //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/iDataSoure/) - if (!MyUtils::getins()->CreateDirPath(strTrainPath)) - { - LogError << "iCarXH:" << pTrain->iCarXH << " train savecsv err"; - return false; - } - - //2. 保存csv - std::string strCsvName = pTrain->strTrainDate + pTrain->strTrainName + "_" + szCameraNo + "_train.csv"; - strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); - std::string strCsvPath = strTrainPath + strCsvName; - - bool bIsExsit = false; - if (access(strCsvPath.c_str(), F_OK) != -1) - { - bIsExsit = true; - } - - try - { - // 写文件 - std::ofstream outFile; - outFile.open(strCsvPath, std::ios::app); - - if (!bIsExsit) - { - outFile << "car_xh" << ',' - << "train_num_name" << ',' - << "train_pro_name" << ',' - << "t_type" << ',' - << "t_num" << ',' - << "load" << ',' - << "self" << ',' - << "volume" << ',' - << "change" << ',' - << "volumesurface" << ',' - << "num_ltx" << ',' - << "num_lty" << ',' - << "num_rbx" << ',' - << "num_rby" << ',' - << "pro_ltx" << ',' - << "pro_lty" << ',' - << "pro_rbx" << ',' - << "pro_rby" << ',' - << "start_frameId" << ',' - << "end_frameId" << ',' - << "start_timestamp" << ',' //记录车厢开始,结束帧时间戳,用于比对集装箱合并 - << "timestamp" << ',' - << "end_timestamp" << ',' - << "start_num" << ',' - << "num_timestamp" << ',' //记录车号,属性时间戳,用于比对定检期合并 - << "end_num" << ',' - << "start_pro" << ',' - << "pro_timestamp" << ',' - << "end_pro" << std::endl; - } - outFile << pTrain->iCarXH << ',' - << pTrain->trainNum.strBestImg << ',' - << pTrain->trainPro.strBestImg << ',' - << pTrain->trainNum.strTrainType << ',' - << pTrain->trainNum.strTrainNum << ',' - << pTrain->trainPro.strLoad << ',' - << pTrain->trainPro.strSelf << ',' - << pTrain->trainPro.strVolume << ',' - << pTrain->trainPro.strChange << ',' - << pTrain->trainPro.strVolumeSurface << ',' - << pTrain->trainNum.step1Location.fLTX << ',' - << pTrain->trainNum.step1Location.fLTY << ',' - << pTrain->trainNum.step1Location.fRBX << ',' - << pTrain->trainNum.step1Location.fRBY << ',' - << pTrain->trainPro.step1Location.fLTX << ',' - << pTrain->trainPro.step1Location.fLTY << ',' - << pTrain->trainPro.step1Location.fRBX << ',' - << pTrain->trainPro.step1Location.fRBY << ',' - << pTrain->iStartFrameId << ',' - << pTrain->iEndFrameId << ',' - << pTrain->i64StartTimeStamp << ',' - << pTrain->i64TimeStamp << ',' - << pTrain->i64EndTimeStamp << ',' - << pTrain->trainNum.i64StartTimeStamp << ',' - << pTrain->trainNum.i64TimeStamp << ',' - << pTrain->trainNum.i64EndTimeStamp << ',' - << pTrain->trainPro.i64StartTimeStamp << ',' - << pTrain->trainPro.i64TimeStamp << ',' - << pTrain->trainPro.i64EndTimeStamp << std::endl; - - outFile.close(); - } - catch (const std::exception &) - { - LogError << "strCsvPath:" << strCsvPath << " train savecsv fail!"; - return false; - } - return true; -} - -/** -* 保存定检期的最优结果到CSV中 -* inParam : std::shared_ptr pChkDate :定检期信息 -* outParam: -* return : true/false -*/ -bool SaveCsvEngine::SaveChkDateCsv(std::shared_ptr pChkDate) -{ - if (pChkDate->strBestImg.empty()) - { - LogDebug << "datetime:" << pChkDate->strTrainDate << " " << pChkDate->strTrainName - << " carxh:" << pChkDate->iCarXH << " chkdate empty"; - return true; - } - //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/iDataSoure/) - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pChkDate->iDataSource + 1); - std::string strChkDatePath = strResultPath_ + pChkDate->strTrainDate + "/" + pChkDate->strTrainName + "/" + - szCameraNo + "/"; - - if (!MyUtils::getins()->CreateDirPath(strChkDatePath)) - { - LogError << "iCarXH:" << pChkDate->iCarXH << "chkdate savecsv err"; - return false; - } - - //2. 保存csv - std::string strCsvName = pChkDate->strTrainDate + pChkDate->strTrainName + "_" + szCameraNo + "_chkdate.csv"; - strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); - std::string strCsvPath = strChkDatePath + strCsvName; - - bool bIsExsit = false; - if (access(strCsvPath.c_str(), F_OK) != -1) - { - bIsExsit = true; - } - - try - { - // 写文件 - std::ofstream outFile; - outFile.open(strCsvPath, std::ios::app); // 打开模式可省略 - - if (!bIsExsit) - { - outFile << "car_xh" << ',' - << "chkdate_name" << ',' - << "chkdate1" << ',' - << "chkdate2" << ',' - << "chkdate_ltx" << ',' - << "chkdate_lty" << ',' - << "chkdate_rbx" << ',' - << "chkdate_rby" << ',' - << "start_frameId" << ',' - << "end_frameId" << ',' - << "start_timestamp" << ',' - << "end_timestamp" << ',' - << "timestamp" << ',' - << "chkdate1deadline" << std::endl; - } - outFile << pChkDate->iCarXH << ',' - << pChkDate->strBestImg << ',' - << pChkDate->strChkDate1 << ',' - << pChkDate->strChkDate2 << ',' - << pChkDate->step1Location.fLTX << ',' - << pChkDate->step1Location.fLTY << ',' - << pChkDate->step1Location.fRBX << ',' - << pChkDate->step1Location.fRBY << ',' - << pChkDate->iStartFrameId << ',' - << pChkDate->iEndFrameId << ',' - << pChkDate->i64StartTimeStamp << ',' - << pChkDate->i64EndTimeStamp << ',' - << pChkDate->i64TimeStamp << ',' - << pChkDate->strChkDate1DeadLine << std::endl; - - outFile.close(); - } - catch (const std::exception &) - { - LogError << "strCsvPath:" << strCsvPath << " chkdate savecsv fail!"; - return false; - } - return true; -} - -/** -* 保存集装箱的最优结果到CSV中 -* inParam : std::shared_ptr pTrainContainer :集装箱信息 -* outParam: -* return : true/false -*/ -bool SaveCsvEngine::SaveContainerCsv(std::shared_ptr pTrainContainer) -{ - std::vector vecContainer; - vecContainer.emplace_back(pTrainContainer->container1); - vecContainer.emplace_back(pTrainContainer->container2); - for (auto iter = vecContainer.begin(); iter != vecContainer.end(); iter++) - { - if (iter->strContainerNo.empty()) - { - continue; - } - // 1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/iDataSoure/) - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", iter->iDataSource + 1); - std::string strContainerPath = strResultPath_ + iter->strTrainDate + "/" + iter->strTrainName + "/" + - szCameraNo + "/"; - - if (!MyUtils::getins()->CreateDirPath(strContainerPath)) - { - LogError << "ContainerNo:" << iter->strContainerNo << " container savecsv err"; - continue; - } - // 2. 保存csv - std::string strCsvName = iter->strTrainDate + iter->strTrainName + "_" + szCameraNo + "_container.csv"; - strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); - std::string strCsvPath = strContainerPath + strCsvName; - - bool bIsExsit = false; - if (access(strCsvPath.c_str(), F_OK) != -1) - { - bIsExsit = true; - } - - try - { - // 写文件 - std::ofstream outFile; - outFile.open(strCsvPath, std::ios::app); - - if (!bIsExsit) - { - outFile << "datasource" << ',' - << "container_name" << ',' - << "containerNo" << ',' - << "container_ltx" << ',' - << "container_lty" << ',' - << "container_rbx" << ',' - << "container_rby" << ',' - << "start_frameId" << ',' - << "end_frameId" << ',' - << "timestamp" << std::endl; - } - outFile << iter->iDataSource << ',' - << iter->strBestImg << ',' - << iter->strContainerNo << ',' - << iter->step1Location.fLTX << ',' - << iter->step1Location.fLTY << ',' - << iter->step1Location.fRBX << ',' - << iter->step1Location.fRBY << ',' - << iter->iStartFrameId << ',' - << iter->iEndFrameId << ',' - << iter->i64TimeStamp << std::endl; - - outFile.close(); - } - catch (const std::exception &) - { - LogError << "strCsvPath:" << strCsvPath << " container savecsv fail!"; - continue; - } - } - return true; -} - -APP_ERROR SaveCsvEngine::Process() -{ - int iRet = APP_ERR_OK; - while (!isStop_) - { - - bool bPopFlag = false; - //pop端口0 车厢信息 - std::shared_ptr pVoidData0 = nullptr; - iRet = inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr != pVoidData0) - { - std::shared_ptr pTrain = std::static_pointer_cast(pVoidData0); - if (pTrain->bMergerFlag) - { - SaveMergerCsv(pTrain); - } - else - { - SaveTrainCsv(pTrain); - } - bPopFlag = true; - } - //pop端口1 定检期信息 - if (inputQueMap_.count(strPort1_) > 0) - { - std::shared_ptr pVoidData1 = nullptr; - inputQueMap_[strPort1_]->pop(pVoidData1); - if (nullptr != pVoidData1) - { - std::shared_ptr pChkDate = std::static_pointer_cast(pVoidData1); - SaveChkDateCsv(pChkDate); - bPopFlag = true; - } - } - //pop端口2 集装箱信息 - if (inputQueMap_.count(strPort2_) > 0) - { - std::shared_ptr pVoidData2 = nullptr; - inputQueMap_[strPort2_]->pop(pVoidData2); - if (nullptr != pVoidData2) - { - std::shared_ptr pTrainContainer = std::static_pointer_cast(pVoidData2); - SaveContainerCsv(pTrainContainer); - bPopFlag = true; - } - } - - if (!bPopFlag) - { - usleep(1000); - continue; - } - } - return APP_ERR_OK; -} +#include "SaveCsvEngine.h" using namespace ai_matrix; SaveCsvEngine::SaveCsvEngine() {} SaveCsvEngine::~SaveCsvEngine() {} APP_ERROR SaveCsvEngine::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; strPort2_ = engineName_ + "_" + std::to_string(engineId_) + "_2"; strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); strPoundNo_ = MyYaml::GetIns()->GetStringValue("atlas_poundno"); LogInfo << "SaveCsvEngine Init ok"; return APP_ERR_OK; } APP_ERROR SaveCsvEngine::DeInit() { LogInfo << "SaveCsvEngine DeInit ok"; return APP_ERR_OK; } /** * 保存合并后车厢的最优结果到CSV中 (该文件支持其web导入) * inParam : std::shared_ptr pTrain :列车信息 * outParam: * return : true/false */ bool SaveCsvEngine::SaveMergerCsv(std::shared_ptr pTrain) { //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/) std::string strTrainPath = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + "/"; if (!MyUtils::getins()->CreateDirPath(strTrainPath)) { LogError << "iCarXH:" << pTrain->iCarXH << " train savecsv err"; return false; } //2. 保存csv std::string strCsvName = pTrain->strTrainDate + pTrain->strTrainName + std::string(".csv"); strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); std::string strCsvPath = strTrainPath + strCsvName; bool bIsExsit = false; if (access(strCsvPath.c_str(), F_OK) != -1) { bIsExsit = true; } try { // 写文件 std::ofstream outFile; outFile.open(strCsvPath, std::ios::app); // 打开模式可省略 if (!bIsExsit) { outFile << "poundno" << ',' << "year" << ',' << "time" << ',' << "direction" << ',' << "speed" << ',' << "typeId" << ',' << "skipInterval" << ',' << "carxh" << ',' << "type" << ',' << "num" << ',' << "load" << ',' << "self" << ',' << "volume" << ',' << "volumesurface" << ',' << "change" << ',' << "numImgPath" << ',' << "proImgPath" << ',' << "videoStart" << ',' << "videoEnd" << ',' << "containerNo1" << ',' << "containerNo2" << ',' << "inspection" << ',' << "inspectionImg" << ',' << "containerImg_1" << ',' << "containerImg_2" << ',' << "startTime" << ',' << "endTime" << std::endl; } std::string strTime = pTrain->strTrainName; strTime = MyUtils::getins()->replace_all_distinct(strTime, std::string("-"), std::string(":")); ai_matrix::DataSourceConfig dataSourceConfig = MyYaml::GetIns()->GetDataSourceConfigById(pTrain->trainNum.iDataSource); //获取摄像机参数 char szCameraNo[4] = {0}; sprintf(szCameraNo, "%03d", pTrain->trainNum.iDataSource + 1); char szNumImgPath[64] = {0}; //车号最优图片路径 if (!pTrain->trainNum.strBestImg.empty()) { sprintf(szNumImgPath, "%03d/%s", pTrain->trainNum.iDataSource + 1, pTrain->trainNum.strBestImg.c_str()); } char szProImgPath[64] = {0}; //属性最优图片路径 if (!pTrain->trainPro.strBestImg.empty()) { sprintf(szProImgPath, "%03d/%s", pTrain->trainPro.iDataSource + 1, pTrain->trainPro.strBestImg.c_str()); } char szChkDateImgPath[64] = {0}; //定检期最优图片路径 if (!pTrain->chkDate.strBestImg.empty()) { sprintf(szChkDateImgPath, "%03d/%s", pTrain->chkDate.iDataSource + 1, pTrain->chkDate.strBestImg.c_str()); } char szContainer1ImgPath[64] = {0}; //集装箱1最优图片路径 if (!pTrain->container1.strBestImg.empty()) { sprintf(szContainer1ImgPath, "%03d/%s", pTrain->container1.iDataSource + 1, pTrain->container1.strBestImg.c_str()); } char szContainer2ImgPath[64] = {0}; //集装箱2最优图片路径 if (!pTrain->container2.strBestImg.empty()) { sprintf(szContainer2ImgPath, "%03d/%s", pTrain->container2.iDataSource + 1, pTrain->container2.strBestImg.c_str()); } outFile << strPoundNo_ << ',' << pTrain->strTrainDate << ',' << strTime << ',' << pTrain->iDirection << ',' << 0.0 << ',' << pTrain->trainNum.iTrainTypeId << ',' << dataSourceConfig.iSkipInterval << ',' << pTrain->iCarXH << ',' << pTrain->trainNum.strTrainType << ',' << pTrain->trainNum.strTrainNum << ',' << pTrain->trainPro.strLoad << ',' << pTrain->trainPro.strSelf << ',' << pTrain->trainPro.strVolume << ',' << pTrain->trainPro.strVolumeSurface << ',' //容量记表 << pTrain->trainPro.strChange << ',' << szNumImgPath << ',' << szProImgPath << ',' << pTrain->iStartFrameId << ',' << pTrain->iEndFrameId << ',' << pTrain->container1.strContainerNo << ',' << pTrain->container2.strContainerNo << ',' << pTrain->chkDate.strChkDate1DeadLine << ',' << szChkDateImgPath << ',' << szContainer1ImgPath << ',' << szContainer2ImgPath << ',' << MyUtils::getins()->Stamp2Time(pTrain->i64StartTimeStamp, true) << ',' << MyUtils::getins()->Stamp2Time(pTrain->i64EndTimeStamp, true) << std::endl; outFile.close(); } catch (const std::exception &) { LogError << "strCsvPath:" << strCsvPath << " train savecsv fail!"; return false; } return true; } /** * 保存车厢的最优结果到CSV中 * inParam : std::shared_ptr pTrain :列车信息 * outParam: * return : true/false */ bool SaveCsvEngine::SaveTrainCsv(std::shared_ptr pTrain) { char szCameraNo[4] = {0}; sprintf(szCameraNo, "%03d", pTrain->iDataSource + 1); std::string strTrainPath = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + "/" + szCameraNo + "/"; //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/iDataSoure/) if (!MyUtils::getins()->CreateDirPath(strTrainPath)) { LogError << "iCarXH:" << pTrain->iCarXH << " train savecsv err"; return false; } //2. 保存csv std::string strCsvName = pTrain->strTrainDate + pTrain->strTrainName + "_" + szCameraNo + "_train.csv"; strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); std::string strCsvPath = strTrainPath + strCsvName; bool bIsExsit = false; if (access(strCsvPath.c_str(), F_OK) != -1) { bIsExsit = true; } try { // 写文件 std::ofstream outFile; outFile.open(strCsvPath, std::ios::app); if (!bIsExsit) { outFile << "car_xh" << ',' << "train_num_name" << ',' << "train_pro_name" << ',' << "t_type" << ',' << "t_num" << ',' << "load" << ',' << "self" << ',' << "volume" << ',' << "change" << ',' << "volumesurface" << ',' << "num_ltx" << ',' << "num_lty" << ',' << "num_rbx" << ',' << "num_rby" << ',' << "pro_ltx" << ',' << "pro_lty" << ',' << "pro_rbx" << ',' << "pro_rby" << ',' << "start_frameId" << ',' << "end_frameId" << ',' << "start_timestamp" << ',' //记录车厢开始,结束帧时间戳,用于比对集装箱合并 << "timestamp" << ',' << "end_timestamp" << ',' << "start_num" << ',' << "num_timestamp" << ',' //记录车号,属性时间戳,用于比对定检期合并 << "end_num" << ',' << "start_pro" << ',' << "pro_timestamp" << ',' << "end_pro" << std::endl; } outFile << pTrain->iCarXH << ',' << pTrain->trainNum.strBestImg << ',' << pTrain->trainPro.strBestImg << ',' << pTrain->trainNum.strTrainType << ',' << pTrain->trainNum.strTrainNum << ',' << pTrain->trainPro.strLoad << ',' << pTrain->trainPro.strSelf << ',' << pTrain->trainPro.strVolume << ',' << pTrain->trainPro.strChange << ',' << pTrain->trainPro.strVolumeSurface << ',' << pTrain->trainNum.step1Location.fLTX << ',' << pTrain->trainNum.step1Location.fLTY << ',' << pTrain->trainNum.step1Location.fRBX << ',' << pTrain->trainNum.step1Location.fRBY << ',' << pTrain->trainPro.step1Location.fLTX << ',' << pTrain->trainPro.step1Location.fLTY << ',' << pTrain->trainPro.step1Location.fRBX << ',' << pTrain->trainPro.step1Location.fRBY << ',' << pTrain->iStartFrameId << ',' << pTrain->iEndFrameId << ',' << pTrain->i64StartTimeStamp << ',' << pTrain->i64TimeStamp << ',' << pTrain->i64EndTimeStamp << ',' << pTrain->trainNum.i64StartTimeStamp << ',' << pTrain->trainNum.i64TimeStamp << ',' << pTrain->trainNum.i64EndTimeStamp << ',' << pTrain->trainPro.i64StartTimeStamp << ',' << pTrain->trainPro.i64TimeStamp << ',' << pTrain->trainPro.i64EndTimeStamp << std::endl; outFile.close(); } catch (const std::exception &) { LogError << "strCsvPath:" << strCsvPath << " train savecsv fail!"; return false; } return true; } /** * 保存定检期的最优结果到CSV中 * inParam : std::shared_ptr pChkDate :定检期信息 * outParam: * return : true/false */ bool SaveCsvEngine::SaveChkDateCsv(std::shared_ptr pChkDate) { if (pChkDate->strBestImg.empty()) { LogDebug << "datetime:" << pChkDate->strTrainDate << " " << pChkDate->strTrainName << " carxh:" << pChkDate->iCarXH << " chkdate empty"; return true; } //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/iDataSoure/) char szCameraNo[4] = {0}; sprintf(szCameraNo, "%03d", pChkDate->iDataSource + 1); std::string strChkDatePath = strResultPath_ + pChkDate->strTrainDate + "/" + pChkDate->strTrainName + "/" + szCameraNo + "/"; if (!MyUtils::getins()->CreateDirPath(strChkDatePath)) { LogError << "iCarXH:" << pChkDate->iCarXH << "chkdate savecsv err"; return false; } //2. 保存csv std::string strCsvName = pChkDate->strTrainDate + pChkDate->strTrainName + "_" + szCameraNo + "_chkdate.csv"; strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); std::string strCsvPath = strChkDatePath + strCsvName; bool bIsExsit = false; if (access(strCsvPath.c_str(), F_OK) != -1) { bIsExsit = true; } try { // 写文件 std::ofstream outFile; outFile.open(strCsvPath, std::ios::app); // 打开模式可省略 if (!bIsExsit) { outFile << "car_xh" << ',' << "chkdate_name" << ',' << "chkdate1" << ',' << "chkdate2" << ',' << "chkdate_ltx" << ',' << "chkdate_lty" << ',' << "chkdate_rbx" << ',' << "chkdate_rby" << ',' << "start_frameId" << ',' << "end_frameId" << ',' << "start_timestamp" << ',' << "end_timestamp" << ',' << "timestamp" << ',' << "chkdate1deadline" << std::endl; } outFile << pChkDate->iCarXH << ',' << pChkDate->strBestImg << ',' << pChkDate->strChkDate1 << ',' << pChkDate->strChkDate2 << ',' << pChkDate->step1Location.fLTX << ',' << pChkDate->step1Location.fLTY << ',' << pChkDate->step1Location.fRBX << ',' << pChkDate->step1Location.fRBY << ',' << pChkDate->iStartFrameId << ',' << pChkDate->iEndFrameId << ',' << pChkDate->i64StartTimeStamp << ',' << pChkDate->i64EndTimeStamp << ',' << pChkDate->i64TimeStamp << ',' << pChkDate->strChkDate1DeadLine << std::endl; outFile.close(); } catch (const std::exception &) { LogError << "strCsvPath:" << strCsvPath << " chkdate savecsv fail!"; return false; } return true; } /** * 保存集装箱的最优结果到CSV中 * inParam : std::shared_ptr pTrainContainer :集装箱信息 * outParam: * return : true/false */ bool SaveCsvEngine::SaveContainerCsv(std::shared_ptr pTrainContainer) { std::vector vecContainer; vecContainer.emplace_back(pTrainContainer->container1); vecContainer.emplace_back(pTrainContainer->container2); for (auto iter = vecContainer.begin(); iter != vecContainer.end(); iter++) { if (iter->strContainerNo.empty()) { continue; } // 1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/iDataSoure/) char szCameraNo[4] = {0}; sprintf(szCameraNo, "%03d", iter->iDataSource + 1); std::string strContainerPath = strResultPath_ + iter->strTrainDate + "/" + iter->strTrainName + "/" + szCameraNo + "/"; if (!MyUtils::getins()->CreateDirPath(strContainerPath)) { LogError << "ContainerNo:" << iter->strContainerNo << " container savecsv err"; continue; } // 2. 保存csv std::string strCsvName = iter->strTrainDate + iter->strTrainName + "_" + szCameraNo + "_container.csv"; strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); std::string strCsvPath = strContainerPath + strCsvName; bool bIsExsit = false; if (access(strCsvPath.c_str(), F_OK) != -1) { bIsExsit = true; } try { // 写文件 std::ofstream outFile; outFile.open(strCsvPath, std::ios::app); if (!bIsExsit) { outFile << "datasource" << ',' << "container_name" << ',' << "containerNo" << ',' << "container_ltx" << ',' << "container_lty" << ',' << "container_rbx" << ',' << "container_rby" << ',' << "start_frameId" << ',' << "end_frameId" << ',' << "timestamp" << std::endl; } outFile << iter->iDataSource << ',' << iter->strBestImg << ',' << iter->strContainerNo << ',' << iter->step1Location.fLTX << ',' << iter->step1Location.fLTY << ',' << iter->step1Location.fRBX << ',' << iter->step1Location.fRBY << ',' << iter->iStartFrameId << ',' << iter->iEndFrameId << ',' << iter->i64TimeStamp << std::endl; outFile.close(); } catch (const std::exception &) { LogError << "strCsvPath:" << strCsvPath << " container savecsv fail!"; continue; } } return true; } APP_ERROR SaveCsvEngine::Process() { int iRet = APP_ERR_OK; while (!isStop_) { bool bPopFlag = false; //pop端口0 车厢信息 std::shared_ptr pVoidData0 = nullptr; iRet = inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr != pVoidData0) { std::shared_ptr pTrain = std::static_pointer_cast(pVoidData0); if (pTrain->bMergerFlag) { SaveMergerCsv(pTrain); } else { SaveTrainCsv(pTrain); } bPopFlag = true; } //pop端口1 定检期信息 if (inputQueMap_.count(strPort1_) > 0) { std::shared_ptr pVoidData1 = nullptr; inputQueMap_[strPort1_]->pop(pVoidData1); if (nullptr != pVoidData1) { std::shared_ptr pChkDate = std::static_pointer_cast(pVoidData1); SaveChkDateCsv(pChkDate); bPopFlag = true; } } //pop端口2 集装箱信息 if (inputQueMap_.count(strPort2_) > 0) { std::shared_ptr pVoidData2 = nullptr; inputQueMap_[strPort2_]->pop(pVoidData2); if (nullptr != pVoidData2) { std::shared_ptr pTrainContainer = std::static_pointer_cast(pVoidData2); SaveContainerCsv(pTrainContainer); bPopFlag = true; } } if (!bPopFlag) { usleep(1000); continue; } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/SaveEngine/SaveImgEngine.cpp b/nvidia_ascend_engine/common_engine/SaveEngine/SaveImgEngine.cpp index 3569b64..887f1d2 100644 --- a/nvidia_ascend_engine/common_engine/SaveEngine/SaveImgEngine.cpp +++ b/nvidia_ascend_engine/common_engine/SaveEngine/SaveImgEngine.cpp @@ -45,10 +45,10 @@ APP_ERROR SaveImgEngine::Process() LogWarn << "engineId_:" << engineId_ << " not use engine"; return APP_ERR_OK; } - + vector compression_params; - compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg - compression_params.push_back(iPicQuality); //图片质量 + compression_params.push_back(cv::IMWRITE_JPEG_QUALITY); //选择jpeg + compression_params.push_back(iPicQuality); //图片质量 iDirection_ = DIRECTION_UNKNOWN; int iRet = APP_ERR_OK; @@ -61,7 +61,7 @@ APP_ERROR SaveImgEngine::Process() usleep(1000); continue; } - + std::shared_ptr pSaveImgData = std::static_pointer_cast(pvoidd); //如果设置了方向,则方向不对直接过滤,但结束帧不能过滤,需流转到后面Engine,保证后面处理正确。 @@ -113,13 +113,13 @@ APP_ERROR SaveImgEngine::Process() } // 3.保存图片 - + if (pSaveImgData->pData != nullptr && pSaveImgData->iSize != 0) { cv::Mat matBGR(pSaveImgData->iHeight, pSaveImgData->iWidth, CV_8UC3, static_cast(pSaveImgData->pData.get())); //RGB iWidth = pSaveImgData->iWidth; iHeight = pSaveImgData->iHeight; - + // cv::Mat mtOutImage; // cv::cvtColor(cvimg, mtOutImage, cv::COLOR_RGB2BGR); diff --git a/nvidia_ascend_engine/common_engine/SaveEngine/SaveStepOneResultEngine.cpp b/nvidia_ascend_engine/common_engine/SaveEngine/SaveStepOneResultEngine.cpp index c762b25..c7dcff9 100644 --- a/nvidia_ascend_engine/common_engine/SaveEngine/SaveStepOneResultEngine.cpp +++ b/nvidia_ascend_engine/common_engine/SaveEngine/SaveStepOneResultEngine.cpp @@ -1,705 +1 @@ -#include "SaveStepOneResultEngine.h" - - -using namespace ai_matrix; - -SaveStepOneResultEngine::SaveStepOneResultEngine() {} - -SaveStepOneResultEngine::~SaveStepOneResultEngine() {} - -APP_ERROR SaveStepOneResultEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - iSplitSpan_ = MyYaml::GetIns()->GetIntValue("partition_frame_span"); - iSplitSpanPX_ = MyYaml::GetIns()->GetIntValue("gc_split_frame_span_px"); - - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); - - std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); - std::string delimiter(","); - for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) - { - int iCnt = 0; - std::vector vecSplit = MyUtils::getins()->split(iter->second.strTarget, delimiter); - for (auto iter = vecSplit.begin(); iter != vecSplit.end(); iter++) - { - if (*iter == "NUM") - { - iCnt++; - } - else if (*iter == "CHKDATE") - { - iCnt++; - } - else if (*iter == "CONTAINER" || *iter == "CONTAINER_T") - { - iCnt++; - } - } - mapInvokeModelCnt_[iter->first] = iCnt; - } - - InitParam(); - LogInfo << "SaveStepOneResultEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR SaveStepOneResultEngine::DeInit() -{ - LogInfo << "SaveStepOneResultEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* 初始化参数信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SaveStepOneResultEngine::InitParam() -{ - iPushSpaceFrameId_ = 0; - i64TimeStampFirst_ = 0; - iDirection_ = DIRECTION_UNKNOWN; - bPushIsEnd_ = false; - vecParationInfo_.clear(); - std::vector().swap(vecParationInfo_); - bDealCenterFlag_ = false; - parationInfoLast_.i64EndTimeStamp = 0; - parationInfoLast_.modelSpaceFrame = 0; - parationInfoLast_.iRate = 0; - parationInfoLast_.bmodelconfirmed = false; - parationInfoLast_.fLTX = 0.0; - parationInfoLast_.fRBX = 0.0; - parationInfoLast_.strTrainDate = ""; - parationInfoLast_.strTrainName = ""; - parationInfoLast_.bIsEnd = false; - parationInfoLast_.nStatus = 0; - mapNumCenterInfo_.clear(); - mapProCenterInfo_.clear(); - bHaveHeadFlag_ = false; - headInfo_.iFrameId = 0; - headInfo_.fCenterX = 0; -} - -/** -* 构造车厢间隔信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SaveStepOneResultEngine::MakeParationInfo(PartionInfo ¶tionInfo, std::shared_ptr pProcessData, Json::Value &jvStep1Space) -{ - parationInfo.i64EndTimeStamp = pProcessData->i64TimeStamp; - parationInfo.modelSpaceFrame = pProcessData->iFrameId; - parationInfo.iRate = pProcessData->iRate; - parationInfo.bmodelconfirmed = true; - parationInfo.fLTX = jvStep1Space[0]["ltx"].asFloat(); - parationInfo.fRBX = jvStep1Space[0]["rbx"].asFloat(); - parationInfo.strTrainDate = pProcessData->strTrainDate; - parationInfo.strTrainName = pProcessData->strTrainName; - parationInfo.bIsEnd = pProcessData->bIsEnd; - parationInfo.nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); - parationInfoLast_ = parationInfo; -} - -/** -* 处理中心间隔信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SaveStepOneResultEngine::DealCenterSpace(std::vector &vecParationInfo, - std::shared_ptr pProcessData) -{ - int iVecSize = vecParationInfo.size(); - if (iVecSize < 0) - { - return; - } - LogDebug << "积累的车厢切分信息数:" << iVecSize << " 帧:" << pProcessData->iFrameId - << " 第一个车厢切分信息帧:" << vecParationInfo.at(0).modelSpaceFrame - << " 最后一个车厢切分信息帧:" << vecParationInfo.at(iVecSize - 1).modelSpaceFrame - << " 最后一个车厢切分信息是否为结束:" << vecParationInfo.at(iVecSize - 1).bIsEnd; - - /* - 因停车后再行驶未能及时判断出为行驶状态,导致更新间隔信息,出现漏切分车厢(具体原因分析见正通2023-02-28的问题分析记录) - 漏切分时vecParationInfo中保存的是两辆车的间隔信息,因此针对vecParationInfo做特殊处理,从此处切分出遗漏的车厢。 - */ - std::vector vecSpacePos; - for (int i = 1; i < iVecSize; i++) - { - int iCenterXPre = vecParationInfo[i - 1].fLTX + (vecParationInfo[i - 1].fRBX - vecParationInfo[i - 1].fLTX) / 2; - int iCenterX = vecParationInfo[i].fLTX + (vecParationInfo[i].fRBX - vecParationInfo[i].fLTX) / 2; - bool bIntervalFlag = ((int)(vecParationInfo[i].modelSpaceFrame - vecParationInfo[i - 1].modelSpaceFrame)) > iSplitSpan_; - LogDebug << "上一帧ID:" << vecParationInfo[i - 1].modelSpaceFrame << " 上一帧间隔X轴中线:" << iCenterXPre - << " 本帧ID:" << vecParationInfo[i].modelSpaceFrame << " 本帧间隔X轴中线:" << iCenterX - << " 满足帧间隔:" << bIntervalFlag << " i:" << i; - if (iDirection_ == DIRECTION_LEFT && (iCenterXPre < iCenterX - iSplitSpanPX_) && bIntervalFlag) - { - vecSpacePos.push_back(i - 1); - } - if (iDirection_ == DIRECTION_RIGHT && (iCenterXPre - iSplitSpanPX_ > iCenterX) && bIntervalFlag) - { - vecSpacePos.push_back(i - 1); - } - } - LogDebug << "vecSpacePos size:" << vecSpacePos.size(); - vecSpacePos.push_back(iVecSize - 1); - - /* - 如果集合中最后为列车结束帧,则表示停车在车厢间隔。这时用最后一个作为车厢划分帧。 - 其他场景使用靠近中心的间隔帧作为车厢划分帧 - */ - for (int iSpacePos = 0; iSpacePos < vecSpacePos.size(); iSpacePos++) - { - LogDebug << "index:" << vecSpacePos.at(iSpacePos) << " frameid:" << vecParationInfo[vecSpacePos.at(iSpacePos)].modelSpaceFrame; - std::shared_ptr pPartionInfo = std::make_shared(); - if (iSpacePos == vecSpacePos.size() - 1 && vecParationInfo[vecSpacePos.at(iSpacePos)].bIsEnd) - { - *pPartionInfo = vecParationInfo[vecSpacePos.at(iSpacePos)]; - } - else - { - int iPos = 0; - int iImageCenter = pProcessData->iWidth / 2; - int iToCenterXMin = iImageCenter; - int iBegin = (iSpacePos == 0 ? 0 : vecSpacePos.at(iSpacePos - 1) + 1); - for (int i = iBegin; i <= vecSpacePos.at(iSpacePos); i++) - { - int iCenterX = vecParationInfo[i].fLTX + (vecParationInfo[i].fRBX - vecParationInfo[i].fLTX) / 2; - if (iToCenterXMin > abs(iCenterX - iImageCenter)) - { - iToCenterXMin = abs(iCenterX - iImageCenter); - iPos = i; - } - } - *pPartionInfo = vecParationInfo[iPos]; - } - - //此处切分时,依据车号,属性判断是否有漏的车厢,如果有则依靠车号属性切分。 - SplitTrainByNumPro(pPartionInfo, pProcessData); - - pPartionInfo->fLTX = pPartionInfo->fLTX / (pProcessData->iWidth / METHOD_BASE_WIDTH); - pPartionInfo->fRBX = pPartionInfo->fRBX / (pProcessData->iWidth / METHOD_BASE_WIDTH); - if (iPushSpaceFrameId_ == 0) - { - pPartionInfo->i64StartTimeStamp = i64TimeStampFirst_; - pPartionInfo->startframe = dataSourceConfig_.iSkipInterval; - } - pPartionInfo->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); - - LogWarn << "--------- 向Paration 发送数据 --------"; - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pPartionInfo), true); - - iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame; - bPushIsEnd_ = pPartionInfo->bIsEnd; - LogDebug << "pushSpaceFrameId:" << iPushSpaceFrameId_ << " timeStamp:" << pPartionInfo->i64EndTimeStamp - << " ltx:" << pPartionInfo->fLTX << " rbx:" << pPartionInfo->fRBX - << " bPushIsEnd:" << bPushIsEnd_; - } - vecParationInfo.clear(); -} - -/** -* 处理车厢间隔 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SaveStepOneResultEngine::DealTrainSpaceInfo(std::shared_ptr pProcessData, Json::Value &jvStep1Space) -{ - /* - 无方向时,识别的内容都放入集合中。 - 有向时,按方向判断是否push车厢间隔框 - 向左行驶:帧间隔中心点小于画面1/3时,则处理车厢间隔集合。新车厢间隔必须大于上次车厢中心点再放入集合等待处理。 - 向右行驶:帧间隔中心点大于画面2/3时,则处理车厢间隔集合。新车厢间隔必须小于上次车厢中心点再放入集合等待处理。 - 注:最后一节不会再有帧间隔了,因此直接发送的结束帧,且坐标设置中心点。 - */ - if (jvStep1Space.size() <= 0 || pProcessData->iOrigFrameId < 50) - { - return; - } - - /* - 停车状态后不再放入信息到集合中,防止长时间停在间隔上导致集合持续增大。 - 停车状态且有间隔时需更新最后间隔框帧号。(防止在XXX帧停车且有间隔框,然后开始倒车再正向行驶,当再回到开始倒车的位置时,此时帧号为YYYY, - 会符合下面的partition_frame_span判断,导致bIntervalFlag为true而切分车厢) - */ - if (pProcessData->iStatus == TRAINSTATUS_STOP && !pProcessData->bIsEnd) - { - LogDebug << "status_stop parationInfoLast_:" << parationInfoLast_.modelSpaceFrame << " update by frameId:" << pProcessData->iFrameId; - parationInfoLast_.i64EndTimeStamp = pProcessData->i64TimeStamp; - parationInfoLast_.modelSpaceFrame = pProcessData->iFrameId; - return; - } - - if (iDirection_ == DIRECTION_UNKNOWN) - { - std::string strFilePath = strResultPath_ + pProcessData->strTrainDate + "/" + pProcessData->strTrainName + "/" + "direction.txt"; - Json::Value jvDirectionInfo; - if (MyUtils::getins()->ReadJsonInfo(jvDirectionInfo, strFilePath)) - { - iDirection_ = jvDirectionInfo["direction"].asInt(); - } - else - { - LogWarn << "暂未检测出行车方向"; - } - } - - bool bIntervalFlag = ((int)(pProcessData->iFrameId - parationInfoLast_.modelSpaceFrame)) > iSplitSpan_; - int iCenterCur = jvStep1Space[0]["ltx"].asFloat() + (jvStep1Space[0]["rbx"].asFloat() - jvStep1Space[0]["ltx"].asFloat()) / 2; - int iCenterLast = parationInfoLast_.fLTX + (parationInfoLast_.fRBX - parationInfoLast_.fLTX) / 2; - LogDebug << "当前帧:" << pProcessData->iFrameId << " 间隔框中心线:" << iCenterCur - << " 上一帧:" << parationInfoLast_.modelSpaceFrame << " 间隔框中心线:" << iCenterLast - << " 行车方向:" << iDirection_ << " 是否满足切分帧数:" << bIntervalFlag << " bDealCenterFlag_:" << bDealCenterFlag_; - - if (iDirection_ == DIRECTION_UNKNOWN || iCenterLast == 0) - { - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - vecParationInfo_.push_back(parationInfo); - } - else if (iDirection_ == DIRECTION_LEFT) - { - if (iCenterCur < (pProcessData->iWidth / 3)) - { - if (!bDealCenterFlag_) - { - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - vecParationInfo_.push_back(parationInfo); - DealCenterSpace(vecParationInfo_, pProcessData); - bDealCenterFlag_ = true; - } - //这需要替换parationInfoLast_, 确保parationInfoLast_是最靠左的一个间隔,但不需要加入集合 - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - } - else if ((iCenterLast < iCenterCur - iSplitSpanPX_) && bIntervalFlag) //该条件只会在新车间隔出来进入一次 - { - //防止上节车厢间隔框所有识别都大于画面的1/3,因此当前车厢间隔出来后也需处理下上节车厢间隔 - if (!bDealCenterFlag_ && vecParationInfo_.size() > 0) - { - LogDebug << "lastFrameid:" << vecParationInfo_[0].modelSpaceFrame << " frameid:" << pProcessData->iFrameId; - DealCenterSpace(vecParationInfo_, pProcessData); - } - - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - vecParationInfo_.push_back(parationInfo); - bDealCenterFlag_ = false; - } - else - { - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - //该条件是防止第一个XXX帧满足小于画面1/3后切割,后一帧XXX+1的中心点大于画面1/3导致的加入vec中出现的多切分现象。(向右增加30px的浮动) - if (!(bDealCenterFlag_ && !bIntervalFlag && (iCenterCur < (pProcessData->iWidth / 3 + 80)))) - { - vecParationInfo_.push_back(parationInfo); - } - } - } - else if (iDirection_ == DIRECTION_RIGHT) - { - if (iCenterCur > (pProcessData->iWidth / 3 * 2)) - { - if (!bDealCenterFlag_) - { - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - vecParationInfo_.push_back(parationInfo); - DealCenterSpace(vecParationInfo_, pProcessData); - bDealCenterFlag_ = true; - } - - //这需要替换parationInfoLast_, 确保parationInfoLast_是最靠右的一个间隔,但不需要加入集合 - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - } - else if ((iCenterLast - iSplitSpanPX_ > iCenterCur) && bIntervalFlag) //该条件只会在新车间隔出来进入一次 - { - //防止上节车厢间隔所有识别框都小于画面的2/3,因此当前车厢间隔出来后也需处理下上节车厢间隔 - if (!bDealCenterFlag_ && vecParationInfo_.size() > 0) - { - LogDebug << "lastFrameid:" << vecParationInfo_[0].modelSpaceFrame << " frameid:" << pProcessData->iFrameId; - DealCenterSpace(vecParationInfo_, pProcessData); - } - - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - vecParationInfo_.push_back(parationInfo); - bDealCenterFlag_ = false; - } - else - { - PartionInfo parationInfo; - MakeParationInfo(parationInfo, pProcessData, jvStep1Space); - //该条件是防止第一个XXX帧满足大于画面2/3后切割,后一帧XXX+1的中心点小于画面2/3导致的加入vec中出现的多切分现象。(向左增加30px的浮动) - if (!(bDealCenterFlag_ && !bIntervalFlag && (iCenterCur > (pProcessData->iWidth / 3 * 2 - 80)))) - { - vecParationInfo_.push_back(parationInfo); - } - } - } -} - -void SaveStepOneResultEngine::SplitTrainByNumPro(std::shared_ptr &pPartionInfo, std::shared_ptr &pProcessData) -{ - //向左行驶用车号位置,向右行驶用属性位置。 - std::map *pMapCenterInfoTemp_ = nullptr; - if (iDirection_ == DIRECTION_LEFT) - { - pMapCenterInfoTemp_ = &mapNumCenterInfo_; - mapProCenterInfo_.clear(); - } - else if (iDirection_ == DIRECTION_RIGHT) - { - pMapCenterInfoTemp_ = &mapProCenterInfo_; - mapNumCenterInfo_.clear(); - } - - if (pMapCenterInfoTemp_ == nullptr || pMapCenterInfoTemp_->size() <= 0) - { - return; - } - - LogDebug << "pPartionInfo->modelSpaceFrame:" << pPartionInfo->modelSpaceFrame << " mapsize:" << pMapCenterInfoTemp_->size(); - auto iter = pMapCenterInfoTemp_->begin(); - int iCenterXPre = iter->second; - uint32_t iFrameIdPre = iter->first; - bool bFlag = false; - uint32_t iSplitFrameId = 0; - while (++iter != pMapCenterInfoTemp_->end()) - { - bool bIntervalFlag = (int)(iter->first - iFrameIdPre) > iSplitSpan_; - LogDebug << "iFrameIdPre:" << iFrameIdPre << " iCenterXPre:" << iCenterXPre - << " iFrameid:" << iter->first << " iCenter:" << iter->second << " bIntervalFlag:" << bIntervalFlag; - if (iDirection_ == DIRECTION_LEFT && (iCenterXPre < iter->second - iSplitSpanPX_) && bIntervalFlag) - { - iSplitFrameId = iter->first; - bFlag = true; - } - if (iDirection_ == DIRECTION_RIGHT && (iCenterXPre - iSplitSpanPX_ > iter->second) && bIntervalFlag) - { - iSplitFrameId = iter->first; - //iSplitFrameId = iFrameIdPre; //向右行驶,从车号行驶到最右侧开始切分。 - bFlag = true; - } - - //比较完后,可更新前一帧数据 - iCenterXPre = iter->second; - iFrameIdPre = iter->first; - - if(bFlag) - { - if (iDirection_ == DIRECTION_LEFT && iter->second < (pProcessData->iWidth / 3)) - { - bFlag = false; - } - else if (iDirection_ == DIRECTION_RIGHT && iter->second > (pProcessData->iWidth / 3 * 2)) - { - bFlag = false; - } - if (!bFlag) - { - PartionInfo parationInfo; - std::shared_ptr pPartionInfoNew = std::make_shared(); - // pPartionInfoNew->i64EndTimeStamp = pProcessData->i64TimeStamp; - pPartionInfoNew->modelSpaceFrame = iSplitFrameId; - // parationInfo.iRate = pProcessData->iRate; - pPartionInfoNew->bmodelconfirmed = false; - // pPartionInfoNew->fLTX = jvStep1Space[0]["ltx"].asFloat(); - // pPartionInfoNew->fRBX = jvStep1Space[0]["rbx"].asFloat(); - pPartionInfoNew->strTrainDate = pProcessData->strTrainDate; - pPartionInfoNew->strTrainName = pProcessData->strTrainName; - pPartionInfoNew->bIsEnd = false; //**通过该函数切分的肯定不是最后一节 - pPartionInfoNew->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); - if (iPushSpaceFrameId_ == 0) - { - pPartionInfoNew->i64StartTimeStamp = i64TimeStampFirst_; - pPartionInfoNew->startframe = dataSourceConfig_.iSkipInterval; - } -// pPartionInfoNew->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); - - //构造一个间隔信息写入到切分帧中 - char szCameraNo[5] = {0}; - sprintf(szCameraNo, "%03d/", pProcessData->iDataSource + 1); - std::string strFilePath; - strFilePath = strResultPath_ + pProcessData->strOrigTrainDate + "/" + pProcessData->strOrigTrainName + "/" + - szCameraNo + std::to_string(iSplitFrameId) + ".txt"; - Json::Value jvFrameInfo; - MyUtils::getins()->ReadJsonInfo(jvFrameInfo, strFilePath); - Json::Value jvOneSpace; - jvOneSpace["classid"] = 18; - jvOneSpace["ltx"] = pMapCenterInfoTemp_->at(iSplitFrameId) + (iDirection_ == DIRECTION_LEFT ? -50 : 50); - jvOneSpace["lty"] = 0; - jvOneSpace["rbx"] = pMapCenterInfoTemp_->at(iSplitFrameId) + (iDirection_ == DIRECTION_LEFT ? -50 : 50); - jvOneSpace["rby"] = 0; - jvFrameInfo["step1Space"].append(jvOneSpace); - MyUtils::getins()->WriteJsonInfo(jvFrameInfo, strFilePath); - - LogWarn << "--------- 向Paration 发送数据 --------"; - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pPartionInfoNew), true); - - iPushSpaceFrameId_ = pPartionInfoNew->modelSpaceFrame; - bPushIsEnd_ = pPartionInfoNew->bIsEnd; - LogDebug << "SplitTrainByNumPro pushSpaceFrameId:" << iPushSpaceFrameId_ << " timeStamp:" << pPartionInfoNew->i64EndTimeStamp - << " ltx:" << pPartionInfoNew->fLTX << " rbx:" << pPartionInfoNew->fRBX - << " bPushIsEnd:" << bPushIsEnd_; - - while (pMapCenterInfoTemp_->size() > 0) - { - auto iterDel = pMapCenterInfoTemp_->begin(); - if(iterDel->first > iPushSpaceFrameId_) - { - break; - } - LogDebug << "erase iFrameId:" << iterDel->first; - pMapCenterInfoTemp_->erase(iterDel); - } - } - } - - if (iter->first >= pPartionInfo->modelSpaceFrame) - { - LogDebug << "frameid:"<< iter->first << " >= pPartionInfo->modelSpaceFrame:" << pPartionInfo->modelSpaceFrame << " break"; - break; - } - } - - while (pMapCenterInfoTemp_->size() > 0) - { - auto iterDel = pMapCenterInfoTemp_->begin(); - if (iterDel->first > pPartionInfo->modelSpaceFrame) - { - break; - } - LogDebug << "erase iFrameId:" << iterDel->first; - pMapCenterInfoTemp_->erase(iterDel); - } -} - -APP_ERROR SaveStepOneResultEngine::Process() -{ - int iRet = APP_ERR_OK; - while (!isStop_) - { - //pop端口0 - std::shared_ptr pVoidData0 = nullptr; - iRet = inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); - continue; - } - std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - - if (pProcessData->iFrameId == dataSourceConfig_.iSkipInterval) - { - i64TimeStampFirst_ = pProcessData->i64TimeStamp; - } - - char szCameraNo[5] = {0}; - sprintf(szCameraNo, "%03d/", pProcessData->iDataSource + 1); - std::string strFilePath; - strFilePath = strResultPath_ + pProcessData->strOrigTrainDate + "/" + pProcessData->strOrigTrainName + "/" + - szCameraNo + std::to_string(pProcessData->iOrigFrameId) + ".txt"; - - - Json::Value jvStep1Num; - Json::Value jvStep1Pro; - Json::Value jvStep1ChkDate; - Json::Value jvStep1Container; - Json::Value jvStep1Space; - Json::Value jvStep1TrainSpace; - Json::Value jvStep1TopSpace; - for (int i = 0; i < pPostData->vecPostSubData.size(); i++) - { - PostSubData postSubData = pPostData->vecPostSubData[i]; - if (postSubData.vecSingleData.size() < 0) - { - continue; - } - - SingleData sdInfo = postSubData.vecSingleData.at(0); - Json::Value jvInfo; - jvInfo["classid"] = sdInfo.iClassId; - jvInfo["score"] = sdInfo.fScore; - jvInfo["clear"] = sdInfo.fClear; - jvInfo["ltx"] = sdInfo.fLTX; - jvInfo["lty"] = sdInfo.fLTY; - jvInfo["rbx"] = sdInfo.fRBX; - jvInfo["rby"] = sdInfo.fRBY; - float fCenter = sdInfo.fLTX + (sdInfo.fRBX - sdInfo.fLTX) / 2; - if (postSubData.iTargetType == NUM || postSubData.iTargetType == HEAD) - { - jvStep1Num.append(jvInfo); - if (pProcessData->iDataSource == 0 && pProcessData->iStatus != TRAINSTATUS_STOP) - { - if (postSubData.iTargetType != HEAD) - { - mapNumCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); - } - else - { - //车头没有属性,因此车头号也加入到属性中。保证向右行驶属性在前时最后2节的切分。 - //车头只加入一次,防止一个车头2个车头号的场景。但有两个车头且没识别车头间隔则无法处理。 - if (!bHaveHeadFlag_) - { - bool bIntervalFlag = ((int)(pProcessData->iFrameId - headInfo_.iFrameId) > iSplitSpan_ && headInfo_.iFrameId != 0); - - LogDebug << "frameid:" << pProcessData->iFrameId << " center:" << fCenter - << " preframeid:" << headInfo_.iFrameId << " precenter:" << headInfo_.fCenterX << " bIntervalFlag:" << bIntervalFlag; - if ((bIntervalFlag && abs((int)(headInfo_.fCenterX - fCenter)) > iSplitSpanPX_)) - { - bHaveHeadFlag_ = true; - } - else - { - headInfo_.fCenterX = fCenter; - headInfo_.iFrameId = pProcessData->iFrameId; - mapNumCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); - mapProCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); - } - } - } - } - } - else if (postSubData.iTargetType == PRO) - { - jvStep1Pro.append(jvInfo); - if (pProcessData->iDataSource == 0 && pProcessData->iStatus != TRAINSTATUS_STOP) - { - mapProCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); - } - } - else if (postSubData.iTargetType == CHKDATE) - { - jvStep1ChkDate.append(jvInfo); - } - else if (postSubData.iTargetType == CONTAINER) - { - jvStep1Container.append(jvInfo); - } - else if (postSubData.iTargetType == SPACE) - { - jvStep1Space.append(jvInfo); - } - else if (postSubData.iTargetType == TRAINSPACE) - { - jvStep1TrainSpace.append(jvInfo); - } - else if (postSubData.iTargetType == TOPSPACE) - { - jvStep1TopSpace.append(jvInfo); - } - } - - //先读取文本内容,追加新的信息后再写入 - Json::Value jvFrameInfo; - if (!MyUtils::getins()->ReadJsonInfo(jvFrameInfo, strFilePath)) - { - LogError << "read fail:" << strFilePath; - } - - if (jvStep1Num.size() > 0) - { - jvFrameInfo["step1Num"] = jvStep1Num; - } - if (jvStep1Pro.size() > 0) - { - jvFrameInfo["step1Pro"] = jvStep1Pro; - } - if (jvStep1ChkDate.size() > 0) - { - jvFrameInfo["step1ChkDate"] = jvStep1ChkDate; - } - if (jvStep1Container.size() > 0) - { - jvFrameInfo["step1Container"] = jvStep1Container; - } - if (jvStep1Space.size() > 0) - { - jvFrameInfo["step1Space"] = jvStep1Space; - } - if (jvStep1TrainSpace.size() > 0) - { - jvFrameInfo["step1TrainSpace"] = jvStep1TrainSpace; - if (jvStep1Space.size() <= 0) - { - jvFrameInfo["step1Space"] = jvStep1TrainSpace; - jvStep1Space = jvStep1TrainSpace; - } - } - if (jvStep1TopSpace.size() > 0) - { - jvFrameInfo["step1TopSpace"] = jvStep1TopSpace; - } - - int iInvokeModelCnt = jvFrameInfo["invokeModelCnt"].asInt(); - iInvokeModelCnt++; - jvFrameInfo["invokeModelCnt"] = iInvokeModelCnt; - if (mapInvokeModelCnt_[pProcessData->iDataSource] == iInvokeModelCnt) - { - jvFrameInfo["step1Finish"] = true; - } - jvFrameInfo["isEnd"] = (pProcessData->bIsEnd || jvFrameInfo["isEnd"].asBool()); - if (pProcessData->iStatus == TRAINSTATUS_STOP && pProcessData->iStatus != jvFrameInfo["status"].asInt()) - { - jvFrameInfo["status"] = pProcessData->iStatus; - } - MyUtils::getins()->WriteJsonInfo(jvFrameInfo, strFilePath); - //第一步处理结束后, push端口1,做复制图片文本数据和图片上传处理。 - if (jvFrameInfo["step1Finish"].asBool()) - { - iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast(pProcessData), true); - } - - if (pProcessData->iDataSource == 0 && pPostData->iModelType == MODELTYPE_NUM) - { - DealTrainSpaceInfo(pProcessData, jvStep1Space); - - if (pProcessData->bIsEnd) - { - //最后一节处理下前一节信息 - if (!bDealCenterFlag_ && vecParationInfo_.size() > 0) - { - LogDebug << "lastFrameid:" << vecParationInfo_[0].modelSpaceFrame << " frameid:" << pProcessData->iFrameId; - DealCenterSpace(vecParationInfo_, pProcessData); - } - if (!bPushIsEnd_) - { - std::shared_ptr pPartionInfo = std::make_shared(); - pPartionInfo->iRate = pProcessData->iRate; - pPartionInfo->i64EndTimeStamp = pProcessData->i64TimeStamp; - pPartionInfo->modelSpaceFrame = pProcessData->iFrameId; - pPartionInfo->bmodelconfirmed = true; - pPartionInfo->strTrainDate = pProcessData->strTrainDate; - pPartionInfo->strTrainName = pProcessData->strTrainName; - pPartionInfo->bIsEnd = pProcessData->bIsEnd; - pPartionInfo->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); - - //最后一节和倒数第二节之间的间隔未能识别时,此时也需要通过车号属性切分下。 - SplitTrainByNumPro(pPartionInfo, pProcessData); - - LogWarn << "--------- 向Paration 发送数据 --------"; - outputQueMap_[strPort0_]->push(std::static_pointer_cast(pPartionInfo), true); - - iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame; - bPushIsEnd_ = pPartionInfo->bIsEnd; - LogDebug << "pushSpaceFrameId:" << iPushSpaceFrameId_ << " timeStamp:" << pPartionInfo->i64EndTimeStamp - << " ltx:" << pPartionInfo->fLTX << " rbx:" << pPartionInfo->fRBX - << " bPushIsEnd:" << bPushIsEnd_; - } - InitParam(); - } - } - } - return APP_ERR_OK; -} +#include "SaveStepOneResultEngine.h" using namespace ai_matrix; SaveStepOneResultEngine::SaveStepOneResultEngine() {} SaveStepOneResultEngine::~SaveStepOneResultEngine() {} APP_ERROR SaveStepOneResultEngine::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); iSplitSpan_ = MyYaml::GetIns()->GetIntValue("partition_frame_span"); iSplitSpanPX_ = MyYaml::GetIns()->GetIntValue("gc_split_frame_span_px"); dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); std::string delimiter(","); for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) { int iCnt = 0; std::vector vecSplit = MyUtils::getins()->split(iter->second.strTarget, delimiter); for (auto iter = vecSplit.begin(); iter != vecSplit.end(); iter++) { if (*iter == "NUM") { iCnt++; } else if (*iter == "CHKDATE") { iCnt++; } else if (*iter == "CONTAINER" || *iter == "CONTAINER_T") { iCnt++; } } mapInvokeModelCnt_[iter->first] = iCnt; } InitParam(); LogInfo << "SaveStepOneResultEngine Init ok"; return APP_ERR_OK; } APP_ERROR SaveStepOneResultEngine::DeInit() { LogInfo << "SaveStepOneResultEngine DeInit ok"; return APP_ERR_OK; } /** * 初始化参数信息 * inParam : N/A * outParam: N/A * return : N/A */ void SaveStepOneResultEngine::InitParam() { iPushSpaceFrameId_ = 0; i64TimeStampFirst_ = 0; iDirection_ = DIRECTION_UNKNOWN; bPushIsEnd_ = false; vecParationInfo_.clear(); std::vector().swap(vecParationInfo_); bDealCenterFlag_ = false; parationInfoLast_.i64EndTimeStamp = 0; parationInfoLast_.modelSpaceFrame = 0; parationInfoLast_.iRate = 0; parationInfoLast_.bmodelconfirmed = false; parationInfoLast_.fLTX = 0.0; parationInfoLast_.fRBX = 0.0; parationInfoLast_.strTrainDate = ""; parationInfoLast_.strTrainName = ""; parationInfoLast_.bIsEnd = false; parationInfoLast_.nStatus = 0; mapNumCenterInfo_.clear(); mapProCenterInfo_.clear(); bHaveHeadFlag_ = false; headInfo_.iFrameId = 0; headInfo_.fCenterX = 0; } /** * 构造车厢间隔信息 * inParam : N/A * outParam: N/A * return : N/A */ void SaveStepOneResultEngine::MakeParationInfo(PartionInfo ¶tionInfo, std::shared_ptr pProcessData, Json::Value &jvStep1Space) { parationInfo.i64EndTimeStamp = pProcessData->i64TimeStamp; parationInfo.modelSpaceFrame = pProcessData->iFrameId; parationInfo.iRate = pProcessData->iRate; parationInfo.bmodelconfirmed = true; parationInfo.fLTX = jvStep1Space[0]["ltx"].asFloat(); parationInfo.fRBX = jvStep1Space[0]["rbx"].asFloat(); parationInfo.strTrainDate = pProcessData->strTrainDate; parationInfo.strTrainName = pProcessData->strTrainName; parationInfo.bIsEnd = pProcessData->bIsEnd; parationInfo.nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); parationInfoLast_ = parationInfo; } /** * 处理中心间隔信息 * inParam : N/A * outParam: N/A * return : N/A */ void SaveStepOneResultEngine::DealCenterSpace(std::vector &vecParationInfo, std::shared_ptr pProcessData) { int iVecSize = vecParationInfo.size(); if (iVecSize < 0) { return; } LogDebug << "积累的车厢切分信息数:" << iVecSize << " 帧:" << pProcessData->iFrameId << " 第一个车厢切分信息帧:" << vecParationInfo.at(0).modelSpaceFrame << " 最后一个车厢切分信息帧:" << vecParationInfo.at(iVecSize - 1).modelSpaceFrame << " 最后一个车厢切分信息是否为结束:" << vecParationInfo.at(iVecSize - 1).bIsEnd; /* 因停车后再行驶未能及时判断出为行驶状态,导致更新间隔信息,出现漏切分车厢(具体原因分析见正通2023-02-28的问题分析记录) 漏切分时vecParationInfo中保存的是两辆车的间隔信息,因此针对vecParationInfo做特殊处理,从此处切分出遗漏的车厢。 */ std::vector vecSpacePos; for (int i = 1; i < iVecSize; i++) { int iCenterXPre = vecParationInfo[i - 1].fLTX + (vecParationInfo[i - 1].fRBX - vecParationInfo[i - 1].fLTX) / 2; int iCenterX = vecParationInfo[i].fLTX + (vecParationInfo[i].fRBX - vecParationInfo[i].fLTX) / 2; bool bIntervalFlag = ((int)(vecParationInfo[i].modelSpaceFrame - vecParationInfo[i - 1].modelSpaceFrame)) > iSplitSpan_; LogDebug << "上一帧ID:" << vecParationInfo[i - 1].modelSpaceFrame << " 上一帧间隔X轴中线:" << iCenterXPre << " 本帧ID:" << vecParationInfo[i].modelSpaceFrame << " 本帧间隔X轴中线:" << iCenterX << " 满足帧间隔:" << bIntervalFlag << " i:" << i; if (iDirection_ == DIRECTION_LEFT && (iCenterXPre < iCenterX - iSplitSpanPX_) && bIntervalFlag) { vecSpacePos.push_back(i - 1); } if (iDirection_ == DIRECTION_RIGHT && (iCenterXPre - iSplitSpanPX_ > iCenterX) && bIntervalFlag) { vecSpacePos.push_back(i - 1); } } LogDebug << "vecSpacePos size:" << vecSpacePos.size(); vecSpacePos.push_back(iVecSize - 1); /* 如果集合中最后为列车结束帧,则表示停车在车厢间隔。这时用最后一个作为车厢划分帧。 其他场景使用靠近中心的间隔帧作为车厢划分帧 */ for (int iSpacePos = 0; iSpacePos < vecSpacePos.size(); iSpacePos++) { LogDebug << "index:" << vecSpacePos.at(iSpacePos) << " frameid:" << vecParationInfo[vecSpacePos.at(iSpacePos)].modelSpaceFrame; std::shared_ptr pPartionInfo = std::make_shared(); if (iSpacePos == vecSpacePos.size() - 1 && vecParationInfo[vecSpacePos.at(iSpacePos)].bIsEnd) { *pPartionInfo = vecParationInfo[vecSpacePos.at(iSpacePos)]; } else { int iPos = 0; int iImageCenter = pProcessData->iWidth / 2; int iToCenterXMin = iImageCenter; int iBegin = (iSpacePos == 0 ? 0 : vecSpacePos.at(iSpacePos - 1) + 1); for (int i = iBegin; i <= vecSpacePos.at(iSpacePos); i++) { int iCenterX = vecParationInfo[i].fLTX + (vecParationInfo[i].fRBX - vecParationInfo[i].fLTX) / 2; if (iToCenterXMin > abs(iCenterX - iImageCenter)) { iToCenterXMin = abs(iCenterX - iImageCenter); iPos = i; } } *pPartionInfo = vecParationInfo[iPos]; } //此处切分时,依据车号,属性判断是否有漏的车厢,如果有则依靠车号属性切分。 SplitTrainByNumPro(pPartionInfo, pProcessData); pPartionInfo->fLTX = pPartionInfo->fLTX / (pProcessData->iWidth / METHOD_BASE_WIDTH); pPartionInfo->fRBX = pPartionInfo->fRBX / (pProcessData->iWidth / METHOD_BASE_WIDTH); if (iPushSpaceFrameId_ == 0) { pPartionInfo->i64StartTimeStamp = i64TimeStampFirst_; pPartionInfo->startframe = dataSourceConfig_.iSkipInterval; } pPartionInfo->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); LogWarn << "--------- 向Paration 发送数据 --------"; outputQueMap_[strPort0_]->push(std::static_pointer_cast(pPartionInfo)); iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame; bPushIsEnd_ = pPartionInfo->bIsEnd; LogDebug << "pushSpaceFrameId:" << iPushSpaceFrameId_ << " timeStamp:" << pPartionInfo->i64EndTimeStamp << " ltx:" << pPartionInfo->fLTX << " rbx:" << pPartionInfo->fRBX << " bPushIsEnd:" << bPushIsEnd_; } vecParationInfo.clear(); } /** * 处理车厢间隔 * inParam : N/A * outParam: N/A * return : N/A */ void SaveStepOneResultEngine::DealTrainSpaceInfo(std::shared_ptr pProcessData, Json::Value &jvStep1Space) { /* 无方向时,识别的内容都放入集合中。 有向时,按方向判断是否push车厢间隔框 向左行驶:帧间隔中心点小于画面1/3时,则处理车厢间隔集合。新车厢间隔必须大于上次车厢中心点再放入集合等待处理。 向右行驶:帧间隔中心点大于画面2/3时,则处理车厢间隔集合。新车厢间隔必须小于上次车厢中心点再放入集合等待处理。 注:最后一节不会再有帧间隔了,因此直接发送的结束帧,且坐标设置中心点。 */ if (jvStep1Space.size() <= 0 || pProcessData->iOrigFrameId < 50) { return; } /* 停车状态后不再放入信息到集合中,防止长时间停在间隔上导致集合持续增大。 停车状态且有间隔时需更新最后间隔框帧号。(防止在XXX帧停车且有间隔框,然后开始倒车再正向行驶,当再回到开始倒车的位置时,此时帧号为YYYY, 会符合下面的partition_frame_span判断,导致bIntervalFlag为true而切分车厢) */ if (pProcessData->iStatus == TRAINSTATUS_STOP && !pProcessData->bIsEnd) { // LogDebug << "status_stop parationInfoLast_:" << parationInfoLast_.modelSpaceFrame << " update by frameId:" << pProcessData->iFrameId; parationInfoLast_.i64EndTimeStamp = pProcessData->i64TimeStamp; parationInfoLast_.modelSpaceFrame = pProcessData->iFrameId; return; } if (iDirection_ == DIRECTION_UNKNOWN) { std::string strFilePath = strResultPath_ + pProcessData->strTrainDate + "/" + pProcessData->strTrainName + "/" + "direction.txt"; Json::Value jvDirectionInfo; if (MyUtils::getins()->ReadJsonInfo(jvDirectionInfo, strFilePath)) { iDirection_ = jvDirectionInfo["direction"].asInt(); } else { LogWarn << "暂未检测出行车方向"; } } bool bIntervalFlag = ((int)(pProcessData->iFrameId - parationInfoLast_.modelSpaceFrame)) > iSplitSpan_; int iCenterCur = jvStep1Space[0]["ltx"].asFloat() + (jvStep1Space[0]["rbx"].asFloat() - jvStep1Space[0]["ltx"].asFloat()) / 2; int iCenterLast = parationInfoLast_.fLTX + (parationInfoLast_.fRBX - parationInfoLast_.fLTX) / 2; LogDebug << "当前帧:" << pProcessData->iFrameId << " 间隔框中心线:" << iCenterCur << " 上一帧:" << parationInfoLast_.modelSpaceFrame << " 间隔框中心线:" << iCenterLast << " 行车方向:" << iDirection_ << " 是否满足切分帧数:" << bIntervalFlag << " bDealCenterFlag_:" << bDealCenterFlag_; if (iDirection_ == DIRECTION_UNKNOWN || iCenterLast == 0) { PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); vecParationInfo_.push_back(parationInfo); } else if (iDirection_ == DIRECTION_LEFT) { if (iCenterCur < (pProcessData->iWidth / 3)) { if (!bDealCenterFlag_) { PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); vecParationInfo_.push_back(parationInfo); DealCenterSpace(vecParationInfo_, pProcessData); bDealCenterFlag_ = true; } //这需要替换parationInfoLast_, 确保parationInfoLast_是最靠左的一个间隔,但不需要加入集合 PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); } else if ((iCenterLast < iCenterCur - iSplitSpanPX_) && bIntervalFlag) //该条件只会在新车间隔出来进入一次 { //防止上节车厢间隔框所有识别都大于画面的1/3,因此当前车厢间隔出来后也需处理下上节车厢间隔 if (!bDealCenterFlag_ && vecParationInfo_.size() > 0) { LogDebug << "lastFrameid:" << vecParationInfo_[0].modelSpaceFrame << " frameid:" << pProcessData->iFrameId; DealCenterSpace(vecParationInfo_, pProcessData); } PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); vecParationInfo_.push_back(parationInfo); bDealCenterFlag_ = false; } else { PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); //该条件是防止第一个XXX帧满足小于画面1/3后切割,后一帧XXX+1的中心点大于画面1/3导致的加入vec中出现的多切分现象。(向右增加30px的浮动,因为大框可能不是同一种) if (!(bDealCenterFlag_ && !bIntervalFlag && (iCenterCur < (pProcessData->iWidth / 3 + 80)))) { vecParationInfo_.push_back(parationInfo); } } } else if (iDirection_ == DIRECTION_RIGHT) { if (iCenterCur > (pProcessData->iWidth / 3 * 2)) { if (!bDealCenterFlag_) { PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); vecParationInfo_.push_back(parationInfo); DealCenterSpace(vecParationInfo_, pProcessData); bDealCenterFlag_ = true; } //这需要替换parationInfoLast_, 确保parationInfoLast_是最靠右的一个间隔,但不需要加入集合 PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); } else if ((iCenterLast - iSplitSpanPX_ > iCenterCur) && bIntervalFlag) //该条件只会在新车间隔出来进入一次 { //防止上节车厢间隔所有识别框都小于画面的2/3,因此当前车厢间隔出来后也需处理下上节车厢间隔 if (!bDealCenterFlag_ && vecParationInfo_.size() > 0) { LogDebug << "lastFrameid:" << vecParationInfo_[0].modelSpaceFrame << " frameid:" << pProcessData->iFrameId; DealCenterSpace(vecParationInfo_, pProcessData); } PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); vecParationInfo_.push_back(parationInfo); bDealCenterFlag_ = false; } else { PartionInfo parationInfo; MakeParationInfo(parationInfo, pProcessData, jvStep1Space); //该条件是防止第一个XXX帧满足大于画面2/3后切割,后一帧XXX+1的中心点小于画面2/3导致的加入vec中出现的多切分现象。(向左增加80px的浮动因为大框可能不是同一种) if (!(bDealCenterFlag_ && !bIntervalFlag && (iCenterCur > (pProcessData->iWidth / 3 * 2 - 80)))) { vecParationInfo_.push_back(parationInfo); } } } } void SaveStepOneResultEngine::SplitTrainByNumPro(std::shared_ptr &pPartionInfo, std::shared_ptr &pProcessData) { //向左行驶用车号位置,向右行驶用属性位置。 std::map *pMapCenterInfoTemp_ = nullptr; if (iDirection_ == DIRECTION_LEFT) { pMapCenterInfoTemp_ = &mapNumCenterInfo_; mapProCenterInfo_.clear(); } else if (iDirection_ == DIRECTION_RIGHT) { pMapCenterInfoTemp_ = &mapProCenterInfo_; mapNumCenterInfo_.clear(); } if (pMapCenterInfoTemp_ == nullptr || pMapCenterInfoTemp_->size() <= 0) { return; } LogDebug << "pPartionInfo->modelSpaceFrame:" << pPartionInfo->modelSpaceFrame << " mapsize:" << pMapCenterInfoTemp_->size(); auto iter = pMapCenterInfoTemp_->begin(); int iCenterXPre = iter->second; uint32_t iFrameIdPre = iter->first; bool bFlag = false; uint32_t iSplitFrameId = 0; while (++iter != pMapCenterInfoTemp_->end()) { bool bIntervalFlag = (int)(iter->first - iFrameIdPre) > iSplitSpan_; LogDebug << "iFrameIdPre:" << iFrameIdPre << " iCenterXPre:" << iCenterXPre << " iFrameid:" << iter->first << " iCenter:" << iter->second << " bIntervalFlag:" << bIntervalFlag; if (iDirection_ == DIRECTION_LEFT && (iCenterXPre < iter->second - iSplitSpanPX_) && bIntervalFlag) { iSplitFrameId = iter->first; bFlag = true; } if (iDirection_ == DIRECTION_RIGHT && (iCenterXPre - iSplitSpanPX_ > iter->second) && bIntervalFlag) { iSplitFrameId = iter->first; //iSplitFrameId = iFrameIdPre; //向右行驶,从车号行驶到最右侧开始切分。 bFlag = true; } //比较完后,可更新前一帧数据 iCenterXPre = iter->second; iFrameIdPre = iter->first; if(bFlag) { if (iDirection_ == DIRECTION_LEFT && iter->second < (pProcessData->iWidth / 3)) { bFlag = false; } else if (iDirection_ == DIRECTION_RIGHT && iter->second > (pProcessData->iWidth / 3 * 2)) { bFlag = false; } if (!bFlag) { PartionInfo parationInfo; std::shared_ptr pPartionInfoNew = std::make_shared(); // pPartionInfoNew->i64EndTimeStamp = pProcessData->i64TimeStamp; pPartionInfoNew->modelSpaceFrame = iSplitFrameId; // parationInfo.iRate = pProcessData->iRate; pPartionInfoNew->bmodelconfirmed = false; // pPartionInfoNew->fLTX = jvStep1Space[0]["ltx"].asFloat(); // pPartionInfoNew->fRBX = jvStep1Space[0]["rbx"].asFloat(); pPartionInfoNew->strTrainDate = pProcessData->strTrainDate; pPartionInfoNew->strTrainName = pProcessData->strTrainName; pPartionInfoNew->bIsEnd = false; //**通过该函数切分的肯定不是最后一节 pPartionInfoNew->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); if (iPushSpaceFrameId_ == 0) { pPartionInfoNew->i64StartTimeStamp = i64TimeStampFirst_; pPartionInfoNew->startframe = dataSourceConfig_.iSkipInterval; } // pPartionInfoNew->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); //构造一个间隔信息写入到切分帧中 char szCameraNo[5] = {0}; sprintf(szCameraNo, "%03d/", pProcessData->iDataSource + 1); std::string strFilePath; strFilePath = strResultPath_ + pProcessData->strOrigTrainDate + "/" + pProcessData->strOrigTrainName + "/" + szCameraNo + std::to_string(iSplitFrameId) + ".txt"; Json::Value jvFrameInfo; MyUtils::getins()->ReadJsonInfo(jvFrameInfo, strFilePath); Json::Value jvOneSpace; jvOneSpace["classid"] = 18; jvOneSpace["ltx"] = pMapCenterInfoTemp_->at(iSplitFrameId) + (iDirection_ == DIRECTION_LEFT ? -50 : 50); jvOneSpace["lty"] = 0; jvOneSpace["rbx"] = pMapCenterInfoTemp_->at(iSplitFrameId) + (iDirection_ == DIRECTION_LEFT ? -50 : 50); jvOneSpace["rby"] = 0; jvFrameInfo["step1Space"].append(jvOneSpace); MyUtils::getins()->WriteJsonInfo(jvFrameInfo, strFilePath); LogWarn << "--------- 向Paration 发送数据 --------"; outputQueMap_[strPort0_]->push(std::static_pointer_cast(pPartionInfoNew)); iPushSpaceFrameId_ = pPartionInfoNew->modelSpaceFrame; bPushIsEnd_ = pPartionInfoNew->bIsEnd; LogDebug << "SplitTrainByNumPro pushSpaceFrameId:" << iPushSpaceFrameId_ << " timeStamp:" << pPartionInfoNew->i64EndTimeStamp << " ltx:" << pPartionInfoNew->fLTX << " rbx:" << pPartionInfoNew->fRBX << " bPushIsEnd:" << bPushIsEnd_; while (pMapCenterInfoTemp_->size() > 0) { auto iterDel = pMapCenterInfoTemp_->begin(); if(iterDel->first > iPushSpaceFrameId_) { break; } LogDebug << "erase iFrameId:" << iterDel->first; pMapCenterInfoTemp_->erase(iterDel); } } } if (iter->first >= pPartionInfo->modelSpaceFrame) { LogDebug << "frameid:"<< iter->first << " >= pPartionInfo->modelSpaceFrame:" << pPartionInfo->modelSpaceFrame << " break"; break; } } while (pMapCenterInfoTemp_->size() > 0) { auto iterDel = pMapCenterInfoTemp_->begin(); if (iterDel->first > pPartionInfo->modelSpaceFrame) { break; } LogDebug << "erase iFrameId:" << iterDel->first; pMapCenterInfoTemp_->erase(iterDel); } } APP_ERROR SaveStepOneResultEngine::Process() { int iRet = APP_ERR_OK; while (!isStop_) { //pop端口0 std::shared_ptr pVoidData0 = nullptr; iRet = inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); continue; } std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); if (pProcessData->iFrameId == dataSourceConfig_.iSkipInterval) { i64TimeStampFirst_ = pProcessData->i64TimeStamp; } char szCameraNo[5] = {0}; sprintf(szCameraNo, "%03d/", pProcessData->iDataSource + 1); std::string strFilePath; strFilePath = strResultPath_ + pProcessData->strOrigTrainDate + "/" + pProcessData->strOrigTrainName + "/" + szCameraNo + std::to_string(pProcessData->iOrigFrameId) + ".txt"; Json::Value jvStep1Num; Json::Value jvStep1Pro; Json::Value jvStep1ChkDate; Json::Value jvStep1Container; Json::Value jvStep1Space; Json::Value jvStep1TrainSpace; Json::Value jvStep1TopSpace; for (int i = 0; i < pPostData->vecPostSubData.size(); i++) { PostSubData postSubData = pPostData->vecPostSubData[i]; if (postSubData.vecSingleData.size() < 0) { continue; } SingleData sdInfo = postSubData.vecSingleData.at(0); Json::Value jvInfo; jvInfo["classid"] = sdInfo.iClassId; jvInfo["score"] = sdInfo.fScore; jvInfo["clear"] = sdInfo.fClear; jvInfo["ltx"] = sdInfo.fLTX; jvInfo["lty"] = sdInfo.fLTY; jvInfo["rbx"] = sdInfo.fRBX; jvInfo["rby"] = sdInfo.fRBY; float fCenter = sdInfo.fLTX + (sdInfo.fRBX - sdInfo.fLTX) / 2; if (postSubData.iTargetType == NUM || postSubData.iTargetType == HEAD) { jvStep1Num.append(jvInfo); if (pProcessData->iDataSource == 0 && pProcessData->iStatus != TRAINSTATUS_STOP) { if (postSubData.iTargetType != HEAD) { mapNumCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); } else { //车头没有属性,因此车头号也加入到属性中。保证向右行驶属性在前时最后2节的切分。 //车头只加入一次,防止一个车头2个车头号的场景。但有两个车头且没识别车头间隔则无法处理。 if (!bHaveHeadFlag_) { bool bIntervalFlag = ((int)(pProcessData->iFrameId - headInfo_.iFrameId) > iSplitSpan_ && headInfo_.iFrameId != 0); LogDebug << "frameid:" << pProcessData->iFrameId << " center:" << fCenter << " preframeid:" << headInfo_.iFrameId << " precenter:" << headInfo_.fCenterX << " bIntervalFlag:" << bIntervalFlag; if ((bIntervalFlag && abs((int)(headInfo_.fCenterX - fCenter)) > iSplitSpanPX_)) { bHaveHeadFlag_ = true; } else { headInfo_.fCenterX = fCenter; headInfo_.iFrameId = pProcessData->iFrameId; mapNumCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); mapProCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); } } } } } else if (postSubData.iTargetType == PRO) { jvStep1Pro.append(jvInfo); if (pProcessData->iDataSource == 0 && pProcessData->iStatus != TRAINSTATUS_STOP) { mapProCenterInfo_.insert(std::make_pair(pProcessData->iFrameId, fCenter)); } } else if (postSubData.iTargetType == CHKDATE) { jvStep1ChkDate.append(jvInfo); } else if (postSubData.iTargetType == CONTAINER) { jvStep1Container.append(jvInfo); } else if (postSubData.iTargetType == SPACE) { jvStep1Space.append(jvInfo); } else if (postSubData.iTargetType == TRAINSPACE) { jvStep1TrainSpace.append(jvInfo); } else if (postSubData.iTargetType == TOPSPACE) { jvStep1TopSpace.append(jvInfo); } } //先读取文本内容,追加新的信息后再写入 Json::Value jvFrameInfo; if (!MyUtils::getins()->ReadJsonInfo(jvFrameInfo, strFilePath)) { LogError << "read fail:" << strFilePath; } if (jvStep1Num.size() > 0) { jvFrameInfo["step1Num"] = jvStep1Num; } if (jvStep1Pro.size() > 0) { jvFrameInfo["step1Pro"] = jvStep1Pro; } if (jvStep1ChkDate.size() > 0) { jvFrameInfo["step1ChkDate"] = jvStep1ChkDate; } if (jvStep1Container.size() > 0) { jvFrameInfo["step1Container"] = jvStep1Container; } if (jvStep1Space.size() > 0) { jvFrameInfo["step1Space"] = jvStep1Space; } if (jvStep1TrainSpace.size() > 0) { jvFrameInfo["step1TrainSpace"] = jvStep1TrainSpace; if (jvStep1Space.size() <= 0) { jvFrameInfo["step1Space"] = jvStep1TrainSpace; jvStep1Space = jvStep1TrainSpace; } } if (jvStep1TopSpace.size() > 0) { jvFrameInfo["step1TopSpace"] = jvStep1TopSpace; } int iInvokeModelCnt = jvFrameInfo["invokeModelCnt"].asInt(); iInvokeModelCnt++; jvFrameInfo["invokeModelCnt"] = iInvokeModelCnt; if (mapInvokeModelCnt_[pProcessData->iDataSource] == iInvokeModelCnt) { jvFrameInfo["step1Finish"] = true; } jvFrameInfo["isEnd"] = (pProcessData->bIsEnd || jvFrameInfo["isEnd"].asBool()); if (pProcessData->iStatus == TRAINSTATUS_STOP && pProcessData->iStatus != jvFrameInfo["status"].asInt()) { jvFrameInfo["status"] = pProcessData->iStatus; } MyUtils::getins()->WriteJsonInfo(jvFrameInfo, strFilePath); //第一步处理结束后, push端口1,做复制图片文本数据和图片上传处理。 if (jvFrameInfo["step1Finish"].asBool()) { iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast(pProcessData)); } if (pProcessData->iDataSource == 0 && pPostData->iModelType == MODELTYPE_NUM) { DealTrainSpaceInfo(pProcessData, jvStep1Space); if (pProcessData->bIsEnd) { //最后一节处理下前一节信息 if (!bDealCenterFlag_ && vecParationInfo_.size() > 0) { LogDebug << "lastFrameid:" << vecParationInfo_[0].modelSpaceFrame << " frameid:" << pProcessData->iFrameId; DealCenterSpace(vecParationInfo_, pProcessData); } if (!bPushIsEnd_) { std::shared_ptr pPartionInfo = std::make_shared(); pPartionInfo->iRate = pProcessData->iRate; pPartionInfo->i64EndTimeStamp = pProcessData->i64TimeStamp; pPartionInfo->modelSpaceFrame = pProcessData->iFrameId; pPartionInfo->bmodelconfirmed = true; pPartionInfo->strTrainDate = pProcessData->strTrainDate; pPartionInfo->strTrainName = pProcessData->strTrainName; pPartionInfo->bIsEnd = pProcessData->bIsEnd; pPartionInfo->nStatus = ((pProcessData->iStatus == TRAINSTATUS_STOP) ? TRAIN_PAUSE : iDirection_); //最后一节和倒数第二节之间的间隔未能识别时,此时也需要通过车号属性切分下。 SplitTrainByNumPro(pPartionInfo, pProcessData); LogWarn << "--------- 向Paration 发送数据 --------"; outputQueMap_[strPort0_]->push(std::static_pointer_cast(pPartionInfo)); iPushSpaceFrameId_ = pPartionInfo->modelSpaceFrame; bPushIsEnd_ = pPartionInfo->bIsEnd; LogDebug << "pushSpaceFrameId:" << iPushSpaceFrameId_ << " timeStamp:" << pPartionInfo->i64EndTimeStamp << " ltx:" << pPartionInfo->fLTX << " rbx:" << pPartionInfo->fRBX << " bPushIsEnd:" << bPushIsEnd_; } InitParam(); } } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/SelectBestEngine/SelectBestEngine.cpp b/nvidia_ascend_engine/common_engine/SelectBestEngine/SelectBestEngine.cpp index 085783c..22e0173 100644 --- a/nvidia_ascend_engine/common_engine/SelectBestEngine/SelectBestEngine.cpp +++ b/nvidia_ascend_engine/common_engine/SelectBestEngine/SelectBestEngine.cpp @@ -1,765 +1 @@ -#include "SelectBestEngine.h" -#include "myutils.h" - -using namespace ai_matrix; - -SelectBestEngine::SelectBestEngine() {} - -SelectBestEngine::~SelectBestEngine() {} - -APP_ERROR SelectBestEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - iSelectBestMode_ = MyYaml::GetIns()->GetIntValue("gc_select_best_mode"); - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - strBestPath_ = MyYaml::GetIns()->GetPathValue("gc_best_path"); - - //获取几个摄像头识别车号 - std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); - for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) - { - if (iter->second.strTarget.find("NUM") != std::string::npos) - { - mapDataSourceIsEnd_[iter->first] = false; - } - } - - InitParam(); - LogInfo << "SelectBestEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR SelectBestEngine::DeInit() -{ - LogInfo << "SelectBestEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* push数据到队列,队列满时则休眠一段时间再push -* inParam : const std::string strPort push的端口 - : const std::shared_ptr &pTrain push的数据 -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::PushData(const std::string &strPort, const std::shared_ptr &pTrain) -{ - while (true) - { - int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pTrain)); - if (iRet != 0) - { - LogDebug << "num:" << pTrain->trainNum.strTrainNum << " push fail iRet:" << iRet; - if (iRet == 2) - { - usleep(10000); // 10ms - continue; - } - } - break; - } -} - -/** -* 初始化车号参数信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::InitNumParam() -{ - mapTrainTypeId_.clear(); - mapNumInfo_.clear(); - strBestNumImg_ = ""; - i64TimeStampNum_ = 0; - fMaxScoreSumNum_ = 0; - memset(&step1LocationBestNum_, 0, sizeof(step1LocationBestNum_)); - iDataSourceNum_ = 0; -} - -/** -* 初始化属性参数信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::InitProParam() -{ - mapProInfo_.clear(); - strBestProImg_ = ""; - i64TimeStampPro_ = 0; - fMaxScoreSumPro_ = 0; - memset(&step1LocationBestPro_, 0, sizeof(step1LocationBestPro_)); - iDataSourcePro_ = 0; -} - -/** -* 初始化车号参数信息(只有车结束调用) -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::InitHeadParam() -{ - mapHeadInfo_.clear(); - strBestHeadImg_ = ""; - i64TimeStampHead_ = 0; - fMaxScoreSumHead_ = 0; - memset(&step1LocationBestHead_, 0, sizeof(step1LocationBestHead_)); - iDataSourceHead_ = 0; -} - -/** -* 初始化参数信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::InitParam() -{ - iNumIndex_ = 1; - iProIndex_ = 1; - InitNumParam(); - InitProParam(); - InitHeadParam(); - - for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) - { - iter->second = false; - } -} - -/** -* 获取最优长度 -* inParam : std::vector &vecAllTransInfo 待汇总取优的结果集 -* : TargetMaxLen iMaxLen 目标最大长度 -* outParam: N/A -* return : 最优长度 -*/ -int SelectBestEngine::GetBestLength(std::vector &vecAllTransInfo, TargetMaxLen iMaxLen) -{ - //1.获取结果中每种长度出现的次数 - std::map mapResultSize; - for (size_t i = 0; i < vecAllTransInfo.size(); i++) - { - int iNowSize = vecAllTransInfo[i].vecValue.size(); - if (mapResultSize.find(iNowSize) != mapResultSize.end()) - { - mapResultSize[iNowSize]++; - continue; - } - mapResultSize[iNowSize] = 1; - } - - int iBestLen = 0; - //2.获取最优长度 - if (iSelectBestMode_ == FREQUENCY) - { - //2.1 按长度出现的频次最多,作为最优长度 - int iCnt = 0; - for (auto it = mapResultSize.begin(); it != mapResultSize.end(); it++) - { - if (iCnt < it->second && it->first <= iMaxLen) - { - iCnt = it->second; - iBestLen = it->first; - } - } - } - else if (iSelectBestMode_ == LENGTH) - { - //2.2 按最长长度且不能大于最大长度,作为最优长度 - for (auto rit = mapResultSize.rbegin(); rit != mapResultSize.rend(); rit++) - { - if (rit->first <= iMaxLen) - { - iBestLen = rit->first; - break; - } - } - } - - return iBestLen; -} - -/** -* 获取最优结果 -* inParam : std::vector &vecAllTransInfo 待汇总取优的结果集 -* : TargetMaxLen iMaxLen 目标最大长度 -* outParam: N/A -* return : 最优结果 -*/ -std::string SelectBestEngine::GetBest(std::vector &vecAllTransInfo, TargetMaxLen iMaxLen) -{ - std::string strValue = ""; - if (vecAllTransInfo.size() <= 0) - { - return strValue; - } - - //优先使用校验通过的数据选优。 - std::vector vecTransInfoTemp; - for (size_t i = 0; i < vecAllTransInfo.size(); i++) - { - TransInfo transInfo = vecAllTransInfo[i]; - if (transInfo.IsChkFlag) - { - vecTransInfoTemp.emplace_back(transInfo); - } - } - if (vecTransInfoTemp.size() > 0) - { - vecAllTransInfo = vecTransInfoTemp; - } - else - { - // 此处因车厢太脏。识别效果很差,难以与RFID识别结果融合,所以增加eles - return strValue; - } - - //获取最优长度 - int iBestLen = GetBestLength(vecAllTransInfo, iMaxLen); - - //初始化最优结果 - TransInfo transInfoBest; - transInfoBest.vecScore.reserve(iBestLen); - transInfoBest.vecValue.reserve(iBestLen); - for (int i = 0; i < iBestLen; i++) - { - transInfoBest.vecScore.emplace_back(0); - transInfoBest.vecValue.emplace_back(""); - } - - std::map mapResult; //符合最优长度的结果集 [key:结果; value:结果出现次数] - for (size_t iIndex = 0; iIndex < vecAllTransInfo.size(); iIndex++) - { - if (vecAllTransInfo[iIndex].vecValue.size() != iBestLen) - { - continue; - } - - std::string strValueTemp; - for (int j = 0; j < iBestLen; j++) - { - strValueTemp += vecAllTransInfo[iIndex].vecValue[j]; - if (transInfoBest.vecScore[j] < vecAllTransInfo[iIndex].vecScore[j]) - { - transInfoBest.vecScore[j] = vecAllTransInfo[iIndex].vecScore[j]; - transInfoBest.vecValue[j] = vecAllTransInfo[iIndex].vecValue[j]; - } - } - - if (mapResult.find(strValueTemp) != mapResult.end()) - { - mapResult[strValueTemp]++; - } - else - { - mapResult[strValueTemp] = 1; - } - } - - //按字符最高得分汇总结果 - for (size_t i = 0; i < transInfoBest.vecValue.size(); ++i) - { - strValue += transInfoBest.vecValue[i]; - } - - //按出现次数汇总结果 - int iMaxCnt = 0; - std::string strValue2; - for (auto iter = mapResult.begin(); iter != mapResult.end(); iter++) - { - if (iter->second > iMaxCnt) - { - iMaxCnt = iter->second; - strValue2 = iter->first; - } - } - - //最高得分汇总和最高次数汇总不相等,且识别同一结果次数大于等于3次,则使用按次数汇总结果。 - if (strValue != strValue2) - { - LogWarn << "engineId:" << engineId_ << " value1:" << strValue << " value2:" << strValue2 - << " not equal value2cnt:" << iMaxCnt; - if (iMaxCnt >= 3) - { - strValue = strValue2; - } - } - - return strValue; -} - -/** -* 车号数据加入到待选优集合中 -* inParam : std::shared_ptr pProcessData :处理帧数据 - : TransSubData &transSubData :转换后子数据 -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::NumAddSelectBestMap(std::shared_ptr pProcessData, TransSubData &transSubData) -{ - for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) - { - TransInfo transInfo = transSubData.vecTransInfo[i]; - mapNumInfo_[transInfo.iLine].emplace_back(transInfo); - } - - //记录车厢类型ID - if (mapTrainTypeId_.find(transSubData.iBigClassId) != mapTrainTypeId_.end()) - { - mapTrainTypeId_[transSubData.iBigClassId]++; - } - else - { - mapTrainTypeId_[transSubData.iBigClassId] = 1; - } - - //最高分和最优帧号 - if (fMaxScoreSumNum_ < transSubData.fScoreSum) - { - fMaxScoreSumNum_ = transSubData.fScoreSum; - strBestNumImg_ = std::to_string(pProcessData->iFrameId) + ".jpg"; - i64TimeStampNum_ = pProcessData->i64TimeStamp; - step1LocationBestNum_ = transSubData.step1Location; - iDataSourceNum_ = pProcessData->iDataSource; - } -} - -/** -* 属性数据加入到待选优集合中 -* inParam : std::shared_ptr pProcessData :处理帧数据 - : TransSubData &transSubData :转换后子数据 -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::ProAddSelectBestMap(std::shared_ptr pProcessData, TransSubData &transSubData) -{ - for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) - { - TransInfo transInfo = transSubData.vecTransInfo[i]; - mapProInfo_[transInfo.iLine].emplace_back(transInfo); - } - - //最高分和最优帧号 - if (fMaxScoreSumPro_ < transSubData.fScoreSum) - { - fMaxScoreSumPro_ = transSubData.fScoreSum; - strBestProImg_ = std::to_string(pProcessData->iFrameId) + ".jpg"; - i64TimeStampPro_ = pProcessData->i64TimeStamp; - step1LocationBestPro_ = transSubData.step1Location; - iDataSourcePro_ = pProcessData->iDataSource; - } -} - -/** -* 车头数据加入到待选优集合中 -* inParam : std::shared_ptr pProcessData :处理帧数据 - : TransSubData &transSubData :转换后子数据 -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::HeadAddSelectBestMap(std::shared_ptr pProcessData, TransSubData &transSubData) -{ - for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) - { - TransInfo transInfo = transSubData.vecTransInfo[i]; - mapHeadInfo_[transInfo.iLine].emplace_back(transInfo); - } - - //记录车头大框识别次数 - auto iter = mapTrainTypeId_.find(0); - if (iter == mapTrainTypeId_.end()) - { - mapTrainTypeId_.insert(std::make_pair(0, 1)); - } - else - { - iter->second++; - } - - //最高分和最优帧号 - if (fMaxScoreSumHead_ < transSubData.fScoreSum) - { - fMaxScoreSumHead_ = transSubData.fScoreSum; - strBestHeadImg_ = std::to_string(pProcessData->iFrameId) + ".jpg"; - i64TimeStampHead_ = pProcessData->i64TimeStamp; - step1LocationBestHead_ = transSubData.step1Location; - iDataSourceHead_ = pProcessData->iDataSource; - } -} - -/** -* 汇总车头最佳值 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -bool SelectBestEngine::GetHeadBest(std::shared_ptr pProcessData) -{ - //2.无识别车头信息,不汇总 - if (mapHeadInfo_.empty()) - { - LogDebug << "engineId:" << engineId_ << " no head info"; - return false; - } - - std::shared_ptr pTrain = std::make_shared(); - pTrain->trainNum.iDataSource = iDataSourceHead_; - pTrain->trainNum.bIsEnd = pProcessData->bIsEnd; - pTrain->trainNum.strTrainDate = pProcessData->strTrainDate; - pTrain->trainNum.strTrainName = pProcessData->strTrainName; - pTrain->trainNum.iDirection = pProcessData->iDirection; - - //车头型号 - if (mapHeadInfo_.find(0) != mapHeadInfo_.end()) - { - pTrain->trainNum.strTrainType = GetBest(mapHeadInfo_.at(0), TYPE_MAXLEN); - } - - //车头编号 - if (mapHeadInfo_.find(1) != mapHeadInfo_.end()) - { - pTrain->trainNum.strTrainNum = GetBest(mapHeadInfo_.at(1), NUM_MAXLEN); - } - - pTrain->trainNum.strBestImg = strBestHeadImg_; - pTrain->trainNum.iCarXH = 0; - pTrain->trainNum.step1Location = step1LocationBestHead_; - pTrain->trainNum.i64TimeStamp = i64TimeStampHead_; - pTrain->trainNum.iTrainTypeId = 0; //车头 - - - //push端口1,车头属性 - pTrain->trainPro.iDataSource = iDataSourceHead_; - pTrain->trainPro.bIsEnd = pProcessData->bIsEnd; - pTrain->trainPro.strTrainDate = pProcessData->strTrainDate; - pTrain->trainPro.strTrainName = pProcessData->strTrainName; - pTrain->trainPro.iDirection = pProcessData->iDirection; - pTrain->trainPro.iCarXH = 0; - - pTrain->strTrainDate = pTrain->trainNum.strTrainDate; - pTrain->strTrainName = pTrain->trainNum.strTrainName; - pTrain->iDirection = pTrain->trainNum.iDirection; - pTrain->iDataSource = pTrain->trainNum.iDataSource >= pTrain->trainPro.iDataSource ? pTrain->trainNum.iDataSource : pTrain->trainPro.iDataSource; - - LogInfo << "\n ---汇总结果--- \n" - << "日期时间: " << pTrain->strTrainDate << " " << pTrain->strTrainName << "\n" - << "车厢序号: " << pTrain->iCarXH << "\n" - << "车型Id: " << pTrain->trainNum.iTrainTypeId << "\n" - << "车型: " << pTrain->trainNum.strTrainType << "\n" - << "车号: " << pTrain->trainNum.strTrainNum << "\n" - << "载重: " << pTrain->trainPro.strLoad << "\n" - << "自重: " << pTrain->trainPro.strSelf << "\n" - << "容积: " << pTrain->trainPro.strVolume << "\n" - << "换长: " << pTrain->trainPro.strChange << "\n" - << "容量记表: " << pTrain->trainPro.strVolumeSurface << "\n" - << "编号图片: " << pTrain->trainNum.strBestImg << "\n" - << "属性图片: " << pTrain->trainPro.strBestImg << "\n" - << "行驶方向: " << pTrain->iDirection << "\n" - << " ---汇总结果 END--- "; - - //拷贝最优图片到最优路径下 - CopyBestImgToBestPath(pTrain); - - std::shared_ptr pTrainToCsv = std::make_shared(); - *pTrainToCsv = *pTrain; - PushData(strPort0_, pTrain); - PushData(strPort1_, pTrainToCsv); - return true; -} - -/** -* 汇总车号最佳值 -* inParam : std::shared_ptr pProcessData -* outParam: TrainNum &trainNum -* return : N/A -*/ -void SelectBestEngine::GetNumBest(TrainNum &trainNum, std::shared_ptr pProcessData) -{ - trainNum.iDataSource = iDataSourceNum_; - trainNum.bIsEnd = pProcessData->bIsEnd; - trainNum.strTrainDate = pProcessData->strTrainDate; - trainNum.strTrainName = pProcessData->strTrainName; - trainNum.iDirection = pProcessData->iDirection; - trainNum.iCarXH = pProcessData->iTrainIndex; - - //车型 - if (mapNumInfo_.find(0) != mapNumInfo_.end()) - { - trainNum.strTrainType = GetBest(mapNumInfo_.at(0), TYPE_MAXLEN); - } - //编号 - if (mapNumInfo_.find(1) != mapNumInfo_.end()) - { - trainNum.strTrainNum = GetBest(mapNumInfo_.at(1), NUM_MAXLEN); - } - - //按出现次数选车厢类型ID - int iMaxCnt = 0; - for (auto iter = mapTrainTypeId_.begin(); iter != mapTrainTypeId_.end(); iter++) - { - if (iter->second > iMaxCnt) - { - iMaxCnt = iter->second; - trainNum.iTrainTypeId = iter->first; - } - } - - trainNum.strBestImg = strBestNumImg_; - trainNum.fScoreSum = fMaxScoreSumNum_; - trainNum.iCarXH = iNumIndex_++; - trainNum.step1Location = step1LocationBestNum_; - trainNum.i64TimeStamp = i64TimeStampNum_; - //初始化车号信息 - InitNumParam(); -} - -/** -* 汇总属性最佳值 -* inParam : std::shared_ptr pProcessData -* outParam: TrainPro &trainPro -* return : N/A -*/ -void SelectBestEngine::GetProBest(TrainPro &trainPro, std::shared_ptr pProcessData) -{ - trainPro.iDataSource = iDataSourcePro_; - trainPro.bIsEnd = pProcessData->bIsEnd; - trainPro.strTrainDate = pProcessData->strTrainDate; - trainPro.strTrainName = pProcessData->strTrainName; - trainPro.iDirection = pProcessData->iDirection; - trainPro.iCarXH = pProcessData->iTrainIndex; - - //载重 - if (mapProInfo_.find(0) != mapProInfo_.end()) - { - trainPro.strLoad = GetBest(mapProInfo_.at(0), LOAD_MAXLEN); - } - //自重 - if (mapProInfo_.find(1) != mapProInfo_.end()) - { - trainPro.strSelf = GetBest(mapProInfo_.at(1), SELF_MAXLEN); - if (trainPro.strSelf.length() == 3) - { - trainPro.strSelf = trainPro.strSelf.substr(0, 2) + "." + trainPro.strSelf.substr(2, 1); - } - } - //容积 - if (mapProInfo_.find(2) != mapProInfo_.end()) - { - trainPro.strVolume = GetBest(mapProInfo_.at(2), VOLUME_MAXLEN); - //棚车容器一般为1开头得三位整数,因此不需要额外补小数点处理。 - if (trainPro.strVolume.length() == 3 && trainPro.strVolume.substr(0, 1) != "1") - { - trainPro.strVolume = trainPro.strVolume.substr(0, 2) + "." + trainPro.strVolume.substr(2, 1); - } - } - - //换长 - if (mapProInfo_.find(3) != mapProInfo_.end()) - { - trainPro.strChange = GetBest(mapProInfo_.at(3), CHANGE_MAXLEN); - if (trainPro.strChange.length() == 1) - { - if (trainPro.strChange.at(0) != '1') - { - trainPro.strChange = "1." + trainPro.strChange; - } - } - else if (trainPro.strChange.length() == 2) - { - trainPro.strChange = trainPro.strChange.substr(0, 1) + "." + trainPro.strChange.substr(1, 1); - } - } - - //罐车容量记表 - if (mapProInfo_.find(4) != mapProInfo_.end()) - { - trainPro.strVolumeSurface = GetBest(mapProInfo_.at(4), VOLUMESURFACE_MAXLEN); - } - - trainPro.strBestImg = strBestProImg_; - trainPro.fScoreSum = fMaxScoreSumPro_; - trainPro.iCarXH = iProIndex_++; - trainPro.step1Location = step1LocationBestPro_; - trainPro.i64TimeStamp = i64TimeStampPro_; - //初始化属性信息 - InitProParam(); -} - -/** -* 拷贝最优图片到最优路径下 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::CopyBestImgToBestPath(const std::shared_ptr &pTrain) -{ - //拷贝最优图片到最优路径下 - if (!pTrain->trainNum.strBestImg.empty()) - { - char szCameraNo[6] = {0}; //车号最优图片路径 - sprintf(szCameraNo, "/%03d/", pTrain->trainNum.iDataSource + 1); - std::string strDes = strBestPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo; - if (!MyUtils::getins()->CreateDirPath(strDes)) - { - LogError << "engineId:" << engineId_ << " CreateDirPath err strDes:" << strDes; - return; - } - - std::string strSrc = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo + pTrain->trainNum.strBestImg; - strDes += pTrain->trainNum.strBestImg; - MyUtils::getins()->copyFile(strSrc, strDes); - } - if (!pTrain->trainPro.strBestImg.empty()) - { - char szCameraNo[6] = {0}; //车号最优图片路径 - sprintf(szCameraNo, "/%03d/", pTrain->trainPro.iDataSource + 1); - std::string strDes = strBestPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo; - if (!MyUtils::getins()->CreateDirPath(strDes)) - { - LogError << "engineId:" << engineId_ << " CreateDirPath err strDes:" << strDes; - return; - } - std::string strSrc = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo + pTrain->trainPro.strBestImg; - strDes += pTrain->trainPro.strBestImg; - MyUtils::getins()->copyFile(strSrc, strDes); - } -} - - -/** -* 汇总车厢最佳值 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void SelectBestEngine::GetTrainBest(std::shared_ptr pProcessData) -{ - std::shared_ptr pTrain = std::make_shared(); - //1.汇总车号信息 - GetNumBest(pTrain->trainNum, pProcessData); - - //2.汇总属性信息 - GetProBest(pTrain->trainPro, pProcessData); - - /*按车型删除误识别的属性 - 1.非罐车删除容量计表 - 2.平车删除容积 - */ - if (pTrain->trainNum.iTrainTypeId != 5 && pTrain->trainNum.iTrainTypeId != -1) - { - pTrain->trainPro.strVolumeSurface = ""; - } - if (pTrain->trainNum.iTrainTypeId == 6) - { - pTrain->trainPro.strVolume = ""; - } - - pTrain->strTrainDate = pTrain->trainNum.strTrainDate; - pTrain->strTrainName = pTrain->trainNum.strTrainName; - pTrain->iDirection = pTrain->trainNum.iDirection; - pTrain->iCarXH = pTrain->trainNum.iCarXH; - pTrain->iDataSource = pTrain->trainNum.iDataSource >= pTrain->trainPro.iDataSource ? pTrain->trainNum.iDataSource : pTrain->trainPro.iDataSource; - - LogInfo << "\n ---汇总结果--- \n" - << "日期时间: " << pTrain->strTrainDate << " " << pTrain->strTrainName << "\n" - << "车厢序号: " << pTrain->iCarXH << "\n" - << "车型Id: " << pTrain->trainNum.iTrainTypeId << "\n" - << "车型: " << pTrain->trainNum.strTrainType << "\n" - << "车号: " << pTrain->trainNum.strTrainNum << "\n" - << "载重: " << pTrain->trainPro.strLoad << "\n" - << "自重: " << pTrain->trainPro.strSelf << "\n" - << "容积: " << pTrain->trainPro.strVolume << "\n" - << "换长: " << pTrain->trainPro.strChange << "\n" - << "容量记表: " << pTrain->trainPro.strVolumeSurface << "\n" - << "编号图片: " << pTrain->trainNum.strBestImg << "\n" - << "属性图片: " << pTrain->trainPro.strBestImg << "\n" - << "行驶方向: " << pTrain->iDirection << "\n" - << " ---汇总结果 END--- "; - - //拷贝最优图片到最优路径下 - CopyBestImgToBestPath(pTrain); - - std::shared_ptr pTrainToCsv = std::make_shared(); - *pTrainToCsv = *pTrain; - PushData(strPort0_, pTrain); - PushData(strPort1_, pTrainToCsv); -} - -APP_ERROR SelectBestEngine::Process() -{ - int iRet = APP_ERR_OK; - while (!isStop_) - { - //pop端口0 - std::shared_ptr pVoidData0 = nullptr; - iRet = inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); - continue; - } - - std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); - std::shared_ptr pTransData = std::static_pointer_cast(pProcessData->pVoidData); - if (pProcessData->bIsEnd) - { - mapDataSourceIsEnd_[pProcessData->iDataSource] = pProcessData->bIsEnd; - } - - for (size_t i = 0; i < pTransData->vecTransSubData.size(); i++) - { - TransSubData transSubData = pTransData->vecTransSubData[i]; - //车头 - if (transSubData.iBigClassId == 0) - { - //车头加入待汇总集合中 - HeadAddSelectBestMap(pProcessData, transSubData); - } - //属性 - else if (transSubData.iBigClassId == 1) - { - //属性加入待汇总集合中 - ProAddSelectBestMap(pProcessData, transSubData); - } - //车号 - else if (transSubData.iBigClassId >= 2 && transSubData.iBigClassId <= 6) - { - //车号加入待汇总集合中 - NumAddSelectBestMap(pProcessData, transSubData); - } - } - - //3. 结束帧,需汇总 - bool bAllEnd = true; - for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) - { - bAllEnd = bAllEnd && iter->second; - } - - if (bAllEnd) - { - bool bHeadFlag = false; - //第一节或最后一节汇总车头 - //(注:针对2个车头的场景,除判断第一节和最后一节外,额外增加车头的次数,当车头大框次数大于3次时,则认为车头。因此后续第一个节和最后一节的条件可以删除) - if (pProcessData->iTrainIndex == 1 || pProcessData->bIsTrainEnd || - (mapTrainTypeId_.find(0) != mapTrainTypeId_.end() && (mapTrainTypeId_[0] >= 2 || mapTrainTypeId_.size() == 1))) - { - bHeadFlag = GetHeadBest(pProcessData); - } - - //汇总车厢 车号和属性 - if (!bHeadFlag) - { - GetTrainBest(pProcessData); - } - - //初始化参数变量 - InitParam(); - } - } - return APP_ERR_OK; -} +#include "SelectBestEngine.h" #include "myutils.h" using namespace ai_matrix; SelectBestEngine::SelectBestEngine() {} SelectBestEngine::~SelectBestEngine() {} APP_ERROR SelectBestEngine::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; iSelectBestMode_ = MyYaml::GetIns()->GetIntValue("gc_select_best_mode"); strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); strBestPath_ = MyYaml::GetIns()->GetPathValue("gc_best_path"); //获取几个摄像头识别车号 std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) { if (iter->second.strTarget.find("NUM") != std::string::npos) { mapDataSourceIsEnd_[iter->first] = false; } } InitParam(); LogInfo << "SelectBestEngine Init ok"; return APP_ERR_OK; } APP_ERROR SelectBestEngine::DeInit() { LogInfo << "SelectBestEngine DeInit ok"; return APP_ERR_OK; } /** * push数据到队列,队列满时则休眠一段时间再push * inParam : const std::string strPort push的端口 : const std::shared_ptr &pTrain push的数据 * outParam: N/A * return : N/A */ void SelectBestEngine::PushData(const std::string &strPort, const std::shared_ptr &pTrain) { while (true) { int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pTrain)); if (iRet != 0) { LogDebug << "num:" << pTrain->trainNum.strTrainNum << " push fail iRet:" << iRet; if (iRet == 2) { usleep(10000); // 10ms continue; } } break; } } /** * 初始化车号参数信息 * inParam : N/A * outParam: N/A * return : N/A */ void SelectBestEngine::InitNumParam() { mapTrainTypeId_.clear(); mapNumInfo_.clear(); strBestNumImg_ = ""; i64TimeStampNum_ = 0; fMaxScoreSumNum_ = 0; memset(&step1LocationBestNum_, 0, sizeof(step1LocationBestNum_)); iDataSourceNum_ = 0; } /** * 初始化属性参数信息 * inParam : N/A * outParam: N/A * return : N/A */ void SelectBestEngine::InitProParam() { mapProInfo_.clear(); strBestProImg_ = ""; i64TimeStampPro_ = 0; fMaxScoreSumPro_ = 0; memset(&step1LocationBestPro_, 0, sizeof(step1LocationBestPro_)); iDataSourcePro_ = 0; } /** * 初始化车号参数信息(只有车结束调用) * inParam : N/A * outParam: N/A * return : N/A */ void SelectBestEngine::InitHeadParam() { mapHeadInfo_.clear(); strBestHeadImg_ = ""; i64TimeStampHead_ = 0; fMaxScoreSumHead_ = 0; memset(&step1LocationBestHead_, 0, sizeof(step1LocationBestHead_)); iDataSourceHead_ = 0; } /** * 初始化参数信息 * inParam : N/A * outParam: N/A * return : N/A */ void SelectBestEngine::InitParam() { iNumIndex_ = 1; iProIndex_ = 1; InitNumParam(); InitProParam(); InitHeadParam(); for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) { iter->second = false; } } /** * 获取最优长度 * inParam : std::vector &vecAllTransInfo 待汇总取优的结果集 * : TargetMaxLen iMaxLen 目标最大长度 * outParam: N/A * return : 最优长度 */ int SelectBestEngine::GetBestLength(std::vector &vecAllTransInfo, TargetMaxLen iMaxLen) { //1.获取结果中每种长度出现的次数 std::map mapResultSize; for (size_t i = 0; i < vecAllTransInfo.size(); i++) { int iNowSize = vecAllTransInfo[i].vecValue.size(); if (mapResultSize.find(iNowSize) != mapResultSize.end()) { mapResultSize[iNowSize]++; continue; } mapResultSize[iNowSize] = 1; } int iBestLen = 0; //2.获取最优长度 if (iSelectBestMode_ == FREQUENCY) { //2.1 按长度出现的频次最多,作为最优长度 int iCnt = 0; for (auto it = mapResultSize.begin(); it != mapResultSize.end(); it++) { if (iCnt < it->second && it->first <= iMaxLen) { iCnt = it->second; iBestLen = it->first; } } } else if (iSelectBestMode_ == LENGTH) { //2.2 按最长长度且不能大于最大长度,作为最优长度 for (auto rit = mapResultSize.rbegin(); rit != mapResultSize.rend(); rit++) { if (rit->first <= iMaxLen) { iBestLen = rit->first; break; } } } return iBestLen; } /** * 获取最优结果 * inParam : std::vector &vecAllTransInfo 待汇总取优的结果集 * : TargetMaxLen iMaxLen 目标最大长度 * outParam: N/A * return : 最优结果 */ std::string SelectBestEngine::GetBest(std::vector &vecAllTransInfo, TargetMaxLen iMaxLen) { std::string strValue = ""; if (vecAllTransInfo.size() <= 0) { LogInfo << "<<< --- 没数据 --- >>>"; return strValue; } //优先使用校验通过的数据选优。 std::vector vecTransInfoTemp; for (size_t i = 0; i < vecAllTransInfo.size(); i++) { TransInfo transInfo = vecAllTransInfo[i]; if (transInfo.IsChkFlag) { vecTransInfoTemp.emplace_back(transInfo); } } if (vecTransInfoTemp.size() > 0) { vecAllTransInfo = vecTransInfoTemp; } else { // LogInfo << "--->>> 没有符合正则的??"; // 此处因车厢太脏。识别效果很差,难以与RFID识别结果融合,所以增加eles return strValue; } //获取最优长度 int iBestLen = GetBestLength(vecAllTransInfo, iMaxLen); // LogInfo << "--->>> 最优长度:" << iBestLen; //初始化最优结果 TransInfo transInfoBest; transInfoBest.vecScore.reserve(iBestLen); transInfoBest.vecValue.reserve(iBestLen); for (int i = 0; i < iBestLen; i++) { transInfoBest.vecScore.emplace_back(0); transInfoBest.vecValue.emplace_back(""); } std::map mapResult; //符合最优长度的结果集 [key:结果; value:结果出现次数] for (size_t iIndex = 0; iIndex < vecAllTransInfo.size(); iIndex++) { if (vecAllTransInfo[iIndex].vecValue.size() != iBestLen) { continue; } std::string strValueTemp; for (int j = 0; j < iBestLen; j++) { strValueTemp += vecAllTransInfo[iIndex].vecValue[j]; if (transInfoBest.vecScore[j] < vecAllTransInfo[iIndex].vecScore[j]) { transInfoBest.vecScore[j] = vecAllTransInfo[iIndex].vecScore[j]; transInfoBest.vecValue[j] = vecAllTransInfo[iIndex].vecValue[j]; } } if (mapResult.find(strValueTemp) != mapResult.end()) { mapResult[strValueTemp]++; } else { mapResult[strValueTemp] = 1; } } //按字符最高得分汇总结果 for (size_t i = 0; i < transInfoBest.vecValue.size(); ++i) { strValue += transInfoBest.vecValue[i]; } //按出现次数汇总结果 int iMaxCnt = 0; std::string strValue2; for (auto iter = mapResult.begin(); iter != mapResult.end(); iter++) { if (iter->second > iMaxCnt) { iMaxCnt = iter->second; strValue2 = iter->first; } } //最高得分汇总和最高次数汇总不相等,且识别同一结果次数大于等于3次,则使用按次数汇总结果。 if (strValue != strValue2) { LogWarn << "engineId:" << engineId_ << " value1:" << strValue << " value2:" << strValue2 << " not equal value2cnt:" << iMaxCnt; if (iMaxCnt >= 3) { strValue = strValue2; } } return strValue; } /** * 车号数据加入到待选优集合中 * inParam : std::shared_ptr pProcessData :处理帧数据 : TransSubData &transSubData :转换后子数据 * outParam: N/A * return : N/A */ void SelectBestEngine::NumAddSelectBestMap(std::shared_ptr pProcessData, TransSubData &transSubData) { for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) { TransInfo transInfo = transSubData.vecTransInfo[i]; // LogInfo << "待选优 >>> " << transInfo.vecValue[0]; mapNumInfo_[transInfo.iLine].emplace_back(transInfo); } //记录车厢类型ID if (mapTrainTypeId_.find(transSubData.iBigClassId) != mapTrainTypeId_.end()) { mapTrainTypeId_[transSubData.iBigClassId]++; } else { mapTrainTypeId_[transSubData.iBigClassId] = 1; } //最高分和最优帧号 if (fMaxScoreSumNum_ < transSubData.fScoreSum) { fMaxScoreSumNum_ = transSubData.fScoreSum; strBestNumImg_ = std::to_string(pProcessData->iFrameId) + ".jpg"; i64TimeStampNum_ = pProcessData->i64TimeStamp; step1LocationBestNum_ = transSubData.step1Location; iDataSourceNum_ = pProcessData->iDataSource; } } /** * 属性数据加入到待选优集合中 * inParam : std::shared_ptr pProcessData :处理帧数据 : TransSubData &transSubData :转换后子数据 * outParam: N/A * return : N/A */ void SelectBestEngine::ProAddSelectBestMap(std::shared_ptr pProcessData, TransSubData &transSubData) { for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) { TransInfo transInfo = transSubData.vecTransInfo[i]; mapProInfo_[transInfo.iLine].emplace_back(transInfo); } //最高分和最优帧号 if (fMaxScoreSumPro_ < transSubData.fScoreSum) { fMaxScoreSumPro_ = transSubData.fScoreSum; strBestProImg_ = std::to_string(pProcessData->iFrameId) + ".jpg"; i64TimeStampPro_ = pProcessData->i64TimeStamp; step1LocationBestPro_ = transSubData.step1Location; iDataSourcePro_ = pProcessData->iDataSource; } } /** * 车头数据加入到待选优集合中 * inParam : std::shared_ptr pProcessData :处理帧数据 : TransSubData &transSubData :转换后子数据 * outParam: N/A * return : N/A */ void SelectBestEngine::HeadAddSelectBestMap(std::shared_ptr pProcessData, TransSubData &transSubData) { for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) { TransInfo transInfo = transSubData.vecTransInfo[i]; mapHeadInfo_[transInfo.iLine].emplace_back(transInfo); } //记录车头大框识别次数 auto iter = mapTrainTypeId_.find(0); if (iter == mapTrainTypeId_.end()) { mapTrainTypeId_.insert(std::make_pair(0, 1)); } else { iter->second++; } //最高分和最优帧号 if (fMaxScoreSumHead_ < transSubData.fScoreSum) { fMaxScoreSumHead_ = transSubData.fScoreSum; strBestHeadImg_ = std::to_string(pProcessData->iFrameId) + ".jpg"; i64TimeStampHead_ = pProcessData->i64TimeStamp; step1LocationBestHead_ = transSubData.step1Location; iDataSourceHead_ = pProcessData->iDataSource; } } /** * 汇总车头最佳值 * inParam : N/A * outParam: N/A * return : N/A */ bool SelectBestEngine::GetHeadBest(std::shared_ptr pProcessData) { //2.无识别车头信息,不汇总 if (mapHeadInfo_.empty()) { LogDebug << "engineId:" << engineId_ << " no head info"; return false; } std::shared_ptr pTrain = std::make_shared(); pTrain->trainNum.iDataSource = iDataSourceHead_; pTrain->trainNum.bIsEnd = pProcessData->bIsEnd; pTrain->trainNum.strTrainDate = pProcessData->strTrainDate; pTrain->trainNum.strTrainName = pProcessData->strTrainName; pTrain->trainNum.iDirection = pProcessData->iDirection; //车头型号 if (mapHeadInfo_.find(0) != mapHeadInfo_.end()) { pTrain->trainNum.strTrainType = GetBest(mapHeadInfo_.at(0), TYPE_MAXLEN); } //车头编号 if (mapHeadInfo_.find(1) != mapHeadInfo_.end()) { pTrain->trainNum.strTrainNum = GetBest(mapHeadInfo_.at(1), NUM_MAXLEN); } pTrain->trainNum.strBestImg = strBestHeadImg_; pTrain->trainNum.iCarXH = 0; pTrain->trainNum.step1Location = step1LocationBestHead_; pTrain->trainNum.i64TimeStamp = i64TimeStampHead_; pTrain->trainNum.iTrainTypeId = 0; //车头 //push端口1,车头属性 pTrain->trainPro.iDataSource = iDataSourceHead_; pTrain->trainPro.bIsEnd = pProcessData->bIsEnd; pTrain->trainPro.strTrainDate = pProcessData->strTrainDate; pTrain->trainPro.strTrainName = pProcessData->strTrainName; pTrain->trainPro.iDirection = pProcessData->iDirection; pTrain->trainPro.iCarXH = 0; pTrain->strTrainDate = pTrain->trainNum.strTrainDate; pTrain->strTrainName = pTrain->trainNum.strTrainName; pTrain->iDirection = pTrain->trainNum.iDirection; pTrain->iDataSource = pTrain->trainNum.iDataSource >= pTrain->trainPro.iDataSource ? pTrain->trainNum.iDataSource : pTrain->trainPro.iDataSource; LogInfo << "\n ---汇总结果--- \n" << "日期时间: " << pTrain->strTrainDate << " " << pTrain->strTrainName << "\n" << "车厢序号: " << pTrain->iCarXH << "\n" << "车型Id: " << pTrain->trainNum.iTrainTypeId << "\n" << "车型: " << pTrain->trainNum.strTrainType << "\n" << "车号: " << pTrain->trainNum.strTrainNum << "\n" << "载重: " << pTrain->trainPro.strLoad << "\n" << "自重: " << pTrain->trainPro.strSelf << "\n" << "容积: " << pTrain->trainPro.strVolume << "\n" << "换长: " << pTrain->trainPro.strChange << "\n" << "容量记表: " << pTrain->trainPro.strVolumeSurface << "\n" << "编号图片: " << pTrain->trainNum.strBestImg << "\n" << "属性图片: " << pTrain->trainPro.strBestImg << "\n" << "行驶方向: " << pTrain->iDirection << "\n" << " ---汇总结果 END--- "; //拷贝最优图片到最优路径下 CopyBestImgToBestPath(pTrain); std::shared_ptr pTrainToCsv = std::make_shared(); *pTrainToCsv = *pTrain; PushData(strPort0_, pTrain); PushData(strPort1_, pTrainToCsv); return true; } /** * 汇总车号最佳值 * inParam : std::shared_ptr pProcessData * outParam: TrainNum &trainNum * return : N/A */ void SelectBestEngine::GetNumBest(TrainNum &trainNum, std::shared_ptr pProcessData) { trainNum.iDataSource = iDataSourceNum_; trainNum.bIsEnd = pProcessData->bIsEnd; trainNum.strTrainDate = pProcessData->strTrainDate; trainNum.strTrainName = pProcessData->strTrainName; trainNum.iDirection = pProcessData->iDirection; trainNum.iCarXH = pProcessData->iTrainIndex; //车型 if (mapNumInfo_.find(0) != mapNumInfo_.end()) { trainNum.strTrainType = GetBest(mapNumInfo_.at(0), TYPE_MAXLEN); // LogInfo << "-->>> " << trainNum.strTrainType; } //编号 if (mapNumInfo_.find(1) != mapNumInfo_.end()) { trainNum.strTrainNum = GetBest(mapNumInfo_.at(1), NUM_MAXLEN); } //按出现次数选车厢类型ID int iMaxCnt = 0; for (auto iter = mapTrainTypeId_.begin(); iter != mapTrainTypeId_.end(); iter++) { if (iter->second > iMaxCnt) { iMaxCnt = iter->second; trainNum.iTrainTypeId = iter->first; } } trainNum.strBestImg = strBestNumImg_; trainNum.fScoreSum = fMaxScoreSumNum_; trainNum.iCarXH = iNumIndex_++; trainNum.step1Location = step1LocationBestNum_; trainNum.i64TimeStamp = i64TimeStampNum_; //初始化车号信息 InitNumParam(); } /** * 汇总属性最佳值 * inParam : std::shared_ptr pProcessData * outParam: TrainPro &trainPro * return : N/A */ void SelectBestEngine::GetProBest(TrainPro &trainPro, std::shared_ptr pProcessData) { trainPro.iDataSource = iDataSourcePro_; trainPro.bIsEnd = pProcessData->bIsEnd; trainPro.strTrainDate = pProcessData->strTrainDate; trainPro.strTrainName = pProcessData->strTrainName; trainPro.iDirection = pProcessData->iDirection; trainPro.iCarXH = pProcessData->iTrainIndex; //载重 if (mapProInfo_.find(0) != mapProInfo_.end()) { trainPro.strLoad = GetBest(mapProInfo_.at(0), LOAD_MAXLEN); } //自重 if (mapProInfo_.find(1) != mapProInfo_.end()) { trainPro.strSelf = GetBest(mapProInfo_.at(1), SELF_MAXLEN); if (trainPro.strSelf.length() == 3) { trainPro.strSelf = trainPro.strSelf.substr(0, 2) + "." + trainPro.strSelf.substr(2, 1); } } //容积 if (mapProInfo_.find(2) != mapProInfo_.end()) { trainPro.strVolume = GetBest(mapProInfo_.at(2), VOLUME_MAXLEN); //棚车容器一般为1开头得三位整数,因此不需要额外补小数点处理。 if (trainPro.strVolume.length() == 3 && trainPro.strVolume.substr(0, 1) != "1") { trainPro.strVolume = trainPro.strVolume.substr(0, 2) + "." + trainPro.strVolume.substr(2, 1); } } //换长 if (mapProInfo_.find(3) != mapProInfo_.end()) { trainPro.strChange = GetBest(mapProInfo_.at(3), CHANGE_MAXLEN); if (trainPro.strChange.length() == 1) { if (trainPro.strChange.at(0) != '1') { trainPro.strChange = "1." + trainPro.strChange; } } else if (trainPro.strChange.length() == 2) { trainPro.strChange = trainPro.strChange.substr(0, 1) + "." + trainPro.strChange.substr(1, 1); } } //罐车容量记表 if (mapProInfo_.find(4) != mapProInfo_.end()) { trainPro.strVolumeSurface = GetBest(mapProInfo_.at(4), VOLUMESURFACE_MAXLEN); } trainPro.strBestImg = strBestProImg_; trainPro.fScoreSum = fMaxScoreSumPro_; trainPro.iCarXH = iProIndex_++; trainPro.step1Location = step1LocationBestPro_; trainPro.i64TimeStamp = i64TimeStampPro_; //初始化属性信息 InitProParam(); } /** * 拷贝最优图片到最优路径下 * inParam : N/A * outParam: N/A * return : N/A */ void SelectBestEngine::CopyBestImgToBestPath(const std::shared_ptr &pTrain) { //拷贝最优图片到最优路径下 if (!pTrain->trainNum.strBestImg.empty()) { char szCameraNo[6] = {0}; //车号最优图片路径 sprintf(szCameraNo, "/%03d/", pTrain->trainNum.iDataSource + 1); std::string strDes = strBestPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo; if (!MyUtils::getins()->CreateDirPath(strDes)) { LogError << "engineId:" << engineId_ << " CreateDirPath err strDes:" << strDes; return; } std::string strSrc = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo + pTrain->trainNum.strBestImg; strDes += pTrain->trainNum.strBestImg; MyUtils::getins()->copyFile(strSrc, strDes); } if (!pTrain->trainPro.strBestImg.empty()) { char szCameraNo[6] = {0}; //车号最优图片路径 sprintf(szCameraNo, "/%03d/", pTrain->trainPro.iDataSource + 1); std::string strDes = strBestPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo; if (!MyUtils::getins()->CreateDirPath(strDes)) { LogError << "engineId:" << engineId_ << " CreateDirPath err strDes:" << strDes; return; } std::string strSrc = strResultPath_ + pTrain->strTrainDate + "/" + pTrain->strTrainName + szCameraNo + pTrain->trainPro.strBestImg; strDes += pTrain->trainPro.strBestImg; MyUtils::getins()->copyFile(strSrc, strDes); } } /** * 汇总车厢最佳值 * inParam : N/A * outParam: N/A * return : N/A */ void SelectBestEngine::GetTrainBest(std::shared_ptr pProcessData) { std::shared_ptr pTrain = std::make_shared(); //1.汇总车号信息 GetNumBest(pTrain->trainNum, pProcessData); //2.汇总属性信息 GetProBest(pTrain->trainPro, pProcessData); /*按车型删除误识别的属性 1.非罐车删除容量计表 2.平车删除容积 */ if (pTrain->trainNum.iTrainTypeId != 5 && pTrain->trainNum.iTrainTypeId != -1) { pTrain->trainPro.strVolumeSurface = ""; } if (pTrain->trainNum.iTrainTypeId == 6) { pTrain->trainPro.strVolume = ""; } pTrain->strTrainDate = pTrain->trainNum.strTrainDate; pTrain->strTrainName = pTrain->trainNum.strTrainName; pTrain->iDirection = pTrain->trainNum.iDirection; pTrain->iCarXH = pTrain->trainNum.iCarXH; pTrain->iDataSource = pTrain->trainNum.iDataSource >= pTrain->trainPro.iDataSource ? pTrain->trainNum.iDataSource : pTrain->trainPro.iDataSource; LogInfo << "\n ---汇总结果--- \n" << "日期时间: " << pTrain->strTrainDate << " " << pTrain->strTrainName << "\n" << "车厢序号: " << pTrain->iCarXH << "\n" << "车型Id: " << pTrain->trainNum.iTrainTypeId << "\n" << "车型: " << pTrain->trainNum.strTrainType << "\n" << "车号: " << pTrain->trainNum.strTrainNum << "\n" << "载重: " << pTrain->trainPro.strLoad << "\n" << "自重: " << pTrain->trainPro.strSelf << "\n" << "容积: " << pTrain->trainPro.strVolume << "\n" << "换长: " << pTrain->trainPro.strChange << "\n" << "容量记表: " << pTrain->trainPro.strVolumeSurface << "\n" << "编号图片: " << pTrain->trainNum.strBestImg << "\n" << "属性图片: " << pTrain->trainPro.strBestImg << "\n" << "行驶方向: " << pTrain->iDirection << "\n" << " ---汇总结果 END--- "; //拷贝最优图片到最优路径下 CopyBestImgToBestPath(pTrain); std::shared_ptr pTrainToCsv = std::make_shared(); *pTrainToCsv = *pTrain; PushData(strPort0_, pTrain); PushData(strPort1_, pTrainToCsv); } APP_ERROR SelectBestEngine::Process() { int iRet = APP_ERR_OK; while (!isStop_) { //pop端口0 std::shared_ptr pVoidData0 = nullptr; iRet = inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); continue; } std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); std::shared_ptr pTransData = std::static_pointer_cast(pProcessData->pVoidData); if (pProcessData->bIsEnd) { mapDataSourceIsEnd_[pProcessData->iDataSource] = pProcessData->bIsEnd; } for (size_t i = 0; i < pTransData->vecTransSubData.size(); i++) { TransSubData transSubData = pTransData->vecTransSubData[i]; //车头 if (transSubData.iBigClassId == 0) { //车头加入待汇总集合中 HeadAddSelectBestMap(pProcessData, transSubData); } //属性 else if (transSubData.iBigClassId == 1) { //属性加入待汇总集合中 ProAddSelectBestMap(pProcessData, transSubData); } //车号 else if (transSubData.iBigClassId >= 2 && transSubData.iBigClassId <= 6) { //车号加入待汇总集合中 NumAddSelectBestMap(pProcessData, transSubData); } } //3. 结束帧,需汇总 bool bAllEnd = true; for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) { bAllEnd = bAllEnd && iter->second; } if (bAllEnd) { bool bHeadFlag = false; //第一节或最后一节汇总车头 //(注:针对2个车头的场景,除判断第一节和最后一节外,额外增加车头的次数,当车头大框次数大于3次时,则认为车头。因此后续第一个节和最后一节的条件可以删除) if (pProcessData->iTrainIndex == 1 || pProcessData->bIsTrainEnd || (mapTrainTypeId_.find(0) != mapTrainTypeId_.end() && (mapTrainTypeId_[0] >= 2 || mapTrainTypeId_.size() == 1))) { bHeadFlag = GetHeadBest(pProcessData); } //汇总车厢 车号和属性 if (!bHeadFlag) { GetTrainBest(pProcessData); } //初始化参数变量 InitParam(); } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/SocketEngine/SocketEngine.cpp b/nvidia_ascend_engine/common_engine/SocketEngine/SocketEngine.cpp index 9577ba8..07348d7 100644 --- a/nvidia_ascend_engine/common_engine/SocketEngine/SocketEngine.cpp +++ b/nvidia_ascend_engine/common_engine/SocketEngine/SocketEngine.cpp @@ -1,279 +1,279 @@ -#include "SocketEngine.h" +#include "SocketEngine.h" SocketEngine::SocketEngine() { - isStop_ = false; + isStop_ = false; } SocketEngine::~SocketEngine() {} APP_ERROR SocketEngine::Init() { - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; + strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - this->socketOpenType_ = MyYaml::GetIns()->GetIntValue("socket_server_open"); - this->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port"); - this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len"); + this->socketOpenType_ = MyYaml::GetIns()->GetIntValue("socket_server_open"); + this->socketPort_ = MyYaml::GetIns()->GetIntValue("socket_server_port"); + this->socketQueueLen_ = MyYaml::GetIns()->GetIntValue("socket_server_queue_len"); - MyShellInfo << "SocketEngine init ok"; - return APP_ERR_OK; + MyShellInfo << "SocketEngine init ok"; + return APP_ERR_OK; } APP_ERROR SocketEngine::DeInit() { - for (int fd = 0; fd <= max_fd; ++fd) - { - if (FD_ISSET(fd, &master_set)) - { - close(fd); - } - } + for (int fd = 0; fd <= max_fd; ++fd) + { + if (FD_ISSET(fd, &master_set)) + { + close(fd); + } + } - MyShellInfo << "SocketEngine deinit ok"; - return APP_ERR_OK; + MyShellInfo << "SocketEngine deinit ok"; + return APP_ERR_OK; } APP_ERROR SocketEngine::Process() { - int ret = APP_ERR_OK; + int ret = APP_ERR_OK; - if (this->socketOpenType_) - { - while (!isStop_) - { - if (!this->Socket_(this->socketPort_)) continue; - if (!this->Bind()) continue; - this->Listen(this->socketQueueLen_); - this->Run(); - } + if (this->socketOpenType_) + { + while (!isStop_) + { + if (!this->Socket_(this->socketPort_)) continue; + if (!this->Bind()) continue; + this->Listen(this->socketQueueLen_); + this->Run(); + } - } - else - { - while (!isStop_) - { - usleep(1000); - } - } + } + else + { + while (!isStop_) + { + usleep(1000); + } + } - return APP_ERR_OK; + return APP_ERR_OK; } bool SocketEngine::Socket_(int port) { - bzero(&server_addr, sizeof(server_addr)); - server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = htons(INADDR_ANY); - server_addr.sin_port = htons(port); - // create socket to listen - listen_fd = socket(PF_INET, SOCK_STREAM, 0); - if (listen_fd < 0) - { - LogError << "Create Scoket_Server Failed!"; - return false; - } - int opt = 1; - setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); - return true; + bzero(&server_addr, sizeof(server_addr)); + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = htons(INADDR_ANY); + server_addr.sin_port = htons(port); + // create socket to listen + listen_fd = socket(PF_INET, SOCK_STREAM, 0); + if (listen_fd < 0) + { + LogError << "Create Scoket_Server Failed!"; + return false; + } + int opt = 1; + setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); + return true; } bool SocketEngine::Bind() { - if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)))) - { - LogError << "Scoket_Server Bind Failed!"; - return false; - } - LogInfo << "Scoket_Server Bind Successfully."; - return true; + if (-1 == (bind(listen_fd, (struct sockaddr*)&server_addr, sizeof(server_addr)))) + { + LogError << "Scoket_Server Bind Failed!"; + return false; + } + LogInfo << "Scoket_Server Bind Successfully."; + return true; } bool SocketEngine::Listen(int queue_len) { - if (-1 == listen(listen_fd, queue_len)) - { - LogError << "Scoket_Server Listen Failed!"; - return false; - } - LogInfo << "Scoket_Server Listen Successfully."; - return true; + if (-1 == listen(listen_fd, queue_len)) + { + LogError << "Scoket_Server Listen Failed!"; + return false; + } + LogInfo << "Scoket_Server Listen Successfully."; + return true; } bool SocketEngine::Accept() { - struct sockaddr_in client_addr; - socklen_t client_addr_len = sizeof(client_addr); + struct sockaddr_in client_addr; + socklen_t client_addr_len = sizeof(client_addr); - int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len); - if (new_fd < 0) - { - LogError << "Scoket_Server Accept Failed!"; - return false; - } + int new_fd = accept(listen_fd, (struct sockaddr*)&client_addr, &client_addr_len); + if (new_fd < 0) + { + LogError << "Scoket_Server Accept Failed!"; + return false; + } - std::string ip(inet_ntoa(client_addr.sin_addr)); // 获取客户端IP + std::string ip(inet_ntoa(client_addr.sin_addr)); // 获取客户端IP - LogInfo << ip << " new connection was accepted."; + LogInfo << ip << " new connection was accepted."; - mmap.insert(std::make_pair(new_fd, std::make_pair(ip, 0))); + mmap.insert(std::make_pair(new_fd, std::make_pair(ip, 0))); - // 将新建立的连接的fd加入master_set - FD_SET(new_fd, &master_set); - if (new_fd > max_fd) - { - max_fd = new_fd; - } - return true; + // 将新建立的连接的fd加入master_set + FD_SET(new_fd, &master_set); + if (new_fd > max_fd) + { + max_fd = new_fd; + } + return true; } bool SocketEngine::Recv(int nums) { - for (int fd = 0; fd <= max_fd; ++fd) - { - if (FD_ISSET(fd, &working_set)) - { - bool close_conn = false; // 标记当前连接是否断开了 + for (int fd = 0; fd <= max_fd; ++fd) + { + if (FD_ISSET(fd, &working_set)) + { + bool close_conn = false; // 标记当前连接是否断开了 - char order_str[512] = { 0 }; + char order_str[512] = { 0 }; - int size_get = recv(fd, (char*)&order_str, sizeof(order_str) - 1, 0); + int size_get = recv(fd, (char*)&order_str, sizeof(order_str) - 1, 0); - if (size_get <= 0) - { - continue; - } - else - { + if (size_get <= 0) + { + continue; + } + else + { - bool isHeart_beat = (std::string(order_str) == "matrixai"); - if (isHeart_beat) - { - mmap[fd].second = 0; // 每次收到心跳包,count置0 - //LogDebug << "Scoket_Server Received heart-beat from client."; - } - else - { - LogInfo << "Received message from client:" << std::string(order_str); - } - } + bool isHeart_beat = (std::string(order_str) == "matrixai"); + if (isHeart_beat) + { + mmap[fd].second = 0; // 每次收到心跳包,count置0 + //LogDebug << "Scoket_Server Received heart-beat from client."; + } + else + { + LogInfo << "Received message from client:" << std::string(order_str); + } + } - if (close_conn) // 当前这个连接有问题,关闭它 - { - close(fd); - FD_CLR(fd, &master_set); - if (fd == max_fd) // 需要更新max_fd; - { - while (FD_ISSET(max_fd, &master_set) == false) - --max_fd; - } - } - } - } + if (close_conn) // 当前这个连接有问题,关闭它 + { + close(fd); + FD_CLR(fd, &master_set); + if (fd == max_fd) // 需要更新max_fd; + { + while (FD_ISSET(max_fd, &master_set) == false) + --max_fd; + } + } + } + } - return true; + return true; } bool SocketEngine::Run() { - pthread_t id; // 创建心跳检测线程 - int ret = pthread_create(&id, NULL, heart_handler, (void*)this); - if (ret != 0) - { - LogError << "Scoket_Server Can not create heart-beat checking thread."; - return false; - } + pthread_t id; // 创建心跳检测线程 + int ret = pthread_create(&id, NULL, heart_handler, (void*)this); + if (ret != 0) + { + LogError << "Scoket_Server Can not create heart-beat checking thread."; + return false; + } - ret = pthread_create(&id, NULL, sendInfo, (void*)this); - if (ret != 0) - { - LogError << "Scoket_Server Can not create message send thread."; - return false; - } + ret = pthread_create(&id, NULL, sendInfo, (void*)this); + if (ret != 0) + { + LogError << "Scoket_Server Can not create message send thread."; + return false; + } - max_fd = listen_fd; // 初始化max_fd - FD_ZERO(&master_set); - FD_SET(listen_fd, &master_set); // 添加监听fd + max_fd = listen_fd; // 初始化max_fd + FD_ZERO(&master_set); + FD_SET(listen_fd, &master_set); // 添加监听fd - while (!isStop_) - { - FD_ZERO(&working_set); - memcpy(&working_set, &master_set, sizeof(master_set)); + while (!isStop_) + { + FD_ZERO(&working_set); + memcpy(&working_set, &master_set, sizeof(master_set)); - timeout.tv_sec = 30; - timeout.tv_usec = 0; + timeout.tv_sec = 30; + timeout.tv_usec = 0; - int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout); - /*if (nums < 0) - { - LogError << "Scoket_Server select() error!"; - return false; - }*/ + int nums = select(max_fd + 1, &working_set, NULL, NULL, &timeout); + /*if (nums < 0) + { + LogError << "Scoket_Server select() error!"; + return false; + }*/ - if (nums <= 0) - { - //cout << "select() is timeout!"; - continue; - } + if (nums <= 0) + { + //cout << "select() is timeout!"; + continue; + } - if (FD_ISSET(listen_fd, &working_set)) - Accept(); // 有新的客户端请求 - else - Recv(nums); // 接收客户端的消息 + if (FD_ISSET(listen_fd, &working_set)) + Accept(); // 有新的客户端请求 + else + Recv(nums); // 接收客户端的消息 - } + } - return true; + return true; } //解析命令 bool SocketEngine::getOrder(const std::string &recv, Json::Value &order) { - Json::CharReaderBuilder readerBuilder; - std::shared_ptr reader(readerBuilder.newCharReader()); + Json::CharReaderBuilder readerBuilder; + std::shared_ptr reader(readerBuilder.newCharReader()); - JSONCPP_STRING errs; - if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs)) - return false; + JSONCPP_STRING errs; + if (!reader->parse(recv.data(), recv.data() + recv.size(), &order, &errs)) + return false; - if (order.isArray()) { - if (order.size() > 0) order = order[0]; - return true; - } - return true; + if (order.isArray()) { + if (order.size() > 0) order = order[0]; + return true; + } + return true; } std::string SocketEngine::getFeedBack(const std::string poundNo, const std::string type, const std::string info) { - Json::Value feedBack; - Json::StreamWriterBuilder strbuild; + Json::Value feedBack; + Json::StreamWriterBuilder strbuild; - feedBack["poundNo"] = poundNo; - feedBack["type"] = type; - feedBack["info"] = info; - // - return Json::writeString(strbuild, feedBack); + feedBack["poundNo"] = poundNo; + feedBack["type"] = type; + feedBack["info"] = info; + // + return Json::writeString(strbuild, feedBack); } void* SocketEngine::sendInfo(void* arg) { - SocketEngine* s = (SocketEngine*)arg; - while (!s->isStop_) { - //pop端口0 - std::shared_ptr pVoidData0 = nullptr; - s->inputQueMap_[s->strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } + SocketEngine* s = (SocketEngine*)arg; + while (!s->isStop_) { + //pop端口0 + std::shared_ptr pVoidData0 = nullptr; + s->inputQueMap_[s->strPort0_]->pop(pVoidData0); + if (nullptr == pVoidData0) + { + usleep(1000); //1ms + continue; + } - std::shared_ptr pMessage = std::static_pointer_cast(pVoidData0); + std::shared_ptr pMessage = std::static_pointer_cast(pVoidData0); - SendAllClient(s->mmap, *pMessage); - } + SendAllClient(s->mmap, *pMessage); + } } @@ -281,176 +281,176 @@ void* SocketEngine::sendInfo(void* arg) { // thread function void* SocketEngine::heart_handler(void* arg) { - LogInfo << "Scoket_Server The heartbeat checking thread started.\n"; - SocketEngine* s = (SocketEngine*)arg; - while (1) - { - std::map >::iterator it = s->mmap.begin(); - for (; it != s->mmap.end(); ) - { - if (it->second.second == 5) // sleep(3)*5没有收到心跳包,判定客户端掉线 - { - LogInfo << "The client " << it->second.first << " has be offline.\n"; + LogInfo << "Scoket_Server The heartbeat checking thread started.\n"; + SocketEngine* s = (SocketEngine*)arg; + while (1) + { + std::map >::iterator it = s->mmap.begin(); + for (; it != s->mmap.end(); ) + { + if (it->second.second == 5) // sleep(3)*5没有收到心跳包,判定客户端掉线 + { + LogInfo << "The client " << it->second.first << " has be offline.\n"; - int fd = it->first; - close(fd); // 关闭该连接 - FD_CLR(fd, &s->master_set); - if (fd == s->max_fd) // 需要更新max_fd; - { - while (FD_ISSET(s->max_fd, &s->master_set) == false) - s->max_fd--; - } + int fd = it->first; + close(fd); // 关闭该连接 + FD_CLR(fd, &s->master_set); + if (fd == s->max_fd) // 需要更新max_fd; + { + while (FD_ISSET(s->max_fd, &s->master_set) == false) + s->max_fd--; + } - s->mmap.erase(it++); // 从map中移除该记录 - } - else if (it->second.second < 5 && it->second.second >= 0) - { - it->second.second += 1; - ++it; - } - else - { - ++it; - } - } - sleep(3); // 定时三秒 - } + s->mmap.erase(it++); // 从map中移除该记录 + } + else if (it->second.second < 5 && it->second.second >= 0) + { + it->second.second += 1; + ++it; + } + else + { + ++it; + } + } + sleep(1); // 定时三秒 + } } bool SocketEngine::SendClient(std::map > mmap, const std::string ip, const std::string message) { - try - { - std::map >::iterator it = mmap.begin(); - for (; it != mmap.end(); ++it) - { - if (it->second.first == ip) // 遍历找雷达ip - { - int fd = it->first; + try + { + std::map >::iterator it = mmap.begin(); + for (; it != mmap.end(); ++it) + { + if (it->second.first == ip) // 遍历找雷达ip + { + int fd = it->first; - if (send(fd, message.c_str(), message.size(), 0) <= 0) - { - LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message; - return false; - } - else - { - char clientFeedBack[256] = { 0 }; - if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0) - { - Json::Value feedBack; + if (send(fd, message.c_str(), message.size(), 0) <= 0) + { + LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message; + return false; + } + else + { + char clientFeedBack[256] = { 0 }; + if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0) + { + Json::Value feedBack; - if (!getOrder(clientFeedBack, feedBack)) { - LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack; - return false; - } + if (!getOrder(clientFeedBack, feedBack)) { + LogError << "Get Client IP:" << ip << " feekBack format is error : " << clientFeedBack; + return false; + } - if (feedBack.get("success", "").asString() == "true") - { - return true; - } - else - { - LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString(); - return false; - } - } - else { + if (feedBack.get("success", "").asString() == "true") + { + return true; + } + else + { + LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString(); + return false; + } + } + else { - LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!"; - return false; - } - } - } - } - } - catch (const std::exception&) - { - LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message; - return false; - } - LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection"; - return false; + LogError << "Socker Server send message to IP:" << ip << " successful, But recv error!"; + return false; + } + } + } + } + } + catch (const std::exception&) + { + LogError << "Socker Server send message to IP:" << ip << " failed, message:" << message; + return false; + } + LogError << "Socker Server send message to IP:" << ip << " failed, because no find connection"; + return false; } bool SocketEngine::SendAllClient(std::map > mmap, const std::string message) { - try - { - std::map >::iterator it = mmap.begin(); - for (; it != mmap.end(); ++it) - { - int fd = it->first; - LogInfo << "Socket send IP: " << it->second.first << " msg:" << message; - if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0) - { - LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message; - return false; - } - else - { - // char clientFeedBack[256] = { 0 }; - // if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0) - // { - // Json::Value feedBack; + try + { + std::map >::iterator it = mmap.begin(); + for (; it != mmap.end(); ++it) + { + int fd = it->first; + LogInfo << "Socket send IP: " << it->second.first << " msg:" << message; + if (send(fd, message.c_str(), message.size(), MSG_NOSIGNAL) <= 0) + { + LogError << "Socker Server send message to IP:" << it->second.first << " failed, message:" << message; + return false; + } + else + { + // char clientFeedBack[256] = { 0 }; + // if (recv(fd, clientFeedBack, sizeof(clientFeedBack), 0) > 0) + // { + // Json::Value feedBack; - // if (!getOrder(clientFeedBack, feedBack)) { - // LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack; - // return false; - // } + // if (!getOrder(clientFeedBack, feedBack)) { + // LogError << "Get Client IP: "<< it->second.first << " feekBack format is error : " << clientFeedBack; + // return false; + // } - // if (feedBack.get("success", "").asString() == "true") - // { - // return true; - // } - // else - // { - // LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString(); - // return false; - // } - // } - // else { + // if (feedBack.get("success", "").asString() == "true") + // { + // return true; + // } + // else + // { + // LogError << "Client FeedBack Error: " << feedBack.get("error_msg", "").asString(); + // return false; + // } + // } + // else { - // LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!"; - // return false; - // } - } - } - } - catch (const std::exception&) - { - LogError << "Socker Server send message to all client failed, message:" << message; - return false; - } - return false; + // LogError << "Socker Server send message to IP:" << it->second.first << " successful, But recv error!"; + // return false; + // } + } + } + } + catch (const std::exception&) + { + LogError << "Socker Server send message to all client failed, message:" << message; + return false; + } + return false; } std::string SocketEngine::HexToStr(const std::string &str) { - std::string hex = str; - long len = hex.length(); - std::string newString; - for (long i = 0; i < len; i += 2) - { - std::string byte = hex.substr(i, 2); - char chr = (char)(int)strtol(byte.c_str(), NULL, 16); - newString.push_back(chr); - } - return newString; + std::string hex = str; + long len = hex.length(); + std::string newString; + for (long i = 0; i < len; i += 2) + { + std::string byte = hex.substr(i, 2); + char chr = (char)(int)strtol(byte.c_str(), NULL, 16); + newString.push_back(chr); + } + return newString; } std::string SocketEngine::StrToHex(const std::string &str) { - unsigned char c; - char buf[2]; - std::string result = ""; - std::stringstream ss; - ss << str; - while (ss.read((char*)(&c), sizeof(c))) - { - sprintf(buf, "%02x", c); - result += buf; - } - return result; + unsigned char c; + char buf[2]; + std::string result = ""; + std::stringstream ss; + ss << str; + while (ss.read((char*)(&c), sizeof(c))) + { + sprintf(buf, "%02x", c); + result += buf; + } + return result; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/TrainAnaEngine/PostTrainAnaEngine.cpp b/nvidia_ascend_engine/common_engine/TrainAnaEngine/PostTrainAnaEngine.cpp deleted file mode 100644 index 43281bd..0000000 --- a/nvidia_ascend_engine/common_engine/TrainAnaEngine/PostTrainAnaEngine.cpp +++ /dev/null @@ -1,118 +0,0 @@ -#include "PostTrainAnaEngine.h" - -using namespace ai_matrix; - -PostTrainAnaEngine::PostTrainAnaEngine() {} - -PostTrainAnaEngine::~PostTrainAnaEngine() {} - -APP_ERROR PostTrainAnaEngine::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); - - for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) - { - //端口0是主摄像头push存图,需给其他使用的数据源push(来车/结束)通知 - if (iter->first != 0) - { - setPushPort_.insert(iter->first); - } - else - { - dataSourceCfg_ = iter->second; - } - } - InitParam(); - LogInfo << "PostTrainAnaEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR PostTrainAnaEngine::DeInit() -{ - LogInfo << "PostTrainAnaEngine DeInit ok"; - return APP_ERR_OK; -} - - -/** -* 参数初始化(列车结束时需调用) -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void PostTrainAnaEngine::InitParam() -{ - iMoveDataNO_ = dataSourceCfg_.iSkipInterval; -} - -APP_ERROR PostTrainAnaEngine::Process() -{ - int iRet = APP_ERR_OK; - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } - - std::shared_ptr pDecodedData = std::static_pointer_cast(pVoidData0); - if (pDecodedData->iStatus == TRAINSTATUS_NO && !pDecodedData->bIsEnd) - { - continue; - } - - //组织数据, push其他端口 (只通知2次,车来一次,车结束一次) - if (iMoveDataNO_ == dataSourceCfg_.iSkipInterval || pDecodedData->bIsEnd) - { - LogDebug << "traindate:" << pDecodedData->strTrainDate << " trainname:" << pDecodedData->strTrainName - << " frameid:" << iMoveDataNO_ << " isEnd:" << pDecodedData->bIsEnd; - - uint32_t iFrameId = iMoveDataNO_ / dataSourceCfg_.iSkipInterval * dataSourceCfg_.iSkipInterval; - std::shared_ptr pMoveData = std::make_shared(); - pMoveData->iFrameId = iFrameId; //当前帧号 - pMoveData->i64TimeStamp = pDecodedData->i64TimeStamp; - pMoveData->bHasTrain = true; - pMoveData->bIsEnd = pDecodedData->bIsEnd; - pMoveData->strTrainDate = pDecodedData->strTrainDate; - pMoveData->strTrainName = pDecodedData->strTrainName; - pMoveData->iDirection = pDecodedData->iDirection; - for (auto iter = setPushPort_.begin(); iter != setPushPort_.end(); iter++) - { - outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_" + std::to_string(*iter)]->push(std::static_pointer_cast(pMoveData)); - } - outputQueMap_[engineName_ + "_" + std::to_string(engineId_) + "_5"]->push(std::static_pointer_cast(pMoveData)); - } - - //跳帧 存图 - if (iMoveDataNO_ % dataSourceCfg_.iSkipInterval == 0 || pDecodedData->bIsEnd) - { - // push端口,存图 - std::shared_ptr pSaveImgData = std::make_shared(); - pSaveImgData->pDecodeData = pDecodedData; - pSaveImgData->iFrameId = iMoveDataNO_; //帧号 - char szCameraNo[4] = {0}; - sprintf(szCameraNo, "%03d", pDecodedData->iDataSource + 1); - pSaveImgData->strImgPath = strResultPath_ + pDecodedData->strTrainDate + "/" + pDecodedData->strTrainName + "/" + szCameraNo; - pSaveImgData->strImgName = std::to_string(pSaveImgData->iFrameId) + ".jpg"; - pSaveImgData->bIsEnd = pDecodedData->bIsEnd; - pSaveImgData->bSaveToFtp = true; - pSaveImgData->i64TimeStamp = pDecodedData->i64TimeStamp; - pSaveImgData->iDirection = pDecodedData->iDirection; - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pSaveImgData)); - } - - iMoveDataNO_++; - - //结束帧或停车时需重新初始化相关信息 - if (pDecodedData->bIsEnd) - { - InitParam(); - } - } - return APP_ERR_OK; -} diff --git a/nvidia_ascend_engine/common_engine/TrainAnaEngine/PostTrainAnaEngine.h b/nvidia_ascend_engine/common_engine/TrainAnaEngine/PostTrainAnaEngine.h deleted file mode 100644 index 22adbc9..0000000 --- a/nvidia_ascend_engine/common_engine/TrainAnaEngine/PostTrainAnaEngine.h +++ /dev/null @@ -1,41 +0,0 @@ -/** - * 新来车检测后处理 - * */ - -#ifndef POSTTRAINANAENGINE_H -#define POSTTRAINANAENGINE_H - -#include "AppCommon.h" -#include "MyYaml.h" -#include "myutils.h" -#include "EngineBase.h" -#include "EngineFactory.h" - -class PostTrainAnaEngine : public ai_matrix::EngineBase -{ -public: - PostTrainAnaEngine(); - ~PostTrainAnaEngine(); - - APP_ERROR Init() override; - APP_ERROR DeInit() override; - APP_ERROR Process() override; - -private: - //参数初始化 - void InitParam(); - - - std::string strPort0_; - uint32_t iMoveDataNO_ = 1; //动态检测数据编号 - std::string strTrainData_; - std::string strTrainName_; - std::string strResultPath_; - - std::set setPushPort_; - ai_matrix::DataSourceConfig dataSourceCfg_; -}; - -ENGINE_REGIST(PostTrainAnaEngine) - -#endif diff --git a/nvidia_ascend_engine/common_engine/TrainAnaEngine/TrainAnaEngine.cpp b/nvidia_ascend_engine/common_engine/TrainAnaEngine/TrainAnaEngine.cpp deleted file mode 100644 index 814f31c..0000000 --- a/nvidia_ascend_engine/common_engine/TrainAnaEngine/TrainAnaEngine.cpp +++ /dev/null @@ -1,1684 +0,0 @@ -#include "TrainAnaEngine.h" - -#define SHOW_RECTANGLE - -using namespace ai_matrix; - -unsigned int num=0; - -TrainAnaEngine::TrainAnaEngine() {} - -TrainAnaEngine::~TrainAnaEngine() {} - -APP_ERROR TrainAnaEngine::Init() -{ - LogInfo << "TrainAnaEngine Init start"; - // 初始化相机帧率 - nFrameRate = FRAME_RATE; - nRecIndex = 0; - nPicAreaChangeing = 0x00; - - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strPort1_ = engineName_ + "_" + std::to_string(engineId_) + "_1"; - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - strResultPath_for_test = MyYaml::GetIns()->GetPathValue("gc_result_path_for_test"); - - // 获取算法参数的文件路径 - std::string strsettingpath = MyYaml::GetIns()->GetStringValue("method_setting"); - // 读取算法参数的内容 - getsetting(strsettingpath); - // 获取动态检测参数的数量 - int nMethodCount = lstAction.size(); - // LogInfo << "TrainAnaEngine Init method list count:" << nMethodCount; - if (nMethodCount > 2) - { - //计算变化值 - nRightComeFlagR3 = 0x00000001 << (lstAction.size() - 3); - nRightComeFlagR2 = 0x00000001 << (lstAction.size() - 2) + nRightComeFlagR3; - nRightComeFlagR1 = 0x00000001 << (lstAction.size() - 1) + nRightComeFlagR2; - // LogInfo << "TrainAnaEngine Init nRightComeFlagR3:" << nRightComeFlagR3; - // LogInfo << "TrainAnaEngine Init nRightComeFlagR2:" << nRightComeFlagR2; - // LogInfo << "TrainAnaEngine Init nRightComeFlagR1:" << nRightComeFlagR1; - } - // 获取尾部车钩的偏移量 - nTailPixOffset = getTailPixOffset(); - // LogInfo << "TrainAnaEngine Init nTailPixOffset:" << nTailPixOffset; - //初始化来车检测状态 - nStatus=TRAIN_INIT_STATUS; - // 初始化引擎相关的参数 - vResetPartion(); - - LogInfo << "TrainAnaEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR TrainAnaEngine::DeInit() -{ - LogInfo << "TrainAnaEngine DeInit ok"; - return APP_ERR_OK; -} - - -/** -* 参数初始化(列车结束时需调用) -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void TrainAnaEngine::InitParam() -{ - LogInfo << "TrainAnaEngine InitParam start"; - strTrainData_ = ""; - strTrainName_ = ""; - LogInfo << "TrainAnaEngine InitParam end"; -} - - -/** -* 初始化车厢分割信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void TrainAnaEngine::vResetPartion() -{ - LogInfo << "TrainAnaEngine vResetPartion start"; - InitParam(); - // //行车状态为初始化 - // nStatus = TRAIN_INIT_STATUS; - // nPreStatus = TRAIN_INIT_STATUS; - - //设定检测动态区域均为未发生变化 - nPicAreaChangeing = 0x00; - nPrePicAreaChangeing = 0x00; - //清空车厢划分列表 - lstPartInfo.clear(); - //初始化开始帧 - nLatestFrame = 0; - - // 根据帧率计算检测到车钩以后忽略检测的帧数 - // 1.默认车辆3.9秒通过 - // 2.默认车体长度 14.5(TRAIN_WIDTH) - // 3.单位:米/秒 - fdefaultspeed = (TRAIN_WIDTH / 3.9); - - // 车体的三分之一作为忽略标准 - // 车体三分之一的通过时间 - float fpasstime = (TRAIN_WIDTH / 3.0) / fdefaultspeed; - // 忽略帧数:时间*帧率 - nSamePartionIgnoreCount = fpasstime * nFrameRate; - - nPartionPassFrameCount = 0; - - LogInfo << "TrainAnaEngine vResetPartion start"; -} - -/** -* 格式化算分配置文件内容 -* inParam : 单个算法配置分割后的字符信息 -* outParam: 结构化的算法配置信息 -* return : N/A -*/ -void TrainAnaEngine::vformatStructAnalyseInfo(std::vector elems, AnalyseInfo &info) -{ - LogInfo << "TrainAnaEngine vformatStructAnalyseInfo start"; - //以下内容为文件读取的结果 - //算法类型 1动态检测 2车厢划分 - info.nType = -1; - //检测敏感区域开始位置的X值 - info.nAreaX1 = -1; - //检测敏感区域开始位置的Y值 - info.nAreaY1 = -1; - //检测敏感区域结束位置的X值 - info.nAreaX2 = -1; - //检测敏感区域结束位置的Y值 - info.nAreaY2 = -1; - //算法结果等级相同做AND处理,不同做OR处理 - info.bOrLevel = -1; - //是否以不同作为判断结果 - info.bDiff = false; - //算法是否有效 1有效 0无效 - info.bOn = false; - //判断相同的阈值 - info.dSameThresholdVal = 0.0; - //判断不同的阈值 - info.dDiffThresholdVal = 0.0; - //判断停车的累计帧数阈值 - info.nPauseMaxCoumt = 0; - //图像增强的算法(位运算) - //0x01 灰度化 - //0x02 直方图均衡化 - //0x04 自定义 - info.npicimprovetype = -1; - //OPENCV模板对比算法 - info.templemethod = -1; - //直方图对比算法 - info.histmethod = -1; - //自定义算法 - info.specmethod = -1; - //图像比对的方法(位运算) - //0x01 OPENCV模板对比 - //0x02 直方图对比 - //0x04 自定义 - info.compmethod = -1; - //对比的基准图的路径 - info.baseImagePath = ""; - - //以下内容为初始化结果 - //图像对比数值 - info.dComparePoint = 0.0; - //上一帧对比数值 - info.dPreComparePoint = 0.0; - //图像与基础状态是否发生变化 - info.bChanged = 0.0; - //上一帧图像与基础状态是否发生变化 - info.bPreChanged = 0.0; - //图像变化后(保持在一个平衡状态即值不变的状态)累计值 - info.nSameCount = 0; - - char *chrevptr; - if (elems.size() == IMAGEANALYSE_NUM) - { - info.nType = atoi(elems[0].c_str()); - info.nAreaX1 = atoi(elems[1].c_str()); - info.nAreaY1 = atoi(elems[2].c_str()); - info.nAreaX2 = atoi(elems[3].c_str()); - info.nAreaY2 = atoi(elems[4].c_str()); - info.bOrLevel = atoi(elems[5].c_str()); - info.bDiff = (atoi(elems[6].c_str()) == 1) ? true : false; - info.bOn = (atoi(elems[7].c_str()) == 1) ? true : false; - info.dSameThresholdVal = strtod(elems[8].c_str(), &chrevptr); - info.dDiffThresholdVal = strtod(elems[9].c_str(), &chrevptr); - info.nPauseMaxCoumt = atoi(elems[10].c_str()); - info.npicimprovetype = atoi(elems[11].c_str()); - info.templemethod = atoi(elems[12].c_str()); - info.histmethod = atoi(elems[13].c_str()); - info.specmethod = atoi(elems[14].c_str()); - info.compmethod = atoi(elems[15].c_str()); - info.baseImagePath = elems[16]; - } - LogInfo << "TrainAnaEngine vformatStructAnalyseInfo end"; -} - -/** -* 获取图像比对的结果值 -* inParam : 算法配置信息 -* inParam : 当前图像的Mat值 -* inParam : 比对基础图像的Mat值 -* outParam: N/A -* return : 比对值的数组 -*/ -std::vector TrainAnaEngine::getCompPoint(AnalyseInfo info, cv::Mat baseimg, cv::Mat tarpic) -{ - LogInfo << "TrainAnaEngine getCompPoint start"; - std::vector dRetVal; - cv::Point cvOutPoint; - - LogInfo << "TrainAnaEngine getCompPoint info.compmethod:" << info.compmethod; - if ((info.compmethod & IMAGE_COMP_BY_SPEC) == IMAGE_COMP_BY_SPEC) - { - double dHistPoint = anapicbySpec(baseimg); - dRetVal.push_back(dHistPoint); - } - //OPENCV模型比对方法 - if ((info.compmethod & IMAGE_COMP_BY_TEMPLE) == IMAGE_COMP_BY_TEMPLE) - { - double dtemplePoint = anapicbyTemple(baseimg, tarpic, info.templemethod, cvOutPoint); - dRetVal.push_back(dtemplePoint); - } - //直方图比对方法 - if ((info.compmethod & IMAGE_COMP_BY_HIST) == IMAGE_COMP_BY_HIST) - { - double dHistPoint = anapicbyHist(baseimg, tarpic, info.histmethod); - dRetVal.push_back(dHistPoint); - } - - - LogInfo << "TrainAnaEngine getCompPoint end:" << dRetVal[0]; - return dRetVal; -} - -/** -* 获取算法配置文件的内容 -* inParam : 算法配置文件路径 -* outParam: N/A -* return : N/A -*/ -void TrainAnaEngine::getsetting(string strFilePath) -{ - //LogInfo << "TrainAnaEngine getsetting start"; - std::string strLineInfo; - std::ifstream finfile(strFilePath); - int nindex = 0; - //按行读取 - while (std::getline(finfile, strLineInfo)) - { - //LogInfo << "TrainAnaEngine getsetting nindex:" << nindex; - //首行作为注释不读取 - if (nindex == 0) - { - nindex++; - continue; - } - nindex++; - std::vector elems; - //每行以逗号, 作为分隔符 - elems = MyUtils::getins()->split(strLineInfo, ","); - - AnalyseInfo strTempInfo; - //根据逗号分割的列表数据 初始化算法配置信息 - vformatStructAnalyseInfo(elems, strTempInfo); - //LogInfo << "TrainAnaEngine getsetting strTempInfo.nType :" << strTempInfo.nType ; - //保存动态检测的算法到集合中 - if (strTempInfo.nType == TRAIN_ACTION) - { - lstAction.push_back(strTempInfo); - } - //保存车厢划分的算法到集合中 - else if(strTempInfo.nType == TRAIN_PARTION) - { - lstPartion.push_back(strTempInfo); - } - } - //LogInfo << "TrainAnaEngine getsetting end"; -} - -/** -* 根据直方图做比对 -* inParam : 当前图像的Mat值 -* inParam : 比对基础图像的Mat值 -* inParam : 比对算法 -* outParam: N/A -* return : 比对值 -*/ -double TrainAnaEngine::anapicbySpec(cv::Mat baseimg) -{ - LogInfo << "TrainAnaEngine anapicbySpec start"; - double match = 0.0; - int nmean = 0; - Mat tmp_m, tmp_sd; - cv::Mat mtTempImage = mtresizeImage(baseimg, (int)(baseimg.cols / 4), (int)(baseimg.rows / 4)); - - - cv::Mat mtOutImage; - cv::meanStdDev(mtTempImage, tmp_m, tmp_sd); - nmean = (int)tmp_m.at(0,0); - int nwidth = mtTempImage.cols; - int nHeight = mtTempImage.rows; - std::vector elems; - int nmax = 0; - int nmin = 0; - for(int i = 0;i < nHeight;i++) { - int ncheckval = 0; - for(int j = 0; j < nwidth;j++) { - ncheckval = ncheckval + mtTempImage.at(i,j); - } - ncheckval = (int)(ncheckval / nwidth) - nmean; - if(ncheckval > nmax){ - nmax = ncheckval; - } - if(ncheckval < nmin){ - nmin = ncheckval; - } - elems.push_back(ncheckval); - } - - int nstartindex = 6; - int nendindex = 24; - int nblackcount = 0; - for(int i = nstartindex + 1;i < nendindex;i++) { - if(elems[i] < 0 && elems[i - 1] < 0){ - nblackcount++; - } else { - //nblackcount = 0; - } - } - LogInfo << "TrainAnaEngine anapicbySpec nblackcount:" << nblackcount; - if (nblackcount > ((nendindex - nstartindex) / 2)) { - for(int i = 0;i < nHeight;i++) { - elems[i] = 0 - elems[i]; - } - } - - int nfirstpot = -1; - int nsecondpot = -1; - int nthirdpot = -1; - int nfirstpotsum = 0; - int nsecondpotsum = 0; - int nthirdpotsum = 0; - - int npremax = 0; - int npremin = 0; - int nfirstmax = 0; - int nfirstmin = 0; - int nsecondmax = 0; - int nsecondmin = 0; - - for(int i = 2; i < nHeight; i++) { - LogInfo << "TrainAnaEngine elems[i] :" << elems[i]; - if (elems[i -2] < elems[i - 1] && elems[i - 1] < elems[i] && nfirstpot == -1 && elems[i] > 0) { - nfirstpot = i; - } - if (nfirstpot == -1) { - if(npremax < elems[i]){ - npremax = elems[i]; - } - if(npremin > elems[i]){ - npremin = elems[i]; - } - continue; - } - if (elems[i -2] > elems[i - 1] && elems[i - 1] > elems[i] && nsecondpot == -1 && elems[i] < 0) { - nsecondpot = i; - } - if (nsecondpot == -1 && elems[i] > 0) { - nfirstpotsum++; - if(nfirstmax < elems[i]){ - nfirstmax = elems[i]; - } - if(nfirstmin > elems[i]){ - nfirstmin = elems[i]; - } - } - if (nsecondpot == -1) { - continue; - } - if (nthirdpot == -1 && elems[i] < 0) { - nsecondpotsum++; - if(nsecondmax < elems[i]){ - nsecondmax = elems[i]; - } - if(nsecondmin > elems[i]){ - nsecondmin = elems[i]; - } - } - if (elems[i -2] < elems[i - 1] && elems[i - 1] < elems[i] && nthirdpot == -1 && elems[i] > 0) { - nthirdpot = i; - } - if (nthirdpot != -1) { - nthirdpotsum++; - } - } - - LogInfo << "TrainAnaEngine nHeight :" << nHeight; - LogInfo << "TrainAnaEngine nfirstpot :" << nfirstpot; - LogInfo << "TrainAnaEngine nsecondpot :" << nsecondpot; - LogInfo << "TrainAnaEngine nthirdpot :" << nthirdpot; - LogInfo << "TrainAnaEngine nmax :" << nmax; - LogInfo << "TrainAnaEngine nmin :" << nmin; - LogInfo << "TrainAnaEngine npremin :" << npremin; - LogInfo << "TrainAnaEngine npremax :" << npremax; - LogInfo << "TrainAnaEngine nfirstmax :" << nfirstmax; - LogInfo << "TrainAnaEngine nfirstmin :" << nfirstmin; - LogInfo << "TrainAnaEngine nsecondmax :" << nsecondmax; - LogInfo << "TrainAnaEngine nsecondmin :" << nsecondmin; - if ( - (nfirstpot < (int)(nHeight / 3)) - && (nsecondpot > (int)(nHeight / 2)) && (nsecondpot < (int)(nHeight *2 / 3)) - && (nthirdpot > (int)(nHeight * 3/ 4)) - && (npremin < 0) - && (nfirstmax > 0) - && (nsecondmin < 0) - //&& (nfirstpotsum > (nsecondpot - nfirstpot - 2)) - //&& (nsecondpotsum > (nthirdpot - nsecondpot - 2)) - //&& (nthirdpotsum >= (nHeight - nthirdpot - 1)) - //&& (nmax- nfirstmax > nmax/2) - //&& (nsecondmin < nmin/2) - ){ - match = 1.0; - double firstsinoffset = 180.0/nfirstpot; - double secondsinoffset = 180.0/(nsecondpot - nfirstpot); - double thirdsinoffset = 180.0/(nthirdpot - nsecondpot); - double dbaseoffset = 1.0 / (nHeight * 1.0); - double dmaxoffset = (nmax-nmin) * 1.0 ; - LogInfo << "TrainAnaEngine firstsinoffset :" << firstsinoffset; - LogInfo << "TrainAnaEngine secondsinoffset :" << secondsinoffset; - LogInfo << "TrainAnaEngine thirdsinoffset :" << thirdsinoffset; - LogInfo << "TrainAnaEngine dbaseoffset :" << dbaseoffset; - LogInfo << "TrainAnaEngine dmaxoffset :" << dmaxoffset; - double dtmp = 0.0; - for (int i = 0; i < nHeight; i++) { - if (i < nfirstpot){ - dtmp = dbaseoffset * abs(elems[i] - sin((i)*firstsinoffset)*(npremin* 1.0))/ dmaxoffset; - } else if(i>= nfirstpot && i < nsecondpot){ - dtmp = dbaseoffset * abs(elems[i] - sin((i - nfirstpot)*secondsinoffset)*(nfirstmax * 1.0)) / dmaxoffset; - } else if(i>= nsecondpot && i < nthirdpotsum){ - dtmp = dbaseoffset * abs(elems[i] - sin((i - nsecondpot)*thirdsinoffset)*(nsecondmin * 1.0)) / dmaxoffset; - } else if(i >= nthirdpotsum){ - dtmp = 0.0; - } - LogInfo << "TrainAnaEngine befor match :" << match; - LogInfo << "TrainAnaEngine dtmp :" << dtmp; - match = match - dtmp; - LogInfo << "TrainAnaEngine after match :" << match; - } - //match = 1.0; - } - if (strResultPath_for_test != "") - { - std::ostringstream ossfloat,ossint; - ossfloat<<(int)(match * 1000); - ossint< imagedata; - imagefile >> std::noskipws; - std::copy(std::istream_iterator(imagefile), std::istream_iterator(), std::back_inserter(imagedata)); - cv::Mat jpegimage = cv::imdecode(Mat(imagedata), cv::IMREAD_COLOR); - imagefile.close(); - LogInfo << "TrainAnaEngine mtdecodeImageDatabyFile end"; - return jpegimage; -} - - -/** -* 将图像二进制数据转化为Mat值 -* inParam : 二进制数据指针 -* inParam : 二进制数据长度 -* outParam: N/A -* return : 图像Mat值 -*/ -cv::Mat TrainAnaEngine::mtdecodeImageDatabyBin(LPVOID lpimgdata, int imglen) -{ - LogInfo << "TrainAnaEngine mtdecodeImageDatabyBin start"; - //LogInfo << "TrainAnaEngine mtdecodeImageDatabyBin imglen:" << imglen; - const char *buffer = static_cast(lpimgdata); - vector::size_type size = imglen; - - std::vector imagedata(buffer, buffer + size); - cv::Mat jpegimage = imdecode(imagedata, cv::IMREAD_COLOR); - LogInfo << "TrainAnaEngine mtdecodeImageDatabyBin end"; - return jpegimage; -} - - -/** -* 图像增强 -* inParam : 原始图片的Mat值 -* inParam : 算法配置信息 -* outParam: N/A -* return : 图像Mat值 -*/ -cv::Mat TrainAnaEngine::mtImproveImage(cv::Mat inImage, AnalyseInfo info, bool bcvread) -{ - LogInfo << "TrainAnaEngine mtImproveImage start"; - cv::Mat mtOutImage = inImage; - //cv::Mat mtOutImage; - int x1 = info.nAreaX1; - int y1 = info.nAreaY1; - int width = info.nAreaX2 - info.nAreaX1; - int height = info.nAreaY2 - info.nAreaY1; - int type = info.nType; - int mode = (bcvread == false) ? cv::COLOR_YUV2GRAY_420 : cv::COLOR_RGB2GRAY; - - //LogInfo << "TrainAnaEngine mtImproveImage x1:"<(i, j) = 6*pow((double)inImage.at(i, j), fgamma); - } - } - cv::normalize(mtTempImage, mtTempImage, 0, 255, NORM_MINMAX); - cv::convertScaleAbs(mtTempImage, mtOutImage); - LogInfo << "TrainAnaEngine mtGammaImage end"; - return mtOutImage; -} - - -/** -* 图像进行自定义处理 -* inParam : 原始图片的Mat值 -* outParam: N/A -* return : 图像Mat值 -*/ -cv::Mat TrainAnaEngine::mtspecImage(cv::Mat inImage) -{ - LogInfo << "TrainAnaEngine mtspecImage start"; - cv::Mat mtTempImage = inImage; - cv::Mat mtOutImage; - //中值滤波,降采样 - cv::medianBlur(inImage,mtTempImage,3); - cv::resize(mtTempImage, mtOutImage, Size((int)(mtTempImage.rows*0.5),(int)(mtTempImage.cols*0.5) ), INTER_LINEAR); - LogInfo << "TrainAnaEngine mtspecImage end"; - return mtOutImage; -} - -/* -* 获取最近100帧的dComparePoint的最大值与最小值之差 -* inParam : 第i个方框的dComparePoint值 -* inParam : 第i个框的索引 -* outParam: N/A -* return : N/A -*/ -float TrainAnaEngine::GetPointMaxReduceMin(float dComparePoint,int index){ - static float array[20] ={0.0}; - switch (index) - { - case 0: - static int num_count1=0; - static float array1[20] ={0.0}; - array1[num_count1]=dComparePoint; - num_count1++; - if (num_count1>19){ - num_count1=0; - } - for(int i=0;i<=19;i++){ - array[i]=array1[i]; - } - break; - - - case 1: - static int num_count2=0; - static float array2[20] ={0.0}; - array2[num_count2]=dComparePoint; - num_count2++; - if (num_count2>19){ - num_count2=0; - } - for(int i=0;i<=19;i++){ - array[i]=array2[i]; - } - break; - - - case 2: - static int num_count3=0; - static float array3[20] ={0.0}; - array3[num_count3]=dComparePoint; - num_count3++; - if (num_count3>19){ - num_count3=0; - } - for(int i=0;i<=19;i++){ - array[i]=array3[i]; - } - break; - } - - sort(array,array+20); - return (array[19]-array[0]); -} -/** -* 来车动态检测 -* inParam : 原始图片的Mat值 -* inParam : 原始图片的时间戳 -* outParam: N/A -* return : N/A -*/ -void TrainAnaEngine::checkAction(cv::Mat baseimg, uint64_t i64TimeStamp) -{ - #ifdef SHOW_RECTANGLE - cv::Mat img=baseimg.clone(); - cv::Scalar sca(0,0,255); - #endif - - - //count[5]记录选择区域的状态为来车所保持的帧数,当帧数大于5时,改变选择区域的状态为来车 - static int count[5]={0}; - LogInfo << "TrainAnaEngine checkAction start"; - // 记录上一帧的行车状态 - nPreStatus = nStatus; - // 记录上一帧的动态变化情况 - nPrePicAreaChangeing = nPicAreaChangeing; - // 初始化当前帧的动态变化情况 - nPicAreaChangeing = 0x00; - // 检测区域数量 - int nlistlen = lstAction.size(); - //LogInfo << "TrainAnaEngine checkAction nlistlen:" << nlistlen; - //LogInfo << "TrainAnaEngine checkAction i64TimeStamp:" << i64TimeStamp; - - - for (int i = 0; i < nlistlen; i++) - { - // 根据检测区域切分当前帧 - cv::Mat cvImg1 = mtareaImage(baseimg, lstAction[i].nAreaX1, lstAction[i].nAreaY1, lstAction[i].nAreaX2, lstAction[i].nAreaY2); - cvImg1 = mtImproveImage(cvImg1, lstAction[i], false); - // 根据检测区域切分基础帧 - cv::Mat cvImg2 = mtareaImage(cvFirstImg, lstAction[i].nAreaX1+5, lstAction[i].nAreaY1+5, lstAction[i].nAreaX2-5, lstAction[i].nAreaY2-5); - cvImg2 = mtImproveImage(cvImg2, lstAction[i], false); - // 获取比对数值 - std::vector lstRet = getCompPoint(lstAction[i], cvImg1, cvImg2); - // 记录上一帧比对数值 - lstAction[i].dPreComparePoint = lstAction[i].dComparePoint; - // 记录当前帧比对数值 - lstAction[i].dComparePoint = lstRet[0]; - //LogInfo << "TrainAnaEngine checkAction i:" << i; - //LogInfo << "TrainAnaEngine checkAction nlistlen:" << nlistlen; - //LogInfo << "TrainAnaEngine checkAction nStatus:" << nStatus; - //LogInfo << "TrainAnaEngine checkAction lstAction[i].dComparePoint:" << lstAction[i].dComparePoint; - //LogInfo << "TrainAnaEngine checkAction lstAction[i].dSameThresholdVal:" << lstAction[i].dSameThresholdVal; - - #ifdef SHOW_RECTANGLE - //方框的位置 - cv::Rect rect(lstAction[i].nAreaX1,lstAction[i].nAreaY1,(lstAction[i].nAreaX2-lstAction[i].nAreaX1),(lstAction[i].nAreaY2-lstAction[i].nAreaY1)); - //point1当前的方框状态显示的位置 - cv::Point point(lstAction[i].nAreaX1,lstAction[i].nAreaY1-90); - //point2时当前的方框相似度的值显示的位置 - cv::Point point2(lstAction[i].nAreaX1,lstAction[i].nAreaY1-60); - //point2时当前的方框累加的值显示的位置 - cv::Point point3(lstAction[i].nAreaX1,lstAction[i].nAreaY1-30); - cv::rectangle(img,rect,sca,3); - #endif - - // 比对数值小于设定的阈值则判断检测区域发生变化 - if (lstAction[i].dComparePoint < lstAction[i].dSameThresholdVal){ - //LogInfo << "TrainAnaEngine checkAction start nPicAreaChangeing:" << nPicAreaChangeing; - // 设定状态 当前区域存在变化 - count[i]++; - if(count[i]>=5){ - // nPicAreaChangeing += 0x00000001 << i; - lstAction[i].bChanged = true; - if(count[i]>10) - count[i]=10; - } - //LogInfo << "TrainAnaEngine checkAction end nPicAreaChangeing:" << nPicAreaChangeing; - }else{ - count[i]--; - if(count[i]<=0){ - count[i]=0; - //nPicAreaChangeing =(nPicAreaChangeing&(~(0x00000001< 检测有车 - if (nStatus == TRAIN_INIT_STATUS){ - //LogInfo << "TrainAnaEngine checkAction TRAIN_INIT_STATUS start"; - // 动态检测区域状态是否发生变化 true 发生 false 未发生 - bool bStatuschanged = false; - //根据方框的编号以及对应的状态判断当前来车的方向以及有无来车 - //0对应左侧方框一,1对应中间方框 - if((lstAction[0].bChanged&&lstAction[1].bChanged&&(!lstAction[2].bChanged))||(lstAction[0].bChanged&(!lstAction[1].bChanged)&lstAction[2].bChanged)){ - nStatus = TRAIN_RIGHT_RUN; - bStatuschanged = true; - }else if(lstAction[1].bChanged&&lstAction[2].bChanged&&(!lstAction[0].bChanged)){ - nStatus = TRAIN_LEFT_RUN; - bStatuschanged = true; - } - // }else if(lstAction[0].bChanged&&lstAction[1].bChanged&&lstAction[2].bChanged){ - // nStatus = TRAIN_RIGHT_RUN; - // bStatuschanged = true; - // } - - // 状态发生变化 - if (bStatuschanged == true) { - // 开始记录车厢划分信息/添加一节车厢划分信息 - PartionInfo stTempInfo; - stTempInfo.nindex = 1; - stTempInfo.startframe = 1; - stTempInfo.i64StartTimeStamp = i64TimeStamp; - lstPartInfo.push_back(stTempInfo); - } - - //基础帧替换的第一种情况。 - //用于计算高校相似度保持的帧数,当帧数保持10帧以上则进行帧替换 - static int count_num=0; - bool bEmpty1=true; - for (int i = 0; i < nlistlen; i++) { - bEmpty1=bEmpty1&&(lstAction[i].dPreComparePoint>=0.95); - } - if (bEmpty1){ - count_num++; - if(count_num>=10) { - // 没有发生变化,则将该帧作为基础帧 - cvFirstImg = baseimg; - - count_num=0; - } - }else{ - count_num=0; - } - - - //基础帧替换的第二种情况,过车后引起的相似度下降,需要最近100帧相似度波动小于0.03 - bool bEmpty2=true; - static int count_num2=0; - for (int i = 0; i < nlistlen; i++) { - bEmpty2=bEmpty2&&(!lstAction[i].bChanged); - bEmpty2=bEmpty2&&(lstAction[i].fluctuationFlag); - } - if(bEmpty2){ - count_num2++; - if(count_num2>100){ - cvFirstImg = baseimg; - count_num2=0; - } - }else{ - count_num2=0; - } - - #ifdef SHOW_RECTANGLE - LogInfo<<"current img id "<=2 )&& noFluctuationFlag); - bpassed=(bpassed && noFluctuationFlag); - - //计算累计帧数 - static unsigned short int count1=0; - static unsigned short int count2=0; - // 状态 有车 -> 停车 - if (bpaused == true) - { - count1++; - if(count1>50){ - nStatus = TRAIN_PAUSE; - count1=0; - count2=0; - } - }else{ - count1=0; - } - // 状态 有车 -> 完全通过 - if (bpassed == true) - { - count2++; - if(count2>50){ - nStatus = TRAIN_PASSED; - count1=0; - count2=0; - } - }else{ - count2=0; - - } - - #ifdef SHOW_RECTANGLE - LogInfo<<"current img id "<=2 )&& noFluctuationFlag); - bpassed=(bpassed && noFluctuationFlag); - - //计算累计帧数 - static unsigned short int count1=0; - static unsigned short int count2=0; - // 状态 有车 -> 停车 - if (bpaused == true) - { - count1++; - if(count1>50){ - nStatus = TRAIN_PAUSE; - count1=0; - count2=0; - } - }else{ - count1=0; - } - // 状态 有车 -> 完全通过 - if (bpassed == true) - { - count2++; - if(count2>50){ - nStatus = TRAIN_PASSED; - count1=0; - count2=0; - } - }else{ - count2=0; - } - #ifdef SHOW_RECTANGLE - LogInfo<<"current img id "<=2 )&& noFluctuationFlag); - bpassed=(bpassed && noFluctuationFlag); - - //计算累计帧数 - static unsigned short int count1=0; - static unsigned short int count2=0; - // 状态 有车 -> 停车 - if (bpaused == true) - { - count1++; - if(count1>50){ - nStatus = TRAIN_PAUSE; - count1=0; - count2=0; - } - }else{ - count1=0; - } - // 状态 有车 -> 完全通过 - if (bpassed == true) - { - count2++; - if(count2>50){ - nStatus = TRAIN_PASSED; - count1=0; - count2=0; - } - }else{ - count2=0; - } - - #ifdef SHOW_RECTANGLE - LogInfo<<"current img id "<20){ - nStatus=TRAIN_RESTART; - count=0; - } - count++; - } - #ifdef SHOW_RECTANGLE - LogInfo<<"current img id "< lstRet = getCompPoint(lstPartion[i], cvImg1, cvImg2); - lstPartion[i].dComparePoint = lstRet[0]; - //LogInfo << "TrainAnaEngine checkPartion lstPartion[i].dComparePoint:" << lstPartion[i].dComparePoint; - - // 获取是相同还是不同作为判断标准 - bool bCurrentRet = (lstPartion[i].bDiff == true) ? lstPartion[i].dComparePoint < lstPartion[i].dDiffThresholdVal : lstPartion[i].dComparePoint > lstPartion[i].dSameThresholdVal; - // 对比等级不同 进行判断结果OR处理 - if (lstPartion[i].bOrLevel != nPreOrLevel) - { - //LogInfo << "TrainAnaEngine checkPartion lstPartion[i].bOrLevel != nPreOrLevel"; - bPartion = bPartion || bCurrentRet; - } - // 比对等级相同 进行判断结果AND处理 - else - { - //LogInfo << "TrainAnaEngine checkPartion lstPartion[i].bOrLevel == nPreOrLevel"; - bPartion = bPartion && bCurrentRet; - } - // 判断结果存在false的情况 直接停止判断确定没有车厢划分信息 - if (bPartion == false) - { - //LogInfo << "TrainAnaEngine checkPartion bPartion == false"; - break; - } - } - // 存在车厢划分信息 - if (bPartion == true) - { - //LogInfo << "TrainAnaEngine checkPartion bPartion == true for end"; - // nPartionPassFrameCount = 0; - // 获取最新的车厢节数 - int nPrePartionIndex = lstPartInfo.size() - 1; - - // 获取时间戳 - lstPartInfo[nPrePartionIndex].i64EndTimeStamp = i64TimeStamp; - // 根据开始帧时间戳和结束帧时间错 计算当节车厢的行车速度 - //LogInfo << "TrainAnaEngine checkPartion bPartion == true lstPartInfo[nPrePartionIndex].ftime:" << abs(lstPartInfo[nPrePartionIndex].i64EndTimeStamp - lstPartInfo[nPrePartionIndex].i64StartTimeStamp); - // 根据时间戳计算时间差 - float nTimePassed = (abs(lstPartInfo[nPrePartionIndex].i64EndTimeStamp - lstPartInfo[nPrePartionIndex].i64StartTimeStamp)) * 1.0; - lstPartInfo[nPrePartionIndex].fspeed = (TRAIN_WIDTH * 1000.0) /nTimePassed; - // - //nSamePartionIgnoreCount = (nTimePassed / (3 * 5000)) * nFrameRate; - // 结束帧为当前帧再往后 (除以2的原因:中间为车钩,车钩后的车体宽度为整个镜头的宽度除以2) - lstPartInfo[nPrePartionIndex].endframe = nLatestFrame + getOffsetFrame(lstPartInfo[nPrePartionIndex].fspeed, (TRAIN_IN_CAMERA_WIDTH / 2), nFrameRate); - //LogInfo << "TrainAnaEngine checkPartion bPartion == true lstPartInfo[nPrePartionIndex].endframe" << lstPartInfo[nPrePartionIndex].endframe; - lstPartInfo[nPrePartionIndex].bfuncconfirmed = true; - //LogInfo << "TrainAnaEngine checkPartion bPartion == true lstPartInfo[nPrePartionIndex].i64EndTimeStamp:" << lstPartInfo[nPrePartionIndex].i64EndTimeStamp; - //LogInfo << "TrainAnaEngine checkPartion bPartion == true lstPartInfo[nPrePartionIndex].i64StartTimeStamp:" << lstPartInfo[nPrePartionIndex].i64StartTimeStamp; - // 如果时间戳相同则不是划分信息 - if (lstPartInfo[nPrePartionIndex].i64EndTimeStamp == lstPartInfo[nPrePartionIndex].i64StartTimeStamp) { - bPartion = false; - return bPartion; - } - - - //LogInfo << "TrainAnaEngine checkPartion nPrePartionIndex" << nPrePartionIndex; - //LogInfo << "TrainAnaEngine checkPartion lstPartInfo[nPrePartionIndex].i64EndTimeStamp" << lstPartInfo[nPrePartionIndex].i64EndTimeStamp; - //LogInfo << "TrainAnaEngine checkPartion lstPartInfo[nPrePartionIndex].nLatestFrame" << nLatestFrame; - //LogInfo << "TrainAnaEngine checkPartion lstPartInfo[nPrePartionIndex].fspeed:" << lstPartInfo[nPrePartionIndex].fspeed; - //LogInfo << "TrainAnaEngine checkPartion lstPartInfo[nPrePartionIndex].endframe" << lstPartInfo[nPrePartionIndex].endframe; - //LogInfo << "TrainAnaEngine checkPartion bPartion == true lstPartInfo[nPrePartionIndex].fspeed:" << lstPartInfo[nPrePartionIndex].fspeed; - } - LogInfo << "TrainAnaEngine checkPartion end"; - return bPartion; -} - -/** -* 计算车钩从中间到边缘的间隔帧 -* inParam : 行车速度(单位:米/秒) -* inParam : 宽度 -* inParam : 相机帧率(单位:帧/秒) -* outParam: N/A -* return : 间隔帧 -*/ -int TrainAnaEngine::getOffsetFrame(float fspeed, int width, int nFrameRate) -{ - LogInfo << "TrainAnaEngine getOffsetFrame start"; - //LogInfo << "TrainAnaEngine getOffsetFrame fspeed:" << fspeed; - //LogInfo << "TrainAnaEngine getOffsetFrame width:" << width; - //LogInfo << "TrainAnaEngine getOffsetFrame nFrameRate:" << nFrameRate; - //LogInfo << "TrainAnaEngine getOffsetFrame nLatestFrame:" << nLatestFrame; - //偏移值 = (中间到边缘的宽度(米) / 速度(米/秒)->时间(秒))* 帧率(帧/秒) - float ftmp = width * (float) nFrameRate; - //LogInfo << "TrainAnaEngine getOffsetFrame start end:" << ftmp; - ftmp = ftmp / fspeed; - //LogInfo << "TrainAnaEngine getOffsetFrame start end:" << ftmp; - int nRet = (int) ftmp; - LogInfo << "TrainAnaEngine getOffsetFrame start end:" << nRet; - return nRet; -} - - -/** -* 计算车钩移动的像素值 -* inParam : 行车速度(单位:米/秒) -* inParam : 宽度 -* inParam : 相机帧率(单位:帧/秒) -* outParam: N/A -* return : 间隔帧 -*/ -int TrainAnaEngine::getCouplerOffsetPosition(float fspeed, int nframeindex) -{ - LogInfo << "TrainAnaEngine getCouplerOffsetPosition start"; - //LogInfo << "TrainAnaEngine getCouplerOffsetPosition fspeed:" << fspeed; - //LogInfo << "TrainAnaEngine getCouplerOffsetPosition start:" << nframeindex; - //单位换算 - // 米/秒 -> 米/帧 - // 米/帧 = 米/秒 * 秒/帧(即:1/帧率) - float fmeter_frame = fspeed / nFrameRate; - //LogInfo << "TrainAnaEngine getCouplerOffsetPosition fmeter_frame:" << fmeter_frame; - // 米/帧 -> 像素/帧 - // 像素/帧 = 米/帧 * 像素/米 - float fpix_frame = fmeter_frame * (METHOD_BASE_WIDTH / TRAIN_IN_CAMERA_WIDTH); - //LogInfo << "TrainAnaEngine getCouplerOffsetPosition fpix_frame:" << fpix_frame; - - int nretPixOffet = (int)fpix_frame; - nretPixOffet = nretPixOffet * nframeindex; - //LogInfo << "TrainAnaEngine getCouplerOffsetPosition nretPixOffet:" << nretPixOffet; - LogInfo << "TrainAnaEngine getCouplerOffsetPosition end"; - return nretPixOffet; -} - -int TrainAnaEngine::getTailPixOffset() -{ - LogInfo << "TrainAnaEngine getTailPixOffset start"; - // 单位计算 - // 帧宽像素/米 - float fframewidth_meter = ((METHOD_BASE_WIDTH * 1.0) / (TRAIN_IN_CAMERA_WIDTH)); - //LogInfo << "TrainAnaEngine getTailPixOffset fframewidth_meter:" << fframewidth_meter; - // 车尾车钩像素位置 - float fOffsetPosistion = TRAIN_WIDTH * fframewidth_meter; - //LogInfo << "TrainAnaEngine getTailPixOffset fOffsetPosistion:" << fOffsetPosistion; - - int nretOffset = (int)fOffsetPosistion; - //LogInfo << "TrainAnaEngine getTailPixOffset nretOffset:" << nretOffset; - //LogInfo << "TrainAnaEngine getTailPixOffset end"; - return nretOffset; -} - - -APP_ERROR TrainAnaEngine::Process() -{ - int iRet = APP_ERR_OK; - //程序启动标志位 - bool bInited = false; - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } - - LogInfo << "TrainAnaEngine Process start"; - std::shared_ptr pDecodeData = std::static_pointer_cast(pVoidData0); - std::shared_ptr pHostData = nullptr; - - //获取图像数据 - cv::Mat matYUV(pDecodeData->iHeight * 3 / 2, pDecodeData->iWidth, CV_8UC1); - int iCopySize = pDecodeData->iWidth * pDecodeData->iHeight * 3 / 2; - memcpy(matYUV.data, pHostData.get(), iCopySize); - - // 将YUV格式灰度化之后修改图像尺寸 - cv::Mat cvtemp; - cv::cvtColor(matYUV, cvtemp, cv::COLOR_YUV2GRAY_420); - //cv::imwrite("/home/HwHiAiUser/1.jpg",cvtemp); - matYUV = mtresizeImage(cvtemp, METHOD_BASE_WIDTH, METHOD_BASE_HEIGHT); - //来车 - //cv::Mat baseimg = mtdecodeImageDatabyBin(lpimgdata, imglen); - //cv::Mat baseimg = matYUV.data; - //程序启动第一帧跳过 保存为基础图像 - if (bInited == false) { - cvFirstImg = matYUV; - bInited = true; - nFrameRate = pDecodeData->iRate; - continue; - } - LogInfo << "TrainAnaEngine Process pDecodeData.i64TimeStamp:" << pDecodeData->i64TimeStamp; - ncurtime = pDecodeData->i64TimeStamp; - //来车状态检测 - checkAction(matYUV, pDecodeData->i64TimeStamp); - - //判断是否有来车 - pDecodeData->iStatus = (nStatus == TRAIN_LEFT_RUN || nStatus == TRAIN_RIGHT_RUN || nStatus == TRAIN_UNKOWN_RUN || nStatus == TRAIN_RESTART) ? 1 : ( nStatus == TRAIN_PAUSE)? 2 : 0; - //判断来车方向 0 方向未知/无车 1右侧来车(向左行驶:模型识别用) 2左侧来车(向右行驶:模型识别用) - pDecodeData->iDirection = ((nStatus == TRAIN_LEFT_RUN) ? 1 : ((nStatus == TRAIN_RIGHT_RUN) ? 2 : 0)); - //列车是否通过 - pDecodeData->bIsEnd = (nStatus == TRAIN_PASSED || nStatus == TRAIN_RESTART ) ? true : false; - LogInfo << "TrainAnaEngine Process pDecodeData->iStatus:" << pDecodeData->iStatus; - //LogInfo << "TrainAnaEngine Process pDecodeData->iDirection:" << pDecodeData->iDirection; - //新过车创建文件夹 - if ((nStatus != TRAIN_INIT_STATUS && nPreStatus == TRAIN_INIT_STATUS) || - ( nPreStatus == TRAIN_RESTART && nStatus == TRAIN_UNKOWN_RUN)) - { - strTrainData_ = MyUtils::getins()->GetDate(); - strTrainName_ = MyUtils::getins()->GetTime(); - std::string strTrainPath = strResultPath_ + strTrainData_ + "/" + strTrainName_ + "/"; - MyUtils::getins()->CreateDirPath(strTrainPath); - } - //过车日期 - pDecodeData->strTrainDate = strTrainData_; - //过车时间 - pDecodeData->strTrainName = strTrainName_; - - // iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pDecodeData)); - - //当前帧是否有划分信息 - bool bPartionExist = false; - - //有车的状态进行车厢划分检测 - if (nStatus != TRAIN_INIT_STATUS){ - //LogInfo << "TrainAnaEngine Process nPartionPassFrameCount:" << nPartionPassFrameCount; - //LogInfo << "TrainAnaEngine Process nSamePartionIgnoreCount:" << nSamePartionIgnoreCount; - //检测到划分状态的情况下 进行跳帧处理 - //跳帧值为计算的车体通过三分之一之后的帧 - if (nPartionPassFrameCount < nSamePartionIgnoreCount) { - nPartionPassFrameCount++; - } else { - //超过跳帧进行车厢划分检测 - bPartionExist = checkPartion(matYUV, pDecodeData->i64TimeStamp); - //如果检测到车厢划分信息则检测跳帧的值 - if (bPartionExist == true) { - nPartionPassFrameCount = 0; - } - } - } - - /// write json info to file - - //先读取文本内容,追加新的信息后再写入 - //划分信息 JSON格式 - Json::Value jvPartionInfo; - //JSON保存路径 - std::string strFilePath; - //当然车厢通过的数量 - int nPartionIndex = lstPartInfo.size() - 1; - - LogInfo << "TrainAnaEngine Process nPartionIndex:" << nPartionIndex; - LogInfo << "TrainAnaEngine Process bPartionExist:" << bPartionExist; - //检测到车厢划分信息 - if ((bPartionExist == true)) { - strFilePath = strResultPath_ + pDecodeData->strTrainDate + "/" + pDecodeData->strTrainName + "/" - + std::to_string(nPartionIndex + 1) + ".txt"; - // 记录过车日期 - jvPartionInfo["trainDate"] = pDecodeData->strTrainDate; - // 记录过车时间 - jvPartionInfo["trainName"] = pDecodeData->strTrainName; - // 记录车厢节数 (索引从0开始 所以这里+1) - jvPartionInfo["trainNo"] = nPartionIndex + 1; - // 记录行车开始帧 - jvPartionInfo["startFrameId"] = lstPartInfo[nPartionIndex].startframe; - // 记录行车结束帧 - jvPartionInfo["endFrameId"] = lstPartInfo[nPartionIndex].endframe; - // 记录车厢是否完全通过 - jvPartionInfo["isEnd"] = pDecodeData->bIsEnd; - - // 首部车钩的偏移位置 (单位帧) - int headpos = 0; - // 尾部车钩的偏移位置 (单位帧) - int tailpos = (0 - nTailPixOffset); - - if (nPartionIndex == 0) - { - headpos = METHOD_BASE_WIDTH / 2; - tailpos = tailpos + headpos; - } - // 是否位右侧来车 - bool brightcome = false; - if (nStatus == TRAIN_RIGHT_RUN) - { - brightcome = true; - // 右侧来车 首部车钩从画面最右侧开始 - headpos = METHOD_BASE_WIDTH; - // 右侧来车 尾部车钩从画面最右侧+车厢宽的像素值 - tailpos = METHOD_BASE_WIDTH + nTailPixOffset; - - if (nPartionIndex == 0) - { - headpos = METHOD_BASE_WIDTH / 2; - tailpos = tailpos - headpos; - } - } - - - //LogInfo << "TrainAnaEngine Process lstPartInfo[nPartionIndex].startframe:" << lstPartInfo[nPartionIndex].startframe ; - //LogInfo << "TrainAnaEngine Process lstPartInfo[nPartionIndex].endframe:" << lstPartInfo[nPartionIndex].endframe; - //从当节车厢的开始帧到结束帧计算首部车钩和尾部车钩的偏移值 - for (int nplayframe = lstPartInfo[nPartionIndex].startframe; nplayframe <= lstPartInfo[nPartionIndex].endframe; nplayframe++) - { - Json::Value jvposInfo; - // 当前车厢的第几几帧 - int noffsetindex = (nplayframe - lstPartInfo[nPartionIndex].startframe); - // 根据车速计算车钩位置量(单位 像素) - int noffsetpos = getCouplerOffsetPosition(lstPartInfo[nPartionIndex].fspeed, noffsetindex); - // 初始化首部车钩偏移量(单位 像素) - jvposInfo["headpos"] = -1; - // 初始化尾部车钩偏移量(单位 像素) - jvposInfo["tailpos"] = -1; - - if (brightcome == false) { - // 左侧来车 - // 首部车钩和尾部车钩 每帧加 车钩偏移值 - jvposInfo["headpos"] = (headpos + noffsetpos); - jvposInfo["tailpos"] = (tailpos + noffsetpos); - } else { - // 右侧来车 - // 首部车钩和尾部车钩 每帧减 车钩偏移值 - jvposInfo["headpos"] = (headpos - noffsetpos); - jvposInfo["tailpos"] = (tailpos - noffsetpos); - } - //LogInfo << "TrainAnaEngine Process jvposInfo[headpos]" << jvposInfo["headpos"]; - // LogInfo << "TrainAnaEngine Process jvposInfo[tailpos]:" << jvposInfo["tailpos"]; - //LogInfo << "TrainAnaEngine Process jvPartionListInfo.append"; - jvPartionInfo[std::to_string(nplayframe)] = jvposInfo; - } - - PartionInfo stTempInfo; - // 开始记录新的一节车厢信息(从索引变成序号+1 ,新增一节车厢信息+1) - stTempInfo.nindex = nPartionIndex + 2; - // 上一节车厢的结束帧 - (偏移帧 = (镜头内的车体宽度/ (速度) -> 通过时间) * 帧/秒 ) 作为下一节车厢的开始帧 - int ntempOffsetFrame = lstPartInfo[nPartionIndex].endframe - (int)(((TRAIN_IN_CAMERA_WIDTH) / lstPartInfo[nPartionIndex].fspeed) * nFrameRate); - //LogInfo << "TrainAnaEngine Process ntempOffsetFrame:" << ntempOffsetFrame; - stTempInfo.startframe = (ntempOffsetFrame > nSamePartionIgnoreCount) ? ntempOffsetFrame : nSamePartionIgnoreCount; - stTempInfo.i64StartTimeStamp = pDecodeData->i64TimeStamp; - // 初始化下一节的结束帧 - //stTempInfo.endframe = 0; - - lstPartInfo.push_back(stTempInfo); - // 记录当前车厢的信息到JSON文件 - //MyUtils::getins()->WriteJsonInfo(jvPartionInfo, strFilePath); - std::shared_ptr pTrainRange = std::make_shared(); - pTrainRange->strTrainDate = jvPartionInfo["trainDate"].asString(); - pTrainRange->strTrainName = jvPartionInfo["trainName"].asString(); - pTrainRange->iTrainIndex = jvPartionInfo["trainNo"].asInt(); - pTrainRange->iStartFrameId = jvPartionInfo["startFrameId"].asInt(); - pTrainRange->iEndFrameId = jvPartionInfo["endFrameId"].asInt(); - pTrainRange->bIsEnd = jvPartionInfo["isEnd"].asBool(); - //iRet = outputQueMap_[strPort1_]->push(std::static_pointer_cast(pTrainRange)); - } - - // 有车的情况下。记录帧数:累加1 - if (nStatus != TRAIN_INIT_STATUS) - { - nLatestFrame = nLatestFrame + 1; - } - //停车或无车(初始化相关参数) - - - /* - if ((nStatus == TRAIN_INIT_STATUS - && (nStatus != TRAIN_INIT_STATUS)) || pDecodeData->bIsEnd) - { - vResetPartion(); - } - */ - // 车厢通过初始化状态 - if (pDecodeData->bIsEnd) { - vResetPartion(); - } - LogError<<"current img id "< -#include "AppCommon.h" -#include "MyYaml.h" -#include "myutils.h" -#include "EngineBase.h" -#include "EngineFactory.h" -#include "math.h" -#include "opencv2/core/core.hpp" -#include "opencv2/highgui/highgui.hpp" -#include "opencv2/imgproc/imgproc.hpp" -#include "opencv2/imgcodecs/imgcodecs.hpp" - -using namespace cv; -using namespace std; - -typedef void* LPVOID; - -class TrainAnaEngine : public ai_matrix::EngineBase -{ -public: - TrainAnaEngine(); - ~TrainAnaEngine(); - - APP_ERROR Init() override; - APP_ERROR DeInit() override; - APP_ERROR Process() override; - -private: - - //////////////////////////////变量部分////////////////////////////////////////// - //engine变量 - std::string strPort0_; - std::string strPort1_; - ai_matrix::DataSourceConfig dataSourceConfig_; - std::string strResultPath_; - std::string strResultPath_for_test; - std::string strTrainData_; - std::string strTrainName_; - - //划分算法参数和算法计算的实况数值 - std::vector lstAction; //行车检测算法基准参数集 - std::vector lstPartion; //车厢划分算法基准参数集 - std::vector lstPartInfo; //当前车次车厢划分结果 - - int nRightComeFlagR1; //最右侧检测区域状态变化的数值 - int nRightComeFlagR2; //次右侧检测区域状态变化的数值 - int nRightComeFlagR3; //第三右侧检测区域状态变化的数值 - - //动态数据 - int nStatus; //车辆状态 - int nPreStatus; //上一帧车辆状态 - int nPicAreaChangeing; //图片区域变化状态(从左往右) - int nPrePicAreaChangeing; //上一帧图片区域变化状态(从左往右) - int nSamePartionIgnoreCount; //检测到车钩跳帧数 - int nPartionPassFrameCount; //检测到车钩后通过了多少帧 - int nTailPixOffset; //尾部车钩偏移位置 - float fdefaultspeed; //缺省行车速度 - cv::Mat cvFirstImg; //比对基准图 - uint64_t ncurtime; - - //图像相关 - long nLatestFrame; //目前为止最大帧数 - int nFrameRate; //相机帧率 - unsigned int nRecIndex; //测试用记录索引 - - //////////////////////////////函数部分////////////////////////////////////////// - //基础函数 - void InitParam(); //参数初始化 - void checkAction(cv::Mat baseimg, uint64_t i64TimeStamp); //行车检测 - bool checkPartion(cv::Mat baseimg, uint64_t i64TimeStamp); //车厢划分检测 - - //功能函数 - void vformatStructAnalyseInfo(std::vector elems, AnalyseInfo &info); //读取的csv文件内容格式化到结构体变量中 - void getsetting(string strFilePath); //读取的算法参数的csv文件 - double anapicbyHist(cv::Mat baseimg, cv::Mat tarpic, int method); //根据检测物形状进行比对 - double anapicbyTemple(cv::Mat baseimg, cv::Mat tarpic, int method, cv::Point &pPos); //根据直方图进行比对 - double anapicbySpec(cv::Mat baseimg); - void vResetPartion(); //重置车厢划分信息 - int getOffsetFrame(float fspeed, int nFrameRate, int width); //根据车钩位置计算帧数 - int getCouplerOffsetPosition(float fspeed, int nframeindex); //计算车钩在图片的x坐标(预测的计算值非实际值) - int getTailPixOffset(); //计算尾部车钩在图片的x坐标(预测的计算值非实际值) - float GetPointMaxReduceMin(float dComparePoint,int index); //获取最近100帧的dComparePoint的最大值与最小值之差 - //图像处理函数 - cv::Mat mtdecodeImageDatabyFile(string path); //读取图像文件并转化为Mat格式 - cv::Mat mtdecodeImageDatabyBin(LPVOID lpimgdata, int imglen); //将图像二进制数据转化为Mat格式 - cv::Mat mtImproveImage(cv::Mat inImage, AnalyseInfo info, bool bcvread); //图像优化 根据配置进行灰度/直方图均衡/gamma变化/自定义优化 - cv::Mat mtresizeImage(cv::Mat inImage, int width, int height); //调整车厢图像尺寸为固定尺寸 - cv::Mat mtareaImage(cv::Mat inImage, int x1, int y1, int x2, int y2); //从图像获取敏感位置图像数据 - cv::Mat mtgrayImage(cv::Mat inImage, int mode); //图像灰度化 - cv::Mat mtequalizeImage(cv::Mat inImage); //图像直方图均衡化 - cv::Mat mtGammaImage(cv::Mat inImage, float fgamma); //图像gamma变换 - cv::Mat mtspecImage(cv::Mat inImage); //图像自定义优化 - std::vectorgetCompPoint(AnalyseInfo info, cv::Mat baseimg, cv::Mat tarpic); //获取图像比对值 - - -}; - -ENGINE_REGIST(TrainAnaEngine) - -#endif diff --git a/nvidia_ascend_engine/common_engine/TrainAnaEngine/TrainParationMgr.cpp b/nvidia_ascend_engine/common_engine/TrainAnaEngine/TrainParationMgr.cpp index 6f3bf53..ad62c5d 100644 --- a/nvidia_ascend_engine/common_engine/TrainAnaEngine/TrainParationMgr.cpp +++ b/nvidia_ascend_engine/common_engine/TrainAnaEngine/TrainParationMgr.cpp @@ -1,256 +1 @@ -#include "TrainParationMgr.h" - -using namespace ai_matrix; - -TrainParationMgr::TrainParationMgr() {} - -TrainParationMgr::~TrainParationMgr() {} - -APP_ERROR TrainParationMgr::Init() -{ - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - //获取主摄像头信息 - mainCfg_ = MyYaml::GetIns()->GetDataSourceConfigById(0); - - nFrameRate = 25; - InitParam(); - nTailPixOffset = getTailPixOffset(); - LogInfo << "TrainParationMgr Init ok"; - return APP_ERR_OK; -} - -APP_ERROR TrainParationMgr::DeInit() -{ - LogInfo << "TrainParationMgr DeInit ok"; - return APP_ERR_OK; -} - -int TrainParationMgr::getTailPixOffset() -{ - LogInfo << "TrainParationMgr getTailPixOffset start"; - // 单位计算 - // 帧宽像素/米 - float fframewidth_meter = ((METHOD_BASE_WIDTH * 1.0) / (TRAIN_IN_CAMERA_WIDTH)); - // 车尾车钩像素位置 - float fOffsetPosistion = TRAIN_WIDTH * fframewidth_meter; - int nretOffset = (int)fOffsetPosistion; - return nretOffset; -} - -/** -* 参数初始化(列车结束时需调用) -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void TrainParationMgr::InitParam() -{ - -} - -/** -* 计算车钩移动的像素值 -* inParam : 行车速度(单位:米/秒) -* inParam : 宽度 -* inParam : 相机帧率(单位:帧/秒) -* outParam: N/A -* return : 间隔帧 -*/ -int TrainParationMgr::getCouplerOffsetPosition(float fspeed, int nframeindex) -{ - LogInfo << "TrainAnaEngine getCouplerOffsetPosition start"; - //单位换算 - // 米/秒 -> 米/帧 - // 米/帧 = 米/秒 * 秒/帧(即:1/帧率) - float fmeter_frame = fspeed / nFrameRate; - // 米/帧 -> 像素/帧 - // 像素/帧 = 米/帧 * 像素/米 - float fpix_frame = fmeter_frame * (METHOD_BASE_WIDTH / TRAIN_IN_CAMERA_WIDTH); - - int nretPixOffet = (int)fpix_frame; - nretPixOffet = nretPixOffet * nframeindex; - LogInfo << "TrainAnaEngine getCouplerOffsetPosition nretPixOffet:" << nretPixOffet; - LogInfo << "TrainAnaEngine getCouplerOffsetPosition end"; - return nretPixOffet; -} - -/** -* 计算车钩移动的像素值 -* inParam : 行车速度(单位:米/秒) -* inParam : 宽度 -* inParam : 相机帧率(单位:帧/秒) -* outParam: N/A -* return : 间隔帧 -*/ -int TrainParationMgr::getCouplerOffsetPix(float fspeed, int noffsetPix) -{ - LogInfo << "TrainAnaEngine getCouplerOffsetPix start"; - LogInfo << "TrainAnaEngine getCouplerOffsetPix fspeed:" << fspeed; -// LogInfo << "TrainAnaEngine getCouplerOffsetPix start:" << nframeindex; - //单位换算 - // 米/秒 -> 米/帧 - // 米/帧 = 米/秒 * 秒/帧(即:1/帧率) - float fmeter_frame = fspeed / nFrameRate; - LogInfo << "TrainAnaEngine getCouplerOffsetPix fmeter_frame:" << fmeter_frame; - // 米/帧 -> 像素/帧 - // 像素/帧 = 米/帧 * 像素/米 - float fpix_frame = fmeter_frame * (METHOD_BASE_WIDTH / TRAIN_IN_CAMERA_WIDTH); - LogInfo << "TrainAnaEngine getCouplerOffsetPix fpix_frame:" << fpix_frame; - - int nretPixOffet = (int)fpix_frame; - nretPixOffet = (noffsetPix - (METHOD_BASE_WIDTH / 2)) / nretPixOffet; - LogInfo << "TrainAnaEngine getCouplerOffsetPix nretPixOffet:" << nretPixOffet; - LogInfo << "TrainAnaEngine getCouplerOffsetPix end"; - return nretPixOffet; -} - -/** -* 计算车钩从中间到边缘的间隔帧 -* inParam : 行车速度(单位:米/秒) -* inParam : 宽度 -* inParam : 相机帧率(单位:帧/秒) -* outParam: N/A -* return : 间隔帧 -*/ -int TrainParationMgr::getOffsetFrame(float fspeed, int width, int nFrameRate) -{ - LogInfo << "TrainAnaEngine getOffsetFrame start"; - LogInfo << "TrainAnaEngine getOffsetFrame fspeed:" << fspeed; - LogInfo << "TrainAnaEngine getOffsetFrame width:" << width; - LogInfo << "TrainAnaEngine getOffsetFrame nFrameRate:" << nFrameRate; - //LogInfo << "TrainAnaEngine getOffsetFrame nLatestFrame:" << nLatestFrame; - //偏移值 = (中间到边缘的宽度(米) / 速度(米/秒)->时间(秒))* 帧率(帧/秒) - float ftmp = width * (float) nFrameRate; - LogInfo << "TrainAnaEngine getOffsetFrame start end:" << ftmp; - ftmp = ftmp / fspeed; - LogInfo << "TrainAnaEngine getOffsetFrame start end:" << ftmp; - int nRet = (int) ftmp; - LogInfo << "TrainAnaEngine getOffsetFrame start end:" << nRet; - return nRet; -} - - - -APP_ERROR TrainParationMgr::Process() -{ - int iRet = APP_ERR_OK; - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } - - std::shared_ptr pPartionInfo = std::static_pointer_cast(pVoidData0); - - int nSize = lstPartInfo.size(); - int nPartionIndex = nSize - 1; - - //当然车厢通过的数量 - if (nSize == 0) { - PartionInfo stTempInfo; - stTempInfo.endframe = pPartionInfo->modelSpaceFrame; - stTempInfo.i64EndTimeStamp = pPartionInfo->i64EndTimeStamp; - stTempInfo.nindex = 1; - //第一节车厢开始帧为跳帧数,开始帧时间设置为来车时间 - stTempInfo.startframe = mainCfg_.iSkipInterval; - std::string strTemp = pPartionInfo->strTrainDate + " " + pPartionInfo->strTrainName; - stTempInfo.i64StartTimeStamp = MyUtils::getins()->GetParamTimeMilliSeconds(strTemp); - stTempInfo.fspeed = TRAIN_DEFAULT_SPEED; - stTempInfo.fLTX = (abs(pPartionInfo->fLTX - pPartionInfo->fRBX) / 2) + pPartionInfo->fLTX; - lstPartInfo.push_back(stTempInfo); - //lstPartInfo.push_back(stTempInfo); - nPartionIndex++; - } - lstPartInfo[nPartionIndex].i64EndTimeStamp = pPartionInfo->i64EndTimeStamp; - lstPartInfo[nPartionIndex].endframe = pPartionInfo->modelSpaceFrame; - // 根据开始帧时间戳和结束帧时间错 计算当节车厢的行车速度 - // 根据时间戳计算时间差 - - - float nTimePassed = (abs(lstPartInfo[nPartionIndex].i64EndTimeStamp - lstPartInfo[nPartionIndex].i64StartTimeStamp)) * 1.0; - //防止停车导致速度过小 - if(pPartionInfo->nStatus != TRAIN_PAUSE && nTimePassed <= 50000) { - lstPartInfo[nPartionIndex].fspeed = (TRAIN_WIDTH * 1000.0) /nTimePassed; - } else { - if (nPartionIndex >= 1){ - lstPartInfo[nPartionIndex].fspeed = lstPartInfo[nPartionIndex - 1].fspeed / 3; - } else { - lstPartInfo[nPartionIndex].fspeed = TRAIN_DEFAULT_SPEED / 10; - } - } - - // - //nSamePartionIgnoreCount = (nTimePassed / (3 * 5000)) * nFrameRate; - // 结束帧为当前帧再往后 (除以2的原因:中间为车钩,车钩后的车体宽度为整个镜头的宽度除以2) - lstPartInfo[nPartionIndex].bmodelconfirmed = true; - - /// write json info to file - - //先读取文本内容,追加新的信息后再写入 - //划分信息 JSON格式 - Json::Value jvPartionInfo; - //JSON保存路径 - std::string strFilePath; - - //检测到车厢划分信息 - strFilePath = strResultPath_ + pPartionInfo->strTrainDate + "/" + pPartionInfo->strTrainName + "/" - + std::to_string(nPartionIndex + 1) + ".txt"; - - LogInfo << "TrainAnaEngine Process lstPartInfo[nPartionIndex].startframe:" << lstPartInfo[nPartionIndex].startframe ; - LogInfo << "TrainAnaEngine Process lstPartInfo[nPartionIndex].endframe:" << lstPartInfo[nPartionIndex].endframe; - - PartionInfo stTempInfo; - // 开始记录新的一节车厢信息(从索引变成序号+1 ,新增一节车厢信息+1) - stTempInfo.nindex = nPartionIndex + 2; - // 上一节车厢的结束帧 - (偏移帧 = (镜头内的车体宽度/ (速度) -> 通过时间) * 帧/秒 ) 作为下一节车厢的开始帧 - int ntempOffsetFrame = lstPartInfo[nPartionIndex].endframe; - stTempInfo.startframe = ntempOffsetFrame; - stTempInfo.i64StartTimeStamp = pPartionInfo->i64EndTimeStamp; - // 初始化下一节的结束帧 - //stTempInfo.endframe = 0; - - lstPartInfo.push_back(stTempInfo); - - // 记录过车日期 - jvPartionInfo["trainDate"] = pPartionInfo->strTrainDate; - // 记录过车时间 - jvPartionInfo["trainName"] = pPartionInfo->strTrainName; - // 记录车厢节数 (索引从0开始 所以这里+1) - jvPartionInfo["trainNo"] = nPartionIndex + 1; - // 记录行车开始帧 - jvPartionInfo["startFrameId"] = lstPartInfo[nPartionIndex].startframe; - jvPartionInfo["startTimeStamp"] = lstPartInfo[nPartionIndex].i64StartTimeStamp; - // 记录行车结束帧 - jvPartionInfo["endFrameId"] = lstPartInfo[nPartionIndex].endframe; - jvPartionInfo["endTimeStamp"] = lstPartInfo[nPartionIndex].i64EndTimeStamp; - // 记录车厢是否完全通过 - jvPartionInfo["isEnd"] = pPartionInfo->bIsEnd; - - //是否是间隔模型切分的车厢 - jvPartionInfo["modelconfirmed"] = pPartionInfo->bmodelconfirmed; - - // 记录当前车厢的信息到JSON文件 - MyUtils::getins()->WriteJsonInfo(jvPartionInfo, strFilePath); - std::shared_ptr pTrainRange = std::make_shared(); - pTrainRange->strTrainDate = jvPartionInfo["trainDate"].asString(); - pTrainRange->strTrainName = jvPartionInfo["trainName"].asString(); - pTrainRange->iTrainIndex = jvPartionInfo["trainNo"].asInt(); - pTrainRange->iStartFrameId = jvPartionInfo["startFrameId"].asInt(); - pTrainRange->i64StartTimeStamp = jvPartionInfo["startTimeStamp"].asInt64(); - pTrainRange->iEndFrameId = jvPartionInfo["endFrameId"].asInt(); - pTrainRange->i64EndTimeStamp = jvPartionInfo["endTimeStamp"].asInt64(); - pTrainRange->bIsEnd = jvPartionInfo["isEnd"].asBool(); - pTrainRange->bmodelconfirmed = jvPartionInfo["modelconfirmed"].asBool(); - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pTrainRange), true); - - if (pPartionInfo->bIsEnd) { - lstPartInfo.clear(); - } - } - return APP_ERR_OK; -} +#include "TrainParationMgr.h" using namespace ai_matrix; TrainParationMgr::TrainParationMgr() {} TrainParationMgr::~TrainParationMgr() {} APP_ERROR TrainParationMgr::Init() { strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); //获取主摄像头信息 mainCfg_ = MyYaml::GetIns()->GetDataSourceConfigById(0); nFrameRate = 25; InitParam(); nTailPixOffset = getTailPixOffset(); LogInfo << "TrainParationMgr Init ok"; return APP_ERR_OK; } APP_ERROR TrainParationMgr::DeInit() { LogInfo << "TrainParationMgr DeInit ok"; return APP_ERR_OK; } int TrainParationMgr::getTailPixOffset() { LogInfo << "TrainParationMgr getTailPixOffset start"; // 单位计算 // 帧宽像素/米 float fframewidth_meter = ((METHOD_BASE_WIDTH * 1.0) / (TRAIN_IN_CAMERA_WIDTH)); // 车尾车钩像素位置 float fOffsetPosistion = TRAIN_WIDTH * fframewidth_meter; int nretOffset = (int)fOffsetPosistion; return nretOffset; } /** * 参数初始化(列车结束时需调用) * inParam : N/A * outParam: N/A * return : N/A */ void TrainParationMgr::InitParam() { } /** * 计算车钩移动的像素值 * inParam : 行车速度(单位:米/秒) * inParam : 宽度 * inParam : 相机帧率(单位:帧/秒) * outParam: N/A * return : 间隔帧 */ int TrainParationMgr::getCouplerOffsetPosition(float fspeed, int nframeindex) { LogInfo << "TrainAnaEngine getCouplerOffsetPosition start"; //单位换算 // 米/秒 -> 米/帧 // 米/帧 = 米/秒 * 秒/帧(即:1/帧率) float fmeter_frame = fspeed / nFrameRate; // 米/帧 -> 像素/帧 // 像素/帧 = 米/帧 * 像素/米 float fpix_frame = fmeter_frame * (METHOD_BASE_WIDTH / TRAIN_IN_CAMERA_WIDTH); int nretPixOffet = (int)fpix_frame; nretPixOffet = nretPixOffet * nframeindex; LogInfo << "TrainAnaEngine getCouplerOffsetPosition nretPixOffet:" << nretPixOffet; LogInfo << "TrainAnaEngine getCouplerOffsetPosition end"; return nretPixOffet; } /** * 计算车钩移动的像素值 * inParam : 行车速度(单位:米/秒) * inParam : 宽度 * inParam : 相机帧率(单位:帧/秒) * outParam: N/A * return : 间隔帧 */ int TrainParationMgr::getCouplerOffsetPix(float fspeed, int noffsetPix) { LogInfo << "TrainAnaEngine getCouplerOffsetPix start"; LogInfo << "TrainAnaEngine getCouplerOffsetPix fspeed:" << fspeed; // LogInfo << "TrainAnaEngine getCouplerOffsetPix start:" << nframeindex; //单位换算 // 米/秒 -> 米/帧 // 米/帧 = 米/秒 * 秒/帧(即:1/帧率) float fmeter_frame = fspeed / nFrameRate; LogInfo << "TrainAnaEngine getCouplerOffsetPix fmeter_frame:" << fmeter_frame; // 米/帧 -> 像素/帧 // 像素/帧 = 米/帧 * 像素/米 float fpix_frame = fmeter_frame * (METHOD_BASE_WIDTH / TRAIN_IN_CAMERA_WIDTH); LogInfo << "TrainAnaEngine getCouplerOffsetPix fpix_frame:" << fpix_frame; int nretPixOffet = (int)fpix_frame; nretPixOffet = (noffsetPix - (METHOD_BASE_WIDTH / 2)) / nretPixOffet; LogInfo << "TrainAnaEngine getCouplerOffsetPix nretPixOffet:" << nretPixOffet; LogInfo << "TrainAnaEngine getCouplerOffsetPix end"; return nretPixOffet; } /** * 计算车钩从中间到边缘的间隔帧 * inParam : 行车速度(单位:米/秒) * inParam : 宽度 * inParam : 相机帧率(单位:帧/秒) * outParam: N/A * return : 间隔帧 */ int TrainParationMgr::getOffsetFrame(float fspeed, int width, int nFrameRate) { LogInfo << "TrainAnaEngine getOffsetFrame start"; LogInfo << "TrainAnaEngine getOffsetFrame fspeed:" << fspeed; LogInfo << "TrainAnaEngine getOffsetFrame width:" << width; LogInfo << "TrainAnaEngine getOffsetFrame nFrameRate:" << nFrameRate; //LogInfo << "TrainAnaEngine getOffsetFrame nLatestFrame:" << nLatestFrame; //偏移值 = (中间到边缘的宽度(米) / 速度(米/秒)->时间(秒))* 帧率(帧/秒) float ftmp = width * (float) nFrameRate; LogInfo << "TrainAnaEngine getOffsetFrame start end:" << ftmp; ftmp = ftmp / fspeed; LogInfo << "TrainAnaEngine getOffsetFrame start end:" << ftmp; int nRet = (int) ftmp; LogInfo << "TrainAnaEngine getOffsetFrame start end:" << nRet; return nRet; } APP_ERROR TrainParationMgr::Process() { int iRet = APP_ERR_OK; while (!isStop_) { std::shared_ptr pVoidData0 = nullptr; inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); //1ms continue; } std::shared_ptr pPartionInfo = std::static_pointer_cast(pVoidData0); int nSize = lstPartInfo.size(); int nPartionIndex = nSize - 1; //当然车厢通过的数量 if (nSize == 0) { PartionInfo stTempInfo; stTempInfo.endframe = pPartionInfo->modelSpaceFrame; stTempInfo.i64EndTimeStamp = pPartionInfo->i64EndTimeStamp; stTempInfo.nindex = 1; //第一节车厢开始帧为跳帧数,开始帧时间设置为来车时间 stTempInfo.startframe = mainCfg_.iSkipInterval; std::string strTemp = pPartionInfo->strTrainDate + " " + pPartionInfo->strTrainName; stTempInfo.i64StartTimeStamp = MyUtils::getins()->GetParamTimeMilliSeconds(strTemp); // LogWarn << "日期:" << strTemp << " -- 时间戳:" << stTempInfo.i64StartTimeStamp; stTempInfo.fspeed = TRAIN_DEFAULT_SPEED; stTempInfo.fLTX = (abs(pPartionInfo->fLTX - pPartionInfo->fRBX) / 2) + pPartionInfo->fLTX; lstPartInfo.push_back(stTempInfo); //lstPartInfo.push_back(stTempInfo); nPartionIndex++; } lstPartInfo[nPartionIndex].i64EndTimeStamp = pPartionInfo->i64EndTimeStamp; lstPartInfo[nPartionIndex].endframe = pPartionInfo->modelSpaceFrame; // 根据开始帧时间戳和结束帧时间错 计算当节车厢的行车速度 // 根据时间戳计算时间差 float nTimePassed = (abs(lstPartInfo[nPartionIndex].i64EndTimeStamp - lstPartInfo[nPartionIndex].i64StartTimeStamp)) * 1.0; //防止停车导致速度过小 if(pPartionInfo->nStatus != TRAIN_PAUSE && nTimePassed <= 50000) { lstPartInfo[nPartionIndex].fspeed = (TRAIN_WIDTH * 1000.0) /nTimePassed; } else { if (nPartionIndex >= 1){ lstPartInfo[nPartionIndex].fspeed = lstPartInfo[nPartionIndex - 1].fspeed / 3; } else { lstPartInfo[nPartionIndex].fspeed = TRAIN_DEFAULT_SPEED / 10; } } // //nSamePartionIgnoreCount = (nTimePassed / (3 * 5000)) * nFrameRate; // 结束帧为当前帧再往后 (除以2的原因:中间为车钩,车钩后的车体宽度为整个镜头的宽度除以2) lstPartInfo[nPartionIndex].bmodelconfirmed = true; /// write json info to file //先读取文本内容,追加新的信息后再写入 //划分信息 JSON格式 Json::Value jvPartionInfo; //JSON保存路径 std::string strFilePath; //检测到车厢划分信息 strFilePath = strResultPath_ + pPartionInfo->strTrainDate + "/" + pPartionInfo->strTrainName + "/" + std::to_string(nPartionIndex + 1) + ".txt"; LogInfo << "TrainAnaEngine Process lstPartInfo[nPartionIndex].startframe:" << lstPartInfo[nPartionIndex].startframe ; LogInfo << "TrainAnaEngine Process lstPartInfo[nPartionIndex].endframe:" << lstPartInfo[nPartionIndex].endframe; PartionInfo stTempInfo; // 开始记录新的一节车厢信息(从索引变成序号+1 ,新增一节车厢信息+1) stTempInfo.nindex = nPartionIndex + 2; // 上一节车厢的结束帧 - (偏移帧 = (镜头内的车体宽度/ (速度) -> 通过时间) * 帧/秒 ) 作为下一节车厢的开始帧 int ntempOffsetFrame = lstPartInfo[nPartionIndex].endframe; stTempInfo.startframe = ntempOffsetFrame; stTempInfo.i64StartTimeStamp = pPartionInfo->i64EndTimeStamp; // 初始化下一节的结束帧 //stTempInfo.endframe = 0; lstPartInfo.push_back(stTempInfo); // 记录过车日期 jvPartionInfo["trainDate"] = pPartionInfo->strTrainDate; // 记录过车时间 jvPartionInfo["trainName"] = pPartionInfo->strTrainName; // 记录车厢节数 (索引从0开始 所以这里+1) jvPartionInfo["trainNo"] = nPartionIndex + 1; // 记录行车开始帧 jvPartionInfo["startFrameId"] = lstPartInfo[nPartionIndex].startframe; jvPartionInfo["startTimeStamp"] = lstPartInfo[nPartionIndex].i64StartTimeStamp; // 记录行车结束帧 jvPartionInfo["endFrameId"] = lstPartInfo[nPartionIndex].endframe; jvPartionInfo["endTimeStamp"] = lstPartInfo[nPartionIndex].i64EndTimeStamp; // 记录车厢是否完全通过 jvPartionInfo["isEnd"] = pPartionInfo->bIsEnd; //是否是间隔模型切分的车厢 jvPartionInfo["modelconfirmed"] = pPartionInfo->bmodelconfirmed; // 记录当前车厢的信息到JSON文件 MyUtils::getins()->WriteJsonInfo(jvPartionInfo, strFilePath); std::shared_ptr pTrainRange = std::make_shared(); pTrainRange->strTrainDate = jvPartionInfo["trainDate"].asString(); pTrainRange->strTrainName = jvPartionInfo["trainName"].asString(); pTrainRange->iTrainIndex = jvPartionInfo["trainNo"].asInt(); pTrainRange->iStartFrameId = jvPartionInfo["startFrameId"].asInt(); pTrainRange->i64StartTimeStamp = jvPartionInfo["startTimeStamp"].asInt64(); pTrainRange->iEndFrameId = jvPartionInfo["endFrameId"].asInt(); pTrainRange->i64EndTimeStamp = jvPartionInfo["endTimeStamp"].asInt64(); pTrainRange->bIsEnd = jvPartionInfo["isEnd"].asBool(); pTrainRange->bmodelconfirmed = jvPartionInfo["modelconfirmed"].asBool(); iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pTrainRange)); if (pPartionInfo->bIsEnd) { lstPartInfo.clear(); } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/common_engine/TransEngine/TransTrainEngine.cpp b/nvidia_ascend_engine/common_engine/TransEngine/TransTrainEngine.cpp index dd13320..0854254 100644 --- a/nvidia_ascend_engine/common_engine/TransEngine/TransTrainEngine.cpp +++ b/nvidia_ascend_engine/common_engine/TransEngine/TransTrainEngine.cpp @@ -1,842 +1 @@ -#include "TransTrainEngine.h" -#include "myutils.h" -#include -#include - -using namespace ai_matrix; - -namespace -{ - //按照x坐标排列 - bool CompareX(const SingleData &v1, const SingleData &v2) - { - return (v1.fLTX < v2.fLTX); - } - - //自定义比较规则 - bool CmpVec(const pair &P1, const pair &P2) - { - return P1.second < P2.second; - } -} - -TransTrainEngine::TransTrainEngine() {} - -TransTrainEngine::~TransTrainEngine() {} - -APP_ERROR TransTrainEngine::Init() -{ - bUseEngine_ = MyUtils::getins()->ChkIsHaveTarget("NUM"); - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - modelConfig_ = MyYaml::GetIns()->GetModelConfig("TrainStepTwoEngine"); - strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); - - //读取模型参数信息文件 - Json::Value jvModelInfo; - if (!MyUtils::getins()->ReadJsonInfo(jvModelInfo, modelConfig_.strModelInfoPath)) - { - LogError << "ModelInfoPath:" << modelConfig_.strModelInfoPath << " doesn't exist or read failed!"; - return APP_ERR_COMM_NO_EXIST; - } - for (int i = 0; i < jvModelInfo["class"].size(); i++) - { - vecClassNames_.push_back(jvModelInfo["class"][i].asString()); - } - - // 获取几个摄像头识别车号 - std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); - for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) - { - iSkipInterval_ = iter->second.iSkipInterval; - if (iter->second.strTarget.find("NUM") != std::string::npos) - { - LogDebug << "sourceid:" << iter->first << " deal Num"; - mapDataSourceIsEnd_[iter->first] = false; - } - } - - InitParam(); - LogInfo << "TransTrainEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR TransTrainEngine::DeInit() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - LogInfo << "TransTrainEngine DeInit ok"; - return APP_ERR_OK; -} - -/** -* 初始化参数信息 -* inParam : N/A -* outParam: N/A -* return : N/A -*/ -void TransTrainEngine::InitParam() -{ - for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) - { - iter->second = false; - } - mapNumInfo_.clear(); - mapPreFrameId_.clear(); -} - -/** - * 校验车型是否符合验证 - * inParam : int classId 大框类别id - * : const std::string &trainNum 车型字符信息 - * outParam: N/A - * return : true:符合; false:不符合 - */ -bool TransTrainEngine::AuthTransNum(int classId, const std::string &trainNum) -{ -// LogInfo << "classId:" << classId << " trainNum:" << trainNum; - switch (classId) - { - case TRAIN_HEAD: // 车头上的编号 - break; - case K_TRAIN_NUM: // 编号 矿车、煤炭漏斗车(兖矿自备、枣矿自备) - { - if (trainNum == "K13" || trainNum == "KM100AH") - { - return true; - } - std::regex reg; - switch (trainNum.size()) - { - case 4: - reg = "^K[1FMZ]{1}[36789]{1}[018ABKNT]{1}"; - break; - case 5: - reg = "^K[1M]{1}[368]{1}[1ABDN]{1}[AGKNT]{1}"; - break; - case 6: - reg = "^K[MF]{1}[69]{1}[80]{1}A[KH]{1}"; - break; - default: - LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; - return false; - } - return std::regex_match(trainNum, reg); - } - case C_TRAIN_NUM: // 敞车 特殊车型 C5D CF CFK - { - if (trainNum == "CF" || trainNum == "C62A(N)") - { - return true; - } - std::regex reg; - switch (trainNum.size()) - { - case 3: - reg = "^C[15678F]{1}[0123456DK]{1}"; - break; - case 4: - reg = "^C[1678]{1}[012346]{1}[0ABCEFHKMTY]{1}"; - break; - case 5: - reg = "^C[1678]{1}[01246]{1}[0ABCEY]{1}[KAFHNT]{1}"; - break; - case 6: - reg = "^C[17]{1}0[0E]{1}[A-]{1}[AH]{1}"; - break; - default: - LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; - return false; - } - return std::regex_match(trainNum, reg); - } - case P_TRAIN_NUM: // 编号 棚车 - { - if (trainNum == "P70(H)" || trainNum == "P62(N)") - { - return true; - } - std::regex reg; - switch (trainNum.size()) - { - case 3: - reg = "^P[1678]{1}[012345]{1}"; - break; - case 4: - reg = "^P[678]{1}[023456]{1}[ABHKNST]{1}"; - break; - case 5: - reg = "^P6[24]{1}[ANG]{1}[KT]{1}"; - break; - default: - LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; - return false; - } - return std::regex_match(trainNum, reg); - } - case G_TRAIN_NUM: // 编号 罐车 - { - if (trainNum == "GY100SK") - { - return true; - } - std::regex reg; - switch (trainNum.size()) - { - case 2: - reg = "^G[HLS]{1}"; - break; - case 3: - reg = "^[GL]{1}[1567HL]{1}[01246789K]{1}"; - break; - case 4: - reg = "^[GU]{1}[167FJLNQSWY]{1}[170689]{1}[KSABDGTM075W]{1}"; - break; - case 5: - reg = "^[GU]{1}[17FHNQY6]{1}[1706A89]{1}[SBDAM057W]{1}[KEHTB0ZAS]{1}"; - break; - case 6: - reg = "^[UG]{1}[6YH]{1}[1489A]{1}[057W]{1}[Z0LSA]{1}[KSAT]{1}"; - break; - default: - LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; - return false; - } - return std::regex_match(trainNum, reg); - } - case NX_TRAIN_NUM: // 编号 平车 - { - if (trainNum == "N6") - { - return true; - } - std::regex reg; - switch (trainNum.size()) - { - case 3: - reg = "^[NQX]{1}[1234678T]{1}[0124567HK]{1}"; - break; - case 4: - reg = "^[BNX]{1}[16X]{1}[17BC]{1}[07AGKT]{1}"; - break; - case 5: - reg = "^[NX]{1}[16NX]{1}[17C]{1}[07AGT]{1}[KTABH]{1}"; - break; - case 6: - reg = "^NX17[AB]{1}[KTH]{1}"; - break; - default: - LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; - return false; - } - return std::regex_match(trainNum, reg); - } - case J_TRAIN_NUM: // 编号 牲畜车 特种车 - { - if (trainNum == "TP64GK") - { - return true; - } - std::regex reg; - switch (trainNum.size()) - { - case 2: - reg = "^[DT]{1}[2678]{1}"; - break; - case 3: - reg = "^[DST]{1}[12346789LQ]{1}[012578ADFGP]{1}"; - break; - case 4: - reg = "^[DJNT]{1}[12356AFKQS]{1}[012345678DFQS]{1}[A12345679GHKQ]{1}"; - break; - case 5: - reg = "^[DJQT]{1}[2KNSH1P]{1}[613XQ2]{1}[A761234B]{1}[KA70G]{1}"; - break; - default: - LogWarn << "Unknow train, classId: " << classId << " trainNum:" << trainNum; - return false; - } - return std::regex_match(trainNum, reg); - } - default: - LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; - return false; - } - return true; -} - -/** -* 过滤第二步字段代号的误识别 -* inParam : std::vector &vecObjs -* : TargetMaxLen iMaxLen -* outParam: N/A -* return : N/A -*/ -void TransTrainEngine::FilterSingleData(std::vector &vecObjs, TargetMaxLen iMaxLen) -{ - /*误识别场景 - 例: 车厢容积属性只有2位时,但因误识别导致自重的某个字符字段代号错误,划归到容积中,这样实际只有2位的容积变为3位。导致选优时错误。 - 只处理1个字段代号的误识别,若有多个字段代号同时错误,无法区分哪些字符字段代号是正确的。(字段代号误识别较多时,则增强模型训练) - - 排除一个最大和最小值后计算平局坐标值,每个框左上角和平局值左上角高度差大于平局值的高度则剔除. - */ - if (vecObjs.size() != iMaxLen || vecObjs.size() <= 2) - { - return; - } - - std::deque dqObjs(vecObjs.begin(), vecObjs.end()); - std::sort(dqObjs.begin(), dqObjs.end(), [](SingleData &a, SingleData &b) - { - return a.fLTY < b.fLTY; - }); - dqObjs.pop_front(); - dqObjs.pop_back(); - - SingleData singleDataAvg; - for (auto iter = dqObjs.begin(); iter != dqObjs.end(); iter++) - { - singleDataAvg.fLTX += iter->fLTX; - singleDataAvg.fLTY += iter->fLTY; - singleDataAvg.fRBX += iter->fRBX; - singleDataAvg.fRBY += iter->fRBY; - } - singleDataAvg.fLTX = singleDataAvg.fLTX / dqObjs.size(); - singleDataAvg.fLTY = singleDataAvg.fLTY / dqObjs.size(); - singleDataAvg.fRBX = singleDataAvg.fRBX / dqObjs.size(); - singleDataAvg.fRBY = singleDataAvg.fRBY / dqObjs.size(); - float fAvgHeight = singleDataAvg.fRBY - singleDataAvg.fLTY; - - //剔除位置错误的字符信息 - for (auto iter = vecObjs.begin(); iter != vecObjs.end(); iter++) - { - float fTemp = fabs(iter->fLTY - singleDataAvg.fLTY); - if (fTemp > (fAvgHeight - 5)) - { - std::string strOne = vecClassNames_.at(iter->iClassId); - LogWarn << "engineId:" << engineId_ << " " << strOne << " Line wrong "; - vecObjs.erase(iter); - break; - } - } -} - -/** -* 属性框内容转换 -* inParam : std::map> &mapLine -* outParam: TransSubData &transSubData -* return : N/A -*/ -void TransTrainEngine::TransPro(TransSubData &transSubData, std::map> &mapLine) -{ - //载重 - if (mapLine.find(0) != mapLine.end()) - { - TransInfo loadInfo; - loadInfo.iLine = 0; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(0).size(); j++) - { - //过滤非数字 - std::string strOne = vecClassNames_.at(mapLine.at(0).at(j).iClassId); - if (strOne[0] < '0' || strOne[0] > '9') - { - LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in load"; - continue; - } - strTemp += strOne; - loadInfo.vecValue.emplace_back(strOne); - loadInfo.vecScore.emplace_back(mapLine.at(0).at(j).fScore); - transSubData.fScoreSum += mapLine.at(0).at(j).fScore; - } - - //匹配正则表达式 - //std::regex reg("^[0-9]{2}"); - std::regex reg("^[1,4,5,6,7,8,9]{1}[0-9]{1,2}$"); //(第1位:棚车:4 5; K自备车:1 5 7 8 9; 平车:7; 罐车:6 7; 敞车:6 7 8) - if (std::regex_match(strTemp, reg)) - { - loadInfo.IsChkFlag = true; - } - transSubData.vecTransInfo.emplace_back(loadInfo); - } - - //自重 - if (mapLine.find(1) != mapLine.end()) - { - FilterSingleData(mapLine.at(1), SELF_MAXLEN); - TransInfo selfInfo; - selfInfo.iLine = 1; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(1).size(); j++) - { - //过滤非数字 - std::string strOne = vecClassNames_.at(mapLine.at(1).at(j).iClassId); - if (strOne[0] < '0' || strOne[0] > '9') - { - LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in self"; - continue; - } - strTemp += strOne; - selfInfo.vecValue.emplace_back(strOne); - selfInfo.vecScore.emplace_back(mapLine.at(1).at(j).fScore); - transSubData.fScoreSum += mapLine.at(1).at(j).fScore; - } - - //匹配正则表达式 - std::regex reg("^[1,2,3]{1}[0-9]{1,2}$"); - if (std::regex_match(strTemp, reg)) - { - selfInfo.IsChkFlag = true; - } - transSubData.vecTransInfo.emplace_back(selfInfo); - } - - //容积 - if (mapLine.find(2) != mapLine.end()) - { - FilterSingleData(mapLine.at(2), VOLUME_MAXLEN); - TransInfo volumeInfo; - volumeInfo.iLine = 2; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(2).size(); j++) - { - //过滤非数字 - std::string strOne = vecClassNames_.at(mapLine.at(2).at(j).iClassId); - if (strOne[0] < '0' || strOne[0] > '9') - { - LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in volume"; - continue; - } - strTemp += strOne; - volumeInfo.vecValue.emplace_back(strOne); - volumeInfo.vecScore.emplace_back(mapLine.at(2).at(j).fScore); - transSubData.fScoreSum += mapLine.at(2).at(j).fScore; - } - - //匹配正则表达式 - //std::regex reg("^[0-9]{2,3}$"); - std::regex reg("^[1,6,7,8,9]{1}[0-9]{1,2}$"); //(第1位:棚车:1; K自备车:1或9; 罐车:6或7; 敞车:7或8) - if (std::regex_match(strTemp, reg)) - { - volumeInfo.IsChkFlag = true; - } - transSubData.vecTransInfo.emplace_back(volumeInfo); - } - - //换长 - if (mapLine.find(3) != mapLine.end()) - { - TransInfo changeInfo; - changeInfo.iLine = 3; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(3).size(); j++) - { - //过滤非数字 - std::string strOne = vecClassNames_.at(mapLine.at(3).at(j).iClassId); - if (strOne[0] < '0' || strOne[0] > '9') - { - LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in change"; - continue; - } - strTemp += strOne; - changeInfo.vecValue.emplace_back(strOne); - changeInfo.vecScore.emplace_back(mapLine.at(3).at(j).fScore); - transSubData.fScoreSum += mapLine.at(3).at(j).fScore; - } - - //匹配正则表达式 - //std::regex reg("^[0-9]{2}$"); - std::regex reg("^[1]{1}[0-9]{1}$"); - if (std::regex_match(strTemp, reg)) - { - changeInfo.IsChkFlag = true; - } - transSubData.vecTransInfo.emplace_back(changeInfo); - } - - //罐车容量计表 - if (mapLine.find(4) != mapLine.end()) - { - TransInfo volumeSurfaceInfo; - volumeSurfaceInfo.iLine = 4; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(4).size(); j++) - { - strTemp += vecClassNames_.at(mapLine.at(4).at(j).iClassId); - volumeSurfaceInfo.vecValue.emplace_back(vecClassNames_.at(mapLine.at(4).at(j).iClassId)); - volumeSurfaceInfo.vecScore.emplace_back(mapLine.at(4).at(j).fScore); - transSubData.fScoreSum += mapLine.at(4).at(j).fScore; - } - - volumeSurfaceInfo.IsChkFlag = true; //暂不校验 - transSubData.vecTransInfo.emplace_back(volumeSurfaceInfo); - } -} - -/** -* 车号框内容转换 -* inParam : std::map> &mapLine -* outParam: TransSubData &transSubData -* return : N/A -*/ -void TransTrainEngine::TransNum(TransSubData &transSubData, std::map> &mapLine) -{ - //车型 - if (mapLine.find(0) != mapLine.end()) - { - TransInfo typeInfo; - typeInfo.iLine = 0; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(0).size(); j++) - { - std::string strOne = vecClassNames_.at(mapLine.at(0).at(j).iClassId); - - /*20230117 该逻辑删除,有厂区发现有C70C DF4DD等车型。 针对重复印刷的场景需想其他方法处理。 - //注:车型多次印刷会导致之前印刷的个别字符会识别,导致最终的识别内容变多。针对车型没有重复字符的特点,因此剔除重复的字符 - auto iter = find(typeInfo.vecValue.begin(), typeInfo.vecValue.end(), strOne); - if (iter != typeInfo.vecValue.end()) - { - LogWarn << "Possible duplicate recognition strOne:" << strOne; - continue; - } - */ - - strTemp += strOne; - typeInfo.vecValue.emplace_back(strOne); - typeInfo.vecScore.emplace_back(mapLine.at(0).at(j).fScore); - transSubData.fScoreSum += mapLine.at(0).at(j).fScore; - } - - //校验车型是否符合验证 - typeInfo.IsChkFlag = AuthTransNum(transSubData.iBigClassId, strTemp); - - transSubData.vecTransInfo.emplace_back(typeInfo); - } - - //编号 - if (mapLine.find(1) != mapLine.end()) - { - TransInfo numInfo; - numInfo.iLine = 1; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(1).size(); j++) - { - std::string strOne = vecClassNames_.at(mapLine.at(1).at(j).iClassId); - //过滤非数字 - if (strOne[0] < '0' || strOne[0] > '9') - { - LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in num"; - continue; - } - strTemp += strOne; - numInfo.vecValue.emplace_back(strOne); - numInfo.vecScore.emplace_back(mapLine.at(1).at(j).fScore); - transSubData.fScoreSum += mapLine.at(1).at(j).fScore; - } - - //匹配正则表达式 - std::regex reg("^[0-9]{7}$"); //车厢编号,固定7位 - if (std::regex_match(strTemp, reg)) - { - numInfo.IsChkFlag = true; - } - - transSubData.vecTransInfo.emplace_back(numInfo); - } -} - -/** -* 车头框内容转换 -* inParam : std::map> &mapLine -* outParam: TransSubData &transSubData -* return : N/A -*/ -void TransTrainEngine::TransHead(TransSubData &transSubData, std::map> &mapLine) -{ - //车头型号 - if (mapLine.find(0) != mapLine.end()) - { - TransInfo typeInfo; - typeInfo.iLine = 0; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(0).size(); j++) - { - strTemp += vecClassNames_.at(mapLine.at(0).at(j).iClassId); - typeInfo.vecValue.emplace_back(vecClassNames_.at(mapLine.at(0).at(j).iClassId)); - typeInfo.vecScore.emplace_back(mapLine.at(0).at(j).fScore); - transSubData.fScoreSum += mapLine.at(0).at(j).fScore; - } - - //不做结果校验,IsChkFlag默认为true - typeInfo.IsChkFlag = true; - transSubData.vecTransInfo.emplace_back(typeInfo); - } - - //车头编号 - if (mapLine.find(1) != mapLine.end()) - { - TransInfo numInfo; - numInfo.iLine = 1; - std::string strTemp = ""; - for (auto j = 0; j < mapLine.at(1).size(); j++) - { - std::string strOne = vecClassNames_.at(mapLine.at(1).at(j).iClassId); - //过滤非数字 - if (strOne[0] < '0' || strOne[0] > '9') - { - LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in headnum"; - continue; - } - strTemp += strOne; - numInfo.vecValue.emplace_back(strOne); - numInfo.vecScore.emplace_back(mapLine.at(1).at(j).fScore); - transSubData.fScoreSum += mapLine.at(1).at(j).fScore; - } - - //不做结果校验,IsChkFlag默认为true - numInfo.IsChkFlag = true; - transSubData.vecTransInfo.emplace_back(numInfo); - } -} - - -/** -* 记录在画面中间位置识别的车号 -* inParam : const TransSubData &transSubData 车号信息 - : const std::shared_ptr &pProcessData 帧数据 -* outParam: N/A -* return : N/A -*/ -void TransTrainEngine::RecordNum(const TransSubData &transSubData, const std::shared_ptr &pProcessData) -{ - int iCenterX = transSubData.step1Location.fLTX + (transSubData.step1Location.fRBX - transSubData.step1Location.fLTX) / 2; - int iImgL = pProcessData->iWidth / 3; - int iImgR = pProcessData->iWidth / 3 * 2; - if (iCenterX <= iImgL || iCenterX >= iImgR) - { - return; - } - - std::string strValue; - for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) - { - TransInfo transInfo = transSubData.vecTransInfo[i]; - if (transInfo.iLine != 1) - { - continue; - } - for (size_t j = 0; j < transInfo.vecValue.size(); j++) - { - strValue += transInfo.vecValue[j]; - } - } - - bool bIntervalFlag = ((int)(pProcessData->iFrameId - mapPreFrameId_[pProcessData->iDataSource]) > iSkipInterval_ * 2); - if (mapNumInfo_[pProcessData->iDataSource].find(strValue) == mapNumInfo_[pProcessData->iDataSource].end()) - { - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " NUM:" << strValue - << " bIntervalFlag:" << bIntervalFlag; - if (bIntervalFlag) - { - mapNumInfo_[pProcessData->iDataSource][strValue] = pProcessData->iFrameId; - } - } - LogDebug << "sourceid:" << pProcessData->iDataSource << " preframeid:" << mapPreFrameId_[pProcessData->iDataSource] - << " frameid:" << pProcessData->iFrameId << " mapsize:" << mapNumInfo_[pProcessData->iDataSource].size(); - mapPreFrameId_[pProcessData->iDataSource] = pProcessData->iFrameId; -} - -/** -* 保存中间位置识别车号信息到csv中 -* inParam : std::shared_ptr pTrain :列车信息 -* outParam: -* return : true/false -*/ -bool TransTrainEngine::SaveMiddleNumCsv(const std::vector> &vecNums, const std::shared_ptr &pProcessData, - int iSourceId) -{ - //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/) - std::string strTrainPath = strResultPath_ + pProcessData->strTrainDate + "/" + pProcessData->strTrainName + "/"; - if (!MyUtils::getins()->CreateDirPath(strTrainPath)) - { - LogError << "fail CreateDirPath:" << strTrainPath; - return false; - } - - //2. 保存csv - std::string strCsvName = pProcessData->strTrainDate + pProcessData->strTrainName + "_" + std::to_string(iSourceId) + ".csv"; - strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); - strTrainPath += strCsvName; - - try - { - // 写文件 - std::ofstream outFile; - outFile.open(strTrainPath, std::ios::app); - - outFile << "num" << ',' << "frameid" << std::endl; - - for (auto iterVec = vecNums.begin(); iterVec != vecNums.end(); iterVec++) - { - outFile << iterVec->first << "," << iterVec->second << std::endl; - } - outFile.close(); - } - catch (const std::exception &) - { - LogError << "fail open dirPath:" << strTrainPath; - return false; - } - return true; -} - -/** -* push数据到队列,队列满时则休眠一段时间再push -* inParam : const std::string strPort push的端口 - : const std::shared_ptr &pProcessData push的数据 -* outParam: N/A -* return : N/A -*/ -void TransTrainEngine::PushData(const std::string &strPort, const std::shared_ptr &pProcessData) -{ - while (true) - { - int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pProcessData)); - if (iRet != 0) - { - LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet; - if (iRet == 2) - { - usleep(10000); // 10ms - continue; - } - } - break; - } -} - -APP_ERROR TransTrainEngine::Process() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - int iRet = APP_ERR_OK; - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1000); //1ms - continue; - } - - std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); - //第2步后处理结果 - std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); - - //最后一节的最后一帧为整列车的结束 - if (pProcessData->bIsTrainEnd && pProcessData->bIsEnd) - { - mapDataSourceIsEnd_[pProcessData->iDataSource] = true; - } - - //组织输出数据 - std::shared_ptr pTransData = std::make_shared(); - for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) - { - PostSubData postSubData = pPostData->vecPostSubData[i]; - - //按字段代号分类 - std::map> mapLine; - for (size_t j = 0; j < postSubData.vecSingleData.size(); j++) - { - mapLine[postSubData.vecSingleData.at(j).iLine].push_back(postSubData.vecSingleData.at(j)); - } - - //每一行按x坐标排序 - for (auto it = mapLine.begin(); it != mapLine.end(); it++) - { - std::sort(it->second.begin(), it->second.end(), CompareX); - - std::string strTemp = ""; - for (auto j = 0; j < it->second.size(); j++) - { - strTemp += vecClassNames_.at(it->second.at(j).iClassId); - } -// LogDebug << "step2 char sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId -// << " bigclassId:" << postSubData.iBigClassId << " line:" << it->first << "," << strTemp; - } - - TransSubData transSubData; - transSubData.iBigClassId = postSubData.iBigClassId; - transSubData.iCarXH = postSubData.iCarXH; - transSubData.step1Location = postSubData.step1Location; - //按大类处理 - if(postSubData.iBigClassId == 1) - { - TransPro(transSubData, mapLine); - } - else if (postSubData.iBigClassId >= 2 && postSubData.iBigClassId <= 6) - { - TransNum(transSubData, mapLine); - RecordNum(transSubData, pProcessData); - } - else if(postSubData.iBigClassId == 0) - { - TransHead(transSubData, mapLine); - RecordNum(transSubData, pProcessData); - } - else - { - continue; - } - - pTransData->vecTransSubData.emplace_back(transSubData); - } - - //是否全部结束 - bool bAllEnd = true; - for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) - { - bAllEnd = bAllEnd && iter->second; - } - - pProcessData->pVoidData = std::static_pointer_cast(pTransData); - - LogInfo << " FrameID:" << pProcessData->iFrameId << " 来车时间:" << pProcessData->strTrainName; - // push端口0,车号属性选优处理 - PushData(strPort0_, pProcessData); - - if (bAllEnd) - { - for(auto iter = mapNumInfo_.begin(); iter != mapNumInfo_.end(); iter++) - { - std::vector> vecTemp(iter->second.begin(), iter->second.end()); - sort(vecTemp.begin(), vecTemp.end(), CmpVec); //按帧号排序 - SaveMiddleNumCsv(vecTemp, pProcessData, iter->first); - - // for(auto iterVec = vecTemp.begin(); iterVec != vecTemp.end(); iterVec++) - // { - // LogDebug << "sourceid:" << iter->first << " num:" << iterVec->first << " frameid:" << iterVec->second; - // } - } - //转个json数组发送后面用于比较。(车厢个数和该json数据是否相等,相等则不处理。不相等则挨个比较下。) - - //初始化参数变量 - InitParam(); - } - } - - return APP_ERR_OK; -} +#include "TransTrainEngine.h" #include "myutils.h" #include #include using namespace ai_matrix; namespace { //按照x坐标排列 bool CompareX(const SingleData &v1, const SingleData &v2) { return (v1.fLTX < v2.fLTX); } //自定义比较规则 bool CmpVec(const pair &P1, const pair &P2) { return P1.second < P2.second; } } TransTrainEngine::TransTrainEngine() {} TransTrainEngine::~TransTrainEngine() {} APP_ERROR TransTrainEngine::Init() { bUseEngine_ = MyUtils::getins()->ChkIsHaveTarget("NUM"); if (!bUseEngine_) { LogWarn << "engineId_:" << engineId_ << " not use engine"; return APP_ERR_OK; } strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; modelConfig_ = MyYaml::GetIns()->GetModelConfig("TrainStepTwoEngine"); strResultPath_ = MyYaml::GetIns()->GetPathValue("gc_result_path"); //读取模型参数信息文件 Json::Value jvModelInfo; if (!MyUtils::getins()->ReadJsonInfo(jvModelInfo, modelConfig_.strModelInfoPath)) { LogError << "ModelInfoPath:" << modelConfig_.strModelInfoPath << " doesn't exist or read failed!"; return APP_ERR_COMM_NO_EXIST; } for (int i = 0; i < jvModelInfo["class"].size(); i++) { vecClassNames_.push_back(jvModelInfo["class"][i].asString()); } // 获取几个摄像头识别车号 std::map mapUseDataSouceCfg = MyYaml::GetIns()->GetUseDataSourceConfig(); for (auto iter = mapUseDataSouceCfg.begin(); iter != mapUseDataSouceCfg.end(); iter++) { iSkipInterval_ = iter->second.iSkipInterval; if (iter->second.strTarget.find("NUM") != std::string::npos) { LogDebug << "sourceid:" << iter->first << " deal Num"; mapDataSourceIsEnd_[iter->first] = false; } } InitParam(); LogInfo << "TransTrainEngine Init ok"; return APP_ERR_OK; } APP_ERROR TransTrainEngine::DeInit() { if (!bUseEngine_) { LogWarn << "engineId_:" << engineId_ << " not use engine"; return APP_ERR_OK; } LogInfo << "TransTrainEngine DeInit ok"; return APP_ERR_OK; } /** * 初始化参数信息 * inParam : N/A * outParam: N/A * return : N/A */ void TransTrainEngine::InitParam() { for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) { iter->second = false; } mapNumInfo_.clear(); mapPreFrameId_.clear(); } /** * 校验车型是否符合验证 * inParam : int classId 大框类别id * : const std::string &trainNum 车型字符信息 * outParam: N/A * return : true:符合; false:不符合 */ bool TransTrainEngine::AuthTransNum(int classId, const std::string &trainNum) { // LogInfo << "classId:" << classId << " trainNum:" << trainNum; switch (classId) { case TRAIN_HEAD: // 车头上的编号 break; case K_TRAIN_NUM: // 编号 矿车、煤炭漏斗车(兖矿自备、枣矿自备) { if (trainNum == "K13" || trainNum == "KM100AH") { return true; } std::regex reg; switch (trainNum.size()) { case 4: reg = "^K[1FMZ]{1}[36789]{1}[018ABKNT]{1}"; break; case 5: reg = "^K[1M]{1}[368]{1}[1ABDN]{1}[AGKNT]{1}"; break; case 6: reg = "^K[MF]{1}[69]{1}[80]{1}A[KH]{1}"; break; default: LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; return false; } return std::regex_match(trainNum, reg); } case C_TRAIN_NUM: // 敞车 特殊车型 C5D CF CFK { if (trainNum == "CF" || trainNum == "C62A(N)") { return true; } std::regex reg; switch (trainNum.size()) { case 3: reg = "^C[15678F]{1}[0123456DK]{1}"; break; case 4: reg = "^C[1678]{1}[012346]{1}[0ABCEFHKMTY]{1}"; break; case 5: reg = "^C[1678]{1}[01246]{1}[0ABCEY]{1}[KAFHNT]{1}"; break; case 6: reg = "^C[17]{1}0[0E]{1}[A-]{1}[AH]{1}"; break; default: LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; return false; } return std::regex_match(trainNum, reg); } case P_TRAIN_NUM: // 编号 棚车 { if (trainNum == "P70(H)" || trainNum == "P62(N)") { return true; } std::regex reg; switch (trainNum.size()) { case 3: reg = "^P[1678]{1}[012345]{1}"; break; case 4: reg = "^P[678]{1}[023456]{1}[ABHKNST]{1}"; break; case 5: reg = "^P6[24]{1}[ANG]{1}[KT]{1}"; break; default: LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; return false; } return std::regex_match(trainNum, reg); } case G_TRAIN_NUM: // 编号 罐车 { if (trainNum == "GY100SK") { return true; } std::regex reg; switch (trainNum.size()) { case 2: reg = "^G[HLS]{1}"; break; case 3: reg = "^[GL]{1}[1567HL]{1}[01246789K]{1}"; break; case 4: reg = "^[GU]{1}[167FJLNQSWY]{1}[170689]{1}[KSABDGTM075W]{1}"; break; case 5: reg = "^[GU]{1}[17FHNQY6]{1}[1706A89]{1}[SBDAM057W]{1}[KEHTB0ZAS]{1}"; break; case 6: reg = "^[UG]{1}[6YH]{1}[1489A]{1}[057W]{1}[Z0LSA]{1}[KSAT]{1}"; break; default: LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; return false; } return std::regex_match(trainNum, reg); } case NX_TRAIN_NUM: // 编号 平车 { if (trainNum == "N6") { return true; } std::regex reg; switch (trainNum.size()) { case 3: reg = "^[NQX]{1}[1234678T]{1}[0124567HK]{1}"; break; case 4: reg = "^[BNX]{1}[16X]{1}[17BC]{1}[07AGKT]{1}"; break; case 5: reg = "^[NX]{1}[16NX]{1}[17C]{1}[07AGT]{1}[KTABH]{1}"; break; case 6: reg = "^NX17[AB]{1}[KTH]{1}"; break; default: LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; return false; } return std::regex_match(trainNum, reg); } case J_TRAIN_NUM: // 编号 牲畜车 特种车 { if (trainNum == "TP64GK") { return true; } std::regex reg; switch (trainNum.size()) { case 2: reg = "^[DT]{1}[2678]{1}"; break; case 3: reg = "^[DST]{1}[12346789LQ]{1}[012578ADFGP]{1}"; break; case 4: reg = "^[DJNT]{1}[12356AFKQS]{1}[012345678DFQS]{1}[A12345679GHKQ]{1}"; break; case 5: reg = "^[DJQT]{1}[2KNSH1P]{1}[613XQ2]{1}[A761234B]{1}[KA70G]{1}"; break; default: LogWarn << "Unknow train, classId: " << classId << " trainNum:" << trainNum; return false; } return std::regex_match(trainNum, reg); } default: LogWarn << "Unknow train,classId:" << classId << " trainNum:" << trainNum; return false; } return true; } /** * 过滤第二步字段代号的误识别 * inParam : std::vector &vecObjs * : TargetMaxLen iMaxLen * outParam: N/A * return : N/A */ void TransTrainEngine::FilterSingleData(std::vector &vecObjs, TargetMaxLen iMaxLen) { /*误识别场景 例: 车厢容积属性只有2位时,但因误识别导致自重的某个字符字段代号错误,划归到容积中,这样实际只有2位的容积变为3位。导致选优时错误。 只处理1个字段代号的误识别,若有多个字段代号同时错误,无法区分哪些字符字段代号是正确的。(字段代号误识别较多时,则增强模型训练) 排除一个最大和最小值后计算平局坐标值,每个框左上角和平局值左上角高度差大于平局值的高度则剔除. */ if (vecObjs.size() != iMaxLen || vecObjs.size() <= 2) { return; } std::deque dqObjs(vecObjs.begin(), vecObjs.end()); std::sort(dqObjs.begin(), dqObjs.end(), [](SingleData &a, SingleData &b) { return a.fLTY < b.fLTY; }); dqObjs.pop_front(); dqObjs.pop_back(); SingleData singleDataAvg; for (auto iter = dqObjs.begin(); iter != dqObjs.end(); iter++) { singleDataAvg.fLTX += iter->fLTX; singleDataAvg.fLTY += iter->fLTY; singleDataAvg.fRBX += iter->fRBX; singleDataAvg.fRBY += iter->fRBY; } singleDataAvg.fLTX = singleDataAvg.fLTX / dqObjs.size(); singleDataAvg.fLTY = singleDataAvg.fLTY / dqObjs.size(); singleDataAvg.fRBX = singleDataAvg.fRBX / dqObjs.size(); singleDataAvg.fRBY = singleDataAvg.fRBY / dqObjs.size(); float fAvgHeight = singleDataAvg.fRBY - singleDataAvg.fLTY; //剔除位置错误的字符信息 for (auto iter = vecObjs.begin(); iter != vecObjs.end(); iter++) { float fTemp = fabs(iter->fLTY - singleDataAvg.fLTY); if (fTemp > (fAvgHeight - 5)) { std::string strOne = vecClassNames_.at(iter->iClassId); LogWarn << "engineId:" << engineId_ << " " << strOne << " Line wrong "; vecObjs.erase(iter); break; } } } /** * 属性框内容转换 * inParam : std::map> &mapLine * outParam: TransSubData &transSubData * return : N/A */ void TransTrainEngine::TransPro(TransSubData &transSubData, std::map> &mapLine) { //载重 if (mapLine.find(0) != mapLine.end()) { TransInfo loadInfo; loadInfo.iLine = 0; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(0).size(); j++) { //过滤非数字 std::string strOne = vecClassNames_.at(mapLine.at(0).at(j).iClassId); if (strOne[0] < '0' || strOne[0] > '9') { LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in load"; continue; } strTemp += strOne; loadInfo.vecValue.emplace_back(strOne); loadInfo.vecScore.emplace_back(mapLine.at(0).at(j).fScore); transSubData.fScoreSum += mapLine.at(0).at(j).fScore; } //匹配正则表达式 //std::regex reg("^[0-9]{2}"); std::regex reg("^([4,5,6,7,8,9]{1}[0-9]{1}|[1]{1}[0-3]{1}[0-9]{1})$"); //(第1位:棚车:4 5; K自备车:1 5 7 8 9; 平车:7; 罐车:6 7; 敞车:6 7 8) if (std::regex_match(strTemp, reg)) { loadInfo.IsChkFlag = true; } transSubData.vecTransInfo.emplace_back(loadInfo); } //自重 if (mapLine.find(1) != mapLine.end()) { FilterSingleData(mapLine.at(1), SELF_MAXLEN); TransInfo selfInfo; selfInfo.iLine = 1; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(1).size(); j++) { //过滤非数字 std::string strOne = vecClassNames_.at(mapLine.at(1).at(j).iClassId); if (strOne[0] < '0' || strOne[0] > '9') { LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in self"; continue; } strTemp += strOne; selfInfo.vecValue.emplace_back(strOne); selfInfo.vecScore.emplace_back(mapLine.at(1).at(j).fScore); transSubData.fScoreSum += mapLine.at(1).at(j).fScore; } //匹配正则表达式 std::regex reg("^[1,2,3]{1}[0-9]{1,2}$"); if (std::regex_match(strTemp, reg)) { selfInfo.IsChkFlag = true; } transSubData.vecTransInfo.emplace_back(selfInfo); } //容积 if (mapLine.find(2) != mapLine.end()) { FilterSingleData(mapLine.at(2), VOLUME_MAXLEN); TransInfo volumeInfo; volumeInfo.iLine = 2; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(2).size(); j++) { //过滤非数字 std::string strOne = vecClassNames_.at(mapLine.at(2).at(j).iClassId); if (strOne[0] < '0' || strOne[0] > '9') { LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in volume"; continue; } strTemp += strOne; volumeInfo.vecValue.emplace_back(strOne); volumeInfo.vecScore.emplace_back(mapLine.at(2).at(j).fScore); transSubData.fScoreSum += mapLine.at(2).at(j).fScore; } //匹配正则表达式 //std::regex reg("^[0-9]{2,3}$"); std::regex reg("^[1,6,7,8,9]{1}[0-9]{1,2}$"); //(第1位:棚车:1; K自备车:1或9; 罐车:6或7; 敞车:7或8) if (std::regex_match(strTemp, reg)) { volumeInfo.IsChkFlag = true; } transSubData.vecTransInfo.emplace_back(volumeInfo); } //换长 if (mapLine.find(3) != mapLine.end()) { TransInfo changeInfo; changeInfo.iLine = 3; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(3).size(); j++) { //过滤非数字 std::string strOne = vecClassNames_.at(mapLine.at(3).at(j).iClassId); if (strOne[0] < '0' || strOne[0] > '9') { LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in change"; continue; } strTemp += strOne; changeInfo.vecValue.emplace_back(strOne); changeInfo.vecScore.emplace_back(mapLine.at(3).at(j).fScore); transSubData.fScoreSum += mapLine.at(3).at(j).fScore; } //匹配正则表达式 //std::regex reg("^[0-9]{2}$"); std::regex reg("^[1]{1}[0-9]{1}$"); if (std::regex_match(strTemp, reg)) { changeInfo.IsChkFlag = true; } transSubData.vecTransInfo.emplace_back(changeInfo); } //罐车容量计表 if (mapLine.find(4) != mapLine.end()) { TransInfo volumeSurfaceInfo; volumeSurfaceInfo.iLine = 4; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(4).size(); j++) { strTemp += vecClassNames_.at(mapLine.at(4).at(j).iClassId); volumeSurfaceInfo.vecValue.emplace_back(vecClassNames_.at(mapLine.at(4).at(j).iClassId)); volumeSurfaceInfo.vecScore.emplace_back(mapLine.at(4).at(j).fScore); transSubData.fScoreSum += mapLine.at(4).at(j).fScore; } volumeSurfaceInfo.IsChkFlag = true; //暂不校验 transSubData.vecTransInfo.emplace_back(volumeSurfaceInfo); } } /** * 车号框内容转换 * inParam : std::map> &mapLine * outParam: TransSubData &transSubData * return : N/A */ void TransTrainEngine::TransNum(TransSubData &transSubData, std::map> &mapLine) { //车型 if (mapLine.find(0) != mapLine.end()) { TransInfo typeInfo; typeInfo.iLine = 0; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(0).size(); j++) { std::string strOne = vecClassNames_.at(mapLine.at(0).at(j).iClassId); /*20230117 该逻辑删除,有厂区发现有C70C DF4DD等车型。 针对重复印刷的场景需想其他方法处理。 //注:车型多次印刷会导致之前印刷的个别字符会识别,导致最终的识别内容变多。针对车型没有重复字符的特点,因此剔除重复的字符 auto iter = find(typeInfo.vecValue.begin(), typeInfo.vecValue.end(), strOne); if (iter != typeInfo.vecValue.end()) { LogWarn << "Possible duplicate recognition strOne:" << strOne; continue; } */ strTemp += strOne; typeInfo.vecValue.emplace_back(strOne); typeInfo.vecScore.emplace_back(mapLine.at(0).at(j).fScore); transSubData.fScoreSum += mapLine.at(0).at(j).fScore; } //校验车型是否符合验证 typeInfo.IsChkFlag = AuthTransNum(transSubData.iBigClassId, strTemp); // LogInfo << "--->>> 符合正则吗?" << typeInfo.IsChkFlag << " --- " << strTemp; transSubData.vecTransInfo.emplace_back(typeInfo); } //编号 if (mapLine.find(1) != mapLine.end()) { TransInfo numInfo; numInfo.iLine = 1; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(1).size(); j++) { std::string strOne = vecClassNames_.at(mapLine.at(1).at(j).iClassId); //过滤非数字 if (strOne[0] < '0' || strOne[0] > '9') { LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in num"; continue; } strTemp += strOne; numInfo.vecValue.emplace_back(strOne); numInfo.vecScore.emplace_back(mapLine.at(1).at(j).fScore); transSubData.fScoreSum += mapLine.at(1).at(j).fScore; } //匹配正则表达式 std::regex reg("^[0-9]{7}$"); //车厢编号,固定7位 if (std::regex_match(strTemp, reg)) { numInfo.IsChkFlag = true; } transSubData.vecTransInfo.emplace_back(numInfo); } } /** * 车头框内容转换 * inParam : std::map> &mapLine * outParam: TransSubData &transSubData * return : N/A */ void TransTrainEngine::TransHead(TransSubData &transSubData, std::map> &mapLine) { //车头型号 if (mapLine.find(0) != mapLine.end()) { TransInfo typeInfo; typeInfo.iLine = 0; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(0).size(); j++) { strTemp += vecClassNames_.at(mapLine.at(0).at(j).iClassId); typeInfo.vecValue.emplace_back(vecClassNames_.at(mapLine.at(0).at(j).iClassId)); typeInfo.vecScore.emplace_back(mapLine.at(0).at(j).fScore); transSubData.fScoreSum += mapLine.at(0).at(j).fScore; } //不做结果校验,IsChkFlag默认为true typeInfo.IsChkFlag = true; transSubData.vecTransInfo.emplace_back(typeInfo); } //车头编号 if (mapLine.find(1) != mapLine.end()) { TransInfo numInfo; numInfo.iLine = 1; std::string strTemp = ""; for (auto j = 0; j < mapLine.at(1).size(); j++) { std::string strOne = vecClassNames_.at(mapLine.at(1).at(j).iClassId); //过滤非数字 if (strOne[0] < '0' || strOne[0] > '9') { LogWarn << "engineId:" << engineId_ << " " << strOne << " not digit in headnum"; continue; } strTemp += strOne; numInfo.vecValue.emplace_back(strOne); numInfo.vecScore.emplace_back(mapLine.at(1).at(j).fScore); transSubData.fScoreSum += mapLine.at(1).at(j).fScore; } //不做结果校验,IsChkFlag默认为true numInfo.IsChkFlag = true; transSubData.vecTransInfo.emplace_back(numInfo); } } /** * 记录在画面中间位置识别的车号 * inParam : const TransSubData &transSubData 车号信息 : const std::shared_ptr &pProcessData 帧数据 * outParam: N/A * return : N/A */ void TransTrainEngine::RecordNum(const TransSubData &transSubData, const std::shared_ptr &pProcessData) { int iCenterX = transSubData.step1Location.fLTX + (transSubData.step1Location.fRBX - transSubData.step1Location.fLTX) / 2; int iImgL = pProcessData->iWidth / 3; int iImgR = pProcessData->iWidth / 3 * 2; if (iCenterX <= iImgL || iCenterX >= iImgR) { return; } std::string strValue; for (size_t i = 0; i < transSubData.vecTransInfo.size(); i++) { TransInfo transInfo = transSubData.vecTransInfo[i]; if (transInfo.iLine != 1) { continue; } for (size_t j = 0; j < transInfo.vecValue.size(); j++) { strValue += transInfo.vecValue[j]; } } bool bIntervalFlag = ((int)(pProcessData->iFrameId - mapPreFrameId_[pProcessData->iDataSource]) > iSkipInterval_ * 2); if (mapNumInfo_[pProcessData->iDataSource].find(strValue) == mapNumInfo_[pProcessData->iDataSource].end()) { LogDebug << " frameid:" << pProcessData->iFrameId << " NUM:" << strValue << " bIntervalFlag:" << bIntervalFlag; if (bIntervalFlag) { mapNumInfo_[pProcessData->iDataSource][strValue] = pProcessData->iFrameId; } } // LogDebug << " preframeid:" << mapPreFrameId_[pProcessData->iDataSource] // << " frameid:" << pProcessData->iFrameId << " mapsize:" << mapNumInfo_[pProcessData->iDataSource].size(); mapPreFrameId_[pProcessData->iDataSource] = pProcessData->iFrameId; } /** * 保存中间位置识别车号信息到csv中 * inParam : std::shared_ptr pTrain :列车信息 * outParam: * return : true/false */ bool TransTrainEngine::SaveMiddleNumCsv(const std::vector> &vecNums, const std::shared_ptr &pProcessData, int iSourceId) { //1. 创建保存路径 (固定路径/YYYY-MM-DD/hh-mm-ss/) std::string strTrainPath = strResultPath_ + pProcessData->strTrainDate + "/" + pProcessData->strTrainName + "/"; if (!MyUtils::getins()->CreateDirPath(strTrainPath)) { LogError << "fail CreateDirPath:" << strTrainPath; return false; } //2. 保存csv std::string strCsvName = pProcessData->strTrainDate + pProcessData->strTrainName + "_" + std::to_string(iSourceId) + ".csv"; strCsvName = MyUtils::getins()->replace_all_distinct(strCsvName, std::string("-"), std::string("")); strTrainPath += strCsvName; try { // 写文件 std::ofstream outFile; outFile.open(strTrainPath, std::ios::app); outFile << "num" << ',' << "frameid" << std::endl; for (auto iterVec = vecNums.begin(); iterVec != vecNums.end(); iterVec++) { outFile << iterVec->first << "," << iterVec->second << std::endl; } outFile.close(); } catch (const std::exception &) { LogError << "fail open dirPath:" << strTrainPath; return false; } return true; } /** * push数据到队列,队列满时则休眠一段时间再push * inParam : const std::string strPort push的端口 : const std::shared_ptr &pProcessData push的数据 * outParam: N/A * return : N/A */ void TransTrainEngine::PushData(const std::string &strPort, const std::shared_ptr &pProcessData) { while (true) { int iRet = outputQueMap_[strPort]->push(std::static_pointer_cast(pProcessData)); if (iRet != 0) { LogDebug << "sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId << " push fail iRet:" << iRet; if (iRet == 2) { usleep(10000); // 10ms continue; } } break; } } APP_ERROR TransTrainEngine::Process() { if (!bUseEngine_) { LogWarn << "engineId_:" << engineId_ << " not use engine"; return APP_ERR_OK; } int iRet = APP_ERR_OK; while (!isStop_) { std::shared_ptr pVoidData0 = nullptr; inputQueMap_[strPort0_]->pop(pVoidData0); if (nullptr == pVoidData0) { usleep(1000); //1ms continue; } std::shared_ptr pProcessData = std::static_pointer_cast(pVoidData0); //第2步后处理结果 std::shared_ptr pPostData = std::static_pointer_cast(pProcessData->pVoidData); //最后一节的最后一帧为整列车的结束 if (pProcessData->bIsTrainEnd && pProcessData->bIsEnd) { mapDataSourceIsEnd_[pProcessData->iDataSource] = true; } //组织输出数据 std::shared_ptr pTransData = std::make_shared(); for (size_t i = 0; i < pPostData->vecPostSubData.size(); i++) { PostSubData postSubData = pPostData->vecPostSubData[i]; //按字段代号分类 std::map> mapLine; for (size_t j = 0; j < postSubData.vecSingleData.size(); j++) { mapLine[postSubData.vecSingleData.at(j).iLine].push_back(postSubData.vecSingleData.at(j)); } //每一行按x坐标排序 for (auto it = mapLine.begin(); it != mapLine.end(); it++) { std::sort(it->second.begin(), it->second.end(), CompareX); std::string strTemp = ""; for (auto j = 0; j < it->second.size(); j++) { strTemp += vecClassNames_.at(it->second.at(j).iClassId); } // LogDebug << "step2 char sourceid:" << pProcessData->iDataSource << " frameid:" << pProcessData->iFrameId // << " bigclassId:" << postSubData.iBigClassId << " line:" << it->first << "," << strTemp; } TransSubData transSubData; transSubData.iBigClassId = postSubData.iBigClassId; transSubData.iCarXH = postSubData.iCarXH; transSubData.step1Location = postSubData.step1Location; //按大类处理 if(postSubData.iBigClassId == 1) { TransPro(transSubData, mapLine); } else if (postSubData.iBigClassId >= 2 && postSubData.iBigClassId <= 6) { TransNum(transSubData, mapLine); RecordNum(transSubData, pProcessData); } else if(postSubData.iBigClassId == 0) { TransHead(transSubData, mapLine); RecordNum(transSubData, pProcessData); } else { continue; } pTransData->vecTransSubData.emplace_back(transSubData); } //是否全部结束 bool bAllEnd = true; for (auto iter = mapDataSourceIsEnd_.begin(); iter != mapDataSourceIsEnd_.end(); iter++) { bAllEnd = bAllEnd && iter->second; } pProcessData->pVoidData = std::static_pointer_cast(pTransData); // push端口0,车号属性选优处理 PushData(strPort0_, pProcessData); if (bAllEnd) { for(auto iter = mapNumInfo_.begin(); iter != mapNumInfo_.end(); iter++) { std::vector> vecTemp(iter->second.begin(), iter->second.end()); sort(vecTemp.begin(), vecTemp.end(), CmpVec); //按帧号排序 SaveMiddleNumCsv(vecTemp, pProcessData, iter->first); // for(auto iterVec = vecTemp.begin(); iterVec != vecTemp.end(); iterVec++) // { // LogDebug << "sourceid:" << iter->first << " num:" << iterVec->first << " frameid:" << iterVec->second; // } } //转个json数组发送后面用于比较。(车厢个数和该json数据是否相等,相等则不处理。不相等则挨个比较下。) //初始化参数变量 InitParam(); } } return APP_ERR_OK; } \ No newline at end of file diff --git a/nvidia_ascend_engine/nvidia_engine/DecodeEngine/ImgDecodeEngine.cpp b/nvidia_ascend_engine/nvidia_engine/DecodeEngine/ImgDecodeEngine.cpp deleted file mode 100644 index 32adbe6..0000000 --- a/nvidia_ascend_engine/nvidia_engine/DecodeEngine/ImgDecodeEngine.cpp +++ /dev/null @@ -1,137 +0,0 @@ -#include "ImgDecodeEngine.h" - -#include -#include -#include -#include -using namespace std; -using namespace cv; - - -using namespace ai_matrix; - -ImgDecodeEngine::ImgDecodeEngine() {} - -ImgDecodeEngine::~ImgDecodeEngine() {} - -APP_ERROR ImgDecodeEngine::Init() -{ - bUseEngine_ = true; - dataSourceConfig_ = MyYaml::GetIns()->GetDataSourceConfigById(engineId_); //获取摄像机参数 - if (MyYaml::GetIns()->GetStringValue("gc_data_source") != "images" || !dataSourceConfig_.bUse) - { - bUseEngine_ = false; - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - strPort0_ = engineName_ + "_" + std::to_string(engineId_) + "_0"; - - width_ = IMAGE_WIDTH, height_ = IMAGE_HEIGHT; - - LogInfo << "ImgDecodeEngine Init ok"; - return APP_ERR_OK; -} - -APP_ERROR ImgDecodeEngine::DeInit() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - - LogInfo << "ImgDecodeEngine deinit ok"; - return APP_ERR_OK; -} - -APP_ERROR ImgDecodeEngine::Process() -{ - if (!bUseEngine_) - { - LogWarn << "engineId_:" << engineId_ << " not use engine"; - return APP_ERR_OK; - } - // #ifdef SAVE_BGR2RGB_FILE - // char rgb_stream[256] = {}; - // sprintf(rgb_stream, "bgr2rgb_stream_%dx%d.rgb", width_, height_); - // FILE *rgb_stream_fp = fopen(rgb_stream, "ab+"); - // #endif - - uint64_t u64count_num = 0; - int iRet = APP_ERR_OK; - - while (!isStop_) - { - std::shared_ptr pVoidData0 = nullptr; - inputQueMap_[strPort0_]->pop(pVoidData0); - if (nullptr == pVoidData0) - { - usleep(1*1000); //n ms - continue; - } - //透传下一个Engine - outputQueMap_[strPort0_]->push(pVoidData0); - - // // std::cout<<"Enter BGR2RGBEngine Thread "<<++u64count_num<<" Times!"< pBGRFrameData = std::static_pointer_cast(pVoidData0); - - // //构造RGB数据 - // void* pRGBBuffer = nullptr; - // unsigned int pRGBBuffer_Size = width_*height_*3; - // pRGBBuffer = new uint8_t[pRGBBuffer_Size]; - // std::shared_ptr pRGBFrameData = std::make_shared(); - - // //像素格式转换 - // cv::Mat BGRImage(height_, width_, CV_8UC3, static_cast(pBGRFrameData->pData.get())); //BGR - // cv::Mat RGBImage(height_, width_, CV_8UC3, pRGBBuffer); //RGB - - // #ifdef OPENCV_CVTCOLOR_BGR2RGB_TIME_CONSUMING_TEST - // auto start = std::chrono::system_clock::now(); //计时开始 - // cv::cvtColor(BGRImage, RGBImage, cv::COLOR_BGR2RGB); //像素格式转换 BGR转RGB - // auto end = std::chrono::system_clock::now(); //计时结束 - // std::cout << "frame width: "<(end - start).count() << "ms" << std::endl; - // #else - // cv::cvtColor(BGRImage, RGBImage, cv::COLOR_BGR2RGB); //像素格式转换 BGR转RGB - // #endif - - // //压入像素格式转换后的数据 - // //组织数据 - // pRGBFrameData->iDataSource = engineId_; - // pRGBFrameData->iSize = pRGBBuffer_Size; - // pRGBFrameData->pData.reset(pRGBBuffer, [](void* data){if(data) {delete[] data; data = nullptr;}}); //智能指针管理内存 - // // pFrameData->pData.reset(pRGBBuffer, Deleter); //智能指针管理内存 - // pRGBFrameData->i64TimeStamp = pBGRFrameData->i64TimeStamp; - - // //开启此宏保存转换后的RGB数据 - // #ifdef SAVE_BGR2RGB_FILE - // if (rgb_stream_fp) - // { - // fwrite(pRGBFrameData->pData.get(), 1, pRGBFrameData->iSize, rgb_stream_fp); - // fflush(rgb_stream_fp); - // fsync(fileno(rgb_stream_fp)); - // } - // #endif - - // std::cout<<"port0 push the rgb frame data!"<push(std::static_pointer_cast(pRGBFrameData)); - // if (iRet != APP_ERR_OK){ - // LogError << "push the rgb frame data failed..."; - // // std::cerr<<"push the rgb frame data failed..."< &vecRet, std continue; } + if (it->class_id == K_TRAIN_NUM) + { + int iCenterY = pProcessData->iHeight / 2; + int iHeight0 = it->bbox[1] / 2 + it->bbox[3] / 2; + if (iHeight0 > iCenterY) { + LogWarn << "矿车编号大框在画面Y轴中线以下,帧号:" + << pProcessData->iFrameId + << " 画面Y轴中心:" << iCenterY + << " 大框Y轴中心:" << iHeight0 ; + it = vecRet.erase(it); + continue; + } + } + //补连塔的相机比较近,间隔基本在画面底部,因此当间隔比较靠画面上时过滤掉。 if ((it->class_id >= 9 && it->class_id <= 17 && it->class_id != 15) || it->class_id == U_TRAIN_SPACE) { diff --git a/nvidia_ascend_engine/nvidia_engine/TrainStepTwoEngine/TrainStepTwoEngine.cpp b/nvidia_ascend_engine/nvidia_engine/TrainStepTwoEngine/TrainStepTwoEngine.cpp index b0c8210..6777f3e 100644 --- a/nvidia_ascend_engine/nvidia_engine/TrainStepTwoEngine/TrainStepTwoEngine.cpp +++ b/nvidia_ascend_engine/nvidia_engine/TrainStepTwoEngine/TrainStepTwoEngine.cpp @@ -239,7 +239,7 @@ APP_ERROR TrainStepTwoEngine::Process() // push端口0,第1步推理 pProcessData->pVoidData = std::static_pointer_cast(pPostData); - iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData), true); + iRet = outputQueMap_[strPort0_]->push(std::static_pointer_cast(pProcessData)); // PushData(strPort0_, pProcessData); } return APP_ERR_OK;