Ignore object files.
[yaz-moved-to-github.git] / zoom / zoomtst4.c
1 /* $Id: zoomtst4.c,v 1.10 2007-01-03 08:42:17 adam Exp $  */
2
3 /** \file zoomtst4.c
4     \brief Asynchronous multi-target client with separate present
5     
6     Asynchronous multi-target going through proxy doing search and retrieve
7     using present.
8 */
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <yaz/xmalloc.h>
13
14 #include <yaz/zoom.h>
15
16 const char *my_callback (void *handle, const char *name)
17 {
18     if (!strcmp (name, "async"))
19         return "1";
20     return 0;
21 }
22
23 int main(int argc, char **argv)
24 {
25     int i;
26     int no = argc-3;
27     ZOOM_connection z[500]; /* allow at most 500 connections */
28     ZOOM_resultset r[500];  /* and result sets .. */
29     ZOOM_query q;
30     ZOOM_options o = ZOOM_options_create ();
31
32     if (argc < 4)
33     {
34         fprintf (stderr, "usage:\n%s proxy target1 .. targetN query\n",
35                  *argv);
36         exit (2);
37     }
38     if (no > 500)
39         no = 500;
40
41     /* function my_callback called when reading options .. */
42     ZOOM_options_set_callback (o, my_callback, 0);
43
44     /* get 20 (at most) records from offset 5 */
45     ZOOM_options_set (o, "start", "5");
46     ZOOM_options_set (o, "count", "20");
47     ZOOM_options_set (o, "schema", "gils-schema");
48     ZOOM_options_set (o, "elementSetName", "F");
49
50     /* set proxy */
51     ZOOM_options_set (o, "proxy", argv[1]);
52     
53     /* create query */
54     q = ZOOM_query_create ();
55     if (ZOOM_query_prefix (q, argv[argc-1]))
56     {
57         printf ("bad PQF: %s\n", argv[argc-1]);
58         exit (1);
59     }
60     /* connect - and search all */
61     for (i = 0; i<no; i++)
62     {
63         z[i] = ZOOM_connection_create (o);
64         ZOOM_connection_connect (z[i], argv[i+2], 0);
65         r[i] = ZOOM_connection_search (z[i], q);
66     }
67
68     /* network I/O */
69     while (ZOOM_event (no, z))
70         ;
71
72     /* handle errors */
73     for (i = 0; i<no; i++)
74     {
75         int error;
76         const char *errmsg, *addinfo;
77         if ((error = ZOOM_connection_error(z[i], &errmsg, &addinfo)))
78             fprintf (stderr, "%s error: %s (%d) %s\n",
79                      ZOOM_connection_option_get(z[i], "host"),
80                      errmsg, error, addinfo);
81         else
82             printf ("%s: %ld hits\n", ZOOM_connection_option_get(z[i], "host"),
83                     (long) ZOOM_resultset_size(r[i]));
84     }
85
86     /* destroy stuff and exit */
87     ZOOM_query_destroy (q);
88     for (i = 0; i<no; i++)
89     {
90         ZOOM_resultset_destroy (r[i]);
91         ZOOM_connection_destroy (z[i]);
92     }
93     ZOOM_options_destroy(o);
94     exit (0);
95 }
96 /*
97  * Local variables:
98  * c-basic-offset: 4
99  * indent-tabs-mode: nil
100  * End:
101  * vim: shiftwidth=4 tabstop=8 expandtab
102  */
103