Skip to content

Commit

Permalink
Merge branch 'master' into development/json-gen-restrict
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaszm authored Nov 22, 2023
2 parents 5ae36b4 + a84007f commit 3a36945
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 137 deletions.
23 changes: 13 additions & 10 deletions JsonGenerator/source/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
DOC_ISSUES = True
DEFAULT_DEFINITIONS_FILE = "../../ProxyStubGenerator/default.h"
FRAMEWORK_NAMESPACE = "WPEFramework"
INTERFACE_NAMESPACE = "::" + FRAMEWORK_NAMESPACE + "::Exchange"
INTERFACE_NAMESPACES = ["::WPEFramework::Exchange"]
INTERFACES_SECTION = True
INTERFACE_SOURCE_LOCATION = None
INTERFACE_SOURCE_REVISION = None
Expand Down Expand Up @@ -66,7 +66,7 @@ class RpcFormat(Enum):

def Parse(cmdline):
global DEFAULT_DEFINITIONS_FILE
global INTERFACE_NAMESPACE
global INTERFACE_NAMESPACES
global JSON_INTERFACE_PATH
global NO_INCLUDES
global NO_VERSIONING
Expand Down Expand Up @@ -169,12 +169,11 @@ def Parse(cmdline):
default=DEFAULT_DEFINITIONS_FILE,
help="include a C++ header file with common types (default: include '%s')" % DEFAULT_DEFINITIONS_FILE)
cpp_group.add_argument("--namespace",
dest="if_namespace",
dest="if_namespaces",
metavar="NS",
type=str,
action="store",
default=INTERFACE_NAMESPACE,
help="set namespace to look for interfaces in (default: %s)" % INTERFACE_NAMESPACE)
action="append",
default=[],
help="set namespace to look for interfaces in (default: %s)" % [INTERFACE_NAMESPACES])
cpp_group.add_argument("--format",
dest="format",
type=str,
Expand Down Expand Up @@ -286,13 +285,17 @@ def Parse(cmdline):
DUMP_JSON = args.dump_json
FORCE = args.force
DEFAULT_DEFINITIONS_FILE = args.extra_include
INTERFACE_NAMESPACE = args.if_namespace
if not INTERFACE_NAMESPACE.startswith("::"):
INTERFACE_NAMESPACE = "::" + INTERFACE_NAMESPACE
INTERFACES_SECTION = not args.no_interfaces_section
INTERFACE_SOURCE_LOCATION = args.source_location
INTERFACE_SOURCE_REVISION = args.source_revision

if args.if_namespaces:
INTERFACE_NAMESPACES = args.if_namespaces

for i, ns in enumerate(INTERFACE_NAMESPACES):
if not ns.startswith("::"):
INTERFACE_NAMESPACES[i] = "::" + ns

if RpcFormat.EXTENDED.value in args.format:
RPC_FORMAT = RpcFormat.EXTENDED
elif RpcFormat.COLLAPSED.value in args.format:
Expand Down
33 changes: 22 additions & 11 deletions JsonGenerator/source/header_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,15 @@ def __init__(self, obj, msg):
super(CppParseError, self).__init__(msg)


def LoadInterfaceInternal(file, log, all = False, includePaths = []):
def LoadInterfaceInternal(file, tree, ns, log, all = False, includePaths = []):

def StripFrameworkNamespace(identifier):
return str(identifier).replace("::" + config.FRAMEWORK_NAMESPACE + "::", "")

def StripInterfaceNamespace(identifier):
return str(identifier).replace(config.INTERFACE_NAMESPACE + "::", "")
return str(identifier).replace(ns + "::", "")

tree = CppParser.ParseFiles([os.path.join(os.path.dirname(os.path.realpath(__file__)),
posixpath.normpath(config.DEFAULT_DEFINITIONS_FILE)), file], includePaths, log)

interfaces = [i for i in CppInterface.FindInterfaceClasses(tree, config.INTERFACE_NAMESPACE, file) if (i.obj.is_json or (all and not i.obj.is_event))]
interfaces = [i for i in CppInterface.FindInterfaceClasses(tree, ns, file) if (i.obj.is_json or (all and not i.obj.is_event))]

def Build(face):
def _EvaluateRpcFormat(obj):
Expand All @@ -77,6 +74,7 @@ def _EvaluateRpcFormat(obj):
schema["$schema"] = "interface.json.schema"
schema["jsonrpc"] = "2.0"
schema["@generated"] = True
schema["namespace"] = ns

if face.obj.is_json:
schema["mode"] = "auto"
Expand All @@ -92,7 +90,7 @@ def _EvaluateRpcFormat(obj):
info = dict()
info["format"] = rpc_format.value

if not face.obj.parent.full_name.endswith(config.INTERFACE_NAMESPACE):
if not face.obj.parent.full_name.endswith(ns):
info["namespace"] = face.obj.parent.name[1:] if (face.obj.parent.name[0] == "I" and face.obj.parent.name[1].isupper()) else face.obj.parent.name

info["class"] = face.obj.name[1:] if face.obj.name[0] == "I" else face.obj.name
Expand Down Expand Up @@ -423,7 +421,7 @@ def BuildResult(vars, is_property=False):

if face.obj.json_prefix:
prefix = (face.obj.json_prefix + "::")
elif face.obj.parent.full_name != config.INTERFACE_NAMESPACE:
elif face.obj.parent.full_name != ns:
prefix = (face.obj.parent.name.lower() + "_")
else:
prefix = ""
Expand Down Expand Up @@ -766,13 +764,26 @@ def BuildResult(vars, is_property=False):
schema = Build(face)
if schema:
schemas.append(schema)
else:
log.Info("No interfaces found")

return schemas, []

def LoadInterface(file, log, all = False, includePaths = []):
try:
return LoadInterfaceInternal(file, log, all, includePaths)
schemas = []
includes = []

tree = CppParser.ParseFiles([os.path.join(os.path.dirname(os.path.realpath(__file__)),
posixpath.normpath(config.DEFAULT_DEFINITIONS_FILE)), file], includePaths, log)

for ns in config.INTERFACE_NAMESPACES:
s, i = LoadInterfaceInternal(file, tree, ns, log, all, includePaths)
schemas.extend(s)
includes.extend(i)

if not schemas:
log.Info("No interfaces found")

return schemas, includes

except CppParser.ParserError as ex:
raise CppParseError(None, str(ex))
38 changes: 22 additions & 16 deletions JsonGenerator/source/rpc_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def Emit(parameters):
emit.Line()


def _EmitRpcPrologue(root, emit, header_file, source_file, data_emitted, prototypes = []):
def _EmitRpcPrologue(root, emit, header_file, source_file, ns, data_emitted, prototypes = []):
json_source = source_file.endswith(".json")

emit.Line()
Expand Down Expand Up @@ -222,9 +222,9 @@ def _EmitRpcPrologue(root, emit, header_file, source_file, data_emitted, prototy

emit.Line()

for i, ns in enumerate(config.INTERFACE_NAMESPACE.split("::")):
if ns:
emit.Line("namespace %s {" % ns)
for i, ns_ in enumerate(ns.split("::")):
if ns_:
emit.Line("namespace %s {" % ns_)
if i >= 2:
emit.Indent()
emit.Line()
Expand All @@ -242,7 +242,7 @@ def _EmitRpcPrologue(root, emit, header_file, source_file, data_emitted, prototy
emit.Indent()
emit.Line()

def _EmitRpcEpilogue(root, emit):
def _EmitRpcEpilogue(root, emit, ns):
emit.Unindent()
emit.Line("} // namespace %s" % ("J" + root.json_name))
emit.Line()
Expand All @@ -252,11 +252,11 @@ def _EmitRpcEpilogue(root, emit):
emit.Line("} // namespace %s" % root.schema["info"]["namespace"])
emit.Line()

for i, ns in reversed(list(enumerate(config.INTERFACE_NAMESPACE.split("::")))):
if ns:
for i, ns_ in reversed(list(enumerate(ns.split("::")))):
if ns_:
if i >= 2:
emit.Unindent()
emit.Line("} // namespace %s" % ns)
emit.Line("} // namespace %s" % ns_)
emit.Line()

emit.Line()
Expand All @@ -272,11 +272,11 @@ def _EmitVersionCode(emit, version):
emit.Unindent()
emit.Line("} // namespace Version")

def _EmitRpcCode(root, emit, header_file, source_file, data_emitted):
def _EmitRpcCode(root, emit, ns, header_file, source_file, data_emitted):
json_source = source_file.endswith(".json")

for i, ns in enumerate(config.INTERFACE_NAMESPACE.split("::")):
if ns and i >= 2:
for i, ns_ in enumerate(ns.split("::")):
if ns_ and i >= 2:
emit.Indent()

if "info" in root.schema and "namespace" in root.schema["info"]:
Expand Down Expand Up @@ -881,15 +881,21 @@ def _Invoke(params, response, use_prefix = True, const_cast = False, parent = ""
return prototypes

def EmitRpcCode(root, emit, header_file, source_file, data_emitted):
prototypes = _EmitRpcCode(root, emit, header_file, source_file, data_emitted)

ns = root.schema["namespace"] if "namespace" in root.schema else "::WPEFramework::Exchange"

prototypes = _EmitRpcCode(root, emit, ns, header_file, source_file, data_emitted)

with emitter.Emitter(None, config.INDENT_SIZE) as prototypes_emitter:
_EmitRpcPrologue(root, prototypes_emitter, header_file, source_file, data_emitted, prototypes)
_EmitRpcPrologue(root, prototypes_emitter, header_file, source_file, ns, data_emitted, prototypes)
emit.Prepend(prototypes_emitter)

_EmitRpcEpilogue(root, emit)
_EmitRpcEpilogue(root, emit, ns)

def EmitRpcVersionCode(root, emit, header_file, source_file, data_emitted):
_EmitRpcPrologue(root, emit, header_file, source_file, data_emitted)

ns = root.schema["namespace"] if "namespace" in root.schema else "::WPEFramework::Exchange"

_EmitRpcPrologue(root, emit, header_file, source_file, ns, data_emitted)
_EmitVersionCode(emit, rpc_version.GetVersion(root.schema["info"] if "info" in root.schema else dict()))
_EmitRpcEpilogue(root, emit)
_EmitRpcEpilogue(root, emit, ns)
2 changes: 1 addition & 1 deletion LuaGenerator/GenerateLua.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ THUNDER_DIR="${1:-../../Thunder}"
INTERFACES_DIR="${2:-../../ThunderInterfaces}"

files="$THUNDER_DIR/Source/com/ICOM.h"
files="$files $THUNDER_DIR/Source/plugins/IController.h $THUNDER_DIR/Source/plugins/IPlugin.h $THUNDER_DIR/Source/plugins/IShell.h $THUNDER_DIR/Source/plugins/IStateControl.h $THUNDER_DIR/Source/plugins/ISubSystem.h $THUNDER_DIR/Source/plugins/IDispatcher.h"
files="$files $THUNDER_DIR/Source/plugins/IController.h $THUNDER_DIR/Source/plugins/IControllerDeprecated.h $THUNDER_DIR/Source/plugins/IPlugin.h $THUNDER_DIR/Source/plugins/IShell.h $THUNDER_DIR/Source/plugins/IStateControl.h $THUNDER_DIR/Source/plugins/ISubSystem.h $THUNDER_DIR/Source/plugins/IDispatcher.h"
files="$files $INTERFACES_DIR/interfaces/I*.h"
# add more interface files if needed..

Expand Down
Loading

0 comments on commit 3a36945

Please sign in to comment.