-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Task Summary
Comprehensive refactoring of mainTrafficLayer.cpp to improve code quality, reduce technical debt, and enhance maintainability. This includes cleaning up printout/banner messages, removing dead/commented code, consolidating duplicate logic, improving code structure, and implementing memory safety improvements.
Why is this needed?
The current mainTrafficLayer.cpp has grown to ~950 lines with accumulated technical debt:
- Inconsistent and scattered console output during startup
- Dead code and TODO comments that should be tracked issues
- Duplicated logic patterns that increase maintenance burden
- Large monolithic
main()function that's difficult to navigate - Unsafe memory patterns (volatile vs atomic, raw file handles)
Refactoring will improve code readability, reduce bugs, and make future development more efficient.
Scope of Work
Files involved:
TrafficLayer/TrafficLayer/mainTrafficLayer.cpp
Tasks:
1. Printout/Banner Cleanup
- Remove extra
\n\nformatting inconsistencies (completed in initial cleanup) - Remove "No verbose logging" negative info print (completed)
- Consolidate scattered port prints into single summary (completed)
- Add build date/time to banner (
__DATE__,__TIME__) - Add configuration summary block after config parsing
2. Remove Dead/Commented Code
- Remove old TODO comments (lines 132-141) - convert to tracked issues
- Remove unnecessary file existence check (lines 359-366)
- Remove empty debug blocks (
int aa = 1;at lines 924-925, 1145) - Remove empty verbose block (lines 481-486)
- Remove large commented-out code blocks (lines 623-641)
3. Consolidate Duplicate Logic
- Extract subscription handling to helper function (lines 488-523 duplicate pattern)
- Create
extractPortsFromSubscription()function (lines 537-584 repeated pattern) - Consolidate identical
sendDatabranches (lines 1002-1036)
4. Improve Code Structure
- Extract functions from main():
parseCommandLineArgs()initializeLogging()setupConfiguration()setupConnections()runSimulationLoop()
- Move
Timer_tstruct closer to usage or remove ifENABLE_TIMINGalways false - Move global variables
Config_c,Sock_cinto main or pass as parameters
5. Memory/Resource Safety Improvements
- Replace
volatile boolwithstd::atomic<bool>forg_shutdown.shutdownRequested(line 17) - Use RAII for file handles - replace
fopen/fclosepairs withstd::ofstream
6. Configuration Cleanup
- Remove
ENABLE_TIMINGcode if hardcoded to false, or make configurable via config.yaml
Environment (if version-specific)
- C++ compiler/version: Visual Studio 2022
Risks or Dependencies
- Changes to main executable require thorough testing across all simulator combinations (VISSIM/SUMO, with/without CarMaker, with/without Carla)
- Should be done incrementally with testing between each major change
- No external dependencies
Additional Context (optional)
This issue was created after initial cleanup of startup printout formatting. The initial cleanup normalized console output formatting and consolidated scattered port information into a single summary line.
Related line references are based on the current state after initial cleanup and may shift as changes are made.