This commit is contained in:
Gerhard Hoffmann 2024-03-11 14:27:33 +01:00
parent 590abe538d
commit 3c7b5d0958
7 changed files with 99 additions and 44 deletions

View File

@ -17,10 +17,6 @@ typedef TariffCalculator *TariffCalculatorHandle;
typedef TariffCalculatorHandle (*NewTariffCalculatorFunc)();
typedef void (*DeleteTariffCalculatorFunc)(TariffCalculatorHandle handle);
//extern "C" {
//#include "calculator_c_interface_lib.h"
//bool __declspec(dllimport) initTariffEditor();
//}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
@ -30,6 +26,16 @@ int main(int argc, char *argv[])
//setDebugLevel(LOG_NOTICE);
}
#ifdef __linux__
//TariffCalculatorHandle handle = NewTariffCalculator();
//DeleteTariffCalculator(handle);
if (InitGitLibrary() > 0) {
qCritical() << CloneRepository("https://git.mimbach49.de/GerhardHoffmann/customer_999.git", "/tmp/customer_999");
ShutdownGitLibrary();
}
#else
QLibrary library("C:\\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Release\\CalculatorCInterface\\release\\CalculatorCInterface.dll");
if (library.load()) {
qCritical() << "loaded";
@ -45,11 +51,7 @@ int main(int argc, char *argv[])
d(handle);
}
}
//initTariffEditor();
#endif
return 0; // a.exec();
}

View File

@ -2,6 +2,11 @@ QT+=core
TEMPLATE = lib
DEFINES += CALCULATOR_C_INTERFACE_LIBRARY
QMAKE_CXXFLAGS += -fPIC
unix {
LIBS += -L/usr/lib64 -lgit2
}
# INCLUDEPATH+=$$_PRO_FILE_PWD_/../Utilities/

View File

