hwsd  1.4.0
Local and remote ZeroConf service discovery for hardware resources
module.ipp
1 
2 /* Copyright (c) 2012, Daniel Nachbaur <danielnachbaur@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Lesser General Public License version 2.1 as published
6  * by the Free Software Foundation.
7  *
8  * This library is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11  * details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this library; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16  */
17 
18 #include <iostream>
19 
20 namespace hwsd
21 {
22 
23 template< typename T > Module< T >::Module()
24  : next_( 0 )
25 {
26  if( !stack_ )
27  {
28  stack_ = this;
29  return;
30  }
31 
32  for( Module* module = stack_; module; module = module->next_ )
33  {
34  if( !module->next_ )
35  {
36  module->next_ = this;
37  return;
38  }
39  }
40 }
41 
42 template< typename T > Module< T >::~Module()
43 {
44  Module* previous = 0;
45  for( Module* module = stack_; module; module = module->next_ )
46  {
47  if( module == this )
48  {
49  if( previous )
50  previous->next_ = next_;
51  else
52  stack_ = next_;
53  break;
54  }
55  previous = module;
56  }
57 }
58 
59 template< typename T >
60 bool Module< T >::announce( const std::string& session ) const
61 {
62  const T& resources = discover();
63  for( typename T::const_iterator i = resources.begin();
64  i != resources.end(); ++i )
65  {
66  typename T::value_type info = *i;
67  info.session = session;
68  std::cout << info << std::endl;
69  }
70  return true;
71 }
72 
73 }
Module()
Register and construct a new module.
Definition: module.ipp:23
virtual ~Module()
Destruct this module.
Definition: module.ipp:42
virtual bool announce(const std::string &session) const
Announce the information about all found resources.
Definition: module.ipp:60
Definition: filter.h:27
Base class for runtime-attached DSOs of a query implementation.
Definition: module.h:32