Branch
Hash :
94046104
Author :
Thomas de Grivel
Date :
2020-02-24T15:19:27
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
#include <pw13/pw13.h>
#include"../common/type_message.h"
#include"protocole_server.h"
#include"../client/tcp.h"
#include"../common/fct_racc.h"
#include"perf.h"
pw13_list liste_patch;
pw13_list liste_patch_local;
/* FICHIER A ENLEVER DE LA SVN A PRIORI IL SERT A RIEN */
/* remove avec une recherche en itératif + adresses du pére->suiv, ptet caster le list->elem avec (s_succ_pred*) */
void remove_patch_from_list(pw13_list list_patch,pw13_patch p)
{
pw13_list liste;
pw13_list * pere_suiv;
while( liste && ( liste->elem != p ) ){
pere_suiv = &liste->suiv;
liste = liste->suiv;
}
if (!list){
pere_suiv = &liste->suiv;
free(list);
}
}
pw13_list seek_from_list(pw13_list liste, ,pw13_patch p)
{
if(liste)
{
s_succ_pred *e = (s_succ_pred*) liste->elem;
if((e->patch) == p)
{
return(liste);
}
else
seek_from_list(liste->suiv,p);
}
return(NULL);
}
void edit_patch_from_list(pw13_list list_patch,s_succ_pred* s_patch)
{
pw13_list liste;
liste = seek_from_list(list_patch, s_patch->patch);
liste->elem = s_patch;
}
/*/////////////////////////////////////////
/ Gestion des messages reseau cote server /
/////////////////////////////////////////*/
int message_reseau(pw13_patchwork pw,
int * sockfd)
{
waitsock_data (sockfd,sizeof (int));
int num;
recv(*sockfd,&num, sizeof(num),0);
switch(num)
{
case PW13_CREATE_PATCH :
{
pw13_patch s_patch;
pw13_cluster_create_patch s;
s_succ_pred l;
waitsock_data (sockfd,sizeof (pw13_cluster_create_patch));
recv (*sockfd,&s, sizeof (s),0);
s_patch=pw13_patch_of_classpath(pw,
s.classpath,
s.name
);
l.patch=s_patch;
l.succ=NULL;
l.pred=NULL;
pw13_list_insert_tail(&liste_patch,&l);
}
case PW13_DESTROY_PATCH :
{
pw13_cluster_destroy_patch s;
waitsock_data (sockfd,sizeof (pw13_cluster_destroy_patch));
recv (*sockfd,&s, sizeof (s),0);
remove_patch_from_list(liste_patch, s.patch);
pw13_patch_destroy(s.patch);
}
case PW13_CONNECT_PATCH_LOCAL :
{
pw13_cluster_connect_local s;
pw13_list l;
s_output_liste_local ol;
s_input_liste_local il;
waitsock_data (sockfd,sizeof (pw13_cluster_connect_local));
recv (*sockfd,&s, sizeof (s),0);
if (!(PW13_SUCCESS==
pw13_pw_connect (
s.source,
s.output_id,
s.dest,
s.input_id
)
))
return(0);
/* remplir ol et il */
l=seek_from_list(liste_patch_local,s.source);
s_succ_pred *e = (s_succ_pred*) l->elem;
pw13_list_insert_tail (&(e->succ), &ol);
pw13_list_insert_tail (&(e->pred), &il);
}
case PW13_CONNECT_PATCH_DISTANT :
{
pw13_cluster_connect_distant s;
int* sock_nb;
int bind_patch_input=PW13_BIND_PATCH_INPUT;
pw13_list l;
s_succ_pred *e = (s_succ_pred*) l->elem;
s_output_liste ol;
waitsock_data (sockfd,sizeof (pw13_cluster_connect_distant));
recv (*sockfd,&s, sizeof (s),0);
sock_nb=TCPinterpatch(s.dest_serv);
ol.o=s.output_id;
ol.socket=sock_nb;
l=(seek_from_list(liste_patch,s.source));
pw13_list_insert_tail(&(e->succ),&ol);
edit_patch_from_list(liste_patch,e);
TCPsend(sock_nb,&bind_patch_input,sizeof(int));
TCPsend(sock_nb,&s.input_id,sizeof(s.input_id));
}
case PW13_BIND_PATCH_INPUT :
{
pw13_cluster_bind_patch_input s;
pw13_list l;
s_succ_pred *e = (s_succ_pred*) l->elem;
s_input_liste il;
waitsock_data (sockfd,sizeof (pw13_cluster_bind_patch_input));
recv (*sockfd,&s, sizeof (s),0);
il.i=s.input_id;
il.socket=sockfd;
l=seek_from_list(liste_patch,s.dest);
pw13_list_insert_tail(&(e->succ),&il);
edit_patch_from_list(liste_patch,e);
}
default : return(0);
}
return 0;
}