~ubuntu-branches/ubuntu/precise/ncbi-tools6/precise

« back to all changes in this revision

Viewing changes to connect/ncbi_servicep.h

  • Committer: Bazaar Package Importer
  • Author(s): Aaron M. Ucko
  • Date: 2005-03-27 12:00:15 UTC
  • mfrom: (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050327120015-embhesp32nj73p9r
Tags: 6.1.20041020-3
* Fix FTBFS under GCC 4.0 caused by inconsistent use of "static" on
  functions.  (Closes: #295110.)
* Add a watch file, now that we can.  (Upstream's layout needs version=3.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef NCBI_SERVICEP__H
2
 
#define NCBI_SERVICEP__H
 
1
#ifndef CONNECT___NCBI_SERVICEP__H
 
2
#define CONNECT___NCBI_SERVICEP__H
3
3
 
4
 
/*  $Id: ncbi_servicep.h,v 6.13 2001/09/28 20:50:41 lavr Exp $
 
4
/*  $Id: ncbi_servicep.h,v 6.25 2004/08/19 15:48:04 lavr Exp $
5
5
 * ===========================================================================
6
6
 *
7
7
 *                            PUBLIC DOMAIN NOTICE
31
31
 * File Description:
32
32
 *   Private API to define server iterator structure.
33
33
 *
 
34
 */
 
35
 
 
36
#include "ncbi_server_infop.h"
 
37
#include <connect/ncbi_service.h>
 
38
 
 
39
 
 
40
#ifdef __cplusplus
 
41
extern "C" {
 
42
#endif
 
43
 
 
44
 
 
45
/* Table of iterator "virtual functions"
 
46
 */
 
47
typedef struct {
 
48
    void        (*Reset)(SERV_ITER iter);
 
49
    SSERV_Info* (*GetNextInfo)(SERV_ITER iter, HOST_INFO* host_info);
 
50
    int/*bool*/ (*Update)(SERV_ITER iter, TNCBI_Time now, const char* text);
 
51
    int/*bool*/ (*Penalize)(SERV_ITER iter, double penalty);
 
52
    void        (*Close)(SERV_ITER iter);
 
53
    const char* name;
 
54
} SSERV_VTable;
 
55
 
 
56
 
 
57
/* Iterator structure
 
58
 */
 
59
struct SSERV_IterTag {
 
60
    const char*  service;        /* requested service name                 */
 
61
    TSERV_Type   types;          /* requested server type(s)               */
 
62
    unsigned int preferred_host; /* preferred host to select, network b.o. */
 
63
    double       preference;     /* range [0..100] %%                      */
 
64
    SSERV_Info** skip;           /* servers to skip                        */
 
65
    size_t       n_skip;         /* number of servers in the array         */
 
66
    size_t       n_max_skip;     /* number of allocated slots in the array */
 
67
    SSERV_Info*  last;           /* last server info taken out             */
 
68
 
 
69
    const SSERV_VTable* op;      /* table of virtual functions             */
 
70
 
 
71
    void*        data;           /* private data field                     */
 
72
    int/*bool*/  external;       /* true for mapping of external requests  */
 
73
};
 
74
 
 
75
 
 
76
/* Modified 'fast track' routine for one-shot obtaining of a service info.
 
77
 * Please see <connect/ncbi_service.h> for explanations [SERV_GetInfoEx()].
 
78
 * For now, this call is to exclusively support MYgethostbyname() replacement
 
79
 * of standard gethostbyname() libcall in apache Web daemon (see in daemons/).
 
80
 *
 
81
 * NOTE: Preference 0.0 does not prohibit the preferred_host to be selected;
 
82
 *       nor preference 100.0 ultimately opts for the preferred_host; rather,
 
83
 *       the preference is considered as an estimate for the selection
 
84
 *       probability when all other conditions for favoring the host are
 
85
 *       optimal, i.e. preference 0.0 actually means not to favor the preferred
 
86
 *       host at all, while 100.0 means to opt for that as much as possible.
 
87
 */
 
88
SSERV_Info* SERV_GetInfoP
 
89
(const char*         service,       /* service name                          */
 
90
 TSERV_Type          types,         /* mask of type(s) of servers requested  */
 
91
 unsigned int        preferred_host,/* preferred host to use service on, nbo */
 
92
 double              preference,    /* [0=min..100=max] preference in %%     */
 
93
 int/*bool*/         external       /* whether mapping is not local to NCBI  */
 
94
 );
 
95
 
 
96
/* same as the above but creates an iterator to get services one by one */
 
97
SERV_ITER SERV_OpenP
 
98
(const char*         service,
 
99
 TSERV_Type          type,
 
100
 unsigned int        preferred_host,
 
101
 double              preference,
 
102
 int/*bool*/         external
 
103
 );
 
104
 
 
105
 
 
106
/* Private interface: update mapper information from the given text
 
107
 * (<CR><LF> separated lines, usually taken from HTTP header).
 
108
 */
 
109
int/*bool*/ SERV_Update(SERV_ITER iter, const char* text);
 
110
 
 
111
 
 
112
/* Private interface: print and return the HTTP-compliant header portion
 
113
 * (<CR><LF> separated lines, including the last line) out of the information
 
114
 * contained in the iterator; to be used in mapping requests to DISPD.
 
115
 * Return value must be 'free'd.
 
116
 */
 
117
char* SERV_PrintEx(SERV_ITER iter, const SConnNetInfo* referrer);
 
118
 
 
119
#define SERV_Print(iter) SERV_PrintEx(iter, 0)
 
120
 
 
121
 
 
122
/* Get name of underlying service mapper.
 
123
 */
 
124
const char* SERV_MapperName(SERV_ITER iter);
 
125
 
 
126
 
 
127
/* Get final service name, using CONN_SERVICE_NAME_service environment
 
128
 * variable, then (if not found) registry section [service] and a key
 
129
 * CONN_SERVICE_NAME. Return resulting name (perhaps, an exact copy of
 
130
 * "service" if no override name was found in environment/registry), which
 
131
 * is to be freed by a caller when no longer needed. Return NULL on error.
 
132
 * NOTE: This procedure does not detect cyclical redefinitions.
 
133
 */
 
134
char* SERV_ServiceName(const char* service);
 
135
 
 
136
 
 
137
/* Get configuration file name. Returned '\0'-terminated string
 
138
 * is to be free()'d by a caller when no longer needed.
 
139
 * Return NULL if no configuration file name available.
 
140
 */
 
141
char* SERV_GetConfig(void);
 
142
 
 
143
 
 
144
/* Given the status gap and wanted preference, calculate
 
145
 * acceptable stretch for the gap (the number of candidates is n).
 
146
 */
 
147
double SERV_Preference(double pref, double gap, unsigned int n);
 
148
 
 
149
 
 
150
#ifdef __cplusplus
 
151
}  /* extern "C" */
 
152
#endif
 
153
 
 
154
 
 
155
/*
34
156
 * --------------------------------------------------------------------------
35
157
 * $Log: ncbi_servicep.h,v $
 
158
 * Revision 6.25  2004/08/19 15:48:04  lavr
 
159
 * SERV_ITER::type renamed into SERV_ITER::types to reflect its bitmask nature
 
160
 *
 
161
 * Revision 6.24  2004/07/01 16:27:55  lavr
 
162
 * +SERV_PrintEx()
 
163
 *
 
164
 * Revision 6.23  2003/06/26 15:19:56  lavr
 
165
 * Additional parameter "external" for SERV_{Open|GetInfo}P()
 
166
 *
 
167
 * Revision 6.22  2003/06/09 19:53:11  lavr
 
168
 * +SERV_OpenP()
 
169
 *
 
170
 * Revision 6.21  2003/03/07 22:21:55  lavr
 
171
 * Explain what is "preference" for SERV_GetInfoP()
 
172
 *
 
173
 * Revision 6.20  2003/02/28 14:49:09  lavr
 
174
 * SERV_Preference(): redeclare last argument 'unsigned'
 
175
 *
 
176
 * Revision 6.19  2003/02/13 21:37:28  lavr
 
177
 * Comment SERV_Preference(), change last argument
 
178
 *
 
179
 * Revision 6.18  2003/01/31 21:19:41  lavr
 
180
 * +SERV_Preference()
 
181
 *
 
182
 * Revision 6.17  2002/10/28 20:16:00  lavr
 
183
 * Take advantage of host info API
 
184
 *
 
185
 * Revision 6.16  2002/10/11 19:48:25  lavr
 
186
 * +SERV_GetConfig()
 
187
 * const dropped in return value of SERV_ServiceName()
 
188
 *
 
189
 * Revision 6.15  2002/09/19 18:08:43  lavr
 
190
 * Header file guard macro changed; log moved to end
 
191
 *
 
192
 * Revision 6.14  2002/05/06 19:17:04  lavr
 
193
 * +SERV_ServiceName() - translation of service name
 
194
 *
36
195
 * Revision 6.13  2001/09/28 20:50:41  lavr
37
196
 * Update VT method changed - now called on per-line basis
38
197
 *
80
239
 * ==========================================================================
81
240
 */
82
241
 
83
 
#include <connect/ncbi_service.h>
84
 
 
85
 
#ifdef __cplusplus
86
 
extern "C" {
87
 
#endif
88
 
 
89
 
 
90
 
/* Table of iterator "virtual functions"
91
 
 */
92
 
typedef struct {
93
 
    void        (*Reset)(SERV_ITER iter);
94
 
    SSERV_Info* (*GetNextInfo)(SERV_ITER iter, char** env);
95
 
    int/*bool*/ (*Update)(SERV_ITER iter, TNCBI_Time now, const char* text);
96
 
    int/*bool*/ (*Penalize)(SERV_ITER iter, double penalty);
97
 
    void        (*Close)(SERV_ITER iter);
98
 
    const char* name;
99
 
} SSERV_VTable;
100
 
 
101
 
 
102
 
/* Iterator structure
103
 
 */
104
 
struct SSERV_IterTag {
105
 
    const char*  service;        /* requested service name                 */
106
 
    TSERV_Type   type;           /* requested server type(s)               */
107
 
    unsigned int preferred_host; /* preferred host to select, network b.o. */
108
 
    SSERV_Info** skip;           /* servers to skip                        */
109
 
    size_t       n_skip;         /* number of servers in the array         */
110
 
    size_t       n_max_skip;     /* number of allocated slots in the array */
111
 
    SSERV_Info*  last;           /* last server info taken out             */
112
 
 
113
 
    const SSERV_VTable* op;      /* table of virtual functions             */
114
 
 
115
 
    void*        data;           /* private data field                     */
116
 
};
117
 
 
118
 
 
119
 
/* Private interface: update mapper information from the given text
120
 
 * (<CR><LF> separated lines, usually taken from HTTP header).
121
 
 */
122
 
int/*bool*/ SERV_Update(SERV_ITER iter, const char* text);
123
 
 
124
 
 
125
 
/* Private interface: print and return the HTTP-compliant header portion
126
 
 * (<CR><LF> separated lines, including the last line) out of the information
127
 
 * contained in the iterator; to be used in mapping requests to DISPD.
128
 
 * Return value must be 'free'd.
129
 
 */
130
 
char* SERV_Print(SERV_ITER iter);
131
 
 
132
 
 
133
 
/* Get name of underlying service mapper.
134
 
 */
135
 
const char* SERV_MapperName(SERV_ITER iter);
136
 
 
137
 
 
138
 
#ifdef __cplusplus
139
 
}  /* extern "C" */
140
 
#endif
141
 
 
142
 
#endif /* NCBI_SERVICEP__H */
 
242
#endif /* CONNECT___NCBI_SERVICEP__H */