AGENT++  4.0.3
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
RequestList Class Reference

The RequestList represents a non ordered queue of Requests. More...

#include <request.h>

Inheritance diagram for RequestList:
ThreadManager Synchronized

Public Member Functions

 RequestList ()
 Default constructor.
 
virtual ~RequestList ()
 Destructor (SYNCHRONIZED)
 
virtual void set_address_validation (bool)
 Activate or deactivate source address validation for SNMP v1/v2c requests (SNMP-COMMUNITY-MIB).
 
bool get_address_validation ()
 Gets the current state of the source address validation for community base SNMP versions.
 
virtual void set_snmp (Snmpx *session)
 Set the Snmpx session to be used for incoming requests.
 
Snmpxget_snmp ()
 Get the Snmpx session used by this RequestList.
 
void set_read_community (const NS_SNMP OctetStr &)
 Set READ community.
 
void set_write_community (const NS_SNMP OctetStr &)
 Set WRITE community.
 
virtual Requestreceive (int)
 Wait a given time for an incoming request.
 
virtual unsigned long get_request_id (const Vbx &)
 Return the corresponding request id of a request in the receiver RequestList that contains the specified variable binding.
 
virtual bool done (unsigned long, int, const Vbx &)
 Mark a sub-request as done and put the result of the sub-request into the response PDU.
 
virtual void error (unsigned long, int, int)
 Mark a sub-request as done with an error and put the corresponding SNMP error code for the sub-request into the response PDU.
 
virtual Requestget_request (unsigned long)
 Return a pointer to the request identified by a given transaction id.
 
virtual Requestfind_request_on_id (unsigned long)
 Return a pointer to the request identified by a given request id.
 
virtual void answer (Request *)
 Answer a Request by sending the corresponding response PDU.
 
unsigned long create_transaction_id ()
 Get next transaction id.
 
bool is_empty ()
 Check whether the request list (queue) is empty or not.
 
unsigned long size ()
 Get the actual size of the request list.
 
virtual void remove_request (Request *req)
 Remove a request that should not be processed.
 
- Public Member Functions inherited from ThreadManager
 ThreadManager ()
 Default constructor.
 
virtual ~ThreadManager ()
 Destructor.
 
void start_synch ()
 Start synchronized execution.
 
void end_synch ()
 End synchronized execution.
 
- Public Member Functions inherited from Synchronized
 Synchronized ()
 
 ~Synchronized ()
 
void wait ()
 Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object.
 
bool wait (unsigned long timeout)
 Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed.
 
void notify ()
 Wakes up a single thread that is waiting on this object's monitor.
 
void notify_all ()
 Wakes up all threads that are waiting on this object's monitor.
 
bool lock ()
 Enter a critical section.
 
TryLockResult trylock ()
 Try to enter a critical section.
 
bool unlock ()
 Leave a critical section.
 

Protected Member Functions

virtual Requestadd_request (Request *)
 Add a Request to the RequestList.
 
virtual bool community_ok (int, const NS_SNMP OctetStr &)
 Check whether a given community is acceptable for the specified PDU type.
 
virtual void authenticationFailure (const NS_SNMP OctetStr &context, const NS_SNMP GenAddress &sourceAddress, int status)
 Sends an authenticationFailure notification if the corresponding MIB object is enabled.
 

Static Protected Member Functions

static void null_vbs (Request *req)
 Set all variable bindings (for response) to null values.
 

Protected Attributes

List< Request > * requests
 
Snmpxsnmp
 
NS_SNMP OctetStr * write_community
 
NS_SNMP OctetStr * read_community
 
unsigned long next_transaction_id
 
bool sourceAddressValidation
 

Additional Inherited Members

- Public Types inherited from Synchronized
enum  TryLockResult { LOCKED = 1, BUSY = 0, OWNED = -1 }
 
- Static Public Member Functions inherited from ThreadManager
static void start_global_synch ()
 Start global synchronized execution.
 
static void end_global_synch ()
 End global synchronized execution.
 

Detailed Description

The RequestList represents a non ordered queue of Requests.

On multi-threaded SNMP agents this queue could contain more than one pending Request at once. The RequestList provides member functions to receive, process, lookup, and modify Requests.

The following example illustrates, how RequestList may be used in an v1 or v2c SNMP agent:

main (int argc, char* argv[]) { int status; Snmpx snmp(status, 161); // create SNMP++ session

if (status != SNMP_CLASS_SUCCESS) { // if fail print error cout << snmp.error_msg(status); // message exit(1); }

Mib mib; // create the agents MIB RequestList reqList;

mib.set_request_list(&reqList); // register RequestList // to be used by mib for outgoing requests

reqList.set_snmp(&snmp); // register the Snmpx object to // be used by the RequestList for incoming SNMP requests

mib.add(new systemGroup()); // add sysGroup and snmpGroup mib.add(new snmpGroup()); // (provided with AGENT++) to mib ...

Request* req; // pointer to an incoming SNMP request for (;;) { // loop forever (agent is a daemon)

    // wait for incoming request max 120 sec
    // and then just loop once
    req = reqList.receive(120);

    if (req) mib.process_request(req); // process the request

} }

Author
Frank Fock
Version
3.5.14

Constructor & Destructor Documentation

RequestList::RequestList ( )

Default constructor.

virtual RequestList::~RequestList ( )
virtual

