NVIDIA DeepStream SDK API Reference

6.4 Release
capture_time_rules.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20  * DEALINGS IN THE SOFTWARE.
21  */
22 
23 #pragma once
24 
25 #include <string>
26 #include <iostream>
27 #include <chrono>
28 #include <vector>
29 
31  typedef std::chrono::time_point<std::chrono::system_clock> t_time_pt;
32  typedef std::chrono::duration<unsigned long long> t_duration;
33 public:
38  void init(const std::string &path, unsigned default_second_interval);
39 
42  t_duration getCurrentTimeInterval();
43 
46  bool is_init_();
47 
48 private:
49  struct TimeRule {
50  unsigned begin_time_hour;
51  unsigned begin_time_minute;
52  unsigned end_time_hour;
53  unsigned end_time_minute;
54  unsigned interval_between_frame_capture_seconds;
55  bool end_time_is_next_day;
56  };
57 
64  static bool isInTimeRule(const TimeRule &t, const tm &now);
65 
66  enum ParseResult{
67  PARSE_RESULT_OK,
68  PARSE_RESULT_BAD_CHARS,
69  PARSE_RESULT_OUT_OF_BOUND,
70  PARSE_RESULT_EMPTY
71  };
72 
73  static ParseResult stoi_err_handling(unsigned& dst, const std::string &src, unsigned max_bound);
74  static bool parsing_contains_error(const std::vector<ParseResult>& parse_res_list,
75  const std::vector<std::string>& str_list, const std::string& curr_line,
76  unsigned line_number);
77  bool single_time_rule_parser(const std::string &path, const std::string &line,
78  unsigned line_number);
79 
80  std::chrono::seconds default_duration_;
81  t_time_pt end_of_current_time_interval_;
82  t_duration current_time_interval_;
83  std::vector<TimeRule> rules_;
84  bool init_ = false;
85 };
86 
87 
CaptureTimeRules::getCurrentTimeInterval
t_duration getCurrentTimeInterval()
Compute the correct time interval using the local computer time.
CaptureTimeRules
Definition: capture_time_rules.h:30
CaptureTimeRules::init
void init(const std::string &path, unsigned default_second_interval)
Fills the time rules with the content of the file in path.
CaptureTimeRules::is_init_
bool is_init_()