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