~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSException.cc

  • Committer: Monty Taylor
  • Date: 2010-09-26 21:24:15 UTC
  • mto: (1796.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 1797.
  • Revision ID: mordred@inaugust.com-20100926212415-5fn3p3q75pgiei7r
Moved protocol doc into the docs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
2
 *
3
3
 * PrimeBase Media Stream for MySQL
4
4
 *
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
20
 * Continued development: Barry Leslie
27
27
 
28
28
#include "CSConfig.h"
29
29
 
30
 
#ifdef OS_WINDOWS
31
 
#define strsignal(s) NULL
32
 
#else
33
30
#include <sys/signal.h>
34
 
#endif
35
 
 
36
31
#include <limits.h>
37
32
#include <string.h>
38
33
 
73
68
        CSL.log(self, CSLog::Error, " ");
74
69
        CSL.log(self, CSLog::Error, getMessage());
75
70
        CSL.eol(self, CSLog::Error);
76
 
#ifdef DUMP_STACK_TRACE
77
71
        CSL.log(self, CSLog::Error, getStackTrace());
78
 
#endif
79
72
        CSL.unlock();
80
73
}
81
74
 
88
81
        CSL.log(self, CSLog::Error, " ");
89
82
        CSL.log(self, CSLog::Error, getMessage());
90
83
        CSL.eol(self, CSLog::Error);
91
 
#ifdef DUMP_STACK_TRACE
92
84
        CSL.log(self, CSLog::Error, getStackTrace());
93
 
#endif
94
85
        CSL.unlock();
95
86
}
96
87
 
97
 
void CSException::initException_va(const char *func, const char *file, int line, int err, const char *fmt, va_list ap)
98
 
{
99
 
 
100
 
        cs_format_context(CS_EXC_CONTEXT_SIZE, iContext, func, file, line);
101
 
        iErrorCode = err;
102
 
#ifdef OS_WINDOWS
103
 
        vsprintf(iMessage, fmt, ap);
104
 
#else
105
 
        size_t len;
106
 
        len = vsnprintf(iMessage, CS_EXC_MESSAGE_SIZE-1, fmt, ap);
107
 
        if (len > CS_EXC_MESSAGE_SIZE-1)
108
 
                len = CS_EXC_MESSAGE_SIZE-1;
109
 
        iMessage[len] = 0;
110
 
#endif
111
 
}
112
 
 
113
 
void CSException::initExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...)
114
 
{
115
 
        va_list ap;
116
 
 
117
 
        va_start(ap, fmt);
118
 
        initException_va(func, file, line, err, fmt, ap);
119
 
        va_end(ap);
120
 
}
121
 
 
122
88
void CSException::initException(const char *func, const char *file, int line, int err, const char *message)
123
89
{
124
90
        cs_format_context(CS_EXC_CONTEXT_SIZE, iContext, func, file, line);
141
107
{
142
108
        cs_format_context(CS_EXC_CONTEXT_SIZE, iContext, func, file, line);
143
109
        iErrorCode = CS_ERR_ASSERTION;
144
 
        cs_strcpy(CS_EXC_MESSAGE_SIZE, iMessage, "Assertion failed: ");
145
 
        cs_strcat(CS_EXC_MESSAGE_SIZE, iMessage, message);
 
110
        cs_strcpy(CS_EXC_MESSAGE_SIZE, iMessage, message);
146
111
}
147
112
 
148
113
void CSException::getCoreError(uint32_t size, char *buffer, int err)
181
146
        cs_format_context(CS_EXC_CONTEXT_SIZE, iContext, func, file, line);
182
147
        iErrorCode = err;
183
148
        getCoreError(CS_EXC_MESSAGE_SIZE, iMessage, err);
184
 
        cs_replace_string(CS_EXC_MESSAGE_SIZE, iMessage, "%s", item);
 
149
        cs_replace_string(CS_EXC_MESSAGE_SIZE, iMessage, '%', item);
185
150
}
186
151
 
187
152
void CSException::initOSError(const char *func, const char *file, int line, int err)
289
254
        else {
290
255
                CSException e;
291
256
                
292
 
                e.initException(func, file, line, err, message);
 
257
                e.initException(func, file, line, err,message);
293
258
                e.log(NULL, "*** Uncaught error");
294
259
        }
295
260
}
299
264
        throwException(func, file, line, err, message, NULL);
300
265
}
301
266
 
302
 
void CSException::throwExceptionf(const char *func, const char *file, int line, int err, const char *fmt, ...)
303
 
{
304
 
        CSThread        *self;
305
 
        va_list         ap;
306
 
 
307
 
        va_start(ap, fmt);
308
 
        if ((self = CSThread::getSelf())) {
309
 
                self->myException.initException_va(func, file, line, err, fmt, ap);
310
 
                va_end(ap);
311
 
                self->myException.setStackTrace(self, NULL);
312
 
                self->throwException();
313
 
        }
314
 
        else {
315
 
                CSException e;
316
 
                
317
 
                e.initException_va(func, file, line, err, fmt, ap);
318
 
                va_end(ap);
319
 
                e.log(NULL, "*** Uncaught error");
320
 
        }
321
 
}
322
 
 
323
267
void CSException::throwAssertion(const char *func, const char *file, int line, const char *message)
324
268
{
325
269
        CSThread *self;
327
271
        if ((self = CSThread::getSelf())) {
328
272
                self->myException.initAssertion(func, file, line, message);
329
273
                self->myException.setStackTrace(self);
330
 
                /* Not sure why we log the excpetion down here?!
331
274
                self->logException();
332
 
                */
333
275
                self->throwException();
334
276
        }
335
277
        else {
470
412
void CSException::throwLastError(const char *func, const char *file, int line)
471
413
{
472
414
#ifdef OS_WINDOWS
473
 
        throwOSError(func, file, line, (int) GetLastError());
 
415
        throwOSError(func, file, line, (int) getLastError());
474
416
#else
475
417
        throwOSError(func, file, line, (int) errno);
476
418
#endif