| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, 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 | 90 | String Environment::getVar(String const& varName) | |
| 35 | { | ||
| 36 | 90 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 37 |
1/2✓ Branch 2 taken 90 times.
✗ Branch 3 not taken.
|
90 | gate_result_t result = gate_env_get_var(varName.c_impl(), &tmp); |
| 38 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 90 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
90 | GATEXX_CHECK_EXCEPTION(result); |
| 39 | 180 | return String::createFrom(tmp); | |
| 40 | } | ||
| 41 | 91 | String Environment::getVar(String const& varName, String const& altValue) | |
| 42 | { | ||
| 43 | 91 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 44 |
1/2✓ Branch 2 taken 91 times.
✗ Branch 3 not taken.
|
91 | gate_result_t result = gate_env_get_var(varName.c_impl(), &tmp); |
| 45 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 1 times.
|
91 | if (GATE_SUCCEEDED(result)) |
| 46 | { | ||
| 47 | 90 | return String::createFrom(tmp); | |
| 48 | } | ||
| 49 | else | ||
| 50 | { | ||
| 51 | 1 | return altValue; | |
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | 90 | static gate_bool_t GATE_CALL gate_env_enum_callback(char const* varname, char const* varvalue, void* userparam) | |
| 56 | { | ||
| 57 | 90 | Map<String, String>* ptr = static_cast<Map<String, String>*>(userparam); | |
| 58 |
1/2✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
|
180 | String name(varname); |
| 59 |
1/2✓ Branch 1 taken 90 times.
✗ Branch 2 not taken.
|
90 | String value(varvalue); |
| 60 | 90 | ptr->tryAdd(name, value); | |
| 61 | 180 | return true; | |
| 62 | } | ||
| 63 | |||
| 64 | 1 | Map<String, String> Environment::getVars() | |
| 65 | { | ||
| 66 | 1 | Map<String, String> mapping; | |
| 67 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_env_list_vars(&gate_env_enum_callback, &mapping); |
| 68 | 1 | return mapping; | |
| 69 | } | ||
| 70 | |||
| 71 | 3 | String Environment::getWorkPath() | |
| 72 | { | ||
| 73 | 3 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 74 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | result_t result = gate_env_get_workpath(&path); |
| 75 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
3 | GATEXX_CHECK_EXCEPTION(result); |
| 76 | 6 | return String::createFrom(path); | |
| 77 | } | ||
| 78 | 1 | void Environment::setWorkPath(String const& path) | |
| 79 | { | ||
| 80 | 1 | result_t result = gate_env_set_workpath(path.c_impl()); | |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 82 | 1 | } | |
| 83 | |||
| 84 | 1 | String Environment::getTempPath() | |
| 85 | { | ||
| 86 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 87 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_temp_rootpath(&path); |
| 88 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 89 | 2 | return String::createFrom(path); | |
| 90 | } | ||
| 91 | 1 | String Environment::getHomePath() | |
| 92 | { | ||
| 93 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 94 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_home_rootpath(&path); |
| 95 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 96 | 2 | return String::createFrom(path); | |
| 97 | } | ||
| 98 | |||
| 99 | 2 | String Environment::getAppExecutableDirPath() | |
| 100 | { | ||
| 101 | 2 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 102 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t result = gate_env_app_rootpath(&path); |
| 103 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 104 | 4 | return String::createFrom(path); | |
| 105 | } | ||
| 106 | 1 | String Environment::getAppExecutablePath() | |
| 107 | { | ||
| 108 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 109 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_app_executable(&path); |
| 110 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 111 | 2 | return String::createFrom(path); | |
| 112 | } | ||
| 113 | 11 | String Environment::getAppExecutableName() | |
| 114 | { | ||
| 115 | 11 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 116 |
1/2✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
|
11 | result_t result = gate_env_app_executable_name(&path); |
| 117 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
11 | GATEXX_CHECK_EXCEPTION(result); |
| 118 | 22 | return String::createFrom(path); | |
| 119 | } | ||
| 120 | 2 | String Environment::getAppConfigPath(String const& appName, bool globalConfig) | |
| 121 | { | ||
| 122 | 2 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 123 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | result_t result = gate_env_app_configpath(appName.c_impl(), globalConfig, &path); |
| 124 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(result); |
| 125 | 4 | return String::createFrom(path); | |
| 126 | } | ||
| 127 | |||
| 128 | 6 | String Environment::getDataPath(DataPathIdEnum id) | |
| 129 | { | ||
| 130 | 6 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 131 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | result_t result = gate_env_data_path((uint32_t)id, &path); |
| 132 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
|
6 | GATEXX_CHECK_EXCEPTION(result); |
| 133 | ✗ | return String::createFrom(path); | |
| 134 | } | ||
| 135 | |||
| 136 | 1 | String Environment::getHostName() | |
| 137 | { | ||
| 138 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 139 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_host_name(&path); |
| 140 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 141 | 2 | return String::createFrom(path); | |
| 142 | } | ||
| 143 | 1 | String Environment::getUserName() | |
| 144 | { | ||
| 145 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 146 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_user_name(&path); |
| 147 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 148 | 2 | return String::createFrom(path); | |
| 149 | } | ||
| 150 | |||
| 151 | 1 | String Environment::getShellPath() | |
| 152 | { | ||
| 153 | 1 | gate_string_t path = GATE_STRING_INIT_EMPTY; | |
| 154 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_env_shell_path(&path); |
| 155 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 156 | 2 | return String::createFrom(path); | |
| 157 | } | ||
| 158 | |||
| 159 | } // end of namespace gate | ||
| 160 |