@@ -22,11 +22,12 @@ Hostname1Client::Hostname1Client(sdbus::IConnection& connection)
2222 : ProxyInterfaces{connection, sdbus::ServiceName (INTERFACE_NAME),
2323 sdbus::ObjectPath (OBJECT_PATH)} {
2424 registerProxy ();
25- auto description = Describe ();
26- // Parse description as JSON and print key: value lines
27- std::string parsed = Utils::parseDescriptionJson (description);
28- spdlog::info (" Hostname1 description:\n {}\n Parsed description:\n {}" ,
29- description, parsed);
25+
26+ if (const std::string description = Describe (); !description.empty ()) {
27+ if (const auto s = glz::read_json<Hostname1>(description)) {
28+ printHostname1 (s.value ());
29+ }
30+ }
3031}
3132
3233Hostname1Client::~Hostname1Client () {
@@ -73,8 +74,8 @@ void Hostname1Client::updateHostname1(
7374 hostname1_.OperatingSystemCPEName = value.get <std::string>();
7475 } else if (key == " OperatingSystemSupportEnd" ) {
7576 hostname1_.OperatingSystemSupportEnd = value.get <uint64_t >();
76- } else if (key == " HomeURL " ) {
77- hostname1_.HomeURL = value.get <std::string>();
77+ } else if (key == " OperatingSystemHomeURL " ) {
78+ hostname1_.OperatingSystemHomeURL = value.get <std::string>();
7879 } else if (key == " HardwareVendor" ) {
7980 hostname1_.HardwareVendor = value.get <std::string>();
8081 } else if (key == " HardwareModel" ) {
@@ -86,9 +87,9 @@ void Hostname1Client::updateHostname1(
8687 } else if (key == " FirmwareDate" ) {
8788 hostname1_.FirmwareDate = value.get <uint64_t >();
8889 } else if (key == " MachineID" ) {
89- hostname1_. MachineID = value.get <std::vector<uint8_t >>();
90+ MachineID_ = value.get <std::vector<uint8_t >>();
9091 } else if (key == " BootID" ) {
91- hostname1_. BootID = value.get <std::vector<uint8_t >>();
92+ BootID_ = value.get <std::vector<uint8_t >>();
9293 }
9394 }
9495}
@@ -98,29 +99,32 @@ void Hostname1Client::printHostname1() const {
9899 if (!hostname1_.Hostname .empty ()) {
99100 os << " \t Hostname: " << hostname1_.Hostname << std::endl;
100101 }
101- if (! hostname1_.StaticHostname .empty ()) {
102+ if (hostname1_.StaticHostname .empty ()) {
102103 os << " \t StaticHostname: " << hostname1_.StaticHostname << std::endl;
103104 }
104- if (!hostname1_.PrettyHostname .empty ()) {
105- os << " \t PrettyHostname: " << hostname1_.PrettyHostname << std::endl;
105+ if (hostname1_.PrettyHostname .has_value ()) {
106+ os << " \t PrettyHostname: " << hostname1_.PrettyHostname .value ()
107+ << std::endl;
106108 }
107- if (!hostname1_.DefaultHostname .empty ()) {
108- os << " \t DefaultHostname: " << hostname1_.DefaultHostname << std::endl;
109+ if (hostname1_.DefaultHostname .has_value ()) {
110+ os << " \t DefaultHostname: " << hostname1_.DefaultHostname .value ()
111+ << std::endl;
109112 }
110- if (!hostname1_.HostnameSource .empty ()) {
111- os << " \t HostnameSource: " << hostname1_.HostnameSource << std::endl;
113+ if (hostname1_.HostnameSource .has_value ()) {
114+ os << " \t HostnameSource: " << hostname1_.HostnameSource .value ()
115+ << std::endl;
112116 }
113- if (! hostname1_.IconName .empty ()) {
114- os << " \t IconName: " << hostname1_.IconName << std::endl;
117+ if (hostname1_.IconName .has_value ()) {
118+ os << " \t IconName: " << hostname1_.IconName . value () << std::endl;
115119 }
116- if (! hostname1_.Chassis .empty ()) {
117- os << " \t Chassis: " << hostname1_.Chassis << std::endl;
120+ if (hostname1_.Chassis .has_value ()) {
121+ os << " \t Chassis: " << hostname1_.Chassis . value () << std::endl;
118122 }
119- if (! hostname1_.Deployment .empty ()) {
120- os << " \t Deployment: " << hostname1_.Deployment << std::endl;
123+ if (hostname1_.Deployment .has_value ()) {
124+ os << " \t Deployment: " << hostname1_.Deployment . value () << std::endl;
121125 }
122- if (! hostname1_.Location .empty ()) {
123- os << " \t Location: " << hostname1_.Location << std::endl;
126+ if (hostname1_.Location .has_value ()) {
127+ os << " \t Location: " << hostname1_.Location . value () << std::endl;
124128 }
125129 if (!hostname1_.KernelName .empty ()) {
126130 os << " \t KernelName: " << hostname1_.KernelName << std::endl;
@@ -143,39 +147,127 @@ void Hostname1Client::printHostname1() const {
143147 os << " \t OperatingSystemSupportEnd: "
144148 << hostname1_.OperatingSystemSupportEnd .value () << std::endl;
145149 }
146- if (!hostname1_.HomeURL .empty ()) {
147- os << " \t HomeURL: " << hostname1_.HomeURL << std::endl;
150+ if (hostname1_.OperatingSystemHomeURL .has_value ()) {
151+ os << " \t OperatingSystemHomeUrl: "
152+ << hostname1_.OperatingSystemHomeURL .value () << std::endl;
148153 }
149- if (!hostname1_.HardwareVendor .empty ()) {
150- os << " \t HardwareVendor: " << hostname1_.HardwareVendor << std::endl;
154+ if (hostname1_.HardwareVendor .has_value ()) {
155+ os << " \t HardwareVendor: " << hostname1_.HardwareVendor .value ()
156+ << std::endl;
151157 }
152- if (! hostname1_.HardwareModel .empty ()) {
153- os << " \t HardwareModel: " << hostname1_.HardwareModel << std::endl;
158+ if (hostname1_.HardwareModel .has_value ()) {
159+ os << " \t HardwareModel: " << hostname1_.HardwareModel . value () << std::endl;
154160 }
155- if (!hostname1_.FirmwareVersion .empty ()) {
156- os << " \t FirmwareVersion: " << hostname1_.FirmwareVersion << std::endl;
161+ if (hostname1_.FirmwareVersion .has_value ()) {
162+ os << " \t FirmwareVersion: " << hostname1_.FirmwareVersion .value ()
163+ << std::endl;
157164 }
158- if (!hostname1_.FirmwareVendor .empty ()) {
159- os << " \t FirmwareVendor: " << hostname1_.FirmwareVendor << std::endl;
165+ if (hostname1_.FirmwareVendor .has_value ()) {
166+ os << " \t FirmwareVendor: " << hostname1_.FirmwareVendor .value ()
167+ << std::endl;
160168 }
161169 if (hostname1_.FirmwareDate .has_value ()) {
162170 os << " \t FirmwareDate: " << hostname1_.FirmwareDate .value () << std::endl;
163171 }
164- if (hostname1_. MachineID .has_value ()) {
172+ if (MachineID_ .has_value ()) {
165173 os << " \t MachineID: " ;
166- for (const auto & b : hostname1_. MachineID .value ()) {
174+ for (const auto & b : MachineID_ .value ()) {
167175 os << std::hex << std::setw (2 ) << std::setfill (' 0' ) << static_cast <int >(b)
168176 << " " ;
169177 }
170178 os << std::endl;
171179 }
172- if (hostname1_. BootID .has_value ()) {
180+ if (BootID_ .has_value ()) {
173181 os << " \t BootID: " ;
174- for (const auto & b : hostname1_. BootID .value ()) {
182+ for (const auto & b : BootID_ .value ()) {
175183 os << std::hex << std::setw (2 ) << std::setfill (' 0' ) << static_cast <int >(b)
176184 << " " ;
177185 }
178186 os << std::endl;
179187 }
180188 spdlog::info (" \n {}" , os.str ());
189+ }
190+
191+ void Hostname1Client::printHostname1 (const Hostname1& val) {
192+ std::ostringstream os;
193+ if (!val.Hostname .empty ()) {
194+ os << " \t Hostname: " << val.Hostname << std::endl;
195+ }
196+ if (val.StaticHostname .empty ()) {
197+ os << " \t StaticHostname: " << val.StaticHostname << std::endl;
198+ }
199+ if (val.PrettyHostname .has_value ()) {
200+ os << " \t PrettyHostname: " << val.PrettyHostname .value () << std::endl;
201+ }
202+ if (val.DefaultHostname .has_value ()) {
203+ os << " \t DefaultHostname: " << val.DefaultHostname .value () << std::endl;
204+ }
205+ if (val.HostnameSource .has_value ()) {
206+ os << " \t HostnameSource: " << val.HostnameSource .value () << std::endl;
207+ }
208+ if (val.IconName .has_value ()) {
209+ os << " \t IconName: " << val.IconName .value () << std::endl;
210+ }
211+ if (val.Chassis .has_value ()) {
212+ os << " \t Chassis: " << val.Chassis .value () << std::endl;
213+ }
214+ if (val.Deployment .has_value ()) {
215+ os << " \t Deployment: " << val.Deployment .value () << std::endl;
216+ }
217+ if (val.Location .has_value ()) {
218+ os << " \t Location: " << val.Location .value () << std::endl;
219+ }
220+ if (!val.KernelName .empty ()) {
221+ os << " \t KernelName: " << val.KernelName << std::endl;
222+ }
223+ if (!val.KernelRelease .empty ()) {
224+ os << " \t KernelRelease: " << val.KernelRelease << std::endl;
225+ }
226+ if (!val.KernelVersion .empty ()) {
227+ os << " \t KernelVersion: " << val.KernelVersion << std::endl;
228+ }
229+ if (!val.OperatingSystemPrettyName .empty ()) {
230+ os << " \t OperatingSystemPrettyName: " << val.OperatingSystemPrettyName
231+ << std::endl;
232+ }
233+ if (val.OperatingSystemReleaseData .has_value ()) {
234+ os << " \t OperatingSystemReleaseData: " << std::endl;
235+ for (const auto & item : val.OperatingSystemReleaseData .value ()) {
236+ os << " \t\t " << item << std::endl;
237+ }
238+ }
239+ if (!val.OperatingSystemCPEName .empty ()) {
240+ os << " \t OperatingSystemCPEName: " << val.OperatingSystemCPEName
241+ << std::endl;
242+ }
243+ if (val.OperatingSystemSupportEnd .has_value ()) {
244+ os << " \t OperatingSystemSupportEnd: "
245+ << val.OperatingSystemSupportEnd .value () << std::endl;
246+ }
247+ if (val.OperatingSystemHomeURL .has_value ()) {
248+ os << " \t OperatingSystemHomeURL: " << val.OperatingSystemHomeURL .value ()
249+ << std::endl;
250+ }
251+ if (val.HardwareVendor .has_value ()) {
252+ os << " \t HardwareVendor: " << val.HardwareVendor .value () << std::endl;
253+ }
254+ if (val.HardwareModel .has_value ()) {
255+ os << " \t HardwareModel: " << val.HardwareModel .value () << std::endl;
256+ }
257+ if (val.FirmwareVersion .has_value ()) {
258+ os << " \t FirmwareVersion: " << val.FirmwareVersion .value () << std::endl;
259+ }
260+ if (val.FirmwareVendor .has_value ()) {
261+ os << " \t FirmwareVendor: " << val.FirmwareVendor .value () << std::endl;
262+ }
263+ if (val.FirmwareDate .has_value ()) {
264+ os << " \t FirmwareDate: " << val.FirmwareDate .value () << std::endl;
265+ }
266+ if (val.MachineID .has_value ()) {
267+ os << " \t MachineID: " << val.MachineID .value () << std::endl;
268+ }
269+ if (val.BootID .has_value ()) {
270+ os << " \t BootID: " << val.BootID .value () << std::endl;
271+ }
272+ spdlog::info (" \n {}" , os.str ());
181273}
0 commit comments