if (defined($self->{DELETE})) {
set_delete_handler($self->{DELETE});
}
-
+ if (defined($self->{START})) {
+ set_start_handler($self->{START});
+ }
start_server(@args);
}
The programmer can specify subroutines to take care of the following type
of events:
+ - Start service (called once).
- Initialize request
- Search request
- Present request
means of the SimpleServer object constructor
my $z = new Net::Z3950::SimpleServer(
+ START => \&my_start_handler,
INIT => \&my_init_handler,
CLOSE => \&my_close_handler,
SEARCH => \&my_search_handler,
In particular, you need to use the -T switch to start your SimpleServer
in threaded mode.
+=head2 Start handler
+
+The start handler is called when service is started. The argument hash
+passed to the start handler has the form
+
+ $args = {
+ CONFIG => "default-config" ## GFS config (as given by -c)
+ };
+
+
+The purpose of the start handler is to read the configuration file
+for the Generic Frontend Server . This is specified by option -c.
+If -c is omitted, the configuration file is set to "default-config".
+
+The start handler is optional. It is supported in Simpleserver 1.16 and
+later.
+
=head2 Init handler
The init handler is called whenever a Z39.50 client is attempting
SV *delete_ref = NULL;
SV *scan_ref = NULL;
SV *explain_ref = NULL;
+SV *start_ref = NULL;
PerlInterpreter *root_perl_context;
#define GRS_BUF_SIZE 8192
return;
}
+static void start_stop(struct statserv_options_block *sob, SV *handler_ref)
+{
+ HV *href;
+ dSP;
+ ENTER;
+ SAVETMPS;
+
+ href = newHV();
+ hv_store(href, "CONFIG", 6, newSVpv(sob->configname, 0), 0);
+
+ PUSHMARK(sp);
+
+ XPUSHs(sv_2mortal(newRV((SV*) href)));
+
+ PUTBACK;
+
+ if (handler_ref != NULL)
+ {
+ CV* handler_cv = simpleserver_sv2cv( handler_ref );
+ perl_call_sv( (SV *) handler_cv, G_SCALAR | G_DISCARD);
+ }
+
+ SPAGAIN;
+
+ PUTBACK;
+ FREETMPS;
+ LEAVE;
+
+
+}
+
+void bend_start(struct statserv_options_block *sob)
+{
+ start_stop(sob, start_ref);
+}
MODULE = Net::Z3950::SimpleServer PACKAGE = Net::Z3950::SimpleServer
CODE:
explain_ref = newSVsv(arg);
+void
+set_start_handler(arg)
+ SV *arg
+ CODE:
+ start_ref = newSVsv(arg);
+
int
start_server(...)
PREINIT:
char *ptr;
int i;
STRLEN len;
+ struct statserv_options_block *sob;
CODE:
argv_buf = (char **)xmalloc((items + 1) * sizeof(char *));
argv = argv_buf;
strcpy(*argv_buf++, ptr);
}
*argv_buf = NULL;
+
+ sob = statserv_getcontrol();
+ sob->bend_start = bend_start;
+ statserv_setcontrol(sob);
+
root_perl_context = PERL_GET_CONTEXT;
yaz_mutex_create(&simpleserver_mutex);
#if 0
/* only for debugging perl_clone .. */
tst_clones();
#endif
-
+
RETVAL = statserv_main(items, argv, bend_init, bend_close);
OUTPUT:
RETVAL
}
}
+sub my_start_handler {
+ my $args = shift;
+ my $config = $args->{CONFIG};
+}
+
Net::Z3950::SimpleServer::yazlog("hello");
my $handler = new Net::Z3950::SimpleServer(
+ START => "main::my_start_handler",
INIT => "main::my_init_handler",
SEARCH => "main::my_search_handler",
SCAN => "main::my_scan_handler",