~ubuntu-branches/ubuntu/precise/code-saturne/precise

« back to all changes in this revision

Viewing changes to salome/cfd_proxy/cfd_proxy_comm.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-24 00:00:08 UTC
  • mfrom: (6.1.9 sid)
  • Revision ID: package-import@ubuntu.com-20111124000008-2vo99e38267942q5
Tags: 2.1.0-3
Install a missing file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _CFD_PROXY_COMM_H_
 
2
#define _CFD_PROXY_COMM_H_
 
3
 
 
4
//============================================================================
 
5
// Definitions of base communication functions
 
6
//============================================================================
 
7
 
 
8
/*
 
9
  This file is part of Code_Saturne, a general-purpose CFD tool.
 
10
 
 
11
  Copyright (C) 1998-2011 EDF S.A.
 
12
 
 
13
  This program is free software; you can redistribute it and/or modify it under
 
14
  the terms of the GNU General Public License as published by the Free Software
 
15
  Foundation; either version 2 of the License, or (at your option) any later
 
16
  version.
 
17
 
 
18
  This program is distributed in the hope that it will be useful, but WITHOUT
 
19
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
20
  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
21
  details.
 
22
 
 
23
  You should have received a copy of the GNU General Public License along with
 
24
  this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 
25
  Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
26
*/
 
27
 
 
28
//----------------------------------------------------------------------------
 
29
// System headers
 
30
//----------------------------------------------------------------------------
 
31
 
 
32
//----------------------------------------------------------------------------
 
33
// Local headers
 
34
//----------------------------------------------------------------------------
 
35
 
 
36
#include "cfd_proxy_defs.h"
 
37
 
 
38
//----------------------------------------------------------------------------
 
39
 
 
40
#ifdef __cplusplus
 
41
extern "C" {
 
42
#if 0
 
43
} /* Fake brace to force Emacs auto-indentation back to column 0 */
 
44
#endif
 
45
#endif /* __cplusplus */
 
46
 
 
47
//----------------------------------------------------------------------------
 
48
// Message types
 
49
//----------------------------------------------------------------------------
 
50
 
 
51
typedef enum {
 
52
 
 
53
  CFD_PROXY_COMM_MSG_NONE,       // Not a message
 
54
  CFD_PROXY_COMM_MSG_ABORT,      // Emergency stop
 
55
  CFD_PROXY_COMM_MSG_STOP,       // End of communication
 
56
  CFD_PROXY_COMM_MSG_FORWARD,    // Message to forward
 
57
  CFD_PROXY_COMM_MSG_OTHER       // Undefined message type
 
58
 
 
59
} cfd_proxy_comm_msg_t;
 
60
 
 
61
typedef enum {
 
62
 
 
63
  CFD_PROXY_COMM_TYPE_SOCKET,    // Communicate through sockets
 
64
  CFD_PROXY_COMM_TYPE_NULL       // Null communicator
 
65
 
 
66
} cfd_proxy_comm_type_t;
 
67
 
 
68
//----------------------------------------------------------------------------
 
69
// Macro definitions
 
70
//----------------------------------------------------------------------------
 
71
 
 
72
#define CFD_PROXY_COMM_CMD_ABORT                       "cmd:abort"
 
73
#define CFD_PROXY_COMM_CMD_STOP                         "cmd:stop"
 
74
#define CFD_PROXY_COMM_FORWARD                           "forward"
 
75
 
 
76
#define CFD_PROXY_COMM_PROC_ALL                                -1
 
77
 
 
78
#define CFD_PROXY_COMM_L_SEC_NAME                              32
 
79
 
 
80
//----------------------------------------------------------------------------
 
81
// Structure definitions
 
82
//----------------------------------------------------------------------------
 
83
 
 
84
typedef struct _cfd_proxy_comm_t cfd_proxy_comm_t;
 
85
 
 
86
// Public structure used to save data from a message header, simplifying
 
87
// the transfer of this data to processing functions
 
88
 
 
89
typedef struct {
 
90
 
 
91
  char                   func_name[32]; // Function name
 
92
 
 
93
  int                    comp_id;       // Component id
 
94
 
 
95
  int                    n_ints;        // Number of integer values
 
96
  int                    n_doubles;     // Number of double-precision values
 
97
  int                    n_strings;     // Number of string values
 
98
 
 
99
  int                    ints_size;     // Size of array containing ints
 
100
  int                    doubles_size;  // Size of array containing doubles
 
101
  int                    strings_size;  // Size of array containing strings
 
102
 
 
103
  int                   *int_vals;      // Array of integer values
 
104
  double                *double_vals;   // Array of double-precision values
 
105
  char                  *string_vals;   // Array of string values
 
106
 
 
107
} cfd_proxy_comm_request_t;
 
108
 
 
109
//============================================================================
 
110
// Global variables
 
111
//============================================================================
 
112
 
 
113
//============================================================================
 
114
// Public function prototypes
 
115
//============================================================================
 
116
 
 
117
//----------------------------------------------------------------------------
 
118
// Initialize a communicator
 
119
//
 
120
// parameters:
 
121
//   type  <-- communication type
 
122
//   echo  <-- echo on main output
 
123
//----------------------------------------------------------------------------
 
124
 
 
125
cfd_proxy_comm_t *
 
126
cfd_proxy_comm_initialize(cfd_proxy_comm_type_t  type,
 
127
                          int                    echo);
 
128
 
 
129
//----------------------------------------------------------------------------
 
130
// Finalize a communicator
 
