Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 130 additions & 38 deletions src/hostname1/hostname1_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ Hostname1Client::Hostname1Client(sdbus::IConnection& connection)
: ProxyInterfaces{connection, sdbus::ServiceName(INTERFACE_NAME),
sdbus::ObjectPath(OBJECT_PATH)} {
registerProxy();
auto description = Describe();
// Parse description as JSON and print key: value lines
std::string parsed = Utils::parseDescriptionJson(description);
spdlog::info("Hostname1 description:\n{}\nParsed description:\n{}",
description, parsed);

if (const std::string description = Describe(); !description.empty()) {
if (const auto s = glz::read_json<Hostname1>(description)) {
printHostname1(s.value());
}
}
}

Hostname1Client::~Hostname1Client() {
Expand Down Expand Up @@ -73,8 +74,8 @@ void Hostname1Client::updateHostname1(
hostname1_.OperatingSystemCPEName = value.get<std::string>();
} else if (key == "OperatingSystemSupportEnd") {
hostname1_.OperatingSystemSupportEnd = value.get<uint64_t>();
} else if (key == "HomeURL") {
hostname1_.HomeURL = value.get<std::string>();
} else if (key == "OperatingSystemHomeURL") {
hostname1_.OperatingSystemHomeURL = value.get<std::string>();
} else if (key == "HardwareVendor") {
hostname1_.HardwareVendor = value.get<std::string>();
} else if (key == "HardwareModel") {
Expand All @@ -86,9 +87,9 @@ void Hostname1Client::updateHostname1(
} else if (key == "FirmwareDate") {
hostname1_.FirmwareDate = value.get<uint64_t>();
} else if (key == "MachineID") {
hostname1_.MachineID = value.get<std::vector<uint8_t>>();
MachineID_ = value.get<std::vector<uint8_t>>();
} else if (key == "BootID") {
hostname1_.BootID = value.get<std::vector<uint8_t>>();
BootID_ = value.get<std::vector<uint8_t>>();
}
}
}
Expand All @@ -98,29 +99,32 @@ void Hostname1Client::printHostname1() const {
if (!hostname1_.Hostname.empty()) {
os << "\tHostname: " << hostname1_.Hostname << std::endl;
}
if (!hostname1_.StaticHostname.empty()) {
if (hostname1_.StaticHostname.empty()) {
os << "\tStaticHostname: " << hostname1_.StaticHostname << std::endl;
}
if (!hostname1_.PrettyHostname.empty()) {
os << "\tPrettyHostname: " << hostname1_.PrettyHostname << std::endl;
if (hostname1_.PrettyHostname.has_value()) {
os << "\tPrettyHostname: " << hostname1_.PrettyHostname.value()
<< std::endl;
}
if (!hostname1_.DefaultHostname.empty()) {
os << "\tDefaultHostname: " << hostname1_.DefaultHostname << std::endl;
if (hostname1_.DefaultHostname.has_value()) {
os << "\tDefaultHostname: " << hostname1_.DefaultHostname.value()
<< std::endl;
}
if (!hostname1_.HostnameSource.empty()) {
os << "\tHostnameSource: " << hostname1_.HostnameSource << std::endl;
if (hostname1_.HostnameSource.has_value()) {
os << "\tHostnameSource: " << hostname1_.HostnameSource.value()
<< std::endl;
}
if (!hostname1_.IconName.empty()) {
os << "\tIconName: " << hostname1_.IconName << std::endl;
if (hostname1_.IconName.has_value()) {
os << "\tIconName: " << hostname1_.IconName.value() << std::endl;
}
if (!hostname1_.Chassis.empty()) {
os << "\tChassis: " << hostname1_.Chassis << std::endl;
if (hostname1_.Chassis.has_value()) {
os << "\tChassis: " << hostname1_.Chassis.value() << std::endl;
}
if (!hostname1_.Deployment.empty()) {
os << "\tDeployment: " << hostname1_.Deployment << std::endl;
if (hostname1_.Deployment.has_value()) {
os << "\tDeployment: " << hostname1_.Deployment.value() << std::endl;
}
if (!hostname1_.Location.empty()) {
os << "\tLocation: " << hostname1_.Location << std::endl;
if (hostname1_.Location.has_value()) {
os << "\tLocation: " << hostname1_.Location.value() << std::endl;
}
if (!hostname1_.KernelName.empty()) {
os << "\tKernelName: " << hostname1_.KernelName << std::endl;
Expand All @@ -143,39 +147,127 @@ void Hostname1Client::printHostname1() const {
os << "\tOperatingSystemSupportEnd: "
<< hostname1_.OperatingSystemSupportEnd.value() << std::endl;
}
if (!hostname1_.HomeURL.empty()) {
os << "\tHomeURL: " << hostname1_.HomeURL << std::endl;
if (hostname1_.OperatingSystemHomeURL.has_value()) {
os << "\tOperatingSystemHomeUrl: "
<< hostname1_.OperatingSystemHomeURL.value() << std::endl;
}
if (!hostname1_.HardwareVendor.empty()) {
os << "\tHardwareVendor: " << hostname1_.HardwareVendor << std::endl;
if (hostname1_.HardwareVendor.has_value()) {
os << "\tHardwareVendor: " << hostname1_.HardwareVendor.value()
<< std::endl;
}
if (!hostname1_.HardwareModel.empty()) {
os << "\tHardwareModel: " << hostname1_.HardwareModel << std::endl;
if (hostname1_.HardwareModel.has_value()) {
os << "\tHardwareModel: " << hostname1_.HardwareModel.value() << std::endl;
}
if (!hostname1_.FirmwareVersion.empty()) {
os << "\tFirmwareVersion: " << hostname1_.FirmwareVersion << std::endl;
if (hostname1_.FirmwareVersion.has_value()) {
os << "\tFirmwareVersion: " << hostname1_.FirmwareVersion.value()
<< std::endl;
}
if (!hostname1_.FirmwareVendor.empty()) {
os << "\tFirmwareVendor: " << hostname1_.FirmwareVendor << std::endl;
if (hostname1_.FirmwareVendor.has_value()) {
os << "\tFirmwareVendor: " << hostname1_.FirmwareVendor.value()
<< std::endl;
}
if (hostname1_.FirmwareDate.has_value()) {
os << "\tFirmwareDate: " << hostname1_.FirmwareDate.value() << std::endl;
}
if (hostname1_.MachineID.has_value()) {
if (MachineID_.has_value()) {
os << "\tMachineID: ";
for (const auto& b : hostname1_.MachineID.value()) {
for (const auto& b : MachineID_.value()) {
os << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(b)
<< " ";
}
os << std::endl;
}
if (hostname1_.BootID.has_value()) {
if (BootID_.has_value()) {
os << "\tBootID: ";
for (const auto& b : hostname1_.BootID.value()) {
for (const auto& b : BootID_.value()) {
os << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(b)
<< " ";
}
os << std::endl;
}
spdlog::info("\n{}", os.str());
}

void Hostname1Client::printHostname1(const Hostname1& val) {
std::ostringstream os;
if (!val.Hostname.empty()) {
os << "\tHostname: " << val.Hostname << std::endl;
}
if (val.StaticHostname.empty()) {
os << "\tStaticHostname: " << val.StaticHostname << std::endl;
}
if (val.PrettyHostname.has_value()) {
os << "\tPrettyHostname: " << val.PrettyHostname.value() << std::endl;
}
if (val.DefaultHostname.has_value()) {
os << "\tDefaultHostname: " << val.DefaultHostname.value() << std::endl;
}
if (val.HostnameSource.has_value()) {
os << "\tHostnameSource: " << val.HostnameSource.value() << std::endl;
}
if (val.IconName.has_value()) {
os << "\tIconName: " << val.IconName.value() << std::endl;
}
if (val.Chassis.has_value()) {
os << "\tChassis: " << val.Chassis.value() << std::endl;
}
if (val.Deployment.has_value()) {
os << "\tDeployment: " << val.Deployment.value() << std::endl;
}
if (val.Location.has_value()) {
os << "\tLocation: " << val.Location.value() << std::endl;
}
if (!val.KernelName.empty()) {
os << "\tKernelName: " << val.KernelName << std::endl;
}
if (!val.KernelRelease.empty()) {
os << "\tKernelRelease: " << val.KernelRelease << std::endl;
}
if (!val.KernelVersion.empty()) {
os << "\tKernelVersion: " << val.KernelVersion << std::endl;
}
if (!val.OperatingSystemPrettyName.empty()) {
os << "\tOperatingSystemPrettyName: " << val.OperatingSystemPrettyName
<< std::endl;
}
if (val.OperatingSystemReleaseData.has_value()) {
os << "\tOperatingSystemReleaseData: " << std::endl;
for (const auto& item : val.OperatingSystemReleaseData.value()) {
os << "\t\t" << item << std::endl;
}
}
if (!val.OperatingSystemCPEName.empty()) {
os << "\tOperatingSystemCPEName: " << val.OperatingSystemCPEName
<< std::endl;
}
if (val.OperatingSystemSupportEnd.has_value()) {
os << "\tOperatingSystemSupportEnd: "
<< val.OperatingSystemSupportEnd.value() << std::endl;
}
if (val.OperatingSystemHomeURL.has_value()) {
os << "\tOperatingSystemHomeURL: " << val.OperatingSystemHomeURL.value()
<< std::endl;
}
if (val.HardwareVendor.has_value()) {
os << "\tHardwareVendor: " << val.HardwareVendor.value() << std::endl;
}
if (val.HardwareModel.has_value()) {
os << "\tHardwareModel: " << val.HardwareModel.value() << std::endl;
}
if (val.FirmwareVersion.has_value()) {
os << "\tFirmwareVersion: " << val.FirmwareVersion.value() << std::endl;
}
if (val.FirmwareVendor.has_value()) {
os << "\tFirmwareVendor: " << val.FirmwareVendor.value() << std::endl;
}
if (val.FirmwareDate.has_value()) {
os << "\tFirmwareDate: " << val.FirmwareDate.value() << std::endl;
}
if (val.MachineID.has_value()) {
os << "\tMachineID: " << val.MachineID.value() << std::endl;
}
if (val.BootID.has_value()) {
os << "\tBootID: " << val.BootID.value() << std::endl;
}
spdlog::info("\n{}", os.str());
}
66 changes: 40 additions & 26 deletions src/hostname1/hostname1_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,59 @@ class Hostname1Client final
static constexpr auto INTERFACE_NAME = "org.freedesktop.hostname1";
static constexpr auto OBJECT_PATH = "/org/freedesktop/hostname1";

explicit Hostname1Client(sdbus::IConnection& connection);

virtual ~Hostname1Client();

void updateHostname1(
const std::map<sdbus::PropertyName, sdbus::Variant>& changedProperties);

void printHostname1() const;

struct hostname1 {
struct Hostname1 {
std::string Hostname;
std::string StaticHostname;
std::string PrettyHostname;
std::string DefaultHostname;
std::string HostnameSource;
std::string IconName;
std::string Chassis;
std::string Deployment;
std::string Location;
std::optional<std::string> PrettyHostname;
std::optional<std::string> DefaultHostname;
std::optional<std::string> HostnameSource;
std::optional<std::string> IconName;
std::optional<std::string> Chassis;
std::optional<std::string> ChassisAssetTag;
std::optional<std::string> Deployment;
std::optional<std::string> Location;
std::string KernelName;
std::string KernelRelease;
std::string KernelVersion;
std::string OperatingSystemPrettyName;
std::string OperatingSystemCPEName;
std::optional<std::string> OperatingSystemHomeURL;
std::optional<uint64_t> OperatingSystemSupportEnd;
std::string HomeURL;
std::string HardwareVendor;
std::string HardwareModel;
std::string FirmwareVersion;
std::string FirmwareVendor;
std::optional<std::vector<std::string>> OperatingSystemReleaseData;
std::optional<std::string> OperatingSystemImageID;
std::optional<std::string> OperatingSystemImageVersion;
std::optional<std::vector<std::string>> MachineInformationData;
std::optional<std::string> HardwareVendor;
std::optional<std::string> HardwareModel;
std::optional<std::string> HardwareSerial;
std::optional<std::string> HardwareSKU;
std::optional<std::string> HardwareVersion;
std::optional<std::string> FirmwareVersion;
std::optional<std::string> FirmwareVendor;
std::optional<uint64_t> FirmwareDate;
std::optional<std::vector<uint8_t>> MachineID;
std::optional<std::vector<uint8_t>> BootID;
std::optional<std::string> MachineID;
std::optional<std::string> BootID;
std::optional<std::string> ProductUUID;
std::optional<std::string> VSockCID;
};

[[nodiscard]] const hostname1& getHostname1() const { return hostname1_; }
explicit Hostname1Client(sdbus::IConnection& connection);

virtual ~Hostname1Client();

void updateHostname1(
const std::map<sdbus::PropertyName, sdbus::Variant>& changedProperties);

void printHostname1() const;
static void printHostname1(const Hostname1& val);

[[nodiscard]] const Hostname1& getHostname1() const { return hostname1_; }

private:
hostname1 hostname1_{};
Hostname1 hostname1_{};

std::optional<std::vector<uint8_t>> MachineID_;
std::optional<std::vector<uint8_t>> BootID_;

void onPropertiesChanged(
const sdbus::InterfaceName& interfaceName,
Expand Down
2 changes: 2 additions & 0 deletions src/hostname1/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "hostname1_client.h"

#include "../utils/utils.h"

int main() {
const auto connection = sdbus::createSystemBusConnection();
connection->enterEventLoopAsync();
Expand Down
Loading