Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | |||
29 | #include "gate/environments.hpp" | ||
30 | |||
31 | namespace gate | ||
32 | { | ||
33 | |||
34 | 88 | String Environment::getVar(String const& varName) | |
35 | { | ||
36 | 88 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
37 |
1/2✓ Branch 2 taken 88 times.
✗ Branch 3 not taken.
|
88 | gate_result_t result = gate_env_get_var(varName.c_impl(), &tmp); |
38 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 88 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
88 | GATEXX_CHECK_EXCEPTION(result); |
39 | 176 | return String::createFrom(tmp); | |
40 | } | ||
41 | ✗ | String Environment::getVar(String const& varName, String const& altValue) | |
42 | { | ||
43 | ✗ | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
44 | ✗ | gate_result_t result = gate_env_get_var(varName.c_impl(), &tmp); | |
45 | ✗ | if (GATE_SUCCEEDED(result)) | |
46 | { | ||
47 | ✗ | return String::createFrom(tmp); | |
48 | } | ||
49 | else | ||
50 | { | ||
51 | ✗ | return altValue; | |
52 | } | ||
53 | } | ||
54 | |||
55 | 88 | static gate_bool_t gate_env_enum_callback(char const* varname, char const* varvalue, void* userparam) | |
56 | { | ||
57 | 88 | Map<String, String>* ptr = static_cast<Map<String, String>*>(userparam); | |
58 | try | ||
59 | { | ||
60 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
176 | String name(varname); |
61 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
176 | String value(varvalue); |
62 |
1/2✓ Branch 1 taken 88 times.
✗ Branch 2 not taken.
|
88 | ptr->add(name, value); |
63 | } | ||
64 | ✗ | catch (...) | |
65 | { | ||
66 | // well, just ignore allocation problems as we cannot return the error | ||
67 | //TODO: Add userparam that is able to carry errors back to the source function | ||
68 | // return false; | ||
69 | } | ||
70 | 88 | return true; | |
71 | } | ||
72 | |||
73 | 1 | Map<String, String> Environment::getVars() | |
74 | { | ||
75 | 1 | Map<String, String> mapping; | |
76 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_env_list_vars(&gate_env_enum_callback, &mapping); |
77 | 1 | return mapping; | |
78 | } | ||
79 | |||
80 | 3 | String Environment::getWorkPath() | |
81 | { | ||
82 | 3 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
83 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | result_t result = gate_env_get_workpath(&path); |
84 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
3 | GATEXX_CHECK_EXCEPTION(result); |
85 | 6 | return String::createFrom(path); | |
86 | } | ||
87 | 1 | void Environment::setWorkPath(String const& path) | |
88 | { | ||
89 | 1 | result_t result = gate_env_set_workpath(path.c_impl()); | |
90 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
91 | 1 | } | |
92 | |||
93 | 1 | String Environment::getTempPath() | |
94 | { | ||
95 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
96 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_temp_rootpath(&path); |
97 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
98 | 2 | return String::createFrom(path); | |
99 | } | ||
100 | 1 | String Environment::getHomePath() | |
101 | { | ||
102 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
103 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_home_rootpath(&path); |
104 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
105 | 2 | return String::createFrom(path); | |
106 | } | ||
107 | |||
108 | 1 | String Environment::getAppExecutableDirPath() | |
109 | { | ||
110 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
111 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_app_rootpath(&path); |
112 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
113 | 2 | return String::createFrom(path); | |
114 | } | ||
115 | 1 | String Environment::getAppExecutablePath() | |
116 | { | ||
117 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
118 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_app_executable(&path); |
119 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
120 | 2 | return String::createFrom(path); | |
121 | } | ||
122 | 1 | String Environment::getAppExecutableName() | |
123 | { | ||
124 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
125 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_app_executable_name(&path); |
126 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
127 | 2 | return String::createFrom(path); | |
128 | } | ||
129 | 2 | String Environment::getAppConfigPath(String const& appName, bool globalConfig) | |
130 | { | ||
131 | 2 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
132 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result_t result = gate_env_app_configpath(appName.c_impl(), globalConfig, &path); |
133 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
134 | 4 | return String::createFrom(path); | |
135 | } | ||
136 | |||
137 | ✗ | String Environment::getDataPath(DataPathIdEnum id) | |
138 | { | ||
139 | ✗ | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
140 | ✗ | result_t result = gate_env_data_path((uint32_t)id, &path); | |
141 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
142 | ✗ | return String::createFrom(path); | |
143 | } | ||
144 | |||
145 | 1 | String Environment::getHostName() | |
146 | { | ||
147 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
148 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_get_workpath(&path); |
149 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
150 | 2 | return String::createFrom(path); | |
151 | } | ||
152 | 1 | String Environment::getUserName() | |
153 | { | ||
154 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
155 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_get_workpath(&path); |
156 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
157 | 2 | return String::createFrom(path); | |
158 | } | ||
159 | |||
160 | ✗ | String Environment::getShellPath() | |
161 | { | ||
162 | ✗ | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
163 | ✗ | result_t result = gate_env_shell_path(&path); | |
164 | ✗ | GATEXX_CHECK_EXCEPTION(result); | |
165 | ✗ | return String::createFrom(path); | |
166 | } | ||
167 | |||
168 | } // end of namespace gate | ||
169 |