-
Notifications
You must be signed in to change notification settings - Fork 130
06b Areg SDK Code Generator
The Areg SDK Code Generator is a build-time utility that automates the generation of service interface code for Remote (Public) and Local (Private) services. By transforming .siml service interface definitions into production-ready C++ code, codegen.jar eliminates repetitive boilerplate, ensures interface consistency, and allows developers to focus on business logic rather than communication infrastructure.
Generates complete service interface code for object-based RPC communication, including:
- Service provider stubs and skeletons
- Service consumer proxies
- Request/response handlers
- Event notification dispatchers
- Attribute accessors
- Serialization/deserialization logic
- Standards Compliance: All generated code adheres to Areg SDK coding standards
- Type Safety: Strongly-typed interfaces prevent runtime errors
- Version Control: Interface changes automatically propagate to all generated code
- Documentation: Self-documenting code with clear method signatures
- Zero Boilerplate: Eliminates hundreds of lines of repetitive code per service
- Rapid Prototyping: Define interfaces quickly, generate code instantly
- Modular Architecture: Clean separation between interface definition and implementation
-
Easy Refactoring: Update
.simlfile, regenerate—no manual code changes needed
Enables distributed development by allowing external teams to:
- Generate service implementation code from interface definitions alone
- Implement services without access to proprietary business logic
- Maintain interface contracts across organizational boundaries
- Java 17 or newer installed and available in system PATH
- Areg SDK built (provides
codegen.jarin the output directory)
Create a .siml file defining your service interface. A service interface consists of:
- Data Structures: Custom types, enumerations, imported types
- Attributes: Shared state accessible to all consumers
- Requests: Service Consumer-initiated RPC calls expecting responses
- Responses: Service Provider-side answers to requests
- Broadcasts: Service Provider-initiated event to all connected and subscribed consumers
Example: HelloService.siml
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ServiceInterface FormatVersion="1.0.0">
<Overview ID="1" Name="HelloService" Version="1.0.0">
<Description>Simple greeting service</Description>
</Overview>
<MethodList>
<Method ID="2" MethodType="request" Name="Greeting">
<Description>Request a personalized greeting</Description>
</Method>
<Method ID="3" MethodType="response" Name="Greeting">
<Description>Greeting response</Description>
</Method>
</MethodList>
</ServiceInterface>For detailed .siml syntax, see Service Interface Documentation.
java -jar codegen.jar --doc=<path-to-siml-file> --root=<output-root> --target=<relative-path>Parameters:
-
--doc: Path to.simlservice interface definition file -
--root: Root directory for generated files (typically project source directory) -
--target: Relative path within root for generated code (e.g.,generated/services)
Example:
java -jar codegen.jar \
--doc=./services/HelloService.siml \
--root=./src \
--target=generatedGenerated files appear in: ./src/generated/
java -jar codegen.jar --helpDisplays all available command-line options and usage information.
Tip
Use the Lusan GUI tool to visually design service interfaces. Lusan provides an intuitive graphical editor for .siml files, eliminating the need to write XML manually.
Areg SDK provides CMake functions in functions.cmake to seamlessly integrate code generation into the build process:
Generates code in ${AREG_GENERATE_DIR} with automatic directory structure:
addServiceInterface(<static-lib-name> <path-to-siml-file>)Behavior:
- Creates directory structure based on
.simlfile location - Generates C++ source and header files
- Compiles files into a static library
- Makes library available for linking
Example:
addServiceInterface(HelloServiceLib ./services/HelloService.siml)
macro_declare_executable(HelloService HelloServiceLib main.cpp provider.cpp)Generates code in a custom location:
addServiceInterfaceEx(<static-lib-name> <path-to-siml-file> <custom-output-dir>)Use when you need control over the output directory structure.
Low-level function for advanced scenarios:
macro_add_service_interface(<lib-name> <siml-path> <codegen-path> <output-dir>)Allows specifying custom code generator location and output directory.
For Visual Studio projects without CMake, see the dedicated guide:
📘 Integrating Areg Framework with Microsoft Visual Studio
Manual integration steps:
- Run
codegen.jarfrom command line or custom build step - Add generated files to a static library project
- Link the library with your application projects
Step 1: Create Service Interface
Define services/HelloService.siml following the Service Interface structure.
Step 2: Configure CMake Build
In your CMakeLists.txt:
# Include Areg SDK
include(<areg-sdk-path>/areg.cmake)
# Generate service interface code and create static library
addServiceInterface(HelloServiceLib ./services/HelloService.siml)
# Create executable linking the generated library
macro_declare_executable(
HelloService # Executable name
HelloServiceLib # Generated service library
main.cpp # Application sources
ServiceProvider.cpp
)Step 3: Implement Business Logic
Use generated base classes:
#include "generated/HelloServiceStub.hpp"
class ServiceProvider : public HelloServiceStub {
public:
// Implement request handler
virtual void requestGreeting(const String& name) override {
// Business logic here
String greeting = "Hello, " + name + "!";
responseGreeting(greeting);
}
};Step 4: Build Project
cmake -B ./build
cmake --build ./buildCode generation happens automatically during the build process.
Step 1: Create Service Interface
Define services/HelloService.siml following the Service Interface structure.
Step 2: Run Code Generator
java -jar codegen.jar ^
--doc=services/HelloService.siml ^
--root=src ^
--target=generatedStep 3: Add Generated Files to Project
- Create a static library project in Visual Studio
- Add generated files from
src/generated/to the project - Compile the library
- Link it with your application project
Step 4: Implement Business Logic
Same as CMake workflow—inherit from generated stubs and implement service methods.
- Keep interfaces focused: One service per functional domain
-
Version interfaces: Use semantic versioning in
.simlfiles - Document thoroughly: Add descriptions to all methods and parameters
- Plan for evolution: Design interfaces with future extensions in mind
- Automate in build system: Use CMake functions instead of manual invocation
-
Version control
.simlfiles: Track interface definitions, not generated code -
Exclude generated code from VCS: Add
generated/to.gitignore -
Regenerate on interface changes: Always rebuild after modifying
.simlfiles
project/
├── services/
│ └── HelloService.siml # Interface definitions (version controlled)
├── src/
│ ├── generated/ # Generated code (excluded from VCS)
│ │ ├── HelloServiceStub.hpp
│ │ ├── HelloServiceStub.cpp
│ │ ├── HelloServiceClientBase.hpp
│ │ ├── HelloServiceClientBase.cpp
│ │ ├── HelloServiceProxy.hpp
│ │ └── HelloServiceProxy.cpp
│ └── implementation/ # Business logic (version controlled)
│ ├── ServiceProvider.cpp
│ └── ServiceConsumer.cpp
└── CMakeLists.txt
- Manual edits to generated code: Never modify generated files—changes will be lost on regeneration
-
Stale generated code: Always regenerate after updating
.simlfiles - Missing dependencies: Ensure Java 17+ is installed and accessible
- Path issues: Use absolute paths or CMake variables for reliable builds
The codegen.jar tool is a cornerstone of Areg SDK development, transforming service interface definitions into production-ready C++ code. By automating boilerplate generation, enforcing interface consistency, and integrating seamlessly with modern build systems, it enables developers to build robust, maintainable distributed applications efficiently.
Key Takeaways:
-
Automates service interface code generation from
.simldefinitions - Eliminates hundreds of lines of boilerplate per service
- Ensures type-safe, standards-compliant communication code
- Integrates seamlessly with CMake and Visual Studio workflows
- Accelerates development cycles and reduces errors
For advanced service interface design and visual editing, explore the Lusan GUI tool.
Help us to make docs greater: See something is wrong, unclear or need a help? Submit a change, open a discussion or ask AREG SDK community a question.
Copyright © 2026, Aregtech, www.areg.tech, email: info[at]areg.tech