summaryrefslogtreecommitdiff
path: root/ctools/asn_connection.h
blob: f30323576ac2e90a3e651ad435610a4b25f51556 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#ifndef CTOOLS___ASN_CONNECTION__H
#define CTOOLS___ASN_CONNECTION__H

/* $Id: asn_connection.h,v 1.12 2012/02/29 20:14:34 kazimird Exp $
 * ===========================================================================
 *
 *                            PUBLIC DOMAIN NOTICE
 *               National Center for Biotechnology Information
 *
 *  This software/database is a "United States Government Work" under the
 *  terms of the United States Copyright Act.  It was written as part of
 *  the author's official duties as a United States Government employee and
 *  thus cannot be copyrighted.  This software/database is freely available
 *  to the public for use. The National Library of Medicine and the U.S.
 *  Government have not placed any restriction on its use or reproduction.
 *
 *  Although all reasonable efforts have been taken to ensure the accuracy
 *  and reliability of the software and data, the NLM and the U.S.
 *  Government do not and cannot warrant the performance or results that
 *  may be obtained by using this software or data. The NLM and the U.S.
 *  Government disclaim all warranties, express or implied, including
 *  warranties of performance, merchantability or fitness for any particular
 *  purpose.
 *
 *  Please cite the author in any work or product based on this material.
 *
 * ===========================================================================
 *
 * Author:  Denis Vakatov, Anton Lavrentiev
 *
 * File Description:
 *    Build C Toolkit ASN.1 streams on top of CONN (connection).
 *
 */

#include <connect/ncbi_service_connector.h>
#include <asn.h>


/** @addtogroup CToolsASNConn
 *
 * @{
 */


#ifdef __cplusplus
extern "C" {
#endif


typedef enum {
    eAsnConn_Input,
    eAsnConn_Output
} EAsnConn_Direction;


typedef enum {
    eAsnConn_Binary,
    eAsnConn_Text
} EAsnConn_Format;


/* Build a ASN.1 stream on top of a CONN (connection) handle.
 * According to arguments, the stream is created for either reading or writing,
 * and is capable to handle either binary or text ASN.1.
 * Return ASN.1 stream pointer on success, or 0 on error.
 * NOTE: Returned stream is valid while the underlying conn exists.  After call
 *       to CONN_Close() the stream becomes invalid, and should not be used.
 *       Don't destroy the ASN.1 stream explicitly using AsnIoFree()!
 */
AsnIoPtr CreateAsnConn
(CONN               conn,
 EAsnConn_Direction direction,
 EAsnConn_Format    fmt
 );


/* Create a service connection using the service name, type, and connection
 * parameters (use default connection parameters if 'net_info' is passed NULL).
 * Create two ASN.1 streams based on the connection:  one stream for input, and
 * another one for output.  Return pointers to the streams via the 'input' and
 * 'output' arguments.  No corresponding stream is created if either pointer is
 * passed NULL.
 * On success, return the created CONN handle; otherwise, return 0.
 * NOTE: Both returned ASN.1 streams are valid as long as the connection handle
 *       exists; that is, after the connection handle is passed to CONN_Close()
 *       either pointer becomes invalid, and should not be used.
 *       Don't destroy the ASN.1 streams explicitly using AsnIoFree()!
 */
CONN CreateAsnConn_ServiceEx
(const char*           service,
 EAsnConn_Format       input_fmt,
 AsnIoPtr*             input,
 EAsnConn_Format       output_fmt,
 AsnIoPtr*             output,
 TSERV_Type            type,
 const SConnNetInfo*   net_info,
 const SSERVICE_Extra* params
 );


/* Equivalent of CreateAsnConn_ServiceEx with zeroes in last three arguments.
 */
CONN CreateAsnConn_Service
(const char*     service,
 EAsnConn_Format input_fmt,
 AsnIoPtr*       input,
 EAsnConn_Format output_fmt,
 AsnIoPtr*       output
 );


#ifdef __cplusplus
}  /* extern "C" */
#endif


/* @} */


#endif /* CTOOLS___ASN_CONNECTION__H */