i’ve some problems expanding a class of my project…
in General my project works fine (it compiles without error) but now i want to include into my Logging class a mqtt functionality (sending logs via mqtt) so i try to include my wifi and mqtt libary (both of these classes include the logging class so both classes depend on the Logging class) - i’ve looked for hours on goolge and many different forums but it seems to be another problem…
Now i think i can’t handle this problem without any help… so i hope that someone here can help me…
There are a lot of circular dependencies in that project, leading to an around 8600 lines long library dependency graph. The project is very strongly coupled. For example, logger.h includes mqtthandler.h which includes moduleState.h which includes logger.h, … Everything depends on everything. I’m seeing the usage of forward declarations to break the include chain but then that file is included anyways.
Your project builds if I break up the circular dependency in logger.h to 3 other submodules by removing the lines
since you’ve forward-declared these classes (and don’t use any specific functions in them or constructors), this works out nicely.
This also shortens the dependency graph to ~2200 lines.
Try and keep module coupling to an absolute minimium. If the logger needs to log via MQTT or WiFi or to a file, the MQTT or whatever logic should be stand-alone and not need the logger – that leads to circularily otherwise. Strict seperation should be applied here.
Also your platformio.ini isn’t quite right – it has the lib_deps declarations in old libraryname-only style. For me e.g. it picked up Arduino Json 5.x with which it didn’t build and I explicitly needed version 6.x. Also WiFiClient is an invalid dependency since it’s part of the ESP8266WiFi library which is right written as a dependency right above it. It should look like
Thanks for your help…
In this Case it works fine for me but i want to use the functionality of these Modules in my Logger Class…
If i use your Solution it compiles fine but i can’t use the mqtt function because the compiler don’t know what “mqtt” is…
I added the part in the SysloggerClass file (line 205 - 213 - what should I need to do to get this working?).
Link to the File: ESPBase/lib/logging/src/logger.cpp at dev_linearWeb · j54j6/ESPBase · GitHub
Is that what i want to do possible that I can use the SysLogger Class inside the MQTT Class but also use the MQTT Class inside the SysLogger Class (and later maybe the same thing with other classes…)
Oh and can you explain me a “best practice” for the following statement in your last answer^^ :
Try and keep module coupling to an absolute minimium. If the logger needs to log via MQTT or WiFi or to a file, the MQTT or whatever logic should be stand-alone and not need the logger
Because i want to log every moule to see errors or information for debuging and i thougt it is “goog-practice” if i write a own class for logging and include it in any sub Module of my project so i don’t need to write a logger for each class :^)… what is the “best practice” here?
Thank you so much for your help.
I appreciate you :).
Since we’ve removed the three includes from the .h file to get a valid non-circular declaration of all functions, the .cpp file will need to include those files now to access the real underlying functionality.