source: branches/FACT++_lidctrl_new_eth/dim/src/dic.c@ 19950

Last change on this file since 19950 was 18349, checked in by tbretz, 9 years ago
Updated to v20r15
File size: 52.6 KB
Line 
1
2/*
3 * DIC (Delphi Information Client) Package implements a library of
4 * routines to be used by clients.
5 *
6 * Started on : 10-11-91
7 * Last modification : 10-08-94
8 * Written by : C. Gaspar
9 * Adjusted by : G.C. Ballintijn
10 *
11 */
12
13#ifdef VMS
14# include <cfortran.h>
15# include <assert.h>
16#endif
17
18#define DIMLIB
19#include <dim.h>
20#include <dic.h>
21
22/*
23#define DEBUG
24*/
25
26#ifdef VMS
27#define TMP_ENABLE_AST long int ast_enable = sys$setast(1);
28#define TMP_DISABLE_AST if (ast_enable != SS$_WASSET) sys$setast(0);
29#endif
30
31#define BAD_CONN_TIMEOUT 2
32
33typedef struct bad_conn {
34 struct bad_conn *next;
35 struct bad_conn *prev;
36 DIC_CONNECTION conn;
37 int n_retries;
38 int retrying;
39} DIC_BAD_CONNECTION;
40
41static DIC_SERVICE *Service_pend_head = 0;
42static DIC_SERVICE *Cmnd_head = 0;
43static DIC_SERVICE *Current_server = 0;
44static DIC_BAD_CONNECTION *Bad_connection_head = 0;
45static int Dic_timer_q = 0;
46static int Dns_dic_conn_id = 0;
47static TIMR_ENT *Dns_dic_timr = NULL;
48static int Tmout_max = 0;
49static int Tmout_min = 0;
50static int Threads_off = 0;
51
52static void (*Error_user_routine)() = 0;
53static int Error_conn_id = 0;
54static int Curr_conn_id = 0;
55
56#ifdef DEBUG
57static int Debug_on = 1;
58#else
59static int Debug_on = 0;
60#endif
61
62_DIM_PROTO( unsigned request_service, (char *service_name, int req_type,
63 int req_timeout, void *service_address,
64 int service_size, void (*usr_routine)(void*,void*,int*),
65 dim_long tag, void *fill_addr, int fill_size, int stamped) );
66_DIM_PROTO( int request_command, (char *service_name, void *service_address,
67 int service_size, void (*usr_routine)(void*,int*),
68 dim_long tag, int stamped) );
69_DIM_PROTO( DIC_SERVICE *insert_service, (int type, int timeout, char *name,
70 int *address, int size, void (*routine)(),
71 dim_long tag, int *fill_addr, int fill_size,
72 int pending, int stamped ) );
73_DIM_PROTO( void modify_service, (DIC_SERVICE *servp, int timeout,
74 int *address, int size, void (*routine)(),
75 dim_long tag, int *fill_addr, int fill_size, int stamped) );
76_DIM_PROTO( DIC_SERVICE *locate_command, (char *serv_name) );
77_DIM_PROTO( DIC_SERVICE *locate_pending, (char *serv_name) );
78_DIM_PROTO( DIC_BAD_CONNECTION *locate_bad, (char *node, char *task, int port) );
79_DIM_PROTO( void service_tmout, (int serv_id) );
80_DIM_PROTO( static void request_dns_info, (int retry) );
81_DIM_PROTO( static int handle_dns_info, (DNS_DIC_PACKET *) );
82_DIM_PROTO( void close_dns_conn, (void) );
83_DIM_PROTO( static void release_conn, (int conn_id) );
84_DIM_PROTO( static void get_format_data, (int format, FORMAT_STR *format_data,
85 char *def) );
86_DIM_PROTO( static void execute_service, (DIS_PACKET *packet,
87 DIC_SERVICE *servp, int size) );
88
89void print_packet(DIS_PACKET *packet)
90{
91 dim_print_date_time();
92 printf("Bad ID received from server -> Packet received:\n");
93 printf("\tpacket->size = %d\n",vtohl(packet->size));
94 printf("\tpacket->service_id = %d\n",vtohl(packet->service_id));
95}
96
97void dic_set_debug_on()
98{
99 Debug_on = 1;
100}
101
102void dic_set_debug_off()
103{
104 Debug_on = 0;
105}
106
107void dic_no_threads()
108{
109 Threads_off = 1;
110}
111
112void dic_add_error_handler( void (*user_routine)())
113{
114
115 DISABLE_AST
116 Error_user_routine = user_routine;
117 ENABLE_AST
118}
119
120static void error_handler(int conn_id, int severity, int errcode, char *reason)
121{
122 int last_conn_id;
123
124 if(Error_user_routine)
125 {
126 Error_conn_id = conn_id;
127 last_conn_id = Curr_conn_id;
128 (Error_user_routine)(severity, errcode, reason);
129 Error_conn_id = 0;
130 Curr_conn_id = last_conn_id;
131 }
132 else
133 {
134 dim_print_msg(reason, severity);
135 if(severity == 3)
136 {
137 printf("Exiting!\n");
138 exit(2);
139 }
140 }
141}
142
143static void recv_rout( int conn_id, DIS_PACKET *packet, int size, int status )
144{
145 register DIC_SERVICE *servp, *auxp;
146 register DIC_CONNECTION *dic_connp;
147 int service_id, once_only, found = 0;
148 char node[MAX_NODE_NAME], task[MAX_TASK_NAME];
149 void move_to_notok_service();
150 void do_cmnd_callback();
151 void dim_panic(char *);
152
153 dic_connp = &Dic_conns[conn_id] ;
154 switch( status )
155 {
156 case STA_DISC:
157 if(Debug_on)
158 {
159 dna_get_node_task(conn_id, node, task);
160 dim_print_date_time();
161 printf("Conn %d: Server %s on node %s Disconnected\n",
162 conn_id, task, node);
163 fflush(stdout);
164 }
165 if( !(servp = (DIC_SERVICE *) dic_connp->service_head) )
166 {
167 release_conn( conn_id );
168 break;
169 }
170 while( (servp = (DIC_SERVICE *) dll_get_next(
171 (DLL *) dic_connp->service_head,
172 (DLL *) servp)) )
173 {
174#ifdef DEBUG
175 printf("\t %s was in the service list\n",servp->serv_name);
176 fflush(stdout);
177#endif
178/*
179 Will be done later by the DNS answer
180 service_tmout( servp->serv_id );
181*/
182 if(!strcmp(dic_connp->task_name,"DIS_DNS"))
183 {
184 service_tmout( servp->serv_id );
185 }
186 else if(Dns_dic_conn_id <= 0)
187 {
188 service_tmout( servp->serv_id );
189 }
190/*
191 servp->pending = WAITING_DNS_UP;
192 servp->conn_id = 0;
193*/
194 auxp = servp->prev;
195 move_to_notok_service( servp );
196 servp = auxp;
197 }
198 if( (servp = (DIC_SERVICE *) Cmnd_head) )
199 {
200 while( (servp = (DIC_SERVICE *) dll_get_next(
201 (DLL *) Cmnd_head,
202 (DLL *) servp)) )
203 {
204 if( servp->conn_id == conn_id )
205 {
206#ifdef DEBUG
207 printf("\t%s was in the Command list\n", servp->serv_name);
208 printf("servp = %x, type = %d, pending = %d\n",servp, servp->type, servp->pending);
209 fflush(stdout);
210#endif
211 auxp = servp->prev;
212 if( (servp->type == ONCE_ONLY ) &&
213 (servp->pending == WAITING_SERVER_UP))
214 {
215 service_tmout( servp->serv_id );
216 }
217 else if( (servp->type == COMMAND ) &&
218 (servp->pending == WAITING_CMND_ANSWER))
219 {
220 service_tmout( servp->serv_id );
221 }
222 else
223 {
224 servp->pending = WAITING_DNS_UP;
225 dic_release_service( (unsigned)servp->serv_id );
226 }
227 servp = auxp;
228 }
229 }
230 }
231 release_conn( conn_id );
232 request_dns_info(0);
233 break;
234 case STA_DATA:
235 if( !(DIC_SERVICE *) dic_connp->service_head )
236 break;
237 service_id = vtohl(packet->service_id);
238 if((unsigned)service_id & 0x80000000) /* Service removed by server */
239 {
240 service_id &= 0x7fffffff;
241 if( (servp = (DIC_SERVICE *) id_get_ptr(service_id, SRC_DIC)))
242 {
243 if( servp->type != COMMAND )
244 {
245 service_tmout( servp->serv_id );
246/*
247 servp->pending = WAITING_DNS_UP;
248 servp->conn_id = 0;
249*/
250 move_to_notok_service( servp );
251 }
252 else
253 {
254 service_tmout( servp->serv_id );
255 break;
256 }
257 }
258 else
259 {
260/*
261 print_packet(packet);
262*/
263 if( (servp = (DIC_SERVICE *) Cmnd_head) )
264 {
265 while( (servp = (DIC_SERVICE *) dll_get_next(
266 (DLL *) Cmnd_head,
267 (DLL *) servp)) )
268 {
269 if( servp->conn_id == conn_id )
270 {
271#ifdef DEBUG
272 printf("\t%s was in the Command list\n", servp->serv_name);
273 fflush(stdout);
274#endif
275 auxp = servp->prev;
276 if( (servp->type == ONCE_ONLY ) &&
277 (servp->pending == WAITING_SERVER_UP))
278 {
279 service_tmout( servp->serv_id );
280 }
281 else if( (servp->type == COMMAND ) &&
282 (servp->pending == WAITING_CMND_ANSWER))
283 {
284 service_tmout( servp->serv_id );
285 }
286 else
287 {
288 servp->pending = WAITING_DNS_UP;
289 dic_release_service( (unsigned)servp->serv_id );
290 }
291 servp = auxp;
292 }
293 }
294 }
295 }
296 if( dll_empty((DLL *)dic_connp->service_head) ) {
297 if( (servp = (DIC_SERVICE *) Cmnd_head) ) {
298 while( (servp = (DIC_SERVICE *) dll_get_next(
299 (DLL *) Cmnd_head,
300 (DLL *) servp)) )
301 {
302 if( servp->conn_id == conn_id)
303 found = 1;
304 }
305 }
306 if( !found)
307 {
308 release_conn( conn_id );
309 }
310 }
311 request_dns_info(0);
312 break;
313 }
314 if( (servp = (DIC_SERVICE *) id_get_ptr(service_id, SRC_DIC)))
315 {
316 if(servp->serv_id == service_id)
317 {
318 once_only = 0;
319 if(servp->type == ONCE_ONLY)
320 once_only = 1;
321 else
322 {
323 if( servp->timeout > 0 )
324 {
325 if(servp->timer_ent)
326 dtq_clear_entry( servp->timer_ent );
327 }
328 }
329 Curr_conn_id = conn_id;
330 execute_service(packet, servp, size);
331 Curr_conn_id = 0;
332 if( once_only )
333 {
334 auxp = locate_command(servp->serv_name);
335 if((auxp) && (auxp != servp))
336 {
337 servp->pending = WAITING_DNS_UP;
338 dic_release_service( (unsigned)servp->serv_id );
339 }
340 else
341 {
342 servp->pending = NOT_PENDING;
343 servp->tmout_done = 0;
344 if( servp->timer_ent )
345 {
346 dtq_rem_entry( Dic_timer_q, servp->timer_ent );
347 servp->timer_ent = 0;
348 }
349 }
350 }
351 }
352 }
353/*
354 else
355 {
356 print_packet(packet);
357 if(Error_user_routine)
358 (Error_user_routine)( packet->buffer );
359 }
360*/
361 break;
362 case STA_CONN:
363 if(Debug_on)
364 {
365 dna_get_node_task(conn_id, node, task);
366 dim_print_date_time();
367 printf("Conn %d: Server %s on node %s Connected\n",
368 conn_id, task, node);
369 fflush(stdout);
370 }
371 break;
372 default: dim_panic( "recv_rout(): Bad switch" );
373 }
374}
375
376static void execute_service(DIS_PACKET *packet, DIC_SERVICE *servp, int size)
377{
378 int format;
379 FORMAT_STR format_data_cp[MAX_NAME/4], *formatp;
380 static int *buffer;
381 static int buffer_size = 0;
382 int add_size;
383 int *pkt_buffer, header_size;
384
385 Current_server = servp;
386 format = servp->format;
387 memcpy(format_data_cp, servp->format_data, sizeof(format_data_cp));
388 if((format & 0xF) == ((MY_FORMAT) & 0xF))
389 {
390 for(formatp = format_data_cp; formatp->par_bytes; formatp++)
391 formatp->flags &= (short)0xFFF0; /* NOSWAP */
392 }
393 if( servp->stamped)
394 {
395 pkt_buffer = ((DIS_STAMPED_PACKET *)packet)->buffer;
396 header_size = DIS_STAMPED_HEADER;
397 servp->time_stamp[0] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[0]);
398 if(((unsigned)servp->time_stamp[0] & 0xFFFF0000) == 0xc0de0000)
399 {
400/*
401 servp->time_stamp[0] &= 0x0000FFFF;
402*/
403 servp->time_stamp[1] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[1]);
404 servp->quality = vtohl(((DIS_STAMPED_PACKET *)packet)->quality);
405 }
406 else if((vtohl(((DIS_STAMPED_PACKET *)packet)->reserved[0])) == (int)0xc0dec0de)
407 {
408/*
409 servp->time_stamp[0] &= 0x0000FFFF;
410*/
411 servp->time_stamp[1] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[1]);
412 servp->quality = vtohl(((DIS_STAMPED_PACKET *)packet)->quality);
413 }
414 else
415 {
416 pkt_buffer = ((DIS_PACKET *)packet)->buffer;
417 header_size = DIS_HEADER;
418 }
419 }
420 else
421 {
422 pkt_buffer = ((DIS_PACKET *)packet)->buffer;
423 header_size = DIS_HEADER;
424 }
425 size -= header_size;
426 if( servp->serv_address )
427 {
428 if( size > servp->serv_size )
429 size = servp->serv_size;
430 add_size = copy_swap_buffer_in(format_data_cp,
431 servp->serv_address,
432 pkt_buffer, size);
433 if( servp->user_routine )
434 (servp->user_routine)(&servp->tag, servp->serv_address, &add_size );
435 }
436 else
437 {
438 if( servp->user_routine )
439 {
440 add_size = size + (size/2);
441 if(!buffer_size)
442 {
443 buffer = (int *)malloc((size_t)add_size);
444 buffer_size = add_size;
445 }
446 else
447 {
448 if( add_size > buffer_size )
449 {
450 free(buffer);
451 buffer = (int *)malloc((size_t)add_size);
452 buffer_size = add_size;
453 }
454 }
455 add_size = copy_swap_buffer_in(format_data_cp,
456 buffer,
457 pkt_buffer, size);
458 (servp->user_routine)( &servp->tag, buffer, &add_size );
459 }
460 }
461 Current_server = 0;
462}
463
464static void recv_dns_dic_rout( int conn_id, DNS_DIC_PACKET *packet, int size, int status )
465{
466 register DIC_SERVICE *servp, *auxp;
467 void dim_panic(char *);
468
469 if(size){}
470 switch( status )
471 {
472 case STA_DISC: /* connection broken */
473 servp = Service_pend_head;
474 while( (servp = (DIC_SERVICE *) dll_get_next(
475 (DLL *) Service_pend_head,
476 (DLL *) servp)) )
477 {
478 if( (servp->pending == WAITING_DNS_ANSWER) ||
479 (servp->pending == WAITING_SERVER_UP))
480 {
481 if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
482 {
483 auxp = servp->prev;
484 servp->pending = WAITING_DNS_UP;
485 service_tmout( servp->serv_id );
486 servp = auxp;
487 }
488 else
489 {
490 servp->pending = WAITING_DNS_UP;
491 }
492 }
493 }
494 dna_close( Dns_dic_conn_id );
495 Dns_dic_conn_id = 0;
496 request_dns_info(0);
497 break;
498 case STA_CONN: /* connection received */
499 dna_set_test_write(conn_id, 2*(dim_get_keepalive_timeout()));
500 if(Dns_dic_conn_id < 0)
501 {
502 Dns_dic_conn_id = conn_id;
503 request_dns_info(0);
504
505 }
506 break;
507 case STA_DATA: /* normal packet */
508 if( vtohl(packet->size) == DNS_DIC_HEADER )
509 {
510 handle_dns_info( packet );
511 }
512 break;
513 default: dim_panic( "recv_dns_dic_rout(): Bad switch" );
514 }
515}
516
517
518void service_tmout( int serv_id )
519{
520 int once_only, size = 0;
521 register DIC_SERVICE *servp;
522
523/*
524dim_print_date_time();
525printf("In service tmout\n");
526*/
527 servp=(DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
528 if(!servp)
529 return;
530 if(servp->tmout_done)
531 return;
532/*
533dim_print_date_time();
534printf("In service tmout %s\n", servp->serv_name);
535*/
536 servp->tmout_done = 1;
537 Curr_conn_id = servp->conn_id;
538/*
539 if( servp->type == UPDATE )
540 return;
541*/
542 if( servp->type == COMMAND )
543 {
544 if( servp->user_routine )
545 {
546 if(servp->pending == WAITING_CMND_ANSWER)
547 size = 1;
548 else
549 size = 0;
550 (servp->user_routine)( &servp->tag, &size );
551 }
552 else
553 {
554 if((servp->pending == WAITING_DNS_UP) || (servp->pending == WAITING_DNS_ANSWER))
555 {
556 dim_print_date_time();
557 printf(" Client Sending Command: Command %s discarded, no DNS answer\n", servp->serv_name);
558 fflush(stdout);
559 }
560/*
561 else if(servp->pending == WAITING_SERVER_UP)
562 {
563 }
564*/
565 }
566 dic_release_service( (unsigned)servp->serv_id );
567 Curr_conn_id = 0;
568 return;
569 }
570 once_only = 0;
571 if(servp->type == ONCE_ONLY)
572 once_only = 1;
573/*
574 if( servp->fill_address )
575*/
576 if( servp->fill_size >= 0 )
577 {
578 size = servp->fill_size;
579 if( servp->serv_address )
580 {
581 if( size > servp->serv_size )
582 size = servp->serv_size;
583 memcpy(servp->serv_address, servp->fill_address, (size_t)size);
584 if( servp->user_routine )
585 (servp->user_routine)( &servp->tag, servp->serv_address, &size);
586 }
587 else
588 {
589 if( servp->user_routine )
590 (servp->user_routine)( &servp->tag, servp->fill_address, &size);
591 }
592 }
593 if( once_only )
594 {
595 dic_release_service( (unsigned)servp->serv_id );
596 }
597 Curr_conn_id = 0;
598}
599
600
601unsigned dic_info_service( char *serv_name, int req_type, int req_timeout, void *serv_address,
602 int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size )
603{
604 unsigned ret;
605
606 ret = request_service( serv_name, req_type, req_timeout,
607 serv_address, serv_size, usr_routine, tag,
608 fill_addr, fill_size, 0 );
609
610 return(ret);
611}
612
613unsigned dic_info_service_stamped( char *serv_name, int req_type, int req_timeout, void *serv_address,
614 int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size )
615{
616 unsigned ret;
617
618 ret = request_service( serv_name, req_type, req_timeout,
619 serv_address, serv_size, usr_routine, tag,
620 fill_addr, fill_size, 1 );
621
622 return(ret);
623}
624
625unsigned request_service( char *serv_name, int req_type, int req_timeout, void *serv_address,
626 int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size, int stamped )
627{
628 register DIC_SERVICE *servp;
629 int conn_id;
630 int send_service();
631 int locate_service();
632 void dim_init_threads(void);
633
634 if(!Threads_off)
635 {
636 dim_init_threads();
637 }
638 {
639 DISABLE_AST
640 /* create a timer queue for timeouts if not yet done */
641 if( !Dic_timer_q ) {
642 conn_arr_create( SRC_DIC );
643 Dic_timer_q = dtq_create();
644 }
645
646 /* store_service */
647 if(req_timeout < 0)
648 req_timeout = 0;
649 if(req_type == ONCE_ONLY)
650 {
651 if( !Cmnd_head ) {
652 Cmnd_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE) );
653 dll_init( (DLL *) Cmnd_head );
654 Cmnd_head->serv_id = 0;
655 }
656 if( (servp = locate_command(serv_name)) )
657 {
658 if( (conn_id = servp->conn_id) )
659 {
660 if(servp->pending == NOT_PENDING)
661 {
662 modify_service( servp, req_timeout,
663 (int *)serv_address, serv_size, usr_routine, tag,
664 (int *)fill_addr, fill_size, stamped);
665 servp->pending = WAITING_SERVER_UP;
666 if(send_service(conn_id, servp))
667 {
668 ENABLE_AST
669 return(1);
670 }
671 }
672 }
673 }
674 }
675 servp = insert_service( req_type, req_timeout,
676 serv_name, (int *)serv_address, serv_size, usr_routine, tag,
677 (int *)fill_addr, fill_size, WAITING_DNS_UP, stamped );
678
679 /* get_address of server from name_server */
680
681 if( locate_service(servp) <= 0)
682 {
683/*
684 service_tmout( servp->serv_id );
685*/
686 dtq_start_timer( 0, service_tmout, servp->serv_id);
687 }
688 ENABLE_AST
689 }
690 return((unsigned) servp->serv_id);
691}
692
693
694int dic_cmnd_service( char *serv_name, void *serv_address, int serv_size )
695{
696 int ret;
697
698 ret = request_command( serv_name, serv_address, serv_size,
699 0, 0, 0 );
700
701 return(ret ? 1 : 0);
702
703}
704
705int dic_cmnd_service_stamped( char *serv_name, void *serv_address, int serv_size )
706{
707 int ret;
708
709 ret = request_command( serv_name, serv_address, serv_size,
710 0, 0, 1 );
711
712 return(ret ? 1 : 0);
713
714}
715
716int dic_cmnd_callback( char *serv_name, void *serv_address, int serv_size,
717 void (*usr_routine)(), dim_long tag )
718{
719 int ret;
720
721 ret = request_command( serv_name, serv_address, serv_size,
722 usr_routine, tag, 0 );
723 return(ret ? 1 : 0);
724}
725
726int dic_cmnd_callback_stamped( char *serv_name, void *serv_address, int serv_size,
727 void (*usr_routine)(), dim_long tag )
728{
729 int ret;
730
731 ret = request_command( serv_name, serv_address, serv_size,
732 usr_routine, tag, 1 );
733 return(ret ? 1 : 0);
734}
735
736int request_command(char *serv_name, void *serv_address, int serv_size,
737 void (*usr_routine)(), dim_long tag, int stamped)
738{
739 int conn_id, ret;
740 register DIC_SERVICE *servp, *testp;
741 int *fillp;
742 int send_command();
743 int end_command();
744 void dim_init_threads(void);
745 int locate_service();
746
747 if(!Threads_off)
748 {
749 dim_init_threads();
750 }
751 {
752 DISABLE_AST
753 /* create a timer queue for timeouts if not yet done */
754 if( !Dic_timer_q ) {
755 conn_arr_create( SRC_DIC );
756 Dic_timer_q = dtq_create();
757 }
758
759 /* store_service */
760 if( !Cmnd_head ) {
761 Cmnd_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE) );
762 dll_init( (DLL *) Cmnd_head );
763 Cmnd_head->serv_id = 0;
764 }
765 if( (servp = locate_command(serv_name)) )
766 {
767 if(!(testp = locate_pending(serv_name)))
768 {
769 if( (conn_id = servp->conn_id) )
770 {
771 if(servp->fill_size > 0)
772 free( servp->fill_address );
773 fillp = serv_address;
774 if(serv_size > 0)
775 {
776 fillp = (int *)malloc((size_t)serv_size);
777 memcpy( (char *)fillp, (char *)serv_address, (size_t)serv_size );
778 }
779 servp->fill_address = fillp;
780 servp->fill_size = serv_size;
781/*
782 servp->fill_address = (int *)serv_address;
783 servp->fill_size = serv_size;
784*/
785 servp->user_routine = usr_routine;
786 servp->tag = tag;
787 ret = send_command(conn_id, servp);
788 end_command(servp, ret);
789 ENABLE_AST
790 return(1);
791 }
792 }
793 }
794 servp = insert_service( COMMAND, 0,
795 serv_name, 0, 0, usr_routine, tag,
796 (int *)serv_address, serv_size,
797 WAITING_DNS_UP, stamped );
798 if( locate_service(servp) <= 0)
799 {
800/*
801 service_tmout( servp->serv_id );
802*/
803 dtq_start_timer( 0, service_tmout, servp->serv_id);
804 }
805 ENABLE_AST
806 }
807 return(-1);
808}
809
810DIC_SERVICE *insert_service( int type, int timeout, char *name, int *address, int size,
811 void (*routine)(), dim_long tag, int *fill_addr, int fill_size,
812 int pending, int stamped)
813{
814 register DIC_SERVICE *newp;
815 int *fillp;
816 int service_id;
817 int tout;
818 float ftout;
819
820 DISABLE_AST
821 newp = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE));
822 newp->pending = 0;
823 strncpy( newp->serv_name, name, (size_t)MAX_NAME );
824 newp->type = type;
825 newp->timeout = timeout;
826 newp->serv_address = address;
827 newp->serv_size = size;
828 newp->user_routine = routine;
829 newp->tag = tag;
830 fillp = fill_addr;
831 if(fill_size > 0)
832 {
833 fillp = (int *)malloc((size_t)fill_size);
834 memcpy( (char *) fillp, (char *) fill_addr, (size_t)fill_size );
835 }
836 newp->fill_address = fillp;
837 newp->fill_size = fill_size;
838 newp->conn_id = 0;
839 newp->format_data[0].par_bytes = 0;
840 newp->next = (DIC_SERVICE *)0;
841 service_id = id_get((void *)newp, SRC_DIC);
842 newp->serv_id = service_id;
843 if( !Service_pend_head )
844 {
845 Service_pend_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE));
846 dll_init( (DLL *) Service_pend_head );
847 Service_pend_head->serv_id = 0;
848 }
849 dll_insert_queue( (DLL *) Service_pend_head, (DLL *)newp );
850 newp->timer_ent = NULL;
851 if(type != MONIT_FIRST)
852 {
853 if( timeout )
854 {
855 tout = timeout;
856 if(type != ONCE_ONLY)
857 {
858 if(tout < 10)
859 tout = 10;
860 ftout = (float)tout * (float)1.5;
861 tout = (int)ftout;
862 }
863 newp->curr_timeout = tout;
864 newp->timer_ent = dtq_add_entry( Dic_timer_q,
865 newp->curr_timeout,
866 service_tmout, newp->serv_id );
867 }
868 }
869 newp->pending = pending;
870 newp->tmout_done = 0;
871 newp->stamped = stamped;
872 newp->time_stamp[0] = 0;
873 newp->time_stamp[1] = 0;
874 newp->quality = 0;
875 newp->def[0] = '\0';
876#ifdef VxWorks
877 newp->tid = taskIdSelf();
878#endif
879 ENABLE_AST
880 return(newp);
881}
882
883
884void modify_service( DIC_SERVICE *servp, int timeout, int *address, int size, void (*routine)(),
885 dim_long tag, int *fill_addr, int fill_size, int stamped)
886{
887 int *fillp;
888
889 if( servp->timer_ent )
890 {
891 dtq_rem_entry( Dic_timer_q, servp->timer_ent );
892 servp->timer_ent = 0;
893 }
894 servp->timeout = timeout;
895 servp->serv_address = address;
896 servp->serv_size = size;
897 servp->user_routine = routine;
898 servp->tag = tag;
899 if(servp->fill_size > 0)
900 free( servp->fill_address );
901 fillp = fill_addr;
902 if(fill_size > 0)
903 {
904 fillp = (int *)malloc((size_t)fill_size);
905 memcpy( (char *) fillp, (char *) fill_addr, (size_t)fill_size );
906 }
907 servp->fill_address = fillp;
908 servp->fill_size = fill_size;
909 servp->stamped = stamped;
910 if(timeout)
911 {
912 servp->curr_timeout = timeout;
913 servp->timer_ent = dtq_add_entry( Dic_timer_q,
914 servp->curr_timeout,
915 service_tmout, servp->serv_id );
916 }
917 else
918 servp->timer_ent = NULL;
919}
920
921void dic_change_address( unsigned serv_id, void *serv_address, int serv_size)
922{
923 register DIC_SERVICE *servp;
924
925 DISABLE_AST
926 if( serv_id == 0 )
927 {
928 ENABLE_AST
929 return;
930 }
931 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
932 servp->serv_address = (int *)serv_address;
933 servp->serv_size = serv_size;
934 ENABLE_AST
935}
936
937int dic_get_quality( unsigned serv_id )
938{
939 register DIC_SERVICE *servp;
940
941 DISABLE_AST
942 if( serv_id == 0 )
943 {
944 if(Current_server)
945 servp = Current_server;
946 else
947 {
948
949 ENABLE_AST
950 return(-1);
951 }
952 }
953 else
954 {
955 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
956 }
957 ENABLE_AST
958 return(servp->quality);
959}
960
961char *dic_get_format( unsigned serv_id )
962{
963 register DIC_SERVICE *servp;
964
965 DISABLE_AST
966 if( serv_id == 0 )
967 {
968 if(Current_server)
969 servp = Current_server;
970 else
971 {
972 ENABLE_AST
973 return((char *) 0);
974 }
975 }
976 else
977 {
978 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
979 }
980 ENABLE_AST
981 return(servp->def);
982}
983
984int dic_get_timestamp( unsigned serv_id, int *secs, int *milisecs )
985{
986 register DIC_SERVICE *servp;
987
988 DISABLE_AST
989 *secs = 0;
990 *milisecs = 0;
991 if( serv_id == 0 )
992 {
993 if(Current_server)
994 servp = Current_server;
995 else
996 {
997 ENABLE_AST
998 return(-1);
999 }
1000 }
1001 else
1002 {
1003 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
1004 }
1005 ENABLE_AST
1006 if(servp->time_stamp[1])
1007 {
1008 *secs = servp->time_stamp[1];
1009 if(((unsigned)servp->time_stamp[0] & 0xFFFF0000) == 0xc0de0000)
1010 *milisecs = servp->time_stamp[0] & 0x0000FFFF;
1011 else
1012 *milisecs = servp->time_stamp[0];
1013 return(1);
1014 }
1015 else
1016 {
1017/*
1018 *secs = 0;
1019 *milisecs = 0;
1020*/
1021 return(0);
1022 }
1023}
1024
1025void dic_release_service( unsigned service_id )
1026{
1027 register DIC_SERVICE *servp;
1028 register int conn_id, pending;
1029 static DIC_PACKET *dic_packet;
1030 static int packet_size = 0;
1031 DIC_DNS_PACKET dic_dns_packet;
1032 register DIC_DNS_PACKET *dic_dns_p = &dic_dns_packet;
1033 SERVICE_REQ *serv_reqp;
1034 int release_service();
1035
1036 DISABLE_AST
1037 if( !packet_size ) {
1038 dic_packet = (DIC_PACKET *)malloc((size_t)DIC_HEADER);
1039 packet_size = DIC_HEADER;
1040 }
1041 if( service_id == 0 )
1042 {
1043 ENABLE_AST
1044 return;
1045 }
1046 servp = (DIC_SERVICE *)id_get_ptr(service_id, SRC_DIC);
1047 if( servp == 0 )
1048 {
1049 ENABLE_AST
1050 return;
1051 }
1052 if(servp->serv_id != (int)service_id)
1053 {
1054 ENABLE_AST
1055 return;
1056 }
1057 pending = servp->pending;
1058 switch( pending )
1059 {
1060 case NOT_PENDING :
1061 conn_id = servp->conn_id;
1062 strncpy(dic_packet->service_name, servp->serv_name, (size_t)MAX_NAME);
1063 dic_packet->type = htovl(DIM_DELETE);
1064 dic_packet->service_id = (int)htovl(service_id);
1065 dic_packet->size = htovl(DIC_HEADER);
1066 dna_write_nowait( conn_id, dic_packet, DIC_HEADER );
1067 release_service( servp );
1068 break;
1069 case WAITING_SERVER_UP :
1070 if( ( servp->type == COMMAND )||( servp->type == ONCE_ONLY ) )
1071 {
1072 servp->pending = DELETED;
1073 break;
1074 }
1075 if( Dns_dic_conn_id > 0) {
1076 dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1077 dic_dns_p->src_type = htovl(SRC_DIC);
1078 serv_reqp = &dic_dns_p->service;
1079 strcpy( serv_reqp->service_name, servp->serv_name );
1080 serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1081 dna_write( Dns_dic_conn_id, dic_dns_p,
1082 sizeof(DIC_DNS_PACKET) );
1083 }
1084 release_service( servp );
1085 break;
1086 case WAITING_CMND_ANSWER :
1087 case WAITING_DNS_UP :
1088 release_service( servp );
1089 break;
1090 case WAITING_DNS_ANSWER :
1091 servp->pending = DELETED;
1092 break;
1093 }
1094 ENABLE_AST
1095}
1096
1097
1098int release_service( DIC_SERVICE *servicep )
1099{
1100 register DIC_SERVICE *servp;
1101 register int conn_id = 0;
1102 register int found = 0;
1103 register DIC_CONNECTION *dic_connp;
1104 char name[MAX_NAME], *ptr;
1105 int id;
1106
1107 id = servicep->serv_id;
1108 servicep->serv_id = 0;
1109 conn_id = servicep->conn_id;
1110 dic_connp = &Dic_conns[conn_id] ;
1111 dll_remove( (DLL *) servicep );
1112 if( servicep->timer_ent )
1113 {
1114 dtq_rem_entry( Dic_timer_q, servicep->timer_ent );
1115 }
1116/*
1117 if(servicep->type != COMMAND)
1118*/
1119 if(servicep->fill_size > 0)
1120 free( servicep->fill_address );
1121 if(strstr(servicep->serv_name,"/RpcOut"))
1122 {
1123 strcpy(name, servicep->serv_name);
1124 }
1125 else
1126 name[0] = '\0';
1127 free( servicep );
1128 if( conn_id && dic_connp->service_head )
1129 {
1130 if( dll_empty((DLL *)dic_connp->service_head) )
1131 {
1132 if( (servp = (DIC_SERVICE *) Cmnd_head) )
1133 {
1134 while( (servp = (DIC_SERVICE *) dll_get_next(
1135 (DLL *) Cmnd_head,
1136 (DLL *) servp)) )
1137 {
1138 if( servp->conn_id == conn_id)
1139 found = 1;
1140 }
1141 }
1142 if( !found)
1143 {
1144 if(Debug_on)
1145 {
1146 dim_print_date_time();
1147 printf("Conn %d, Server %s on node %s released\n",
1148 conn_id, dic_connp->task_name, dic_connp->node_name);
1149 fflush(stdout);
1150 }
1151 release_conn( conn_id );
1152 }
1153 }
1154 }
1155 if(name[0])
1156 {
1157 ptr = strstr(name,"/RpcOut");
1158 strcpy(ptr + 4, "In");
1159 if( (servp = locate_command(name)) )
1160 release_service(servp);
1161 }
1162 id_free(id, SRC_DIC);
1163 return(1);
1164}
1165
1166
1167int locate_service( DIC_SERVICE *servp )
1168{
1169 extern int open_dns(dim_long, void (*)(), void (*)(), int, int, int);
1170
1171 if(!strcmp(servp->serv_name,"DIS_DNS/SERVER_INFO"))
1172 {
1173 Tmout_min = DID_DNS_TMOUT_MIN;
1174 Tmout_max = DID_DNS_TMOUT_MAX;
1175 }
1176 if(Tmout_min == 0)
1177 {
1178 Tmout_min = DIC_DNS_TMOUT_MIN;
1179 Tmout_max = DIC_DNS_TMOUT_MAX;
1180 }
1181 if( !Dns_dic_conn_id )
1182 {
1183 DISABLE_AST;
1184 Dns_dic_conn_id = open_dns( 0, recv_dns_dic_rout, error_handler,
1185 Tmout_min,
1186 Tmout_max,
1187 SRC_DIC);
1188 if(Dns_dic_conn_id == -2)
1189 error_handler(0, DIM_FATAL, DIMDNSUNDEF, "DIM_DNS_NODE undefined");
1190 ENABLE_AST;
1191 }
1192 if( Dns_dic_conn_id > 0)
1193 {
1194 DISABLE_AST;
1195 request_dns_info(servp->prev->serv_id);
1196 ENABLE_AST;
1197 }
1198
1199 return(Dns_dic_conn_id);
1200}
1201
1202DIC_SERVICE *locate_command( char *serv_name )
1203{
1204 register DIC_SERVICE *servp;
1205
1206 if(!Cmnd_head)
1207 return((DIC_SERVICE *)0);
1208 if( (servp = (DIC_SERVICE *) dll_search( (DLL *) Cmnd_head, serv_name,
1209 (int)strlen(serv_name)+1)) )
1210 return(servp);
1211 return((DIC_SERVICE *)0);
1212}
1213
1214DIC_SERVICE *locate_pending( char *serv_name )
1215{
1216 register DIC_SERVICE *servp;
1217
1218 if(!Service_pend_head)
1219 return((DIC_SERVICE *)0);
1220 if( (servp = (DIC_SERVICE *) dll_search( (DLL *) Service_pend_head, serv_name,
1221 (int)strlen(serv_name)+1)) )
1222 return(servp);
1223 return((DIC_SERVICE *)0);
1224}
1225
1226DIC_BAD_CONNECTION *locate_bad(char *node, char *task, int port)
1227{
1228 DIC_BAD_CONNECTION *bad_connp;
1229
1230 if(!Bad_connection_head)
1231 return((DIC_BAD_CONNECTION *)0);
1232 bad_connp = Bad_connection_head;
1233 while( (bad_connp = (DIC_BAD_CONNECTION *) dll_get_next(
1234 (DLL *) Bad_connection_head,
1235 (DLL *) bad_connp)) )
1236 {
1237 if((!strcmp(bad_connp->conn.node_name, node)) &&
1238 (!strcmp(bad_connp->conn.task_name, task)) &&
1239 (bad_connp->conn.port == port) )
1240 return(bad_connp);
1241 }
1242 return((DIC_BAD_CONNECTION *)0);
1243}
1244
1245static void request_dns_info(int id)
1246{
1247 DIC_SERVICE *servp, *ptr;
1248 int n_pend = 0;
1249 int request_dns_single_info();
1250 extern int open_dns();
1251
1252 DISABLE_AST
1253 if( Dns_dic_conn_id <= 0)
1254 {
1255 Dns_dic_conn_id = open_dns( 0, recv_dns_dic_rout, error_handler,
1256 Tmout_min,
1257 Tmout_max,
1258 SRC_DIC);
1259 if(Dns_dic_conn_id == -2)
1260 error_handler(0, DIM_FATAL, DIMDNSUNDEF, "DIM_DNS_NODE undefined");
1261 }
1262 if( Dns_dic_conn_id > 0)
1263 {
1264 servp = Service_pend_head;
1265 if(id > 0)
1266 {
1267 ptr = (DIC_SERVICE *)id_get_ptr(id, SRC_DIC);
1268 if(ptr)
1269 {
1270 if((ptr->serv_id == id) && (ptr->pending != NOT_PENDING))
1271 servp = ptr;
1272 }
1273 }
1274
1275 while( (servp = (DIC_SERVICE *) dll_get_next(
1276 (DLL *) Service_pend_head,
1277 (DLL *) servp)) )
1278 {
1279 if( servp->pending == WAITING_DNS_UP)
1280 {
1281 if(!request_dns_single_info( servp ))
1282 {
1283 ENABLE_AST
1284 return;
1285 }
1286 n_pend++;
1287 }
1288 if(n_pend == 1000)
1289 {
1290 dtq_start_timer( 0, request_dns_info, servp->serv_id);
1291 ENABLE_AST
1292 return;
1293 }
1294 }
1295 }
1296 else
1297 {
1298 servp = Service_pend_head;
1299 while( (servp = (DIC_SERVICE *) dll_get_next(
1300 (DLL *) Service_pend_head,
1301 (DLL *) servp)) )
1302 {
1303 if( servp->pending == WAITING_DNS_UP)
1304 {
1305 if(( servp->type != COMMAND )&&( servp->type != ONCE_ONLY ))
1306 service_tmout( servp->serv_id );
1307 }
1308 }
1309 }
1310 ENABLE_AST
1311}
1312
1313
1314int request_dns_single_info( DIC_SERVICE *servp )
1315{
1316 static DIC_DNS_PACKET Dic_dns_packet;
1317 static SERVICE_REQ *serv_reqp;
1318 int ret = 1;
1319
1320 if( Dns_dic_conn_id > 0)
1321 {
1322 if(Debug_on)
1323 {
1324 dim_print_date_time();
1325 printf("Requesting DNS Info for %s, id %d\n",
1326 servp->serv_name, servp->serv_id);
1327 }
1328
1329 Dic_dns_packet.src_type = htovl(SRC_DIC);
1330 serv_reqp = &Dic_dns_packet.service;
1331 strcpy( serv_reqp->service_name, servp->serv_name );
1332 serv_reqp->service_id = htovl(servp->serv_id);
1333 servp->pending = WAITING_DNS_ANSWER;
1334 Dic_dns_packet.size = htovl(sizeof(DIC_DNS_PACKET));
1335 if(!dna_write( Dns_dic_conn_id, &Dic_dns_packet,
1336 sizeof(DIC_DNS_PACKET) ) )
1337 {
1338 ret = 0;
1339 }
1340
1341 }
1342 return ret;
1343}
1344
1345
1346static int handle_dns_info( DNS_DIC_PACKET *packet )
1347{
1348 int conn_id, service_id;
1349 DIC_SERVICE *servp;
1350 char *node_name, *task_name;
1351 char node_info[MAX_NODE_NAME+4];
1352 int i, port, protocol, format, pid;
1353 register DIC_CONNECTION *dic_connp ;
1354 DIC_DNS_PACKET dic_dns_packet;
1355 register DIC_DNS_PACKET *dic_dns_p = &dic_dns_packet;
1356 SERVICE_REQ *serv_reqp;
1357 DIC_BAD_CONNECTION *bad_connp;
1358 int retrying = 0;
1359 int tmout;
1360 int send_service_command();
1361 int find_connection();
1362 void move_to_bad_service();
1363 void retry_bad_connection();
1364
1365 service_id = vtohl(packet->service_id);
1366
1367 servp = (DIC_SERVICE *)id_get_ptr(service_id, SRC_DIC);
1368 if(!servp)
1369 return(0);
1370 if(servp->serv_id != service_id)
1371 return(0);
1372 if(Debug_on)
1373 {
1374 dim_print_date_time();
1375 printf("Receiving DNS Info for service %s, id %d\n",servp->serv_name,
1376 vtohl(packet->service_id));
1377 }
1378 node_name = packet->node_name;
1379 if(node_name[0] == (char)0xFF)
1380 {
1381 error_handler(0, DIM_FATAL, DIMDNSREFUS, "DIM_DNS refuses connection");
1382 return(0);
1383 }
1384
1385 task_name = packet->task_name;
1386 strcpy(node_info,node_name);
1387 for(i = 0; i < 4; i ++)
1388 node_info[(int)strlen(node_name)+i+1] = packet->node_addr[i];
1389 port = vtohl(packet->port);
1390 pid = vtohl(packet->pid);
1391 protocol = vtohl(packet->protocol);
1392 format = vtohl(packet->format);
1393
1394 if( Dns_dic_timr )
1395 dtq_clear_entry( Dns_dic_timr );
1396 if( servp->pending == DELETED ) {
1397 if( Dns_dic_conn_id > 0) {
1398 dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1399 dic_dns_p->src_type = htovl(SRC_DIC);
1400 serv_reqp = &dic_dns_p->service;
1401 strcpy( serv_reqp->service_name, servp->serv_name );
1402 serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1403 dna_write( Dns_dic_conn_id, dic_dns_p,
1404 sizeof(DIC_DNS_PACKET) );
1405 }
1406 release_service( servp );
1407 return(0);
1408 }
1409 if( !node_name[0] )
1410 {
1411 servp->pending = WAITING_SERVER_UP;
1412 service_tmout( servp->serv_id );
1413 if( servp->pending == DELETED )
1414 {
1415 if( Dns_dic_conn_id > 0)
1416 {
1417 dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1418 dic_dns_p->src_type = htovl(SRC_DIC);
1419 serv_reqp = &dic_dns_p->service;
1420 strcpy( serv_reqp->service_name, servp->serv_name );
1421 serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1422 dna_write( Dns_dic_conn_id, dic_dns_p,
1423 sizeof(DIC_DNS_PACKET) );
1424 }
1425 release_service( servp );
1426 }
1427 return(0);
1428 }
1429#ifdef OSK
1430 {
1431 register char *ptr;
1432
1433 if(strncmp(node_name,"fidel",5))
1434 {
1435 for(ptr = node_name; *ptr; ptr++)
1436 {
1437 if(*ptr == '.')
1438 {
1439 *ptr = '\0';
1440 break;
1441 }
1442 }
1443 }
1444 }
1445#endif
1446 if( !(conn_id = find_connection(node_name, task_name, port)) )
1447 {
1448 bad_connp = locate_bad(node_name, task_name, port);
1449 if(bad_connp)
1450 retrying = bad_connp->retrying;
1451 if((!bad_connp) || (retrying))
1452 {
1453 if( (conn_id = dna_open_client(node_info, task_name, port,
1454 protocol, recv_rout, error_handler, SRC_DIC)) )
1455 {
1456/*
1457#ifndef VxWorks
1458 if(format & MY_OS9)
1459 {
1460 dna_set_test_write(conn_id, TEST_TIME_OSK);
1461 format &= 0xfffff7ff;
1462 }
1463 else
1464 {
1465 dna_set_test_write(conn_id, TEST_TIME_VMS);
1466 }
1467#endif
1468*/
1469 dna_set_test_write(conn_id, dim_get_keepalive_timeout());
1470 dic_connp = &Dic_conns[conn_id];
1471 strncpy( dic_connp->node_name, node_name,
1472 (size_t)MAX_NODE_NAME);
1473 strncpy( dic_connp->task_name, task_name,
1474 (size_t)MAX_TASK_NAME);
1475 dic_connp->port = port;
1476 dic_connp->pid = pid;
1477 if(Debug_on)
1478 {
1479 dim_print_date_time();
1480 printf("Conn %d, Server %s on node %s Connecting\n",
1481 conn_id, dic_connp->task_name, dic_connp->node_name);
1482 fflush(stdout);
1483 }
1484
1485 dic_connp->service_head =
1486 malloc(sizeof(DIC_SERVICE));
1487 dll_init( (DLL *) dic_connp->service_head);
1488 ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
1489 if(retrying)
1490 {
1491 dll_remove((DLL *)bad_connp->conn.service_head);
1492 free(bad_connp->conn.service_head);
1493 dll_remove((DLL *)bad_connp);
1494 free(bad_connp);
1495 }
1496 }
1497 else
1498 {
1499 if(!retrying)
1500 {
1501 if( !Bad_connection_head )
1502 {
1503 Bad_connection_head = (DIC_BAD_CONNECTION *) malloc(sizeof(DIC_BAD_CONNECTION));
1504 dll_init( (DLL *) Bad_connection_head );
1505 Bad_connection_head->conn.service_head = 0;
1506 }
1507 bad_connp = (DIC_BAD_CONNECTION *) malloc(sizeof(DIC_BAD_CONNECTION));
1508 bad_connp->n_retries = 0;
1509 bad_connp->conn.service_head = malloc(sizeof(DIC_SERVICE));
1510 dll_init( (DLL *) bad_connp->conn.service_head);
1511
1512 dll_insert_queue( (DLL *) Bad_connection_head, (DLL *) bad_connp );
1513 if(Debug_on)
1514 {
1515 dim_print_date_time();
1516 printf("Failed connecting to Server %s on node %s port %d\n",
1517 task_name, node_name, port);
1518 fflush(stdout);
1519 }
1520 service_tmout( servp->serv_id );
1521 }
1522 bad_connp->n_retries++;
1523 bad_connp->retrying = 0;
1524 strncpy( bad_connp->conn.node_name, node_name, (size_t)MAX_NODE_NAME);
1525 strncpy( bad_connp->conn.task_name, task_name, (size_t)MAX_TASK_NAME);
1526 bad_connp->conn.port = port;
1527 tmout = BAD_CONN_TIMEOUT * (bad_connp->n_retries - 1);
1528 if(tmout > 120)
1529 tmout = 120;
1530/* Can not be 0, the callback of dtq_start_timer(0) is not protected */
1531 if(tmout == 0)
1532 tmout = 1;
1533 dtq_start_timer(tmout, retry_bad_connection, (dim_long)bad_connp);
1534 if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
1535 return(0);
1536 move_to_bad_service(servp, bad_connp);
1537/*
1538 ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
1539
1540 servp = Service_pend_head;
1541 while( (servp = (DIC_SERVICE *) dll_get_next(
1542 (DLL *) Service_pend_head,
1543 (DLL *) servp)) )
1544 {
1545 if( (servp->pending == WAITING_DNS_ANSWER) ||
1546 (servp->pending == WAITING_SERVER_UP))
1547 servp->pending = WAITING_DNS_UP;
1548 }
1549 dna_close( Dns_dic_conn_id );
1550 Dns_dic_conn_id = 0;
1551 request_dns_info(0);
1552*/
1553 return(0);
1554 }
1555 }
1556 else
1557 {
1558 if(!retrying)
1559 service_tmout( servp->serv_id );
1560 if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
1561 return(0);
1562 move_to_bad_service(servp, bad_connp);
1563 return(0);
1564 }
1565 }
1566 strcpy(servp->def, packet->service_def);
1567 get_format_data(format, servp->format_data, servp->def);
1568 servp->format = format;
1569 servp->conn_id = conn_id;
1570
1571 send_service_command( servp );
1572/*
1573 if( ret == 1)
1574 {
1575 if(servp->pending != WAITING_CMND_ANSWER)
1576 servp->pending = NOT_PENDING;
1577 servp->tmout_done = 0;
1578 }
1579*/
1580 return(1);
1581}
1582
1583void retry_bad_connection(DIC_BAD_CONNECTION *bad_connp)
1584{
1585DIC_SERVICE *servp, *auxp;
1586int found = 0;
1587void move_to_notok_service();
1588
1589 if(!bad_connp)
1590 return;
1591 servp = (DIC_SERVICE *)bad_connp->conn.service_head;
1592 while( (servp = (DIC_SERVICE *) dll_get_next(
1593 (DLL *) bad_connp->conn.service_head,
1594 (DLL *) servp)) )
1595 {
1596/*
1597 servp->pending = WAITING_DNS_UP;
1598 servp->conn_id = 0;
1599*/
1600 auxp = servp->prev;
1601 move_to_notok_service( servp );
1602 servp = auxp;
1603 found = 1;
1604 }
1605 bad_connp->retrying = 1;
1606 if(found)
1607 request_dns_info(0);
1608}
1609
1610void move_to_ok_service( DIC_SERVICE *servp, int conn_id )
1611{
1612 if(Dic_conns[conn_id].service_head)
1613 {
1614 DISABLE_AST
1615/*
1616printf("move_to_ok %s\n",servp->serv_name);
1617*/
1618 servp->pending = NOT_PENDING;
1619 servp->tmout_done = 0;
1620 dll_remove( (DLL *) servp );
1621 dll_insert_queue( (DLL *) Dic_conns[conn_id].service_head,
1622 (DLL *) servp );
1623 ENABLE_AST
1624 }
1625}
1626
1627void move_to_bad_service( DIC_SERVICE *servp, DIC_BAD_CONNECTION *bad_connp)
1628{
1629 DISABLE_AST
1630/*
1631printf("move_to_bad %s\n",servp->serv_name);
1632*/
1633 servp->pending = WAITING_DNS_UP;
1634 dll_remove( (DLL *) servp );
1635 dll_insert_queue( (DLL *) bad_connp->conn.service_head, (DLL *) servp );
1636 ENABLE_AST
1637}
1638
1639void move_to_cmnd_service( DIC_SERVICE *servp )
1640{
1641/*
1642 if(servp->pending != WAITING_CMND_ANSWER)
1643*/
1644 DISABLE_AST
1645/*
1646printf("move_to_cmnd %s\n",servp->serv_name);
1647*/
1648 servp->pending = NOT_PENDING;
1649 servp->tmout_done = 0;
1650 dll_remove( (DLL *) servp );
1651 dll_insert_queue( (DLL *) Cmnd_head, (DLL *) servp );
1652 ENABLE_AST
1653}
1654
1655void move_to_notok_service(DIC_SERVICE *servp )
1656{
1657 DISABLE_AST
1658/*
1659printf("move_to_notok %s\n",servp->serv_name);
1660*/
1661 servp->pending = WAITING_DNS_UP;
1662 servp->conn_id = 0;
1663 dll_remove( (DLL *) servp );
1664 dll_insert_queue( (DLL *) Service_pend_head, (DLL *) servp );
1665 ENABLE_AST
1666}
1667
1668static void get_format_data(int format, FORMAT_STR *format_data, char *def)
1669{
1670 register FORMAT_STR *formatp = format_data;
1671 register char code, last_code = 0;
1672 int num;
1673 char *ptr = def;
1674
1675 if(format){}
1676 while(*ptr)
1677 {
1678 switch(*ptr)
1679 {
1680 case 'i':
1681 case 'I':
1682 case 'l':
1683 case 'L':
1684 *ptr = 'I';
1685 break;
1686 case 'x':
1687 case 'X':
1688 *ptr = 'X';
1689 break;
1690 case 's':
1691 case 'S':
1692 *ptr = 'S';
1693 break;
1694 case 'f':
1695 case 'F':
1696 *ptr = 'F';
1697 break;
1698 case 'd':
1699 case 'D':
1700 *ptr = 'D';
1701 break;
1702 case 'c':
1703 case 'C':
1704 *ptr = 'C';
1705 break;
1706 }
1707 ptr++;
1708 }
1709 code = *def;
1710 while(*def)
1711 {
1712 if(code != last_code)
1713 {
1714 formatp->par_num = 0;
1715 formatp->flags = 0;
1716 switch(code)
1717 {
1718 case 'i':
1719 case 'I':
1720 case 'l':
1721 case 'L':
1722 formatp->par_bytes = SIZEOF_LONG;
1723 formatp->flags |= SWAPL;
1724 break;
1725 case 'x':
1726 case 'X':
1727 formatp->par_bytes = SIZEOF_DOUBLE;
1728 formatp->flags |= SWAPD;
1729 break;
1730 case 's':
1731 case 'S':
1732 formatp->par_bytes = SIZEOF_SHORT;
1733 formatp->flags |= SWAPS;
1734 break;
1735 case 'f':
1736 case 'F':
1737 formatp->par_bytes = SIZEOF_LONG;
1738 formatp->flags |= SWAPL;
1739#ifdef vms
1740/*
1741 if((format & 0xF0) != (MY_FORMAT & 0xF0))
1742*/
1743 formatp->flags |= (format & 0xF0);
1744 formatp->flags |= IT_IS_FLOAT;
1745#endif
1746 break;
1747 case 'd':
1748 case 'D':
1749 formatp->par_bytes = SIZEOF_DOUBLE;
1750 formatp->flags |= SWAPD;
1751#ifdef vms
1752/*
1753 if((format & 0xF0) != (MY_FORMAT & 0xF0))
1754*/
1755 formatp->flags |= (format & 0xF0);
1756 formatp->flags |= IT_IS_FLOAT;
1757#endif
1758 break;
1759 case 'c':
1760 case 'C':
1761 case 'b':
1762 case 'B':
1763 case 'v':
1764 case 'V':
1765 formatp->par_bytes = SIZEOF_CHAR;
1766 formatp->flags |= NOSWAP;
1767 break;
1768 }
1769 }
1770 def++;
1771 if(*def != ':')
1772 {
1773/* tested by the server
1774 if(*def)
1775 {
1776 printf("Bad service definition parsing\n");
1777 fflush(stdout);
1778 }
1779 else
1780*/
1781 formatp->par_num = 0;
1782 }
1783 else
1784 {
1785 def++;
1786 sscanf(def,"%d",&num);
1787 formatp->par_num += num;
1788 while((*def != ';') && (*def != '\0'))
1789 def++;
1790 if(*def)
1791 def++;
1792 }
1793 last_code = code;
1794 code = *def;
1795 if(code != last_code)
1796 formatp++;
1797 }
1798 formatp->par_bytes = 0;
1799/*
1800 if((format & 0xF) == (MY_FORMAT & 0xF))
1801 {
1802 for(i = 0, formatp = format_data; i<index;i++, formatp++)
1803 formatp->flags &= 0xF0;
1804 }
1805*/
1806}
1807
1808int end_command(DIC_SERVICE *servp, int ret)
1809{
1810 DIC_SERVICE *aux_servp;
1811 DIC_CONNECTION *dic_connp;
1812
1813 DISABLE_AST
1814 dic_connp = &Dic_conns[servp->conn_id];
1815 if(servp->pending != WAITING_CMND_ANSWER)
1816 {
1817 if((!ret) || (!dic_connp->service_head))
1818 {
1819 servp->pending = WAITING_DNS_UP;
1820 dic_release_service( (unsigned)servp->serv_id );
1821 }
1822 else
1823 {
1824 aux_servp = locate_command(servp->serv_name);
1825 if( !aux_servp )
1826 {
1827 move_to_cmnd_service( servp );
1828 }
1829 else
1830 {
1831 if(aux_servp != servp)
1832 {
1833 servp->pending = WAITING_DNS_UP;
1834 dic_release_service( (unsigned)servp->serv_id );
1835 }
1836 }
1837 }
1838 }
1839 ENABLE_AST
1840 return(ret);
1841}
1842
1843int send_service_command(DIC_SERVICE *servp)
1844{
1845 int ret = 1;
1846 int conn_id;
1847 int send_command();
1848 int send_service();
1849
1850 conn_id = servp->conn_id;
1851 if( servp->type == COMMAND )
1852 {
1853 ret = send_command(conn_id, servp);
1854 end_command(servp, ret);
1855 }
1856 else
1857 {
1858 if( send_service(conn_id, servp))
1859 {
1860 if( servp->type == ONCE_ONLY )
1861 {
1862 if( !locate_command(servp->serv_name) )
1863 {
1864 move_to_cmnd_service( servp );
1865 }
1866 }
1867 else
1868 move_to_ok_service( servp, conn_id );
1869 }
1870 else
1871 {
1872 if( servp->type == ONCE_ONLY )
1873 {
1874 servp->pending = WAITING_DNS_UP;
1875 dic_release_service( (unsigned)servp->serv_id );
1876 }
1877 else
1878 {
1879 servp->pending = WAITING_DNS_UP;
1880 servp->conn_id = 0;
1881/*
1882 release_conn(conn_id);
1883*/
1884 request_dns_info(0);
1885 }
1886 }
1887 }
1888 return(ret);
1889}
1890
1891int send_service(int conn_id, DIC_SERVICE *servp)
1892{
1893 static DIC_PACKET *dic_packet;
1894 static int serv_packet_size = 0;
1895 int type, ret;
1896
1897 if( !serv_packet_size ) {
1898 dic_packet = (DIC_PACKET *)malloc((size_t)DIC_HEADER);
1899 serv_packet_size = DIC_HEADER;
1900 }
1901
1902 strncpy( dic_packet->service_name, servp->serv_name, (size_t)MAX_NAME );
1903 type = servp->type;
1904 if(servp->stamped)
1905 type |= STAMPED;
1906 dic_packet->type = htovl(type);
1907 dic_packet->timeout = htovl(servp->timeout);
1908 dic_packet->service_id = htovl(servp->serv_id);
1909 dic_packet->format = htovl(MY_FORMAT);
1910 dic_packet->size = htovl(DIC_HEADER);
1911 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER);
1912 if(!ret)
1913 {
1914 dim_print_date_time();
1915 printf(" Client Sending Service Request: Couldn't write to Conn %3d : Server %s@%s service %s\n",
1916 conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node, servp->serv_name);
1917 fflush(stdout);
1918 }
1919 return(ret);
1920}
1921
1922typedef struct
1923{
1924 int ret_code;
1925 int serv_id;
1926} CMNDCB_ITEM;
1927
1928void do_cmnd_callback(CMNDCB_ITEM *itemp)
1929{
1930
1931 DIC_SERVICE *servp;
1932 int ret, serv_id;
1933/*
1934 itemp = (CMNDCB_ITEM *)id_get_ptr(id, SRC_DIC);
1935*/
1936 serv_id = itemp->serv_id;
1937 ret = itemp->ret_code;
1938 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
1939 if(servp)
1940 {
1941 if(servp->serv_id == serv_id)
1942 {
1943 Curr_conn_id = servp->conn_id;
1944 (servp->user_routine)( &servp->tag, &ret );
1945 servp->pending = NOT_PENDING;
1946 end_command(servp, ret);
1947 Curr_conn_id = 0;
1948 }
1949 }
1950/*
1951 id_free(id, SRC_DIC);
1952*/
1953 free(itemp);
1954}
1955
1956int send_command(int conn_id, DIC_SERVICE *servp)
1957{
1958 static DIC_PACKET *dic_packet;
1959 static int cmnd_packet_size = 0;
1960 register int size;
1961 int ret;
1962 CMNDCB_ITEM *itemp;
1963
1964 size = servp->fill_size;
1965
1966 if(size < 0)
1967 return(1);
1968
1969 if( !cmnd_packet_size ) {
1970 dic_packet = (DIC_PACKET *)malloc((size_t)(DIC_HEADER + size));
1971 cmnd_packet_size = DIC_HEADER + size;
1972 }
1973 else
1974 {
1975 if( DIC_HEADER + size > cmnd_packet_size ) {
1976 free( dic_packet );
1977 dic_packet = (DIC_PACKET *)malloc((size_t)(DIC_HEADER + size));
1978 cmnd_packet_size = DIC_HEADER + size;
1979 }
1980 }
1981
1982 strncpy(dic_packet->service_name, servp->serv_name, (size_t)MAX_NAME);
1983 dic_packet->type = htovl(COMMAND);
1984 dic_packet->timeout = htovl(0);
1985 dic_packet->format = htovl(MY_FORMAT);
1986
1987 dic_packet->service_id = /*id_get((void *)servp)*/servp->serv_id;
1988
1989 size = copy_swap_buffer_out(servp->format, servp->format_data,
1990 dic_packet->buffer, servp->fill_address,
1991 size);
1992 dic_packet->size = htovl( size + DIC_HEADER);
1993 if( servp->user_routine )
1994 {
1995 servp->pending = WAITING_CMND_ANSWER;
1996 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
1997 itemp = (CMNDCB_ITEM *)malloc(sizeof(CMNDCB_ITEM));
1998 itemp->serv_id = servp->serv_id;
1999 itemp->ret_code = ret;
2000/*
2001 id = id_get((void *)itemp, SRC_DIC);
2002*/
2003 dtq_start_timer(0, do_cmnd_callback, (dim_long)itemp);
2004/*
2005 (servp->user_routine)( &servp->tag, &ret );
2006*/
2007 }
2008 else
2009 {
2010 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
2011 }
2012/*
2013 if(!ret)
2014 {
2015 servp->pending = WAITING_DNS_UP;
2016 dic_release_service( (unsigned)servp->serv_id );
2017 }
2018*/
2019 /*
2020 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
2021 if(!ret)
2022 {
2023 servp->pending = WAITING_DNS_UP;
2024 dic_release_service( (unsigned)servp->serv_id );
2025 }
2026 else
2027 {
2028 dim_usleep(5000);
2029 if( servp->user_routine )
2030 (servp->user_routine)( &servp->tag, &ret );
2031 }
2032*/
2033 if(!ret)
2034 {
2035 dim_print_date_time();
2036 printf(" Client Sending Command: Couldn't write to Conn %3d : Server %s@%s\n",conn_id,
2037 Net_conns[conn_id].task, Net_conns[conn_id].node);
2038 fflush(stdout);
2039 }
2040 return(ret);
2041}
2042
2043int find_connection(char *node, char *task, int port)
2044{
2045 register int i;
2046 register DIC_CONNECTION *dic_connp;
2047
2048 if(task){}
2049 for( i=0, dic_connp = Dic_conns; i<Curr_N_Conns; i++, dic_connp++ )
2050 {
2051/*
2052 if((!strcmp(dic_connp->task_name, task))
2053 &&(!strcmp(dic_connp->node_name, node)))
2054*/
2055 if((!strcmp(dic_connp->node_name, node))
2056 && (dic_connp->port == port))
2057 return(i);
2058 }
2059 return(0);
2060}
2061
2062int dic_get_id(char *name)
2063{
2064 extern int get_proc_name(char *name);
2065
2066 get_proc_name(name);
2067 strcat(name,"@");
2068 get_node_name(&name[(int)strlen(name)]);
2069 return(1);
2070}
2071
2072#ifdef VxWorks
2073void dic_destroy(int tid)
2074{
2075 register int i;
2076 register DIC_CONNECTION *dic_connp;
2077 register DIC_SERVICE *servp, *auxp;
2078 int found = 0;
2079
2080 if(!Dic_conns)
2081 return;
2082 for( i=0, dic_connp = Dic_conns; i<Curr_N_Conns; i++, dic_connp++ )
2083 {
2084 if(servp = (DIC_SERVICE *) dic_connp->service_head)
2085 {
2086 while( servp = (DIC_SERVICE *) dll_get_next(
2087 (DLL *) dic_connp->service_head,
2088 (DLL *) servp) )
2089 {
2090 if( servp->tid == tid )
2091 {
2092 auxp = servp->prev;
2093 dic_release_service( (unsigned)servp->serv_id );
2094 servp = auxp;
2095 if(!dic_connp->service_head)
2096 break;
2097 }
2098 else
2099 found = 1;
2100 }
2101 }
2102 }
2103 if(!found)
2104 {
2105 if(Dns_dic_conn_id > 0)
2106 {
2107 dna_close( Dns_dic_conn_id );
2108 Dns_dic_conn_id = 0;
2109 }
2110 }
2111}
2112
2113void DIMDestroy(int tid)
2114{
2115 dis_destroy(tid);
2116 dic_destroy(tid);
2117}
2118
2119#endif
2120
2121static void release_conn(int conn_id)
2122{
2123 register DIC_CONNECTION *dic_connp = &Dic_conns[conn_id];
2124
2125 if(Debug_on)
2126 {
2127 dim_print_date_time();
2128 printf("Conn %d, Server %s on node %s completely released\n",
2129 conn_id, dic_connp->task_name, dic_connp->node_name);
2130 fflush(stdout);
2131 }
2132 dic_connp->task_name[0] = '\0';
2133 dic_connp->port = 0;
2134 if(dic_connp->service_head)
2135 {
2136 free((DIC_SERVICE *)dic_connp->service_head);
2137 dic_connp->service_head = (char *)0;
2138 }
2139 dna_close(conn_id);
2140}
2141
2142void dic_close_dns()
2143{
2144 register DIC_SERVICE *servp, *auxp;
2145
2146 if(Dns_dic_conn_id > 0)
2147 {
2148 if( (servp = (DIC_SERVICE *) Cmnd_head) )
2149 {
2150 while( (servp = (DIC_SERVICE *) dll_get_next(
2151 (DLL *) Cmnd_head,
2152 (DLL *) servp)) )
2153 {
2154#ifdef DEBUG
2155 printf("\t%s was in the Command list\n", servp->serv_name);
2156 printf("type = %d, pending = %d\n",servp->type, servp->pending);
2157 fflush(stdout);
2158#endif
2159 auxp = servp->prev;
2160 if( (servp->type == ONCE_ONLY ) &&
2161 (servp->pending == WAITING_SERVER_UP))
2162 {
2163 service_tmout( servp->serv_id );
2164 }
2165 else if( (servp->type == COMMAND ) &&
2166 (servp->pending == WAITING_CMND_ANSWER))
2167 {
2168 service_tmout( servp->serv_id );
2169 }
2170 else
2171 {
2172 servp->pending = WAITING_DNS_UP;
2173 dic_release_service( (unsigned)servp->serv_id );
2174 }
2175 servp = auxp;
2176 }
2177 }
2178 dna_close( Dns_dic_conn_id );
2179 Dns_dic_conn_id = 0;
2180 }
2181}
2182/*
2183append_service(service_info_buffer, servp)
2184char *service_info_buffer;
2185SERVICE *servp;
2186{
2187 char name[MAX_NAME], *ptr;
2188
2189 if(strstr(servp->name,"/RpcIn"))
2190 {
2191 strcpy(name,servp->name);
2192 ptr = (char *)strstr(name,"/RpcIn");
2193 *ptr = 0;
2194 strcat(service_info_buffer, name);
2195 strcat(service_info_buffer, "|");
2196 if(servp->def[0])
2197 {
2198 strcat(service_info_buffer, servp->def);
2199 }
2200 strcat(name,"/RpcOut");
2201 if(servp = find_service(name))
2202 {
2203 strcat(service_info_buffer, ",");
2204 if(servp->def[0])
2205 {
2206 strcat(service_info_buffer, servp->def);
2207 }
2208 }
2209 strcat(service_info_buffer, "|RPC");
2210 strcat(service_info_buffer, "\n");
2211 }
2212 else if(strstr(servp->name,"/RpcOut"))
2213 {
2214 }
2215 else
2216 {
2217 strcat(service_info_buffer, servp->name);
2218 strcat(service_info_buffer, "|");
2219 if(servp->def[0])
2220 {
2221 strcat(service_info_buffer, servp->def);
2222 }
2223 strcat(service_info_buffer, "|");
2224 if(servp->type == COMMAND)
2225 {
2226 strcat(service_info_buffer, "CMD");
2227 }
2228 strcat(service_info_buffer, "\n");
2229 }
2230}
2231*/
2232
2233char *dic_get_error_services()
2234{
2235 return(dic_get_server_services(Error_conn_id));
2236}
2237
2238char *dic_get_server_services(int conn_id)
2239{
2240 DIC_SERVICE *servp;
2241 DIC_CONNECTION *dic_connp;
2242 int n_services = 0;
2243 int max_size;
2244 static int curr_allocated_size = 0;
2245 static char *service_info_buffer;
2246 char *buff_ptr;
2247
2248
2249 if(!conn_id)
2250 return((char *)0);
2251 dic_connp = &Dic_conns[conn_id];
2252 if( (servp = (DIC_SERVICE *) dic_connp->service_head) )
2253 {
2254 while( (servp = (DIC_SERVICE *) dll_get_next(
2255 (DLL *) dic_connp->service_head,
2256 (DLL *) servp)) )
2257 {
2258 n_services++;
2259 }
2260 if(!n_services)
2261 return((char *)0);
2262 max_size = n_services * MAX_NAME;
2263 if(!curr_allocated_size)
2264 {
2265 service_info_buffer = (char *)malloc((size_t)max_size);
2266 curr_allocated_size = max_size;
2267 }
2268 else if (max_size > curr_allocated_size)
2269 {
2270 free(service_info_buffer);
2271 service_info_buffer = (char *)malloc((size_t)max_size);
2272 curr_allocated_size = max_size;
2273 }
2274 service_info_buffer[0] = '\0';
2275 buff_ptr = service_info_buffer;
2276
2277 servp = (DIC_SERVICE *) dic_connp->service_head;
2278 while( (servp = (DIC_SERVICE *) dll_get_next(
2279 (DLL *) dic_connp->service_head,
2280 (DLL *) servp)) )
2281 {
2282 strcat(buff_ptr, servp->serv_name);
2283 strcat(buff_ptr, "\n");
2284 buff_ptr += (int)strlen(buff_ptr);
2285 }
2286 }
2287 else
2288 {
2289 return((char *)0);
2290 }
2291/*
2292 dim_print_date_time();
2293 printf("Server %s@%s provides services:\n",
2294 dic_connp->task_name, dic_connp->node_name);
2295 printf("%s\n",service_info_buffer);
2296*/
2297 return(service_info_buffer);
2298}
2299
2300int dic_get_conn_id()
2301{
2302 return(Curr_conn_id);
2303}
2304
2305int dic_get_server(char *name)
2306{
2307 int ret = 0;
2308 char node[MAX_NODE_NAME], task[MAX_TASK_NAME];
2309
2310 DISABLE_AST
2311
2312 if(Curr_conn_id)
2313 {
2314 dna_get_node_task(Curr_conn_id, node, task);
2315 strcpy(name,task);
2316 strcat(name,"@");
2317 strcat(name,node);
2318 ret = Curr_conn_id;
2319 }
2320 ENABLE_AST
2321 return(ret);
2322}
2323
2324int dic_get_server_pid(int *pid)
2325{
2326 int ret = 0;
2327
2328 DISABLE_AST
2329
2330 *pid = 0;
2331 if(Curr_conn_id)
2332 {
2333 *pid = Dic_conns[Curr_conn_id].pid;
2334 ret = Curr_conn_id;
2335 }
2336 ENABLE_AST
2337 return(ret);
2338}
2339
2340void dic_stop()
2341{
2342 int dic_find_server_conns();
2343
2344 dtq_delete(Dic_timer_q);
2345 dic_close_dns();
2346 if(!dic_find_server_conns())
2347 dim_stop();
2348}
2349
2350int dic_find_server_conns()
2351{
2352 int i;
2353 int n = 0;
2354
2355 for( i = 0; i< Curr_N_Conns; i++ )
2356 {
2357 if(Net_conns[i].channel != 0)
2358 {
2359 if(Dna_conns[i].read_ast == recv_rout)
2360 {
2361 dna_close(i);
2362 }
2363 else
2364 {
2365 n++;
2366 }
2367 }
2368 }
2369 return(n);
2370}
2371
2372#ifdef VMS
2373/* CFORTRAN WRAPPERS */
2374FCALLSCFUN9(INT, dic_info_service, DIC_INFO_SERVICE, dic_info_service,
2375 STRING, INT, INT, PVOID, INT, PVOID, INT, PVOID, INT)
2376FCALLSCFUN9(INT, dic_info_service_stamped, DIC_INFO_SERVICE_STAMPED,
2377 dic_info_service_stamped,
2378 STRING, INT, INT, PVOID, INT, PVOID, INT, PVOID, INT)
2379FCALLSCFUN3(INT, dic_cmnd_service, DIC_CMND_SERVICE, dic_cmnd_service,
2380 STRING, PVOID, INT)
2381FCALLSCFUN5(INT, dic_cmnd_callback, DIC_CMND_CALLBACK, dic_cmnd_callback,
2382 STRING, PVOID, INT, PVOID, INT)
2383FCALLSCFUN3(INT, dic_cmnd_service_stamped, DIC_CMND_SERVICE_STAMPED,
2384 dic_cmnd_service_stamped,
2385 STRING, PVOID, INT)
2386FCALLSCFUN5(INT, dic_cmnd_callback_stamped, DIC_CMND_CALLBACK_STAMPED,
2387 dic_cmnd_callback_stamped,
2388 STRING, PVOID, INT, PVOID, INT)
2389FCALLSCSUB3( dic_change_address, DIC_CHANGE_ADDRESS, dic_change_address,
2390 INT, PVOID, INT)
2391FCALLSCSUB1( dic_release_service, DIC_RELEASE_SERVICE, dic_release_service,
2392 INT)
2393FCALLSCFUN1(INT, dic_get_quality, DIC_GET_QUALITY, dic_get_quality,
2394 INT)
2395FCALLSCFUN3(INT, dic_get_timestamp, DIC_GET_TIMESTAMP, dic_get_timestamp,
2396 INT,PINT,PINT)
2397FCALLSCFUN1(INT, dic_get_id, DIC_GET_ID, dic_get_id,
2398 PSTRING)
2399FCALLSCFUN1(STRING, dic_get_format, DIC_GET_FORMAT, dic_get_format,
2400 INT)
2401#endif
Note: See TracBrowser for help on using the repository browser.