Files
smmapdfw/smmapdfw/smmapd/workertest.c
2005-04-01 12:49:34 +00:00

130 lines
3.2 KiB
C

/*
Copyright (C) 2005, Wolfgang Hottgenroth
This file is part of smmapdfw.
smmapdfw is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
smmapdfw is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
License for more details.
You should have received a copy of the GNU General Public License
along with smmapdfw. If not, write to the Free Software Foundation, 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define CVS_ID "$Id$"
#define RELEASE_ID "0.1"
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <syslog.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "htbuffer.h"
#include "containers.h"
#include "cfg.h"
#define _SMMAPD_C_
#include "smmapd.h"
cfg_t *cfg;
void usage() {
printf("workertest -f cfgfile [-h] -w worker -q query\n");
printf(" -f cfgfile\n");
printf(" -h print this help\n");
printf(" -w worker to use\n");
printf(" -q query parameters\n\n");
}
int main(int argc, char **argv) {
int c, res, dispatcher_result;
char *cfg_file=NULL, *worker=NULL, *query=NULL;
void *handle;
container_handle_t *container_handle;
htbuffer_t *answer, *input;
while ((c = getopt(argc, argv,"w:q:f:hv")) != -1)
switch (c) {
case 'f':
cfg_file = htstrdup(optarg);
break;
case 'w':
worker = htstrdup(optarg);
break;
case 'q':
query = htstrdup(optarg);
break;
case 'v':
printf("\nworkertest - Wolfgang Hottgenroth <woho@hottis.de>\n");
printf(" cvs_id: %s\n", CVS_ID);
printf(" release_id: %s\n\n", RELEASE_ID);
exit(1);
case 'h':
default:
usage();
exit(1);
}
if (NULL == cfg_file) {
usage();
exit(1);
}
openlog("workertest", LOG_PID, LOG_LOCAL2);
syslog(LOG_INFO, "main: started");
cfg = readcfg((cfg_file == NULL) ? DEFAULT_SMMAPD_INI : cfg_file);
syslog(LOG_INFO, "main: load worker");
res = register_worker(worker);
if (0 != res) {
syslog(LOG_INFO, "main: unable to load worker");
exit(1);
}
syslog(LOG_INFO, "main: setup containers");
res = containers_setup(&container_handle);
if (0 != res) {
syslog(LOG_INFO, "main: unable to setup containers");
exit(1);
}
answer = htbuffer_init(512);
input = htbuffer_init(512);
htbuffer_strcpy(input, worker);
htbuffer_strcat(input, " ");
htbuffer_strcat(input, query);
syslog(LOG_INFO, "main: querying worker {%s} with {%s}", worker, query);
dispatcher_result = containers_dispatcher(container_handle, input->buf, answer);
syslog(LOG_INFO, "main: result {%d}, answer {%s}", dispatcher_result, answer->buf);
printf("result {%d}, answer {%s}\n", dispatcher_result, answer->buf);
htbuffer_free(input);
htbuffer_free(answer);
syslog(LOG_INFO, "main: buffers freed");
containers_destroy(container_handle);
syslog(LOG_INFO, "main: containers destroyed");
syslog(LOG_INFO, "main: finished");
closelog();
}