Stefan Scholz / ETL
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers message.h Source File

message.h

00001 /******************************************************************************
00002 The MIT License(MIT)
00003 
00004 Embedded Template Library.
00005 https://github.com/ETLCPP/etl
00006 http://www.etlcpp.com
00007 
00008 Copyright(c) 2017 jwellbelove
00009 
00010 Permission is hereby granted, free of charge, to any person obtaining a copy
00011 of this software and associated documentation files(the "Software"), to deal
00012 in the Software without restriction, including without limitation the rights
00013 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
00014 copies of the Software, and to permit persons to whom the Software is
00015 furnished to do so, subject to the following conditions :
00016 
00017 The above copyright notice and this permission notice shall be included in all
00018 copies or substantial portions of the Software.
00019 
00020 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00021 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00022 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
00023 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00024 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00025 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
00026 SOFTWARE.
00027 ******************************************************************************/
00028 
00029 #ifndef __ETL_MESSAGE__
00030 #define __ETL_MESSAGE__
00031 
00032 #include <stdint.h>
00033 
00034 #include "platform.h "
00035 #include "error_handler.h "
00036 #include "exception.h "
00037 #include "message_types.h"
00038 
00039 #undef ETL_FILE
00040 #define ETL_FILE "38"
00041 
00042 namespace etl
00043 {
00044   //***************************************************************************
00045   class message_exception : public etl::exception
00046   {
00047   public:
00048 
00049     message_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
00050       : exception(reason_, file_name_, line_number_)
00051     {
00052     }
00053   };
00054 
00055   //***************************************************************************
00056   class unhandled_message_exception : public etl::message_exception
00057   {
00058   public:
00059 
00060     unhandled_message_exception(string_type file_name_, numeric_type line_number_)
00061       : message_exception(ETL_ERROR_TEXT("message:unknown", ETL_FILE"A"), file_name_, line_number_)
00062     {
00063     }
00064   };
00065 
00066   //***************************************************************************
00067   class imessage
00068   {
00069   public:
00070 
00071 #ifdef ETL_MESSAGES_ARE_VIRTUAL
00072     virtual ~imessage()
00073     {
00074     }
00075 #endif
00076 
00077     imessage(etl::message_id_t id) 
00078       : message_id(id)
00079     {
00080     }
00081 
00082     const etl::message_id_t message_id;
00083   };
00084 
00085   //***************************************************************************
00086   template <const etl::message_id_t ID_>
00087   class message : public imessage
00088   {
00089   public:
00090 
00091     message()
00092       : imessage(ID_)
00093     {
00094     }
00095 
00096     enum
00097     {
00098       ID = ID_
00099     };
00100   };
00101 }
00102 
00103 #undef ETL_FILE
00104 
00105 #endif
00106