diff --git a/contributing.md b/contributing.md new file mode 100644 index 00000000..56e4ee22 --- /dev/null +++ b/contributing.md @@ -0,0 +1,55 @@ +# Pull Requests + +TODO + +# Code Style + +## Naming Convention + +- Namespaces: `CamelCase` +- Classes: `CamelCase` +- Structs: `CamelCase_t` +- Members: `camelCase` +- Enum: `SNAKE_CASE` +- Macros: `SNAKE_CASE` + +## Brace Style + +```c++ +int myFunction() { + if (shortIf) { shortFunctionName(); } + + if (longIf) { + longFunction(); + otherStuff(); + myLongFunction(); + } +} +``` + +Note: If it makes the code cleaner, remember to use the `?` keyword instead of a `if else` statement. + +## Structure + +Headers and their associated C++ files shall be in the same directory. All headers must use `#pragma once` instead of other include guards. Only include files in a header that are being used in that header. Include the rest in the associated C++ file. + +# Modules + +## Module Naming Convention + +All modules names must be `snake_case`. If the module is a source, it must end with `_source`. If it is a sink, it must end with `_sink`. + +For example, lets take the module named `cool_source`: + +- Directory: `cool_source` +- Class: `CoolSourceModule` +- Binary: `cool_source.` + +## Integration into main repository + +If the module meets the code quality requirements, it may be added to the official repository. A module that doesn't require any external dependencies that the core doesn't already use may be enabled for build by default. Otherwise, they must be disabled for build by default with a `OPT_BUILD_MODULE_NAME` variable set to `OFF`. + +# Best Practices + +* All additions and/or bug fixes to the core must not add additional dependencies. + diff --git a/demo_module/CMakeLists.txt b/demo_module/CMakeLists.txt new file mode 100644 index 00000000..c03009f9 --- /dev/null +++ b/demo_module/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.13) +project(demo) + +if (MSVC) + set(CMAKE_CXX_FLAGS "-O2 /std:c++17 /EHsc") +elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -Wno-unused-command-line-argument -undefined dynamic_lookup -fPIC") +else () + set(CMAKE_CXX_FLAGS "-O3 -std=c++17 -fPIC") +endif () + +file(GLOB SRC "src/*.cpp") +include_directories("src/") + +add_library(demo SHARED ${SRC}) +set_target_properties(demo PROPERTIES PREFIX "") + +# Install directives +install(TARGETS demo DESTINATION lib/sdrpp/plugins) \ No newline at end of file diff --git a/demo_module/src/main.cpp b/demo_module/src/main.cpp new file mode 100644 index 00000000..6a7f803a --- /dev/null +++ b/demo_module/src/main.cpp @@ -0,0 +1,61 @@ +#include +#include +#include + +SDRPP_MOD_INFO { + /* Name: */ "demo", + /* Description: */ "My fancy new module", + /* Author: */ "author1;author2,author3,etc...", + /* Version: */ 0, 1, 0, + /* Max instances */ -1 +}; + +class DemoModule : public ModuleManager::Instance { +public: + DemoModule(std::string name) { + this->name = name; + gui::menu.registerEntry(name, menuHandler, this, NULL); + } + + ~DemoModule() { + + } + + void enable() { + enabled = true; + } + + void disable() { + enabled = false; + } + + bool isEnabled() { + return enabled; + } + +private: + static void menuHandler(void* ctx) { + DemoModule* _this = (DemoModule*)ctx; + ImGui::Text("Hello SDR++, my name is %s", _this->name.c_str()); + } + + std::string name; + bool enabled = true; + +}; + +MOD_EXPORT void _INIT_() { + // Nothing here +} + +MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { + return new DemoModule(name); +} + +MOD_EXPORT void _DELETE_INSTANCE_(void* instance) { + delete (DemoModule*)instance; +} + +MOD_EXPORT void _END_() { + // Nothing here +} \ No newline at end of file diff --git a/discord_integration/src/main.cpp b/discord_integration/src/main.cpp index d7f2c7d6..a3bb098e 100644 --- a/discord_integration/src/main.cpp +++ b/discord_integration/src/main.cpp @@ -18,19 +18,19 @@ SDRPP_MOD_INFO { #define DISCORD_APP_ID "834590435708108860" -class PresenceModule : public ModuleManager::Instance { +class DiscordIntegrationModule : public ModuleManager::Instance { public: - PresenceModule(std::string name) { + DiscordIntegrationModule(std::string name) { this->name = name; // Change to timer start later on workerRunning = true; - workerThread = std::thread(&PresenceModule::worker, this); + workerThread = std::thread(&DiscordIntegrationModule::worker, this); startPresence(); } - ~PresenceModule() { + ~DiscordIntegrationModule() { // Change to timer stop later on workerRunning = false; if (workerThread.joinable()) { workerThread.join(); } @@ -39,7 +39,7 @@ public: void enable() { // Change to timer start later on workerRunning = true; - workerThread = std::thread(&PresenceModule::worker, this); + workerThread = std::thread(&DiscordIntegrationModule::worker, this); enabled = true; } @@ -148,11 +148,11 @@ MOD_EXPORT void _INIT_() { } MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { - return new PresenceModule(name); + return new DiscordIntegrationModule(name); } MOD_EXPORT void _DELETE_INSTANCE_(void* instance) { - delete (PresenceModule*)instance; + delete (DiscordIntegrationModule*)instance; } MOD_EXPORT void _END_() {