/*
- * $Id: zoom-c.c,v 1.12 2001-11-22 09:45:31 adam Exp $
+ * $Id: zoom-c.c,v 1.13 2001-11-28 23:00:19 adam Exp $
*
* ZOOM layer for C, connections, result sets, queries.
*/
*taskp = xmalloc (sizeof(**taskp));
(*taskp)->running = 0;
(*taskp)->which = which;
- (*taskp)->u.resultset = 0; /* one null pointer there at least */
(*taskp)->next = 0;
clear_error (c);
return *taskp;
switch (task->which)
{
case ZOOM_TASK_SEARCH:
- ZOOM_resultset_destroy (task->u.resultset);
+ ZOOM_resultset_destroy (task->u.search.resultset);
break;
case ZOOM_TASK_RETRIEVE:
- ZOOM_resultset_destroy (task->u.resultset);
+ ZOOM_resultset_destroy (task->u.retrieve.resultset);
break;
case ZOOM_TASK_CONNECT:
break;
c->resultsets = r;
task = ZOOM_connection_add_task (c, ZOOM_TASK_SEARCH);
- task->u.resultset = r;
+ task->u.search.resultset = r;
ZOOM_resultset_addref (r);
(q->refcount)++;
c = r->connection;
if (!c)
return;
- if (start >= r->size)
- return;
-
- if (start + count > r->size)
- count = r->size - start;
-
task = ZOOM_connection_add_task (c, ZOOM_TASK_RETRIEVE);
- task->u.resultset = r;
- ZOOM_resultset_addref (r);
+ task->u.retrieve.resultset = r;
+ task->u.retrieve.start = start;
+ task->u.retrieve.count = count;
- r->start = start;
- r->count = count;
+ ZOOM_resultset_addref (r);
if (!r->connection->async || force_sync)
while (r->connection && ZOOM_event (1, &r->connection))
assert (c->tasks);
assert (c->tasks->which == ZOOM_TASK_SEARCH);
- r = c->tasks->u.resultset;
+ r = c->tasks->u.search.resultset;
elementSetName =
ZOOM_options_get (r->options, "elementSetName");
if (!c->tasks)
return ;
- if (c->tasks->which != ZOOM_TASK_SEARCH &&
- c->tasks->which != ZOOM_TASK_RETRIEVE)
- return ;
-
- resultset = c->tasks->u.resultset;
-
+ switch (c->tasks->which)
+ {
+ case ZOOM_TASK_SEARCH:
+ resultset = c->tasks->u.search.resultset;
+ break;
+ case ZOOM_TASK_RETRIEVE:
+ resultset = c->tasks->u.retrieve.resultset;
+ break;
+ default:
+ return;
+ }
if (sr && sr->which == Z_Records_NSD)
{
Z_DiagRec dr, *dr_p = &dr;
if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
return ;
- resultset = c->tasks->u.resultset;
+ resultset = c->tasks->u.search.resultset;
resultset->size = *sr->resultCount;
handle_records (c, sr->records, 0);
if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
return 0;
- resultset = c->tasks->u.resultset;
+ resultset = c->tasks->u.search.resultset;
if (c->error)
{
if (!c->tasks)
return 0;
- if (c->tasks->which != ZOOM_TASK_SEARCH &&
- c->tasks->which != ZOOM_TASK_RETRIEVE)
- return 0;
- resultset = c->tasks->u.resultset;
-
+ switch (c->tasks->which)
+ {
+ case ZOOM_TASK_SEARCH:
+ resultset = c->tasks->u.search.resultset;
+ break;
+ case ZOOM_TASK_RETRIEVE:
+ resultset = c->tasks->u.retrieve.resultset;
+ resultset->start = c->tasks->u.retrieve.start;
+ resultset->count = c->tasks->u.retrieve.count;
+
+ if (resultset->start >= resultset->size)
+ return 0;
+ if (resultset->start + resultset->count > resultset->size)
+ resultset->count = resultset->size - resultset->start;
+ break;
+ default:
+ return 0;
+ }
+
if (c->error) /* don't continue on error */
return 0;
if (resultset->start < 0)
/*
* Private C header for ZOOM C.
- * $Id: zoom-p.h,v 1.6 2001-11-22 09:45:31 adam Exp $
+ * $Id: zoom-p.h,v 1.7 2001-11-28 23:00:19 adam Exp $
*/
#include <yaz/proto.h>
#include <yaz/comstack.h>
int which;
union {
#define ZOOM_TASK_SEARCH 1
- ZOOM_resultset resultset;
+ struct {
+ ZOOM_resultset resultset;
+ } search;
#define ZOOM_TASK_RETRIEVE 2
- /** also resultset here */
+ struct {
+ int start;
+ ZOOM_resultset resultset;
+ int count;
+ } retrieve;
#define ZOOM_TASK_CONNECT 3
} u;
ZOOM_task next;
/*
- * $Id: zoomtst6.c,v 1.7 2001-11-18 21:14:23 adam Exp $
+ * $Id: zoomtst6.c,v 1.8 2001-11-28 23:00:19 adam Exp $
*
* Asynchronous multi-target client doing two searches
*/
int pos;
printf ("%s: %d hits\n", tname, ZOOM_resultset_size(r));
/* go through all records at target */
- for (pos = 0; pos < 2; pos++)
+ for (pos = 0; pos < 4; pos++)
{
ZOOM_record rec = ZOOM_resultset_record (r, pos);
-
- /* get database for record and record itself at pos */
- const char *db = ZOOM_record_get (rec, "database", 0);
- int len;
- const char *render = ZOOM_record_get (rec, "render", &len);
- /* if rec is non-null, we got a record for display */
- if (rec)
- {
- printf ("%d %s\n", pos+1, (db ? db : "unknown"));
- if (render)
- fwrite (render, 1, len, stdout);
- putchar ('\n');
- }
+ if (rec)
+ {
+ /* get database for record and record itself at pos */
+ const char *db = ZOOM_record_get (rec, "database", 0);
+ int len;
+ const char *render = ZOOM_record_get (rec, "render", &len);
+ /* if rec is non-null, we got a record for display */
+ if (rec)
+ {
+ printf ("%d %s\n", pos+1, (db ? db : "unknown"));
+ if (render)
+ fwrite (render, 1, len, stdout);
+ putchar ('\n');
+ }
+ }
}
}
for (i = 0; i<no; i++)
r2[i] = ZOOM_connection_search (z[i], q);
-
- /* network I/O */
- while (ZOOM_event (no, z))
- ;
-
+ /* fetch 5th record from first result set as well */
for (i = 0; i<no; i++)
ZOOM_resultset_records (r1[i], 0, 4, 1);