@@ -21,16 +21,17 @@ namespace qs::io::ipc::comm {
2121
2222struct NoCurrentGeneration : std::monostate {};
2323struct TargetNotFound : std::monostate {};
24- struct FunctionNotFound : std::monostate {};
24+ struct EntryNotFound : std::monostate {};
2525
2626using QueryResponse = std::variant<
2727 std::monostate,
2828 NoCurrentGeneration,
2929 TargetNotFound,
30- FunctionNotFound ,
30+ EntryNotFound ,
3131 QVector<WireTargetDefinition>,
3232 WireTargetDefinition,
33- WireFunctionDefinition>;
33+ WireFunctionDefinition,
34+ WirePropertyDefinition>;
3435
3536void QueryMetadataCommand::exec (qs::ipc::IpcServerConnection* conn) const {
3637 auto resp = conn->responseStream <QueryResponse>();
@@ -44,16 +45,24 @@ void QueryMetadataCommand::exec(qs::ipc::IpcServerConnection* conn) const {
4445 auto * handler = registry->findHandler (this ->target );
4546
4647 if (handler) {
47- if (this ->function .isEmpty ()) {
48+ if (this ->name .isEmpty ()) {
4849 resp << handler->wireDef ();
4950 } else {
50- auto * func = handler->findFunction (this ->function );
51+ auto * func = handler->findFunction (this ->name );
5152
5253 if (func) {
5354 resp << func->wireDef ();
54- } else {
55- resp << FunctionNotFound ();
55+ return ;
5656 }
57+
58+ auto * prop = handler->findProperty (this ->name );
59+
60+ if (prop) {
61+ resp << prop->wireDef ();
62+ return ;
63+ }
64+
65+ resp << EntryNotFound ();
5766 }
5867 } else {
5968 resp << TargetNotFound ();
@@ -64,8 +73,8 @@ void QueryMetadataCommand::exec(qs::ipc::IpcServerConnection* conn) const {
6473 }
6574}
6675
67- int queryMetadata (IpcClient* client, const QString& target, const QString& function ) {
68- client->sendMessage (IpcCommand (QueryMetadataCommand {.target = target, .function = function }));
76+ int queryMetadata (IpcClient* client, const QString& target, const QString& name ) {
77+ client->sendMessage (IpcCommand (QueryMetadataCommand {.target = target, .name = name }));
6978
7079 QueryResponse slot;
7180 if (!client->waitForResponse (slot)) return -1 ;
@@ -82,9 +91,11 @@ int queryMetadata(IpcClient* client, const QString& target, const QString& funct
8291 qCInfo (logBare).noquote () << std::get<WireTargetDefinition>(slot).toString ();
8392 } else if (std::holds_alternative<WireFunctionDefinition>(slot)) {
8493 qCInfo (logBare).noquote () << std::get<WireFunctionDefinition>(slot).toString ();
94+ } else if (std::holds_alternative<WirePropertyDefinition>(slot)) {
95+ qCInfo (logBare).noquote () << std::get<WirePropertyDefinition>(slot).toString ();
8596 } else if (std::holds_alternative<TargetNotFound>(slot)) {
8697 qCCritical (logBare) << " Target not found." ;
87- } else if (std::holds_alternative<FunctionNotFound >(slot)) {
98+ } else if (std::holds_alternative<EntryNotFound >(slot)) {
8899 qCCritical (logBare) << " Function not found." ;
89100 } else if (std::holds_alternative<NoCurrentGeneration>(slot)) {
90101 qCCritical (logBare) << " Not ready to accept queries yet." ;
@@ -119,7 +130,7 @@ using StringCallResponse = std::variant<
119130 std::monostate,
120131 NoCurrentGeneration,
121132 TargetNotFound,
122- FunctionNotFound ,
133+ EntryNotFound ,
123134 ArgParseFailed,
124135 Completed>;
125136
@@ -137,7 +148,7 @@ void StringCallCommand::exec(qs::ipc::IpcServerConnection* conn) const {
137148
138149 auto * func = handler->findFunction (this ->function );
139150 if (!func) {
140- resp << FunctionNotFound ();
151+ resp << EntryNotFound ();
141152 return ;
142153 }
143154
@@ -223,7 +234,7 @@ int callFunction(
223234 qCCritical (logBare).noquote () << " Function definition:" << error.definition .toString ();
224235 } else if (std::holds_alternative<TargetNotFound>(slot)) {
225236 qCCritical (logBare) << " Target not found." ;
226- } else if (std::holds_alternative<FunctionNotFound >(slot)) {
237+ } else if (std::holds_alternative<EntryNotFound >(slot)) {
227238 qCCritical (logBare) << " Function not found." ;
228239 } else if (std::holds_alternative<NoCurrentGeneration>(slot)) {
229240 qCCritical (logBare) << " Not ready to accept queries yet." ;
@@ -233,4 +244,74 @@ int callFunction(
233244
234245 return -1 ;
235246}
247+
248+ struct PropertyValue {
249+ QString value;
250+ };
251+
252+ DEFINE_SIMPLE_DATASTREAM_OPS (PropertyValue, data.value);
253+
254+ using StringPropReadResponse =
255+ std::variant<std::monostate, NoCurrentGeneration, TargetNotFound, EntryNotFound, PropertyValue>;
256+
257+ void StringPropReadCommand::exec (qs::ipc::IpcServerConnection* conn) const {
258+ auto resp = conn->responseStream <StringPropReadResponse>();
259+
260+ if (auto * generation = EngineGeneration::currentGeneration ()) {
261+ auto * registry = IpcHandlerRegistry::forGeneration (generation);
262+
263+ auto * handler = registry->findHandler (this ->target );
264+ if (!handler) {
265+ resp << TargetNotFound ();
266+ return ;
267+ }
268+
269+ auto * prop = handler->findProperty (this ->property );
270+ if (!prop) {
271+ resp << EntryNotFound ();
272+ return ;
273+ }
274+
275+ auto slot = IpcTypeSlot (prop->type );
276+ prop->read (handler, slot);
277+
278+ resp << PropertyValue {
279+ .value = slot.type ()->toString (slot.get ()),
280+ };
281+ } else {
282+ conn->respond (StringCallResponse (NoCurrentGeneration ()));
283+ }
284+ }
285+
286+ int getProperty (IpcClient* client, const QString& target, const QString& property) {
287+ if (target.isEmpty ()) {
288+ qCCritical (logBare) << " Target required to send message." ;
289+ return -1 ;
290+ } else if (property.isEmpty ()) {
291+ qCCritical (logBare) << " Property required to send message." ;
292+ return -1 ;
293+ }
294+
295+ client->sendMessage (IpcCommand (StringPropReadCommand {.target = target, .property = property}));
296+
297+ StringPropReadResponse slot;
298+ if (!client->waitForResponse (slot)) return -1 ;
299+
300+ if (std::holds_alternative<PropertyValue>(slot)) {
301+ auto & result = std::get<PropertyValue>(slot);
302+ QTextStream (stdout) << result.value << Qt::endl;
303+ return 0 ;
304+ } else if (std::holds_alternative<TargetNotFound>(slot)) {
305+ qCCritical (logBare) << " Target not found." ;
306+ } else if (std::holds_alternative<EntryNotFound>(slot)) {
307+ qCCritical (logBare) << " Property not found." ;
308+ } else if (std::holds_alternative<NoCurrentGeneration>(slot)) {
309+ qCCritical (logBare) << " Not ready to accept queries yet." ;
310+ } else {
311+ qCCritical (logIpc) << " Received invalid IPC response from" << client;
312+ }
313+
314+ return -1 ;
315+ }
316+
236317} // namespace qs::io::ipc::comm
0 commit comments