SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Static Public Member Functions | Related Functions
RWSockAddrFactory Class Reference

Builds addresses of any registered type. Not intended for explicit use. More...

#include <rw/network/RWSockAddrFactory.h>

Inheritance diagram for RWSockAddrFactory:
RWSockAddrFactoryBase

Public Member Functions

 RWSockAddrFactory ()
 
virtual ~RWSockAddrFactory ()
 
virtual RWSockAddrBaseoperator() (struct sockaddr *addr, RWSockLenType addrLen) const
 
virtual RWSockAddrBaseoperator() (struct sockaddr *addr, RWSockLenType addrLen, int type) const
 
virtual RWSockAddrBaseoperator() (const RWCString &str) const
 
void registerWithFactory (const RWSockType &family, RWSockAddrFactoryBase *maker)
 
void registerWithFactory (int family, RWSockAddrFactoryBase *maker)
 
void registerWithFactory (const RWCString &family, RWSockAddrFactoryBase *maker)
 
void unRegister (const RWSockType &)
 
void unRegister (int family)
 
void unRegister (const RWCString &family)
 
- Public Member Functions inherited from RWSockAddrFactoryBase
virtual ~RWSockAddrFactoryBase ()
 

Static Public Member Functions

static RWSockAddrFactorytheGlobalRWSockAddrFactory ()
 

Related Functions

(Note that these are not member functions.)

#define rwSockAddrFactory
 

Detailed Description

RWSockAddrFactory builds addresses of any registered type. This class is used by the Networking classes implementation and is not normally used explicitly. The global object rwSockAddrFactory is used by functions such as RWSocket::getsockname(), which do not know the type of socket address to build.

Specific address factory objects need to be registered with the factory via the general factory's registerWithFactory() method. Check RWInetAddrFactory for an example of a specific address family factory.

These singleton objects are constructed when used, so they are not dependent on the order of static initialization.

Constructor & Destructor Documentation

RWSockAddrFactory::RWSockAddrFactory ( )

Creates a factory with no create methods attached.

virtual RWSockAddrFactory::~RWSockAddrFactory ( )
virtual

Virtual destructor.

Member Function Documentation

virtual RWSockAddrBase* RWSockAddrFactory::operator() ( struct sockaddr *  addr,
RWSockLenType  addrLen 
) const
virtual

Returns a pointer to an RWSockAddrBase derived object constructed from the provided sockaddr. This function will find the RWSockAddrFactoryBase registered for the socket address family of addr. It will then pass the input parameters addr and addrLen to that factory to get an RWSockAddrBase derived object of the appropriate type. If no factory has been registered for the requested family, an RWNetNoNumberFactoryRegisteredError exception is thrown.

The addr parameter is expected to point to an concrete socket address type such as sockaddr_in, sockaddr_in6 or sockaddr_un cast to a sockaddr.

The addrLen parameter is expected to describe the size, in bytes, of the object pointed to by addr.

The newly created RWSockAddrBase is allocated on the heap. The caller is responsible for deleting it. Often, this is managed by wrapping the object using an RWSockAddr.

Implements RWSockAddrFactoryBase.

virtual RWSockAddrBase* RWSockAddrFactory::operator() ( struct sockaddr *  addr,
RWSockLenType  addrLen,
int  type 
) const
virtual

Returns a pointer to an RWSockAddrBase derived object constructed from the provided sockaddr. This function will find the RWSockAddrFactoryBase registered for the socket address family of addr. It will then pass the input parameters addr, addrLen, and type to that factory to get an RWSockAddrBase derived object of the appropriate type. If no factory has been registered for the requested family, an RWNetNoNumberFactoryRegisteredError exception is thrown.

The addr parameter is expected to point to an concrete socket address type such as sockaddr_in, sockaddr_in6 or sockaddr_un cast to a sockaddr.

The addrLen parameter is expected to describe the size, in bytes, of the object pointed to by addr.

