| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2026, Stefan Meislinger | | ||
| 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/system/os.hpp" | ||
| 30 | |||
| 31 | namespace gate | ||
| 32 | { | ||
| 33 | namespace sys | ||
| 34 | { | ||
| 35 | |||
| 36 | 1 | OperatingSystem::PlatformEnum OperatingSystem::getPlatform() | |
| 37 | { | ||
| 38 | 1 | uint32_t id = 0; | |
| 39 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_os_get_platform(&id); |
| 40 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(res); |
| 41 | 1 | return static_cast<PlatformEnum>(id); | |
| 42 | } | ||
| 43 | 27 | String OperatingSystem::getPlatformLabel(PlatformEnum id) | |
| 44 | { | ||
| 45 | 27 | char const* static_text = gate_os_get_platform_label(static_cast<uint32_t>(id)); | |
| 46 | 27 | return String::createStatic(static_text); | |
| 47 | } | ||
| 48 | 1 | uint32_t OperatingSystem::getAddressSpace() | |
| 49 | { | ||
| 50 | 1 | return gate_os_address_space(); | |
| 51 | } | ||
| 52 | 1 | uint32_t OperatingSystem::getUpTimeSeconds() | |
| 53 | { | ||
| 54 | 1 | return gate_os_up_time_seconds(); | |
| 55 | } | ||
| 56 | 1 | Time OperatingSystem::getBootTime() | |
| 57 | { | ||
| 58 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Time bootTime = Time::now(); |
| 59 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | uint64_t up_time = gate_os_up_time_seconds(); |
| 60 | 1 | up_time *= 1000000; | |
| 61 | 1 | bootTime.timestamp -= up_time; | |
| 62 | 1 | return bootTime; | |
| 63 | } | ||
| 64 | |||
| 65 | 1 | String OperatingSystem::getOSName() | |
| 66 | { | ||
| 67 | char buffer[1024]; | ||
| 68 | 1 | size_t buffer_used = 0; | |
| 69 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_os_print_osname(buffer, sizeof(buffer), &buffer_used); |
| 70 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_ERROR(res); |
| 71 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, buffer_used); |
| 72 | } | ||
| 73 | 1 | String OperatingSystem::getProductName() | |
| 74 | { | ||
| 75 | char buffer[1024]; | ||
| 76 | 1 | size_t buffer_used = 0; | |
| 77 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_os_print_productname(buffer, sizeof(buffer), &buffer_used); |
| 78 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 79 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, buffer_used); |
| 80 | } | ||
| 81 | 1 | Version OperatingSystem::getVersion() | |
| 82 | { | ||
| 83 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Version ver; |
| 84 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_os_get_version(&ver); |
| 85 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 86 | 1 | return ver; | |
| 87 | } | ||
| 88 | |||
| 89 | 2 | String OperatingSystem::getHostName() | |
| 90 | { | ||
| 91 | gate_string_t hostname; | ||
| 92 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t res = gate_os_get_hostname(&hostname); |
| 93 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(res); |
| 94 | 4 | return String::createFrom(hostname); | |
| 95 | } | ||
| 96 | 1 | void OperatingSystem::setHostName(String const& newHostName) | |
| 97 | { | ||
| 98 | 1 | result_t res = gate_os_set_hostname(newHostName.c_impl()); | |
| 99 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 100 | ✗ | } | |
| 101 | |||
| 102 | 2 | String OperatingSystem::getHostDomain() | |
| 103 | { | ||
| 104 | gate_string_t domainname; | ||
| 105 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | result_t res = gate_os_get_hostdomainname(&domainname); |
| 106 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
2 | GATEXX_CHECK_EXCEPTION(res); |
| 107 | 4 | return String::createFrom(domainname); | |
| 108 | } | ||
| 109 | 1 | void OperatingSystem::setHostDomain(String const& newDomainName) | |
| 110 | { | ||
| 111 | 1 | result_t res = gate_os_set_hostdomainname(newDomainName.c_impl()); | |
| 112 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 113 | ✗ | } | |
| 114 | |||
| 115 | |||
| 116 | 1 | Array<uint8_t> OperatingSystem::getUid() | |
| 117 | { | ||
| 118 | gate_uint8_t buffer[1024]; | ||
| 119 | 1 | size_t buffer_used = 0; | |
| 120 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_os_get_uid(buffer, sizeof(buffer), &buffer_used); |
| 121 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 122 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return Array<uint8_t>(buffer, buffer_used); |
| 123 | } | ||
| 124 | |||
| 125 | 1 | void OperatingSystem::shutdown() | |
| 126 | { | ||
| 127 | 1 | result_t res = gate_os_shutdown(); | |
| 128 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 129 | ✗ | } | |
| 130 | 1 | void OperatingSystem::reboot() | |
| 131 | { | ||
| 132 | 1 | result_t res = gate_os_reboot(); | |
| 133 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 134 | ✗ | } | |
| 135 | |||
| 136 | |||
| 137 | |||
| 138 | |||
| 139 | 2 | SystemCpuInfo::SystemCpuInfo() | |
| 140 | { | ||
| 141 | 2 | gate_os_cpuinfo_t* ptr = static_cast<gate_os_cpuinfo_t*>(this); | |
| 142 | 2 | gate_mem_clear(ptr, sizeof(gate_os_cpuinfo_t)); | |
| 143 | 2 | } | |
| 144 | 1 | uint32_t SystemCpuInfo::getCores() const | |
| 145 | { | ||
| 146 | 1 | return this->cpu_cores; | |
| 147 | } | ||
| 148 | 1 | uint32_t SystemCpuInfo::getVersion() const | |
| 149 | { | ||
| 150 | 1 | return this->cpu_version; | |
| 151 | } | ||
| 152 | 1 | uint32_t SystemCpuInfo::getSpeedMHz() const | |
| 153 | { | ||
| 154 | 1 | return this->cpu_speed_mhz; | |
| 155 | } | ||
| 156 | 1 | uint32_t SystemCpuInfo::getCacheSize() const | |
| 157 | { | ||
| 158 | 1 | return this->cpu_cache_bytes; | |
| 159 | } | ||
| 160 | 1 | String SystemCpuInfo::getName() const | |
| 161 | { | ||
| 162 | 1 | return String(this->cpu_name); | |
| 163 | } | ||
| 164 | 1 | String SystemCpuInfo::getVendor() const | |
| 165 | { | ||
| 166 | 1 | return String(this->cpu_vendor); | |
| 167 | } | ||
| 168 | 1 | String SystemCpuInfo::getDescription() const | |
| 169 | { | ||
| 170 | 1 | return String(this->cpu_description); | |
| 171 | } | ||
| 172 | |||
| 173 | |||
| 174 | |||
| 175 | 1 | SystemCpuActivation::SystemCpuActivation() | |
| 176 | { | ||
| 177 | 1 | gate_os_cpu_activation_t* ptr = static_cast<gate_os_cpu_activation_t*>(this); | |
| 178 | 1 | gate_mem_clear(ptr, sizeof(gate_os_cpu_activation_t)); | |
| 179 | 1 | } | |
| 180 | |||
| 181 | 64 | bool_t SystemCpuActivation::get(size_t coreIndex) | |
| 182 | { | ||
| 183 | 64 | return gate_os_cpu_get_activation(this, coreIndex); | |
| 184 | } | ||
| 185 | 32 | void SystemCpuActivation::set(size_t coreIndex, bool_t enabled) | |
| 186 | { | ||
| 187 | 32 | result_t res = gate_os_cpu_set_activation(this, coreIndex, enabled); | |
| 188 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
|
32 | GATEXX_CHECK_ERROR(res); |
| 189 | 32 | } | |
| 190 | |||
| 191 | |||
| 192 | |||
| 193 | 1 | SystemCpu::ArchEnum SystemCpu::getArchitecture() | |
| 194 | { | ||
| 195 | 1 | enumint_t arch = 0; | |
| 196 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_os_get_cpu_architecture(&arch); |
| 197 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 198 | 1 | return static_cast<SystemCpu::ArchEnum>(arch); | |
| 199 | } | ||
| 200 | |||
| 201 | 14 | String SystemCpu::getArchitectureLabel(ArchEnum arch) | |
| 202 | { | ||
| 203 | 14 | char const* static_text = gate_os_get_cpu_architecture_label(static_cast<gate_uint8_t>(arch)); | |
| 204 | 14 | return String::createStatic(static_text); | |
| 205 | } | ||
| 206 | |||
| 207 | 1 | SystemCpuInfo SystemCpu::getCpuInfo() | |
| 208 | { | ||
| 209 | 1 | SystemCpuInfo info; | |
| 210 | 1 | result_t res = gate_os_get_cpu_info(&info); | |
| 211 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 212 | 1 | return info; | |
| 213 | } | ||
| 214 | |||
| 215 | 99 | static gate_bool_t GATE_CALL gate_os_cpu_feature_callback(char const* feature_name, void* param) | |
| 216 | { | ||
| 217 | 99 | ArrayList<String>* ptr_features = static_cast<ArrayList<String>*>(param); | |
| 218 |
2/4✓ Branch 1 taken 99 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 99 times.
✗ Branch 5 not taken.
|
99 | GATEXX_TRY_IGNORE({ |
| 219 | String text(feature_name); | ||
| 220 | ptr_features->add(text); | ||
| 221 | }); | ||
| 222 | 99 | return true; | |
| 223 | } | ||
| 224 | |||
| 225 | 1 | Array<String> SystemCpu::getCpuFeatures() | |
| 226 | { | ||
| 227 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | ArrayList<String> features; |
| 228 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t res = gate_os_enum_cpu_features(&gate_os_cpu_feature_callback, &features); |
| 229 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 230 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return features.toArray(); |
| 231 | } | ||
| 232 | |||
| 233 | |||
| 234 | ✗ | SystemCpuActivation SystemCpu::getProcessAffinity() | |
| 235 | { | ||
| 236 | ✗ | SystemCpuActivation affinity; | |
| 237 | ✗ | result_t res = gate_os_get_process_cpu_affinity(&affinity); | |
| 238 | ✗ | GATEXX_CHECK_EXCEPTION(res); | |
| 239 | ✗ | return affinity; | |
| 240 | } | ||
| 241 | |||
| 242 | ✗ | void SystemCpu::setProcessAffinity(SystemCpuActivation const& affinity) | |
| 243 | { | ||
| 244 | ✗ | result_t res = gate_os_set_process_cpu_affinity(&affinity); | |
| 245 | ✗ | GATEXX_CHECK_EXCEPTION(res); | |
| 246 | ✗ | } | |
| 247 | |||
| 248 | |||
| 249 | |||
| 250 | |||
| 251 | 1 | SystemCpuLoad::SystemCpuLoad() | |
| 252 | { | ||
| 253 | 1 | result_t result = gate_os_cpu_load_init(&this->impl); | |
| 254 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 255 | 1 | } | |
| 256 | 2 | SystemCpuLoad::~SystemCpuLoad() noexcept | |
| 257 | { | ||
| 258 | 1 | gate_os_cpu_load_uninit(&this->impl); | |
| 259 | 1 | } | |
| 260 | |||
| 261 | 1 | uint16_t SystemCpuLoad::updateState(real32_t& percent) | |
| 262 | { | ||
| 263 | 1 | uint16_t current_load = 0; | |
| 264 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | result_t result = gate_os_cpu_load_update(&this->impl, ¤t_load); |
| 265 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 266 | 1 | percent = (static_cast<real32_t>(current_load) / 65535.0f) * 100.0f; | |
| 267 | 1 | return current_load; | |
| 268 | } | ||
| 269 | |||
| 270 | |||
| 271 | 1 | void SystemMemory::getPhysicalLoad(uint64_t& totalBytes, uint64_t& availableBytes) | |
| 272 | { | ||
| 273 | 1 | result_t result = gate_os_get_physical_memory(&totalBytes, &availableBytes); | |
| 274 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 275 | 1 | } | |
| 276 | 1 | void SystemMemory::getVirtualLoad(uint64_t& totalBytes, uint64_t& availableBytes) | |
| 277 | { | ||
| 278 | 1 | result_t result = gate_os_get_virtual_memory(&totalBytes, &availableBytes); | |
| 279 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(result); |
| 280 | 1 | } | |
| 281 | |||
| 282 | } // end of namespace sys | ||
| 283 | } // end of namespace gate | ||
| 284 |