|
NCBI Home IEB Home C Toolkit docs C++ Toolkit source browser C Toolkit source browser (2) |
NCBI C Toolkit Cross ReferenceC/access/strucapi.c |
source navigation diff markup identifier search freetext search file search |
1 /* strucapi.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: strucapi.c
27 *
28 * Author: Jonathan Kans
29 *
30 * Version Creation Date: 8/18/00
31 *
32 * $Revision: 1.18 $
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 <strucapi.h>
48
49 /* low-level connection functions */
50
51 NLM_EXTERN CONN StrucOpenConnection (
52 Int4 uid
53 )
54
55 {
56 Char query [256];
57 /*
58 CONN conn;
59 size_t n_written;
60 EIO_Status status;
61 */
62
63 if (uid < 1) return NULL;
64
65 /*
66 sprintf (query, "uid=%ld%s", (long) uid,
67 "&save=asntext&form=6&db=t&Dopt=j&Complexity=Cn3D%20Subset");
68
69 conn = QUERY_OpenUrlQuery ("www.ncbi.nlm.nih.gov", 80, "/Structure/mmdb/mmdbsrv.cgi",
70 NULL, "Entrez2Tool", 30, eMIME_T_NcbiData,
71 eMIME_WwwForm, eENCOD_Url, 0);
72
73 status = CONN_Write (conn, (const void *) query, StringLen (query), &n_written);
74 if (status != eIO_Success) {
75 CONN_Close (conn);
76 return NULL;
77 }
78
79 return conn;
80 */
81
82 sprintf (query, "uid=%ld%s", (long) uid,
83 "&save=asntext&form=6&db=t&Dopt=j&Complexity=Cn3D%20Subset");
84 return QUERY_OpenServiceQuery ("StrucFetch", query, 30);
85 }
86
87 NLM_EXTERN BiostrucSeqPtr StrucWaitForReply (
88 CONN conn
89 )
90
91 {
92 BiostrucSeqPtr bsp = NULL;
93 time_t currtime, starttime;
94 time_t max = 0;
95 EIO_Status status;
96 STimeout timeout;
97
98 if (conn == NULL) return NULL;
99
100 #ifdef OS_MAC
101 timeout.sec = 0;
102 timeout.usec = 0;
103 #else
104 timeout.sec = 100;
105 timeout.usec = 0;
106 #endif
107
108 starttime = GetSecs ();
109 while ((status = CONN_Wait (conn, eIO_Read, &timeout)) == eIO_Timeout && max < 300) {
110 currtime = GetSecs ();
111 max = currtime - starttime;
112 #ifdef OS_MAC
113 QUERY_WaitForNextMacEvent ();
114 #endif
115 }
116 if (status == eIO_Success) {
117 /*
118 {
119 FILE *fp = FileOpen ("dummy", "w");
120 QUERY_CopyResultsToFile (conn, fp);
121 FileClose (fp);
122 }
123 */
124 bsp = StrucReadReply (conn, status);
125 }
126 CONN_Close (conn);
127
128 return bsp;
129 }
130
131 /* high-level connection functions */
132
133 NLM_EXTERN BiostrucSeqPtr StrucSynchronousQuery (
134 Int4 uid
135 )
136
137 {
138 BiostrucSeqPtr bsp;
139 CONN conn;
140
141 conn = StrucOpenConnection (uid);
142
143 if (conn == NULL) return NULL;
144
145 QUERY_SendQuery (conn);
146
147 bsp = StrucWaitForReply (conn);
148
149 return bsp;
150 }
151
152 NLM_EXTERN Boolean StrucAsynchronousQuery (
153 Int4 uid,
154 QUEUE* queue,
155 QueryResultProc resultproc,
156 VoidPtr userdata
157 )
158
159 {
160 CONN conn;
161
162 conn = StrucOpenConnection (uid);
163
164 if (conn == NULL) return FALSE;
165
166 QUERY_SendQuery (conn);
167
168 QUERY_AddToQueue (queue, conn, resultproc, userdata, TRUE);
169
170 return TRUE;
171 }
172
173 NLM_EXTERN Int4 StrucCheckQueue (
174 QUEUE* queue
175 )
176
177 {
178 return QUERY_CheckQueue (queue);
179 }
180
181 NLM_EXTERN BiostrucSeqPtr StrucReadReply (
182 CONN conn,
183 EIO_Status status
184 )
185
186 {
187 AsnIoConnPtr aicp;
188 BiostrucSeqPtr bsp = NULL;
189 NcbiMimeAsn1Ptr nmap = NULL;
190
191 if (conn != NULL && status == eIO_Success) {
192 aicp = QUERY_AsnIoConnOpen ("r", conn);
193 nmap = NcbiMimeAsn1AsnRead (aicp->aip, NULL);
194 QUERY_AsnIoConnClose (aicp);
195 if (nmap != NULL && nmap->choice == NcbiMimeAsn1_strucseq) {
196 bsp = (BiostrucSeqPtr) nmap->data.ptrvalue;
197 }
198 }
199 return bsp;
200 }
201
202 |
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more information. |