From 90954c3a9c00c004e6f76471c142cbb90274f476 Mon Sep 17 00:00:00 2001 From: Pravdyvy Date: Wed, 15 Apr 2026 17:35:49 +0300 Subject: [PATCH] init: indexer interface --- .github/pull_request_template.md | 43 ++++ CMakeLists.txt | 205 ++++++++++++++++++++ README .md => README.md | 0 config/indexer_config.json | 160 +++++++++++++++ flake.nix | 149 ++++++++++++++ justfile | 24 +++ metadata.json | 12 ++ src/i_logos_execution_zone_indexer_module.h | 26 +++ src/logos_execution_zone_indexer_module.cpp | 61 ++++++ src/logos_execution_zone_indexer_module.h | 49 +++++ 10 files changed, 729 insertions(+) create mode 100644 .github/pull_request_template.md create mode 100644 CMakeLists.txt rename README .md => README.md (100%) create mode 100644 config/indexer_config.json create mode 100644 flake.nix create mode 100644 justfile create mode 100644 metadata.json create mode 100644 src/i_logos_execution_zone_indexer_module.h create mode 100644 src/logos_execution_zone_indexer_module.cpp create mode 100644 src/logos_execution_zone_indexer_module.h diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..18064c6 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,43 @@ +## ๐ŸŽฏ Purpose + +*What problem does this PR solve or what feature does it add? Mention issues related to it* + +TO COMPLETE + +## โš™๏ธ Approach + +*Describe the core changes introduced by this PR.* + +TO COMPLETE + +- [ ] Change ... +- [ ] Add ... +- [ ] Fix ... +- [ ] ... + +## ๐Ÿงช How to Test + +*How to verify that this PR works as intended.* + +TO COMPLETE + +## ๐Ÿ”— Dependencies + +*Link PRs that must be merged before this one.* + +TO COMPLETE IF APPLICABLE + +## ๐Ÿ”œ Future Work + +*List any work intentionally left out of this PR, whether due to scope, prioritization, or pending decisions.* + +TO COMPLETE IF APPLICABLE + +## ๐Ÿ“‹ PR Completion Checklist + +*Mark only completed items. A complete PR should have all boxes ticked.* + +- [ ] Complete PR description +- [ ] Implement the core functionality +- [ ] Add/update tests +- [ ] Add/update documentation and inline comments diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8236f4b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,205 @@ +cmake_minimum_required(VERSION 3.20) +project(logos_execution_zone_indexer_module LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# ---- Options ---- +option(LOGOS_MODULE_BUNDLE "Create local runtime bundle in target/." ON) +set(LOGOS_CORE_ROOT "" CACHE PATH "Path to logos-core root directory.") +set(LOGOS_EXECUTION_ZONE_INDEXER_ROOT "" CACHE PATH "Path to logos-execution-zone-indexer source root.") +set(LOGOS_EXECUTION_ZONE_INDEXER_LIB "" CACHE PATH "Path to prebuilt logos-execution-zone-indexer lib.") +set(LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE "" CACHE PATH "Path to prebuilt logos-execution-zone-indexer include.") + +set(HAS_LOGOS_CORE_ROOT FALSE) +set(HAS_LOGOS_EXECUTION_ZONE_INDEXER_ROOT FALSE) +set(HAS_LOGOS_EXECUTION_ZONE_INDEXER_LIB FALSE) +set(HAS_LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE FALSE) + +if (DEFINED LOGOS_CORE_ROOT AND NOT "${LOGOS_CORE_ROOT}" STREQUAL "") + set(HAS_LOGOS_CORE_ROOT TRUE) +endif() + +if (DEFINED LOGOS_EXECUTION_ZONE_INDEXER_ROOT AND NOT "${LOGOS_EXECUTION_ZONE_INDEXER_ROOT}" STREQUAL "") + set(HAS_LOGOS_EXECUTION_ZONE_INDEXER_ROOT TRUE) +endif() + +if(DEFINED LOGOS_EXECUTION_ZONE_INDEXER_LIB AND NOT "${LOGOS_EXECUTION_ZONE_INDEXER_LIB}" STREQUAL "") + set(HAS_LOGOS_EXECUTION_ZONE_INDEXER_LIB TRUE) +endif() + +if(DEFINED LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE AND NOT "${LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE}" STREQUAL "") + set(HAS_LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE TRUE) +endif() + +if (NOT HAS_LOGOS_CORE_ROOT) + message(FATAL_ERROR "LOGOS_CORE_ROOT must be set to the logos-core root directory.") +endif() + +if(HAS_LOGOS_EXECUTION_ZONE_INDEXER_LIB AND HAS_LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE AND NOT HAS_LOGOS_EXECUTION_ZONE_INDEXER_ROOT) + message(STATUS "Using prebuilt logos-execution-zone-indexer.") + set(LOGOS_EXECUTION_ZONE_PREBUILT TRUE) +elseif(NOT HAS_LOGOS_EXECUTION_ZONE_INDEXER_LIB AND NOT HAS_LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE AND HAS_LOGOS_EXECUTION_ZONE_INDEXER_ROOT) + message(STATUS "Building logos-execution-zone-indexer from source.") + set(LOGOS_EXECUTION_ZONE_PREBUILT FALSE) +else() + message(FATAL_ERROR "Either both LOGOS_EXECUTION_ZONE_INDEXER_LIB and LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE must be set for prebuilt logos-execution-zone-indexer, or LOGOS_EXECUTION_ZONE_INDEXER_ROOT must be set to build from source.") +endif() + +# ---- Qt ---- +find_package(Qt6 REQUIRED COMPONENTS Core RemoteObjects) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTORCC ON) + +# ---- Directories ---- +set(WORKSPACE_ROOT "${CMAKE_BINARY_DIR}/workspace") +file(MAKE_DIRECTORY "${WORKSPACE_ROOT}") + +# ---- Logos Core SDK ---- +set(SDK_LIB "${LOGOS_CORE_ROOT}/lib/liblogos_sdk.a") +set(SDK_INC "${LOGOS_CORE_ROOT}/include") + +# ---- OS Specifics ---- +if(APPLE) + set(DYLIB_EXT ".dylib") +elseif(WIN32) + set(DYLIB_EXT ".dll") + set(IMPLIB_EXT ".lib") +else() + set(DYLIB_EXT ".so") +endif() + +# NOTE (Windows): +# Rust cdylib typically produces: +# - logos_blockchain.dll (runtime) +# - logos_blockchain.lib (import lib) +# The Windows build hasn't been yet, so adjust accordingly if the DLL is named without the 'lib' prefix. + +# ---- Logos Blockchain (build OR consume) ---- +if(LOGOS_EXECUTION_ZONE_PREBUILT) + set(LOGOS_EXECUTION_ZONE_DYLIB "${LOGOS_EXECUTION_ZONE_INDEXER_LIB}/libindexer_ffi${DYLIB_EXT}") + + if(WIN32) + set(LOGOS_EXECUTION_ZONE_IMPLIB "${LOGOS_EXECUTION_ZONE_INDEXER_LIB}/indexer_ffi${IMPLIB_EXT}") + endif() + + add_custom_target(logos_execution_zone_libs) + +else() + find_program(CARGO_EXECUTABLE cargo REQUIRED) + + set(CARGO_TARGET_DIR "${WORKSPACE_ROOT}/logos-execution-zone/target") + set(INTERNAL_STAGE "${WORKSPACE_ROOT}/stage") + set(INTERNAL_STAGE_LIB "${INTERNAL_STAGE}/lib") + set(INTERNAL_STAGE_INCLUDE "${INTERNAL_STAGE}/include") + file(MAKE_DIRECTORY "${CARGO_TARGET_DIR}" "${INTERNAL_STAGE_LIB}" "${INTERNAL_STAGE_INCLUDE}") + + set(LOGOS_EXECUTION_ZONE_INDEXER_LIB "${INTERNAL_STAGE_LIB}") + set(LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE "${INTERNAL_STAGE_INCLUDE}") + + set(LOGOS_EXECUTION_ZONE_DYLIB "${INTERNAL_STAGE_LIB}/libindexer_ffi${DYLIB_EXT}") + set(LOGOS_EXECUTION_ZONE_HEADER "${INTERNAL_STAGE_INCLUDE}/indexer_ffi.h") + + add_custom_command( + OUTPUT "${LOGOS_EXECUTION_ZONE_DYLIB}" + COMMAND ${CMAKE_COMMAND} -E env + CARGO_TARGET_DIR=${CARGO_TARGET_DIR} + ${CARGO_EXECUTABLE} build --release + --package indexer-ffi + --manifest-path "${LOGOS_EXECUTION_ZONE_INDEXER_ROOT}/Cargo.toml" + COMMAND ${CMAKE_COMMAND} -E copy + "${CARGO_TARGET_DIR}/release/libindexer_ffi${DYLIB_EXT}" + "${LOGOS_EXECUTION_ZONE_DYLIB}" + DEPENDS "${LOGOS_EXECUTION_ZONE_INDEXER_ROOT}/Cargo.toml" + VERBATIM + ) + + add_custom_command( + OUTPUT "${LOGOS_EXECUTION_ZONE_HEADER}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "${LOGOS_EXECUTION_ZONE_INDEXER_ROOT}/indexer-ffi/indexer_ffi.h" + "${LOGOS_EXECUTION_ZONE_HEADER}" + DEPENDS "${LOGOS_EXECUTION_ZONE_DYLIB}" + VERBATIM + ) + + add_custom_target(logos_execution_zone_libs DEPENDS "${LOGOS_EXECUTION_ZONE_DYLIB}" "${LOGOS_EXECUTION_ZONE_HEADER}") +endif() + +# ---- Imported targets ---- +add_library(logos_execution_zone_indexer SHARED IMPORTED GLOBAL) +set_target_properties(logos_execution_zone_indexer PROPERTIES + IMPORTED_LOCATION "${LOGOS_EXECUTION_ZONE_DYLIB}" + INTERFACE_INCLUDE_DIRECTORIES "${LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE}" +) + +if(NOT LOGOS_EXECUTION_ZONE_PREBUILT) + add_dependencies(logos_execution_zone_indexer logos_execution_zone_libs) +endif() + +if(WIN32) + set_target_properties(logos_execution_zone_indexer PROPERTIES IMPORTED_IMPLIB "${LOGOS_EXECUTION_ZONE_IMPLIB}") +endif() + +add_library(logos_core STATIC IMPORTED + src/i_logos_execution_zone_indexer_module.h) +set_target_properties(logos_core PROPERTIES + IMPORTED_LOCATION "${SDK_LIB}" +) + +add_library(logos_cpp_sdk INTERFACE) +target_include_directories(logos_cpp_sdk INTERFACE "${SDK_INC}") + +# ---- Plugin ---- +set(PLUGIN_TARGET logos_execution_zone_indexer_module) + +qt_add_plugin(${PLUGIN_TARGET} CLASS_NAME LogosExecutionZoneIndexerModule) + +target_sources(${PLUGIN_TARGET} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src/logos_execution_zone_indexer_module.cpp +) + +set_property(TARGET ${PLUGIN_TARGET} PROPERTY PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/src/i_logos_execution_zone_indexer_module.h +) + +target_include_directories(${PLUGIN_TARGET} PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src +) + +target_link_libraries(${PLUGIN_TARGET} PRIVATE + Qt6::Core + Qt6::RemoteObjects + logos_execution_zone_indexer + logos_cpp_sdk + logos_core +) + +target_compile_definitions(${PLUGIN_TARGET} PRIVATE + LOGOS_EXECUTION_ZONE_INDEXER_MODULE_METADATA_FILE="${CMAKE_CURRENT_SOURCE_DIR}/metadata.json" +) + +add_dependencies(${PLUGIN_TARGET} logos_execution_zone_libs) + +if(APPLE) + set_target_properties(${PLUGIN_TARGET} PROPERTIES + BUILD_RPATH "@loader_path" + INSTALL_RPATH "@loader_path" + ) +elseif(UNIX) + set_target_properties(${PLUGIN_TARGET} PROPERTIES + BUILD_RPATH "$ORIGIN" + INSTALL_RPATH "$ORIGIN" + ) +endif() + +# ---- Install ---- +install(TARGETS ${PLUGIN_TARGET} + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + PUBLIC_HEADER DESTINATION include +) +install(DIRECTORY "${LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE}/" DESTINATION include) +install(FILES "${LOGOS_EXECUTION_ZONE_DYLIB}" DESTINATION lib) diff --git a/README .md b/README.md similarity index 100% rename from README .md rename to README.md diff --git a/config/indexer_config.json b/config/indexer_config.json new file mode 100644 index 0000000..e4dd8f9 --- /dev/null +++ b/config/indexer_config.json @@ -0,0 +1,160 @@ +{ + "home": ".", + "consensus_info_polling_interval": "1s", + "bedrock_client_config": { + "addr": "http://localhost:8080", + "backoff": { + "start_delay": "100ms", + "max_retries": 5 + } + }, + "channel_id": "0101010101010101010101010101010101010101010101010101010101010101", + "initial_accounts": [ + { + "account_id": "CbgR6tj5kWx5oziiFptM7jMvrQeYY3Mzaao6ciuhSr2r", + "balance": 10000 + }, + { + "account_id": "2RHZhw9h534Zr3eq2RGhQete2Hh667foECzXPmSkGni2", + "balance": 20000 + } + ], + "initial_commitments": [ + { + "npk": [ + 139, + 19, + 158, + 11, + 155, + 231, + 85, + 206, + 132, + 228, + 220, + 114, + 145, + 89, + 113, + 156, + 238, + 142, + 242, + 74, + 182, + 91, + 43, + 100, + 6, + 190, + 31, + 15, + 31, + 88, + 96, + 204 + ], + "account": { + "program_owner": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "balance": 10000, + "data": [], + "nonce": 0 + } + }, + { + "npk": [ + 173, + 134, + 33, + 223, + 54, + 226, + 10, + 71, + 215, + 254, + 143, + 172, + 24, + 244, + 243, + 208, + 65, + 112, + 118, + 70, + 217, + 240, + 69, + 100, + 129, + 3, + 121, + 25, + 213, + 132, + 42, + 45 + ], + "account": { + "program_owner": [ + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "balance": 20000, + "data": [], + "nonce": 0 + } + } + ], + "signing_key": [ + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37, + 37 + ] +} \ No newline at end of file diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..86e21b7 --- /dev/null +++ b/flake.nix @@ -0,0 +1,149 @@ +{ + description = "Logos Blockchain Module - Qt6 Plugin"; + + inputs = { + nixpkgs.follows = "logos-liblogos/nixpkgs"; + + logos-liblogos.url = "github:logos-co/logos-liblogos"; + logos-core.url = "github:logos-co/logos-cpp-sdk"; + + logos-execution-zone.url = "github:logos-blockchain/logos-execution-zone?ref=Pravdyvy/indexer-ffi-spawns-rpc-for-communication"; + + logos-module-viewer.url = "github:logos-co/logos-module-viewer"; + }; + + outputs = + { + self, + nixpkgs, + logos-core, + logos-execution-zone, + logos-module-viewer, + ... + }: + let + lib = nixpkgs.lib; + + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-windows" + ]; + + forAll = lib.genAttrs systems; + + mkPkgs = system: import nixpkgs { inherit system; }; + in + { + packages = forAll ( + system: + let + pkgs = mkPkgs system; + llvmPkgs = pkgs.llvmPackages; + + logosCore = logos-core.packages.${system}.default; + logosExecutionZoneIndexerPackage = logos-execution-zone.packages.${system}.indexer; + + logosExecutionZoneIndexerModulePackage = pkgs.stdenv.mkDerivation { + pname = "logos-execution-zone-module"; + version = "dev"; + src = ./.; + + nativeBuildInputs = [ + pkgs.cmake + pkgs.ninja + pkgs.pkg-config + pkgs.qt6.wrapQtAppsHook + ]; + + buildInputs = [ + pkgs.qt6.qtbase + pkgs.qt6.qtremoteobjects + pkgs.qt6.qttools + llvmPkgs.clang + llvmPkgs.libclang + logosExecutionZoneIndexerPackage + ] + ++ lib.optionals pkgs.stdenv.isDarwin [ + pkgs.libiconv + pkgs.cacert + ]; + + LIBCLANG_PATH = "${llvmPkgs.libclang.lib}/lib"; + CLANG_PATH = "${llvmPkgs.clang}/bin/clang"; + SSL_CERT_FILE = lib.optionalString pkgs.stdenv.isDarwin "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"; + + cmakeFlags = [ + "-DLOGOS_CORE_ROOT=${logosCore}" + "-DLOGOS_EXECUTION_ZONE_INDEXER_LIB=${logosExecutionZoneIndexerPackage}/lib" + "-DLOGOS_EXECUTION_ZONE_INDEXER_INCLUDE=${logosExecutionZoneIndexerPackage}/include" + ]; + }; + in + { + lib = logosExecutionZoneIndexerModulePackage; + default = logosExecutionZoneIndexerModulePackage; + } + ); + + apps = forAll ( + system: + let + pkgs = mkPkgs system; + logosExecutionZoneIndexerModuleLib = self.packages.${system}.lib; + logosModuleViewerPackage = logos-module-viewer.packages.${system}.default; + extension = if pkgs.stdenv.isDarwin then "dylib" + else if pkgs.stdenv.hostPlatform.isWindows then "dll" + else "so"; + inspectModule = { + type = "app"; + program = + "${pkgs.writeShellScriptBin "inspect-module" '' + exec ${logosModuleViewerPackage}/bin/logos-module-viewer \ + --module ${logosExecutionZoneIndexerModuleLib}/lib/liblogos_execution_zone_indexer_module.${extension} + ''}/bin/inspect-module"; + }; + in + { + inspect-module = inspectModule; + default = inspectModule; + } + ); + + devShells = forAll ( + system: + let + pkgs = mkPkgs system; + pkg = self.packages.${system}.default; + logosCorePackage = logos-core.packages.${system}.default; + logosExecutionZoneIndexerPackage = logos-execution-zone.packages.${system}.indexer; + in + { + default = pkgs.mkShell { + inputsFrom = [ pkg ]; + + inherit (pkg) + LIBCLANG_PATH + CLANG_PATH; + + LOGOS_CORE_ROOT = "${logosCorePackage}"; + LOGOS_EXECUTION_ZONE_INDEXER_LIB = "${logosExecutionZoneIndexerPackage}/lib"; + LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE = "${logosExecutionZoneIndexerPackage}/include"; + + shellHook = '' + BLUE='\e[1;34m' + GREEN='\e[1;32m' + RESET='\e[0m' + + echo -e "\n''${BLUE}=== Logos Execution Zone Module Development Environment ===''${RESET}" + echo -e "''${GREEN}LOGOS_CORE_ROOT:''${RESET} $LOGOS_CORE_ROOT" + echo -e "''${GREEN}LOGOS_EXECUTION_ZONE_INDEXER_LIB:''${RESET} $LOGOS_EXECUTION_ZONE_INDEXER_LIB" + echo -e "''${GREEN}LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE:''${RESET} $LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE" + echo -e "''${BLUE}---------------------------------------------------------''${RESET}" + ''; + }; + } + ); + }; +} diff --git a/justfile b/justfile new file mode 100644 index 0000000..07c1165 --- /dev/null +++ b/justfile @@ -0,0 +1,24 @@ +default: build + +configure: + cmake -S . -B build -G Ninja \ + ${LOGOS_CORE_ROOT:+-DLOGOS_CORE_ROOT="$LOGOS_CORE_ROOT"} \ + ${LOGOS_EXECUTION_ZONE_INDEXER_LIB:+-DLOGOS_EXECUTION_ZONE_INDEXER_LIB="$LOGOS_EXECUTION_ZONE_INDEXER_LIB"} \ + ${LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE:+-DLOGOS_EXECUTION_ZONE_INDEXER_INCLUDE="$LOGOS_EXECUTION_ZONE_INDEXER_INCLUDE"} + +build: configure + cmake --build build --parallel --target logos_execution_zone_indexer_module + +clean: + rm -rf build result + +rebuild: clean build + +nix: + nix develop + +prettify: + nix shell nixpkgs#clang-tools -c clang-format -i src/**.cpp src/**.h + +unicode-logs file: + perl -pe 's/\\u([0-9A-Fa-f]{4})/chr(hex($1))/ge' {{file}} | less -R diff --git a/metadata.json b/metadata.json new file mode 100644 index 0000000..d0ab378 --- /dev/null +++ b/metadata.json @@ -0,0 +1,12 @@ +{ + "name": "liblogos_execution_zone_indexer_module", + "version": "1.0.0", + "description": "Logos Execution Zone Indexer Module for Logos Core", + "author": "Logos Blockchain Team", + "type": "core", + "category": "blockchain", + "main": "liblogos_execution_zone_indexer_module", + "dependencies": [], + "capabilities": [], + "include": ["libnomos.dylib"] +} \ No newline at end of file diff --git a/src/i_logos_execution_zone_indexer_module.h b/src/i_logos_execution_zone_indexer_module.h new file mode 100644 index 0000000..969a5b2 --- /dev/null +++ b/src/i_logos_execution_zone_indexer_module.h @@ -0,0 +1,26 @@ +#ifndef I_LOGOS_EXECUTION_ZONE_INDEXER_MODULE_H +#define I_LOGOS_EXECUTION_ZONE_INDEXER_MODULE_H + +#include + +class ILogosExecutionZoneIndexerModule { +public: + virtual ~ILogosExecutionZoneIndexerModule() = default; + + // === Logos Core === + + virtual void initLogos(LogosAPI* logosApiInstance) = 0; + + // === Logos Execution Zone Indexer === + + // Indexer Lifecycle + virtual int start_indexer( + const QString& config_path, + uint16_t port + ) = 0; +}; + +#define ILogosExecutionZoneIndexerModule_iid "org.logos.ilogosexecutionzoneindexermodule" +Q_DECLARE_INTERFACE(ILogosExecutionZoneIndexerModule, ILogosExecutionZoneIndexerModule_iid) + +#endif diff --git a/src/logos_execution_zone_indexer_module.cpp b/src/logos_execution_zone_indexer_module.cpp new file mode 100644 index 0000000..93215ea --- /dev/null +++ b/src/logos_execution_zone_indexer_module.cpp @@ -0,0 +1,61 @@ +#include "logos_execution_zone_indexer_module.h" + +#include +#include +#include +#include +#include +#include + +LogosExecutionZoneIndexerModule::LogosExecutionZoneIndexerModule() = default; + +LogosExecutionZoneIndexerModule::~LogosExecutionZoneIndexerModule() { + if (indexer_service_ffi) { + operation_result = indexer_ffi::stop_indexer(indexer_service_ffi); + + if (indexer_ffi::is_error(&operation_result)) { + int signal = operation_result; + qWarning() << "destructor: indexer FFI error: " << signal; + } + + indexer_service_ffi = nullptr; + } +} + +// === Plugin Interface === + +QString LogosExecutionZoneIndexerModule::name() const { + return "liblogos_execution_zone_indexer_module"; +} + +QString LogosExecutionZoneIndexerModule::version() const { + return "1.0.0"; +} + +// === Logos Core === + +void LogosExecutionZoneIndexerModule::initLogos(LogosAPI* logosApiInstance) { + logosAPI = logosApiInstance; +} + +// === Indexer Lifecycle === + +int LogosExecutionZoneIndexerModule::start_indexer(const QString& config_path, uint16_t port) { + if !(indexer_service_ffi) { + QByteArray utf8 = config_path.toUtf8(); + const char* c_path = utf8.constData(); + + indexer_service_ffi_res = indexer_ffi::start_indexer(c_path, port); + + if (indexer_ffi::is_error(&indexer_service_ffi_res.error)) { + int signal = indexer_service_ffi_res.error; + qWarning() << "start_indexer: indexer FFI error: " << signal; + + return signal; + } + + indexer_service_ffi = indexer_service_ffi_res.value + + return 0; + } +} diff --git a/src/logos_execution_zone_indexer_module.h b/src/logos_execution_zone_indexer_module.h new file mode 100644 index 0000000..398b2ce --- /dev/null +++ b/src/logos_execution_zone_indexer_module.h @@ -0,0 +1,49 @@ +#ifndef LOGOS_EXECUTION_ZONE_INDEXER_MODULE_H +#define LOGOS_EXECUTION_ZONE_INDEXER_MODULE_H + +#include "i_logos_execution_zone_indexer_module.h" + +#ifdef __cplusplus +extern "C" { +#endif +#include +#ifdef __cplusplus +} +#endif + +#include +#include +#include +#include + +class LogosExecutionZoneIndexerModule : public QObject, public PluginInterface, public ILogosExecutionZoneIndexerModule { + Q_OBJECT + Q_PLUGIN_METADATA(IID ILogosExecutionZoneIndexerModule_iid FILE LOGOS_EXECUTION_ZONE_INDEXER_MODULE_METADATA_FILE) + Q_INTERFACES(PluginInterface ILogosExecutionZoneIndexerModule) + +private: + LogosAPI* logosApi = nullptr; + IndexerServiceFFI* indexer_service_ffi = nullptr; + +public: + LogosExecutionZoneIndexerModule(); + ~LogosExecutionZoneIndexerModule() override; + + // === Plugin Interface === + [[nodiscard]] QString name() const override; + [[nodiscard]] QString version() const override; + + // === Logos Core === + + Q_INVOKABLE void initLogos(LogosAPI* logosApiInstance) override; + + // === Logos Execution Zone Indexer === + + // Indexer Lifecycle + Q_INVOKABLE int start_indexer(const QString& config_path, uint16_t port) override; + +signals: + void eventResponse(const QString& eventName, const QVariantList& data); +}; + +#endif