updated folder scanning code
This commit is contained in:
@@ -13,8 +13,16 @@
|
||||
#include "local_com.h"
|
||||
#include "local_schedule.h"
|
||||
#include "log.h"
|
||||
#include "thread_ctrl.h"
|
||||
#include "settings.h"
|
||||
#include "check_dir.h"
|
||||
int main() {
|
||||
printf("welcome to the jakach security tool main thread\n");
|
||||
load_settings();
|
||||
//start a second thread which will scan for new files
|
||||
std::thread folder_scannner_thread(folder_scanner);
|
||||
//
|
||||
//
|
||||
//main thread:
|
||||
/* watches for notifications on bus
|
||||
* start threads (scans etc); only one at a time may run
|
||||
@@ -29,21 +37,32 @@ int main() {
|
||||
//check for tasks in com
|
||||
//check for scheduled tasks
|
||||
//execute tasks
|
||||
log(LOGLEVEL::WARN,"test","test2",222);
|
||||
printf("check_from_com:%d\n",check_for_com_tasks(MAIN_COM, MAIN_COM_PATH));
|
||||
printf("check_from_task:%d\n", check_for_sched_tasks(SCHED,SCHED_PATH));
|
||||
//call_srv("8.8.8.8","","");
|
||||
auto start = std::chrono::high_resolution_clock::now();
|
||||
// printf("check_from_com:%d\n",check_for_com_tasks(MAIN_COM, MAIN_COM_PATH));
|
||||
// printf("check_from_task:%d\n", check_for_sched_tasks(SCHED,SCHED_PATH));
|
||||
//unlock_task("tsk1"); else it will only be executed once. but this function has to be called at the end of the task. else it will nvr be executed again. this would be bad :(
|
||||
Sleep(1000);
|
||||
|
||||
int queue_size=get_queue_size();
|
||||
for (int i = 0; i < queue_size; i++) {
|
||||
char* queue_entry = new char[300 * 2 + 5];
|
||||
queue_entry[0] = '\0';
|
||||
queue_pop(queue_entry);
|
||||
printf("%s\n", queue_entry);
|
||||
delete[] queue_entry;
|
||||
//start a thread that executes check_scan_dir to scan folders for new files. this thread then should start a ock so only one scanfolder thread runs at a time
|
||||
//Sleep(1000);
|
||||
if (can_run_thread()) {
|
||||
int queue_size = get_queue_size();
|
||||
for (int i = 0; i < queue_size; i++) {
|
||||
char* queue_entry = new char[300 * 2 + 5];
|
||||
queue_entry[0] = '\0';
|
||||
queue_pop(queue_entry);
|
||||
//execute the function which starts the threads
|
||||
// printf("%s\n", queue_entry);
|
||||
start_thread(queue_entry);
|
||||
delete[] queue_entry;
|
||||
}
|
||||
}
|
||||
printf("\n\n\n");
|
||||
//to ensure that the loop takes at least 1 second else it will run too fast nd destroy you CPU :)
|
||||
auto stop = std::chrono::high_resolution_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
|
||||
if (duration.count() < 1000)
|
||||
Sleep(1000 - duration.count());
|
||||
|
||||
// printf("\n\n\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user