Files
smmapdfw/smmapdfw/test_worker/test_workers.c
2004-10-15 11:18:48 +00:00

92 lines
2.6 KiB
C

/*
Copyright (C) 2004, 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.
*/
#include <stdlib.h>
#include <syslog.h>
#include "containers_public.h"
#include "htmalloc.h"
int test_worker1_init(cfgl_t *cfg, void **handle);
int test_worker1_setup(void *handle, void **work_handle);
int test_worker1_destroy(void *handle, void *work_handle);
int test_worker1_work(void *handle, void *work_handle, char *input, char *output);
int test_worker2_work(void *handle, void *work_handle, char *input, char *output);
class_descriptor_t test_worker1 = {
"test_worker1",
&test_worker1_init,
NULL,
&test_worker1_setup,
&test_worker1_work,
&test_worker1_destroy
};
class_descriptor_t test_worker2 = {
"test_worker2",
NULL,
NULL,
NULL,
&test_worker2_work,
NULL
};
struct test_worker1_handle_s {
int counter;
};
typedef struct test_worker1_handle_s test_worker1_handle_t;
int test_worker1_init(cfgl_t *cfg, void **handle) {
*handle = (char*) findcfgl(cfg, "text");
syslog(LOG_DEBUG, "test_worker1_init: %s", *handle);
if (NULL == *handle) {
syslog(LOG_ERR, "test_worker1_init: text not configured");
return -1;
}
return 0;
}
int test_worker1_setup(void *handle, void **work_handle) {
test_worker1_handle_t *twh = (test_worker1_handle_t*)htmalloc(sizeof(test_worker1_handle_t));
twh->counter = 0;
*work_handle = twh;
return 0;
}
int test_worker1_destroy(void *handle, void *work_handle) {
syslog(LOG_DEBUG, "test_worker1_destroy: freeing the worker handle");
free(work_handle);
}
int test_worker1_work(void *handle, void *work_handle, char *input, char *output) {
sprintf(output, "Test-Worker 1 receives %s (handle %s) (called %d)\n",
input, (char*)handle, (((test_worker1_handle_t*)work_handle)->counter)++);
return 0;
}
int test_worker2_work(void *handle, void *work_handle, char *input, char *output) {
sprintf(output, "Test-Worker 2 receives %s\n", input);
return 0;
}