xorp

xrl_pf.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-2011 XORP, Inc and Others
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 // XRL Protocol Family Header
00023 
00024 #ifndef __LIBXIPC_XRL_PF_HH__
00025 #define __LIBXIPC_XRL_PF_HH__
00026 
00027 
00028 
00029 #include "libxorp/eventloop.hh"
00030 #include "libxorp/timer.hh"
00031 #include "libxorp/exceptions.hh"
00032 
00033 
00034 
00035 class Xrl;
00036 class XrlError;
00037 class XrlArgs;
00038 class XrlDispatcher;
00039 
00040 class XrlPFConstructorError : public XorpReasonedException
00041 {
00042 public:
00043     XrlPFConstructorError(const char* file, size_t line, const string& reason)
00044     : XorpReasonedException("XrlPFConstructorError", file, line, reason)
00045     {}
00046 };
00047 
00048 class XrlPFListener
00049 {
00050 public:
00051     XrlPFListener(EventLoop& e, XrlDispatcher* d = 0);
00052     virtual ~XrlPFListener();
00053 
00054     virtual const char* address() const = 0;
00055 
00056     virtual const char* protocol() const = 0;
00057 
00058     bool set_dispatcher(const XrlDispatcher* d);
00059 
00060     const XrlDispatcher* dispatcher() const { return _dispatcher; }
00061     EventLoop& eventloop() const        { return _eventloop; }
00062 
00063     virtual bool response_pending() const = 0;
00064 
00065     virtual string toString() const = 0;
00066 
00067 protected:
00068     EventLoop& _eventloop;
00069     const XrlDispatcher* _dispatcher;
00070 };
00071 
00072 
00073 // ----------------------------------------------------------------------------
00074 // XrlPFSender
00075 
00076 class XrlPFSender
00077     : public NONCOPYABLE
00078 {
00079 public:
00080     typedef
00081     XorpCallback2<void, const XrlError&, XrlArgs*>::RefPtr SendCallback;
00082 
00083 public:
00084     XrlPFSender(const string& name, EventLoop& e, const char* address);
00085     virtual ~XrlPFSender();
00086 
00102     virtual bool send(const Xrl&        xrl,
00103               bool          direct_call,
00104               const SendCallback&   cb) = 0;
00105 
00106     virtual bool    sends_pending() const = 0;
00107     virtual const char* protocol() const = 0;
00108 
00114     virtual bool    alive() const = 0;
00115 
00116     // XXX Unfinished support for XRL batching.
00117     virtual void    batch_start() {}
00118     virtual void    batch_stop() {}
00119 
00120     const string& address() const       { return _address; }
00121     EventLoop& eventloop() const        { return _eventloop; }
00122     virtual void set_address(const char* a) { _address = a; }
00123     virtual string toString() const;
00124 
00125 protected:
00126     EventLoop& _eventloop;
00127     string _address;
00128     string _name; // for debugging
00129 };
00130 
00131 #endif // __LIBXIPC_XRL_PF_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations