Remove script no longer in use
[yaz-moved-to-github.git] / zoom / zoomtst11.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
5
6 #include <stdio.h>
7 #include <stdlib.h>
8
9 #include <yaz/zoom.h>
10
11 void probe_package(ZOOM_connection z)
12 {
13     int i;
14     for (i = 1; i<10; i++)
15     {
16         ZOOM_package pkg = ZOOM_connection_package(z, 0);
17         ZOOM_package_option_set(pkg, "action", "recordInsert");
18         ZOOM_package_option_set(pkg, "record", "1234");
19         ZOOM_package_send(pkg, "update");
20     }
21 }
22
23 void probe_search(ZOOM_connection z, int start, int error)
24 {
25     char pqf_str[100];
26     ZOOM_resultset set;
27
28     /* provoke error with yaz-ztest */
29     if (error)
30         ZOOM_connection_option_set(z, "databaseName", "x");
31
32     sprintf(pqf_str, "@attr 1=%d water", start);
33     printf("sending search %s\n", pqf_str);
34     set = ZOOM_connection_search_pqf (z, pqf_str);
35     ZOOM_resultset_destroy(set);
36
37     /* restore database */
38     if (error)
39         ZOOM_connection_option_set(z, "databaseName", "Default");
40 }
41
42 int main(int argc, char **argv)
43 {
44     ZOOM_connection z;
45     int error;
46     int use = 0;
47     const char *errmsg, *addinfo, *diagset;
48
49     if (argc < 2)
50     {
51         fprintf (stderr, "usage:\n%s target\n", *argv);
52         fprintf (stderr,
53                  "Verify: asynchronous single-target client\n");
54         exit (1);
55     }
56
57     /* create connection (don't connect yet) */
58     z = ZOOM_connection_create(0);
59
60     /* option: set sru/get operation (only applicable if http: is used) */
61     ZOOM_connection_option_set (z, "sru", "post");
62
63     /* option: set async operation */
64     ZOOM_connection_option_set (z, "async", "1");
65
66     /* connect to target and initialize */
67     ZOOM_connection_connect (z, argv[1], 0);
68
69     probe_search(z, use, 1);
70
71     /* block here: only one connection */
72     while (ZOOM_event (1, &z))
73     {
74         int ev = ZOOM_connection_last_event(z);
75         int idle = ZOOM_connection_is_idle(z);
76
77         /* see if any error occurred */
78         if ((error = ZOOM_connection_error_x(z, &errmsg, &addinfo, &diagset)))
79         {
80             fprintf (stderr, "Error: %s: %s (%d) %s\n", diagset, errmsg, error,
81                      addinfo);
82
83         }
84         if (ev == ZOOM_EVENT_RECV_SEARCH)
85         {
86             if (error == 0)
87                 printf ("Search OK\n");
88             printf("idle=%d\n", idle);
89         }
90         if (idle)
91         {
92             ZOOM_connection_connect(z, 0, 0); /* allow reconnect */
93
94             if (++use <= 10)
95             {
96                 probe_search(z, use, use&1);
97             }
98             printf("Press enter\n");
99             getchar();
100         }
101     }
102     ZOOM_connection_destroy (z);
103     exit (0);
104 }
105 /*
106  * Local variables:
107  * c-basic-offset: 4
108  * c-file-style: "Stroustrup"
109  * indent-tabs-mode: nil
110  * End:
111  * vim: shiftwidth=4 tabstop=8 expandtab
112  */
113