]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/include/seastar/core/app-template.hh
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / seastar / include / seastar / core / app-template.hh
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
20 */
21 #pragma once
22
23 #include <boost/program_options.hpp>
24 #include <functional>
25 #include <seastar/core/future.hh>
26 #include <seastar/core/sstring.hh>
27 #include <chrono>
28
29 namespace seastar {
30
31 class app_template {
32 public:
33 struct config {
34 /// The name of the application.
35 ///
36 /// Will be used in the --help output to distinguish command line args
37 /// registered by the application, as opposed to those registered by
38 /// seastar and its subsystems.
39 sstring name = "App";
40 /// The description of the application.
41 ///
42 /// Will be printed on the top of the --help output. Lines should be
43 /// hard-wrapped for 80 chars.
44 sstring description = "";
45 std::chrono::duration<double> default_task_quota = std::chrono::microseconds(500);
46 /// \brief Handle SIGINT/SIGTERM by calling reactor::stop()
47 ///
48 /// When true, Seastar will set up signal handlers for SIGINT/SIGTERM that call
49 /// reactor::stop(). The reactor will then execute callbacks installed by
50 /// reactor::at_exit().
51 ///
52 /// When false, Seastar will not set up signal handlers for SIGINT/SIGTERM
53 /// automatically. The default behavior (terminate the program) will be kept.
54 /// You can adjust the behavior of SIGINT/SIGTERM by installing signal handlers
55 /// via reactor::handle_signal().
56 bool auto_handle_sigint_sigterm = true;
57 config() {}
58 };
59
60 using configuration_reader = std::function<void (boost::program_options::variables_map&)>;
61 private:
62 config _cfg;
63 boost::program_options::options_description _opts;
64 boost::program_options::options_description _opts_conf_file;
65 boost::program_options::positional_options_description _pos_opts;
66 std::optional<boost::program_options::variables_map> _configuration;
67 configuration_reader _conf_reader;
68
69 configuration_reader get_default_configuration_reader();
70 public:
71 struct positional_option {
72 const char* name;
73 const boost::program_options::value_semantic* value_semantic;
74 const char* help;
75 int max_count;
76 };
77 public:
78 explicit app_template(config cfg = config());
79
80 boost::program_options::options_description& get_options_description();
81 boost::program_options::options_description& get_conf_file_options_description();
82 boost::program_options::options_description_easy_init add_options();
83 void add_positional_options(std::initializer_list<positional_option> options);
84 boost::program_options::variables_map& configuration();
85 int run_deprecated(int ac, char ** av, std::function<void ()>&& func);
86
87 void set_configuration_reader(configuration_reader conf_reader);
88
89 // Runs given function and terminates the application when the future it
90 // returns resolves. The value with which the future resolves will be
91 // returned by this function.
92 int run(int ac, char ** av, std::function<future<int> ()>&& func);
93
94 // Like run() which takes std::function<future<int>()>, but returns
95 // with exit code 0 when the future returned by func resolves
96 // successfully.
97 int run(int ac, char ** av, std::function<future<> ()>&& func);
98 };
99
100 }