1
/******************************************************************************
5
* Purpose: Implementation of the projCtx thread context object.
6
* Author: Frank Warmerdam, warmerdam@pobox.com
8
******************************************************************************
9
* Copyright (c) 2010, Frank Warmerdam
11
* Permission is hereby granted, free of charge, to any person obtaining a
12
* copy of this software and associated documentation files (the "Software"),
13
* to deal in the Software without restriction, including without limitation
14
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
15
* and/or sell copies of the Software, and to permit persons to whom the
16
* Software is furnished to do so, subject to the following conditions:
18
* The above copyright notice and this permission notice shall be included
19
* in all copies or substantial portions of the Software.
21
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
* DEALINGS IN THE SOFTWARE.
28
*****************************************************************************/
35
static projCtx_t default_context;
36
static int default_context_initialized = 0;
38
/************************************************************************/
40
/************************************************************************/
42
projCtx pj_get_ctx( projPJ pj )
48
/************************************************************************/
51
/* Note we do not deallocate the old context! */
52
/************************************************************************/
54
void pj_set_ctx( projPJ pj, projCtx ctx )
60
/************************************************************************/
61
/* pj_get_default_ctx() */
62
/************************************************************************/
64
projCtx pj_get_default_ctx()
69
if( !default_context_initialized )
71
default_context_initialized = 1;
72
default_context.last_errno = 0;
73
default_context.debug_level = PJ_LOG_NONE;
74
default_context.logger = pj_stderr_logger;
75
default_context.app_data = NULL;
77
if( getenv("PROJ_DEBUG") != NULL )
79
if( atoi(getenv("PROJ_DEBUG")) > 0 )
80
default_context.debug_level = atoi(getenv("PROJ_DEBUG"));
82
default_context.debug_level = PJ_LOG_DEBUG_MINOR;
88
return &default_context;
91
/************************************************************************/
93
/************************************************************************/
95
projCtx pj_ctx_alloc()
98
projCtx ctx = (projCtx_t *) malloc(sizeof(projCtx_t));
99
memcpy( ctx, pj_get_default_ctx(), sizeof(projCtx_t) );
105
/************************************************************************/
107
/************************************************************************/
109
void pj_ctx_free( projCtx ctx )
115
/************************************************************************/
116
/* pj_ctx_get_errno() */
117
/************************************************************************/
119
int pj_ctx_get_errno( projCtx ctx )
122
return ctx->last_errno;
125
/************************************************************************/
126
/* pj_ctx_set_errno() */
128
/* Also sets the global errno. */
129
/************************************************************************/
131
void pj_ctx_set_errno( projCtx ctx, int new_errno )
134
ctx->last_errno = new_errno;
136
pj_errno = new_errno;
139
/************************************************************************/
140
/* pj_ctx_set_debug() */
141
/************************************************************************/
143
void pj_ctx_set_debug( projCtx ctx, int new_debug )
146
ctx->debug_level = new_debug;
149
/************************************************************************/
150
/* pj_ctx_set_logger() */
151
/************************************************************************/
153
void pj_ctx_set_logger( projCtx ctx, void (*new_logger)(void*,int,const char*) )
156
ctx->logger = new_logger;
159
/************************************************************************/
160
/* pj_ctx_set_app_data() */
161
/************************************************************************/
163
void pj_ctx_set_app_data( projCtx ctx, void *new_app_data )
166
ctx->app_data = new_app_data;
169
/************************************************************************/
170
/* pj_ctx_get_app_data() */
171
/************************************************************************/
173
void *pj_ctx_get_app_data( projCtx ctx )
176
return ctx->app_data;