GNU Radio 3.7.1 C++ API
ice_server_template.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 ICE_SERVER_TEMPLATE_H
00024 #define ICE_SERVER_TEMPLATE_H
00025 
00026 #include <gnuradio/rpcserver_ice.h>
00027 #include <gnuradio/ice_application_base.h>
00028 #include <iostream>
00029 
00030 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
00031 class ice_server_template : public ice_application_base<TserverBase, TImplClass>
00032 {
00033 public:
00034   ice_server_template(TImplClass* _this,
00035                       const std::string& contolPortName,
00036                       const std::string& endpointName);
00037   ~ice_server_template();
00038     
00039 protected:
00040   //virtual bool application_started();
00041   TserverBase* i_impl();
00042   friend class ice_application_base<TserverBase, TImplClass>;
00043 
00044 private:
00045   //virtual int run_impl(int, char*[]);
00046   Ice::ObjectAdapterPtr d_adapter;
00047   TserverBase* d_iceserver;
00048   const std::string d_contolPortName, d_endpointName;
00049 };
00050 
00051 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
00052 ice_server_template<TserverBase, TserverClass, TImplClass, TIceClass>::ice_server_template
00053     (TImplClass* _this, const std::string& controlPortName, const std::string& endpointName) 
00054   : ice_application_base<TserverBase, TImplClass>(_this),
00055     d_iceserver(0),
00056     d_contolPortName(controlPortName), 
00057     d_endpointName(endpointName)
00058 {;}
00059 
00060 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
00061 ice_server_template<TserverBase, TserverClass,TImplClass, TIceClass>::~ice_server_template()
00062 {
00063   if(d_adapter) {
00064     d_adapter->deactivate();
00065     delete(d_iceserver);
00066     d_adapter = 0;
00067   }
00068 }
00069 
00070 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
00071 TserverBase* ice_server_template<TserverBase, TserverClass, TImplClass, TIceClass>::i_impl()
00072 { 
00073   if(ice_application_base<TserverBase, TImplClass>::d_this->reacquire_sync()) {
00074     d_adapter = (ice_application_base<TserverBase, TImplClass>::d_this->have_ice_config()) ?
00075       ice_application_base<TserverBase, TImplClass>::d_this->d_this->d_application->communicator()->createObjectAdapter(d_contolPortName) :
00076       ice_application_base<TserverBase, TImplClass>::d_this->d_this->d_application->communicator()->createObjectAdapterWithEndpoints(d_contolPortName,"tcp -h *");
00077 
00078     TserverClass* server_ice(new TserverClass());
00079     TIceClass obj(server_ice);
00080   
00081     Ice::Identity id(ice_application_base<TserverBase, TImplClass>::d_this->d_this->d_application->communicator()->stringToIdentity(d_endpointName));
00082     d_adapter->add(obj, id);
00083     d_adapter->activate();
00084     ice_application_base<TserverBase, TImplClass>::d_this->set_endpoint(ice_application_common::communicator()->proxyToString(d_adapter->createDirectProxy(id)));
00085 
00086     std::cout << std::endl << "Ice Radio Endpoint: "
00087               << ice_server_template<TserverBase, TserverClass, TImplClass, TIceClass>::endpoints()[0]
00088               << std::endl;
00089 
00090     d_iceserver =  (TserverBase*) server_ice;
00091     ice_application_base<TserverBase, TImplClass>::d_this->sync_reacquire();
00092   }
00093 
00094   return d_iceserver;
00095 }
00096 
00097 #endif /* ICE_SERVER_TEMPLATE_H */