|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/access/mimapi.c |
source navigation diff markup identifier search freetext search file search |
1 /* mimapi.c
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information (NCBI)
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government do not place any restriction on its use or reproduction.
13 * We would, however, appreciate having the NCBI and the author cited in
14 * any work or product based on this material
15 *
16 * Although all reasonable efforts have been taken to ensure the accuracy
17 * and reliability of the software and data, the NLM and the U.S.
18 * Government do not and cannot warrant the performance or results that
19 * may be obtained by using this software or data. The NLM and the U.S.
20 * Government disclaim all warranties, express or implied, including
21 * warranties of performance, merchantability or fitness for any particular
22 * purpose.
23 *
24 * ===========================================================================
25 *
26 * File Name: mimapi.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 8/16/00
31 *
32 * $Revision: 1.10 $
33 *
34 * File Description:
35 *
36 * Modifications:
37 * --------------------------------------------------------------------------
38 * Date Name Description of modification
39 * ------- ---------- -----------------------------------------------------
40 *
41 *
42 * ==========================================================================
43 */
44
45 #include <ncbi.h>
46 #include <urlquery.h>
47 #include <mimapi.h>
48
49 /* low-level connection functions */
50
51 NLM_EXTERN CONN MimOpenConnection (
52 Int4 uid
53 )
54
55 {
56 Char query [64];
57
58 if (uid < 1) return NULL;
59
60 /*
61 sprintf (query, "cmd=ASN.1&id=%ld", (long) uid);
62 return QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80, "/entrez/dispomim.cgi",
63 query, "Entrez2Tool", 30, eMIME_T_NcbiData,
64 eMIME_AsnText, eENCOD_None, 0);
65 */
66
67 sprintf (query, "id=%ld", (long) uid);
68 return QUERY_OpenServiceQuery ("MimFetch", query, 30);
69 }
70
71 #ifdef OS_MAC
72 #include <Events.h>
73 #endif
74
75 NLM_EXTERN MimEntryPtr MimWaitForReply (
76 CONN conn
77 )
78
79 {
80 AsnIoConnPtr aicp;
81 time_t currtime, starttime;
82 time_t max = 0;
83 MimEntryPtr mep = NULL;
84 EIO_Status status;
85 STimeout timeout;
86 #ifdef OS_MAC
87 EventRecord currEvent;
88 #endif
89
90 if (conn == NULL) return NULL;
91
92 #ifdef OS_MAC
93 timeout.sec = 0;
94 timeout.usec = 0;
95 #else
96 timeout.sec = 100;
97 timeout.usec = 0;
98 #endif
99
100 starttime = GetSecs ();
101 while ((status = CONN_Wait (conn, eIO_Read, &timeout)) == eIO_Timeout && max < 300) {
102 currtime = GetSecs ();
103 max = currtime - starttime;
104 #ifdef OS_MAC
105 WaitNextEvent (0, &currEvent, 0, NULL);
106 #endif
107 }
108 if (status == eIO_Success) {
109 aicp = QUERY_AsnIoConnOpen ("r", conn);
110 mep = MimEntryAsnRead (aicp->aip, NULL);
111 QUERY_AsnIoConnClose (aicp);
112 }
113 CONN_Close (conn);
114
115 return mep;
116 }
117
118 /* high-level connection functions */
119
120 NLM_EXTERN MimEntryPtr MimSynchronousQuery (
121 Int4 uid
122 )
123
124 {
125 CONN conn;
126 MimEntryPtr mep;
127
128 conn = MimOpenConnection (uid);
129
130 if (conn == NULL) return NULL;
131
132 QUERY_SendQuery (conn);
133
134 mep = MimWaitForReply (conn);
135
136 return mep;
137 }
138
139 NLM_EXTERN Boolean MimAsynchronousQuery (
140 Int4 uid,
141 QUEUE* queue,
142 QueryResultProc resultproc,
143 VoidPtr userdata
144 )
145
146 {
147 CONN conn;
148
149 conn = MimOpenConnection (uid);
150
151 if (conn == NULL) return FALSE;
152
153 QUERY_SendQuery (conn);
154
155 QUERY_AddToQueue (queue, conn, resultproc, userdata, TRUE);
156
157 return TRUE;
158 }
159
160 NLM_EXTERN Int4 MimCheckQueue (
161 QUEUE* queue
162 )
163
164 {
165 return QUERY_CheckQueue (queue);
166 }
167
168 NLM_EXTERN MimEntryPtr MimReadReply (
169 CONN conn,
170 EIO_Status status
171 )
172
173 {
174 AsnIoConnPtr aicp;
175 MimEntryPtr mep = NULL;
176
177 if (conn != NULL && status == eIO_Success) {
178 aicp = QUERY_AsnIoConnOpen ("r", conn);
179 mep = MimEntryAsnRead (aicp->aip, NULL);
180 QUERY_AsnIoConnClose (aicp);
181 }
182 return mep;
183 }
184
185 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |