Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion erpcgen/src/PythonGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void PythonGenerator::generate()

makeIncludesTemplateData();

makeAliasesTemplateData();
//makeAliasesTemplateData();

makeConstTemplateData();

Expand Down Expand Up @@ -407,6 +407,7 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group)

data_list structs;
data_list unions;
data_list aliases;

Log::info("Group symbols:\n");

Expand Down Expand Up @@ -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())
Expand All @@ -468,13 +473,38 @@ data_map PythonGenerator::makeGroupSymbolsTemplateData(Group *group)
}
break;
}
case DataType::kAliasTypeSymbol:
{
AliasType *aliasType = dynamic_cast<AliasType *>(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;
}
}

symbolsTemplate["structs"] = structs;
symbolsTemplate["unions"] = unions;
symbolsTemplate["aliases"] = aliases;

return symbolsTemplate;
}
Expand Down
2 changes: 0 additions & 2 deletions erpcgen/src/templates/c_client_source.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 >%}
Expand Down
4 changes: 4 additions & 0 deletions erpcgen/src/templates/py_client.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
2 changes: 1 addition & 1 deletion erpcgen/src/templates/py_coders.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down
14 changes: 9 additions & 5 deletions erpcgen/src/templates/py_common.template
Original file line number Diff line number Diff line change
Expand Up @@ -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 #}
Expand Down Expand Up @@ -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) %}
5 changes: 2 additions & 3 deletions erpcgen/test/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
9 changes: 7 additions & 2 deletions erpcgen/test/test_length_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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',)
Expand Down
1 change: 0 additions & 1 deletion erpcgen/test/test_name_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion erpcgen/test/test_union_py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/test_callbacks/test_callbacks.erpc
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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);
}
Expand Down
15 changes: 15 additions & 0 deletions test/test_callbacks/test_callbacks_client_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
28 changes: 28 additions & 0 deletions test/test_callbacks/test_callbacks_server_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
////////////////////////////////////////////////////////////////////////////////
Expand Down