diff --git a/Fonction - get_ping_from_temp_log.svg b/Fonction - get_ping_from_temp_log.svg
new file mode 100644
index 0000000..9c31bca
--- /dev/null
+++ b/Fonction - get_ping_from_temp_log.svg
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/Fonction - set_stats_ping.svg b/Fonction - set_stats_ping.svg
new file mode 100644
index 0000000..8ba46c0
--- /dev/null
+++ b/Fonction - set_stats_ping.svg
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/Légende.svg b/Légende.svg
new file mode 100644
index 0000000..865dde8
--- /dev/null
+++ b/Légende.svg
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/Notes.md b/Notes.md
new file mode 100644
index 0000000..282ed4c
--- /dev/null
+++ b/Notes.md
@@ -0,0 +1,42 @@
+Auteurs : Aurélien Amary, Adrien Dick
+
+# TP2 Conplexité cyclomatique
+*Complexité cyclomatique as CC*
+## Calcul du nombre de chemins pour chaque fonction
+### daemon
+- create_daemon ; CC = 4
+- ping_request ; CC = 2
+- send_check ; CC = 3
+- check_keep_working ; CC = 4
+- daemon_work ; CC = 3
+
+### db-sqlite
+- db_connect ; CC = 1
+- db_disconnect ; CC = 1
+- insert_hourly_report ; CC = 1
+
+### ping-report
+- main ; CC = 4
+
+### stats
+- get_ping_from_temp_log ; CC = 15 (voir graphe)
+- write_ping_log ; CC = 4
+- set_stats_ping ; CC = 25 (voir graphe)
+
+### utils
+- write_pid_file ; CC = 2
+- remove_file ; C = 1
+
+## Simplification du code
+*Commentaire "Modif" aux endroits modifiés*
+### get_ping_from_temp_lo
+Factorisation du while en une sous fonction : sub_get_ping_from_temp_log \
+Résultat :
+- get_ping_from_temp_log ; CC = 7
+- sub_get_ping_from_temp_log ; CC = 4
+
+### set_stats_ping
+Factorisation des trois derniers "if" du while en une sous fonction : sub_set_stats_ping \
+Résultat :
+- set_stats_ping ; CC = 9
+- sub_set_stats_ping ; CC = 8
diff --git a/ping-report/src/stats.c b/ping-report/src/stats.c
index 5b343e8..78cdff1 100644
--- a/ping-report/src/stats.c
+++ b/ping-report/src/stats.c
@@ -23,7 +23,6 @@
Ping value as a string or NULL if an error occured
*/
/*@null@*/char* get_ping_from_temp_log(){
-
/* Variables */
FILE* fd = NULL;
char* read_line = NULL;
@@ -67,6 +66,23 @@
return ping; /* NULL */
}
+ sub_get_ping_from_temp_log(&read_line, &n, &fd, ...); //Modif
+
+ /* free allocated memory */
+ regfree(p_reg);
+ free(p_reg);
+ free(pmatch);
+ if(read_line != NULL){
+ free(read_line);
+ }
+
+ (void) fclose(fd);
+
+ /* ping may be null, then it must mean that the ping request was lost */
+ return ping;
+}
+
+void sub_get_ping_from_temp_log(char** read_line, size_t* n, FILE** fd, ...){ //Modif
/* Read file */
while(getline(&read_line,&n,fd) != -1){
@@ -108,21 +124,9 @@
read_line = NULL;
n = 0;
}
-
- /* free allocated memory */
- regfree(p_reg);
- free(p_reg);
- free(pmatch);
- if(read_line != NULL){
- free(read_line);
- }
-
- (void) fclose(fd);
-
- /* ping may be null, then it must mean that the ping request was lost */
- return ping;
}
+
/*
-- write_ping_log --
Desc :
@@ -209,22 +213,7 @@ void set_stats_ping(){
if(ping < 0.1){
/* Ignore null ping */
}else{
- /* Number of ping readed (for mean calculation) */
- nb_ping++;
- /* Max ping */
- if(ping > max){
- max = ping;
- }
- /* Min ping */
- if(ping < min){
- min = ping;
- }
- /* Number of ping above 100 ms */
- if(ping > 100.0){
- nb_high++;
- }
- /* Sum (for mean calculation) */
- sum += ping;
+ sub_set_stats_ping(&nb_ping, &ping, &max, &min, &nb_high, &sum); //Modif
}
}
free(read_line);
@@ -246,4 +235,21 @@ void set_stats_ping(){
}
}
-
+void sub_set_stats_ping(int* nb_ping, double* ping, double* max, double* min, int* nb_high, double* sum){ //Modif
+ /* Number of ping readed (for mean calculation) */
+ *nb_ping++;
+ /* Max ping */
+ if(*ping > m*ax){
+ *max = *ping;
+ }
+ /* Min ping */
+ if(*ping < *min){
+ *min = *ping;
+ }
+ /* Number of ping above 100 ms */
+ if(*ping > 100.0){
+ *nb_high++;
+ }
+ /* Sum (for mean calculation) */
+ *sum += *ping;
+}