Adapt to new atb-units

This commit is contained in:
Gerhard Hoffmann 2024-03-25 16:13:26 +01:00
parent f3680754ec
commit 2d8a947cb4
4 changed files with 52 additions and 29 deletions

View File

@ -598,22 +598,22 @@ int PushLocalRepository(char const *local_path, char const *branch_name, char co
static QMap<QString, LocalGitRepository *> localGitRepos;
int32_t GetFileMenuSize(char const *localGitRepo) {
int32_t GetFileMenuSizeInternal(char const *localGitRepo) {
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
return localGitRepos[localGitRepo]->GetFileMenuSize();
return localGitRepos[localGitRepo]->GetFileMenuSizeInternal();
}
char const *GetFileMenu(const char *localGitRepo) {
char const *GetFileMenuInternal(const char *localGitRepo) {
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenu().constData();
QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenuInternal().constData();
if (a.isValidUtf8()) {
int const len = GetFileMenuSize(localGitRepo);
int const len = GetFileMenuSizeInternal(localGitRepo);
if (len > 0) {
char *json = new char [len+1];
// fprintf(stderr, "allocate pointer %p\n", json);
@ -626,8 +626,12 @@ char const *GetFileMenu(const char *localGitRepo) {
}
char const *GetFileName(char const *localGitRepo, char const *fileId) {
QByteArray const &a = localGitRepos[localGitRepo]->GetFileName(fileId);
char const *GetFileNameInternal(char const *localGitRepo, char const *fileId) {
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
QByteArray const &a = localGitRepos[localGitRepo]->GetFileNameInternal(fileId);
if (a.isValidUtf8()) {
char *c = new char[a.size() + 1];
memset(c, 0x00, a.size() + 1);
@ -638,11 +642,19 @@ char const *GetFileName(char const *localGitRepo, char const *fileId) {
}
int32_t GetFileSize(char const *localGitRepo, char const *fileId) {
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
return localGitRepos[localGitRepo]->GetFileSize(fileId);
}
char const *GetFile(char const *localGitRepo, char const *fileId) {
QByteArray const &a = localGitRepos[localGitRepo]->GetFile(fileId);
char const *GetFileInternal(char const *localGitRepo, char const *fileId) {
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
QByteArray const &a = localGitRepos[localGitRepo]->GetFileInternal(fileId);
if (a.isValidUtf8()) {
char *c = new char[a.size() + 1];
memset(c, 0x00, a.size() + 1);
@ -652,6 +664,14 @@ char const *GetFile(char const *localGitRepo, char const *fileId) {
return nullptr;
}
bool SetFileInternal(char const *localGitRepo, char const *fileId, char const *json, int size) {
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
return localGitRepos[localGitRepo]->SetFileInternal(QString(fileId), QByteArray(json, size));
}
void DeleteMem(char *p) {
if (p) {
// fprintf(stderr, "delete pointer %p\n", p);

View File

@ -12,12 +12,13 @@ extern "C" {
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;
char const *GetFileMenuInternal(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT;
int32_t GetFileMenuSizeInternal(char const *localRepo) CALCULATOR_C_INTERFACE_LIB_EXPORT;
char const *GetFileNameInternal(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;
char const *GetFileInternal(char const *localRepo, char const *fileId) CALCULATOR_C_INTERFACE_LIB_EXPORT;
bool SetFileInternal(char const *localRepo, char const *fileId, char const *json, int size) CALCULATOR_C_INTERFACE_LIB_EXPORT;
TariffCalculatorHandle NewTariffCalculator(void) CALCULATOR_C_INTERFACE_LIB_EXPORT;
void DeleteTariffCalculator(TariffCalculatorHandle handle) CALCULATOR_C_INTERFACE_LIB_EXPORT;

View File

@ -15,11 +15,11 @@ LocalGitRepository::LocalGitRepository(QString const &localRepository)
, m_fileMenuSize(-1) {
}
int32_t LocalGitRepository::GetFileMenuSize() const {
int32_t LocalGitRepository::GetFileMenuSizeInternal() const {
return m_fileMenuSize;
}
QByteArray const &LocalGitRepository::GetFileMenu() const {
QByteArray LocalGitRepository::GetFileMenuInternal() {
if (m_fileMenuSize == -1) {
QFile f(QDir::cleanPath(QString(baseDir) + m_localRepository + QDir::separator()
+ "etc/psa_webinterface/menu_config.json"));
@ -37,7 +37,7 @@ QByteArray const &LocalGitRepository::GetFileMenu() const {
return m_fileMenu;
}
QByteArray LocalGitRepository::GetFileName(QString const &fId) {
QByteArray LocalGitRepository::GetFileNameInternal(QString const &fId) {
QRegularExpressionMatch match;
static const QRegularExpression re("(master|[0-9]+)");
if (fId.lastIndexOf(re, -1, &match) != -1) {
@ -64,8 +64,8 @@ QByteArray LocalGitRepository::GetFileName(QString const &fId) {
return QByteArray();
}
QByteArray LocalGitRepository::GetFile(QString const &fId) {
QByteArray a = GetFileName(fId);
QByteArray LocalGitRepository::GetFileInternal(QString const &fId) {
QByteArray a = GetFileNameInternal(fId);
if (a.isValidUtf8()) {
QFile fn(a);
if (fn.exists()) {
@ -79,7 +79,7 @@ QByteArray LocalGitRepository::GetFile(QString const &fId) {
}
int32_t LocalGitRepository::GetFileSize(QString const &fId) {
QByteArray a = GetFileName(fId);
QByteArray a = GetFileNameInternal(fId);
if (a.isValidUtf8()) {
QFile fn(a);
if (fn.exists()) {
@ -89,18 +89,19 @@ int32_t LocalGitRepository::GetFileSize(QString const &fId) {
return -1;
}
bool LocalGitRepository::SetFile(QString const &fId, QByteArray const &json) {
QByteArray a = GetFileName(fId);
bool LocalGitRepository::SetFileInternal(QString const &fId, QByteArray const &json) {
QByteArray a = GetFileNameInternal(fId);
if (a.isValidUtf8()) {
QFile fn(a);
if (fn.exists()) {
if (fn.open(QIODevice::WriteOnly)) {
qint64 bytesWritten = 0;
qint64 bytesToWrite = a.size();
qint64 bytesToWrite = json.size();
while (bytesToWrite > 0 &&
(bytesWritten = fn.write(json.constData(), bytesToWrite)) != -1) {
bytesToWrite -= bytesWritten;
}
fn.flush();
return (bytesToWrite == 0);
}
}

View File

@ -18,13 +18,14 @@ public:
static char const constexpr *baseDir = "H:\\";
QString gitRepository() const { return m_localRepository; }
QByteArray const &GetFileMenu() const;
int32_t GetFileMenuSize() const;
QByteArray GetFileName(QString const &fileId);
int32_t GetFileSize(QString const &fileId);
QByteArray GetFile(QString const &fileId);
QByteArray GetFileMenuInternal();
int32_t GetFileMenuSizeInternal() const;
bool SetFile(QString const &fileId, QByteArray const &json);
QByteArray GetFileNameInternal(QString const &fileId);
int32_t GetFileSize(QString const &fileId);
QByteArray GetFileInternal(QString const &fileId);
bool SetFileInternal(QString const &fileId, QByteArray const &json);
};
#endif // LOCAL_GIT_REPOSITORY_H_INCLUDED