/Users/maurits/Documents/studie/afstuderen/biosphere/library/libbiosphere.c

Go to the documentation of this file.
00001 /*
00002  * Author: MA Hartman
00003  * Date: jan 25, 2007
00004  * 
00005  * Function:
00006  * Main file for the libbiosphere library.
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_lib.h>
00036 #include <copy.h>
00037 #include <http_common.h>
00038 #include <xml.h>
00039 
00040 #include <apr_network_io.h>
00041 #include <apr_strings.h>
00042 #include <apr_time.h>
00043 #include <string.h>
00044 #include <stdlib.h>
00045 #include <stdio.h>
00046 #include <assert.h>
00047 #include <sys/time.h>
00048 
00049 
00050 const char *get_library_version_string(void)
00051 {
00052         return "libbiosphere for " BIOSPHERE_VERSION_STRING;    
00053 }
00054 
00055 
00056 bs_status init_library(void)
00057 {
00058         apr_initialize();
00059         return BS_OK;
00060 }
00061 
00062 
00063 bs_status cleanup_library(void)
00064 {
00065         apr_terminate();
00066         return BS_OK;   
00067 }
00068 
00069 
00070 bs_status get_services_list(bs_definition **result, bs_uint16 port)
00071 {
00072         apr_pool_t *mp;
00073         bs_status rv;
00074         bs_definition *def;
00075         
00076         apr_pool_create(&mp, NULL);
00077         rv = connect_and_get(&def, "localhost", port, mp);
00078         if (rv != BS_OK) return rv;
00079 
00080         /* Copy the bs_definition to avoid memory pools for the client: */
00081         *result = copy_bs_definition(def);
00082         apr_pool_destroy(mp);
00083         return BS_OK;   
00084 }
00085 
00086 
00087 bs_status make_service_request(bs_service_request *request,
00088                 bs_service_response **response, bs_uint16 port)
00089 {
00090         apr_pool_t *mp;
00091         bs_status rv;
00092         bs_service_response *resp;
00093         struct timeval t;
00094         
00095         gettimeofday(&t, 0);
00096         printf("%ld.%06ld,", t.tv_sec, t.tv_usec);
00097         
00098         apr_pool_create(&mp, NULL);
00099         rv = connect_and_post(request, &resp, "localhost", port, mp);
00100         if (rv != BS_OK) return rv;
00101         
00102         /* Copy the bs_definition to avoid memory pools for the client: */
00103         *response = copy_bs_service_response(resp);
00104         apr_pool_destroy(mp);
00105         
00106         gettimeofday(&t, 0);
00107         printf("%ld.%06ld\n", t.tv_sec, t.tv_usec);
00108         return BS_OK;   
00109 }
00110 
00111 
00112 bs_definition *copy_bs_definition(const bs_definition *def)
00113 {
00114         return copy_definition(def);
00115 }
00116 
00117 
00118 void delete_bs_definition(bs_definition *def)
00119 {
00120         delete_definition(def);
00121 }
00122 
00123 
00124 bs_service_response *copy_bs_service_response(const bs_service_response *response)
00125 {
00126         return copy_response(response);
00127 }

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