File: this_process.h

package info (click to toggle)
anbox 0.0~git20190124-1
  • links: PTS, VCS
  • area: contrib
  • in suites: buster
  • size: 22,000 kB
  • sloc: cpp: 76,190; ansic: 7,434; sh: 1,350; xml: 818; java: 780; python: 390; makefile: 35; lisp: 7
file content (128 lines) | stat: -rw-r--r-- 4,244 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright © 2013 Canonical Ltd.
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Thomas Voß <thomas.voss@canonical.com>
 */

#ifndef CORE_POSIX_THIS_PROCESS_H_
#define CORE_POSIX_THIS_PROCESS_H_

#include <core/posix/visibility.h>

#include <functional>
#include <iosfwd>
#include <string>
#include <system_error>

namespace core
{
namespace posix
{
class Process;
namespace this_process
{
namespace env
{
/**
 * @brief for_each invokes a functor for every key-value pair in the environment.
 * @param [in] functor Invoked for every key-value pair.
 */
CORE_POSIX_DLL_PUBLIC void for_each(
        const std::function<void(const std::string&, const std::string&)>& functor) noexcept(true);

/**
 * @brief get queries the value of an environment variable.
 * @throw std::runtime_error if there is no variable with the given key defined in the env.
 * @param [in] key Name of the variable to query the value for.
 * @return Contents of the variable.
 */
CORE_POSIX_DLL_PUBLIC std::string get_or_throw(const std::string& key);

/**
 * @brief get queries the value of an environment variable.
 * @param [in] key Name of the variable to query the value for.
 * @param [in] default_value Default value to return when key is not present in the environment.
 * @return Contents of the variable or an empty string if the variable is not defined.
 */
CORE_POSIX_DLL_PUBLIC std::string get(
        const std::string& key,
        const std::string& default_value = std::string()) noexcept(true);

/**
 * @brief unset_or_throw removes the variable with name key from the environment.
 * @throw std::system_error in case of errors.
 * @param [in] key Name of the variable to unset.
 */
CORE_POSIX_DLL_PUBLIC void unset_or_throw(const std::string& key);

/**
 * @brief unset removes the variable with name key from the environment.
 * @return false in case of errors, true otherwise.
 * @param [in] key Name of the variable to unset.
 * @param [out] se Receives error details if unset returns false.
 */
CORE_POSIX_DLL_PUBLIC bool unset(const std::string& key,
                            std::error_code& se) noexcept(true);

/**
 * @brief set_or_throw will adjust the contents of the variable identified by key to the provided value.
 * @throw std::system_error in case of errors.
 * @param [in] key Name of the variable to set the value for.
 * @param [in] value New contents of the variable.
 */
CORE_POSIX_DLL_PUBLIC void set_or_throw(const std::string& key,
                                   const std::string& value);
/**
 * @brief set will adjust the contents of the variable identified by key to the provided value.
 * @return false in case of errors, true otherwise.
 * @param [in] key Name of the variable to set the value for.
 * @param [in] value New contents of the variable.
 * @param [out] se Receives the details in case of errors.
 */
CORE_POSIX_DLL_PUBLIC bool set(const std::string &key,
                          const std::string &value,
                          std::error_code& se) noexcept(true);
}

/**
  * @brief Returns a Process instance corresponding to this process.
  */
CORE_POSIX_DLL_PUBLIC Process instance() noexcept(true);

/**
 * @brief Query the parent of the process.
 * @return The parent of the process.
 */
CORE_POSIX_DLL_PUBLIC Process parent() noexcept(true);

/**
 * @brief Access this process's stdin.
 */
CORE_POSIX_DLL_PUBLIC std::istream& cin() noexcept(true);

/**
 * @brief Access this process's stdout.
 */
CORE_POSIX_DLL_PUBLIC std::ostream& cout() noexcept(true);

/**
 * @brief Access this process's stderr.
 */
CORE_POSIX_DLL_PUBLIC std::ostream& cerr() noexcept(true);
}
}
}

#endif // CORE_POSIX_THIS_PROCESS_H_