xorp

exceptions.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2009 XORP, Inc.
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/bgp/exceptions.hh,v 1.16 2008/11/08 06:14:36 mjh Exp $
00021 
00022 #ifndef __BGP_EXCEPTIONS_HH__
00023 #define __BGP_EXCEPTIONS_HH__
00024 
00025 #include "libxorp/xorp.h"
00026 #include "libxorp/exceptions.hh"
00027 
00028 #ifdef HAVE_SYS_UIO_H
00029 #include <sys/uio.h>
00030 #endif
00031 
00032 #ifdef HAVE_NETINET_IN_H
00033 #include <netinet/in.h>
00034 #endif
00035 
00036 
00040 class CorruptMessage : public XorpReasonedException {
00041 public:
00042     static const size_t MAXPACKETSIZE = 4096;
00043     CorruptMessage(const char* file, size_t line, const string init_why = "")
00044     : XorpReasonedException("CorruptMessage", file, line, init_why),
00045       _error(0), _subcode(0), _len(0)
00046     {}
00047 
00048     CorruptMessage(const char* file, size_t line,
00049            const string init_why,
00050            const int error, const int subcode)
00051     : XorpReasonedException("CorruptMessage", file, line, init_why),
00052       _error(error), _subcode(subcode), _len(0)
00053     {}
00054 
00055     CorruptMessage(const char* file, size_t line,
00056            const string init_why,
00057            const int error, const int subcode,
00058            const uint8_t *data, const size_t len)
00059     : XorpReasonedException("CorruptMessage", file, line, init_why),
00060       _error(error), _subcode(subcode), _len(len)
00061     {assert(_len < MAXPACKETSIZE); memcpy(_data, data, _len);}
00062 
00063     int error() const               { return _error; }
00064     int subcode() const             { return _subcode; }
00065     const uint8_t *data() const         { return _data; }
00066     size_t len() const              { return _len; }
00067 
00068 private:
00069     const int       _error;
00070     const int       _subcode;
00071     // this can't reference external data, as that may go out of
00072     // scope, so have a large enough buffer here to store anything we
00073     // need to return
00074     uint8_t         _data[MAXPACKETSIZE];
00075     const size_t    _len;
00076 };
00077 
00083 class UnusableMessage : public XorpReasonedException {
00084 public:
00085     UnusableMessage(const char* file, size_t line,
00086             const string init_why)
00087     : XorpReasonedException("CorruptMessage", file, line, init_why)
00088     {}
00089 };
00090 
00091 class NoFinder : public XorpReasonedException {
00092 public:
00093     NoFinder(const char* file, size_t line, const string init_why = "")
00094     : XorpReasonedException("NoFinder", file, line, init_why)
00095     {}
00096 };
00097 
00098 #endif // __BGP_EXCEPTIONS_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations