GNU Radio Manual and C++ API Reference  3.7.4
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ice_server_template.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef ICE_SERVER_TEMPLATE_H
24 #define ICE_SERVER_TEMPLATE_H
25 
26 #include <gnuradio/rpcserver_ice.h>
28 #include <iostream>
29 
30 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
31 class ice_server_template : public ice_application_base<TserverBase, TImplClass>
32 {
33 public:
34  ice_server_template(TImplClass* _this,
35  const std::string& contolPortName,
36  const std::string& endpointName);
38 
39 protected:
40  //virtual bool application_started();
41  TserverBase* i_impl();
42  friend class ice_application_base<TserverBase, TImplClass>;
43 
44 private:
45  //virtual int run_impl(int, char*[]);
46  Ice::ObjectAdapterPtr d_adapter;
47  TserverBase* d_iceserver;
48  const std::string d_contolPortName, d_endpointName;
49 };
50 
51 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
53  (TImplClass* _this, const std::string& controlPortName, const std::string& endpointName)
55  d_iceserver(0),
56  d_contolPortName(controlPortName),
57  d_endpointName(endpointName)
58 {;}
59 
60 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
62 {
63  if(d_adapter) {
64  d_adapter->deactivate();
65  delete(d_iceserver);
66  d_adapter = 0;
67  }
68 }
69 
70 template<typename TserverBase, typename TserverClass, typename TImplClass, typename TIceClass>
72 {
75  ice_application_base<TserverBase, TImplClass>::d_this->d_this->d_application->communicator()->createObjectAdapter(d_contolPortName) :
76  ice_application_base<TserverBase, TImplClass>::d_this->d_this->d_application->communicator()->createObjectAdapterWithEndpoints(d_contolPortName,"tcp -h *");
77 
78  TserverClass* server_ice(new TserverClass());
79  TIceClass obj(server_ice);
80 
81  Ice::Identity id(ice_application_base<TserverBase, TImplClass>::d_this->d_this->d_application->communicator()->stringToIdentity(d_endpointName));
82  d_adapter->add(obj, id);
83  d_adapter->activate();
84  ice_application_base<TserverBase, TImplClass>::d_this->set_endpoint(ice_application_common::communicator()->proxyToString(d_adapter->createDirectProxy(id)));
85 
86  std::cout << std::endl << "Ice Radio Endpoint: "
88  << std::endl;
89 
90  d_iceserver = (TserverBase*) server_ice;
92  }
93 
94  return d_iceserver;
95 }
96 
97 #endif /* ICE_SERVER_TEMPLATE_H */
Definition: ice_application_base.h:64
Definition: ice_server_template.h:31
static TserverClass * d_this
Definition: ice_application_base.h:86
TserverBase * i_impl()
Definition: ice_server_template.h:71
~ice_server_template()
Definition: ice_server_template.h:61
virtual void sync_reacquire()
Definition: ice_application_base.h:182
ice_server_template(TImplClass *_this, const std::string &contolPortName, const std::string &endpointName)
Definition: ice_server_template.h:53
void set_endpoint(const std::string &endpoint)
Definition: ice_application_base.h:76
bool have_ice_config()
Definition: ice_application_base.h:75
virtual bool reacquire_sync()
Definition: ice_application_base.h:176
static const std::vector< std::string > endpoints()