ode/src/error.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     1 /*************************************************************************
       
     2  *                                                                       *
       
     3  * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith.       *
       
     4  * All rights reserved.  Email: russ@q12.org   Web: www.q12.org          *
       
     5  *                                                                       *
       
     6  * This library is free software; you can redistribute it and/or         *
       
     7  * modify it under the terms of EITHER:                                  *
       
     8  *   (1) The GNU Lesser General Public License as published by the Free  *
       
     9  *       Software Foundation; either version 2.1 of the License, or (at  *
       
    10  *       your option) any later version. The text of the GNU Lesser      *
       
    11  *       General Public License is included with this library in the     *
       
    12  *       file LICENSE.TXT.                                               *
       
    13  *   (2) The BSD-style license that is included with this library in     *
       
    14  *       the file LICENSE-BSD.TXT.                                       *
       
    15  *                                                                       *
       
    16  * This library is distributed in the hope that it will be useful,       *
       
    17  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
       
    18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
       
    19  * LICENSE.TXT and LICENSE-BSD.TXT for more details.                     *
       
    20  *                                                                       *
       
    21  *************************************************************************/
       
    22 
       
    23 #include <ode/config.h>
       
    24 #include <ode/error.h>
       
    25 #include <ode/ode.h>
       
    26 
       
    27 
       
    28 extern "C" EXPORT_C void dSetErrorHandler (dMessageFunction *fn)
       
    29 {
       
    30   GetGlobalData()->error_function = fn;
       
    31 }
       
    32 
       
    33 
       
    34 extern "C" EXPORT_C void dSetDebugHandler (dMessageFunction *fn)
       
    35 {
       
    36   GetGlobalData()->debug_function = fn;
       
    37 }
       
    38 
       
    39 
       
    40 extern "C" EXPORT_C void dSetMessageHandler (dMessageFunction *fn)
       
    41 {
       
    42   GetGlobalData()->message_function = fn;
       
    43 }
       
    44 
       
    45 
       
    46 extern "C" EXPORT_C dMessageFunction *dGetErrorHandler()
       
    47 {
       
    48   return GetGlobalData()->error_function;
       
    49 }
       
    50 
       
    51 
       
    52 extern "C" EXPORT_C dMessageFunction *dGetDebugHandler()
       
    53 {
       
    54   return GetGlobalData()->debug_function;
       
    55 }
       
    56 
       
    57 
       
    58 extern "C" EXPORT_C dMessageFunction *dGetMessageHandler()
       
    59 {
       
    60   return GetGlobalData()->message_function;
       
    61 }
       
    62 
       
    63 
       
    64 static void printMessage (int num, const char *msg1, const char *msg2,
       
    65 			  va_list ap)
       
    66 {
       
    67   fflush (stderr);
       
    68   fflush (stdout);
       
    69   if (num) fprintf (stderr,"\n%s %d: ",msg1,num);
       
    70   else fprintf (stderr,"\n%s: ",msg1);
       
    71   vfprintf (stderr,msg2,ap);
       
    72   fprintf (stderr,"\n");
       
    73   fflush (stderr);
       
    74 }
       
    75 
       
    76 //****************************************************************************
       
    77 // unix
       
    78 
       
    79 #ifndef WIN32
       
    80 
       
    81 extern "C" EXPORT_C void dError (int num, const char *msg, ...)
       
    82 {
       
    83   va_list ap;
       
    84   va_start (ap,msg);
       
    85   if (GetGlobalData()->error_function) GetGlobalData()->error_function (num,msg,ap);
       
    86   else printMessage (num,"ODE Error",msg,ap);
       
    87   exit (1);
       
    88 }
       
    89 
       
    90 /*
       
    91 extern "C" void dDebug (int num, const char *msg, ...)
       
    92 {
       
    93   va_list ap;
       
    94   va_start (ap,msg);
       
    95   if (debug_function) debug_function (num,msg,ap);
       
    96   else printMessage (num,"ODE INTERNAL ERROR",msg,ap);
       
    97   // *((char *)0) = 0;   ... commit SEGVicide
       
    98   abort();
       
    99 }
       
   100 
       
   101 
       
   102 extern "C" void dMessage (int num, const char *msg, ...)
       
   103 {
       
   104   va_list ap;
       
   105   va_start (ap,msg);
       
   106   if (message_function) message_function (num,msg,ap);
       
   107   else printMessage (num,"ODE Message",msg,ap);
       
   108 }
       
   109 */
       
   110 #endif
       
   111