Skip to content

Commit 9c66dd8

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

37 files changed

+161
-63
lines changed

erpcgen/Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ SOURCES += $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
7171
# Prevent make from deleting these temp files.
7272
.SECONDARY: $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
7373
$(OBJS_ROOT)/erpcgen_lexer.cpp \
74-
$(OBJS_ROOT)/erpcgen/src/templates/c_common_header.c \
74+
$(OBJS_ROOT)/erpcgen/src/templates/c_common_standard_header.c \
75+
$(OBJS_ROOT)/erpcgen/src/templates/c_common_erpc_header.c \
7576
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_header.c \
7677
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_source.c \
7778
$(OBJS_ROOT)/erpcgen/src/templates/cpp_client_header.c \
@@ -94,7 +95,8 @@ SOURCES += $(OBJS_ROOT)/erpcgen_parser.tab.cpp \
9495
$(OBJS_ROOT)/erpcgen/src/templates/py_global_init.c
9596

9697
ifeq "$(is_mingw)" "1"
97-
SOURCES += $(ERPC_ROOT)/erpcgen/VisualStudio_v14/c_common_header.cpp \
98+
SOURCES += $(ERPC_ROOT)/erpcgen/VisualStudio_v14/c_common_standard_header.cpp \
99+
$(ERPC_ROOT)/erpcgen/VisualStudio_v14/c_common_erpc_header.cpp \
98100
$(ERPC_ROOT)/erpcgen/VisualStudio_v14/cpp_interface_header.cpp \
99101
$(ERPC_ROOT)/erpcgen/VisualStudio_v14/cpp_interface_source.cpp \
100102
$(ERPC_ROOT)/erpcgen/VisualStudio_v14/cpp_client_header.cpp \
@@ -109,7 +111,8 @@ SOURCES += $(ERPC_ROOT)/erpcgen/VisualStudio_v14/c_common_header.cpp \
109111
$(ERPC_ROOT)/erpcgen/VisualStudio_v14/c_server_source.cpp \
110112
$(OBJS_ROOT)/erpcgen/src/templates/c_crc.cpp
111113
else
112-
SOURCES += $(OBJS_ROOT)/erpcgen/src/templates/c_common_header.c \
114+
SOURCES += $(OBJS_ROOT)/erpcgen/src/templates/c_common_standard_header.c \
115+
$(OBJS_ROOT)/erpcgen/src/templates/c_common_erpc_header.c \
113116
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_header.c \
114117
$(OBJS_ROOT)/erpcgen/src/templates/cpp_interface_source.c \
115118
$(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
@@ -97,7 +97,8 @@
9797
</CustomBuildStep>
9898
<PreBuildEvent>
9999
<Command>python.exe ..\bin\txt_to_c.py --output .\cpp_coders.cpp ..\src\templates\cpp_coders.template
100-
python.exe ..\bin\txt_to_c.py --output .\c_common_header.cpp ..\src\templates\c_common_header.template
100+
python.exe ..\bin\txt_to_c.py --output .\c_common_standard_header.cpp ..\src\templates\c_common_standard_header.template
101+
python.exe ..\bin\txt_to_c.py --output .\c_common_erpc_header.cpp ..\src\templates\c_common_erpc_header.template
101102
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_header.cpp ..\src\templates\cpp_interface_header.template
102103
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_source.cpp ..\src\templates\cpp_interface_source.template
103104
python.exe ..\bin\txt_to_c.py --output .\cpp_client_header.cpp ..\src\templates\cpp_client_header.template
@@ -143,7 +144,8 @@ python.exe ..\bin\txt_to_c.py --output .\py_global_init.cpp ..\src\templates\py_
143144
</Link>
144145
<PreBuildEvent>
145146
<Command>python.exe ..\bin\txt_to_c.py --output .\cpp_coders.cpp ..\src\templates\cpp_coders.template
146-
python.exe ..\bin\txt_to_c.py --output .\c_common_header.cpp ..\src\templates\c_common_header.template
147+
python.exe ..\bin\txt_to_c.py --output .\c_common_standard_header.cpp ..\src\templates\c_common_standard_header.template
148+
python.exe ..\bin\txt_to_c.py --output .\c_common_erpc_header.cpp ..\src\templates\c_common_erpc_header.template
147149
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_header.cpp ..\src\templates\cpp_interface_header.template
148150
python.exe ..\bin\txt_to_c.py --output .\cpp_interface_source.cpp ..\src\templates\cpp_interface_source.template
149151
python.exe ..\bin\txt_to_c.py --output .\cpp_client_header.cpp ..\src\templates\cpp_client_header.template
@@ -240,7 +242,8 @@ python.exe ..\bin\txt_to_c.py --output .\py_global_init.cpp ..\src\templates\py_
240242
<ClCompile Include="..\src\types\Type.cpp" />
241243
<ClCompile Include="..\src\UniqueIdChecker.cpp" />
242244
<ClCompile Include="cpp_coders.cpp" />
243-
<ClCompile Include="c_common_header.cpp" />
245+
<ClCompile Include="c_common_standard_header.cpp" />
246+
<ClCompile Include="c_common_erpc_header.cpp" />
244247
<ClCompile Include="c_crc.cpp" />
245248
<ClCompile Include="cpp_interface_header.cpp" />
246249
<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
@@ -164,7 +164,10 @@
164164
<ClCompile Include="cpp_coders.cpp">
165165
<Filter>Source Files</Filter>
166166
</ClCompile>
167-
<ClCompile Include="c_common_header.cpp">
167+
<ClCompile Include="c_common_standard_header.cpp">
168+
<Filter>Source Files</Filter>
169+
</ClCompile>
170+
<ClCompile Include="c_common_erpc_header.cpp">
168171
<Filter>Source Files</Filter>
169172
</ClCompile>
170173
<ClCompile Include="cpp_interface_header.cpp">

erpcgen/src/CGenerator.cpp

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

3232
// Templates strings converted from text files by txt_to_c.py.
33-
extern const char *const kCCommonHeader;
33+
extern const char *const kCCommonStandardHeader;
34+
extern const char *const kCCommonErpcHeader;
3435
extern const char *const kCppInterfaceHeader;
3536
extern const char *const kCppInterfaceSource;
3637
extern const char *const kCppClientHeader;
@@ -77,7 +78,8 @@ CGenerator::CGenerator(InterfaceDefinition *def)
7778

7879
void CGenerator::generateOutputFiles(const string &fileName)
7980
{
80-
generateCommonCHeaderFiles(fileName);
81+
generateCommonStandardCHeaderFiles(fileName);
82+
generateCommonErpcCHeaderFiles(fileName);
8183

8284
generateInterfaceCppHeaderFile(fileName);
8385
generateInterfaceCppSourceFile(fileName);
@@ -95,12 +97,20 @@ void CGenerator::generateOutputFiles(const string &fileName)
9597
generateServerCSourceFile(fileName);
9698
}
9799

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

106116
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
@@ -76,6 +76,15 @@ Generator::Generator(InterfaceDefinition *def, generator_type_t generatorType)
7676
}
7777

7878
m_outputDirectory /= getAnnStringValue(m_def->getProgramSymbol(), OUTPUT_DIR_ANNOTATION);
79+
80+
if (findAnnotation(m_def->getProgramSymbol(), NAMESPACE_ANNOTATION) != nullptr)
81+
{
82+
m_templateData["namespace"] = getAnnStringValue(m_def->getProgramSymbol(), NAMESPACE_ANNOTATION);
83+
}
84+
else
85+
{
86+
m_templateData["namespace"] = "erpcshim";
87+
}
7988
}
8089

8190
// get group annotation with vector of theirs interfaces

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)