]> gitweb.hhaalo.de Git - sane-kds-s2000w-net.git/commitdiff
set heart beat not under two seconds
authorBastian Dehn <hhaalo@arcor.de>
Sat, 20 Apr 2024 07:43:07 +0000 (09:43 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sat, 20 Apr 2024 07:43:07 +0000 (09:43 +0200)
src/kds_s2000w_config.c
src/kds_s2000w_heartbeat.c
src/kds_s2000w_net.conf
tests/kds_s2000w_read_config_tests.c
tests/kds_s2000w_read_config_tests.h
tests/kds_s2000w_read_config_tests_run.c

index 46f497dbbff1f59defb238ab04fa4e00246afd11..9808f0a8cc587b7d1c4b119d521a1a6b314b2010 100644 (file)
@@ -42,14 +42,13 @@ void load_config(program_config* config, const char* config_stream)
        char* value_str = NULL;
        size_t str_length = 0;
 
-       if (strlen(config_stream) <= 0) {
+       if (strlen(config_stream) <= 0)
                return;
-       }
 
        cfg_opt_t opts[] = {
                CFG_STR("username", "", CFGF_NONE),
                CFG_STR("scanner_url", "", CFGF_NONE),
-               CFG_INT("heartbeat_seconds", 2, CFGF_NONE),
+               CFG_INT("heartbeat_seconds", 0, CFGF_NONE),
                CFG_END()
        };
 
@@ -69,6 +68,9 @@ void load_config(program_config* config, const char* config_stream)
 
        config->heartbeat = cfg_getint(cfg, "heartbeat_seconds");
 
+       if (config->heartbeat < 2)
+               config->heartbeat = 2;
+
        cfg_free(cfg);
        cfg = NULL;
 }
\ No newline at end of file
index 80b2ee754a9bdc3c490b27cdc49dc81149308ee6..1dd7c28d6e78e3969ae7957e85fe4d6280ff39a6 100644 (file)
@@ -4,28 +4,15 @@
 #include "kds_s2000w_config.h"
 #include "kds_s2000w_heartbeat.h"
 
-program_config heartbeat_config;
+extern program_config p_config;
 pthread_t pwait;
 
 void* _wait_thread(void *args)
 {
-       sleep(heartbeat_config.heartbeat);
+       sleep(p_config.heartbeat);
        return NULL;
 }
 
-void _load_config()
-{
-       if (heartbeat_config.heartbeat != 0)
-               return;
-
-       const char* config_file = CONFIG_FILE;
-       char* config_stream = read_config_file(config_file);
-       if (config_stream == NULL)
-               return;
-
-       load_config(&heartbeat_config, config_stream);
-}
-
 void join_thread()
 {
        pthread_join(pwait, NULL);
@@ -33,6 +20,5 @@ void join_thread()
 
 void wait_a_second()
 {
-       _load_config();
        pthread_create(&pwait, NULL, _wait_thread, NULL);
 }
\ No newline at end of file
index f4a0fcd089c57705427b1881c52a5a60d292f543..96c8e3c120c61879fdc2a8537f788704eb5f8e16 100644 (file)
@@ -1,3 +1,4 @@
 scanner_url = "https://scanner.example.com"
 username = "muster"
-heartbeat_seconds = 2
\ No newline at end of file
+# Scanner heart beat is by default 2 seconds before check next scan status,
+# heartbeat_seconds = 2
\ No newline at end of file
index fe6e64276f3c871220d4ab904851832278fe7dc4..34c2f6c722fab02fa20a2099977abb4b05099a48 100644 (file)
@@ -114,6 +114,23 @@ void kds_s200w_config_default_heartbeat_five_seconds()
 
        assert_int_equal(config->heartbeat, 5);
 
+       free(config->scanner_url);
+       config->scanner_url = NULL;
+       free(config->username);
+       config->username = NULL;
+       free(config);
+       config = NULL;
+}
+
+void kds_s200w_config_default_heartbeat_zero_set_default()
+{
+       const char* input_stream = "heartbeat_seconds = 0\n";
+
+       program_config* config = malloc(sizeof(program_config));
+       load_config(config, input_stream);
+
+       assert_int_equal(config->heartbeat, 2);
+
        free(config->scanner_url);
        config->scanner_url = NULL;
        free(config->username);
index cfaf759731341bf1d6b1605e49c012fed01263da..ae5e0f8c3f6a245dc117332df7fc6ee79b3ac609 100644 (file)
@@ -12,5 +12,6 @@ void kds_s2000w_config_multiple_parameters();
 void kds_s2000w_config_read_empty_config();
 void kds_s200w_config_default_heartbeat();
 void kds_s200w_config_default_heartbeat_five_seconds();
+void kds_s200w_config_default_heartbeat_zero_set_default();
 
 #endif
\ No newline at end of file
index 5a213ce2790e2e6887cb32c86368a0c3222d0f33..e26b9d5d12c90803531e2f0c838f1591e5e44884 100644 (file)
@@ -8,7 +8,8 @@ int main()
                cmocka_unit_test(kds_s2000w_config_multiple_parameters),
                cmocka_unit_test(kds_s2000w_config_read_empty_config),
                cmocka_unit_test(kds_s200w_config_default_heartbeat),
-               cmocka_unit_test(kds_s200w_config_default_heartbeat_five_seconds)
+               cmocka_unit_test(kds_s200w_config_default_heartbeat_five_seconds),
+               cmocka_unit_test(kds_s200w_config_default_heartbeat_zero_set_default)
        };
 
        return cmocka_run_group_tests(read_config, NULL, NULL);