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

« back to all changes in this revision

Viewing changes to src/base/cs_proxy_comm.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2011-11-01 17:43:32 UTC
  • mto: (6.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20111101174332-tl4vk45no0x3emc3
Tags: upstream-2.1.0
ImportĀ upstreamĀ versionĀ 2.1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef __CS_PROXY_COMM_H__
 
2
#define __CS_PROXY_COMM_H__
 
3
 
 
4
/*============================================================================
 
5
 * Base communication functions for use with proxy
 
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
 
 
30
/*----------------------------------------------------------------------------
 
31
 *  Local headers
 
32
 *----------------------------------------------------------------------------*/
 
33
 
 
34
#include "cs_base.h"
 
35
 
 
36
/*----------------------------------------------------------------------------*/
 
37
 
 
38
BEGIN_C_DECLS
 
39
 
 
40
/*============================================================================
 
41
 * Macro definitions
 
42
 *============================================================================*/
 
43
 
 
44
#define CS_PROXY_COMM_CMD_ABORT                       "cmd:abort"
 
45
#define CS_PROXY_COMM_CMD_STOP                         "cmd:stop"
 
46
#define CS_PROXY_COMM_FORWARD                           "forward"
 
47
 
 
48
#define CS_PROXY_COMM_L_SEC_NAME                              32
 
49
 
 
50
/*============================================================================
 
51
 * Type and structure definitions
 
52
 *============================================================================*/
 
53
 
 
54
typedef enum {
 
55
  CS_PROXY_TYPE_string,
 
56
  CS_PROXY_TYPE_int,
 
57
  CS_PROXY_TYPE_float,
 
58
  CS_PROXY_TYPE_double
 
59
} cs_proxy_type_t;
 
60
 
 
61
typedef enum {
 
62
 
 
63
  CS_PROXY_COMM_MSG_NONE,       /* Not a message */
 
64
  CS_PROXY_COMM_MSG_ABORT,      /* Emergency stop */
 
65
  CS_PROXY_COMM_MSG_STOP,       /* End of communication */
 
66
  CS_PROXY_COMM_MSG_FORWARD,    /* Message to forward */
 
67
  CS_PROXY_COMM_MSG_OTHER       /* Undefined message type */
 
68
 
 
69
} cs_proxy_comm_msg_t;
 
70
 
 
71
typedef enum {
 
72
 
 
73
  CS_PROXY_COMM_TYPE_SOCKET,    /* Communicate through sockets */
 
74
  CS_PROXY_COMM_TYPE_NULL       /* Null communicator */
 
75
 
 
76
} cs_proxy_comm_type_t;
 
77
 
 
78
typedef struct _cs_proxy_comm_t cs_proxy_comm_t;
 
79
 
 
80
/* Public structure used to save data from a message header, simplifying
 
81
   the transfer of this data to processing functions */
 
82
 
 
83
typedef struct {
 
84
 
 
85
  cs_proxy_comm_msg_t msg_type;
 
86
  int  sec_num;
 
87
  char sec_name[CS_PROXY_COMM_L_SEC_NAME + 1];
 
88
  int  n_elts;
 
89
  cs_type_t elt_type;
 
90
 
 
91
} cs_proxy_comm_msg_header_t;
 
92
 
 
93
/*============================================================================
 
94
 * Global variables
 
95
 *============================================================================*/
 
96
 
 
97
/*============================================================================
 
98
 * Public function prototypes
 
99
 *============================================================================*/
 
100
 
 
101
/*----------------------------------------------------------------------------
 
102
 * Establish a connection to a proxy.
 
103
 *
 
104
 * parameters:
 
105
 *   port_name     <-- name of server port (host:port for IP sockets)
 
106
 *   key           <-- key for authentification
 
107
 *   type          <-- communication type
 
108
 *----------------------------------------------------------------------------*/
 
109
 
 
110
void
 
111
cs_proxy_comm_initialize(const char           *port_name,
 
112
                         int                   key,
 
113
                         cs_proxy_comm_type_t  type);
 
114
 
 
115
/*----------------------------------------------------------------------------
 
116
 * Finalize a connection to a proxy.
 
117
 *----------------------------------------------------------------------------*/
 
118
 
 
119
void
 
120
cs_proxy_comm_finalize(void);
 
121
 
 
122
/*----------------------------------------------------------------------------
 
123
 * Write a record to a proxy.
 
124
 *
 
125
 * parameters:
 
126
 *   rec     <-- pointer to data to write
 
127
 *   size    <-- size of each data element, in bytes
 
128
 *   count   <-- number of data elements
 
129
 *----------------------------------------------------------------------------*/
 
130
 
 
131
void
 
132
cs_proxy_comm_write(const void  *rec,
 
133
                    size_t       size,
 
134
                    size_t       count);
 
135
 
 
136
/*----------------------------------------------------------------------------
 
137
 * Read a record from a proxy.
 
138
 *
 
139
 * parameters:
 
140
 *   rec     --> pointer to data to write
 
141
 *   size    <-- size of each data element, in bytes
 
142
 *   count   <-- number of data elements
 
143
 *----------------------------------------------------------------------------*/
 
144
 
 
145
void
 
146
cs_proxy_comm_read(void    *rec,
 
147
                   size_t   size,
 
148
                   size_t   count);
 
149
 
 
150
/*----------------------------------------------------------------------------
 
151
 * Send a function-relay request to a proxy.
 
152
 *
 
153
 * parameters:
 
154
 *   func_name   <-- name of function associated with request
 
155
 *   comp_id     <-- associated component id
 
156
 *   n_ints      <-- number of integer arguments
 
157
 *   n_doubles   <-- number of floating-point arguments
 
158
 *   n_strings   <-- number of string arguments
 
159
 *   int_vals    <-- integer argument values
 
160
 *   double_vals <-- floating-point argument values
 
161
 *   string_vals <-- string argument values
 
162
 *----------------------------------------------------------------------------*/
 
163
 
 
164
void
 
165
cs_proxy_comm_write_request(const char      *func_name,
 
166
                            int              comp_id,
 
167
                            int              n_ints,
 
168
                            int              n_doubles,
 
169
                            int              n_strings,
 
170
                            const int        int_vals[],
 
171
                            const double     double_vals[],
 
172
                            const char      *string_vals[]);
 
173
 
 
174
/*----------------------------------------------------------------------------
 
175
 * Read a function-relay response from a proxy.
 
176
 *
 
177
 * Return value arrays must be large enough to receive all values.
 
178
 *
 
179
 * parameters:
 
180
 *   n_ints      <-- number of integer arguments
 
181
 *   n_doubles   <-- number of floating-point arguments
 
182
 *   n_strings   <-- number of string arguments
 
183
 *   int_vals    --> integer argument values
 
184
 *   double_vals --> floating-point argument values
 
185
 *   string_vals --> string argument values
 
186
 *
 
187
 * returns:
 
188
 *   the relayed function's return value
 
189
 *----------------------------------------------------------------------------*/
 
190
 
 
191
int
 
192
cs_proxy_comm_read_response(int        n_ints,
 
193
                            int        n_doubles,
 
194
                            int        n_strings,
 
195
                            int        int_vals[],
 
196
                            double     double_vals[],
 
197
                            char      *string_vals[]);
 
198
 
 
199
/*----------------------------------------------------------------------------*/
 
200
 
 
201
END_C_DECLS
 
202
 
 
203
#endif /* __CS_PROXY_COMM_H__ */