source: trunk/FACT++/dim/src/conn_handler.c@ 13995

Last change on this file since 13995 was 13995, checked in by tbretz, 12 years ago
Switched to v19r35
File size: 4.1 KB
Line 
1/*
2 * DNA (Delphi Network Access) implements the network layer for the DIM
3 * (Delphi Information Managment) System.
4 *
5 * Started date : 10-11-91
6 * Written by : C. Gaspar
7 * UNIX adjustment: G.C. Ballintijn
8 *
9 */
10
11/* This module can only handle one type of array, and DIC or DNS.
12 * It cannot handle both simultaniously. It handles at same time
13 * the NET and DNA array's. Although these have to be explicitly
14 * created.
15 */
16
17#define DIMLIB
18#include <dim.h>
19
20static SRC_TYPES My_type; /* Var. indicating type DIC or DIS */
21
22#ifdef VMS
23DIM_NOSHARE DNS_CONNECTION *Dns_conns;
24DIM_NOSHARE DIC_CONNECTION *Dic_conns;
25DIM_NOSHARE DNA_CONNECTION *Dna_conns;
26DIM_NOSHARE NET_CONNECTION *Net_conns;
27DIM_NOSHARE int Curr_N_Conns;
28#else
29DllExp DIM_NOSHARE DNS_CONNECTION *Dns_conns = 0;
30DIM_NOSHARE DIC_CONNECTION *Dic_conns = 0;
31DllExp DIM_NOSHARE DNA_CONNECTION *Dna_conns = 0;
32DllExp DIM_NOSHARE NET_CONNECTION *Net_conns = 0;
33DllExp DIM_NOSHARE int Curr_N_Conns = 0;
34#endif
35
36typedef struct id_item
37{
38 void *ptr;
39 SRC_TYPES type;
40}ID_ITEM;
41
42static ID_ITEM *Id_arr;
43/*
44static void **Id_arr;
45*/
46static int Curr_N_Ids = 0;
47static int Curr_id = 1;
48
49void conn_arr_create(SRC_TYPES type)
50{
51
52 if( Curr_N_Conns == 0 )
53 Curr_N_Conns = CONN_BLOCK;
54
55 switch(type)
56 {
57 case SRC_DIC :
58 Dic_conns = (DIC_CONNECTION *)
59 calloc( Curr_N_Conns, sizeof(DIC_CONNECTION) );
60 My_type = type;
61 break;
62 case SRC_DNS :
63 Dns_conns = (DNS_CONNECTION *)
64 calloc( Curr_N_Conns, sizeof(DNS_CONNECTION) );
65 My_type = type;
66 break;
67 case SRC_DNA :
68 Dna_conns = (DNA_CONNECTION *)
69 calloc( Curr_N_Conns, sizeof(DNA_CONNECTION) );
70 Net_conns = (NET_CONNECTION *)
71 calloc( Curr_N_Conns, sizeof(NET_CONNECTION) );
72 break;
73 default:
74 break;
75 }
76}
77
78
79int conn_get()
80{
81 register DNA_CONNECTION *dna_connp;
82 int i, n_conns, conn_id;
83
84 DISABLE_AST
85 for( i = 1, dna_connp = &Dna_conns[1]; i < Curr_N_Conns; i++, dna_connp++ )
86 {
87 if( !dna_connp->busy )
88 {
89 dna_connp->busy = TRUE;
90 ENABLE_AST
91 return(i);
92 }
93 }
94 n_conns = Curr_N_Conns + CONN_BLOCK;
95 Dna_conns = arr_increase( Dna_conns, sizeof(DNA_CONNECTION), n_conns );
96 Net_conns = arr_increase( Net_conns, sizeof(NET_CONNECTION), n_conns );
97 switch(My_type)
98 {
99 case SRC_DIC :
100 Dic_conns = arr_increase( Dic_conns, sizeof(DIC_CONNECTION),
101 n_conns );
102 break;
103 case SRC_DNS :
104 Dns_conns = arr_increase( Dns_conns, sizeof(DNS_CONNECTION),
105 n_conns );
106 break;
107 default:
108 break;
109 }
110 conn_id = Curr_N_Conns;
111 Curr_N_Conns = n_conns;
112 Dna_conns[conn_id].busy = TRUE;
113 ENABLE_AST
114 return(conn_id);
115}
116
117
118void conn_free(int conn_id)
119{
120 DISABLE_AST
121 Dna_conns[conn_id].busy = FALSE;
122 ENABLE_AST
123}
124
125
126void *arr_increase(void *conn_ptr, int conn_size, int n_conns)
127{
128 register char *new_ptr;
129
130 new_ptr = realloc( conn_ptr, conn_size * n_conns );
131 memset( new_ptr + conn_size * Curr_N_Conns, 0, conn_size * CONN_BLOCK );
132 return(new_ptr);
133}
134
135void id_arr_create()
136{
137
138 Curr_N_Ids = ID_BLOCK;
139 Id_arr = (void *) calloc( Curr_N_Ids, sizeof(ID_ITEM));
140}
141
142
143void *id_arr_increase(void *id_ptr, int id_size, int n_ids)
144{
145 register char *new_ptr;
146
147 new_ptr = realloc( id_ptr, id_size * n_ids );
148 memset( new_ptr + id_size * Curr_N_Ids, 0, id_size * ID_BLOCK );
149 return(new_ptr);
150}
151
152int id_get(void *ptr, SRC_TYPES type)
153{
154 register int i, id;
155 register ID_ITEM *idp;
156
157 DISABLE_AST
158 if(!Curr_N_Ids)
159 {
160 id_arr_create();
161 }
162 for( i = Curr_id, idp = &Id_arr[Curr_id]; i < Curr_N_Ids; i++, idp++ )
163 {
164 if( !idp->type )
165 {
166 idp->ptr = ptr;
167 idp->type = type;
168 Curr_id = i;
169 ENABLE_AST
170 return(i);
171 }
172 }
173 Id_arr = id_arr_increase( Id_arr, sizeof(ID_ITEM), Curr_N_Ids + ID_BLOCK );
174 id = Curr_N_Ids;
175 idp = &Id_arr[id];
176 idp->ptr = ptr;
177 idp->type = type;
178 Curr_N_Ids += ID_BLOCK;
179 Curr_id = id;
180 ENABLE_AST
181 return(id);
182}
183
184void *id_get_ptr(int id, SRC_TYPES type)
185{
186 ID_ITEM *idp;
187 void *ptr;
188 DISABLE_AST
189
190 if((id >= Curr_N_Ids) || (id <= 0))
191 {
192 ENABLE_AST
193 return(0);
194 }
195 idp = &Id_arr[id];
196 if(idp->type == type)
197 {
198 ptr = idp->ptr;
199 ENABLE_AST
200 return(ptr);
201 }
202 ENABLE_AST
203 return(0);
204}
205
206void id_free(int id, SRC_TYPES type)
207{
208 ID_ITEM *idp;
209 DISABLE_AST
210
211 idp = &Id_arr[id];
212 if(idp->type == type)
213 {
214 idp->type = 0;
215 idp->ptr = 0;
216 }
217 Curr_id = 1;
218 ENABLE_AST
219}
Note: See TracBrowser for help on using the repository browser.