Skip to content

Commit

Permalink
api: Add OSDP_EXPORT to exported methods in osdp.h
Browse files Browse the repository at this point in the history
... as that's how MSVC likes it :).

Signed-off-by: Siddharth Chandrasekaran <[email protected]>
  • Loading branch information
sidcha committed Mar 22, 2024
1 parent a1a81b5 commit 2144d25
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ install: libosdp
install -m 644 $(O)/libosdp.pc $(DESTDIR)$(PREFIX)/lib/pkgconfig/
install -d $(DESTDIR)$(PREFIX)/include/
install -m 644 include/osdp.h $(DESTDIR)$(PREFIX)/include/
install -m 644 include/osdp.hpp $(DESTDIR)$(PREFIX)/include/
install -m 644 include/osdp.hpp $(DESTDIR)$(PREFIX)/include/
install -m 644 $(O)/osdp_export.h $(DESTDIR)$(PREFIX)/include/

2 changes: 2 additions & 0 deletions configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ cat > ${BUILD_DIR}/osdp_export.h <<----
#endif /* OSDP_EXPORT_H */
---

CCFLAGS+=" -I${BUILD_DIR}"

## Generate Makefile
echo "Generating config.make"
cat > config.make << ---
Expand Down
25 changes: 25 additions & 0 deletions include/osdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <stdint.h>
#include <stdbool.h>
#include <osdp_export.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -842,6 +843,7 @@ typedef int (*cp_event_callback_t)(void *arg, int pd, struct osdp_event *ev);
* @retval OSDP Context on success
* @retval NULL on errors
*/
OSDP_EXPORT
osdp_t *osdp_pd_setup(const osdp_pd_info_t *info);

/**
Expand All @@ -850,6 +852,7 @@ osdp_t *osdp_pd_setup(const osdp_pd_info_t *info);
*
* @param ctx OSDP context
*/
OSDP_EXPORT
void osdp_pd_refresh(osdp_t *ctx);

/**
Expand All @@ -858,6 +861,7 @@ void osdp_pd_refresh(osdp_t *ctx);
*
* @param ctx OSDP context
*/
OSDP_EXPORT
void osdp_pd_teardown(osdp_t *ctx);

/**
Expand All @@ -867,6 +871,7 @@ void osdp_pd_teardown(osdp_t *ctx);
* @param cap pointer to array of cap (`struct osdp_pd_cap`) terminated by a
* capability with cap->function_code set to 0.
*/
OSDP_EXPORT
void osdp_pd_set_capabilities(osdp_t *ctx, const struct osdp_pd_cap *cap);

/**
Expand All @@ -877,6 +882,7 @@ void osdp_pd_set_capabilities(osdp_t *ctx, const struct osdp_pd_cap *cap);
* @param cb The callback function's pointer
* @param arg A pointer that will be passed as the first argument of `cb`
*/
OSDP_EXPORT
void osdp_pd_set_command_callback(osdp_t *ctx, pd_command_callback_t cb,
void *arg);

