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
15 changes: 8 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ AllowShortEnumsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
BitFieldColonSpacing: After
BreakBeforeBraces: Attach
BitFieldColonSpacing: Both
BreakBeforeBraces: Linux
ColumnLimit: 120
ConstructorInitializerIndentWidth: 8
ContinuationIndentWidth: 8
IndentCaseLabels: true
IndentWidth: 4
InsertBraces: true
IndentCaseLabels: true # Linux is false
IndentWidth: 8
LineEnding: LF
SpaceBeforeParens: ControlStatementsExceptControlMacros
SortIncludes: Never
#UseTab: ForContinuationAndIndentation
SortIncludes: false
UseTab: Always
TabWidth: 8
29 changes: 29 additions & 0 deletions .github/workflows/coding_guidelines.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Coding Guidelines Check

# Trigger this workflow on all pull requests
on:
pull_request:

# Ensure only one instance of this workflow runs per branch
# Cancel any in-progress runs when new commits are pushed
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v5
with:
fetch-depth: 0

# Install clang-format-16 for code formatting checks
- name: Install clang-format-16
run: |
sudo apt-get update
sudo apt-get install -y clang-format-16

- name: Run Formatting Check
run: ./scripts/check_formatting.sh
80 changes: 80 additions & 0 deletions scripts/check_formatting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash
#
# Simple formatting checker for /src folder
# Checks all C/C++ files against .clang-format rules
#

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
SRC_DIR="$ROOT_DIR/src"

# Check if clang-format-16 is available
if ! command -v clang-format-16 &> /dev/null; then
echo "Error: clang-format-16 not found"
echo "Install it with: sudo apt-get install clang-format-16"
exit 1
fi

# Check if src directory exists
if [ ! -d "$SRC_DIR" ]; then
echo "Error: $SRC_DIR directory not found"
exit 1
fi

echo "Checking formatting in $SRC_DIR/.."

# Find all C/C++ files and check formatting
FAILED_FILES=()
while IFS= read -r -d '' file; do
if ! clang-format-16 --style=file --dry-run --Werror "$file" 2>&1; then
FAILED_FILES+=("$file")
fi
done < <(find "$SRC_DIR" -type f \( -name "*.c" -o -name "*.cpp" -o -name "*.h" \) -print0)

# Report results
if [ ${#FAILED_FILES[@]} -eq 0 ]; then
echo "All files are properly formatted"
exit 0
else
echo ""
echo "The following files have formatting issues:"
for file in "${FAILED_FILES[@]}"; do
echo " - $file"
done
echo ""
echo "It is required to format the code before committing, or it will fail CI checks."
echo ""
echo "1. Install clang-format-16.0.0"
echo ""
echo " You can download the package from:"
echo " https://github.com/llvm/llvm-project/releases"
echo ""
echo " For Debian/Ubuntu:"
echo " sudo apt-get install clang-format-16"
echo ""
echo " For macOS with Homebrew (part of llvm@14):"
echo " brew install llvm@14"
echo " /usr/local/opt/llvm@14/bin/clang-format"
echo ""
echo "2. Format C/C++ source files"
echo ""
echo " Format a single file:"
echo " clang-format-16 --style=file -i path/to/file.c"
echo ""
echo " Format all files in src/:"
echo " find src/ -type f \\( -name '*.c' -o -name '*.cpp' -o -name '*.h' \\) \\"
echo " -exec clang-format-16 --style=file -i {} +"
echo ""
echo "3. Disable formatting for specific code blocks (use sparingly)"
echo ""
echo " Wrap code with clang-format off/on comments when formatted code"
echo " is not readable or friendly:"
echo ""
echo " /* clang-format off */"
echo " your code here"
echo " /* clang-format on */"
echo ""
exit 1
fi
27 changes: 14 additions & 13 deletions src/messaging/message_types.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/**
* @copyright Copyright © contributors to Project Ocre,
* which has been established as Project Ocre a Series of LF Projects, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OCRE_MESSAGING_TYPES_H
#define OCRE_MESSAGING_TYPES_H

struct base {};

#endif
/**
* @copyright Copyright © contributors to Project Ocre,
* which has been established as Project Ocre a Series of LF Projects, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef OCRE_MESSAGING_TYPES_H
#define OCRE_MESSAGING_TYPES_H

struct base {
};

#endif
148 changes: 76 additions & 72 deletions src/ocre/api/ocre_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@

#include "ocre/utils/utils.h"

#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || defined(CONFIG_OCRE_CONTAINER_MESSAGING)
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || \
defined(CONFIG_OCRE_CONTAINER_MESSAGING)
#include "ocre_common.h"
#endif
#endif

#ifdef CONFIG_OCRE_SENSORS
#include "../ocre_sensors/ocre_sensors.h"
Expand All @@ -42,110 +43,113 @@
#include "../ocre_messaging/ocre_messaging.h"
#endif

int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name) {
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
if (!module_inst) {
return -1;
}
if (!wasm_runtime_validate_native_addr(module_inst, name, sizeof(struct _ocre_posix_utsname))) {
return -1;
}
int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name)
{
wasm_module_inst_t module_inst = wasm_runtime_get_module_inst(exec_env);
if (!module_inst) {
return -1;
}
if (!wasm_runtime_validate_native_addr(module_inst, name, sizeof(struct _ocre_posix_utsname))) {
return -1;
}

struct utsname info;
if (uname(&info) != 0) {
return -1;
}
struct utsname info;
if (uname(&info) != 0) {
return -1;
}

memset(name, 0, sizeof(struct _ocre_posix_utsname));
memset(name, 0, sizeof(struct _ocre_posix_utsname));

snprintf(name->sysname, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", OCRE_SYSTEM_NAME, info.sysname);
snprintf(name->release, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", APP_VERSION_STRING, info.release);
snprintf(name->version, OCRE_API_POSIX_BUF_SIZE, "%s", info.version);
snprintf(name->sysname, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", OCRE_SYSTEM_NAME, info.sysname);
snprintf(name->release, OCRE_API_POSIX_BUF_SIZE, "%s (%s)", APP_VERSION_STRING, info.release);
snprintf(name->version, OCRE_API_POSIX_BUF_SIZE, "%s", info.version);

#ifdef CONFIG_ARM
#ifdef CONFIG_CPU_CORTEX_M0
strlcat(name->machine, "ARM Cortex-M0", OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, "ARM Cortex-M0", OCRE_API_POSIX_BUF_SIZE);
#elif CONFIG_CPU_CORTEX_M3
strlcat(name->machine, "ARM Cortex-M3", OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, "ARM Cortex-M3", OCRE_API_POSIX_BUF_SIZE);
#elif CONFIG_CPU_CORTEX_M4
strlcat(name->machine, "ARM Cortex-M4", OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, "ARM Cortex-M4", OCRE_API_POSIX_BUF_SIZE);
#elif CONFIG_CPU_CORTEX_M7
strlcat(name->machine, "ARM Cortex-M7", OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, "ARM Cortex-M7", OCRE_API_POSIX_BUF_SIZE);
#elif CONFIG_CPU_CORTEX_M33
strlcat(name->machine, "ARM Cortex-M33", OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, "ARM Cortex-M33", OCRE_API_POSIX_BUF_SIZE);
#elif CONFIG_CPU_CORTEX_M23
strlcat(name->machine, "ARM Cortex-M23", OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, "ARM Cortex-M23", OCRE_API_POSIX_BUF_SIZE);
#elif CONFIG_CPU_CORTEX_M55
strlcat(name->machine, "ARM Cortex-M55", OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, "ARM Cortex-M55", OCRE_API_POSIX_BUF_SIZE);
#endif
#else
strlcat(name->machine, info.machine, OCRE_API_POSIX_BUF_SIZE);
strlcat(name->machine, info.machine, OCRE_API_POSIX_BUF_SIZE);
#endif

strlcat(name->nodename, info.nodename, OCRE_API_POSIX_BUF_SIZE);
strlcat(name->nodename, info.nodename, OCRE_API_POSIX_BUF_SIZE);

return 0;
return 0;
}

int ocre_sleep(wasm_exec_env_t exec_env, int milliseconds) {
core_sleep_ms(milliseconds);
return 0;
int ocre_sleep(wasm_exec_env_t exec_env, int milliseconds)
{
core_sleep_ms(milliseconds);
return 0;
}

// Ocre Runtime API
NativeSymbol ocre_api_table[] = {
{"uname", _ocre_posix_uname, "(*)i", NULL},
{"ocre_sleep", ocre_sleep, "(i)i", NULL},
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || defined(CONFIG_OCRE_CONTAINER_MESSAGING)
{"ocre_get_event", ocre_get_event, "(iiiiii)i", NULL},
{"ocre_register_dispatcher", ocre_register_dispatcher, "(i$)i", NULL},
#endif
{"uname", _ocre_posix_uname, "(*)i", NULL},
{"ocre_sleep", ocre_sleep, "(i)i", NULL},
#if defined(CONFIG_OCRE_TIMER) || defined(CONFIG_OCRE_GPIO) || defined(CONFIG_OCRE_SENSORS) || \
defined(CONFIG_OCRE_CONTAINER_MESSAGING)
{"ocre_get_event", ocre_get_event, "(iiiiii)i", NULL},
{"ocre_register_dispatcher", ocre_register_dispatcher, "(i$)i", NULL},
#endif
// Container Messaging API
#ifdef CONFIG_OCRE_CONTAINER_MESSAGING
{"ocre_publish_message", ocre_messaging_publish, "(***i)i", NULL},
{"ocre_subscribe_message", ocre_messaging_subscribe, "(*)i", NULL},
{"ocre_messaging_free_module_event_data", ocre_messaging_free_module_event_data, "(iii)i", NULL},
{"ocre_publish_message", ocre_messaging_publish, "(***i)i", NULL},
{"ocre_subscribe_message", ocre_messaging_subscribe, "(*)i", NULL},
{"ocre_messaging_free_module_event_data", ocre_messaging_free_module_event_data, "(iii)i", NULL},
#endif
// Sensor API
#ifdef CONFIG_OCRE_SENSORS
{"ocre_sensors_init", ocre_sensors_init, "()i", NULL},
{"ocre_sensors_discover", ocre_sensors_discover, "()i", NULL},
{"ocre_sensors_open", ocre_sensors_open, "(i)i", NULL},
{"ocre_sensors_get_handle", ocre_sensors_get_handle, "(i)i", NULL},
{"ocre_sensors_get_channel_count", ocre_sensors_get_channel_count, "(i)i", NULL},
{"ocre_sensors_get_channel_type", ocre_sensors_get_channel_type, "(ii)i", NULL},
{"ocre_sensors_read", ocre_sensors_read, "(ii)F", NULL},
{"ocre_sensors_open_by_name", ocre_sensors_open_by_name, "($)i", NULL},
{"ocre_sensors_get_handle_by_name", ocre_sensors_get_handle_by_name, "($)i", NULL},
{"ocre_sensors_get_channel_count_by_name", ocre_sensors_get_channel_count_by_name, "($)i", NULL},
{"ocre_sensors_get_channel_type_by_name", ocre_sensors_get_channel_type_by_name, "($i)i", NULL},
{"ocre_sensors_read_by_name", ocre_sensors_read_by_name, "($i)F", NULL},
{"ocre_sensors_get_list", ocre_sensors_get_list, "($i)i", NULL},
{"ocre_sensors_init", ocre_sensors_init, "()i", NULL},
{"ocre_sensors_discover", ocre_sensors_discover, "()i", NULL},
{"ocre_sensors_open", ocre_sensors_open, "(i)i", NULL},
{"ocre_sensors_get_handle", ocre_sensors_get_handle, "(i)i", NULL},
{"ocre_sensors_get_channel_count", ocre_sensors_get_channel_count, "(i)i", NULL},
{"ocre_sensors_get_channel_type", ocre_sensors_get_channel_type, "(ii)i", NULL},
{"ocre_sensors_read", ocre_sensors_read, "(ii)F", NULL},
{"ocre_sensors_open_by_name", ocre_sensors_open_by_name, "($)i", NULL},
{"ocre_sensors_get_handle_by_name", ocre_sensors_get_handle_by_name, "($)i", NULL},
{"ocre_sensors_get_channel_count_by_name", ocre_sensors_get_channel_count_by_name, "($)i", NULL},
{"ocre_sensors_get_channel_type_by_name", ocre_sensors_get_channel_type_by_name, "($i)i", NULL},
{"ocre_sensors_read_by_name", ocre_sensors_read_by_name, "($i)F", NULL},
{"ocre_sensors_get_list", ocre_sensors_get_list, "($i)i", NULL},
#endif
// Timer API
#ifdef CONFIG_OCRE_TIMER
{"ocre_timer_create", ocre_timer_create, "(i)i", NULL},
{"ocre_timer_start", ocre_timer_start, "(iii)i", NULL},
{"ocre_timer_stop", ocre_timer_stop, "(i)i", NULL},
{"ocre_timer_delete", ocre_timer_delete, "(i)i", NULL},
{"ocre_timer_get_remaining", ocre_timer_get_remaining, "(i)i", NULL},
{"ocre_timer_create", ocre_timer_create, "(i)i", NULL},
{"ocre_timer_start", ocre_timer_start, "(iii)i", NULL},
{"ocre_timer_stop", ocre_timer_stop, "(i)i", NULL},
{"ocre_timer_delete", ocre_timer_delete, "(i)i", NULL},
{"ocre_timer_get_remaining", ocre_timer_get_remaining, "(i)i", NULL},
#endif
// GPIO API
#ifdef CONFIG_OCRE_GPIO
{"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL},
{"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL},
{"ocre_gpio_pin_set", ocre_gpio_wasm_set, "(iii)i", NULL},
{"ocre_gpio_pin_get", ocre_gpio_wasm_get, "(ii)i", NULL},
{"ocre_gpio_pin_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL},
{"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL},
{"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL},

{"ocre_gpio_configure_by_name", ocre_gpio_wasm_configure_by_name, "($i)i", NULL},
{"ocre_gpio_set_by_name", ocre_gpio_wasm_set_by_name, "($i)i", NULL},
{"ocre_gpio_get_by_name", ocre_gpio_wasm_get_by_name, "($)i", NULL},
{"ocre_gpio_toggle_by_name", ocre_gpio_wasm_toggle_by_name, "($)i", NULL},
{"ocre_gpio_register_callback_by_name", ocre_gpio_wasm_register_callback_by_name, "($)i", NULL},
{"ocre_gpio_unregister_callback_by_name", ocre_gpio_wasm_unregister_callback_by_name, "($)i", NULL},
{"ocre_gpio_init", ocre_gpio_wasm_init, "()i", NULL},
{"ocre_gpio_configure", ocre_gpio_wasm_configure, "(iii)i", NULL},
{"ocre_gpio_pin_set", ocre_gpio_wasm_set, "(iii)i", NULL},
{"ocre_gpio_pin_get", ocre_gpio_wasm_get, "(ii)i", NULL},
{"ocre_gpio_pin_toggle", ocre_gpio_wasm_toggle, "(ii)i", NULL},
{"ocre_gpio_register_callback", ocre_gpio_wasm_register_callback, "(ii)i", NULL},
{"ocre_gpio_unregister_callback", ocre_gpio_wasm_unregister_callback, "(ii)i", NULL},

{"ocre_gpio_configure_by_name", ocre_gpio_wasm_configure_by_name, "($i)i", NULL},
{"ocre_gpio_set_by_name", ocre_gpio_wasm_set_by_name, "($i)i", NULL},
{"ocre_gpio_get_by_name", ocre_gpio_wasm_get_by_name, "($)i", NULL},
{"ocre_gpio_toggle_by_name", ocre_gpio_wasm_toggle_by_name, "($)i", NULL},
{"ocre_gpio_register_callback_by_name", ocre_gpio_wasm_register_callback_by_name, "($)i", NULL},
{"ocre_gpio_unregister_callback_by_name", ocre_gpio_wasm_unregister_callback_by_name, "($)i", NULL},
#endif
};

Expand Down
12 changes: 6 additions & 6 deletions src/ocre/api/ocre_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
#endif

struct _ocre_posix_utsname {
char sysname[OCRE_API_POSIX_BUF_SIZE];
char nodename[OCRE_API_POSIX_BUF_SIZE];
char release[OCRE_API_POSIX_BUF_SIZE];
char version[OCRE_API_POSIX_BUF_SIZE];
char machine[OCRE_API_POSIX_BUF_SIZE];
char domainname[OCRE_API_POSIX_BUF_SIZE];
char sysname[OCRE_API_POSIX_BUF_SIZE];
char nodename[OCRE_API_POSIX_BUF_SIZE];
char release[OCRE_API_POSIX_BUF_SIZE];
char version[OCRE_API_POSIX_BUF_SIZE];
char machine[OCRE_API_POSIX_BUF_SIZE];
char domainname[OCRE_API_POSIX_BUF_SIZE];
};

int _ocre_posix_uname(wasm_exec_env_t exec_env, struct _ocre_posix_utsname *name);
Expand Down
Loading