Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ jobs:
if: runner.os == 'Linux'
working-directory: build
shell: bash
run: ./notifly_unit_test
run: |
./notifly_unit_test
./notifly_c_gtest

- name: Test on Windows
if: runner.os == 'Windows'
working-directory: build
shell: pwsh
run: .\Release\notifly_unit_test.exe
run: |
.\Release\notifly_unit_test.exe
.\Release\notifly_c_gtest.exe
19 changes: 18 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set_target_properties(${PROJECT_NAME}_c PROPERTIES
OUTPUT_NAME "notifly_c"
VERSION 1.0.0
SOVERSION 1
DEFINE_SYMBOL "NOTIFLY_C_EXPORTS"
)

target_compile_features(${PROJECT_NAME}_c PUBLIC cxx_std_20)
Expand Down Expand Up @@ -52,7 +53,7 @@ set_target_properties(gtest_main PROPERTIES MSVC_RUNTIME_LIBRARY MultiThreaded$<

# 'Unit_Tests_run' is the target name
# 'UNIT_SOURCE' are source files with tests
file(GLOB UNIT_SOURCE test/*.cpp test/*.h src/*.cpp include/*.h)
file(GLOB UNIT_SOURCE test/unit_test.cpp test/unit_test.h src/*.cpp include/*.h)

set(UNIT_TEST notifly_unit_test)
add_executable(${UNIT_TEST} ${UNIT_SOURCE})
Expand Down Expand Up @@ -90,6 +91,22 @@ set_target_properties(${C_EXAMPLE}
LINKER_LANGUAGE C
)

# C Interface Google Test
set(C_GTEST notifly_c_gtest)
add_executable(${C_GTEST} test/test_c_api_gtest.cpp)
target_link_libraries(${C_GTEST} PRIVATE
${PROJECT_NAME}_c
${CMAKE_THREAD_LIBS_INIT}
$<$<PLATFORM_ID:Linux>:dl>
gtest
gtest_main)
target_include_directories(${C_GTEST} PRIVATE include)
set_target_properties(${C_GTEST}
PROPERTIES
OUTPUT_NAME ${C_GTEST}
MSVC_RUNTIME_LIBRARY MultiThreaded$<$<CONFIG:Debug>:Debug>
)

# Function to copy a file only if it does not exist or is different
function(move_file source_file destination_dir)
# Check if the source file exists
Expand Down
7 changes: 6 additions & 1 deletion example/c_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h> // for sleep
#ifdef _WIN32
#include <windows.h>
#define usleep(x) Sleep((x)/1000)
#else
#include <unistd.h>
#endif

// Message IDs
#define MSG_STARTUP 1001
Expand Down
28 changes: 19 additions & 9 deletions include/notifly_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
#ifndef NOTIFLY_C_H
#define NOTIFLY_C_H

#ifdef _WIN32
#ifdef NOTIFLY_C_EXPORTS
#define NOTIFLY_C_API __declspec(dllexport)
#else
#define NOTIFLY_C_API __declspec(dllimport)
#endif
#else
#define NOTIFLY_C_API
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -52,21 +62,21 @@ typedef enum {
#define NOTIFLY_C_VERSION_PATCH 0

/* Instance management */
notifly_handle notifly_create(void);
void notifly_destroy(notifly_handle handle);
notifly_handle notifly_default(void);
NOTIFLY_C_API notifly_handle notifly_create(void);
NOTIFLY_C_API void notifly_destroy(notifly_handle handle);
NOTIFLY_C_API notifly_handle notifly_default(void);

/* Observer management */
int notifly_add_observer(notifly_handle handle, int notification_id, notifly_callback callback, void* user_data);
int notifly_remove_observer(notifly_handle handle, int observer_id);
int notifly_remove_all_observers(notifly_handle handle, int notification_id);
NOTIFLY_C_API int notifly_add_observer(notifly_handle handle, int notification_id, notifly_callback callback, void* user_data);
NOTIFLY_C_API int notifly_remove_observer(notifly_handle handle, int observer_id);
NOTIFLY_C_API int notifly_remove_all_observers(notifly_handle handle, int notification_id);

/* Notification posting */
int notifly_post_notification(notifly_handle handle, int notification_id, void* data);
int notifly_post_notification_async(notifly_handle handle, int notification_id, void* data);
NOTIFLY_C_API int notifly_post_notification(notifly_handle handle, int notification_id, void* data);
NOTIFLY_C_API int notifly_post_notification_async(notifly_handle handle, int notification_id, void* data);

/* Utility functions */
const char* notifly_result_to_string(int result);
NOTIFLY_C_API const char* notifly_result_to_string(int result);

#ifdef __cplusplus
}
Expand Down
Loading
Loading