1 | void register_services(flag)
|
---|
2 | register int flag;
|
---|
3 | {
|
---|
4 | register DIS_DNS_PACKET *dis_dns_p = &Dis_dns_packet;
|
---|
5 | register int n_services, tot_n_services;
|
---|
6 | register SERVICE *servp;
|
---|
7 | register SERVICE_REG *serv_regp;
|
---|
8 | SERVICE *dis_hash_service_get_next_register();
|
---|
9 | extern int get_node_addr();
|
---|
10 | int dis_hash_service_registered();
|
---|
11 |
|
---|
12 | if(!dis_dns_p->src_type)
|
---|
13 | {
|
---|
14 | get_node_name( dis_dns_p->node_name );
|
---|
15 | /*
|
---|
16 | strcpy( dis_dns_p->task_name, Task_name );
|
---|
17 | */
|
---|
18 | strncpy( dis_dns_p->task_name, Task_name,
|
---|
19 | MAX_TASK_NAME-4 );
|
---|
20 | dis_dns_p->task_name[MAX_TASK_NAME-4-1] = '\0';
|
---|
21 | get_node_addr( dis_dns_p->node_addr );
|
---|
22 | /*
|
---|
23 | dis_dns_p->port = htovl(Port_number);
|
---|
24 | */
|
---|
25 | dis_dns_p->pid = htovl(getpid());
|
---|
26 | dis_dns_p->protocol = htovl(Protocol);
|
---|
27 | dis_dns_p->src_type = htovl(SRC_DIS);
|
---|
28 | dis_dns_p->format = htovl(MY_FORMAT);
|
---|
29 | }
|
---|
30 |
|
---|
31 | dis_dns_p->port = htovl(Port_number);
|
---|
32 | serv_regp = dis_dns_p->services;
|
---|
33 | n_services = 0;
|
---|
34 | tot_n_services = 0;
|
---|
35 | if( flag == NONE ) {
|
---|
36 | dis_dns_p->n_services = htovl(n_services);
|
---|
37 | dis_dns_p->size = htovl( DIS_DNS_HEADER +
|
---|
38 | (n_services*sizeof(SERVICE_REG)));
|
---|
39 | if(Dns_dis_conn_id > 0)
|
---|
40 | {
|
---|
41 | if(!dna_write(Dns_dis_conn_id, &Dis_dns_packet,
|
---|
42 | DIS_DNS_HEADER + n_services*sizeof(SERVICE_REG)))
|
---|
43 | {
|
---|
44 | release_conn(Dns_dis_conn_id,0);
|
---|
45 | }
|
---|
46 | }
|
---|
47 | return;
|
---|
48 | }
|
---|
49 | if(flag == ALL)
|
---|
50 | {
|
---|
51 | servp = 0;
|
---|
52 | while( (servp = dis_hash_service_get_next(servp)))
|
---|
53 | {
|
---|
54 | servp->registered = 0;
|
---|
55 | }
|
---|
56 | }
|
---|
57 | servp = 0;
|
---|
58 | while( (servp = dis_hash_service_get_next_register(servp)))
|
---|
59 | {
|
---|
60 | if( flag == MORE )
|
---|
61 | {
|
---|
62 | if( servp->registered )
|
---|
63 | {
|
---|
64 | continue;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | strcpy( serv_regp->service_name, servp->name );
|
---|
69 | strcpy( serv_regp->service_def, servp->def );
|
---|
70 | if(servp->type == COMMAND)
|
---|
71 | serv_regp->service_id = htovl( servp->id | 0x10000000);
|
---|
72 | else
|
---|
73 | serv_regp->service_id = htovl( servp->id );
|
---|
74 |
|
---|
75 | serv_regp++;
|
---|
76 | n_services++;
|
---|
77 | dis_hash_service_registered(servp);
|
---|
78 | if( n_services == MAX_SERVICE_UNIT )
|
---|
79 | {
|
---|
80 | dis_dns_p->n_services = htovl(n_services);
|
---|
81 | dis_dns_p->size = htovl(DIS_DNS_HEADER +
|
---|
82 | n_services * sizeof(SERVICE_REG));
|
---|
83 | if(Dns_dis_conn_id > 0)
|
---|
84 | {
|
---|
85 | if( !dna_write(Dns_dis_conn_id,
|
---|
86 | &Dis_dns_packet,
|
---|
87 | DIS_DNS_HEADER + n_services *
|
---|
88 | sizeof(SERVICE_REG)) )
|
---|
89 | {
|
---|
90 | release_conn(Dns_dis_conn_id,0);
|
---|
91 | }
|
---|
92 | }
|
---|
93 | serv_regp = dis_dns_p->services;
|
---|
94 | tot_n_services += MAX_SERVICE_UNIT;
|
---|
95 | n_services = 0;
|
---|
96 | continue;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | if( n_services )
|
---|
100 | {
|
---|
101 | dis_dns_p->n_services = htovl(n_services);
|
---|
102 | dis_dns_p->size = htovl(DIS_DNS_HEADER +
|
---|
103 | n_services * sizeof(SERVICE_REG));
|
---|
104 | if(Dns_dis_conn_id > 0)
|
---|
105 | {
|
---|
106 | if( !dna_write(Dns_dis_conn_id, &Dis_dns_packet,
|
---|
107 | DIS_DNS_HEADER + n_services * sizeof(SERVICE_REG)))
|
---|
108 | {
|
---|
109 | release_conn(Dns_dis_conn_id,0);
|
---|
110 | }
|
---|
111 |
|
---|
112 | }
|
---|
113 | tot_n_services += n_services;
|
---|
114 | }
|
---|
115 | if(tot_n_services >= MAX_REGISTRATION_UNIT)
|
---|
116 | {
|
---|
117 | send_dns_update_packet();
|
---|
118 | }
|
---|
119 | }
|
---|