Expand All @@ -890,6 +896,7 @@ void osdp_pd_set_command_callback(osdp_t *ctx, pd_command_callback_t cb,
* @retval 0 on success
* @retval -1 on failure
*/
OSDP_EXPORT
int osdp_pd_notify_event(osdp_t *ctx, const struct osdp_event *event);

/**
Expand All @@ -898,6 +905,7 @@ int osdp_pd_notify_event(osdp_t *ctx, const struct osdp_event *event);
* @param ctx OSDP context
* @return int Count of events dequeued.
*/
OSDP_EXPORT
int osdp_pd_flush_events(osdp_t *ctx);

/* ------------------------------- */
Expand All @@ -916,6 +924,7 @@ int osdp_pd_flush_events(osdp_t *ctx);
* @retval OSDP Context on success
* @retval NULL on errors
*/
OSDP_EXPORT
osdp_t *osdp_cp_setup(int num_pd, const osdp_pd_info_t *info);

/**
Expand All @@ -924,6 +933,7 @@ osdp_t *osdp_cp_setup(int num_pd, const osdp_pd_info_t *info);
*
* @param ctx OSDP context
*/
OSDP_EXPORT
void osdp_cp_refresh(osdp_t *ctx);

/**
Expand All @@ -932,6 +942,7 @@ void osdp_cp_refresh(osdp_t *ctx);
*
* @param ctx OSDP context
*/
OSDP_EXPORT
void osdp_cp_teardown(osdp_t *ctx);

/**
Expand All @@ -948,6 +959,7 @@ void osdp_cp_teardown(osdp_t *ctx);
* @note This method only adds the command on to a particular PD's command
* queue. The command itself can fail due to various reasons.
*/
OSDP_EXPORT
int osdp_cp_send_command(osdp_t *ctx, int pd, const struct osdp_cmd *cmd);

/**
Expand All @@ -958,6 +970,7 @@ int osdp_cp_send_command(osdp_t *ctx, int pd, const struct osdp_cmd *cmd);
* osdp_cp_setup()
* @return int Count of events dequeued
*/
OSDP_EXPORT
int osdp_cp_flush_commands(osdp_t *ctx, int pd);

/**
Expand All @@ -974,6 +987,7 @@ int osdp_cp_flush_commands(osdp_t *ctx, int pd);
* @retval 0 on success
* @retval -1 on failure
*/
OSDP_EXPORT
int osdp_cp_get_pd_id(const osdp_t *ctx, int pd, struct osdp_pd_id *id);

/**
Expand All @@ -990,6 +1004,7 @@ int osdp_cp_get_pd_id(const osdp_t *ctx, int pd, struct osdp_pd_id *id);
* @retval 0 on success
* @retval -1 on failure
*/
OSDP_EXPORT
int osdp_cp_get_capability(const osdp_t *ctx, int pd, struct osdp_pd_cap *cap);

/**
Expand All @@ -1000,6 +1015,7 @@ int osdp_cp_get_capability(const osdp_t *ctx, int pd, struct osdp_pd_cap *cap);
* @param cb The callback function's pointer
* @param arg A pointer that will be passed as the first argument of `cb`
*/
OSDP_EXPORT
void osdp_cp_set_event_callback(osdp_t *ctx, cp_event_callback_t cb, void *arg);

/**
Expand All @@ -1018,6 +1034,7 @@ void osdp_cp_set_event_callback(osdp_t *ctx, cp_event_callback_t cb, void *arg);
* @note It doesn't make sense to call some initialization time flags during
* runtime. This method is for dynamic flags that can be turned on/off at runtime.
*/
OSDP_EXPORT
int osdp_cp_modify_flag(osdp_t *ctx, int pd, uint32_t flags, bool do_set);

/* ------------------------------- */
Expand Down Expand Up @@ -1075,6 +1092,7 @@ typedef void (*osdp_log_callback_fn_t)(int log_level, const char *file,
* Note: This function has to be called before osdp_{cp,pd}_setup(). Otherwise
* it will be ignored.
*/
OSDP_EXPORT
void osdp_logger_init(const char *name, int log_level,
osdp_log_puts_fn_t puts_fn);

Expand All @@ -1090,13 +1108,15 @@ void osdp_logger_init(const char *name, int log_level,
* @note This function has to be called before osdp_{cp,pd}_setup(). Otherwise
* it will be ignored.
*/
OSDP_EXPORT
void osdp_set_log_callback(osdp_log_callback_fn_t cb);

/**
* @brief Get LibOSDP version as a `const char *`. Used in diagnostics.
*
* @retval version string
*/
OSDP_EXPORT
const char *osdp_get_version();

/**
Expand All @@ -1106,6 +1126,7 @@ const char *osdp_get_version();
*
* @retval source identifier string
*/
OSDP_EXPORT
const char *osdp_get_source_info();

/**
Expand All @@ -1115,6 +1136,7 @@ const char *osdp_get_source_info();
* @param bitmask pointer to an array of bytes. must be as large as
* (num_pds + 7 / 8).
*/
OSDP_EXPORT
void osdp_get_status_mask(const osdp_t *ctx, uint8_t *bitmask);

/**
Expand All @@ -1125,6 +1147,7 @@ void osdp_get_status_mask(const osdp_t *ctx, uint8_t *bitmask);
* @param bitmask pointer to an array of bytes. must be as large as
* (num_pds + 7 / 8).
*/
OSDP_EXPORT
void osdp_get_sc_status_mask(const osdp_t *ctx, uint8_t *bitmask);

/**
Expand Down Expand Up @@ -1219,6 +1242,7 @@ struct osdp_file_ops {
*
* @retval 0 on success. -1 on errors.
*/
OSDP_EXPORT
int osdp_file_register_ops(osdp_t *ctx, int pd_idx,
const struct osdp_file_ops *ops);

Expand All @@ -1232,6 +1256,7 @@ int osdp_file_register_ops(osdp_t *ctx, int pd_idx,
* @param offset Offset into the file that has been sent/received (CP/PD)
* @retval 0 on success. -1 on errors.
*/
OSDP_EXPORT
int osdp_get_file_tx_status(const osdp_t *ctx, int pd_idx,
int *size, int *offset);

Expand Down
6 changes: 3 additions & 3 deletions include/osdp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace OSDP {

class Common {
class OSDP_EXPORT Common {
public:
Common() : _ctx(nullptr) {}

Expand Down Expand Up @@ -59,7 +59,7 @@ class Common {
osdp_t *_ctx;
};

class ControlPanel : public Common {
class OSDP_EXPORT ControlPanel : public Common {
public:
ControlPanel() {}

Expand Down Expand Up @@ -103,7 +103,7 @@ class ControlPanel : public Common {

};

class PeripheralDevice : public Common {
class OSDP_EXPORT PeripheralDevice : public Common {
public:
PeripheralDevice() {}

Expand Down
41 changes: 12 additions & 29 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,42 +223,25 @@ install(

endif() # CONFIG_BUILD_SHARED

if (MSVC)
# MSVC expects the function declation to match the definition.
# This requires osdp.h also have a lot of OSDP_EXPORT prefixes which
# looks ugly. So for now, we will just disable this entirely.
string(CONCAT EXPORT_CONTENT
"#ifndef OSDP_EXPORT_H\n"
"#define OSDP_EXPORT_H\n"
"\n"
"#define OSDP_EXPORT\n"
"#define OSDP_NO_EXPORT\n"
"#define OSDP_DEPRECATED_EXPORT\n"
"#endif"
)
file(
GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h
CONTENT "${EXPORT_CONTENT}"
)
else()
# generate osdp_export.h for OSDP_EXPORT macro
# must be placed after the target definitions.
include(GenerateExportHeader)
generate_export_header(${LIB_TARGET}
BASE_NAME OSDP
EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h
)
endif() # MSVC
# generate and install osdp_export.h for OSDP_EXPORT macro
include(GenerateExportHeader)
generate_export_header(${LIB_TARGET}
BASE_NAME osdp
EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/osdp_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libosdp
COMPONENT headers
)

# pkg-config file
configure_file(
${PROJECT_SOURCE_DIR}/misc/libosdp.pc.in
${CMAKE_BINARY_DIR}/libosdp.pc @ONLY
)

install(
FILES
${CMAKE_BINARY_DIR}/libosdp.pc
install(FILES ${CMAKE_BINARY_DIR}/libosdp.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT config_files
)
Expand Down

0 comments on commit 2144d25

Please sign in to comment.