The type parameter is passed to the appropriate RWSockAddrFactoryBase instance when a request is made to create a derived RWSockAddrBase. It describes the type of socket address to be created. This would normally be one of SOCK_STREAM or SOCK_DGRAM.

The newly created RWSockAddrBase is allocated on the heap. The caller is responsible for deleting it. Often, this is managed by wrapping the object using an RWSockAddr.

Implements RWSockAddrFactoryBase.

virtual RWSockAddrBase* RWSockAddrFactory::operator() ( const RWCString str) const
virtual

Returns a pointer to an RWSockAddrBase derived object constructed from from the provided RWCString. This function will find the RWSockAddrFactoryBase registered for the socket address family described in str. It will then pass a string derived from str to that factory to get an RWSockAddrBase derived object of the appropriate type. If no factory has been registered for the requested family, an RWNetNoNameFactoryRegisteredError exception is thrown.

The newly created RWSockAddrBase is allocated on the heap. The caller is responsible for deleting it. Often, this is managed by wrapping the object using an RWSockAddr.

Implements RWSockAddrFactoryBase.

void RWSockAddrFactory::registerWithFactory ( const RWSockType family,
RWSockAddrFactoryBase maker 
)

Registers maker objects. Duplicate registration is a no-op. If you attempt to register two different factories with the same family, an exception is thrown. The variant that takes a socket type argument registers both the standard family name for that socket type and the family number. The pointer to the factory must remain valid as long as self is used to build addresses. The RWCString should contain 7-bit US-ASCII data.

void RWSockAddrFactory::registerWithFactory ( int  family,
RWSockAddrFactoryBase maker 
)

Registers maker objects. Duplicate registration is a no-op. If you attempt to register two different factories with the same family, an exception is thrown. The variant that takes a socket type argument registers both the standard family name for that socket type and the family number. The pointer to the factory must remain valid as long as self is used to build addresses. The RWCString should contain 7-bit US-ASCII data.

void RWSockAddrFactory::registerWithFactory ( const RWCString family,
RWSockAddrFactoryBase maker 
)

Registers maker objects. Duplicate registration is a no-op. If you attempt to register two different factories with the same family, an exception is thrown. The variant that takes a socket type argument registers both the standard family name for that socket type and the family number. The pointer to the factory must remain valid as long as self is used to build addresses. The RWCString should contain 7-bit US-ASCII data.

RWSockAddrFactory & RWSockAddrFactory::theGlobalRWSockAddrFactory ( )
inlinestatic
Deprecated:
As of SourcePro 4, use rwSockAddrFactory() instead.

Returns the global factory that is used by the Networking classes. This is more conveniently accessed via the rwSockAddrFactory macro. If the factory has not yet been constructed, it is constructed and the well-known families are registered.

void RWSockAddrFactory::unRegister ( const RWSockType )

Removes all knowledge from the factory of how to build addresses of the indicated family. This is useful if you want to explicitly replace one factory with another for the same family. Unless you first unRegister(), an RWNetAlreadyRegisteredError exception is thrown. It is not an error to unregister a type that has never been registered. The RWCString should contain 7-bit US-ASCII data.

void RWSockAddrFactory::unRegister ( int  family)

Removes all knowledge from the factory of how to build addresses of the indicated family. This is useful if you want to explicitly replace one factory with another for the same family. Unless you first unRegister(), an RWNetAlreadyRegisteredError exception is thrown. It is not an error to unregister a type that has never been registered. The RWCString should contain 7-bit US-ASCII data.

void RWSockAddrFactory::unRegister ( const RWCString family)

Removes all knowledge from the factory of how to build addresses of the indicated family. This is useful if you want to explicitly replace one factory with another for the same family. Unless you first unRegister(), an RWNetAlreadyRegisteredError exception is thrown. It is not an error to unregister a type that has never been registered. The RWCString should contain 7-bit US-ASCII data.

Friends And Related Function Documentation

#define rwSockAddrFactory
related

Defined internally as a macro to obtain a reference to the factory object.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.