Destructor (SYNCHRONIZED)

Member Function Documentation

virtual Request* RequestList::add_request ( Request )
protectedvirtual

Add a Request to the RequestList.

(SYNCHRONIZED)

Parameters
req- A pointer to a Request.
Returns
A pointer to the added Request.
virtual void RequestList::answer ( Request )
virtual

Answer a Request by sending the corresponding response PDU.

(SYNCHRONIZED)

Parameters
req- A pointer to a processed Request.
virtual void RequestList::authenticationFailure ( const NS_SNMP OctetStr &  context,
const NS_SNMP GenAddress &  sourceAddress,
int  status 
)
protectedvirtual

Sends an authenticationFailure notification if the corresponding MIB object is enabled.

Parameters
contextin which the failure occured. In most cases this is the default context ("").
sourceAddressthe source address of the host that sent the unauthenticated SNMP message.
statusthe error code that further classifies the authentication failure.
virtual bool RequestList::community_ok ( int  ,
const NS_SNMP OctetStr &   
)
protectedvirtual

Check whether a given community is acceptable for the specified PDU type.

Parameters
pdutype- A PDU type (e.g., sNMP_PDU_SET, sNMP_PDU_GET, etc.)
community- A v1 or v2c community string.
Returns
TRUE if the given community is ok, FALSE otherwise.
unsigned long RequestList::create_transaction_id ( )
inline

Get next transaction id.

Returns
a unique transaction id.
virtual bool RequestList::done ( unsigned  long,
int  ,
const Vbx  
)
virtual

Mark a sub-request as done and put the result of the sub-request into the response PDU.

(SYNCHRONIZED)

Parameters
request_ida request id of a pending request.
indexthe index of the target sub-request.
vba variable binding containing the result of an sub-request.
Returns
TRUE if request is ready to answer, FALSE otherwise.
virtual void RequestList::error ( unsigned  long,
int  ,
int   
)
virtual

Mark a sub-request as done with an error and put the corresponding SNMP error code for the sub-request into the response PDU.

(SYNCHRONIZED)

Parameters
request_ida request id of a pending request.
indexthe index of a failed sub-request.
erran SNMP error status.
virtual Request* RequestList::find_request_on_id ( unsigned  long)
virtual

Return a pointer to the request identified by a given request id.

(NOT SYNCHRONIZED)

Parameters
request_id- A request id.
Returns
A pointer to a Request or 0 if there is no request pending with the given request id.
bool RequestList::get_address_validation ( )
inline

Gets the current state of the source address validation for community base SNMP versions.

Returns
TRUE if source address validation is activated.
virtual Request* RequestList::get_request ( unsigned  long)
virtual

Return a pointer to the request identified by a given transaction id.

(SYNCHRONIZED)

Parameters
request_ida transaction id.
Returns
a pointer to a Request or 0 if there is no request pending with the given transaction id.
virtual unsigned long RequestList::get_request_id ( const Vbx )
virtual

Return the corresponding request id of a request in the receiver RequestList that contains the specified variable binding.

(SYNCHRONIZED)

Parameters
vb- A variable binding.
Returns
A request id or 0 if a corresponding request could not have been found.
Snmpx* RequestList::get_snmp ( )
inline

Get the Snmpx session used by this RequestList.

Returns
a Snmpx instance.
bool RequestList::is_empty ( )
inline

Check whether the request list (queue) is empty or not.

Returns
TRUE if the queue is empty.
static void RequestList::null_vbs ( Request req)
staticprotected

Set all variable bindings (for response) to null values.

Parameters
reqa pointer to a Request instance.
virtual Request* RequestList::receive ( int  )
virtual

Wait a given time for an incoming request.

Parameters
timeoutThe maximum time in seconds to wait for an incoming request. If timeout is 0 receive will not block, if it is <0 receive will wait forever.
Returns
A pointer to the received request or 0 if within the timeout period no request has been received.
virtual void RequestList::remove_request ( Request req)
virtual

Remove a request that should not be processed.

Parameters
req- The pointer returned from receive(), the pointer is invalid after this function returns.
virtual void RequestList::set_address_validation ( bool  )
virtual

Activate or deactivate source address validation for SNMP v1/v2c requests (SNMP-COMMUNITY-MIB).

Parameters
sourceAddressFilteringif TRUE incoming v1/v2c requests will be validated (not only) on the transport address including the UDP port.
void RequestList::set_read_community ( const NS_SNMP OctetStr &  )

Set READ community.

Parameters
readCommunitythe new community for all GET type requests.
virtual void RequestList::set_snmp ( Snmpx session)
inlinevirtual

Set the Snmpx session to be used for incoming requests.

Parameters
session- A pointer to Snmpx instance.
void RequestList::set_write_community ( const NS_SNMP OctetStr &  )

Set WRITE community.

Parameters
writeCommunitythe new community for SET requests.
unsigned long RequestList::size ( )
inline

Get the actual size of the request list.

Returns
the size of the queue.

Member Data Documentation

unsigned long RequestList::next_transaction_id
protected
NS_SNMP OctetStr* RequestList::read_community
protected
List<Request>* RequestList::requests
protected
Snmpx* RequestList::snmp
protected
bool RequestList::sourceAddressValidation
protected
NS_SNMP OctetStr* RequestList::write_community
protected

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