xorp

finder.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 // $XORP: xorp/libxipc/finder.hh,v 1.26 2008/10/02 21:57:19 bms Exp $
00023 
00024 #ifndef __LIBXIPC_FINDER_HH__
00025 #define __LIBXIPC_FINDER_HH__
00026 
00027 #include "libxorp/xorp.h"
00028 
00029 
00030 
00031 
00032 
00033 #include "xrl_cmd_map.hh"
00034 #include "finder_messenger.hh"
00035 #include "finder_xrl_queue.hh"
00036 
00037 
00038 
00039 // periodic HELLO ping of 100 seconds to decrease useless xorp
00040 // RPC messages.
00041 #define XORP_HELLO_TIMER_MS 100000
00042 
00043 class FinderTarget;
00044 class FinderClass;
00045 class FinderEvent;
00046 
00047 class Finder :
00048     public NONCOPYABLE,
00049     public FinderMessengerManager
00050 {
00051 public:
00052     typedef list<FinderMessengerBase*> FinderMessengerList;
00053     typedef map<FinderMessengerBase*, FinderXrlCommandQueue> OutQueueTable;
00054     typedef map<string, FinderTarget> TargetTable;
00055     typedef map<string, FinderClass> ClassTable;
00056     typedef list<string> Resolveables;
00057     typedef list<FinderEvent> EventQueue;
00058 
00059 public:
00060     Finder(EventLoop& e);
00061     virtual ~Finder();
00062 
00063 protected:
00064     /* Methods for FinderMessengerManager interface */
00065     void messenger_active_event(FinderMessengerBase*);
00066     void messenger_inactive_event(FinderMessengerBase*);
00067     void messenger_stopped_event(FinderMessengerBase*);
00068     void messenger_birth_event(FinderMessengerBase*);
00069     void messenger_death_event(FinderMessengerBase*);
00070     bool manages(const FinderMessengerBase*) const;
00071 
00072 public:
00073     XrlCmdMap& commands();
00074 
00075     bool add_target(const string& class_name,
00076             const string& instance_name,
00077             bool      singleton,
00078             const string& cookie);
00079 
00080     bool active_messenger_represents_target(const string& target_name) const;
00081 
00082     bool remove_target(const string& target_name);
00083 
00084     bool remove_target_with_cookie(const string& cookie);
00085 
00086     bool set_target_enabled(const string& target_name, bool en);
00087 
00088     bool target_enabled(const string& target_name, bool& is_enabled) const;
00089 
00090     bool add_resolution(const string& target,
00091             const string& key,
00092             const string& value);
00093 
00094     bool remove_resolutions(const string& target,
00095                 const string& key);
00096 
00097     bool add_class_watch(const string& target,
00098              const string& class_to_watch,
00099              string& err_msg);
00100 
00101     bool remove_class_watch(const string& target,
00102                 const string& class_to_watch);
00103 
00104     bool add_instance_watch(const string& target,
00105                 const string& instance_to_watch,
00106                 string& err_msg);
00107 
00108     bool remove_instance_watch(const string& target,
00109                    const string& instance_to_watch);
00110 
00111     const string& primary_instance(const string& instance_or_class) const;
00112 
00113     const Resolveables* resolve(const string& target, const string& key);
00114 
00115     size_t messengers() const;
00116 
00117     bool fill_target_list(list<string>& target_list) const;
00118     bool fill_targets_xrl_list(const string& target,
00119                    list<string>& xrl_list) const;
00120 
00121 protected:
00125     void log_arrival_event(const string& class_name,
00126                const string& instance_name);
00127 
00131     void log_departure_event(const string& class_name,
00132                  const string& instance_name);
00133 
00134     void announce_xrl_departure(const string& target, const string& key);
00135 
00136     void announce_events_externally();
00137 
00138     void announce_class_instances(const string& recv_instance_name,
00139                   const string& class_name);
00140 
00141     void announce_new_instance(const string& recv_instance_name,
00142                    FinderXrlCommandQueue& out_queue,
00143                    const string& class_name,
00144                    const string& instance_name);
00145 
00146     bool hello_timer_running() const { return _hello.scheduled(); }
00147     void start_hello_timer();
00148     bool send_hello();
00149 
00150     void remove_target(TargetTable::iterator& i);
00151 
00152     bool add_class_instance(const string& class_name,
00153                 const string& instance,
00154                 bool      singleton);
00155 
00156     bool remove_class_instance(const string& class_name,
00157                    const string& instance);
00158 
00159     bool class_default_instance(const string& class_name,
00160                 string&       instance) const;
00161 
00162     bool class_exists(const string& class_name) const;
00163 
00164     EventLoop& eventloop() const { return _e; }
00165 
00166 protected:
00167     EventLoop&       _e;
00168     XrlCmdMap        _cmds;
00169     FinderMessengerBase* _active_messenger; // Currently active endpoint
00170     FinderMessengerList  _messengers;       // List of Finder
00171                             // communication endpoints
00172     TargetTable      _targets;      // Table of target instances
00173     ClassTable       _classes;      // Table of known classes
00174     OutQueueTable    _out_queues;       // Outbound message queues
00175     EventQueue       _event_queue;      // Queue for externally
00176                             // advertised events
00177     XorpTimer        _hello;        // Timer used to send
00178                             // keepalive messages to
00179                             // FinderMessenger instances
00180 };
00181 
00182 #endif // __LIBXIPC_FINDER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations