#
# $Log: client.tcl,v $
-# Revision 1.14 1995-03-22 16:07:55 adam
+# Revision 1.15 1995-03-28 12:45:22 adam
+# New ir method failback: called on disconnect/protocol error.
+# New ir set/get method: protocol: SR / Z3950.
+# Simple popup and disconnect when failback is invoked.
+#
+# Revision 1.14 1995/03/22 16:07:55 adam
# Minor changes.
#
# Revision 1.13 1995/03/21 17:27:26 adam
destroy .target-define
}
+proc fail-response {target} {
+ close-target
+ tkerror "Target connection closed or protocol error"
+}
+
proc connect-response {target} {
puts "connect-response"
show-target $target
global profile
global hostid
- set hostid $target
- .top.target.m disable 0
- .top.target.m enable 1
z39 disconnect
z39 comstack [lindex $profile($target) 6]
# z39 idAuthentication [lindex $profile($target) 3]
} else {
z39 databaseNames $base
}
- show-status {Connecting} 1
+ z39 failback [list fail-response $target]
z39 callback [list connect-response $target]
z39 connect [lindex $profile($target) 1]:[lindex $profile($target) 2]
+ show-status {Connecting} 1
+ set hostid $target
+ .top.target.m disable 0
+ .top.target.m enable 1
+}
+
+proc close-target {} {
+ global hostid
+
+ set hostid Default
+ z39 disconnect
+ show-target {None}
+ show-status {Not connected} 0
+ show-message {}
+ .top.target.m disable 1
+ .top.target.m enable 0
}
proc load-set-action {} {
top-down-ok-cancel $w {define-target-action} 1
}
-proc close-target {} {
- # pack forget .mid.searchlabel .mid.searchentry
- #.mid.searchentry -state disabled
- z39 disconnect
- show-target {None}
- show-status {Not connected} 0
- show-message {}
- .top.target.m disable 1
- .top.target.m enable 0
-}
-
proc protocol-setup-action {target} {
global profile
global csRadioType
top-down-window $w
- if {$hostid == ""} {
- set hostid Default
- }
-
frame $w.top.databases -relief ridge -border 2
pack $w.top.databases -side left -pady 6 -padx 6 -expand yes -fill x
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: ir-tcl.c,v $
- * Revision 1.18 1995-03-21 15:50:12 adam
+ * Revision 1.19 1995-03-28 12:45:23 adam
+ * New ir method failback: called on disconnect/protocol error.
+ * New ir set/get method: protocol: SR / Z3950.
+ * Simple popup and disconnect when failback is invoked.
+ *
+ * Revision 1.18 1995/03/21 15:50:12 adam
* Minor changes.
*
* Revision 1.17 1995/03/21 13:41:03 adam
typedef struct {
char *cs_type;
+ char *protocol_type;
int connectFlag;
COMSTACK cs_link;
Tcl_Interp *interp;
char *callback;
+ char *failback;
int smallSetUpperBound;
int largeSetLowerBound;
void *addr;
IRObj *p = obj;
int r;
+ int protocol_type = CS_Z3950;
if (argc == 3)
{
interp->result = "already connected";
return TCL_ERROR;
}
+ if (!strcmp (p->protocol_type, "Z3950"))
+ protocol_type = CS_Z3950;
+ else if (!strcmp (p->protocol_type, "SR"))
+ protocol_type = CS_SR;
+ else
+ {
+ interp->result = "bad protocol type";
+ return TCL_ERROR;
+ }
if (!strcmp (p->cs_type, "tcpip"))
{
- p->cs_link = cs_create (tcpip_type, CS_BLOCK);
+ p->cs_link = cs_create (tcpip_type, CS_BLOCK, protocol_type);
addr = tcpip_strtoaddr (argv[2]);
if (!addr)
{
#if MOSI
else if (!strcmp (p->cs_type, "mosi"))
{
- p->cs_link = cs_create (mosi_type, CS_BLOCK);
+ p->cs_link = cs_create (mosi_type, CS_BLOCK, protocol_type);
addr = mosi_strtoaddr (argv[2]);
if (!addr)
{
#endif
else
{
- interp->result = "unknown cs type";
+ interp->result = "unknown comstack type";
return TCL_ERROR;
}
if (ir_strdup (interp, &p->hostname, argv[2]) == TCL_ERROR)
}
/*
+ * do_protocol: Set/get protocol method on IR object
+ */
+static int do_protocol (void *o, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRObj *obj = o;
+
+ if (argc == 3)
+ {
+ free (obj->protocol_type);
+ if (ir_strdup (interp, &obj->protocol_type, argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ }
+ Tcl_AppendElement (interp, obj->protocol_type);
+ return TCL_OK;
+}
+
+/*
* do_callback: add callback
*/
static int do_callback (void *obj, Tcl_Interp *interp,
}
/*
+ * do_failback: add error handle callback
+ */
+static int do_failback (void *obj, Tcl_Interp *interp,
+ int argc, char **argv)
+{
+ IRObj *p = obj;
+
+ if (argc == 3)
+ {
+ free (p->failback);
+ if (ir_strdup (interp, &p->failback, argv[2]) == TCL_ERROR)
+ return TCL_ERROR;
+ p->interp = interp;
+ }
+ return TCL_OK;
+}
+
+/*
* do_databaseNames: specify database names
*/
static int do_databaseNames (void *obj, Tcl_Interp *interp,
{
static IRMethod tab[] = {
{ 1, "comstack", do_comstack },
+ { 1, "protocol", do_protocol },
{ 1, "connect", do_connect },
{ 0, "protocolVersion", do_protocolVersion },
{ 0, "options", do_options },
{ 0, "init", do_init_request },
{ 0, "disconnect", do_disconnect },
{ 0, "callback", do_callback },
+ { 0, "failback", do_failback },
{ 1, "databaseNames", do_databaseNames},
{ 1, "replaceIndicator", do_replaceIndicator},
{ 1, "query", do_query },
return TCL_ERROR;
if (ir_strdup (interp, &obj->cs_type, "tcpip") == TCL_ERROR)
return TCL_ERROR;
+ if (ir_strdup (interp, &obj->protocol_type, "Z3950") == TCL_ERROR)
+ return TCL_ERROR;
obj->cs_link = NULL;
obj->maximumRecordSize = 32768;
obj->buf_in = NULL;
obj->callback = NULL;
+ obj->failback = NULL;
Tcl_CreateCommand (interp, argv[1], ir_obj_method,
(ClientData) obj, ir_obj_delete);
return TCL_OK;
{
query.which = Z_Query_type_2;
query.u.type_2 = &ccl_query;
- ccl_query.buf = argv[2];
+ ccl_query.buf = (unsigned char *) argv[2];
ccl_query.len = strlen (argv[2]);
printf ("- CCL\n");
}
if (r < 0)
{
printf ("cs_rcvconnect error\n");
+ if (p->failback)
+ Tcl_Eval (p->interp, p->failback);
return;
}
if (p->callback)
{
printf ("cs_get failed\n");
ir_select_remove (cs_fileno (p->cs_link), p);
+ if (p->failback)
+ Tcl_Eval (p->interp, p->failback);
return;
}
if (r == 1)
if (!z_APDU (p->odr_in, &apdu, 0))
{
printf ("%s\n", odr_errlist [odr_geterror (p->odr_in)]);
+ if (p->failback)
+ Tcl_Eval (p->interp, p->failback);
return;
}
switch(apdu->which)
default:
printf("Received unknown APDU type (%d).\n",
apdu->which);
+ if (p->failback)
+ Tcl_Eval (p->interp, p->failback);
}
if (p->callback)
Tcl_Eval (p->interp, p->callback);
{
printf ("cs_rcvconnect error\n");
ir_select_remove_write (cs_fileno (p->cs_link), p);
+ if (p->failback)
+ Tcl_Eval (p->interp, p->failback);
return;
}
ir_select_remove_write (cs_fileno (p->cs_link), p);
{
printf ("select write fail\n");
cs_close (p->cs_link);
+ if (p->failback)
+ Tcl_Eval (p->interp, p->failback);
}
else if (r == 0) /* remove select bit */
{