diff --git a/erpcgen/src/PythonGenerator.cpp b/erpcgen/src/PythonGenerator.cpp index 755195c76..26ded4169 100644 --- a/erpcgen/src/PythonGenerator.cpp +++ b/erpcgen/src/PythonGenerator.cpp @@ -136,7 +136,7 @@ void PythonGenerator::generate() makeIncludesTemplateData(); - makeAliasesTemplateData(); + //makeAliasesTemplateData(); makeConstTemplateData(); @@ -407,6 +407,7 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) data_list structs; data_list unions; + data_list aliases; Log::info("Group symbols:\n"); @@ -453,6 +454,10 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) Log::info("%s\n", unionType->getDescription().c_str()); string name = filterName(getOutputName(unionType)); + if(name.find('$') != string::npos) { + Log::debug("%s is inside struct!\n", name.c_str()); + break; + } // check if template for this structure has not already been generated if (names.find(name) == names.end()) @@ -468,6 +473,30 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) } break; } + case DataType::kAliasTypeSymbol: + { + AliasType *aliasType = dynamic_cast(symbol); + if (aliasType == nullptr) + break; + + DataType *elementDataType = aliasType->getElementType(); + DataType *trueDataType = elementDataType->getTrueDataType(); + // Only generate aliases for enums, unions and structs in Python. + if (!(trueDataType->isEnum() || trueDataType->isUnion() || trueDataType->isStruct())) + break; + + string realType = getOutputName(aliasType); + Log::debug("%s\n", realType.c_str()); + + info["name"] = filterName(realType); + info["elementType"] = getTypeInfo(elementDataType); + info["trueType"] = getTypeInfo(trueDataType); + + setTemplateComments(aliasType, info); + + aliases.push_back(info); + break; + } default: break; } @@ -475,6 +504,7 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group) symbolsTemplate["structs"] = structs; symbolsTemplate["unions"] = unions; + symbolsTemplate["aliases"] = aliases; return symbolsTemplate; } diff --git a/erpcgen/src/templates/c_client_source.template b/erpcgen/src/templates/c_client_source.template index 050cedd1b..10711d7c9 100644 --- a/erpcgen/src/templates/c_client_source.template +++ b/erpcgen/src/templates/c_client_source.template @@ -164,8 +164,6 @@ static {$callbackType.prototype} { {% if fn.isCallback %} {% if fn.returnValue.type.isNotVoid %}return {% endif %}{$fn.callbackFName}(k{$iface.name}_service_id, k{$iface.name}_{$fn.name}_id{% for param in fn.parameters %}, {$param.name}{% endfor %}); -{% if fn.returnValue.type.isNotVoid %}return; -{% endif %} {% else -- fn.isCallback >%} {$ clientShimCode(fn, "k"& iface.name & "_service_id", "k" & iface.name & "_" & fn.name & "_id") >} {% endif -- fn.isCallback >%} diff --git a/erpcgen/src/templates/py_client.template b/erpcgen/src/templates/py_client.template index a9bdfd5ee..1c9824419 100644 --- a/erpcgen/src/templates/py_client.template +++ b/erpcgen/src/templates/py_client.template @@ -61,7 +61,11 @@ class {$iface.name}Client(interface.I{$iface.name}): {% if p.type.type == 'union' %} {$p.name}._write(codec, {$p.discriminator}) {% else%} +{% if p.direction == "inout" %} + {$encodeValue(p.type, p.name & ".value", "codec", " ", 0)} +{% else %} {$encodeValue(p.type, p.name, "codec", " ", 0)} +{% endif -- p.direction %} {% endif -- isUnion %} {% endif -- isNullable %} {% endfor -- inParams %} diff --git a/erpcgen/src/templates/py_coders.template b/erpcgen/src/templates/py_coders.template index 60b5760fe..73d2d998a 100644 --- a/erpcgen/src/templates/py_coders.template +++ b/erpcgen/src/templates/py_coders.template @@ -11,7 +11,7 @@ {% else %} {% set self = "self." %} {% endif %} -codec.start_write_union({$self}discriminator) +codec.start_write_union({$self}{$info.discriminatorName}) {# unions are always within structs, so we have self available #} {% set isFirst = true %} {% set hasNonVoidCase = false %} diff --git a/erpcgen/src/templates/py_common.template b/erpcgen/src/templates/py_common.template index e4fcc8289..8583e3da2 100644 --- a/erpcgen/src/templates/py_common.template +++ b/erpcgen/src/templates/py_common.template @@ -58,9 +58,13 @@ class {$s.name}(object): {% endfor -- union cases %} {% endfor -- members %} - def __init__(self{% for m in s.members if not m.lengthForMember %}, {$m.name}=None{% endfor %}): + def __init__(self{% for m in s.members if ((not m.lengthForMember) && m.type.type != 'union') %}, {$m.name}=None{% endfor %}): {% for m in s.members if not m.lengthForMember %} +{% if (m.type.type == 'union' && m.type.isNonEncapsulatedUnion == false) %} + self.{$m.name} = self.{$m.name}_union # {$prettyTypeName(m.name, m.type)} +{% else %} self.{$m.name} = {$m.name} # {$prettyTypeName(m.name, m.type)} +{% endif -- union type %} {% endfor -- members %} {# create read-only properties for @length counts #} @@ -146,10 +150,10 @@ class {$u.name}(object): {% endfor -- group.symbolsMap.unions %} {% endif -- not empty(group.symbolsMap.unions) %} +{% if not empty(group.symbolsMap.aliases) %} -{% if aliases %} # Type aliases -{% for a in aliases %} +{% for a in group.symbolsMap.aliases %} {$a.name} = {$a.elementType.name} -{% endfor -- aliases %} -{% endif -- aliases %} +{% endfor -- group.symbolsMap.aliases %} +{% endif -- not empty(group.symbolsMap.aliases) %} \ No newline at end of file diff --git a/erpcgen/test/readme.md b/erpcgen/test/readme.md index baf8e6efb..c0730d2b9 100644 --- a/erpcgen/test/readme.md +++ b/erpcgen/test/readme.md @@ -4,9 +4,8 @@ erpcgen test system This file documents the parser and output test system for erpcgen. This test system is built on py.test using its extensive plugin hooks. To run the tests, just run -py.test in either the `erpc/erpgen/` or `erpc/erpcgen/test/` directory. -Because of py.test are trying run all tests in all subfolders, is safer to run py.test with parameter -source directory (from erpcgen directory run: "pytest test"). This prevent on windows to execute +py.test in `erpc/erpcgen/test/` directory. It's safer to run py.test with parameter source +directory (from erpcgen directory run: "pytest test"). This prevent on windows to execute boost test in boost folder. diff --git a/erpcgen/test/test_length_py.yml b/erpcgen/test/test_length_py.yml index 85db39ec0..1ac4a1b06 100644 --- a/erpcgen/test/test_length_py.yml +++ b/erpcgen/test/test_length_py.yml @@ -48,7 +48,7 @@ test/interface.py: - def bar(self, l) test/client.py: - def bar(self, l) - - start_write_list(len(l)) + - start_write_list(len(l.value)) - perform_request - start_read_list - not: codec.read_int32() @@ -78,9 +78,14 @@ idl: | lang: py test/client.py: - def bar(self, v) + - if: dir in ('in', ) + then: + - write_{type}(v) + - if: dir in ('inout', ) + then: + - write_{type}(v.value) - if: dir in ('in', 'inout') then: - - write_{type}(v) - not: write_int32(len(v)) - perform_request - if: dir in ('inout',) diff --git a/erpcgen/test/test_name_py.yml b/erpcgen/test/test_name_py.yml index ad57ec695..6fd3de6d3 100644 --- a/erpcgen/test/test_name_py.yml +++ b/erpcgen/test/test_name_py.yml @@ -41,7 +41,6 @@ test/common.py: - if self.d is None - codec.write_int32(self.d) - self.d - - type = StructName test/client.py: - def function(self, m) diff --git a/erpcgen/test/test_union_py.yml b/erpcgen/test/test_union_py.yml index a2cf6b137..9c210920f 100644 --- a/erpcgen/test/test_union_py.yml +++ b/erpcgen/test/test_union_py.yml @@ -168,7 +168,7 @@ lang: py test/common.py: - not: class unionVariable_union(object) - "class structType(object):" - - def __init__(self, discriminator=None, unionVariable=None) + - def __init__(self, discriminator=None) - self.discriminator = discriminator # fruitType - self.unionVariable = unionVariable # unionType - self.unionVariable, self.discriminator = common.unionType()._read(codec) diff --git a/test/test_callbacks/test_callbacks.erpc b/test/test_callbacks/test_callbacks.erpc index 031cdf9ce..3c3aff2ec 100644 --- a/test/test_callbacks/test_callbacks.erpc +++ b/test/test_callbacks/test_callbacks.erpc @@ -12,6 +12,7 @@ import "../common/unit_test_common.erpc" oneway callback1_t(int32 a, int32 b) oneway callback2_t(int32, int32) +callback3_t(int32 arg1, int32 arg2) -> int32 @include("test_core1.h") @group("core0") @@ -21,9 +22,17 @@ interface ClientCore0Services myFun2(callback2_t pCallback2_in, out callback2_t pCallback2_out) -> void + myFun3(callback3_t callback, in int32 arg1, in int32 arg2) -> int32 + + callback3_t my_add; + callback3_t my_sub; + callback3_t my_mul; + callback3_t my_div; + @include("callbacks1.h") callback1_t callback1a; + @include("callbacks1.h") callback1_t callback1b(param1, param2); } diff --git a/test/test_callbacks/test_callbacks_client_impl.cpp b/test/test_callbacks/test_callbacks_client_impl.cpp index 4d812e6ca..7b21043df 100644 --- a/test/test_callbacks/test_callbacks_client_impl.cpp +++ b/test/test_callbacks/test_callbacks_client_impl.cpp @@ -38,3 +38,18 @@ TEST(test_callbacks, In_Out_withoutTable) EXPECT_TRUE(callback2 == *pCallback2_out); } + +TEST(test_callbacks, Common_Callback) +{ + callback3_t callback = my_add; + EXPECT_TRUE(12 == myFun3(callback, 9, 3)); + + callback = my_sub; + EXPECT_TRUE(6 == myFun3(callback, 9, 3)); + + callback = my_mul; + EXPECT_TRUE(27 == myFun3(callback, 9, 3)); + + callback = my_div; + EXPECT_TRUE(3 == myFun3(callback, 9, 3)); +} \ No newline at end of file diff --git a/test/test_callbacks/test_callbacks_server_impl.cpp b/test/test_callbacks/test_callbacks_server_impl.cpp index 1d76d7ee7..c96c0c07c 100644 --- a/test/test_callbacks/test_callbacks_server_impl.cpp +++ b/test/test_callbacks/test_callbacks_server_impl.cpp @@ -49,6 +49,34 @@ void callback2(int32_t param1, int32_t param2) cb2 = (callback2_t *)callback2; } +int32_t myFun3(const callback3_t callback, int32_t arg1, int32_t arg2) +{ + return callback(arg1, arg2); +} + +int32_t my_add(int32_t arg1, int32_t arg2) +{ + return arg1 + arg2; +} + +int32_t my_sub(int32_t arg1, int32_t arg2) +{ + return arg1 - arg2; +} + +int32_t my_mul(int32_t arg1, int32_t arg2) +{ + return arg1 * arg2; +} + +int32_t my_div(int32_t arg1, int32_t arg2) +{ + if(arg2) { + return arg1 / arg2; + } + return 0; +} + //////////////////////////////////////////////////////////////////////////////// // Add service to server code ////////////////////////////////////////////////////////////////////////////////