metaproxy  1.13.0
Classes | Public Member Functions | Private Types | Private Attributes | List of all members
metaproxy_1::FactoryFilter Class Reference

#include <factory_filter.hpp>

Inheritance diagram for metaproxy_1::FactoryFilter:
Inheritance graph
Collaboration diagram for metaproxy_1::FactoryFilter:
Collaboration graph

Classes

class  NotFound
 
class  Rep
 

Public Member Functions

 FactoryFilter ()
 true if registration ok More...
 
 ~FactoryFilter ()
 
bool add_creator (const std::string &fi, CreateFilterCallback cfc)
 
bool drop_creator (std::string fi)
 
metaproxy_1::filter::Base * create (std::string fi)
 
bool exist (std::string fi)
 
bool add_creator_dl (const std::string &fi, const std::string &path)
 

Private Types

typedef metaproxy_1::filter::Base *(* CreateFilterCallback) ()
 

Private Attributes

boost::scoped_ptr< Repm_p
 

Detailed Description

Definition at line 33 of file factory_filter.hpp.

Member Typedef Documentation

typedef metaproxy_1::filter::Base*(* metaproxy_1::FactoryFilter::CreateFilterCallback) ()
private

Definition at line 35 of file factory_filter.hpp.

Constructor & Destructor Documentation

metaproxy_1::FactoryFilter::FactoryFilter ( )

true if registration ok

Definition at line 59 of file factory_filter.cpp.

59  : m_p(new mp::FactoryFilter::Rep)
60 {
61 
62 }
boost::scoped_ptr< Rep > m_p
metaproxy_1::FactoryFilter::~FactoryFilter ( )

Definition at line 64 of file factory_filter.cpp.

65 {
66 
67 }

Member Function Documentation

bool metaproxy_1::FactoryFilter::add_creator ( const std::string &  fi,
CreateFilterCallback  cfc 
)

Definition at line 69 of file factory_filter.cpp.

References m_p.

Referenced by add_creator_dl(), and metaproxy_1::FactoryStatic::FactoryStatic().

71 {
72  return m_p->m_fcm.insert(Rep::CallbackMap::value_type(fi, cfc)).second;
73 }
boost::scoped_ptr< Rep > m_p
bool metaproxy_1::FactoryFilter::add_creator_dl ( const std::string &  fi,
const std::string &  path 
)

Definition at line 104 of file factory_filter.cpp.

References add_creator(), and m_p.

106 {
107 #if HAVE_DLFCN_H
108  if (m_p->m_fcm.find(fi) != m_p->m_fcm.end())
109  {
110  return true;
111  }
112  std::string full_name = "metaproxy_1_filter_" + fi;
113 
114  void *dl_handle = dlopen(0, RTLD_GLOBAL|RTLD_NOW);
115  void *dlsym_ptr = dlsym(dl_handle, full_name.c_str());
116 
117  if (!dlsym_ptr)
118  {
119  std::string full_path = path + "/metaproxy_filter_" + fi + ".so";
120  dl_handle = dlopen(full_path.c_str(), RTLD_GLOBAL|RTLD_NOW);
121  if (!dl_handle)
122  {
123  const char *dl = dlerror();
124  std::cout << "dlopen " << full_path << " failed. dlerror=" << dl <<
125  std::endl;
126  return false;
127  }
128  dlsym_ptr = dlsym(dl_handle, full_name.c_str());
129  }
130  if (!dlsym_ptr)
131  {
132  std::cout << "dlsym " << full_name << " failed\n";
133  return false;
134  }
135  struct metaproxy_1_filter_struct *s = (struct metaproxy_1_filter_struct *) dlsym_ptr;
136  return add_creator(fi, s->creator);
137 #else
138  return false;
139 #endif
140 }
boost::scoped_ptr< Rep > m_p
bool add_creator(const std::string &fi, CreateFilterCallback cfc)

Here is the call graph for this function:

mp::filter::Base * metaproxy_1::FactoryFilter::create ( std::string  fi)

Definition at line 92 of file factory_filter.cpp.

References m_p.

93 {
94  Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi);
95 
96  if (it == m_p->m_fcm.end()){
97  std::string msg = "filter type '" + fi + "' not found";
98  throw NotFound(msg);
99  }
100  // call create function
101  return (it->second());
102 }
boost::scoped_ptr< Rep > m_p
bool metaproxy_1::FactoryFilter::drop_creator ( std::string  fi)

Definition at line 76 of file factory_filter.cpp.

References m_p.

77 {
78  return m_p->m_fcm.erase(fi) == 1;
79 }
boost::scoped_ptr< Rep > m_p
bool metaproxy_1::FactoryFilter::exist ( std::string  fi)

Definition at line 81 of file factory_filter.cpp.

References m_p.

82 {
83  Rep::CallbackMap::const_iterator it = m_p->m_fcm.find(fi);
84 
85  if (it == m_p->m_fcm.end())
86  {
87  return false;
88  }
89  return true;
90 }
boost::scoped_ptr< Rep > m_p

Member Data Documentation

boost::scoped_ptr<Rep> metaproxy_1::FactoryFilter::m_p
private

Definition at line 58 of file factory_filter.hpp.

Referenced by add_creator(), add_creator_dl(), create(), drop_creator(), and exist().


The documentation for this class was generated from the following files: