Skip to content

Commit f50951c

Browse files
committed
Namespace can be defined by user. Default erpcshim
Signed-off-by: Cervenka Dusan <cervenka@acrios.com>
1 parent 085042c commit f50951c

37 files changed

+159
-62
lines changed

erpcgen/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ SOURCES += $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
7070
# Prevent make from deleting these temp files.
7171
.SECONDARY: $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
7272
$(OBJS_ROOT)/erpcgen_lexer.cpp \
73-
$(OBJS_ROOT)/erpcgen/src/templates/c_common_header.c \
73+
$(OBJS_ROOT)/erpcgen/src/templates/c_common_standard_header.c \
74+
$(OBJS_ROOT)/erpcgen/src/templates/c_common_erpc_header.c \
7475
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_header.c \
7576
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_source.c \
7677
$(OBJS_ROOT)/erpcgen/src/templates/cpp_client_header.c \
@@ -92,7 +93,8 @@ SOURCES += $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
9293
$(OBJS_ROOT)/erpcgen/src/templates/py_coders.c \
9394
$(OBJS_ROOT)/erpcgen/src/templates/py_global_init.c
9495

95-
SOURCES += $(OBJS_ROOT)/erpcgen/src/templates/c_common_header.c \
96+
SOURCES += $(OBJS_ROOT)/erpcgen/src/templates/c_common_standard_header.c \
97+
$(OBJS_ROOT)/erpcgen/src/templates/c_common_erpc_header.c \
9698
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_header.c \
9799
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_source.c \
98100
$(OBJS_ROOT)/erpcgen/src/templates/cpp_client_header.c \

erpcgen/VisualStudio_v14/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ cpp_client_header.cpp
99
cpp_server_header.cpp
1010
cpp_server_source.cpp
1111
cpp_coders.cpp
12-
c_common_header.cpp
12+
c_common_standard_header.cpp
13+
c_common_erpc_header.cpp
1314
c_client_source.cpp
1415
c_client_header.cpp
1516
c_server_header.cpp

erpcgen/VisualStudio_v14/erpcgen.vcxproj

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@
9898
</CustomBuildStep>
9999
<PreBuildEvent>
100100
<Command>python.exe ..\bin\txt_to_c.py --output .\cpp_coders.cpp ..\src\templates\cpp_coders.template
101-
python.exe ..\bin\txt_to_c.py --output .\c_common_header.cpp ..\src\templates\c_common_header.template
101+
python.exe ..\bin\txt_to_c.py --output .\c_common_standard_header.cpp ..\src\templates\c_common_standard_header.template
102+
python.exe ..\bin\txt_to_c.py --output .\c_common_erpc_header.cpp ..\src\templates\c_common_erpc_header.template
102103
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_header.cpp ..\src\templates\cpp_interface_header.template
103104
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_source.cpp ..\src\templates\cpp_interface_source.template
104105
python.exe ..\bin\txt_to_c.py --output .\cpp_client_header.cpp ..\src\templates\cpp_client_header.template
@@ -145,7 +146,8 @@ python.exe ..\bin\txt_to_c.py --output .\py_global_init.cpp ..\src\templates\py_
145146
</Link>
146147
<PreBuildEvent>
147148
<Command>python.exe ..\bin\txt_to_c.py --output .\cpp_coders.cpp ..\src\templates\cpp_coders.template
148-
python.exe ..\bin\txt_to_c.py --output .\c_common_header.cpp ..\src\templates\c_common_header.template
149+
python.exe ..\bin\txt_to_c.py --output .\c_common_standard_header.cpp ..\src\templates\c_common_standard_header.template
150+
python.exe ..\bin\txt_to_c.py --output .\c_common_erpc_header.cpp ..\src\templates\c_common_erpc_header.template
149151
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_header.cpp ..\src\templates\cpp_interface_header.template
150152
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_source.cpp ..\src\templates\cpp_interface_source.template
151153
python.exe ..\bin\txt_to_c.py --output .\cpp_client_header.cpp ..\src\templates\cpp_client_header.template
@@ -244,7 +246,8 @@ python.exe ..\bin\txt_to_c.py --output .\py_global_init.cpp ..\src\templates\py_
244246
<ClCompile Include="..\src\UniqueIdChecker.cpp" />
245247
<ClCompile Include="..\src\Utils.cpp" />
246248
<ClCompile Include="cpp_coders.cpp" />
247-
<ClCompile Include="c_common_header.cpp" />
249+
<ClCompile Include="c_common_standard_header.cpp" />
250+
<ClCompile Include="c_common_erpc_header.cpp" />
248251
<ClCompile Include="c_crc.cpp" />
249252
<ClCompile Include="cpp_interface_header.cpp" />
250253
<ClCompile Include="cpp_interface_source.cpp" />

erpcgen/VisualStudio_v14/erpcgen.vcxproj.filters

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@
167167
<ClCompile Include="cpp_coders.cpp">
168168
<Filter>Source Files</Filter>
169169
</ClCompile>
170-
<ClCompile Include="c_common_header.cpp">
170+
<ClCompile Include="c_common_standard_header.cpp">
171+
<Filter>Source Files</Filter>
172+
</ClCompile>
173+
<ClCompile Include="c_common_erpc_header.cpp">
171174
<Filter>Source Files</Filter>
172175
</ClCompile>
173176
<ClCompile Include="cpp_interface_header.cpp">

erpcgen/src/CGenerator.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ using namespace std;
3131
static const char *const kIdentifierChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
3232

3333
// Templates strings converted from text files by txt_to_c.py.
34-
extern const char *const kCCommonHeader;
34+
extern const char *const kCCommonStandardHeader;
35+
extern const char *const kCCommonErpcHeader;
3536
extern const char *const kCppInterfaceHeader;
3637
extern const char *const kCppInterfaceSource;
3738
extern const char *const kCppClientHeader;
@@ -78,7 +79,8 @@ CGenerator::CGenerator(InterfaceDefinition *def)
7879

7980
void CGenerator::generateOutputFiles(const string &fileName)
8081
{
81-
generateCommonCHeaderFiles(fileName);
82+
generateCommonStandardCHeaderFiles(fileName);
83+
generateCommonErpcCHeaderFiles(fileName);
8284

8385
generateInterfaceCppHeaderFile(fileName);
8486
generateInterfaceCppSourceFile(fileName);
@@ -96,12 +98,20 @@ void CGenerator::generateOutputFiles(const string &fileName)
9698
generateServerCSourceFile(fileName);
9799
}
98100

99-
void CGenerator::generateCommonCHeaderFiles(string fileName)
101+
void CGenerator::generateCommonStandardCHeaderFiles(string fileName)
100102
{
101-
fileName += "_common.h";
102-
m_templateData["commonCGuardMacro"] = generateIncludeGuardName(fileName);
103-
m_templateData["commonCHeaderName"] = fileName;
104-
generateOutputFile(fileName, "c_common_header", m_templateData, kCCommonHeader);
103+
fileName += "_common_standard.h";
104+
m_templateData["commonStandardCGuardMacro"] = generateIncludeGuardName(fileName);
105+
m_templateData["commonStandardCHeaderName"] = fileName;
106+
generateOutputFile(fileName, "c_common_standard_header", m_templateData, kCCommonStandardHeader);
107+
}
108+
109+
void CGenerator::generateCommonErpcCHeaderFiles(string fileName)
110+
{
111+
fileName += "_common_erpc.h";
112+
m_templateData["commonErpcCGuardMacro"] = generateIncludeGuardName(fileName);
113+
m_templateData["commonErpcCHeaderName"] = fileName;
114+
generateOutputFile(fileName, "c_common_erpc_header", m_templateData, kCCommonErpcHeader);
105115
}
106116

107117
void CGenerator::generateInterfaceCppHeaderFile(string fileName)

erpcgen/src/CGenerator.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,18 @@ class CGenerator : public Generator
9292
void generateOutputFiles(const std::string &fileNameExtension) override;
9393

9494
/*!
95-
* @brief This function generate output common header file.
95+
* @brief This function generate header file output with common standard code.
9696
*
97-
* @param[in] fileName Name for output client source file.
97+
* @param[in] fileName Name for common standard header file output.
98+
*/
99+
void generateCommonStandardCHeaderFiles(std::string fileName);
100+
101+
/*!
102+
* @brief This function generate header file output with common eRPC code.
103+
*
104+
* @param[in] fileName Name for common eRPC header file output.
98105
*/
99-
void generateCommonCHeaderFiles(std::string fileName);
106+
void generateCommonErpcCHeaderFiles(std::string fileName);
100107

101108
/*!
102109
* @brief This function generate output interface header file.

erpcgen/src/Generator.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ Generator::Generator(InterfaceDefinition *def, generator_type_t generatorType)
9191
{
9292
scopeName = getAnnStringValue(program, SCOPE_NAME_ANNOTATION);
9393
}
94+
95+
if (findAnnotation(m_def->getProgramSymbol(), NAMESPACE_ANNOTATION) != nullptr)
96+
{
97+
m_templateData["namespace"] = getAnnStringValue(m_def->getProgramSymbol(), NAMESPACE_ANNOTATION);
98+
}
99+
else
100+
{
101+
m_templateData["namespace"] = "erpcshim";
102+
}
94103
}
95104

96105
m_templateData["scopeName"] = scopeName;

erpcgen/src/annotations.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
//! Specify the symbol name.
4141
#define NAME_ANNOTATION "name"
4242

43+
//! Specify the namespace of program code.
44+
#define NAMESPACE_ANNOTATION "namespace"
45+
4346
//! Turn off error checking code for allocations in generated output
4447
#define NO_ALLOC_ERRORS_ANNOTATION "no_alloc_errors"
4548

erpcgen/src/templates/c_client_header.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
#if !defined({$clientCGuardMacro})
88
#define {$clientCGuardMacro}
99

10-
#include "{$commonCHeaderName}"
10+
#include "{$commonStandardCHeaderName}"
11+
#include "{$commonErpcCHeaderName}"
1112
#include "erpc_client_manager.h"
1213
{% for iface in group.interfaces %}
1314
{% for fn in iface.functions %}

erpcgen/src/templates/c_client_source.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using namespace erpc;
1818
using namespace std;
19+
{$usingNamespace() >}
1920
{% for iface in group.interfaces %}
2021
{% if count(iface.callbacksAll) > 0 %}
2122

0 commit comments

Comments
 (0)