InfXmppManager

InfXmppManager — Reuse existing connections

Stability Level

Unstable, unless otherwise indicated

Synopsis

#include <libinfinity/common/inf-xmpp-manager.h>

                    InfXmppManager;
struct              InfXmppManagerClass;
InfXmppManager *    inf_xmpp_manager_new                (void);
InfXmppConnection * inf_xmpp_manager_lookup_connection_by_address
                                                        (InfXmppManager *manager,
                                                         const InfIpAddress *address,
                                                         guint port);
InfXmppConnection * inf_xmpp_manager_lookup_connection_by_hostname
                                                        (InfXmppManager *manager,
                                                         const gchar *hostname,
                                                         const gchar *service,
                                                         const gchar *srv);
gboolean            inf_xmpp_manager_contains_connection
                                                        (InfXmppManager *manager,
                                                         InfXmppConnection *connection);
void                inf_xmpp_manager_add_connection     (InfXmppManager *manager,
                                                         InfXmppConnection *connection);
void                inf_xmpp_manager_remove_connection  (InfXmppManager *manager,
                                                         InfXmppConnection *connection);

Object Hierarchy

  GObject
   +----InfXmppManager

Signals

  "connection-added"                               : Run Last
  "connection-removed"                             : Run Last

Description

InfXmppManager stores InfXmppConnection objects and allows to look them up by the IP address and port number of their underlaying InfTcpConnections. This can be used to reuse existing network connections instead of creating new ones.

Each object which needs to make connections should be passed a InfXmppManager. Then, when making a connection to a certain address/port pair, it should first look in the XMPP manager whether there is already an existing connection to the destination host, via inf_xmpp_manager_lookup_connection_by_address(). If there is, it should use it (maybe reopen it if it is closed). Otherwise, it should create a new connection and add it to the XMPP manager via inf_xmpp_manager_add_connection() for others to use.

The XMPP manager can also handle connections whose address is still to be looked up. Such connections are looked up by the hostname given to the name resolver. Once the hostname has been looked up, and if another connection with the same addressand port number exists already, the new connection is removed in favor of the already existing one.

Details

InfXmppManager

typedef struct _InfXmppManager InfXmppManager;

InfXmppManager is an opaque data type. You should only access it via the public API functions.


struct InfXmppManagerClass

struct InfXmppManagerClass {
  void(*connection_added)(InfXmppManager* manager,
                          InfXmppConnection* connection);
  void(*connection_removed)(InfXmppManager* manager,
                            InfXmppConnection* connection,
                            InfXmppConnection* replaced_by);
};

This structure contains the default signal handlers for InfXmppManager.

connection_added ()

Default signal handler for the "connection-added" signal.

connection_removed ()

Default signal handler for the "connection-removed" signal.

inf_xmpp_manager_new ()

InfXmppManager *    inf_xmpp_manager_new                (void);

Creates a new xmpp manager.

Returns :

A new InfXmppManager.

inf_xmpp_manager_lookup_connection_by_address ()

InfXmppConnection * inf_xmpp_manager_lookup_connection_by_address
                                                        (InfXmppManager *manager,
                                                         const InfIpAddress *address,
                                                         guint port);

Looks for a InfXmppConnection contained in manager whose underlaying InfTcpConnection has the given address and port set. Returns NULL if there is no such connection.

This function may also return a closed connection. You can then attempt to reopen it, or remove it from the manager using inf_xmpp_manager_remove_connection() when that fails.

manager :

A InfXmppManager.

address :

The remote InfIpAddress of the connection to look for.

port :

The remote port number of the connection to look for.

Returns :

A InfXmppConnection with the given address and port, or NULL on error.

inf_xmpp_manager_lookup_connection_by_hostname ()

InfXmppConnection * inf_xmpp_manager_lookup_connection_by_hostname
                                                        (InfXmppManager *manager,
                                                         const gchar *hostname,
                                                         const gchar *service,
                                                         const gchar *srv);

Looks for a InfXmppConnection contained in manager whose underlaying InfTcpConnection has a InfNameResolver with the given properties.

This function may also return a closed connection. You can then attempt to reopen it, or remove it from the manager using inf_xmpp_manager_remove_connection() when that fails.

manager :

A InfXmppManager.

hostname :

The remote hostname to look for.

service :

The service string of the connection to look for.

srv :

The SRV record corresponding to the connection.

Returns :

A InfXmppConnection with the given hostname, service and srv, or NULL on error.

inf_xmpp_manager_contains_connection ()

gboolean            inf_xmpp_manager_contains_connection
                                                        (InfXmppManager *manager,
                                                         InfXmppConnection *connection);

Returns whether connection is contained in manager.

manager :

A InfXmppManager.

connection :

A InfXmppConnection.

Returns :

TRUE if connection is contained in manager, FALSE otherwise.

inf_xmpp_manager_add_connection ()

void                inf_xmpp_manager_add_connection     (InfXmppManager *manager,
                                                         InfXmppConnection *connection);

Adds the given connection to manager so that it is found by inf_xmpp_manager_lookup_connection_by_address(), inf_xmpp_manager_lookup_connection_by_hostname() and inf_xmpp_manager_contains_connection().

manager :

A InfXmppManager.

connection :

A InfXmppConnection not yet contained in manager.

inf_xmpp_manager_remove_connection ()

void                inf_xmpp_manager_remove_connection  (InfXmppManager *manager,
                                                         InfXmppConnection *connection);

Removes the given connection from manager.

manager :

A InfXmppManager.

connection :

A InfXmppConnection contained in manager.

Signal Details

The "connection-added" signal

void                user_function                      (InfXmppManager    *xmpp_manager,
                                                        InfXmppConnection *connection,
                                                        gpointer           user_data)         : Run Last

This signal is emitted whenever a new connection has been added to the InfXmppManager, via inf_xmpp_manager_add_connection().

xmpp_manager :

The InfXmppManager emitting the signal.

connection :

The InfXmppConnection that was added to xmpp_manager.

user_data :

user data set when the signal handler was connected.

The "connection-removed" signal

void                user_function                      (InfXmppManager    *infxmppmanager,
                                                        InfXmppConnection *arg1,
                                                        InfXmppConnection *arg2,
                                                        gpointer           user_data)           : Run Last

infxmppmanager :

the object which received the signal.

user_data :

user data set when the signal handler was connected.