<commit_before>/*-------------------------------------------------------------------------
 *
 *   FILE
 *	pqxx/notification.hxx
 *
 *   DESCRIPTION
 *      definition of the pqxx::notification_receiver functor interface.
 *   pqxx::notification_receiver handles incoming notifications.
 *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/notification instead.
 *
 * Copyright (c) 2011, <NAME> <<EMAIL>>
 *
 * See COPYING for copyright license.  If you did not receive a file called
 * COPYING with this source code, please notify the distributor of this mistake,
 * or contact the author.
 *
 *-------------------------------------------------------------------------
 */
#ifndef PQXX_H_NOTIFICATION
#define PQXX_H_NOTIFICATION

#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"

namespace pqxx
{
class connection_base;


/// "Observer" base class for notifications.
/** @addtogroup notification Notifications and Receivers
 *
 * To listen on a notification issued using the NOTIFY command, derive your own
 * class from notification_receiver and define its function-call operator to
 * perform whatever action you wish to take when the given notification arrives.
 * Then create an object of that class and pass it to your connection.  DO NOT
 * use raw SQL to listen for notifications, or your attempts to listen won't be
 * resumed when a connection fails--and you'll have no way to notice.
 *
 * Notifications never arrive inside a transaction, not even in a
 * nontransaction.  Therefore, you are free to open a transaction of your own
 * inside your receiver's function invocation operator.
 *
 * Notifications you are listening for may arrive anywhere within libpqxx code,
 * but be aware that @b PostgreSQL @b defers @b notifications @b occurring
 * @b inside @b transactions.  (This was done for excellent reasons; just think
 * about what happens if the transaction where you happen to handle an incoming
 * notification is later rolled back for other reasons).  So if you're keeping a
 * transaction open, don't expect any of your receivers on the same connection
 * to be notified.
 *
 * Multiple receivers on the same connection may listen on a notification of the
 * same name.  An incoming notification is processed by invoking all receivers
 * (zero or more) of the same name.
 */
class PQXX_LIBEXPORT PQXX_NOVTABLE notification_receiver :
  public PGSTD::binary_function<const PGSTD::string &, int, void>
{
public:
  /// Register the receiver with a connection.
  /**
   * @param channel Name of the notification to listen for.
   */
  notification_receiver(connection_base &, const PGSTD::string &channel);
  virtual ~notification_receiver();

  /// The channel that this receiver listens on.
  const PGSTD::string &channel() const { return m_channel; }

  /// Overridable: action to invoke when notification arrives.
  /**
   * @param payload On PostgreSQL 9.0 or later, an optional string that may have
   * been passed to the NOTIFY command.
   * @param be_pid Process ID of the database backend process that served our
   * connection when the notification arrived.  The actual process ID behind the
   * connection may have changed by the time this method is called.
   */
  virtual void operator()(const PGSTD::string &payload, int backend_pid) =0;

protected:
  connection_base &conn() const throw () { return m_conn; }

private:
  // Not allowed.
  notification_receiver(const notification_receiver &);
  // Not allowed.
  notification_receiver &operator=(const notification_receiver &);

  connection_base &m_conn;
  PGSTD::string m_channel;
};
}

#include "pqxx/compiler-internal-pre.hxx"
#endif
<commit_msg>Missing include (not usually noticeable).<commit_after>/*-------------------------------------------------------------------------
 *
 *   FILE
 *	pqxx/notification.hxx
 *
 *   DESCRIPTION
 *      definition of the pqxx::notification_receiver functor interface.
 *   pqxx::notification_receiver handles incoming notifications.
 *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/notification instead.
 *
 * Copyright (c) 2011, <NAME> <<EMAIL>>
 *
 * See COPYING for copyright license.  If you did not receive a file called
 * COPYING with this source code, please notify the distributor of this mistake,
 * or contact the author.
 *
 *-------------------------------------------------------------------------
 */
#ifndef PQXX_H_NOTIFICATION
#define PQXX_H_NOTIFICATION

#include "pqxx/compiler-public.hxx"
#include "pqxx/compiler-internal-pre.hxx"

namespace pqxx
{
class connection_base;


/// "Observer" base class for notifications.
/** @addtogroup notification Notifications and Receivers
 *
 * To listen on a notification issued using the NOTIFY command, derive your own
 * class from notification_receiver and define its function-call operator to
 * perform whatever action you wish to take when the given notification arrives.
 * Then create an object of that class and pass it to your connection.  DO NOT
 * use raw SQL to listen for notifications, or your attempts to listen won't be
 * resumed when a connection fails--and you'll have no way to notice.
 *
 * Notifications never arrive inside a transaction, not even in a
 * nontransaction.  Therefore, you are free to open a transaction of your own
 * inside your receiver's function invocation operator.
 *
 * Notifications you are listening for may arrive anywhere within libpqxx code,
 * but be aware that @b PostgreSQL @b defers @b notifications @b occurring
 * @b inside @b transactions.  (This was done for excellent reasons; just think
 * about what happens if the transaction where you happen to handle an incoming
 * notification is later rolled back for other reasons).  So if you're keeping a
 * transaction open, don't expect any of your receivers on the same connection
 * to be notified.
 *
 * Multiple receivers on the same connection may listen on a notification of the
 * same name.  An incoming notification is processed by invoking all receivers
 * (zero or more) of the same name.
 */
class PQXX_LIBEXPORT PQXX_NOVTABLE notification_receiver :
  public PGSTD::binary_function<const PGSTD::string &, int, void>
{
public:
  /// Register the receiver with a connection.
  /**
   * @param channel Name of the notification to listen for.
   */
  notification_receiver(connection_base &, const PGSTD::string &channel);
  virtual ~notification_receiver();

  /// The channel that this receiver listens on.
  const PGSTD::string &channel() const { return m_channel; }

  /// Overridable: action to invoke when notification arrives.
  /**
   * @param payload On PostgreSQL 9.0 or later, an optional string that may have
   * been passed to the NOTIFY command.
   * @param be_pid Process ID of the database backend process that served our
   * connection when the notification arrived.  The actual process ID behind the
   * connection may have changed by the time this method is called.
   */
  virtual void operator()(const PGSTD::string &payload, int backend_pid) =0;

protected:
  connection_base &conn() const throw () { return m_conn; }

private:
  // Not allowed.
  notification_receiver(const notification_receiver &);
  // Not allowed.
  notification_receiver &operator=(const notification_receiver &);

  connection_base &m_conn;
  PGSTD::string m_channel;
};
}

#include "pqxx/compiler-internal-pre.hxx"
#include "pqxx/compiler-internal-post.hxx"
#endif

{'fraction_non_alphanumeric': 0.1099554234769688, 'fraction_numerical': 0.0018911252195056058, 'mean_word_length': 3.3862559241706163, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4095826', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1880, 'n_words': 854}