* Copyright (c) 2000-2004, Index Data
* See the file LICENSE for details.
*
- * $Id: zoom-c.c,v 1.24 2004-02-14 15:58:42 adam Exp $
+ * $Id: zoom-c.c,v 1.25 2004-02-23 09:26:11 adam Exp $
*
* ZOOM layer for C, connections, result sets, queries.
*/
case ZOOM_TASK_PACKAGE:
ZOOM_package_destroy (task->u.package);
break;
+ case ZOOM_TASK_SORT:
+ ZOOM_resultset_destroy (task->u.sort.resultset);
+ ZOOM_query_destroy(task->u.sort.q);
+ break;
default:
assert (0);
}
r, r->refcount);
}
}
+
ZOOM_resultset ZOOM_resultset_create ()
{
ZOOM_resultset r = (ZOOM_resultset) xmalloc (sizeof(*r));
}
ZOOM_API(void)
+ ZOOM_resultset_sort(ZOOM_resultset r,
+ const char *sort_type, const char *sort_spec)
+{
+ ZOOM_connection c = r->connection;
+ ZOOM_task task;
+
+ if (!c)
+ return;
+
+ if (c->host_port && c->proto == PROTO_HTTP)
+ {
+ if (!c->cs)
+ {
+ yaz_log(LOG_DEBUG, "NO COMSTACK");
+ ZOOM_connection_add_task(c, ZOOM_TASK_CONNECT);
+ }
+ else
+ {
+ yaz_log(LOG_DEBUG, "PREPARE FOR RECONNECT");
+ c->reconnect_ok = 1;
+ }
+ }
+
+ ZOOM_resultset_cache_reset(r);
+ task = ZOOM_connection_add_task (c, ZOOM_TASK_SORT);
+ task->u.sort.resultset = r;
+ task->u.sort.q = ZOOM_query_create();
+ ZOOM_query_sortby(task->u.sort.q, sort_spec);
+
+ ZOOM_resultset_addref (r);
+
+ if (!c->async)
+ {
+ while (ZOOM_event (1, &c))
+ ;
+ }
+}
+
+ZOOM_API(void)
+ ZOOM_resultset_cache_reset(ZOOM_resultset r)
+{
+ ZOOM_record_cache rc;
+
+ for (rc = r->record_cache; rc; rc = rc->next)
+ {
+ if (rc->rec.wrbuf_marc)
+ wrbuf_free (rc->rec.wrbuf_marc, 1);
+ if (rc->rec.wrbuf_iconv)
+ wrbuf_free (rc->rec.wrbuf_iconv, 1);
+ if (rc->rec.wrbuf_opac)
+ wrbuf_free (rc->rec.wrbuf_opac, 1);
+ }
+ r->record_cache = 0;
+}
+
+ZOOM_API(void)
ZOOM_resultset_destroy(ZOOM_resultset r)
{
if (!r)
r, r->refcount);
if (r->refcount == 0)
{
- ZOOM_record_cache rc;
+ ZOOM_resultset_cache_reset(r);
- for (rc = r->record_cache; rc; rc = rc->next)
- {
- if (rc->rec.wrbuf_marc)
- wrbuf_free (rc->rec.wrbuf_marc, 1);
- if (rc->rec.wrbuf_iconv)
- wrbuf_free (rc->rec.wrbuf_iconv, 1);
- if (rc->rec.wrbuf_opac)
- wrbuf_free (rc->rec.wrbuf_opac, 1);
- }
if (r->connection)
{
/* remove ourselves from the resultsets in connection */
ZOOM_options_get(c->options, "implementationName"),
odr_prepend(c->odr_out, "ZOOM-C", ireq->implementationName));
- version = odr_strdup(c->odr_out, "$Revision: 1.24 $");
+ version = odr_strdup(c->odr_out, "$Revision: 1.25 $");
if (strlen(version) > 10) /* check for unexpanded CVS strings */
version[strlen(version)-2] = '\0';
ireq->implementationVersion = odr_prepend(c->odr_out,
return 1;
}
-static zoom_ret send_sort (ZOOM_connection c)
+static zoom_ret send_sort (ZOOM_connection c,
+ ZOOM_resultset resultset)
{
- ZOOM_resultset resultset;
-
- if (!c->tasks || c->tasks->which != ZOOM_TASK_SEARCH)
- return zoom_complete;
-
- resultset = c->tasks->u.search.resultset;
-
if (c->error)
- {
resultset->r_sort_spec = 0;
- return zoom_complete;
- }
if (resultset->r_sort_spec)
{
Z_APDU *apdu = zget_APDU(c->odr_out, Z_APDU_sortRequest);
break;
case ZOOM_TASK_PACKAGE:
ret = send_package(c);
+ break;
+ case ZOOM_TASK_SORT:
+ c->tasks->u.sort.resultset->r_sort_spec =
+ c->tasks->u.sort.q->sort_spec;
+ ret = send_sort(c, c->tasks->u.sort.resultset);
break;
}
}
static zoom_ret send_sort_present (ZOOM_connection c)
{
- zoom_ret r = send_sort (c);
+ zoom_ret r = zoom_complete;
+
+ if (c->tasks && c->tasks->which == ZOOM_TASK_SEARCH)
+ r = send_sort (c, c->tasks->u.search.resultset);
if (r == zoom_complete)
r = send_present (c);
return r;
* Copyright (c) 2002-2004, Index Data.
* See the file LICENSE for details.
*
- * $Id: zoomsh.c,v 1.26 2004-01-16 10:04:55 adam Exp $
+ * $Id: zoomsh.c,v 1.27 2004-02-23 09:26:11 adam Exp $
*/
/* ZOOM-C Shell */
}
}
+static void cmd_sort (ZOOM_connection *c, ZOOM_resultset *r,
+ ZOOM_options options,
+ const char **args)
+{
+ const char *sort_spec = *args;
+ int i;
+
+ while (*sort_spec == ' ')
+ sort_spec++;
+
+ for (i = 0; i<MAX_CON; i++)
+ {
+ if (r[i])
+ ZOOM_resultset_sort(r[i], "yaz", sort_spec);
+ }
+ while (ZOOM_event(MAX_CON, c))
+ ;
+}
+
static void cmd_help (ZOOM_connection *c, ZOOM_resultset *r,
ZOOM_options options,
const char **args)
cmd_debug(c, r, options, buf);
else if (is_command ("scan", cmd_str, cmd_len))
cmd_scan(c, r, options, buf);
+ else if (is_command ("sort", cmd_str, cmd_len))
+ cmd_sort(c, r, options, buf);
else
printf ("unknown command %.*s\n", cmd_len, cmd_str);
return 2;