Skip to content

Commit

Permalink
libosdp: Fix stable API change violation
Browse files Browse the repository at this point in the history
Commit c9f3f98 broke API backward compatibility without going through the
stable API change process. Fix this issue by reintroducing the removed
method and aliasing it to the new one.

Related-to: #139
Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Oct 22, 2023
1 parent 35f0815 commit aaa303b
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion doc/api/miscellaneous.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Miscellaneous
Debugging and Diagnostics
-------------------------

.. doxygenfunction:: osdp_logger_init
.. doxygenfunction:: osdp_logger_init3

.. doxygenfunction:: osdp_get_version

Expand Down
4 changes: 2 additions & 2 deletions doc/libosdp/debugging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ Log Level
LibOSDP supports different logging levels with ``LOG_DEBUG`` being the most
verbose mode. When asking for help, please set the log level to ``LOG_DEBUG``.

This can be done by calling osdp_logger_init() BEFORE calling osdp_cp/pd_setup()
This can be done by calling osdp_logger_init3() BEFORE calling osdp_cp/pd_setup()
as,

.. code:: c
osdp_logger_init("osdp::cp", LOG_DEBUG, uart_puts);
osdp_logger_init3("osdp::cp", LOG_DEBUG, uart_puts);
Packet Trace Builds
-------------------
Expand Down
17 changes: 16 additions & 1 deletion include/osdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -976,9 +976,24 @@ typedef int (*osdp_log_puts_fn_t)(const char *msg);
* definition to see the behavioral expectations. When this is
* set to NULL, LibOSDP will log to stderr.
*/
void osdp_logger_init(const char *name, int log_level,
void osdp_logger_init3(const char *name, int log_level,
osdp_log_puts_fn_t puts_fn);

/**
* @brief Configure OSDP Logging (deprecated). Provided for backward
* compatiblity. Use osdp_logger_init3 instead.
*
* @param log_level OSDP log levels of type `enum osdp_log_level_e`. Default is
* LOG_INFO.
* @param puts_fn A puts() like function that will be invoked to write the log
* buffer. Can be handy if you want to log to file on a UART
* device without putchar redirection. See `osdp_log_puts_fn_t`
* definition to see the behavioral expectations. When this is
* set to NULL, LibOSDP will log to stderr.
*/
void osdp_logger_init(int log_level, osdp_log_puts_fn_t puts_fn)
__attribute__((deprecated("Use osdp_logger_init3 instead!")));

/**
* @brief Get LibOSDP version as a `const char *`. Used in diagnostics.
*
Expand Down
2 changes: 1 addition & 1 deletion include/osdp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Common {

void logger_init(const char *name, int log_level, osdp_log_puts_fn_t puts_fn)
{
osdp_logger_init(name, log_level, puts_fn);
osdp_logger_init3(name, log_level, puts_fn);
}

const char *get_version()
Expand Down
2 changes: 1 addition & 1 deletion osdpctl/cmd_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ int cmd_handler_start(int argc, char *argv[], void *data)
info->scbk = NULL;
}

osdp_logger_init("osdp::cp", c->log_level, NULL);
osdp_logger_init3("osdp::cp", c->log_level, NULL);

if (c->mode == CONFIG_MODE_CP) {
c->cp_ctx = osdp_cp_setup2(c->num_pd, info_arr);
Expand Down
4 changes: 2 additions & 2 deletions python/pyosdp_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static PyObject *pyosdp_set_loglevel(pyosdp_base_t *self, PyObject *args)
return NULL;
}

osdp_logger_init("pyosdp", log_level, NULL);
osdp_logger_init3("pyosdp", log_level, NULL);

Py_RETURN_NONE;
}
Expand Down Expand Up @@ -263,7 +263,7 @@ static int pyosdp_base_tp_init(pyosdp_base_t *self, PyObject *args, PyObject *kw

channel_manager_init(&self->channel_manager);

osdp_logger_init("pyosdp", OSDP_LOG_INFO, NULL);
osdp_logger_init3("pyosdp", OSDP_LOG_INFO, NULL);

return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion samples/c/cp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main()
{
osdp_t *ctx;

osdp_logger_init("osdp::cp", OSDP_LOG_DEBUG, NULL);
osdp_logger_init3("osdp::cp", OSDP_LOG_DEBUG, NULL);

ctx = osdp_cp_setup2(1, pd_info);
if (ctx == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion samples/c/pd_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int main()
{
osdp_t *ctx;

osdp_logger_init("osdp::pd", OSDP_LOG_DEBUG, NULL);
osdp_logger_init3("osdp::pd", OSDP_LOG_DEBUG, NULL);

ctx = osdp_pd_setup(&info_pd);
if (ctx == NULL) {
Expand Down
8 changes: 7 additions & 1 deletion src/osdp_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int osdp_rb_pop_buf(struct osdp_rb *p, uint8_t *buf, int max_len)
/* --- Exported Methods --- */

OSDP_EXPORT
void osdp_logger_init(const char *name, int log_level,
void osdp_logger_init3(const char *name, int log_level,
osdp_log_puts_fn_t log_fn)
{
logger_t ctx;
Expand All @@ -209,6 +209,12 @@ void osdp_logger_init(const char *name, int log_level,
logger_set_default(&ctx); /* Mark this config as logging default */
}

OSDP_EXPORT
void osdp_logger_init(int log_level, osdp_log_puts_fn_t log_fn)
{
osdp_logger_init3("osdp", log_level, log_fn);
}

OSDP_EXPORT
const char *osdp_get_version()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/test-cp-fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int test_cp_fsm_setup(struct test *t)
.channel.flush = NULL,
.scbk = NULL,
};
osdp_logger_init("osdp::cp", t->loglevel, NULL);
osdp_logger_init3("osdp::cp", t->loglevel, NULL);
struct osdp *ctx = (struct osdp *)osdp_cp_setup2(1, &info);
if (ctx == NULL) {
printf(" init failed!\n");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/test-cp-phy-fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ int test_cp_phy_fsm_setup(struct test *t)
.channel.flush = NULL,
.scbk = NULL,
};
osdp_logger_init("osdp::cp", t->loglevel, NULL);
osdp_logger_init3("osdp::cp", t->loglevel, NULL);
struct osdp *ctx = (struct osdp *)osdp_cp_setup2(1, &info);
if (ctx == NULL) {
printf(" init failed!\n");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/test-cp-phy.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int test_cp_phy_setup(struct test *t)
.channel.flush = NULL,
.scbk = NULL,
};
osdp_logger_init("osdp::cp", t->loglevel, NULL);
osdp_logger_init3("osdp::cp", t->loglevel, NULL);
struct osdp *ctx = (struct osdp *)osdp_cp_setup2(1, &info);
if (ctx == NULL) {
printf(SUB_1 "init failed!\n");
Expand Down
2 changes: 1 addition & 1 deletion tests/unit-tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ int test_mock_pd_receive(void *data, uint8_t *buf, int len)

int test_setup_devices(struct test *t, osdp_t **cp, osdp_t **pd)
{
osdp_logger_init("osdp", t->loglevel, NULL);
osdp_logger_init3("osdp", t->loglevel, NULL);

uint8_t scbk[16] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
Expand Down

0 comments on commit aaa303b

Please sign in to comment.