131
//----------------------------------------------------------------------------
 
132
 
 
133
cfd_proxy_comm_t *
 
134
cfd_proxy_comm_finalize(cfd_proxy_comm_t *comm);
 
135
 
 
136
//----------------------------------------------------------------------------
 
137
// Establish a communicator connection
 
138
//
 
139
// parameters:
 
140
//   comm          <-> communicator
 
141
//   magic_string  <-- magic string for verification
 
142
//
 
143
// returns:
 
144
//   0 in case of success, -1 otherwise;
 
145
//----------------------------------------------------------------------------
 
146
 
 
147
int
 
148
cfd_proxy_comm_connect(cfd_proxy_comm_t  *comm,
 
149
                       const char        *magic_string);
 
150
 
 
151
//----------------------------------------------------------------------------
 
152
// Get a communicator's name
 
153
//
 
154
// This function returns a pointer to an existing name, so the string
 
155
// returned should not be freed by the user.
 
156
//----------------------------------------------------------------------------
 
157
 
 
158
const char *
 
159
cfd_proxy_comm_get_name(const cfd_proxy_comm_t *comm);
 
160
 
 
161
//----------------------------------------------------------------------------
 
162
// Get a communicator's associated connection key
 
163
//----------------------------------------------------------------------------
 
164
 
 
165
int
 
166
cfd_proxy_comm_get_key(const cfd_proxy_comm_t *comm);
 
167
 
 
168
//----------------------------------------------------------------------------
 
169
// Initialize a function request structure.
 
170
//
 
171
// parameters:
 
172
//   r <-> pointer to function request structure
 
173
//----------------------------------------------------------------------------
 
174
 
 
175
void
 
176
cfd_proxy_comm_init_request(cfd_proxy_comm_request_t *r);
 
177
 
 
178
//----------------------------------------------------------------------------
 
179
// Finalize a function request structure.
 
180
//
 
181
// parameters:
 
182
//   r <-> pointer to function request structure
 
183
//----------------------------------------------------------------------------
 
184
 
 
185
void
 
186
cfd_proxy_comm_finalize_request(cfd_proxy_comm_request_t *r);
 
187
 
 
188
//----------------------------------------------------------------------------
 
189
// Write a record to a client.
 
190
//
 
191
// parameters:
 
192
//   comm    <-- communicator
 
193
//   rec     <-- pointer to data to write
 
194
//   size    <-- size of each data element, in bytes
 
195
//   count   <-- number of data elements
 
196
//
 
197
// returns:
 
198
//   0 if request was written correctly, -2 for error
 
199
//----------------------------------------------------------------------------
 
200
 
 
201
int
 
202
cfd_proxy_comm_write(cfd_proxy_comm_t  *comm,
 
203
                     const void        *rec,
 
204
                     size_t             size,
 
205
                     size_t             count);
 
206
 
 
207
//----------------------------------------------------------------------------
 
208
// Read a record from a proxy.
 
209
//
 
210
// parameters:
 
211
//   comm    <-- communicator
 
212
//   rec     --> pointer to data to write
 
213
//   size    <-- size of each data element, in bytes
 
214
//   count   <-- number of data elements
 
215
//
 
216
// returns:
 
217
//   0 if request was read correctly, -1 for end-of-file, -2 for error
 
218
//----------------------------------------------------------------------------
 
219
 
 
220
int
 
221
cfd_proxy_comm_read(cfd_proxy_comm_t  *comm,
 
222
                    void              *rec,
 
223
                    size_t             size,
 
224
                    size_t             count);
 
225
 
 
226
//----------------------------------------------------------------------------
 
227
// Read a function-relay response from a proxy.
 
228
//
 
229
// parameters:
 
230
//   comm <-> communicator
 
231
//   r    <-> pointer to function request structure
 
232
//
 
233
// returns:
 
234
//   0 if request was read correctly, -1 for end-of-file, -2 for error
 
235
//----------------------------------------------------------------------------*/
 
236
 
 
237
int
 
238
cfd_proxy_comm_read_request(cfd_proxy_comm_t          *comm,
 
239
                            cfd_proxy_comm_request_t  *r);
 
240
 
 
241
//----------------------------------------------------------------------------
 
242
// Send a function-relay response to a proxy.
 
243
//
 
244
// parameters:
 
245
//   comm        <-- communicator
 
246
//   retcode     <-- function return code
 
247
//   comp_id     <-- associated component id
 
248
//   n_ints      <-- number of integer arguments
 
249
//   n_doubles   <-- number of floating-point arguments
 
250
//   n_strings   <-- number of string arguments
 
251
//   int_vals    <-- integer argument values
 
252
//   double_vals <-- floating-point argument values
 
253
//   string_vals <-- string argument values
 
254
//
 
255
// returns:
 
256
//   0 if response was written correctly, -2 for error
 
257
//----------------------------------------------------------------------------
 
258
 
 
259
int
 
260
cfd_proxy_comm_write_response(cfd_proxy_comm_t  *comm,
 
261
                              int                retcode,
 
262
                              int                n_ints,
 
263
                              int                n_doubles,
 
264
                              int                n_strings,
 
265
                              const int          int_vals[],
 
266
                              const double       double_vals[],
 
267
                              const char        *string_vals[]);
 
268
 
 
269
//----------------------------------------------------------------------------
 
270
 
 
271
#ifdef __cplusplus
 
272
}
 
273
#endif /* __cplusplus */
 
274
 
 
275
#endif /* _CFD_PROXY_COMM_H_ */