metaproxy  1.21.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

◆ CreateFilterCallback

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

Definition at line 35 of file factory_filter.hpp.

Constructor & Destructor Documentation

◆ FactoryFilter()

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

◆ ~FactoryFilter()

metaproxy_1::FactoryFilter::~FactoryFilter ( )

Definition at line 64 of file factory_filter.cpp.

65 {
66 
67 }

Member Function Documentation

◆ add_creator()

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

Definition at line 69 of file factory_filter.cpp.

71 {
72  return m_p->m_fcm.insert(Rep::CallbackMap::value_type(fi, cfc)).second;
73 }

Referenced by metaproxy_1::FactoryStatic::FactoryStatic().

◆ add_creator_dl()

bool metaproxy_1::FactoryFilter::add_creator_dl ( const std::string &  fi,
const std::string &  path 
)

Definition at line 104 of file factory_filter.cpp.

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 }
bool add_creator(const std::string &fi, CreateFilterCallback cfc)

◆ create()

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

Definition at line 92 of file factory_filter.cpp.

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 }

◆ drop_creator()

bool metaproxy_1::FactoryFilter::drop_creator ( std::string  fi)

Definition at line 76 of file factory_filter.cpp.

77 {
78  return m_p->m_fcm.erase(fi) == 1;
79 }

◆ exist()

bool metaproxy_1::FactoryFilter::exist ( std::string  fi)

Definition at line 81 of file factory_filter.cpp.

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 }

Member Data Documentation

◆ m_p

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

Definition at line 58 of file factory_filter.hpp.


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