/Users/maurits/Documents/studie/afstuderen/biosphere/modules/dummy/bsmod_dummy.c

Go to the documentation of this file.
00001 /*
00002  * Author: MA Hartman
00003  * Date: jan 25, 2007
00004  * 
00005  * Function:
00006  * This is a dummy module to illustrate the workings of a basic module.
00007  * 
00008  * License information:
00009  * 
00010  * Copyright (c) 2006 Maurits Hartman
00011  *
00012  * Permission is hereby granted, free of charge, to any person
00013  * obtaining a copy of this software and associated documentation
00014  * files (the "Software"), to deal in the Software without
00015  * restriction, including without limitation the rights to use,
00016  * copy, modify, merge, publish, distribute, sublicense, and/or sell
00017  * copies of the Software, and to permit persons to whom the
00018  * Software is furnished to do so, subject to the following
00019  * conditions:
00020  * 
00021  * The above copyright notice and this permission notice shall be
00022  * included in all copies or substantial portions of the Software.
00023  * 
00024  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00026  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
00028  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
00029  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00030  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
00031  * OTHER DEALINGS IN THE SOFTWARE.
00032  * 
00033  */
00034  
00035 #include <biosphere_module.h>
00036 
00037 #include <stdio.h>
00038 #include <string.h>
00039 #include <stdlib.h>
00040 #include <sys/time.h>
00041 #include <unistd.h>
00042 
00049 bs_module bsmod_symtable;
00050 
00051 
00055 static bs_status bsmod_dummy_init(void)
00056 {
00057         printf("dummy module initializing!\n");
00058         return BS_OK;   
00059 }
00060 
00061 
00065 static bs_status bsmod_dummy_cleanup(void)
00066 {
00067         printf("shutting bsmod_dummy down!\n");
00068         return BS_OK;   
00069 }
00070 
00071 
00072 static bs_service_response *create_response(const bs_service_request *request)
00073 {
00074         bs_service_response *resp;
00075         bs_message_instance *output;
00076         bs_part_instance *part;
00077         bs_data_type *type;
00078         unsigned i;
00079         char *string;
00080         
00081         string = request->input->parts[0]->data;
00082         
00083         resp = (bs_service_response *) calloc(1, sizeof(bs_service_response));
00084         for (i = 0; i < 16; i++)
00085                 resp->uuid[i] = request->uuid[i];
00086         resp->service = (char *) malloc(strlen(request->service) + 1);
00087         resp->port = (char *) malloc(strlen(request->port) + 1);
00088         resp->operation = (char *) malloc(strlen(request->operation) + 1);
00089         strcpy(resp->service, request->service);
00090         strcpy(resp->port, request->port);
00091         strcpy(resp->operation, request->operation);
00092         
00093         output = (bs_message_instance *) calloc(1, sizeof(bs_service_response));
00094         output->name = (char *) malloc(strlen("EchoResponse") + 1);
00095         strcpy(output->name, "EchoResponse");
00096         output->num_parts = 1;
00097         output->parts = (bs_part_instance **) calloc(1, sizeof(bs_part_instance *));
00098         resp->output = output;
00099         
00100         part = (bs_part_instance *) calloc(1, sizeof(bs_part_instance));
00101         part->name = (char *) malloc(strlen("") + 1);
00102         strcpy(part->name, "return");
00103         part->data = (char *) calloc(1, strlen(string) + 1);
00104         strcpy(part->data, string);
00105         part->size = strlen(string); 
00106         output->parts[0] = part;
00107         
00108         type = (bs_data_type *) calloc(1, sizeof(bs_data_type));
00109         type->name = (char *) malloc(strlen("bs_string") + 1);
00110         strcpy(type->name, "bs_string");
00111         type->builtin = TRUE;
00112         type->from_mp = FALSE;
00113         part->type = type;
00114         
00115         return resp;
00116 }
00117 
00118 
00122 static bs_status bsmod_dummy_handle_service(
00123                 const bs_service_request *request,
00124                 bs_service_response **response, void *extra)
00125 {
00126         struct timeval t;
00127         
00128         gettimeofday(&t, 0);
00129         printf("%ld.%06ld,", t.tv_sec, t.tv_usec);
00130         
00131         *response = create_response(request);
00132         
00133         gettimeofday(&t, 0);
00134         printf("%ld.%06ld,", t.tv_sec, t.tv_usec);
00135         return BS_OK;           
00136 }
00137 
00138 
00139 /* Here come functions offered by the module: */
00140 
00141 /* Final declaration of the bs_module struct: */
00142 bs_module bsmod_symtable = {
00143         /* The major and minor version of the API used by this module: */
00144         0,
00145         0,
00146         
00147         /* The major and minor version of this module: */
00148         0,
00149         1,
00150         
00151         /* The name, author, date and copyright information: */
00152         "dummy module",
00153         "M.A.Hartman",
00154         "jan 25, 2007",
00155         "(c) 2007, M.A.Hartman. See distributed LICENSE file for more information.",
00156         "A dummy module to illustrate the basic workings of a Bio-SPHERE module. "
00157         "It has basically no functionality and contains just the bare minimum "
00158         "required in a module.",
00159         
00160         /* Init and cleanup routines: */
00161         bsmod_dummy_init,
00162         bsmod_dummy_cleanup,
00163         
00164         /* Service request handling function: */
00165         bsmod_dummy_handle_service,
00166         NULL,
00167         "bsmod_dummy.wsdl"
00168 };
00169 

Generated on Tue Jul 17 09:50:52 2007 for Bio-SPHERE by  doxygen 1.5.1