/Users/maurits/Documents/studie/afstuderen/biosphere/modules/stat/general.c

Go to the documentation of this file.
00001 /*
00002  * Author: MA Hartman
00003  * Date: may 4, 2007
00004  * 
00005  * Function:
00006  * General utility functions for the stat 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 "general.h"
00036 #include <type.h>
00037 
00038 #include <string.h>
00039 #include <apr_strings.h>
00040 
00049 static apr_thread_mutex_t *mux;
00050 
00051 extern apr_pool_t *pool;
00052 
00053 
00054 bs_status init_bsmod_stat_mux(void)
00055 {
00056         apr_status_t rv;
00057     rv = apr_thread_mutex_create(&mux, APR_THREAD_MUTEX_DEFAULT, pool);
00058     if (rv != APR_SUCCESS) return BS_ERROR;
00059     return BS_OK;
00060 }
00061 
00062 
00063 inline void lock_bsmod_stat_mux(void)
00064 {
00065         apr_thread_mutex_lock(mux);     
00066 }
00067 
00068 
00069 inline void unlock_bsmod_stat_mux(void)
00070 {
00071         apr_thread_mutex_unlock(mux);   
00072 }
00073 
00074 
00075 bs_service_response *create_error_response(
00076                 const bs_service_request *request,
00077                 bs_status code, const char *description,
00078                 apr_pool_t *mp)
00079 {
00080         bs_service_response *resp;
00081         bs_message_instance *fault;
00082         bs_part_instance *status, *descr;
00083         bs_data_type *type1, *type2;
00084         char *data1;
00085         
00086         data1 = apr_psprintf(mp, "%u", code);
00087         type1 = new_bs_data_type(mp, "bs_uint32");
00088         type2 = new_bs_data_type(mp, "bs_string");
00089         status = new_bs_part_instance(mp, "status_code", type1,
00090                         data1, strlen(data1));
00091         descr = new_bs_part_instance(mp, "description", type2,
00092                         description, strlen(description));
00093         fault = new_bs_message_instance(mp, "BSModStatFaultMessage", 2);
00094         fault->parts[0] = status;
00095         fault->parts[1] = descr;
00096         resp = new_bs_service_response(mp, request->uuid,
00097                         request->service, request->port, request->operation,
00098                         NULL, fault);
00099         return resp;
00100 }
00101 
00102 
00103 bs_service_response *create_void_message(
00104                 const bs_service_request *request, apr_pool_t *mp)
00105 {
00106         bs_service_response *resp;
00107         bs_message_instance *output;
00108         
00109         output = new_bs_message_instance(mp, "VoidMessage", 0);
00110         resp = new_bs_service_response(mp, request->uuid,
00111                         request->service, request->port, request->operation,
00112                         output, NULL);
00113         return resp;    
00114 }
00115 

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