Skip to content

Bugfix/datalink init and cleanup consistency#1380

Merged
skarg merged 11 commits into
masterfrom
bugfix/datalink-init-and-cleanup-consistency
Jun 9, 2026
Merged

Bugfix/datalink init and cleanup consistency#1380
skarg merged 11 commits into
masterfrom
bugfix/datalink-init-and-cleanup-consistency

Conversation

@skarg

@skarg skarg commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

skarg added 4 commits June 9, 2026 10:46
…pps application sources where dlenv_init() is also present.
…default datalink initialization in protocol-specific init functions. Skip default datalink init and task when task callback is set.
…in functions to ensure consistency across applications

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to make datalink initialization and teardown more consistent across the stack by centralizing cleanup behind dlenv_cleanup() and by decoupling bacnet_port_task() from compile-time datalink selection via a configurable periodic-task callback.

Changes:

  • Added dlenv_cleanup() (wrapper around datalink_cleanup()) and updated many apps to register it with atexit() instead of calling datalink_cleanup() directly.
  • Added bacnet_port_task_callback_set() and refactored bacnet_port_task() to invoke a configured callback (with defaults set during bacnet_port_init() when no custom callback is provided).
  • Adjusted server-basic and blinkt apps to initialize via dlenv_init(), register cleanup, and route periodic maintenance via bacnet_port_task_callback_set(dlenv_maintenance_timer).

Reviewed changes

Copilot reviewed 59 out of 59 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/bacnet/datalink/dlenv.h Exports new dlenv_cleanup() API.
src/bacnet/datalink/dlenv.c Implements dlenv_cleanup() as a datalink_cleanup() wrapper.
src/bacnet/basic/server/bacnet_port.h Adds exported bacnet_port_task_callback_set() declaration.
src/bacnet/basic/server/bacnet_port.c Introduces callback-driven bacnet_port_task() and default callback wiring in bacnet_port_init().
src/bacnet/basic/server/bacnet_port_mstp.c Removes direct datalink init from Network Port object init routine.
src/bacnet/basic/server/bacnet_port_ipv6.c Removes direct datalink init from Network Port object init routine.
src/bacnet/basic/server/bacnet_port_ipv4.c Removes direct datalink init from Network Port object init routine.
src/bacnet/basic/server/bacnet_port_bzll.c Removes direct datalink init from Network Port object init routine.
apps/you-are/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/writepropm/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/writeprop/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/writegroup/main.c Removes direct datalink header include; switches atexit() cleanup to dlenv_cleanup().
apps/writefile/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/writebdt/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/whoisrouter/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/whois/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/whohas/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/who-am-i/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/whatisnetnum/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/uptransfer/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/uevent/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/ucov/main.c Removes direct datalink header include; switches atexit() cleanup to dlenv_cleanup().
apps/timesync/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/server/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/server-mini/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/server-discover/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/server-client/main.c Removes direct datalink header include; switches atexit() cleanup to dlenv_cleanup().
apps/server-basic/main.c Uses dlenv_init() + dlenv_cleanup() and routes periodic maintenance via bacnet_port_task_callback_set(dlenv_maintenance_timer).
apps/scov/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/sc-hub/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/remove-list-element/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/reinit/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/readrange/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/readpropm/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/readprop/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/readfile/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/readfdt/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/readbdt/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/ptransfer/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/piface/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/netnumis/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/modbus-gateway/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/initrouter/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/iamrouter/main.c Removes direct datalink header include; switches atexit() cleanup to dlenv_cleanup().
apps/iam/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/getevent/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/gateway2/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/gateway/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/event/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/error/main.c Removes direct datalink header include; switches atexit() cleanup to dlenv_cleanup().
apps/epics/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/delete-object/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/dcc/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/create-object/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/blinkt/main.c Removes direct datalink header include; uses dlenv_init() + dlenv_cleanup() and routes periodic maintenance via bacnet_port_task_callback_set(dlenv_maintenance_timer).
apps/apdu/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/add-list-element/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/ack-alarm/main.c Switches atexit() cleanup to dlenv_cleanup().
apps/abort/main.c Removes direct datalink header include; switches atexit() cleanup to dlenv_cleanup().

Comment thread src/bacnet/basic/server/bacnet_port.c
Comment thread src/bacnet/basic/server/bacnet_port.c
@skarg skarg merged commit 1d7e00f into master Jun 9, 2026
36 checks passed
@skarg skarg deleted the bugfix/datalink-init-and-cleanup-consistency branch June 9, 2026 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double datalink initialization in some of the example apps (mainly regarding MSTP)

2 participants