diff --git a/Calculator/main.cpp b/Calculator/main.cpp index 820677f..8482f4a 100644 --- a/Calculator/main.cpp +++ b/Calculator/main.cpp @@ -31,11 +31,13 @@ int main(int argc, char *argv[]) //TariffCalculatorHandle handle = NewTariffCalculator(); //DeleteTariffCalculator(handle); - if (InitGitLibrary() > 0) { - qCritical() << CloneRepository("https://git.mimbach49.de/GerhardHoffmann/customer_999.git", "C:\\tmp\\customer_999"); - qCritical() << CheckoutLocalBranch("C:\\tmp\\customer_999", "master"); - ShutdownGitLibrary(); - } + //if (InitGitLibrary() > 0) { + // qCritical() << CloneRepository("https://git.mimbach49.de/GerhardHoffmann/customer_999.git", "C:\\tmp\\customer_999"); + // qCritical() << CheckoutLocalBranch("C:\\tmp\\customer_999", "master"); + // ShutdownGitLibrary(); + // } + + qCritical() << GetFileMenuSize("customer_999"); #else QLibrary library("C:\\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Release\\CalculatorCInterface\\release\\CalculatorCInterface.dll"); if (library.load()) { diff --git a/CalculatorCInterface/CalculatorCInterface.pro b/CalculatorCInterface/CalculatorCInterface.pro index e0a6722..d697ba8 100644 --- a/CalculatorCInterface/CalculatorCInterface.pro +++ b/CalculatorCInterface/CalculatorCInterface.pro @@ -28,12 +28,14 @@ CONFIG += c++20 console SOURCES += \ calculator_c_interface_lib.cpp \ - tariff_calculator.cpp + tariff_calculator.cpp \ + local_git_repository.cpp HEADERS += \ calculator_c_interface_lib.h \ calculator_c_interface_lib_global.h \ - tariff_calculator.h + tariff_calculator.h \ + local_git_repository.h # Default rules for deployment. unix { diff --git a/CalculatorCInterface/calculator_c_interface_lib.cpp b/CalculatorCInterface/calculator_c_interface_lib.cpp index 4708e9e..f1b97ef 100644 --- a/CalculatorCInterface/calculator_c_interface_lib.cpp +++ b/CalculatorCInterface/calculator_c_interface_lib.cpp @@ -5,12 +5,17 @@ #include #include #include +#include +#include +#include +#include #include #include #include #include +#include static QMap customerRepoMap; static std::mutex m; @@ -589,7 +594,67 @@ int PushLocalRepository(char const *local_path, char const *branch_name, char co return error; } +#include +static QMap localGitRepos; + +int32_t GetFileMenuSize(char const *localGitRepo) { + if (localGitRepos.count(localGitRepo) == 0) { + localGitRepos.insert(localGitRepo, + new LocalGitRepository(localGitRepo)); + } + return localGitRepos[localGitRepo]->GetFileMenuSize(); +} + +char const *GetFileMenu(const char *localGitRepo) { + static char j[] = "{}"; + char *json = j; + int const len = GetFileMenuSize(localGitRepo); + if (len > 0) { + json = new char [len+1]; + // fprintf(stderr, "allocate pointer %p\n", json); + memset(json, 0x00, len+1); + QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenu().constData(); + if (a.isValidUtf8()) { + memcpy(json, a.constData(), std::min(len, (int)a.size())); + } + } + return json; +} + + +char const *GetFileName(char const *localGitRepo, char const *fileId) { + QByteArray const &a = localGitRepos[localGitRepo]->GetFileName(fileId); + if (a.isValidUtf8()) { + char *c = new char[a.size() + 1]; + memset(c, 0x00, a.size() + 1); + memcpy(c, a.constData(), a.size()); + return c; + } + return nullptr; +} + +int32_t GetFileSize(char const *localGitRepo, char const *fileId) { + return localGitRepos[localGitRepo]->GetFileSize(fileId); +} + +char const *GetFile(char const *localGitRepo, char const *fileId) { + QByteArray const &a = localGitRepos[localGitRepo]->GetFile(fileId); + if (a.isValidUtf8()) { + char *c = new char[a.size() + 1]; + memset(c, 0x00, a.size() + 1); + memcpy(c, a.constData(), a.size()); + return c; + } + return nullptr; +} + +void DeleteMem(char *p) { + if (p) { + // fprintf(stderr, "delete pointer %p\n", p); + delete p; + } +} #ifdef __cplusplus } diff --git a/CalculatorCInterface/calculator_c_interface_lib.h b/CalculatorCInterface/calculator_c_interface_lib.h index 5df2734..8a1589c 100644 --- a/CalculatorCInterface/calculator_c_interface_lib.h +++ b/CalculatorCInterface/calculator_c_interface_lib.h @@ -1,6 +1,5 @@ #ifndef CALCULATOR_C_INTERFACE_LIB_H_INCLUDED #define CALCULATOR_C_INTERFACE_LIB_H_INCLUDED - #include "calculator_c_interface_lib_global.h" #include "tariff_calculator.h" @@ -10,6 +9,16 @@ typedef TariffCalculator *TariffCalculatorHandle; extern "C" { #endif +void DeleteMem(char *p) CALCULATOR_C_INTERFACE_LIB_EXPORT; + +// interface for menu of webpage +char const *GetFileMenu(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT; +int32_t GetFileMenuSize(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT; +char const *GetFileName(char const *localRepo, char const *fileId) CALCULATOR_C_INTERFACE_LIB_EXPORT; +int32_t GetFileSize(char const *localRepo, char const *fileId) CALCULATOR_C_INTERFACE_LIB_EXPORT; +char const *GetFile(char const *localRepo, char const *fileId) CALCULATOR_C_INTERFACE_LIB_EXPORT; +bool SetFile(char const *localRepo, char const *fileId, char const *json) CALCULATOR_C_INTERFACE_LIB_EXPORT; + TariffCalculatorHandle NewTariffCalculator(void) CALCULATOR_C_INTERFACE_LIB_EXPORT; void DeleteTariffCalculator(TariffCalculatorHandle handle) CALCULATOR_C_INTERFACE_LIB_EXPORT;