metaproxy  1.21.0
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
metaproxy_1::filter::Sort::Impl Class Reference
Collaboration diagram for metaproxy_1::filter::Sort::Impl:
Collaboration graph

Public Member Functions

 Impl ()
 
 ~Impl ()
 
void process (metaproxy_1::Package &package)
 
void configure (const xmlNode *ptr, bool test_only, const char *path)
 

Private Member Functions

FrontendPtr get_frontend (mp::Package &package)
 
void release_frontend (mp::Package &package)
 

Private Attributes

int m_prefetch
 
std::string m_xpath_expr
 
std::string m_namespaces
 
bool m_ascending
 
bool m_debug
 
boost::mutex m_mutex
 
boost::condition m_cond_session_ready
 
std::map< mp::Session, FrontendPtrm_clients
 

Friends

class Frontend
 

Detailed Description

Definition at line 41 of file filter_sort.cpp.

Constructor & Destructor Documentation

◆ Impl()

mp::filter::Sort::Impl::Impl ( )

Definition at line 385 of file filter_sort.cpp.

◆ ~Impl()

mp::filter::Sort::Impl::~Impl ( )

Definition at line 389 of file filter_sort.cpp.

390 {
391 }

Member Function Documentation

◆ configure()

void mp::filter::Sort::Impl::configure ( const xmlNode *  ptr,
bool  test_only,
const char *  path 
)

Definition at line 438 of file filter_sort.cpp.

440 {
441  for (ptr = ptr->children; ptr; ptr = ptr->next)
442  {
443  if (ptr->type != XML_ELEMENT_NODE)
444  continue;
445  if (!strcmp((const char *) ptr->name, "sort"))
446  {
447  const struct _xmlAttr *attr;
448  for (attr = ptr->properties; attr; attr = attr->next)
449  {
450  if (!strcmp((const char *) attr->name, "prefetch"))
451  {
452  m_prefetch = mp::xml::get_int(attr->children, -1);
453  if (m_prefetch < 0)
454  {
455  throw mp::filter::FilterException(
456  "Bad or missing value for attribute " +
457  std::string((const char *) attr->name));
458  }
459  }
460  else if (!strcmp((const char *) attr->name, "xpath"))
461  {
462  m_xpath_expr = mp::xml::get_text(attr->children);
463  }
464  else if (!strcmp((const char *) attr->name, "namespaces"))
465  {
466  m_namespaces = mp::xml::get_text(attr->children);
467  }
468  else if (!strcmp((const char *) attr->name, "ascending"))
469  {
470  m_ascending = mp::xml::get_bool(attr->children, true);
471  }
472  else if (!strcmp((const char *) attr->name, "debug"))
473  {
474  m_debug = mp::xml::get_bool(attr->children, false);
475  }
476  else
477  throw mp::filter::FilterException(
478  "Bad attribute " +
479  std::string((const char *) attr->name));
480  }
481  }
482  else
483  {
484  throw mp::filter::FilterException
485  ("Bad element "
486  + std::string((const char *) ptr->name)
487  + " in sort filter");
488  }
489  }
490  if (m_xpath_expr.length() == 0)
491  {
492  throw mp::filter::FilterException
493  ("Missing xpath attribute for config element in sort filter");
494  }
495 
496 }

◆ get_frontend()

yf::Sort::FrontendPtr mp::filter::Sort::Impl::get_frontend ( mp::Package &  package)
private

Definition at line 393 of file filter_sort.cpp.

394 {
395  boost::mutex::scoped_lock lock(m_mutex);
396 
397  std::map<mp::Session,yf::Sort::FrontendPtr>::iterator it;
398 
399  while(true)
400  {
401  it = m_clients.find(package.session());
402  if (it == m_clients.end())
403  break;
404 
405  if (!it->second->m_in_use)
406  {
407  it->second->m_in_use = true;
408  return it->second;
409  }
410  m_cond_session_ready.wait(lock);
411  }
412  FrontendPtr f(new Frontend(this));
413  m_clients[package.session()] = f;
414  f->m_in_use = true;
415  return f;
416 }
std::map< mp::Session, FrontendPtr > m_clients
Definition: filter_sort.cpp:57
boost::condition m_cond_session_ready
Definition: filter_sort.cpp:56
boost::shared_ptr< Frontend > FrontendPtr
Definition: filter_sort.hpp:34

◆ process()

void mp::filter::Sort::Impl::process ( metaproxy_1::Package &  package)

Definition at line 725 of file filter_sort.cpp.

726 {
727  FrontendPtr f = get_frontend(package);
728  Z_GDU *gdu = package.request().get();
729 
730  if (f->m_is_virtual)
731  {
732  f->handle_package(package);
733  }
734  else if (gdu && gdu->which == Z_GDU_Z3950 && gdu->u.z3950->which ==
735  Z_APDU_initRequest)
736  {
737  package.move();
738  f->m_is_virtual = true;
739  }
740  else
741  package.move();
742 
743  release_frontend(package);
744 }
void release_frontend(mp::Package &package)
FrontendPtr get_frontend(mp::Package &package)

◆ release_frontend()

void mp::filter::Sort::Impl::release_frontend ( mp::Package &  package)
private

Definition at line 418 of file filter_sort.cpp.

419 {
420  boost::mutex::scoped_lock lock(m_mutex);
421  std::map<mp::Session,yf::Sort::FrontendPtr>::iterator it;
422 
423  it = m_clients.find(package.session());
424  if (it != m_clients.end())
425  {
426  if (package.session().is_closed())
427  {
428  m_clients.erase(it);
429  }
430  else
431  {
432  it->second->m_in_use = false;
433  }
434  m_cond_session_ready.notify_all();
435  }
436 }

Friends And Related Function Documentation

◆ Frontend

friend class Frontend
friend

Definition at line 42 of file filter_sort.cpp.

Member Data Documentation

◆ m_ascending

bool metaproxy_1::filter::Sort::Impl::m_ascending
private

Definition at line 53 of file filter_sort.cpp.

◆ m_clients

std::map<mp::Session, FrontendPtr> metaproxy_1::filter::Sort::Impl::m_clients
private

Definition at line 57 of file filter_sort.cpp.

◆ m_cond_session_ready

boost::condition metaproxy_1::filter::Sort::Impl::m_cond_session_ready
private

Definition at line 56 of file filter_sort.cpp.

◆ m_debug

bool metaproxy_1::filter::Sort::Impl::m_debug
private

Definition at line 54 of file filter_sort.cpp.

◆ m_mutex

boost::mutex metaproxy_1::filter::Sort::Impl::m_mutex
private

Definition at line 55 of file filter_sort.cpp.

◆ m_namespaces

std::string metaproxy_1::filter::Sort::Impl::m_namespaces
private

Definition at line 52 of file filter_sort.cpp.

◆ m_prefetch

int metaproxy_1::filter::Sort::Impl::m_prefetch
private

Definition at line 50 of file filter_sort.cpp.

◆ m_xpath_expr

std::string metaproxy_1::filter::Sort::Impl::m_xpath_expr
private

Definition at line 51 of file filter_sort.cpp.


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