xorp

common.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
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/rip/tools/common.hh,v 1.10 2008/10/02 21:58:21 bms Exp $
00021 
00022 #ifndef __RIP_TOOLS_COMMON_HH__
00023 #define __RIP_TOOLS_COMMON_HH__
00024 
00025 
00026 
00027 #include "libxorp/xorp.h"
00028 #include "libxorp/ipv4.hh"
00029 #include "libxorp/ipv6.hh"
00030 #include "libxorp/service.hh"
00031 
00032 class EventLoop;
00033 class XrlJobBase;
00034 
00035 // ----------------------------------------------------------------------------
00036 // Utility funtions
00037 
00046 const char* default_xrl_target(uint32_t ip_version);
00047 
00055 uint32_t rip_name_to_ip_version(const char* rip_name);
00056 
00066 bool parse_finder_args(const string&    host_colon_port,
00067                string&      host,
00068                uint16_t&    port);
00069 
00070 
00071 // ----------------------------------------------------------------------------
00072 // Class declarations
00073 
00077 class XrlJobQueue : public ServiceBase
00078 {
00079 public:
00080     typedef ref_ptr<XrlJobBase> Job;
00081 
00082 public:
00083     XrlJobQueue(EventLoop&  e,
00084         const string&   finder_host,
00085         uint16_t    finder_port,
00086         const string&   tgtname);
00087     ~XrlJobQueue();
00088 
00089     int startup();
00090     int shutdown();
00091     void dispatch_complete(const XrlError& xe, const XrlJobBase* cmd);
00092 
00093     XrlSender* sender()         { return _rtr; }
00094     const string& target() const    { return _tgt; }
00095     void enqueue(const Job& cmd)    { _jobs.push_back(cmd); }
00096 
00097 protected:
00098     bool xrl_router_ready_poll();
00099 
00100     void process_next_job();
00101 
00102 protected:
00103     EventLoop&      _e;
00104     string      _fhost; // Finder host
00105     uint16_t        _fport; // Finder port
00106     string      _tgt;   // Xrl target to for jobs
00107 
00108     list<Job>       _jobs;
00109     XrlStdRouter*   _rtr;
00110     XorpTimer       _rtr_poll;  // Timer used to poll XrlRouter::ready
00111     uint32_t        _rtr_poll_cnt;  // Number of timer XrlRouter polled.
00112 };
00113 
00119 class XrlJobBase :
00120     public CallbackSafeObject
00121 {
00122 public:
00123     XrlJobBase(XrlJobQueue& q) : _q(q) {}
00124 
00125     virtual ~XrlJobBase() {}
00126     virtual bool dispatch() = 0;
00127 
00128 protected:
00129     XrlJobQueue& queue() { return _q; }
00130 
00131 private:
00132     XrlJobQueue& _q;
00133 };
00134 
00135 #endif // __RIP_TOOLS_COMMON_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations