Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
mediastreamer2
Commits
b11ddf09
Commit
b11ddf09
authored
Sep 07, 2012
by
Ghislain MARY
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add logging to the oRTP dependencies.
parent
62f4506b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
305 additions
and
0 deletions
+305
-0
src/ortp-deps/logging.c
src/ortp-deps/logging.c
+157
-0
src/ortp-deps/ortp/logging.h
src/ortp-deps/ortp/logging.h
+146
-0
src/ortp-deps/update_ortp.sh
src/ortp-deps/update_ortp.sh
+2
-0
No files found.
src/ortp-deps/logging.c
0 → 100644
View file @
b11ddf09
/*
The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ortp/logging.h"
static
FILE
*
__log_file
=
0
;
/**
*@param file a FILE pointer where to output the ortp logs.
*
**/
void
ortp_set_log_file
(
FILE
*
file
)
{
__log_file
=
file
;
}
static
void
__ortp_logv_out
(
OrtpLogLevel
lev
,
const
char
*
fmt
,
va_list
args
);
OrtpLogFunc
ortp_logv_out
=
__ortp_logv_out
;
/**
*@param func: your logging function, compatible with the OrtpLogFunc prototype.
*
**/
void
ortp_set_log_handler
(
OrtpLogFunc
func
){
ortp_logv_out
=
func
;
}
unsigned
int
__ortp_log_mask
=
ORTP_WARNING
|
ORTP_ERROR
|
ORTP_FATAL
;
/**
* @ param levelmask a mask of ORTP_DEBUG, ORTP_MESSAGE, ORTP_WARNING, ORTP_ERROR
* ORTP_FATAL .
**/
void
ortp_set_log_level_mask
(
int
levelmask
){
__ortp_log_mask
=
levelmask
;
}
char
*
ortp_strdup_vprintf
(
const
char
*
fmt
,
va_list
ap
)
{
/* Guess we need no more than 100 bytes. */
int
n
,
size
=
200
;
char
*
p
,
*
np
;
#ifndef WIN32
va_list
cap
;
/*copy of our argument list: a va_list cannot be re-used (SIGSEGV on linux 64 bits)*/
#endif
if
((
p
=
(
char
*
)
ortp_malloc
(
size
))
==
NULL
)
return
NULL
;
while
(
1
)
{
/* Try to print in the allocated space. */
#ifndef WIN32
va_copy
(
cap
,
ap
);
n
=
vsnprintf
(
p
,
size
,
fmt
,
cap
);
va_end
(
cap
);
#else
/*this works on 32 bits, luckily*/
n
=
vsnprintf
(
p
,
size
,
fmt
,
ap
);
#endif
/* If that worked, return the string. */
if
(
n
>
-
1
&&
n
<
size
)
return
p
;
//printf("Reallocing space.\n");
/* Else try again with more space. */
if
(
n
>
-
1
)
/* glibc 2.1 */
size
=
n
+
1
;
/* precisely what is needed */
else
/* glibc 2.0 */
size
*=
2
;
/* twice the old size */
if
((
np
=
(
char
*
)
ortp_realloc
(
p
,
size
))
==
NULL
)
{
free
(
p
);
return
NULL
;
}
else
{
p
=
np
;
}
}
}
char
*
ortp_strdup_printf
(
const
char
*
fmt
,...){
char
*
ret
;
va_list
args
;
va_start
(
args
,
fmt
);
ret
=
ortp_strdup_vprintf
(
fmt
,
args
);
va_end
(
args
);
return
ret
;
}
#if defined(WIN32) || defined(_WIN32_WCE)
#define ENDLINE "\r\n"
#else
#define ENDLINE "\n"
#endif
#if defined(WIN32) || defined(_WIN32_WCE)
void
ortp_logv
(
int
level
,
const
char
*
fmt
,
va_list
args
)
{
if
(
ortp_logv_out
!=
NULL
&&
ortp_log_level_enabled
(
level
))
ortp_logv_out
(
level
,
fmt
,
args
);
#if !defined(_WIN32_WCE)
if
((
level
)
==
ORTP_FATAL
)
abort
();
#endif
}
#endif
static
void
__ortp_logv_out
(
OrtpLogLevel
lev
,
const
char
*
fmt
,
va_list
args
){
const
char
*
lname
=
"undef"
;
char
*
msg
;
if
(
__log_file
==
NULL
)
__log_file
=
stderr
;
switch
(
lev
){
case
ORTP_DEBUG
:
lname
=
"debug"
;
break
;
case
ORTP_MESSAGE
:
lname
=
"message"
;
break
;
case
ORTP_WARNING
:
lname
=
"warning"
;
break
;
case
ORTP_ERROR
:
lname
=
"error"
;
break
;
case
ORTP_FATAL
:
lname
=
"fatal"
;
break
;
default:
ortp_fatal
(
"Bad level !"
);
}
msg
=
ortp_strdup_vprintf
(
fmt
,
args
);
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
OutputDebugString
(
msg
);
OutputDebugString
(
"
\r\n
"
);
#endif
fprintf
(
__log_file
,
"ortp-%s-%s"
ENDLINE
,
lname
,
msg
);
fflush
(
__log_file
);
ortp_free
(
msg
);
}
src/ortp-deps/ortp/logging.h
0 → 100644
View file @
b11ddf09
/*
The oRTP library is an RTP (Realtime Transport Protocol - rfc3550) stack.
Copyright (C) 2001 Simon MORLAT simon.morlat@linphone.org
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* \file logging.h
* \brief Logging API.
*
**/
#ifndef ORTP_LOGGING_H
#define ORTP_LOGGING_H
#include <ortp/port.h>
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
enum
{
ORTP_DEBUG
=
1
,
ORTP_MESSAGE
=
1
<<
1
,
ORTP_WARNING
=
1
<<
2
,
ORTP_ERROR
=
1
<<
3
,
ORTP_FATAL
=
1
<<
4
,
ORTP_TRACE
=
1
<<
5
,
ORTP_LOGLEV_END
=
1
<<
6
}
OrtpLogLevel
;
typedef
void
(
*
OrtpLogFunc
)(
OrtpLogLevel
lev
,
const
char
*
fmt
,
va_list
args
);
void
ortp_set_log_file
(
FILE
*
file
);
void
ortp_set_log_handler
(
OrtpLogFunc
func
);
VAR_DECLSPEC
OrtpLogFunc
ortp_logv_out
;
extern
unsigned
int
__ortp_log_mask
;
#define ortp_log_level_enabled(level) (__ortp_log_mask & (level))
#if !defined(WIN32) && !defined(_WIN32_WCE)
#define ortp_logv(level,fmt,args) \
{\
if (ortp_logv_out!=NULL && ortp_log_level_enabled(level)) \
ortp_logv_out(level,fmt,args);\
if ((level)==ORTP_FATAL) abort();\
}while(0)
#else
void
ortp_logv
(
int
level
,
const
char
*
fmt
,
va_list
args
);
#endif
void
ortp_set_log_level_mask
(
int
levelmask
);
#ifdef __GNUC__
#define CHECK_FORMAT_ARGS(m,n) __attribute__((format(printf,m,n)))
#else
#define CHECK_FORMAT_ARGS(m,n)
#endif
#ifdef ORTP_DEBUG_MODE
static
inline
void
CHECK_FORMAT_ARGS
(
1
,
2
)
ortp_debug
(
const
char
*
fmt
,...)
{
va_list
args
;
va_start
(
args
,
fmt
);
ortp_logv
(
ORTP_DEBUG
,
fmt
,
args
);
va_end
(
args
);
}
#else
#define ortp_debug(...)
#endif
#ifdef ORTP_NOMESSAGE_MODE
#define ortp_log(...)
#define ortp_message(...)
#define ortp_warning(...)
#else
static
inline
void
CHECK_FORMAT_ARGS
(
2
,
3
)
ortp_log
(
OrtpLogLevel
lev
,
const
char
*
fmt
,...)
{
va_list
args
;
va_start
(
args
,
fmt
);
ortp_logv
(
lev
,
fmt
,
args
);
va_end
(
args
);
}
static
inline
void
CHECK_FORMAT_ARGS
(
1
,
2
)
ortp_message
(
const
char
*
fmt
,...)
{
va_list
args
;
va_start
(
args
,
fmt
);
ortp_logv
(
ORTP_MESSAGE
,
fmt
,
args
);
va_end
(
args
);
}
static
inline
void
CHECK_FORMAT_ARGS
(
1
,
2
)
ortp_warning
(
const
char
*
fmt
,...)
{
va_list
args
;
va_start
(
args
,
fmt
);
ortp_logv
(
ORTP_WARNING
,
fmt
,
args
);
va_end
(
args
);
}
#endif
static
inline
void
CHECK_FORMAT_ARGS
(
1
,
2
)
ortp_error
(
const
char
*
fmt
,...)
{
va_list
args
;
va_start
(
args
,
fmt
);
ortp_logv
(
ORTP_ERROR
,
fmt
,
args
);
va_end
(
args
);
}
static
inline
void
CHECK_FORMAT_ARGS
(
1
,
2
)
ortp_fatal
(
const
char
*
fmt
,...)
{
va_list
args
;
va_start
(
args
,
fmt
);
ortp_logv
(
ORTP_FATAL
,
fmt
,
args
);
va_end
(
args
);
}
#ifdef __cplusplus
}
#endif
#endif
src/ortp-deps/update_ortp.sh
View file @
b11ddf09
...
...
@@ -9,8 +9,10 @@ rm -rf $TEMPGITDIR
git clone
$GITURL
$TEMPGITDIR
mkdir
-p
ortp
cp
-f
$TEMPGITDIR
/include/ortp/logging.h ortp/
cp
-f
$TEMPGITDIR
/include/ortp/port.h ortp/
cp
-f
$TEMPGITDIR
/include/ortp/str_utils.h ortp/
cp
-f
$TEMPGITDIR
/src/logging.c
.
cp
-f
$TEMPGITDIR
/src/port.c
.
cp
-f
$TEMPGITDIR
/src/str_utils.c
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment