| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/components/cpu.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "cpu.h"cxx . . $ `<file>/src/core/components/cpu.h`/ |
| 5 | |
| 6 | #include "controls/icontrol.h"cxx . . $ `<file>/src/core/components/controls/icontrol.h`/ |
| 7 | #include "core/info/icpuinfo.h"cxx . . $ `<file>/src/core/info/icpuinfo.h`/ |
| 8 | #include "sensors/isensor.h"cxx . . $ `<file>/src/core/components/sensors/isensor.h`/ |
| 9 | #include <utility> |
| 10 | |
| 11 | CPUcxx . . $ CPU#::CPUcxx . . $ CPU#CPU(ed5a3c4a5e02d2ec).(stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ICPUInfocxx . . $ ICPUInfo#> &&info, |
| 12 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IControlcxx . . $ IControl#>> &&controls, |
| 13 | stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<ISensorcxx . . $ ISensor#>> &&sensors) noexcept |
| 14 | : id_cxx . . $ CPU#id_.(ICPUcxx . . $ ICPU#::ItemIDcxx . . $ ICPU#ItemID.) |
| 15 | , info_cxx . . $ CPU#info_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(info)) |
| 16 | , controls_cxx . . $ CPU#controls_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(controls)) |
| 17 | , sensors_cxx . . $ CPU#sensors_.(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sensors)) |
| 18 | { |
| 19 | key_cxx . . $ CPU#key_. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "CPU" +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(info_cxx . . $ CPU#info_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).physicalIdcxx . . $ ICPUInfo#physicalId(455f465bc33b4cdf).()); |
| 20 | } |
| 21 | |
| 22 | bool CPUcxx . . $ CPU#::activecxx . . $ CPU#active(50ce9a9e25b4a850).() const |
| 23 | { |
| 24 | return active_cxx . . $ CPU#active_.; |
| 25 | } |
| 26 | |
| 27 | void CPUcxx . . $ CPU#::activatecxx . . $ CPU#activate(b45ddcbc8423892c).(bool active) |
| 28 | { |
| 29 | active_cxx . . $ CPU#active_. = active; |
| 30 | } |
| 31 | |
| 32 | stdcxx . . $ std/::stringcxx . . $ std/string# const &CPUcxx . . $ CPU#::keycxx . . $ CPU#key(f4fff0029955a25f).() const |
| 33 | { |
| 34 | return key_cxx . . $ CPU#key_.; |
| 35 | } |
| 36 | |
| 37 | stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>>> |
| 38 | CPUcxx . . $ CPU#::componentInfocxx . . $ CPU#componentInfo(e6b143d762ee67dc).() const |
| 39 | { |
| 40 | stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::vectorcxx . . $ std/vector#<stdcxx . . $ std/::paircxx . . $ std/pair#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::stringcxx . . $ std/string#>>> infocxx . . $ std/pair#pair(44d48473e6bc55c4).; |
| 41 | |
| 42 | auto name(info_cxx . . $ CPU#info_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).infocxx . . $ ICPUInfo#info(3654cd48a63d288).(ICPUInfocxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02).::Keyscxx . . $ ICPUInfo#Keys#::modelNamecxx . . $ ICPUInfo#Keys#modelName.)); |
| 43 | if (!name.emptycxx . . $ std/__cxx11/basic_string#empty(3482b152b9333168).()) |
| 44 | name.appendcxx . . $ std/__cxx11/basic_string#append(978ca1133b5f6e74).("\n"); |
| 45 | name.appendcxx . . $ std/__cxx11/basic_string#append(978ca1133b5f6e74).("[CPU ").appendcxx . . $ std/__cxx11/basic_string#append(c0b47be1fddc0e75).(stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(info_cxx . . $ CPU#info_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).physicalIdcxx . . $ ICPUInfo#physicalId(455f465bc33b4cdf).())).appendcxx . . $ std/__cxx11/basic_string#append(978ca1133b5f6e74).("]"); |
| 46 | info.firstcxx . . $ std/pair#first. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). name; |
| 47 | |
| 48 | auto infoKeys = info_cxx . . $ CPU#info_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).keyscxx . . $ ICPUInfo#keys(491c255a7e496038).(); |
| 49 | for (auto &infoKey : infoKeys) |
| 50 | info.secondcxx . . $ std/pair#second..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(infoKey, info_cxx . . $ CPU#info_.->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).infocxx . . $ ICPUInfo#info(3654cd48a63d288).(infoKey)); |
| 51 | |
| 52 | return infocxx . . $ std/pair#pair(59816e23a2f1b31c).; |
| 53 | } |
| 54 | |
| 55 | void CPUcxx . . $ CPU#::initcxx . . $ CPU#init(49f6e7a06ebc5aa8).() |
| 56 | { |
| 57 | for (auto &control : controls_cxx . . $ CPU#controls_.) |
| 58 | control->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).initcxx . . $ IControl#init(49f6e7a06ebc5aa8).(); |
| 59 | } |
| 60 | |
| 61 | void CPUcxx . . $ CPU#::preInitcxx . . $ CPU#preInit(151e9138769f295e).(ICommandQueuecxx . . $ ICommandQueue# &ctlCmds) |
| 62 | { |
| 63 | for (auto &control : controls_cxx . . $ CPU#controls_.) |
| 64 | control->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).preInitcxx . . $ IControl#preInit(151e9138769f295e).(ctlCmds); |
| 65 | } |
| 66 | |
| 67 | void CPUcxx . . $ CPU#::postInitcxx . . $ CPU#postInit(151e9138769f295e).(ICommandQueuecxx . . $ ICommandQueue# &ctlCmds) |
| 68 | { |
| 69 | for (auto &control : controls_cxx . . $ CPU#controls_.) |
| 70 | control->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).postInitcxx . . $ IControl#postInit(151e9138769f295e).(ctlCmds); |
| 71 | } |
| 72 | |
| 73 | void CPUcxx . . $ CPU#::synccxx . . $ CPU#sync(151e9138769f295e).(ICommandQueuecxx . . $ ICommandQueue# &ctlCmds) |
| 74 | { |
| 75 | if (active_cxx . . $ CPU#active_.) { |
| 76 | // NOTE clean and sync commands generation cannot be interleaved. |
| 77 | // Interleaving them could cause conflicts between clean and sync |
| 78 | // commands of different controls, leading to an incorrect hardware |
| 79 | // state. |
| 80 | for (auto &control : controls_cxx . . $ CPU#controls_.) |
| 81 | control->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).cleancxx . . $ IControl#clean(151e9138769f295e).(ctlCmds); |
| 82 | for (auto &control : controls_cxx . . $ CPU#controls_.) |
| 83 | control->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).synccxx . . $ IControl#sync(151e9138769f295e).(ctlCmds); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | void CPUcxx . . $ CPU#::updateSensorscxx . . $ CPU#updateSensors(b9a76d75a3ae6a25).( |
| 88 | stdcxx . . $ std/::unordered_mapcxx . . $ std/unordered_map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::unordered_setcxx . . $ std/unordered_set#<stdcxx . . $ std/::stringcxx . . $ std/string#>> const &ignored) |
| 89 | { |
| 90 | for (auto &sensor : sensors_cxx . . $ CPU#sensors_.) { |
| 91 | if (ignored.countcxx . . $ std/unordered_map#count(b71ff106d381144b).(key_cxx . . $ CPU#key_.) > 0 && ignored.atcxx . . $ std/unordered_map#at(7589f80bac630479).(key_cxx . . $ CPU#key_.).countcxx . . $ std/unordered_set#count(2f4fc31398af827b).(sensor->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).IDcxx . . $ Item#ID(f4fff0029955a25f).()) > 0) |
| 92 | continue; // skip ignored sensors |
| 93 | |
| 94 | sensor->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).updatecxx . . $ ISensor#update(49f6e7a06ebc5aa8).(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | ICPUInfocxx . . $ ICPUInfo# const &CPUcxx . . $ CPU#::infocxx . . $ CPU#info(95bebdd3f04fe09b).() const |
| 99 | { |
| 100 | return *cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).info_cxx . . $ CPU#info_.; |
| 101 | } |
| 102 | |
| 103 | stdcxx . . $ std/::stringcxx . . $ std/string# const &CPUcxx . . $ CPU#::IDcxx . . $ CPU#ID(f4fff0029955a25f).() const |
| 104 | { |
| 105 | return id_cxx . . $ CPU#id_.; |
| 106 | } |
| 107 | |
| 108 | void CPUcxx . . $ CPU#::importWithcxx . . $ CPU#importWith(94eddebf9440278).(Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer# &i) |
| 109 | { |
| 110 | auto importer = i.provideImportercxx . . $ Importable#Importer#provideImporter(c13a3bcac0db4745).(*this); |
| 111 | if (importer.has_valuecxx . . $ std/optional#has_value(3482b152b9333168).()) { |
| 112 | auto &cpuImporter = dynamic_cast<ICPUcxx . . $ ICPU#::Importercxx . . $ ISysComponent#Importer# &>(importer->cxx . . $ std/optional#`operator->`(258ee1c9e0a18a5c).getcxx . . $ std/reference_wrapper#get(d426bc7b625886b7).()); |
| 113 | |
| 114 | activatecxx . . $ CPU#activate(b45ddcbc8423892c).(cpuImporter.provideActivecxx . . $ ISysComponent#Importer#provideActive(50ce9a9e25b4a850).()); |
| 115 | |
| 116 | for (auto &control : controls_cxx . . $ CPU#controls_.) |
| 117 | control->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).importWithcxx . . $ Importable#importWith(94eddebf9440278).(*cxx . . $ std/optional#`operator*`(47e1a15210ec6306).importer); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | void CPUcxx . . $ CPU#::exportWithcxx . . $ CPU#exportWith(5b5c94ff60635419).(Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter# &e) const |
| 122 | { |
| 123 | auto exporter = e.provideExportercxx . . $ Exportable#Exporter#provideExporter(3acccbde2694e33a).(*this); |
| 124 | if (exporter.has_valuecxx . . $ std/optional#has_value(3482b152b9333168).()) { |
| 125 | auto &cpuExporter = dynamic_cast<ICPUcxx . . $ ICPU#::Exportercxx . . $ ICPU#Exporter# &>(exporter->cxx . . $ std/optional#`operator->`(258ee1c9e0a18a5c).getcxx . . $ std/reference_wrapper#get(d426bc7b625886b7).()); |
| 126 | |
| 127 | cpuExporter.takeActivecxx . . $ ISysComponent#Exporter#takeActive(b45ddcbc8423892c).(activecxx . . $ CPU#active(50ce9a9e25b4a850).()); |
| 128 | cpuExporter.takeInfocxx . . $ ICPU#Exporter#takeInfo(b148e3110650f661).(infocxx . . $ CPU#info(95bebdd3f04fe09b).()); |
| 129 | |
| 130 | for (auto const &sensor : sensors_cxx . . $ CPU#sensors_.) |
| 131 | cpuExporter.takeSensorcxx . . $ ICPU#Exporter#takeSensor(73745a8c6f82d10e).(*cxx . . $ std/unique_ptr#`operator*`(2fbe4a4c783c152d).sensor); |
| 132 | |
| 133 | for (auto const &control : controls_cxx . . $ CPU#controls_.) |
| 134 | control->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).exportWithcxx . . $ Exportable#exportWith(5b5c94ff60635419).(*cxx . . $ std/optional#`operator*`(47e1a15210ec6306).exporter); |
| 135 | } |
| 136 | } |