1
//============================================================================
2
// Forwarding of function calls
3
//============================================================================
6
This file is part of Code_Saturne, a general-purpose CFD tool.
8
Copyright (C) 1998-2011 EDF S.A.
10
This program is free software; you can redistribute it and/or modify it under
11
the terms of the GNU General Public License as published by the Free Software
12
Foundation; either version 2 of the License, or (at your option) any later
15
This program is distributed in the hope that it will be useful, but WITHOUT
16
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
20
You should have received a copy of the GNU General Public License along with
21
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
22
Street, Fifth Floor, Boston, MA 02110-1301, USA.
25
#include "cs_config.h"
27
// System and SALOME headers
40
#include "cfd_proxy_defs.h"
41
#include "cfd_proxy_comm.h"
42
#include "cfd_proxy_forward.h"
44
//----------------------------------------------------------------------------
49
} /* Fake brace to force back Emacs auto-indentation back to column 0 */
51
#endif /* __cplusplus */
53
//============================================================================
54
// Constants and Macros
55
//============================================================================
57
//============================================================================
58
// Structure definition
59
//============================================================================
61
//============================================================================
63
//============================================================================
65
//============================================================================
66
// Private function definitions
67
//============================================================================
69
//----------------------------------------------------------------------------
70
// Forward a CALCIUM write call
73
// comm <-> communicator
74
// r <-> container for temporary communication request data
78
// 0 if request was forwarded correctly, -1 for end-of-file, -2 for error
79
//----------------------------------------------------------------------------
82
_forward_calcium_write(cfd_proxy_comm_t *comm,
83
cfd_proxy_comm_request_t *r,
84
cfd_proxy_type_t type)
86
void *component = cfd_proxy_glob_component[r->comp_id];
88
int time_dep = r->int_vals[0];
89
int iteration = r->int_vals[1];
90
int n_vals = r->int_vals[2];
91
double cur_time = r->double_vals[0];
92
float _cur_time = cur_time;
93
char *var_name = r->string_vals;
95
size_t type_size = cfd_proxy_glob_type_size[type];
97
int comm_retval = 0, retval = 0;
101
CFDP_MALLOC(buffer, n_vals*type_size, char);
102
comm_retval = cfd_proxy_comm_read(comm, buffer, type_size, n_vals);
103
if (comm_retval != 0) {
110
case CFD_PROXY_TYPE_int:
111
retval = cp_een(component, time_dep, _cur_time, iteration,
112
var_name, n_vals, (int *)buffer);
114
case CFD_PROXY_TYPE_float:
115
retval = cp_ere(component, time_dep, _cur_time, iteration,
116
var_name, n_vals, (float *)buffer);
118
case CFD_PROXY_TYPE_double:
119
retval = cp_edb(component, time_dep, cur_time, iteration,
120
var_name, n_vals, (double *)buffer);
126
comm_retval = cfd_proxy_comm_write_response(comm, retval, 0, 0, 0,
135
//----------------------------------------------------------------------------
136
// Forward a CALCIUM read call
139
// comm <-> communicator
140
// r <-> container for temporary communication request data
141
// type <-- data type
144
// 0 if request was forwarded correctly, -2 for error
145
//----------------------------------------------------------------------------
148
_forward_calcium_read(cfd_proxy_comm_t *comm,
149
cfd_proxy_comm_request_t *r,
150
cfd_proxy_type_t type)
152
void *component = cfd_proxy_glob_component[r->comp_id];
154
int time_dep = r->int_vals[0];
155
int iteration = r->int_vals[1];
156
int n_vals_max = r->int_vals[2];
158
double min_time = r->double_vals[0];
159
double max_time = r->double_vals[1];
160
float _min_time = min_time;
161
float _max_time = max_time;
162
char *var_name = r->string_vals;
165
double double_out[1];
167
size_t type_size = cfd_proxy_glob_type_size[type];
174
CFDP_MALLOC(buffer, n_vals_max*type_size, char);
177
case CFD_PROXY_TYPE_int:
178
retval = cp_len(component, time_dep, &_min_time, &_max_time, &iteration,
179
var_name, n_vals_max, &n_vals, (int *)buffer);
180
min_time = _min_time;
182
case CFD_PROXY_TYPE_float:
183
retval = cp_lre(component, time_dep, &_min_time, &_max_time, &iteration,
184
var_name, n_vals_max, &n_vals, (float *)buffer);
185
min_time = _min_time;
187
case CFD_PROXY_TYPE_double:
188
retval = cp_ldb(component, time_dep, &min_time, &max_time, &iteration,
189
var_name, n_vals_max, &n_vals, (double *)buffer);
195
int_out[0] = iteration;
197
double_out[0] = min_time;
199
comm_retval = cfd_proxy_comm_write_response(comm, retval, 2, 1, 0,
200
int_out, double_out, NULL);
202
if (n_vals > 0 && retval == 0 && comm_retval == 0)
203
comm_retval = cfd_proxy_comm_write(comm, buffer, type_size, n_vals);
211
//============================================================================
212
// Public function definitions
213
//============================================================================
215
//----------------------------------------------------------------------------
216
// Forward a call from the client and its response.
219
// comm <-> communicator
220
// r <-> container for temporary communication request data
223
// 0 if request was forwarded correctly, -1 for end-of-file, -2 for error
224
//----------------------------------------------------------------------------
227
cfd_proxy_forward(cfd_proxy_comm_t *comm,
228
cfd_proxy_comm_request_t *r)
232
comm_retval = cfd_proxy_comm_read_request(comm, r);
234
if (comm_retval != 0)
237
assert( r->comp_id >= 0
238
&& r->comp_id < cfd_proxy_glob_n_components);
240
// Handle function depending on function name
242
if (strncmp(r->func_name, "cp_e", 4) == 0) {
244
if (strncmp(r->func_name, "cp_een", 32) == 0)
245
comm_retval = _forward_calcium_write(comm, r, CFD_PROXY_TYPE_int);
246
else if (strncmp(r->func_name, "cp_ere", 32) == 0)
247
comm_retval = _forward_calcium_write(comm, r, CFD_PROXY_TYPE_float);
248
else if (strncmp(r->func_name, "cp_edb", 32) == 0)
249
comm_retval = _forward_calcium_write(comm, r, CFD_PROXY_TYPE_double);
252
else if (strncmp(r->func_name, "cp_l", 4) == 0) {
254
if (strncmp(r->func_name, "cp_len", 32) == 0)
255
comm_retval = _forward_calcium_read(comm, r, CFD_PROXY_TYPE_int);
256
else if (strncmp(r->func_name, "cp_lre", 32) == 0)
257
comm_retval = _forward_calcium_read(comm, r, CFD_PROXY_TYPE_float);
258
else if (strncmp(r->func_name, "cp_ldb", 32) == 0)
259
comm_retval = _forward_calcium_read(comm, r, CFD_PROXY_TYPE_double);
263
else if (strncmp(r->func_name, "cp_cd", 32) == 0) {
265
void *component = cfd_proxy_glob_component[r->comp_id];
266
char instance_name[256]; // Normally, INSTANCE_LEN = 72
267
const char *string_vals[] = {instance_name};
270
memset(instance_name, '\0', sizeof(instance_name));
272
retval = cp_cd(component, instance_name);
274
comm_retval = cfd_proxy_comm_write_response(comm, retval, 0, 0, 1,
275
NULL, NULL, string_vals);
279
else if (strncmp(r->func_name, "cp_fin", 32) == 0) {
281
void *component = cfd_proxy_glob_component[r->comp_id];
282
int cont = r->int_vals[0];
285
retval = cp_fin(component, cont);
287
comm_retval = cfd_proxy_comm_write_response(comm, retval, 0, 0, 0,
295
//----------------------------------------------------------------------------
296
// Forward all calls from the client and their responses.
297
//----------------------------------------------------------------------------
300
cfd_proxy_forward_all(cfd_proxy_comm_t *comm)
302
cfd_proxy_comm_request_t r;
309
cfd_proxy_comm_init_request(&r);
311
while (retval == 0) {
313
retval = cfd_proxy_forward(comm, &r);
317
cfd_proxy_comm_finalize_request(&r);
320
//----------------------------------------------------------------------------
324
#endif /* __cplusplus */