cpp/example_cpp_callback_be/example_cpp_callback_be.cpp

Demonstrates the use of a callback back-end.

00001 /* /////////////////////////////////////////////////////////////////////////////
00002  * File:        examples/cpp/example_cpp_callback_be/example_cpp_callback_be.cpp
00003  *
00004  * Purpose:     C++ example program for Pantheios. Demonstrates:
00005  *
00006  *                - use of a back-end library that uses callbacks.
00007  *                - use of pantheios::puts() in bail-out conditions
00008  *
00009  * Created:     25th August 2006
00010  * Updated:     31st August 2006
00011  *
00012  * www:         http://www.pantheios.org/
00013  *
00014  * License:     This source code is placed into the public domain 2006
00015  *              by Synesis Software Pty Ltd. There are no restrictions
00016  *              whatsoever to your use of the software.
00017  *
00018  *              This software is provided "as is", and any warranties,
00019  *              express or implied, of any kind and for any purpose, are
00020  *              disclaimed.
00021  *
00022  * ////////////////////////////////////////////////////////////////////////// */
00023 
00024 
00025 /* Pantheios Header Files */
00026 #include <pantheios/pantheios.hpp>                  // Pantheios C++ main header
00027 #include <pantheios/backends/bec.Win32Console.h>    // Include the API for bec.Win32Console
00028 
00029 /* Standard C/C++ Header Files */
00030 #include <exception>                                // for std::exception
00031 #include <string>                                   // for std::string
00032 #include <stdlib.h>                                 // for exit codes
00033 
00034 /* Windows Header Files */
00035 #include <windows.h>                                // for console colour constants
00036 
00037 /* ////////////////////////////////////////////////////////////////////////// */
00038 
00039 // Define the fe.simple process identity, so that it links when using fe.simple
00040 PANTHEIOS_EXTERN_C const char   FE_SIMPLE_PROCESS_IDENTITY[]    =   "example_cpp_callback_be";
00041 
00042 /* ////////////////////////////////////////////////////////////////////////// */
00043 
00044 PANTHEIOS_CALL(void) pantheios_be_Win32Console_getAppInit(int backEndId, pan_be_Win32Console_init_t *init) /* throw() */
00045 {
00046     STLSOFT_SUPPRESS_UNUSED(backEndId); // Avoid whinging compilers
00047 
00048     init->flags |= PANTHEIOS_BE_WIN32CONSOLE_F_NO_TIME;
00049 
00050     init->colours[pantheios::debug]   = FOREGROUND_BLUE | FOREGROUND_INTENSITY; // Lose the white background
00051     init->colours[pantheios::notice]  = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED; // Lose the intensity
00052 }
00053 
00054 /* ////////////////////////////////////////////////////////////////////////// */
00055 
00056 int main()
00057 {
00058   try
00059   {
00060     pantheios::log_DEBUG("debug");
00061     pantheios::log_INFORMATIONAL("informational");
00062     pantheios::log_NOTICE("notice");
00063     pantheios::log_WARNING("warning");
00064     pantheios::log_ERROR("error");
00065     pantheios::log_CRITICAL("critical");
00066     pantheios::log_ALERT("alert");
00067     pantheios::log_EMERGENCY("emergency");
00068 
00069     return EXIT_SUCCESS;
00070   }
00071   catch(std::bad_alloc &)
00072   {
00073     pantheios::log_CRITICAL("out of memory");
00074   }
00075   catch(std::exception &x)
00076   {
00077     pantheios::log_ERROR("Concatenation failed: ", x);
00078   }
00079   catch(...)
00080   {
00081     pantheios::puts(pantheios::emergency, "Unexpected unknown error");
00082   }
00083 
00084   return EXIT_FAILURE;
00085 }
00086 
00087 /* ////////////////////////////////////////////////////////////////////////// */

pantheios Library documentation © Matthew Wilson, 2006 SourceForge.net Logo