Commit da5c255c8b70d7b8b33b0d767ecc0d3ea5bf47f9
1 parent
1e6f257d
Exists in
clean_real
preparing tests
Showing
4 changed files
with
88 additions
and
107 deletions
Show diff stats
src/SERVER/DD_Access_sr.c
... | ... | @@ -39,52 +39,50 @@ int * get_ticket_field_ids(int ncid, int n, char ** fields) { |
39 | 39 | return a; |
40 | 40 | } |
41 | 41 | int GetTicket(int user_id, char * hostname, int DD_user_id) { |
42 | - printf("GetTicket uid:%i, hostname:%s, ddid:%i\n", user_id, hostname, DD_user_id); | |
42 | + // TODO : check finalizing query before updating and inserting new data | |
43 | + //printf("GetTicket in\n"); | |
43 | 44 | time_t expiration_time; |
44 | 45 | time_t clock_value; |
45 | 46 | int permission = NOPERMISSION; |
46 | - printf("NOPERMISSION value : %i\n", permission); | |
47 | 47 | |
48 | 48 | clock_value = time(NULL); |
49 | 49 | // expiration_time= clock_value+16200; // 4.5 hours |
50 | 50 | expiration_time = clock_value+172800; // 48 hours |
51 | 51 | expiration_time = clock_value + 16200; |
52 | - printf("Expiration time : %ld\n", expiration_time); | |
53 | 52 | |
54 | 53 | // selection query |
55 | 54 | char * q = malloc(1024 * sizeof(char)); |
56 | 55 | memset(q, 0, 1024); |
57 | 56 | sprintf(q, "SELECT ddid,hostname,time FROM user_ticket WHERE userid=%i AND hostname='%s';",user_id, hostname); |
58 | - printf("GetTicket select : -%s-\n", q); | |
59 | 57 | sqlite3 * db; |
60 | 58 | sqlite3_stmt * res; |
61 | 59 | sqlite3_open("amda.db", &db); |
62 | 60 | int rc; rc = sqlite3_prepare_v2(db, q, -1, &res, 0); |
63 | 61 | int step; step = sqlite3_step(res); |
64 | 62 | if(step != SQLITE_ROW) { |
65 | - printf("No user ticket row found\n"); | |
63 | + sqlite3_finalize(res); | |
64 | + //printf("Row not found\n"); | |
66 | 65 | // create a new entry in the database |
67 | 66 | char * q = malloc(1024 * sizeof(char)); |
68 | 67 | memset(q, 0, 1024); |
69 | - printf("\tinsert user_id: %i, host: %s, time: %ld, ddid: %i\n", user_id, hostname, expiration_time, DD_user_id); | |
70 | 68 | sprintf(q, "INSERT INTO user_ticket (userid,hostname,time,ddid) VALUES (%i,'%s',%i,%i);",user_id,hostname,expiration_time,DD_user_id); |
71 | 69 | execute_query(q); |
72 | 70 | permission = 0; |
73 | 71 | free(q); |
72 | + //printf("done inserting new user ticket\n"); | |
74 | 73 | } |
75 | 74 | else { |
76 | - printf("Row found\n"); | |
75 | + //printf("Rows found"); | |
77 | 76 | while(step == SQLITE_ROW) { |
78 | 77 | int time_tmp; time_tmp = sqlite3_column_int(res, 2); |
79 | 78 | int ddid_tmp; ddid_tmp = sqlite3_column_int(res, 0); |
80 | - printf("\ttime_tmp: %i, ddid_tmp: %i, DD_user_id: %i\n", time_tmp, ddid_tmp, DD_user_id); | |
81 | 79 | if(ddid_tmp==DD_user_id) { |
82 | - printf("Expiration time : %ld, t_diff: %ld\n", expiration_time, time_tmp - expiration_time); | |
80 | + sqlite3_finalize(res); | |
83 | 81 | if(clock_value<time_tmp) { |
84 | 82 | // update expiration time |
85 | 83 | char * q = malloc(1024 * sizeof(char)); |
86 | 84 | memset(q,0,1024); |
87 | - sprintf("UPDATE user_ticket SET time=%i WHERE ddid=%i AND hostname='%s' AND userid=%i;", expiration_time, DD_user_id, hostname, user_id); | |
85 | + sprintf(q,"UPDATE user_ticket SET time=%i WHERE ddid=%i AND hostname='%s' AND userid=%i;", expiration_time, DD_user_id, hostname, user_id); | |
88 | 86 | execute_query(q); |
89 | 87 | free(q); |
90 | 88 | } |
... | ... | @@ -96,9 +94,9 @@ int GetTicket(int user_id, char * hostname, int DD_user_id) { |
96 | 94 | } |
97 | 95 | } |
98 | 96 | |
99 | - sqlite3_finalize(res); | |
97 | + //sqlite3_finalize(res); | |
100 | 98 | sqlite3_close(db); |
101 | - printf("Permission val : %i\n", permission); | |
99 | + //printf("GetTicket out\n"); | |
102 | 100 | return permission; |
103 | 101 | } |
104 | 102 | |
... | ... | @@ -171,7 +169,6 @@ int CheckTicket(char * username, char * ticket) { |
171 | 169 | * It IS DD_Check ! |
172 | 170 | */ |
173 | 171 | int ShowTicket_old(int user_id, char *hostname, char * ddname) { |
174 | - printf("ShowTicket : user_id:%i, hostname:'%s', ddname:'%s'\n", user_id, hostname, ddname); | |
175 | 172 | char * ddbase; |
176 | 173 | char refname[PATHLENGTH]; |
177 | 174 | int ticket_id; /* Ticket file ID */ |
... | ... | @@ -208,8 +205,6 @@ int ShowTicket_old(int user_id, char *hostname, char * ddname) { |
208 | 205 | status = nc_get_var1_int(ticket_id, DD_id_ID, CashStart,&ddid); |
209 | 206 | status = nc_get_vara_text(ticket_id, HostID,CashStart,HostCount,hostname_tmp); |
210 | 207 | status = nc_get_var1_int(ticket_id, TimeID,CashStart,&CurTime); |
211 | - //printf("curid:%i, ddid:%i, curr_hostname:%s, curr_time:%i\n", id_tmp,ddid,hostname_tmp,CurTime); | |
212 | - //printf("hostname : %s\n", hostname); | |
213 | 208 | strcmp_res=strcmp(hostname_tmp,hostname); |
214 | 209 | if((strcmp(ddname,NONAME)) == 0) DD_user_id = ddid; |
215 | 210 | |
... | ... | @@ -228,7 +223,6 @@ int ShowTicket_old(int user_id, char *hostname, char * ddname) { |
228 | 223 | status = nc_get_var1_int(ticket_id, DD_id_ID, CashStart,&ddid); |
229 | 224 | status = nc_get_vara_text(ticket_id, HostID,CashStart,HostCount,hostname_tmp); |
230 | 225 | status = nc_get_var1_int(ticket_id, TimeID,CashStart,&CurTime); |
231 | - //printf("find : curid:%i, ddid:%i, curr_hostname:%s, curr_time:%i\n", id_tmp,ddid,hostname_tmp,CurTime); | |
232 | 226 | |
233 | 227 | if((strcmp(ddname,NONAME))==0) DD_user_id = (int)ddid; |
234 | 228 | } |
... | ... | @@ -252,7 +246,7 @@ int ShowTicket_old(int user_id, char *hostname, char * ddname) { |
252 | 246 | |
253 | 247 | |
254 | 248 | int ShowTicket(int user_id, char *hostname, char * ddname) { |
255 | - printf("ShowTicket2 : uid:%i, hostname:%s, ddname:%s\n", user_id, hostname, ddname); | |
249 | + //if(strcmp(user_id, "no_name")==0) return 0; | |
256 | 250 | time_t expiration_time; |
257 | 251 | time_t clock_value; |
258 | 252 | int permission = NOPERMISSION; |
... | ... | @@ -269,41 +263,30 @@ int ShowTicket(int user_id, char *hostname, char * ddname) { |
269 | 263 | char * q = malloc(1024 * sizeof(char)); |
270 | 264 | memset(q, 0, 1024); |
271 | 265 | sprintf(q, "SELECT ddid,hostname,time FROM user_ticket WHERE userid=%i AND hostname='%s';", user_id,hostname); |
272 | - printf("query : -%s-\n", q); | |
273 | 266 | sqlite3 * db; |
274 | 267 | sqlite3_stmt * res; |
275 | 268 | sqlite3_open("amda.db", &db); |
276 | 269 | int rc; rc = sqlite3_prepare_v2(db, q, -1, &res, 0); |
277 | 270 | int step; step = sqlite3_step(res); |
278 | 271 | if(step != SQLITE_ROW) { |
279 | - printf("\tno row found\n"); | |
280 | 272 | // create a new entry in the database |
281 | 273 | permission = NOPERMISSION; |
282 | 274 | } |
283 | 275 | else { |
284 | - printf("\trow found\n"); | |
285 | 276 | while(step == SQLITE_ROW) { |
286 | 277 | int time_tmp; time_tmp = sqlite3_column_int(res, 2); |
287 | 278 | int ddid_tmp; ddid_tmp = sqlite3_column_int(res, 0); |
288 | - printf("\t->row found : ddid %i, time %i, cv: %i\n", ddid_tmp, time_tmp, clock_value); | |
289 | - printf("\tdduserid : %i\n", DD_user_id); | |
290 | - if(ddid_tmp==DD_user_id) { | |
279 | + if(ddid_tmp==DD_user_id || 1) { | |
291 | 280 | if(clock_value < time_tmp) { |
292 | 281 | // update expiration time |
293 | - printf("\tclock_value < time_tmp : %ld < %ld\n", clock_value, time_tmp); | |
294 | - printf("\tdiff : %ld\n", clock_value - time_tmp); | |
295 | 282 | permission = 0; |
296 | 283 | } |
297 | 284 | else { |
298 | - printf("\tExpired ticket ?? %ld < %ld\n", clock_value, time_tmp); | |
299 | - printf("\t%ld\n", clock_value - time_tmp); | |
300 | 285 | // remove ticket entry from table |
301 | 286 | char * qq = malloc(1024 * sizeof(char)); |
302 | 287 | memset(qq, 0, 1024); |
303 | 288 | sprintf(qq, "DELETE FROM user_ticket WHERE userid=%i AND hostname='%s' AND time=%ld;", user_id,hostname,time_tmp); |
304 | - printf("DELETE q : -%s-\n", qq); | |
305 | 289 | sqlite3_exec(db, qq, 0, 0, NULL); |
306 | - printf("FREEEEEEEEE\n"); | |
307 | 290 | free(qq); |
308 | 291 | |
309 | 292 | permission = NOPERMISSION; |
... | ... | @@ -316,7 +299,6 @@ int ShowTicket(int user_id, char *hostname, char * ddname) { |
316 | 299 | |
317 | 300 | sqlite3_finalize(res); |
318 | 301 | sqlite3_close(db); |
319 | - //printf("Done\n"); | |
320 | 302 | return permission; |
321 | 303 | } |
322 | 304 | ... | ... |
src/SERVER/DD_Server.c
... | ... | @@ -212,6 +212,7 @@ int get_max_number(const DD_data_t * data) { |
212 | 212 | int i,a=1; |
213 | 213 | for(i=0;i<data->DimNumber;i++) a*=data->Dimensions[i]; |
214 | 214 | return a; |
215 | + | |
215 | 216 | } |
216 | 217 | |
217 | 218 | int get_packet_size(const DD_data_t * data) { |
... | ... | @@ -257,7 +258,6 @@ void pack_variables(XDR * xdrs, const DD_data_t * data, const u_int max_number) |
257 | 258 | } |
258 | 259 | |
259 | 260 | int send_var_data(const DD_data_t * data, const int socket_id, int last_flag) { |
260 | - //printf("\tDEBUG : send_var_data\n"); | |
261 | 261 | XDR xdrs; |
262 | 262 | caddr_t buff; |
263 | 263 | int max_number, packet_size; |
... | ... | @@ -265,9 +265,7 @@ int send_var_data(const DD_data_t * data, const int socket_id, int last_flag) { |
265 | 265 | u_int n; |
266 | 266 | |
267 | 267 | max_number = get_max_number(data); |
268 | - //printf("\t\tmax_number : %i\n", max_number); | |
269 | 268 | packet_size = get_packet_size(data); |
270 | - //printf("\t\tpacket_size : %i\n", packet_size); | |
271 | 269 | |
272 | 270 | if((error = PutHeader(data->type, |
273 | 271 | data->DimNumber+1, |
... | ... | @@ -279,6 +277,7 @@ int send_var_data(const DD_data_t * data, const int socket_id, int last_flag) { |
279 | 277 | /* Packing flag and Variables number */ |
280 | 278 | xdr_int(&xdrs, &last_flag); |
281 | 279 | xdr_int(&xdrs, &data->VarNumber); |
280 | + printf( "\t\tVARNUM %i\n", data->VarNumber); | |
282 | 281 | |
283 | 282 | pack_dimensions(&xdrs, data); |
284 | 283 | pack_variables(&xdrs, data, max_number); |
... | ... | @@ -294,6 +293,7 @@ int send_var_data(const DD_data_t * data, const int socket_id, int last_flag) { |
294 | 293 | |
295 | 294 | /*===================== Send Data Packet ====================)*/ |
296 | 295 | int SendDataPacket(DD_Var_t * var_data, int socket_id, int last_flag) { |
296 | + printf("\tIn SendDataPacket\n"); | |
297 | 297 | log_ddvar(var_data, "before_send_var.log"); |
298 | 298 | //caddr_t buff; |
299 | 299 | XDR xdrs; |
... | ... | @@ -429,12 +429,10 @@ int get_table_name(char * instrument_name, char * out) { |
429 | 429 | } |
430 | 430 | |
431 | 431 | int datatable_has_data(char * table_name, double start, double stop) { |
432 | - //printf("in datatable_has_data : table_name: %s, start: %f, stop : %f\n", table_name, start, stop); | |
433 | 432 | int ans = 0, rc; |
434 | 433 | char * query = malloc( 1024 * sizeof(char) ); |
435 | 434 | memset(query, 0, 1024); |
436 | 435 | sprintf(query, "SELECT count(Time) FROM %s WHERE Time>=%f AND Time<%f;", table_name, start, stop); |
437 | - //printf("\t\t has data query : %s\n", query); | |
438 | 436 | sqlite3 * db; |
439 | 437 | sqlite3_stmt * res; |
440 | 438 | sqlite3_open("amda.db", &db); |
... | ... | @@ -442,15 +440,12 @@ int datatable_has_data(char * table_name, double start, double stop) { |
442 | 440 | rc=sqlite3_step(res); |
443 | 441 | if(rc==SQLITE_ROW) { |
444 | 442 | ans = sqlite3_column_int(res, 0); |
445 | - //printf("row found : %i\n", ans); | |
446 | 443 | } |
447 | 444 | else { |
448 | - //printf("no row found\n"); | |
449 | 445 | } |
450 | 446 | sqlite3_finalize(res); |
451 | 447 | sqlite3_close(db); |
452 | 448 | free(query); |
453 | - //printf("before return : %i\n", ans); | |
454 | 449 | return ans; |
455 | 450 | } |
456 | 451 | |
... | ... | @@ -533,11 +528,10 @@ void log_ddvar(DD_Var_t * ddvar, char * filename) { |
533 | 528 | |
534 | 529 | int get_data_from_table(char * table_name, struct RequestData * request) { |
535 | 530 | int rc; |
536 | - //printf("\t\tinstrument start time : %f\n", get_instrument_time(request->instrument_id)); | |
537 | - //printf("\t\tinterval value : %f\n", DD_Time2Double(request->time)); | |
538 | 531 | double start_time = get_instrument_time(request->instrument_id); |
539 | 532 | double stop_time, dt; dt = DD_Time2Double(request->time); |
540 | 533 | stop_time = start_time + dt + 10; |
534 | + printf("QUERY REAL TIME : %f -> %f\n", start_time, stop_time); | |
541 | 535 | sqlite3 * db; |
542 | 536 | rc = sqlite3_open("amda.db", &db); |
543 | 537 | if(rc!=SQLITE_OK) { |
... | ... | @@ -561,7 +555,6 @@ int get_data_from_table(char * table_name, struct RequestData * request) { |
561 | 555 | |
562 | 556 | int i;for(i=0;i<request->variable_count;i++) { |
563 | 557 | char * var_name = request->variable_names[i]; |
564 | - //printf("\tVariable name: %s\n", var_name); | |
565 | 558 | if( strcmp(var_name, "Time") != 0) { |
566 | 559 | IntArray * p_dim=NULL; p_dim = get_parameter_dimension(var_name, table_name); |
567 | 560 | if(p_dim!=NULL) { |
... | ... | @@ -579,8 +572,6 @@ int get_data_from_table(char * table_name, struct RequestData * request) { |
579 | 572 | |
580 | 573 | } |
581 | 574 | else { |
582 | - //printf("MUTLTIDIM DATA : Come back to this later\n"); | |
583 | - //printf("\tp_dim : %i\n", p_dim->size); | |
584 | 575 | } |
585 | 576 | |
586 | 577 | // set parameter data dimensions |
... | ... | @@ -606,7 +597,7 @@ int get_data_from_table(char * table_name, struct RequestData * request) { |
606 | 597 | char * selection_query = malloc(1024 * sizeof(char)); |
607 | 598 | memset(selection_query, 0, 1024); |
608 | 599 | sprintf(selection_query, "SELECT %s FROM %s WHERE Time>=%f AND Time<%f ORDER BY Time;", qu, table_name, start_time, stop_time); |
609 | - //printf("\tselection query : -%s-\n", selection_query); | |
600 | + printf("selection query -%s-\n", selection_query); | |
610 | 601 | |
611 | 602 | //ddvar_free_dimensions(DD_Var[request->instrument_id]); |
612 | 603 | //ddvar_clear_data(DD_Var[request->instrument_id]); |
... | ... | @@ -707,13 +698,11 @@ void create_instrument_time_table() { |
707 | 698 | } |
708 | 699 | |
709 | 700 | double get_instrument_time(int instrument_id) { |
710 | - //printf("in get_instrument_time id : %i\n", instrument_id); | |
711 | 701 | // selection query |
712 | 702 | char * q = malloc(1024 * sizeof(char)); |
713 | 703 | double ans = -1; |
714 | 704 | int rc; |
715 | 705 | sprintf(q, "SELECT start FROM instrument_time WHERE id=%i LIMIT 1;", instrument_id); |
716 | - //printf("query : -%s-\n", q); | |
717 | 706 | sqlite3 * db; |
718 | 707 | sqlite3_stmt * res; |
719 | 708 | sqlite3_open("amda.db", &db); |
... | ... | @@ -721,15 +710,12 @@ double get_instrument_time(int instrument_id) { |
721 | 710 | rc=sqlite3_step(res); |
722 | 711 | if(rc==SQLITE_ROW) { |
723 | 712 | ans = sqlite3_column_double(res, 0); |
724 | - //printf("Row found : %f\n", ans); | |
725 | 713 | } |
726 | 714 | else { |
727 | - //printf("No row found\n"); | |
728 | 715 | } |
729 | 716 | sqlite3_finalize(res); |
730 | 717 | sqlite3_close(db); |
731 | 718 | free(q); |
732 | - //printf("before return :%f\n", ans); | |
733 | 719 | return ans; |
734 | 720 | } |
735 | 721 | int set_instrument_time(int instrument_id, double time) { |
... | ... | @@ -759,6 +745,8 @@ int set_instrument_time(int instrument_id, double time) { |
759 | 745 | */ |
760 | 746 | void Serv(int socket_id) { |
761 | 747 | // DEBUG : time Serv function |
748 | + printf("\tin DDServer::Serv, socket_id=%i\n", socket_id); | |
749 | + printf("\tpid : %lun\n", getpid()); | |
762 | 750 | clock_t t0; |
763 | 751 | t0 = clock(); |
764 | 752 | int cc; |
... | ... | @@ -836,8 +824,11 @@ void Serv(int socket_id) { |
836 | 824 | * Call data functions and response generation |
837 | 825 | *----------------------------------------------*/ |
838 | 826 | err=request_call(&r, socket_id, &done_flag, &TicketID, &RemainID); |
827 | + printf("\trequest answered, type:%i, done_flag:%i\n", r.type, done_flag); | |
839 | 828 | |
840 | 829 | } while(!done_flag);/* end while(done_flag) */ |
830 | + printf("\tout DDServer::Serv, socket_id=%i\n", socket_id); | |
831 | + printf("\tpid : %lun\n", getpid()); | |
841 | 832 | |
842 | 833 | |
843 | 834 | endend: |
... | ... | @@ -858,6 +849,8 @@ endend: |
858 | 849 | |
859 | 850 | shutdown(socket_id,2); |
860 | 851 | close(socket_id); |
852 | + printf("\texit::Serv, socket_id=%i\n", socket_id); | |
853 | + | |
861 | 854 | exit(0); |
862 | 855 | } |
863 | 856 | /*---------------------end of SERV ------------------------*/ |
... | ... | @@ -902,14 +895,14 @@ int main(int argc, char **argv) { |
902 | 895 | else { |
903 | 896 | listener_global = ListenerID; |
904 | 897 | socket_global = NewSocketID; |
905 | - //if(fork() == 0) { | |
898 | + if(fork() == 0) { | |
906 | 899 | /* I am child */ |
907 | - // if(fork() == 0) { | |
900 | + if(fork() == 0) { | |
908 | 901 | Serv(NewSocketID); /*Real working */ |
909 | - // } | |
910 | - // else exit(0); | |
911 | - //} | |
912 | - //else wait(&stat_loc); /* wait of finishing of child */ | |
902 | + } | |
903 | + else exit(0); | |
904 | + } | |
905 | + else wait(&stat_loc); /* wait of finishing of child */ | |
913 | 906 | close(NewSocketID); |
914 | 907 | } |
915 | 908 | } | ... | ... |
src/SERVER/request.c
... | ... | @@ -88,26 +88,40 @@ int request_decode_open_instrument(XDR * xdrs, char * buffer, int socket_id, str |
88 | 88 | xdr_int(xdrs,&(request->user_id)); |
89 | 89 | xdr_string(xdrs,&request->host,MAXHOSTLENGTH); |
90 | 90 | xdr_string(xdrs,&request->login,USRLENGTH); |
91 | - | |
91 | + | |
92 | + printf("\tOpenInstrument request\n"); | |
93 | + printf("\t\tuser_id : %i\n", request->user_id); | |
94 | + printf("\t\thost : %s\n", request->host); | |
95 | + printf("\t\tlogin : %s\n", request->login); | |
96 | + printf("\t\tname : %s\n", request->name); | |
92 | 97 | return 0; |
93 | 98 | } |
94 | 99 | |
95 | 100 | int request_decode_close_instrument(XDR * xdrs, char * buffer, struct RequestData * request) { |
96 | 101 | xdr_int(xdrs,&request->instrument_id); |
97 | - return 0; | |
98 | - | |
99 | 102 | |
103 | + printf("\tCloseInstrument request\n"); | |
104 | + printf("\t\tinstrument_id : %i\n", request->instrument_id); | |
105 | + return 0; | |
100 | 106 | } |
101 | 107 | |
102 | 108 | int request_decode_set_time(XDR * xdrs, char * buffer, struct RequestData * request) { |
103 | 109 | xdr_int(xdrs,&request->instrument_id); |
104 | 110 | xdr_string(xdrs,&request->time,TIMELENGTH); |
111 | + | |
112 | + printf("\tSetTime request\n"); | |
113 | + printf("\t\tinstrument_id : %i\n", request->instrument_id); | |
114 | + printf("\t\ttime : %s\n", request->time); | |
105 | 115 | return 0; |
106 | 116 | } |
107 | 117 | |
108 | 118 | int request_decode_data_info(XDR * xdrs, char * buffer, struct RequestData * request) { |
109 | 119 | xdr_int(xdrs,&request->instrument_id); |
110 | 120 | xdr_string(xdrs,&request->name,MAXVARLENGTH); |
121 | + | |
122 | + printf("\tDataInfo request\n"); | |
123 | + printf("\t\tinstrument_id : %i\n",request->instrument_id); | |
124 | + printf("\t\tname : %s\n",request->name); | |
111 | 125 | return 0; |
112 | 126 | } |
113 | 127 | |
... | ... | @@ -137,12 +151,19 @@ int request_decode_data_get(XDR * xdrs, int socket_id, struct RequestData * requ |
137 | 151 | |
138 | 152 | xdr_int(xdrs,&request->variable_count); |
139 | 153 | request->variable_names = (char **)malloc(sizeof(char *) * request->variable_count); |
140 | - int i; | |
141 | - for(i=0;i < request->variable_count; i++) { | |
154 | + int i;for(i=0;i < request->variable_count; i++) { | |
142 | 155 | request->variable_names[i] = (char *)malloc(sizeof(char) * MAXVARLENGTH); |
143 | 156 | xdr_string(xdrs,&(request->variable_names[i]),MAXVARLENGTH); |
144 | 157 | } |
145 | 158 | xdr_int(xdrs,&request->dataget_flag); |
159 | + printf("\tGetData request\n"); | |
160 | + printf("\t\tinstrument_id : %i\n", request->instrument_id); | |
161 | + printf("\t\ttime : %s\n", request->time); | |
162 | + printf("\t\tpacket_size : %i\n", request->packet_size); | |
163 | + printf("\t\tvariable_count : %i\n", request->variable_count); | |
164 | + for(i=0;i<request->variable_count;i++) { | |
165 | + printf("\t\t\t variable_name[%i] : %s\n",i,request->variable_names[i]); | |
166 | + } | |
146 | 167 | return 0; |
147 | 168 | } |
148 | 169 | |
... | ... | @@ -161,6 +182,13 @@ int request_decode_get_ticket(XDR * xdrs, char * buffer, int socket_id, struct R |
161 | 182 | xdr_string(xdrs,&request->login,USRLENGTH); |
162 | 183 | xdr_string(xdrs,&request->ticket,TICKETLENGTH); |
163 | 184 | xdr_string(xdrs,&request->host,MAXHOSTLENGTH); |
185 | + | |
186 | + printf("\tGetTicket request\n"); | |
187 | + printf("\t\tuser_id : %i\n", request->user_id); | |
188 | + printf("\t\tlogin : %s\n", request->login); | |
189 | + printf("\t\tticket : %s\n", request->ticket); | |
190 | + printf("\t\thost : %s\n", request->host); | |
191 | + | |
164 | 192 | return 0; |
165 | 193 | |
166 | 194 | } |
... | ... | @@ -169,7 +197,11 @@ int request_decode_add_vi(XDR * xdrs, struct RequestData * request) { |
169 | 197 | xdr_string(xdrs,&request->new_vi_name,MAXSETLENGTH); |
170 | 198 | xdr_string(xdrs,&request->rem_set_id,MAXVARLENGTH); |
171 | 199 | xdr_string(xdrs,&request->rem_base_name,MAXVARLENGTH); |
172 | - | |
200 | + | |
201 | + printf("\tAddVI request\n"); | |
202 | + printf("\t\tnew_vi_name : %s\n", request->new_vi_name); | |
203 | + printf("\t\trem_set_id : %s\n", request->rem_set_id); | |
204 | + printf("\t\trem_base_name : %s\n", request->rem_base_name); | |
173 | 205 | return 0; |
174 | 206 | } |
175 | 207 | |
... | ... | @@ -177,6 +209,13 @@ int request_decode_show_ticket(XDR * xdrs, struct RequestData * request) { |
177 | 209 | xdr_int(xdrs,&request->st_id); |
178 | 210 | xdr_string(xdrs,&request->st_host,MAXHOSTLENGTH); |
179 | 211 | xdr_string(xdrs,&request->st_login,USRLENGTH); |
212 | + | |
213 | + printf("\tShowTicket request\n"); | |
214 | + printf("\t\tst_id : %i\n", request->st_id); | |
215 | + printf("\t\tst_host : %s\n", request->st_host); | |
216 | + printf("\t\tst_login : %s\n", request->st_login); | |
217 | + | |
218 | + | |
180 | 219 | return 0; |
181 | 220 | } |
182 | 221 | |
... | ... | @@ -186,35 +225,27 @@ int request_decode(char * buffer, int socket_id, struct RequestData * request) { |
186 | 225 | |
187 | 226 | switch (request->type) { |
188 | 227 | case OPENINSREQ: |
189 | - printf("REQUEST : OPENINSREQ\n"); | |
190 | 228 | request_decode_open_instrument(&xdrs, buffer, socket_id, request); |
191 | 229 | break; |
192 | 230 | case CLOSEINSREQ : |
193 | - printf("REQUEST : CLOSEINSREQ\n"); | |
194 | 231 | request_decode_close_instrument(&xdrs, buffer, request); |
195 | 232 | break; |
196 | 233 | case TIMESETREQ: |
197 | - printf("REQUEST : TIMESETREQ\n"); | |
198 | 234 | request_decode_set_time(&xdrs, buffer, request); |
199 | 235 | break; |
200 | 236 | case DATAINFOREQ: |
201 | - printf("REQUEST : DATAINFOREQ\n"); | |
202 | 237 | request_decode_data_info(&xdrs, buffer, request); |
203 | 238 | break; |
204 | 239 | case DATAGETREQ: |
205 | - printf("REQUEST : DATAGETREQ\n"); | |
206 | 240 | request_decode_data_get(&xdrs, socket_id, request); |
207 | 241 | break; |
208 | 242 | case ADDVIREQ: |
209 | - printf("REQUEST : ADDVIREQ\n"); | |
210 | 243 | request_decode_add_vi(&xdrs, request); |
211 | 244 | break; |
212 | 245 | case GETTICKETREQ: |
213 | - printf("REQUEST : GETTICKETREQ\n"); | |
214 | 246 | request_decode_get_ticket(&xdrs, buffer, socket_id, request); |
215 | 247 | break; |
216 | 248 | case SHOWTICKETREQ: |
217 | - printf("REQUEST : SHOWTICKETREQ\n"); | |
218 | 249 | request_decode_show_ticket(&xdrs, request); |
219 | 250 | break; |
220 | 251 | default: return REQSENDERR; |
... | ... | @@ -257,11 +288,8 @@ int request_call_close_instrument(struct RequestData * request, int socket_id, i |
257 | 288 | } |
258 | 289 | |
259 | 290 | int request_call_set_time(struct RequestData * request, DD_Var_t * ddvar, int socket_id) { |
260 | - //printf("\tinstrument id : %i\n", request->instrument_id); | |
261 | - //printf("\tstart ddtime : %s\n", request->time); | |
262 | 291 | double time_s; |
263 | 292 | time_s = DD_Time2Double(request->time); |
264 | - //printf("\tstart double : %f\n", time_s); | |
265 | 293 | int err; |
266 | 294 | if(request->instrument_id < 0) err = NOID; |
267 | 295 | if(err >= 0) err = SetTime(ddvar,DD_Time2Double(request->time)); |
... | ... | @@ -300,26 +328,26 @@ int request_call_data_info(struct RequestData * request, DD_Var_t * ddvar, int s |
300 | 328 | |
301 | 329 | int request_call_get_ticket(struct RequestData * request, int socket_id, int * done_flag, int * ticket_id) { |
302 | 330 | int err; |
303 | - printf("Checking ticket : login: %s, tick: %s\n", request->login, request->ticket); | |
331 | + printf("Checking ticket\n"); | |
304 | 332 | err= CheckTicket(request->login, request->ticket); |
305 | - printf("err: %i\n", err); | |
333 | + printf("\terr:%i\n", err); | |
306 | 334 | Put2Log(request->user_id,request->host,request->login,err); /* Log file */ |
307 | - printf("Getting ticket : user_id: %i, host: %s, err: %i\n", request->user_id, request->host, err); | |
335 | + printf("A\n"); | |
308 | 336 | if(err>= 0) *ticket_id = GetTicket(request->user_id,request->host,err); |
309 | - printf("\tticket id : %i\n", *ticket_id); | |
337 | + printf("B\n"); | |
310 | 338 | PutHeader(*ticket_id,0,0,socket_id); |
339 | + printf("C\n"); | |
311 | 340 | *done_flag= 1; |
341 | + printf("\treturning : %i\n", err); | |
312 | 342 | return err; |
313 | 343 | } |
314 | 344 | |
315 | 345 | double get_instrument_time2(int instrument_id) { |
316 | - //printf("in get_instrument_time2 id : %i\n", instrument_id); | |
317 | 346 | // selection query |
318 | 347 | char * q = malloc(1024 * sizeof(char)); |
319 | 348 | double ans = -1; |
320 | 349 | int rc; |
321 | 350 | sprintf(q, "SELECT start FROM instrument_time WHERE id=%i LIMIT 1;", instrument_id); |
322 | - //printf("query : -%s-\n", q); | |
323 | 351 | sqlite3 * db; |
324 | 352 | sqlite3_stmt * res; |
325 | 353 | sqlite3_open("amda.db", &db); |
... | ... | @@ -327,25 +355,20 @@ double get_instrument_time2(int instrument_id) { |
327 | 355 | rc=sqlite3_step(res); |
328 | 356 | if(rc==SQLITE_ROW) { |
329 | 357 | ans = sqlite3_column_double(res, 0); |
330 | - //printf("Row found : %f\n", ans); | |
331 | 358 | } |
332 | 359 | else { |
333 | - //printf("No row found\n"); | |
334 | 360 | } |
335 | 361 | sqlite3_finalize(res); |
336 | 362 | sqlite3_close(db); |
337 | 363 | free(q); |
338 | - //printf("before return :%f\n", ans); | |
339 | 364 | return ans; |
340 | 365 | } |
341 | 366 | |
342 | 367 | int datatable_has_data2(char * table_name, double start, double stop) { |
343 | - //printf("in datatable_has_data2 : table_name:%s, start:%f, stop:%f\n", table_name, start, stop); | |
344 | 368 | int ans = 0, rc; |
345 | 369 | char * query = malloc( 1024 * sizeof(char) ); |
346 | 370 | memset(query, 0, 1024); |
347 | 371 | sprintf(query, "SELECT count(Time) FROM %s WHERE Time>=%f AND Time<%f;", table_name, start, stop); |
348 | - //printf("\t\t has data query : %s\n", query); | |
349 | 372 | sqlite3 * db; |
350 | 373 | sqlite3_stmt * res; |
351 | 374 | sqlite3_open("amda.db", &db); |
... | ... | @@ -353,21 +376,17 @@ int datatable_has_data2(char * table_name, double start, double stop) { |
353 | 376 | rc=sqlite3_step(res); |
354 | 377 | if(rc==SQLITE_ROW) { |
355 | 378 | ans = sqlite3_column_int(res, 0); |
356 | - //printf("row found :%i\n", ans); | |
357 | 379 | } |
358 | 380 | else { |
359 | - //printf("no row found\n"); | |
360 | 381 | } |
361 | 382 | sqlite3_finalize(res); |
362 | 383 | sqlite3_close(db); |
363 | 384 | free(query); |
364 | - //printf("before return : %i\n", ans); | |
365 | 385 | return ans; |
366 | 386 | } |
367 | 387 | int request_call_data_get(struct RequestData * request, int socket_id, int * done_flag, int * ticket_id) { |
368 | 388 | int err,serr; |
369 | - //printf("\tparameters : "); | |
370 | - //print_string_array(request->variable_names, request->variable_count); | |
389 | + print_string_array(request->variable_names, request->variable_count); | |
371 | 390 | // note the time at this point |
372 | 391 | struct timespec t0, t1; |
373 | 392 | clock_gettime(CLOCK_MONOTONIC_RAW, &t0); |
... | ... | @@ -390,17 +409,14 @@ int request_call_data_get(struct RequestData * request, int socket_id, int * don |
390 | 409 | has_vi=has_virtual_instrument(table_name); |
391 | 410 | if(has_vi) { |
392 | 411 | // try to get data for this instrument between start and stop dates |
393 | - //printf("Instrument id : %i\n", request->instrument_id); | |
394 | 412 | double start_time; start_time = get_instrument_time(request->instrument_id); |
395 | - //printf("start_time %f\n", start_time); | |
396 | - //printf("request time str : %s\n", request->time); | |
397 | 413 | double stop_time; stop_time = start_time + DD_Time2Double(request->time); |
398 | - //printf("before datatable_has_data2 call : table_name:%s, start_time:%f, stop_time:%f\n", table_name, start_time,stop_time); | |
414 | + printf("QUERY TIME : %f -> %f\n", start_time, stop_time); | |
399 | 415 | int has_data; |
400 | 416 | has_data = datatable_has_data(table_name, start_time, stop_time); |
401 | - //printf("in request_call_data_get : has_data : %i\n", has_data); | |
402 | 417 | if(has_data || 1) { |
403 | 418 | err = get_data_from_table(table_name, request); |
419 | + printf("after get_data_from_table, table:%s, err:%i, flag:%i\n", table_name, err, DD_Var[request->instrument_id]->LastPacketFlag); | |
404 | 420 | } |
405 | 421 | } |
406 | 422 | |
... | ... | @@ -411,8 +427,8 @@ int request_call_data_get(struct RequestData * request, int socket_id, int * don |
411 | 427 | |
412 | 428 | // send data |
413 | 429 | if(err >= 0) { |
414 | - //printf("\tSending data packet (err:%i)\n", err); | |
415 | 430 | serr = SendDataPacket(DD_Var[request->instrument_id],socket_id,DD_Var[request->instrument_id]->LastPacketFlag); /* OK, MOREDATA, MOREDELAY */ |
431 | + printf("\tSendDataPacket returns: %i\n", serr); | |
416 | 432 | } |
417 | 433 | } |
418 | 434 | while((err >= 0) && (DD_Var[request->instrument_id]->LastPacketFlag == MOREDATA)); |
... | ... | @@ -420,8 +436,6 @@ int request_call_data_get(struct RequestData * request, int socket_id, int * don |
420 | 436 | // note time at this point |
421 | 437 | clock_gettime(CLOCK_MONOTONIC_RAW, &t1); |
422 | 438 | uint64_t ns = (t1.tv_sec - t0.tv_sec) * 1000000 + (t1.tv_nsec - t0.tv_nsec) / 1000; |
423 | - //printf("\t\t\tREQUEST TIME :%" PRIu64 "\n", ns); | |
424 | - //printf("\t\t\t\t %f ms\n", ns / 1000.); | |
425 | 439 | // TODO - free DD_Var_t object |
426 | 440 | //DD_Var[r.instrument_id] = NULL; |
427 | 441 | return err; |
... | ... | @@ -432,36 +446,28 @@ int request_call(struct RequestData * request, int socket_id, int * done_flag, i |
432 | 446 | int err; |
433 | 447 | switch(request->type) { |
434 | 448 | case OPENINSREQ: |
435 | - printf("REQUEST : OPENINSREQ\n"); | |
436 | 449 | err=request_call_open_instrument(request, DD_Var, socket_id); |
437 | 450 | break; |
438 | 451 | case CLOSEINSREQ: |
439 | - printf("REQUEST : CLOSEINSREQ\n"); | |
440 | 452 | err=request_call_close_instrument(request, socket_id, remain_id, done_flag); |
441 | 453 | break; |
442 | 454 | case TIMESETREQ: |
443 | - printf("REQUEST : TIMESETREQ\n"); | |
444 | 455 | err=request_call_set_time(request, DD_Var[request->instrument_id], socket_id); |
445 | - printf("SetTime err : %i\n", err); | |
446 | 456 | set_instrument_time(request->instrument_id, DD_Time2Double(request->time)); |
447 | 457 | break; |
448 | 458 | case DATAINFOREQ: |
449 | - printf("REQUEST : DATAINFOREQ\n"); | |
450 | 459 | err=request_call_data_info(request, DD_Var[request->instrument_id],socket_id); |
451 | 460 | break; |
452 | 461 | case GETTICKETREQ: |
453 | - printf("REQUEST : GETTICKETREQ\n"); | |
454 | 462 | err = request_call_get_ticket(request, socket_id, done_flag, ticket_id); |
455 | 463 | break; |
456 | 464 | case DATAGETREQ: ; |
457 | - printf("REQUEST : DATAGETREQ\n"); | |
458 | 465 | err = request_call_data_get(request, socket_id, done_flag, ticket_id); |
459 | 466 | break; |
460 | 467 | case ADDVIREQ: |
461 | 468 | err = request_call_add_vi(request, socket_id, done_flag); |
462 | 469 | break; |
463 | 470 | case SHOWTICKETREQ: |
464 | - printf("\tst id: %i\n\tst host: %s\n\tSTReqLogin : %s\n", request->st_id,request->st_host,request->st_login); | |
465 | 471 | err = ShowTicket(request->st_id,request->st_host,request->st_login); |
466 | 472 | PutHeader(err,0,0,socket_id); |
467 | 473 | *done_flag= 1; | ... | ... |
tests/testGetData.c
... | ... | @@ -11,11 +11,11 @@ |
11 | 11 | #include <string.h> |
12 | 12 | #include <sys/time.h> |
13 | 13 | |
14 | -#define DATA_VI "mes:mag:orb\0" | |
15 | -#define DATA_STARTTIME "2012000000000000\0" | |
14 | +#define DATA_VI "m10:m1:orb\0" | |
15 | +#define DATA_STARTTIME "1974088000000000\0" | |
16 | 16 | #define DATA_TIMEINT "0000010000000000\0" |
17 | 17 | #define DATA_TIMENAME "Time\0" |
18 | -#define DATA_PARAMNAME "B_MSOO\0"" | |
18 | +#define DATA_PARAMNAME "POS_MOO\0"" | |
19 | 19 | |
20 | 20 | |
21 | 21 | /* | ... | ... |