From: FrancoisGrondin Date: Tue, 24 Oct 2017 19:56:29 +0000 (-0400) Subject: Main file renamed. X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=869b3a7b64b00c84ddde6435a6024976b04a2d3a;p=yn%2Fyn-odas.git Main file renamed. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 2edfaee..2e1958d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,7 +181,7 @@ target_link_libraries(odas ) add_executable(odascore - demo/main.c + demo/client.c demo/configs.c demo/objects.c demo/parameters.c diff --git a/demo/client.c b/demo/client.c new file mode 100644 index 0000000..be5736d --- /dev/null +++ b/demo/client.c @@ -0,0 +1,291 @@ + + #include + + #include "parameters.h" + #include "configs.h" + #include "objects.h" + #include "threads.h" + #include "profiler.h" + + #include + #include + #include + + // +----------------------------------------------------------+ + // | Variables | + // +----------------------------------------------------------+ + + // +------------------------------------------------------+ + // | Type | + // +------------------------------------------------------+ + + enum processing { + processing_singlethread, + processing_multithread + } type; + + // +------------------------------------------------------+ + // | Getopt | + // +------------------------------------------------------+ + + int c; + char * file_config; + + // +------------------------------------------------------+ + // | Objects | + // +------------------------------------------------------+ + + objects * objs; + aobjects * aobjs; + + // +------------------------------------------------------+ + // | Configurations | + // +------------------------------------------------------+ + + configs * cfgs; + + // +------------------------------------------------------+ + // | Profiler | + // +------------------------------------------------------+ + + profiler * prf; + + // +------------------------------------------------------+ + // | Flag | + // +------------------------------------------------------+ + + char stopProcess; + + // +----------------------------------------------------------+ + // | Signal handler | + // +----------------------------------------------------------+ + + void sighandler(int signum) { + + if (type == processing_singlethread) { + stopProcess = 1; + } + if (type == processing_multithread) { + threads_multiple_stop(aobjs); + } + + } + + // +----------------------------------------------------------+ + // | Main routine | + // +----------------------------------------------------------+ + + int main(int argc, char * argv[]) { + + // +------------------------------------------------------+ + // | Arguments | + // +------------------------------------------------------+ + + file_config = (char *) NULL; + char verbose = 0x00; + + type = processing_multithread; + + while ((c = getopt(argc,argv, "c:hsv")) != -1) { + + switch(c) { + + case 'c': + + file_config = (char *) malloc(sizeof(char) * (strlen(optarg)+1)); + strcpy(file_config, optarg); + + break; + + case 'h': + + printf("+----------------------------------------------------+\n"); + printf("| ODAS (Open embeddeD Audition System) |\n"); + printf("+----------------------------------------------------+\n"); + printf("| Author: Francois Grondin |\n"); + printf("| Email: francois.grondin2@usherbrooke.ca |\n"); + printf("| Website: introlab.3it.usherbrooke.ca |\n"); + printf("| Version: 1.0 |\n"); + printf("+----------------------------------------------------+\n"); + printf("| -c Configuration file (.cfg) |\n"); + printf("| -h Help |\n"); + printf("| -s Process sequentially (no multithread) |\n"); + printf("| -v Verbose |\n"); + printf("+----------------------------------------------------+\n"); + + exit(EXIT_SUCCESS); + + break; + + case 's': + + type = processing_singlethread; + + break; + + case 'v': + + verbose = 0x01; + + break; + + } + + } + + if (file_config == NULL) { + printf("Missing configuration file.\n"); + exit(EXIT_FAILURE); + } + + // +------------------------------------------------------+ + // | Copyright | + // +------------------------------------------------------+ + + if (verbose == 0x01) { + + printf("+--------------------------------------------+\n"); + printf("| ODAS (Open embeddeD Audition System) |\n"); + printf("+--------------------------------------------+\n"); + printf("| Author: Francois Grondin |\n"); + printf("| Email: francois.grondin2@usherbrooke.ca |\n"); + printf("| Website: introlab.3it.usherbrooke.ca |\n"); + printf("| Version: 1.0 |\n"); + printf("+--------------------------------------------+\n"); + + } + + // +------------------------------------------------------+ + // | Single thread | + // +------------------------------------------------------+ + + if (type == processing_singlethread) { + + // +--------------------------------------------------+ + // | Profiler | + // +--------------------------------------------------+ + + prf = profiler_construct(); + + // +--------------------------------------------------+ + // | Configure | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing configurations...... "); fflush(stdout); + + cfgs = configs_construct(file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Construct | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing objects............. "); fflush(stdout); + + objs = objects_construct(cfgs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Processing | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Processing....................... "); fflush(stdout); + + threads_single_open(objs); + stopProcess = 0; + while((threads_single_process(objs, prf) == 0) && (stopProcess == 0)); + threads_single_close(objs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Free memory | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Free memory...................... "); fflush(stdout); + + objects_destroy(objs); + configs_destroy(cfgs); + free((void *) file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Results | + // +--------------------------------------------------+ + + if (verbose == 0x01) profiler_printf(prf); + + profiler_destroy(prf); + + } + + // +------------------------------------------------------+ + // | Multiple threads | + // +------------------------------------------------------+ + + if (type == processing_multithread) { + + // +--------------------------------------------------+ + // | Configure | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing configurations...... "); fflush(stdout); + + cfgs = configs_construct(file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Construct | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Initializing objects............. "); fflush(stdout); + + aobjs = aobjects_construct(cfgs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Launch threads | + // +--------------------------------------------------+ + + signal(SIGINT, sighandler); + + if (verbose == 0x01) printf("| + Launch threads................... "); fflush(stdout); + + threads_multiple_start(aobjs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Wait | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Threads running.................. "); fflush(stdout); + + threads_multiple_join(aobjs); + + if (verbose == 0x01) printf("[Done] |\n"); + + // +--------------------------------------------------+ + // | Free memory | + // +--------------------------------------------------+ + + if (verbose == 0x01) printf("| + Free memory...................... "); fflush(stdout); + + aobjects_destroy(aobjs); + configs_destroy(cfgs); + free((void *) file_config); + + if (verbose == 0x01) printf("[Done] |\n"); + + if (verbose == 0x01) printf("+--------------------------------------------+\n"); + + } + + return 0; + + } diff --git a/demo/main.c b/demo/main.c deleted file mode 100644 index be5736d..0000000 --- a/demo/main.c +++ /dev/null @@ -1,291 +0,0 @@ - - #include - - #include "parameters.h" - #include "configs.h" - #include "objects.h" - #include "threads.h" - #include "profiler.h" - - #include - #include - #include - - // +----------------------------------------------------------+ - // | Variables | - // +----------------------------------------------------------+ - - // +------------------------------------------------------+ - // | Type | - // +------------------------------------------------------+ - - enum processing { - processing_singlethread, - processing_multithread - } type; - - // +------------------------------------------------------+ - // | Getopt | - // +------------------------------------------------------+ - - int c; - char * file_config; - - // +------------------------------------------------------+ - // | Objects | - // +------------------------------------------------------+ - - objects * objs; - aobjects * aobjs; - - // +------------------------------------------------------+ - // | Configurations | - // +------------------------------------------------------+ - - configs * cfgs; - - // +------------------------------------------------------+ - // | Profiler | - // +------------------------------------------------------+ - - profiler * prf; - - // +------------------------------------------------------+ - // | Flag | - // +------------------------------------------------------+ - - char stopProcess; - - // +----------------------------------------------------------+ - // | Signal handler | - // +----------------------------------------------------------+ - - void sighandler(int signum) { - - if (type == processing_singlethread) { - stopProcess = 1; - } - if (type == processing_multithread) { - threads_multiple_stop(aobjs); - } - - } - - // +----------------------------------------------------------+ - // | Main routine | - // +----------------------------------------------------------+ - - int main(int argc, char * argv[]) { - - // +------------------------------------------------------+ - // | Arguments | - // +------------------------------------------------------+ - - file_config = (char *) NULL; - char verbose = 0x00; - - type = processing_multithread; - - while ((c = getopt(argc,argv, "c:hsv")) != -1) { - - switch(c) { - - case 'c': - - file_config = (char *) malloc(sizeof(char) * (strlen(optarg)+1)); - strcpy(file_config, optarg); - - break; - - case 'h': - - printf("+----------------------------------------------------+\n"); - printf("| ODAS (Open embeddeD Audition System) |\n"); - printf("+----------------------------------------------------+\n"); - printf("| Author: Francois Grondin |\n"); - printf("| Email: francois.grondin2@usherbrooke.ca |\n"); - printf("| Website: introlab.3it.usherbrooke.ca |\n"); - printf("| Version: 1.0 |\n"); - printf("+----------------------------------------------------+\n"); - printf("| -c Configuration file (.cfg) |\n"); - printf("| -h Help |\n"); - printf("| -s Process sequentially (no multithread) |\n"); - printf("| -v Verbose |\n"); - printf("+----------------------------------------------------+\n"); - - exit(EXIT_SUCCESS); - - break; - - case 's': - - type = processing_singlethread; - - break; - - case 'v': - - verbose = 0x01; - - break; - - } - - } - - if (file_config == NULL) { - printf("Missing configuration file.\n"); - exit(EXIT_FAILURE); - } - - // +------------------------------------------------------+ - // | Copyright | - // +------------------------------------------------------+ - - if (verbose == 0x01) { - - printf("+--------------------------------------------+\n"); - printf("| ODAS (Open embeddeD Audition System) |\n"); - printf("+--------------------------------------------+\n"); - printf("| Author: Francois Grondin |\n"); - printf("| Email: francois.grondin2@usherbrooke.ca |\n"); - printf("| Website: introlab.3it.usherbrooke.ca |\n"); - printf("| Version: 1.0 |\n"); - printf("+--------------------------------------------+\n"); - - } - - // +------------------------------------------------------+ - // | Single thread | - // +------------------------------------------------------+ - - if (type == processing_singlethread) { - - // +--------------------------------------------------+ - // | Profiler | - // +--------------------------------------------------+ - - prf = profiler_construct(); - - // +--------------------------------------------------+ - // | Configure | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Initializing configurations...... "); fflush(stdout); - - cfgs = configs_construct(file_config); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Construct | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Initializing objects............. "); fflush(stdout); - - objs = objects_construct(cfgs); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Processing | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Processing....................... "); fflush(stdout); - - threads_single_open(objs); - stopProcess = 0; - while((threads_single_process(objs, prf) == 0) && (stopProcess == 0)); - threads_single_close(objs); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Free memory | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Free memory...................... "); fflush(stdout); - - objects_destroy(objs); - configs_destroy(cfgs); - free((void *) file_config); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Results | - // +--------------------------------------------------+ - - if (verbose == 0x01) profiler_printf(prf); - - profiler_destroy(prf); - - } - - // +------------------------------------------------------+ - // | Multiple threads | - // +------------------------------------------------------+ - - if (type == processing_multithread) { - - // +--------------------------------------------------+ - // | Configure | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Initializing configurations...... "); fflush(stdout); - - cfgs = configs_construct(file_config); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Construct | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Initializing objects............. "); fflush(stdout); - - aobjs = aobjects_construct(cfgs); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Launch threads | - // +--------------------------------------------------+ - - signal(SIGINT, sighandler); - - if (verbose == 0x01) printf("| + Launch threads................... "); fflush(stdout); - - threads_multiple_start(aobjs); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Wait | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Threads running.................. "); fflush(stdout); - - threads_multiple_join(aobjs); - - if (verbose == 0x01) printf("[Done] |\n"); - - // +--------------------------------------------------+ - // | Free memory | - // +--------------------------------------------------+ - - if (verbose == 0x01) printf("| + Free memory...................... "); fflush(stdout); - - aobjects_destroy(aobjs); - configs_destroy(cfgs); - free((void *) file_config); - - if (verbose == 0x01) printf("[Done] |\n"); - - if (verbose == 0x01) printf("+--------------------------------------------+\n"); - - } - - return 0; - - }