~ubuntu-branches/ubuntu/wily/proj/wily

« back to all changes in this revision

Viewing changes to src/pj_ctx.c

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine, Jerome Villeneuve Larouche, Francesco Paolo Lovergine
  • Date: 2013-11-25 15:11:25 UTC
  • mfrom: (1.2.7)
  • Revision ID: package-import@ubuntu.com-20131125151125-mvcw144wvgep1hev
Tags: 4.8.0-1
[ Jerome Villeneuve Larouche ]
* New upstream release
* Modified libproj-dev.install to remove nad_list.h and projects.h
* Modified proj-bin.install to remove nad2nad
* Modified proj-bin.manpages to remove nad2nad man
* Added symbols for libproj0

[ Francesco Paolo Lovergine ]
* Properly merged with current git master and sid version 4.7.0-2.
* Removed proj transitional package and obsolete conflicts/replaces against
  series 4.6 and older.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/******************************************************************************
 
2
 * $Id$
 
3
 *
 
4
 * Project:  PROJ.4
 
5
 * Purpose:  Implementation of the projCtx thread context object.
 
6
 * Author:   Frank Warmerdam, warmerdam@pobox.com
 
7
 *
 
8
 ******************************************************************************
 
9
 * Copyright (c) 2010, Frank Warmerdam
 
10
 *
 
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:
 
17
 *
 
18
 * The above copyright notice and this permission notice shall be included
 
19
 * in all copies or substantial portions of the Software.
 
20
 *
 
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
 *****************************************************************************/
 
29
 
 
30
#include <projects.h>
 
31
#include <string.h>
 
32
 
 
33
PJ_CVSID("$Id$");
 
34
 
 
35
static projCtx_t default_context;
 
36
static int       default_context_initialized = 0;
 
37
 
 
38
/************************************************************************/
 
39
/*                             pj_get_ctx()                             */
 
40
/************************************************************************/
 
41
 
 
42
projCtx pj_get_ctx( projPJ pj )
 
43
 
 
44
{
 
45
    return pj->ctx;
 
46
}
 
47
 
 
48
/************************************************************************/
 
49
/*                             pj_set_ctx()                             */
 
50
/*                                                                      */
 
51
/*      Note we do not deallocate the old context!                      */
 
52
/************************************************************************/
 
53
 
 
54
void pj_set_ctx( projPJ pj, projCtx ctx )
 
55
 
 
56
{
 
57
    pj->ctx = ctx;
 
58
}
 
59
 
 
60
/************************************************************************/
 
61
/*                         pj_get_default_ctx()                         */
 
62
/************************************************************************/
 
63
 
 
64
projCtx pj_get_default_ctx()
 
65
 
 
66
{
 
67
    pj_acquire_lock();
 
68
 
 
69
    if( !default_context_initialized )
 
70
    {
 
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;
 
76
 
 
77
        if( getenv("PROJ_DEBUG") != NULL )
 
78
        {
 
79
            if( atoi(getenv("PROJ_DEBUG")) > 0 )
 
80
                default_context.debug_level = atoi(getenv("PROJ_DEBUG"));
 
81
            else
 
82
                default_context.debug_level = PJ_LOG_DEBUG_MINOR;
 
83
        }
 
84
    }
 
85
 
 
86
    pj_release_lock();
 
87
 
 
88
    return &default_context;
 
89
}
 
90
 
 
91
/************************************************************************/
 
92
/*                            pj_ctx_alloc()                            */
 
93
/************************************************************************/
 
94
 
 
95
projCtx pj_ctx_alloc()
 
96
 
 
97
{
 
98
    projCtx ctx = (projCtx_t *) malloc(sizeof(projCtx_t));
 
99
    memcpy( ctx, pj_get_default_ctx(), sizeof(projCtx_t) );
 
100
    ctx->last_errno = 0;
 
101
 
 
102
    return ctx;
 
103
}
 
104
 
 
105
/************************************************************************/
 
106
/*                            pj_ctx_free()                             */
 
107
/************************************************************************/
 
108
 
 
109
void pj_ctx_free( projCtx ctx )
 
110
 
 
111
{
 
112
    free( ctx );
 
113
}
 
114
 
 
115
/************************************************************************/
 
116
/*                          pj_ctx_get_errno()                          */
 
117
/************************************************************************/
 
118
 
 
119
int pj_ctx_get_errno( projCtx ctx )
 
120
 
 
121
{
 
122
    return ctx->last_errno;
 
123
}
 
124
 
 
125
/************************************************************************/
 
126
/*                          pj_ctx_set_errno()                          */
 
127
/*                                                                      */
 
128
/*      Also sets the global errno.                                     */
 
129
/************************************************************************/
 
130
 
 
131
void pj_ctx_set_errno( projCtx ctx, int new_errno )
 
132
 
 
133
{
 
134
    ctx->last_errno = new_errno;
 
135
    if( new_errno != 0 )
 
136
        pj_errno = new_errno;
 
137
}
 
138
 
 
139
/************************************************************************/
 
140
/*                          pj_ctx_set_debug()                          */
 
141
/************************************************************************/
 
142
 
 
143
void pj_ctx_set_debug( projCtx ctx, int new_debug )
 
144
 
 
145
{
 
146
    ctx->debug_level = new_debug;
 
147
}
 
148
 
 
149
/************************************************************************/
 
150
/*                         pj_ctx_set_logger()                          */
 
151
/************************************************************************/
 
152
 
 
153
void pj_ctx_set_logger( projCtx ctx, void (*new_logger)(void*,int,const char*) )
 
154
 
 
155
{
 
156
    ctx->logger = new_logger;
 
157
}
 
158
 
 
159
/************************************************************************/
 
160
/*                        pj_ctx_set_app_data()                         */
 
161
/************************************************************************/
 
162
 
 
163
void pj_ctx_set_app_data( projCtx ctx, void *new_app_data )
 
164
 
 
165
{
 
166
    ctx->app_data = new_app_data;
 
167
}
 
168
 
 
169
/************************************************************************/
 
170
/*                        pj_ctx_get_app_data()                         */
 
171
/************************************************************************/
 
172
 
 
173
void *pj_ctx_get_app_data( projCtx ctx )
 
174
 
 
175
{
 
176
    return ctx->app_data;
 
177
}
 
178
 
 
179