xorp

finder_msgs.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 // vim:set sts=4 ts=8:
00003 
00004 // Copyright (c) 2001-2009 XORP, Inc.
00005 //
00006 // This program is free software; you can redistribute it and/or modify
00007 // it under the terms of the GNU Lesser General Public License, Version
00008 // 2.1, June 1999 as published by the Free Software Foundation.
00009 // Redistribution and/or modification of this program under the terms of
00010 // any other version of the GNU Lesser General Public License is not
00011 // permitted.
00012 // 
00013 // This program is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00016 // see the GNU Lesser General Public License, Version 2.1, a copy of
00017 // which can be found in the XORP LICENSE.lgpl file.
00018 // 
00019 // XORP, Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00020 // http://xorp.net
00021 
00022 // $XORP: xorp/libxipc/finder_msgs.hh,v 1.12 2008/10/02 21:57:20 bms Exp $
00023 
00024 #ifndef __LIBXIPC_FINDER_MSGS_HH__
00025 #define __LIBXIPC_FINDER_MSGS_HH__
00026 
00027 #include "libxorp/xorp.h"
00028 #include "libxorp/exceptions.hh"
00029 
00030 #include "xrl.hh"
00031 #include "xrl_error.hh"
00032 
00036 class FinderMessageBase {
00037 public:
00046     FinderMessageBase(uint32_t seqno, char type);
00047 
00048     virtual ~FinderMessageBase();
00049 
00053     const string& str() const { return _rendered; }
00054 
00055 protected:
00056     // String manipluated by base and child classes to provide serializable
00057     // representation.
00058     string   _rendered; 
00059 
00060     static const char* c_msg_template;
00061 
00062     friend class ParsedFinderMessageBase;
00063 };
00064 
00068 class FinderXrlMessage : public FinderMessageBase {
00069 public:
00070     FinderXrlMessage(const Xrl& xrl);
00071     uint32_t seqno() const { return _seqno; }
00072     
00073 protected:
00074     uint32_t _seqno;
00075     static const char c_type = 'x';
00076     static uint32_t c_seqno;
00077     static const char* c_msg_template;
00078 
00079     friend class ParsedFinderXrlMessage;
00080 };
00081 
00085 class FinderXrlResponse : public FinderMessageBase {
00086 public:
00087     FinderXrlResponse(uint32_t seqno, const XrlError& e, const XrlArgs*);
00088     
00089 protected:
00090     static const char c_type = 'r';
00091     static const char* c_msg_template;
00092 
00093     friend class ParsedFinderXrlResponse;
00094 };
00095 
00099 struct BadFinderMessageFormat : public XorpReasonedException {
00100     BadFinderMessageFormat(const char* file, size_t line, const string& why)
00101     : XorpReasonedException("BadFinderMessageFormat", file, line, why)
00102     {}
00103 };
00104 
00108 struct WrongFinderMessageType : public XorpException {
00109     WrongFinderMessageType(const char* file, size_t line)
00110     : XorpException("WrongFinderMessageType", file, line)
00111     {}
00112 };
00113 
00117 class ParsedFinderMessageBase {
00118 public:
00119 
00127     ParsedFinderMessageBase(const char* data, char type)
00128     throw (BadFinderMessageFormat, WrongFinderMessageType);
00129 
00130     virtual ~ParsedFinderMessageBase();
00131     
00132     uint32_t seqno() const { return _seqno; }
00133     char type() const { return _type; }
00134 
00135 protected:
00136     uint32_t bytes_parsed() const { return _bytes_parsed; }
00137 
00138     uint32_t _seqno;
00139     char     _type;
00140     uint32_t _bytes_parsed;
00141 
00142     static const char* c_msg_template;
00143 };
00144 
00148 class ParsedFinderXrlMessage : public ParsedFinderMessageBase {
00149 public:
00159     ParsedFinderXrlMessage(const char* data)
00160     throw (BadFinderMessageFormat, WrongFinderMessageType, InvalidString);
00161 
00162     ~ParsedFinderXrlMessage();
00163 
00164     const Xrl& xrl() const { return *_xrl; }
00165 
00166 private:
00167     Xrl* _xrl;
00168 };
00169 
00173 class ParsedFinderXrlResponse : public ParsedFinderMessageBase {
00174 public:
00185     ParsedFinderXrlResponse(const char* data)
00186     throw (BadFinderMessageFormat, WrongFinderMessageType, InvalidString);
00187 
00188     ~ParsedFinderXrlResponse();
00189     
00190     const XrlError& xrl_error() const { return _xrl_error; }
00191     XrlArgs* xrl_args() const { return _xrl_args; }
00192 
00193 private:
00194     XrlError _xrl_error;
00195     XrlArgs* _xrl_args;
00196 };
00197 
00198 #endif // __LIBXIPC_FINDER_MSGS_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations