Mercurial > hg > freeDiameter
changeset 653:34373acfbc6a
Added sample C++ file in _sample extension
author | Sebastien Decugis <sdecugis@nict.go.jp> |
---|---|
date | Tue, 11 Jan 2011 12:18:09 +0900 |
parents | c23632480951 |
children | 0b547aa70ff5 |
files | extensions/_sample/CMakeLists.txt extensions/_sample/hello.cpp extensions/_sample/sample.c include/freeDiameter/libfreeDiameter.h libfreeDiameter/log.c |
diffstat | 5 files changed, 72 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/extensions/_sample/CMakeLists.txt Tue Jan 11 12:17:50 2011 +0900 +++ b/extensions/_sample/CMakeLists.txt Tue Jan 11 12:18:09 2011 +0900 @@ -1,5 +1,5 @@ # The sample extension -PROJECT("Sample extension" C) +PROJECT("Sample extension") # Overwrite the debug level for the extension code if configured OPTION(DEBUG_LEVEL__SAMPLE "Overwrite debug level for the extension _sample if defined (valid values: FULL, ANNOYING, CALL...)" OFF) @@ -11,7 +11,7 @@ ENDIF (NOT CMAKE_BUILD_TYPE MATCHES "Debug") # Compile as a module -FD_ADD_EXTENSION(dbg_sample sample.c fini.c) +FD_ADD_EXTENSION(dbg_sample sample.c hello.cpp fini.c) ####
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extensions/_sample/hello.cpp Tue Jan 11 12:18:09 2011 +0900 @@ -0,0 +1,50 @@ +/********************************************************************************************************* +* Software License Agreement (BSD License) * +* Author: Sebastien Decugis <sdecugis@nict.go.jp> * +* * +* Copyright (c) 2009, WIDE Project and NICT * +* All rights reserved. * +* * +* Redistribution and use of this software in source and binary forms, with or without modification, are * +* permitted provided that the following conditions are met: * +* * +* * Redistributions of source code must retain the above * +* copyright notice, this list of conditions and the * +* following disclaimer. * +* * +* * Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the * +* following disclaimer in the documentation and/or other * +* materials provided with the distribution. * +* * +* * Neither the name of the WIDE Project or NICT nor the * +* names of its contributors may be used to endorse or * +* promote products derived from this software without * +* specific prior written permission of WIDE Project and * +* NICT. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * +* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * +* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * +* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * +* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * +* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * +*********************************************************************************************************/ + +/* Sample file demonstrating how to write some C++ code */ + +#include <iostream> +extern "C" { + #include <freeDiameter/extension.h> + +} + +extern "C" void mycppfunc(); /* will be called from C code */ + + +void mycppfunc() { + std::cout << "Hello World!" << std::endl; + /* done */ +}
--- a/extensions/_sample/sample.c Tue Jan 11 12:17:50 2011 +0900 +++ b/extensions/_sample/sample.c Tue Jan 11 12:18:09 2011 +0900 @@ -36,6 +36,9 @@ /* Sample extension to test extensions mechanism in freeDiameter */ #include <freeDiameter/extension.h> +/* from sample.cpp */ +void mycppfunc(); + static int sample_main(char * conffile); /* Define the entry point. A convenience macro is provided */ @@ -85,6 +88,9 @@ } TRACE_DEBUG(INFO, "'Example-AVP' created without error\n"); + /* Call the c++ function */ + mycppfunc(); + /* The initialization function returns an error code with the standard POSIX meaning (ENOMEM, and so on) */ return 0; }
--- a/include/freeDiameter/libfreeDiameter.h Tue Jan 11 12:17:50 2011 +0900 +++ b/include/freeDiameter/libfreeDiameter.h Tue Jan 11 12:18:09 2011 +0900 @@ -113,7 +113,7 @@ * RETURN VALUE: * None. */ -void fd_log_debug ( char * format, ... ); +void fd_log_debug ( const char * format, ... ); extern pthread_mutex_t fd_log_lock; extern char * fd_debug_one_function; extern char * fd_debug_one_file; @@ -194,7 +194,7 @@ /* A version of __FILE__ without the full path */ static char * file_bname = NULL; -#define __STRIPPED_FILE__ (file_bname ?: (file_bname = basename(__FILE__))) +#define __STRIPPED_FILE__ (file_bname ?: (file_bname = basename((char *)__FILE__))) /* Boolean for tracing at a certain level */ @@ -215,7 +215,7 @@ #define TRACE_DEBUG(level,format,args... ) { \ if ( TRACE_BOOL(level) ) { \ char __buf[25]; \ - char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ + const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ "\t%s|%*s" format "\n", \ __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ @@ -228,7 +228,7 @@ if ( TRACE_BOOL(level) ) { \ if (fd_g_debug_lvl > FULL) { \ char __buf[25]; \ - char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ + const char * __thn = ((char *)pthread_getspecific(fd_log_thname) ?: "unnamed"); \ fd_log_debug("\t | tid:%-20s\t%s\tin %s@%s:%d\n" \ "\t%s|%*s" format "\n", \ __thn, fd_log_time(NULL, __buf, sizeof(__buf)), __PRETTY_FUNCTION__, __FILE__, __LINE__,\ @@ -483,8 +483,8 @@ /* helper macros (pre-processor hacks to allow macro arguments) */ -#define __str( arg ) #arg -#define _stringize( arg ) __str( arg ) +#define __tostr( arg ) #arg +#define _stringize( arg ) __tostr( arg ) #define __agr( arg1, arg2 ) arg1 ## arg2 #define _aggregate( arg1, arg2 ) __agr( arg1, arg2 ) @@ -1628,7 +1628,7 @@ * sid : pointer to a string containing a Session-Id (UTF-8). * len : length of the sid string (which does not need to be '\0'-terminated) * session : On success, pointer to the session object created / retrieved. - * new : if not NULL, set to 1 on return if the session object has been created, 0 if it was simply retrieved. + * isnew : if not NULL, set to 1 on return if the session object has been created, 0 if it was simply retrieved. * * DESCRIPTION: * Retrieve a session object from a Session-Id string. In case no session object was previously existing with this @@ -1639,7 +1639,7 @@ * EINVAL : A parameter is invalid. * ENOMEM : Not enough memory to complete the operation */ -int fd_sess_fromsid ( char * sid, size_t len, struct session ** session, int * new); +int fd_sess_fromsid ( char * sid, size_t len, struct session ** session, int * isnew); /* * FUNCTION: fd_sess_getsid @@ -2225,7 +2225,7 @@ * dict : the dictionary that contains the Session-Id AVP definition * msg : A valid message. * session : Location to store the session pointer when retrieved. - * new : Indicates if the session has been created. + * isnew : Indicates if the session has been created. * * DESCRIPTION: * This function retrieves or creates the session object corresponding to a message. @@ -2236,7 +2236,7 @@ * 0 : success * !0 : standard error code. */ -int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * new); +int fd_msg_sess_get(struct dictionary * dict, struct msg * msg, struct session ** session, int * isnew); /***************************************/ /* Manage AVP values */ @@ -2663,8 +2663,8 @@ * FUNCTION: fd_fifo_move * * PARAMETERS: - * old : Location of a FIFO that is to be emptied. - * new : A FIFO that will receive the old data. + * oldq : Location of a FIFO that is to be emptied. + * newq : A FIFO that will receive the old data. * loc_update : if non NULL, a place to store the pointer to new FIFO atomically with the move. * * DESCRIPTION: @@ -2674,7 +2674,7 @@ * 0 : The queue has been destroyed successfully. * EINVAL : A parameter is invalid. */ -int fd_fifo_move ( struct fifo * old, struct fifo * new, struct fifo ** loc_update ); +int fd_fifo_move ( struct fifo * oldq, struct fifo * newq, struct fifo ** loc_update ); /* * FUNCTION: fd_fifo_length