GNU Radio 3.7.0 C++ API
rpcserver_aggregator.h
Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /* 
00003  * Copyright 2012 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  * 
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef RPCSERVER_AGGREGATOR_H
00024 #define RPCSERVER_AGGREGATOR_H
00025 
00026 #include <vector>
00027 #include <string>
00028 #include <gnuradio/rpcserver_base.h>
00029 #include <gnuradio/rpcmanager_base.h>
00030 
00031 class rpcserver_aggregator : public virtual rpcserver_base
00032 {
00033 public:
00034   rpcserver_aggregator();
00035   virtual ~rpcserver_aggregator();
00036 
00037   void registerConfigureCallback(const std::string &id, const configureCallback_t callback);
00038   void unregisterConfigureCallback(const std::string &id);
00039 
00040   void registerQueryCallback(const std::string &id, const queryCallback_t callback);
00041   void unregisterQueryCallback(const std::string &id);
00042 
00043   void registerServer(rpcmanager_base::rpcserver_booter_base_sptr server);
00044 
00045   const std::string& type();
00046 
00047   const std::vector<std::string>& registeredServers();
00048 
00049 private:
00050   template<class T, typename Tcallback>
00051   struct registerConfigureCallback_f: public std::unary_function<T,void>
00052   {
00053     registerConfigureCallback_f(const std::string &_id,  const Tcallback _callback)
00054       : id(_id), callback(_callback)
00055     {;}
00056 
00057     void operator()(T& x) { x->i()->registerConfigureCallback(id, callback); }
00058     const std::string& id;  const Tcallback& callback;
00059   };
00060 
00061   template<class T, typename Tcallback>
00062   struct unregisterConfigureCallback_f: public std::unary_function<T,void>
00063   {
00064     unregisterConfigureCallback_f(const std::string &_id)
00065       : id(_id)
00066     {;}
00067 
00068     void operator()(T& x) { x->i()->unregisterConfigureCallback(id); }
00069     const std::string&  id;
00070    };
00071 
00072   template<class T, typename Tcallback>
00073   struct registerQueryCallback_f: public std::unary_function<T,void>
00074   {
00075     registerQueryCallback_f(const std::string &_id,  const Tcallback _callback)
00076       : id(_id), callback(_callback)
00077     {;}
00078 
00079     void operator()(T& x) { x->i()->registerQueryCallback(id, callback); }
00080     const std::string& id;  const Tcallback& callback;
00081   };
00082 
00083   template<class T, typename Tcallback>
00084   struct unregisterQueryCallback_f: public std::unary_function<T,void>
00085   {
00086     unregisterQueryCallback_f(const std::string &_id)
00087       : id(_id)
00088     {;}
00089 
00090     void operator()(T& x) { x->i()->unregisterQueryCallback(id); }
00091     const std::string& id;
00092   };
00093 
00094   const std::string d_type;
00095   typedef std::vector<rpcmanager_base::rpcserver_booter_base_sptr> rpcServerMap_t;
00096   std::vector<std::string> d_registeredServers;
00097   rpcServerMap_t d_serverlist;
00098 };
00099 
00100 #endif /* RPCSERVER_AGGREGATOR_H */