@ -1,18 +1,49 @@
#include "calculator_c_interface_lib.h"
#include <git2.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
TariffCalculatorHandle CALCULATOR_C_INTERFACE_LIB_EXPORT NewTariffCalculator(void) {
TariffCalculatorHandle NewTariffCalculator(void) {
return new TariffCalculator();
}
void CALCULATOR_C_INTERFACE_LIB_EXPORT DeleteTariffCalculator(TariffCalculatorHandle handle) {
void DeleteTariffCalculator(TariffCalculatorHandle handle) {
delete handle;
}
int InitGitLibrary(void) {
return git_libgit2_init();
}
int ShutdownGitLibrary(void) {
return git_libgit2_shutdown();
}
int CloneRepository(char const *url, char const *local_path) {
git_repository *out;
git_clone_options opts;
int res = 0;
if ((res = git_clone_options_init(&opts, GIT_CLONE_OPTIONS_VERSION)) == 0) {
opts.checkout_branch = "master";
fprintf(stderr, "%s:%d %s %s\n", __func__, __LINE__, url, local_path);
if ((res = git_clone(&out, url, local_path, &opts)) < 0) {
git_error const *error = git_error_last();
fprintf(stderr, "%s:%d error: %s\n", __func__, __LINE__, error->message);
}
} else {
git_error const *error = git_error_last();
fprintf(stderr, "%s:%d error: %s\n", __func__, __LINE__, error->message);
}
return res;
}
#ifdef __cplusplus
}

View File

@ -10,12 +10,19 @@ typedef TariffCalculator *TariffCalculatorHandle;
extern "C" {
#endif
TariffCalculatorHandle CALCULATOR_C_INTERFACE_LIB_EXPORT NewTariffCalculator(void);
void CALCULATOR_C_INTERFACE_LIB_EXPORT DeleteTariffCalculator(TariffCalculatorHandle handle);
TariffCalculatorHandle NewTariffCalculator(void) CALCULATOR_C_INTERFACE_LIB_EXPORT;
void DeleteTariffCalculator(TariffCalculatorHandle handle) CALCULATOR_C_INTERFACE_LIB_EXPORT;
int InitGitLibrary(void) CALCULATOR_C_INTERFACE_LIB_EXPORT;
int ShutdownGitLibrary(void) CALCULATOR_C_INTERFACE_LIB_EXPORT;
int CloneRepository(char const *url, char const *local_path) CALCULATOR_C_INTERFACE_LIB_EXPORT;
void DeleteTariffCalculator(TariffCalculatorHandle handle) CALCULATOR_C_INTERFACE_LIB_EXPORT;
#ifdef __cplusplus
}
#endif
#endif // CALCULATOR_C_INTERFACE_LIB_H_INCLUDED

View File

@ -4,9 +4,20 @@
#include <QtCore/qglobal.h>
#if defined(CALCULATOR_C_INTERFACE_LIBRARY)
#ifdef __linux__
#define CALCULATOR_C_INTERFACE_LIB_EXPORT
#else
#define CALCULATOR_C_INTERFACE_LIB_EXPORT Q_DECL_EXPORT __stdcall
#endif
#else
#ifdef __linux__
#define CALCULATOR_C_INTERFACE_LIB_EXPORT
#else
#define CALCULATOR_C_INTERFACE_LIB_EXPORT Q_DECL_IMPORT __stdcall
#endif
#endif
#endif // CALCULATOR_C_INTERFACE_GLOBAL_H

View File

@ -33,8 +33,6 @@ TariffCalculator::~TariffCalculator() {
}
TariffCalculator::TariffCalculator() {
qCritical() << __func__;
return;
// QByteArray ba = readJson("/opt/ptu5/opt/ATBTariffCalculator/Utilities/tariff.template.json");
//QJsonParseError pe;
@ -46,38 +44,37 @@ TariffCalculator::TariffCalculator() {
//
//}
m_a = QJsonArray();
m_o = QJsonObject();
createJsonValue("Project", "Szeged");
createJsonValue("Version", "1.0.0");
createJsonValue("Date", "01.01.1970");
createJsonValue("Committer", "");
createJsonValue("Info", "");
createJsonValue("Tariffhead");
createJsonValue("Products");
createJsonValue("Accuracy");
createJsonValue("Type");
createJsonValue("Price");
createJsonValue("Config");
createJsonValue("TimeRanges");
createJsonValue("Periods");
createJsonValue("DayConfigs");
createJsonValue("Days");
//createJsonValue("Periods");
//createJsonValue("DayConfigs");
//createJsonValue("Days");
m_jsonDoc.setArray(m_a);
m_jsonDoc.setObject(m_o);
qCritical().noquote() << m_jsonDoc.toJson(QJsonDocument::JsonFormat::Indented);
}
void TariffCalculator::createJsonValue(QString const &key, QString const &value) {
if ((key.compare("Project", Qt::CaseInsensitive) == 0)
|| (key.compare("Version", Qt::CaseInsensitive) == 0)
|| (key.compare("Date", Qt::CaseInsensitive) == 0)
|| (key.compare("Committer", Qt::CaseInsensitive) == 0)
|| (key.compare("Info", Qt::CaseInsensitive) == 0)) {
m_a.push_back(QJsonValue({QPair(key, QJsonValue(value))}));
if (key.compare("Tariffhead", Qt::CaseInsensitive) == 0) {
QJsonObject o({
QPair(QString("Project"), QJsonValue(QString("Szeged"))),
QPair(QString("Version"), QJsonValue(QString("1.0.0"))),
QPair(QString("Date"), QJsonValue("01.01.1970")),
QPair(QString("Committer"), QJsonValue("")),
QPair(QString("Info"), QJsonValue(QString("")))});
m_o.insert(key, o);
} else
if (key.compare("Accuracy", Qt::CaseInsensitive) == 0) {
QJsonObject o({
@ -85,16 +82,14 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
QPair(QString("accuracy_label"), QJsonValue(QString("computation-to-the-minute"))),
QPair(QString("accuracy_value"), QJsonValue(1)),
QPair(QString("comment"), QJsonValue(QString("accuracy of tariff computation is individual minutes")))});
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o))}));
m_o.insert(key, o);
} else
if (key.compare("Type", Qt::CaseInsensitive) == 0) {
QJsonObject o({
QPair(QString("type_id"), QJsonValue(1)),
QPair(QString("type_label"), QJsonValue(QString("uniform-minutes"))),
QPair(QString("comment"), QJsonValue(QString("same price for all minutes")))});
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o))}));
m_o.insert(key, o);
} else
if (key.compare("Price", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
@ -113,7 +108,7 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
a.push_back(o1);
a.push_back(o2);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
m_o.insert(key, a);
} else
if (key.compare("Config", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
@ -147,7 +142,7 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
QPair(QString("MinimalPrice"), QJsonValue(o3)),
QPair(QString("MinimalPrice"), QJsonValue(o4))});
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o5))}));
m_o.insert(key, o5);
} else
if (key.compare("Products", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
@ -165,7 +160,7 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
a.push_back(o1);
a.push_back(o2);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
m_o.insert(key, a);
} else
if (key.compare("TimeRanges", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
@ -219,7 +214,7 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
}
a.push_back(b);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
m_o.insert(key, a);
} else
if (key.compare("Periods", Qt::CaseInsensitive) == 0) {
QJsonObject o1({
@ -266,7 +261,7 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
a.push_back(o5);
a.push_back(o6);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
m_o.insert(key, a);
} else
if (key.compare("DayConfigs", Qt::CaseInsensitive) == 0) {
@ -301,7 +296,7 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
a.push_back(o2);
a.push_back(o4);
m_a.push_back(QJsonObject({QPair(key, QJsonValue(a))}));
m_o.insert(key, a);
} else
if (key.compare("Days", Qt::CaseInsensitive) == 0) {
QJsonArray b;
@ -373,7 +368,8 @@ void TariffCalculator::createJsonValue(QString const &key, QString const &value)
// "day_moveable": false
//}
m_a.push_back(QJsonObject({QPair(key, QJsonValue(o3))}));
//m_a.push_back(QJsonObject({QPair(key, QJsonValue(o3))}));
m_o.insert(key, o3);
}
#if 0

View File

@ -6,9 +6,12 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonObject>
#include <git2.h>
class TariffCalculator {
QJsonArray m_a;
QJsonObject m_o;
QJsonDocument m_jsonDoc;
void createJsonValue(QString const &key, QString const &value = "");
public: