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 TariffCalculatorHandle (*NewTariffCalculatorFunc)();
typedef void (*DeleteTariffCalculatorFunc)(TariffCalculatorHandle handle); typedef void (*DeleteTariffCalculatorFunc)(TariffCalculatorHandle handle);
//extern "C" {
//#include "calculator_c_interface_lib.h"
//bool __declspec(dllimport) initTariffEditor();
//}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
@ -30,6 +26,16 @@ int main(int argc, char *argv[])
//setDebugLevel(LOG_NOTICE); //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"); QLibrary library("C:\\build-ATBTariffCalculator-Desktop_Qt_6_5_0_MinGW_64_bit-Release\\CalculatorCInterface\\release\\CalculatorCInterface.dll");
if (library.load()) { if (library.load()) {
qCritical() << "loaded"; qCritical() << "loaded";
@ -45,11 +51,7 @@ int main(int argc, char *argv[])
d(handle); d(handle);
} }
} }
#endif
//initTariffEditor();
return 0; // a.exec(); return 0; // a.exec();
} }

View File

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

View File

@ -1,18 +1,49 @@
#include "calculator_c_interface_lib.h" #include "calculator_c_interface_lib.h"
#include <git2.h>
#include <stdio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
TariffCalculatorHandle CALCULATOR_C_INTERFACE_LIB_EXPORT NewTariffCalculator(void) { TariffCalculatorHandle NewTariffCalculator(void) {
return new TariffCalculator(); return new TariffCalculator();
} }
void CALCULATOR_C_INTERFACE_LIB_EXPORT DeleteTariffCalculator(TariffCalculatorHandle handle) { void DeleteTariffCalculator(TariffCalculatorHandle handle) {
delete 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 #ifdef __cplusplus
} }

View File

@ -10,12 +10,19 @@ typedef TariffCalculator *TariffCalculatorHandle;
extern "C" { extern "C" {
#endif #endif
TariffCalculatorHandle CALCULATOR_C_INTERFACE_LIB_EXPORT NewTariffCalculator(void); TariffCalculatorHandle NewTariffCalculator(void) CALCULATOR_C_INTERFACE_LIB_EXPORT;
void CALCULATOR_C_INTERFACE_LIB_EXPORT DeleteTariffCalculator(TariffCalculatorHandle handle); 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 #ifdef __cplusplus
} }
#endif #endif
#endif // CALCULATOR_C_INTERFACE_LIB_H_INCLUDED #endif // CALCULATOR_C_INTERFACE_LIB_H_INCLUDED

View File

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

View File

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

View File

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