mirror of
https://github.com/Karaka-Management/oms-OnlineResourceWatcher.git
synced 2026-02-18 00:48:40 +00:00
continue implementation
This commit is contained in:
parent
4bd4bde749
commit
b78eb6c942
|
|
@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.22)
|
||||||
project(OnlineResourceWatcherServerApp VERSION 1.0.0 LANGUAGES CXX)
|
project(OnlineResourceWatcherServerApp VERSION 1.0.0 LANGUAGES CXX)
|
||||||
add_executable(OnlineResourceWatcherServerApp main.cpp)
|
add_executable(OnlineResourceWatcherServerApp main.cpp)
|
||||||
|
|
||||||
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
set(CMAKE_CXX_FLAGS "-march=native -msse2 -mavx -maes")
|
set(CMAKE_CXX_FLAGS "-march=native -msse2 -mavx -maes")
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace Controller {
|
||||||
void printHelp(int argc, char **argv)
|
void printHelp(int argc, char **argv)
|
||||||
{
|
{
|
||||||
printf(" The Online Resource Watcher app developed by jingga checks online or local resources\n");
|
printf(" The Online Resource Watcher app developed by jingga checks online or local resources\n");
|
||||||
printf(" for changes and and informs the user about them.\n\n");
|
printf(" for changes and informs the user about them.\n\n");
|
||||||
printf(" Run: ./App ....\n\n");
|
printf(" Run: ./App ....\n\n");
|
||||||
printf(" -h: Prints the help output\n");
|
printf(" -h: Prints the help output\n");
|
||||||
printf(" -v: Prints the version\n");
|
printf(" -v: Prints the version\n");
|
||||||
|
|
@ -61,12 +61,11 @@ namespace Controller {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Models::Resource **resources;
|
Models::Resource **resources;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int simultaneous = 0;
|
} ThreadData;
|
||||||
} ResourceData;
|
|
||||||
|
|
||||||
void onlineResourceThreaded(void *arg)
|
void onlineResourceThreaded(void *arg)
|
||||||
{
|
{
|
||||||
ResourceData *data = (ResourceData *) arg;
|
ThreadData *data = (ThreadData *) arg;
|
||||||
|
|
||||||
char **urls = (char **) malloc(data->count * sizeof(char *));
|
char **urls = (char **) malloc(data->count * sizeof(char *));
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -75,11 +74,19 @@ namespace Controller {
|
||||||
urls[i] = data->resources[i]->uri;
|
urls[i] = data->resources[i]->uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::FileUtils::file_body *multi = Utils::WebUtils::multi_download(urls, data->count, data->simultaneous);
|
Utils::FileUtils::file_body *multi = Utils::WebUtils::multi_download(
|
||||||
|
urls,
|
||||||
|
data->count,
|
||||||
|
5,
|
||||||
|
0,
|
||||||
|
(ResourceTypes *) {.size = 4, .resources = {"jpg", "png", "gif", "css"}}
|
||||||
|
);
|
||||||
// @todo: flag for downloading resources types (e.g. js, css, img)
|
// @todo: flag for downloading resources types (e.g. js, css, img)
|
||||||
// @todo: limit filesize to abort downloading large files
|
// @todo: limit filesize to abort downloading large files
|
||||||
|
|
||||||
free(urls);
|
if (urls != NULL) {
|
||||||
|
free(urls);
|
||||||
|
}
|
||||||
|
|
||||||
bool hasChanged = false;
|
bool hasChanged = false;
|
||||||
meow_u128 tempHash;
|
meow_u128 tempHash;
|
||||||
|
|
@ -117,8 +124,13 @@ namespace Controller {
|
||||||
Models::free_Resource(data->resources[i]);
|
Models::free_Resource(data->resources[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(data->resources);
|
if (data->resources != NULL) {
|
||||||
free(arg);
|
free(data->resources);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg != NULL) {
|
||||||
|
free(arg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void offlineResourceThreaded(void *arg)
|
void offlineResourceThreaded(void *arg)
|
||||||
|
|
@ -142,12 +154,29 @@ namespace Controller {
|
||||||
resources[i].id = atoll(resourceIdStrings[i]);
|
resources[i].id = atoll(resourceIdStrings[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
free(resourceIdStrings);
|
if (resourceIdStrings != NULL) {
|
||||||
|
free(resourceIdStrings);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// find and load all relevant ids from the database
|
// @todo: limit memory usage by doing this multiple times in a loop with limits;
|
||||||
resources = (Models::Resource *) DataStorage::Database::DataMapperFactory::get(&Models::ResourceMapper)
|
DataStorage::Database::QueryResult results = app->db->query_execute(
|
||||||
->where((char *) "status", (void *) Models::ResourceStatus::RESOURCE_ACTIVE)
|
(char *) "SELECT * from oms.orw_resource WHERE oms.orw_resource_status = 1"
|
||||||
->execute();
|
);
|
||||||
|
|
||||||
|
resources = (Models::Resource *) malloc(results.rows * sizeof(Models::Resource));
|
||||||
|
for (size_t row = 0; row < results.rows; ++row) {
|
||||||
|
resources[row] = {};
|
||||||
|
|
||||||
|
for (i = 0; i < results.columns; ++i) {
|
||||||
|
if (results.results[row * results.columns + i] != NULL) {
|
||||||
|
free(results.results[row * results.columns + i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (results.results != NULL) {
|
||||||
|
free(results.results);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// How many resources are handled in one thread
|
// How many resources are handled in one thread
|
||||||
|
|
@ -174,10 +203,9 @@ namespace Controller {
|
||||||
|
|
||||||
// Handle online resources in batches here:
|
// Handle online resources in batches here:
|
||||||
if (j > 0 && (j == THREAD_SIZE || i + 1 >= idLength)) {
|
if (j > 0 && (j == THREAD_SIZE || i + 1 >= idLength)) {
|
||||||
ResourceData *data = (ResourceData *) malloc(sizeof(ResourceData));
|
ThreadData *data = (ThreadData *) malloc(sizeof(ThreadData));
|
||||||
data->resources = onlineResources;
|
data->resources = onlineResources;
|
||||||
data->count = j;
|
data->count = j;
|
||||||
data->simultaneous = THREAD_SIZE;
|
|
||||||
|
|
||||||
Threads::pool_add_work(app->pool, onlineResourceThreaded, data);
|
Threads::pool_add_work(app->pool, onlineResourceThreaded, data);
|
||||||
|
|
||||||
|
|
@ -189,10 +217,9 @@ namespace Controller {
|
||||||
|
|
||||||
// Handle offline resources in batches here:
|
// Handle offline resources in batches here:
|
||||||
if (k > 0 && (k == THREAD_SIZE || i + 1 >= idLength)) {
|
if (k > 0 && (k == THREAD_SIZE || i + 1 >= idLength)) {
|
||||||
ResourceData *data = (ResourceData *) malloc(sizeof(ResourceData));
|
ThreadData *data = (ThreadData *) malloc(sizeof(ThreadData));
|
||||||
data->resources = offlineResources;
|
data->resources = offlineResources;
|
||||||
data->count = k;
|
data->count = k;
|
||||||
data->simultaneous = THREAD_SIZE;
|
|
||||||
|
|
||||||
Threads::pool_add_work(app->pool, offlineResourceThreaded, data);
|
Threads::pool_add_work(app->pool, offlineResourceThreaded, data);
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
2
server/bin/cmake_install.cmake
Executable file → Normal file
2
server/bin/cmake_install.cmake
Executable file → Normal file
|
|
@ -12,7 +12,7 @@ if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
|
||||||
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
|
||||||
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
|
||||||
else()
|
else()
|
||||||
set(CMAKE_INSTALL_CONFIG_NAME "")
|
set(CMAKE_INSTALL_CONFIG_NAME "Debug")
|
||||||
endif()
|
endif()
|
||||||
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,14 @@
|
||||||
"id": "frontend",
|
"id": "frontend",
|
||||||
"lang": "en"
|
"lang": "en"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"threads": {
|
||||||
|
"count": 5
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"online": {
|
||||||
|
"donwloads": 10
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"language": [
|
"language": [
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit bc465ff0a8ea45ccb42b06fb7edb050bfa523791
|
Subproject commit 24068a973461f7d5aecfce6fb4feb3d382ba7140
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "cOMS/Utils/ApplicationUtils.h"
|
#include "cOMS/Utils/ApplicationUtils.h"
|
||||||
#include "cOMS/DataStorage/Database/Connection/ConnectionAbstract.h"
|
#include "cOMS/DataStorage/Database/Connection/ConnectionAbstract.h"
|
||||||
|
|
@ -18,6 +19,7 @@
|
||||||
#include "cOMS/Router/Router.h"
|
#include "cOMS/Router/Router.h"
|
||||||
#include "cOMS/Threads/Thread.h"
|
#include "cOMS/Threads/Thread.h"
|
||||||
#include "cOMS/Application/ApplicationAbstract.h"
|
#include "cOMS/Application/ApplicationAbstract.h"
|
||||||
|
#include "Models/ResourceMapper.h"
|
||||||
|
|
||||||
#include "Routes.h"
|
#include "Routes.h"
|
||||||
|
|
||||||
|
|
@ -101,6 +103,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
Threads::pool_destroy(app.pool);
|
Threads::pool_destroy(app.pool);
|
||||||
|
|
||||||
|
DataStorage::Database::free_MapperData((DataStorage::Database::MapperData *) &Models::ResourceMapper);
|
||||||
|
|
||||||
app.db->close();
|
app.db->close();
|
||||||
app.db = NULL;
|
app.db = NULL;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user