Skip to content

Commit

Permalink
Merge pull request #61 from rdkcentral/development/jsongen-extract-fr…
Browse files Browse the repository at this point in the history
…om-array

[JsonGen] Add @extract keyword
  • Loading branch information
pwielders authored Dec 6, 2023
2 parents c85d952 + cc0729c commit 46663e0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions JsonGenerator/source/documentation_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ def _TableObj(name, obj, parentName="", parent=None, prefix="", parentOptional=F
else:
row += italics("Value must be in range [%s..%s]." % (d["range"][0], d["range"][1]))

if obj.get("extract"):
if row:
row += "<br>"
row += italics("If only one element is present the array will be omitted.")

MdRow([prefix, "opaque object" if obj.get("opaque") else "string (base64)" if obj.get("encode") else obj["type"], row])

if obj["type"] == "object":
Expand Down
3 changes: 3 additions & 0 deletions JsonGenerator/source/header_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ def ConvertType(var):

result = ["array", { "items": ConvertParameter(currentMethod.retval), "iterator": StripInterfaceNamespace(cppType.type) } ]

if "extract" in var.meta.decorators:
result[1]["extract"] = True

if var_type.IsPointerToPointer():
result[1]["ptr"] = True

Expand Down
2 changes: 2 additions & 0 deletions JsonGenerator/source/rpc_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ def _Invoke(params, response, use_prefix = True, const_cast = False, parent = ""
emit.Indent()
emit.Line("%s %s{};" % (arg.items.cpp_native_type, item_name))
emit.Line("while (%s->Next(%s) == true) { %s.Add() = %s; }" % (arg.TempName(), item_name, cpp_name, item_name))
if arg.schema.get("extract"):
emit.Line("%s.SetExtractOnSingle(true);" % (cpp_name))
emit.Line("%s->Release();" % arg.TempName())
emit.Unindent()
emit.Line("}")
Expand Down
4 changes: 4 additions & 0 deletions ProxyStubGenerator/CppParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ def __init__(self, parent_block, parent, string, valid_specifiers, tags_allowed=
skip = 1
elif token[1:] == "OPAQUE":
self.meta.decorators.append("opaque")
elif token[1:] == "EXTRACT":
self.meta.decorators.append("extract")
elif token[1:] == "PROPERTY":
self.meta.is_property = True
elif token[1:] == "BRIEF":
Expand Down Expand Up @@ -1661,6 +1663,8 @@ def _find(word, string):
tagtokens.append("@BITMASK")
if _find("@opaque", token):
tagtokens.append("@OPAQUE")
if _find("@extract", token):
tagtokens.append("@EXTRACT")
if _find("@sourcelocation", token):
tagtokens.append(__ParseParameterValue(token, "@sourcelocation"))
if _find("@alt", token):
Expand Down
1 change: 1 addition & 0 deletions ProxyStubGenerator/StubGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2085,6 +2085,7 @@ def GenerateIdentification(name):
print(" @bitmask - indicates that enumerator lists should be packed into into a bit mask")
print(" @index - indicates that a parameter in a JSON-RPC property or notification is an index")
print(" @opaque - indicates that a string parameter is an opaque JSON object")
print(" @extract - indicates that that if only one element is present in the array it shall be taken out of it")
print(" @prefix {name} - prefixes all JSON-RPC methods, properties and notifications names in an interface with a string")
print(" @text {name} - sets a different name for a parameter, enumerator, struct or JSON-RPC method, property or notification")
print(" @alt {name} - provides an alternative name a JSON-RPC method or property can by called by")
Expand Down

0 comments on commit 46663e0

Please sign in to comment.