Elaboradar 0.1
Caricamento in corso...
Ricerca in corso...
Nessun risultato

◆ save_acq_time()

bool elaboradar::Assets::save_acq_time ( time_t acq_time = 0)

Save acq_time in $LAST_FILE, comparing it with the previous value.

Parametri
[in]acq_time- Volume acquisition time
Restituisce
false, if acq_time is older than the previous file processed
true, if acq_time is newer, if $LAST_FILE does not exist or if $LAST_FILE is not set.

Definizione alla linea 53 del file assets.cpp.

54{
55 if (acq_time == 0) acq_time = conf_acq_time;
56
57 // If LAST_FILE is not set, return true
58 const char* last_file = getenv("LAST_FILE");
59 if (last_file == NULL)
60 {
61 LOG_INFO("$LAST_FILE not set");
62 return true;
63 }
64
65 bool res = true;
66 uint32_t last_time;
67
68 FILE* fp = fopen(last_file, "r");
69
70 // If the file does not exist, return true
71 if (fp == NULL)
72 {
73 LOG_INFO("$LAST_FILE=%s does not exist", last_file);
74 last_time = 0;
75 goto check;
76 }
77
78 // If the file is empty, return true
79 if (fread(&last_time, 4, 1, fp) != 1)
80 {
81 LOG_INFO("$LAST_FILE=%s cannot be read", last_file);
82 last_time = 0;
83 goto check;
84 }
85
86check:
87 {
88 int diff = acq_time - last_time;
89 LOG_INFO("%s: new acq_time is old %c %d", last_file, diff < 0 ? '-' : '+', abs(diff));
90 }
91
92 if (acq_time <= last_time)
93 res = false;
94
95 if (fp) fclose(fp);
96
97 if ((fp = fopen(last_file, "w")) == NULL)
98 {
99 LOG_WARN("cannot write to %s: %s", last_file, strerror(errno));
100 throw std::runtime_error("cannot (re)create $LAST_FILE");
101 }
102
103 // Fit acq_time in 4 bytes (FIXME: so far so good, until 2036)
104 last_time = acq_time;
105 if (fwrite(&last_time, 4, 1, fp) != 1)
106 {
107 LOG_WARN("cannot write to %s: %s", last_file, strerror(errno));
108 throw std::runtime_error("cannot write to $LAST_FILE");
109 }
110 fclose(fp);
111
112 return res;
113}