pfsdp_base.h
Go to the documentation of this file.
1 // Copyright 2022 Fraunhofer IPA
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <mutex>
18 #include <memory>
19 #include <functional>
20 
28 #include "pf_driver/pf/kv.h"
29 
30 class HTTPInterface;
31 
32 class PFSDPBase
33 {
34 private:
35  using HTTPInterfacePtr = std::unique_ptr<HTTPInterface>;
37  std::function<void()> handle_connection_failure;
38 
39  const std::map<std::string, std::string> get_request(const std::string& command,
40  const std::vector<std::string>& json_keys,
41  const std::initializer_list<param_type>& query);
42  const std::map<std::string, std::string>
43  get_request(const std::string& command, const std::vector<std::string>& json_keys = std::vector<std::string>(),
44  const param_map_type& query = param_map_type());
45 
46  bool get_request_bool(const std::string& command,
47  const std::vector<std::string>& json_keys = std::vector<std::string>(),
48  const std::initializer_list<param_type>& query = std::initializer_list<param_type>());
49 
50  bool is_connection_failure(const std::string& http_error);
51 
52  bool check_error(std::map<std::string, std::string>& mp, const std::string& err_code, const std::string& err_text,
53  const std::string& err_http);
54 
55 protected:
56  std::shared_ptr<HandleInfo> info_;
57  std::shared_ptr<ScanConfig> config_;
58  std::shared_ptr<ScanParameters> params_;
59 
60 public:
61  PFSDPBase(std::shared_ptr<HandleInfo> info, std::shared_ptr<ScanConfig> config,
62  std::shared_ptr<ScanParameters> params);
63 
64  void set_connection_failure_cb(std::function<void()> callback);
65 
66  const std::vector<std::string> list_parameters();
67 
68  bool reboot_device();
69 
70  void factory_reset();
71 
72  bool release_handle(const std::string& handle);
73 
75 
76  template <typename... Ts>
77  bool set_parameter(const std::initializer_list<param_type> params)
78  {
79  return get_request_bool("set_parameter", { "" }, params);
80  }
81 
82  template <typename... Ts>
83  std::map<std::string, std::string> get_parameter(const Ts&... ts)
84  {
85  return get_request("get_parameter", { ts... }, { KV("list", ts...) });
86  }
87 
88  std::int64_t get_parameter_int(const std::string& param);
89 
90  float get_parameter_float(const std::string& param);
91 
92  std::string get_parameter_str(const std::string& param);
93 
94  template <typename... Ts>
95  bool reset_parameter(const Ts&... ts)
96  {
97  return get_request_bool("reset_parameter", { "" }, { KV("list", ts...) });
98  }
99 
100  void request_handle_tcp(const std::string& port = "", const std::string& packet_type = "");
101 
102  virtual void request_handle_udp(const std::string& packet_type = "");
103 
104  virtual void get_scanoutput_config(const std::string& handle);
105 
106  bool set_scanoutput_config(const std::string& handle, const ScanConfig& config);
107 
109 
110  bool start_scanoutput();
111 
112  bool stop_scanoutput(const std::string& handle);
113 
114  std::string get_scanoutput_config(const std::string& param, const std::string& handle);
115 
116  bool feed_watchdog(const std::string& handle);
117 
118  virtual std::string get_product();
119 
120  virtual std::string get_part();
121 
122  virtual void get_scan_parameters();
123 
124  virtual void setup_param_server();
125 };
PFSDPBase::check_error
bool check_error(std::map< std::string, std::string > &mp, const std::string &err_code, const std::string &err_text, const std::string &err_http)
Definition: pfsdp_base.cpp:61
PFSDPBase::setup_param_server
virtual void setup_param_server()
Definition: pfsdp_base.cpp:303
PFSDPBase::get_parameter
std::map< std::string, std::string > get_parameter(const Ts &... ts)
Definition: pfsdp_base.h:83
PFSDPBase::set_parameter
bool set_parameter(const std::initializer_list< param_type > params)
Definition: pfsdp_base.h:77
PFSDPBase::request_handle_tcp
void request_handle_tcp(const std::string &port="", const std::string &packet_type="")
Definition: pfsdp_base.cpp:178
PFSDPBase::handle_connection_failure
std::function< void()> handle_connection_failure
Definition: pfsdp_base.h:37
PFSDPBase::request_handle_udp
virtual void request_handle_udp(const std::string &packet_type="")
Definition: pfsdp_base.cpp:205
KV
Definition: kv.h:9
protocol_info.h
PFSDPBase::config_
std::shared_ptr< ScanConfig > config_
Definition: pfsdp_base.h:57
PFSDPBase::get_protocol_info
ProtocolInfo get_protocol_info()
Definition: pfsdp_base.cpp:130
handle_info.h
PFSDPBase::PFSDPBase
PFSDPBase(std::shared_ptr< HandleInfo > info, std::shared_ptr< ScanConfig > config, std::shared_ptr< ScanParameters > params)
Definition: pfsdp_base.cpp:6
PFSDPBase::update_scanoutput_config
bool update_scanoutput_config()
Definition: pfsdp_base.cpp:251
PFSDPBase::reset_parameter
bool reset_parameter(const Ts &... ts)
Definition: pfsdp_base.h:95
PFSDPBase::get_scan_parameters
virtual void get_scan_parameters()
Definition: pfsdp_base.cpp:299
PFSDPBase::get_parameter_float
float get_parameter_float(const std::string &param)
Definition: pfsdp_base.cpp:158
PFSDPBase::params_
std::shared_ptr< ScanParameters > params_
Definition: pfsdp_base.h:58
PFSDPBase::release_handle
bool release_handle(const std::string &handle)
Definition: pfsdp_base.cpp:124
PFSDPBase::list_parameters
const std::vector< std::string > list_parameters()
Definition: pfsdp_base.cpp:108
HTTPInterface
Definition: http_interface.h:24
PFSDPBase::is_connection_failure
bool is_connection_failure(const std::string &http_error)
Definition: pfsdp_base.cpp:49
PFSDPBase::info_
std::shared_ptr< HandleInfo > info_
Definition: pfsdp_base.h:56
PFSDPBase::feed_watchdog
bool feed_watchdog(const std::string &handle)
Definition: pfsdp_base.cpp:284
PFSDPBase::factory_reset
void factory_reset()
Definition: pfsdp_base.cpp:119
PFSDPBase::get_parameter_int
std::int64_t get_parameter_int(const std::string &param)
Definition: pfsdp_base.cpp:148
param_map_type
std::map< std::string, std::string > param_map_type
Definition: param_map_type.h:20
PFSDPBase::get_part
virtual std::string get_part()
Definition: pfsdp_base.cpp:294
ProtocolInfo
Definition: protocol_info.h:6
PFSDPBase::get_request_bool
bool get_request_bool(const std::string &command, const std::vector< std::string > &json_keys=std::vector< std::string >(), const std::initializer_list< param_type > &query=std::initializer_list< param_type >())
Definition: pfsdp_base.cpp:38
scan_parameters.h
PFSDPBase::reboot_device
bool reboot_device()
Definition: pfsdp_base.cpp:114
PFSDPBase::get_scanoutput_config
virtual void get_scanoutput_config(const std::string &handle)
Definition: pfsdp_base.cpp:220
kv.h
PFSDPBase::set_connection_failure_cb
void set_connection_failure_cb(std::function< void()> callback)
Definition: pfsdp_base.cpp:103
PFSDPBase::stop_scanoutput
bool stop_scanoutput(const std::string &handle)
Definition: pfsdp_base.cpp:273
PFSDPBase::http_interface
HTTPInterfacePtr http_interface
Definition: pfsdp_base.h:36
scan_config.h
PFSDPBase::start_scanoutput
bool start_scanoutput()
Definition: pfsdp_base.cpp:267
ScanConfig
Definition: scan_config.h:5
param_map_type.h
PFSDPBase
Definition: pfsdp_base.h:32
PFSDPBase::get_request
const std::map< std::string, std::string > get_request(const std::string &command, const std::vector< std::string > &json_keys, const std::initializer_list< param_type > &query)
Definition: pfsdp_base.cpp:12
PFSDPBase::set_scanoutput_config
bool set_scanoutput_config(const std::string &handle, const ScanConfig &config)
Definition: pfsdp_base.cpp:234
param_type.h
PFSDPBase::HTTPInterfacePtr
std::unique_ptr< HTTPInterface > HTTPInterfacePtr
Definition: pfsdp_base.h:35
PFSDPBase::get_parameter_str
std::string get_parameter_str(const std::string &param)
Definition: pfsdp_base.cpp:168
http_interface.h
PFSDPBase::get_product
virtual std::string get_product()
Definition: pfsdp_base.cpp:289


pf_driver
Author(s): Harsh Deshpande
autogenerated on Sun Feb 4 2024 03:32:56