View Javadoc
1   // NAME
2   //      $RCSfile: OneGetNextPdu.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 3.14 $
7   // CREATED
8   //      $Date: 2006/01/17 17:49:53 $
9   // COPYRIGHT
10  //      Westhawk Ltd
11  // TO DO
12  //
13  
14  /*
15   * Copyright (C) 1996 - 1998 by Westhawk Ltd (www.westhawk.nl)
16   * Copyright (C) 1998 - 2006 by Westhawk Ltd 
17   * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
18   *
19   * Permission to use, copy, modify, and distribute this software
20   * for any purpose and without fee is hereby granted, provided
21   * that the above copyright notices appear in all copies and that
22   * both the copyright notice and this permission notice appear in
23   * supporting documentation.
24   * This software is provided "as is" without express or implied
25   * warranty.
26   * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
27   */
28   
29  package uk.co.westhawk.snmp.pdu;
30  
31  /*-
32   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
33   * SNMP Java Client
34   * ჻჻჻჻჻჻
35   * Copyright 2023 Sentry Software, Westhawk
36   * ჻჻჻჻჻჻
37   * This program is free software: you can redistribute it and/or modify
38   * it under the terms of the GNU Lesser General Public License as
39   * published by the Free Software Foundation, either version 3 of the
40   * License, or (at your option) any later version.
41   *
42   * This program is distributed in the hope that it will be useful,
43   * but WITHOUT ANY WARRANTY; without even the implied warranty of
44   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
45   * GNU General Lesser Public License for more details.
46   *
47   * You should have received a copy of the GNU General Lesser Public
48   * License along with this program.  If not, see
49   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
50   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
51   */
52  import uk.co.westhawk.snmp.stack.*;
53  import java.util.*;
54  
55  /**
56   * <p>
57   * The OneGetNextPdu class will ask for one (1) object (oid), based on
58   * the GetNext request.
59   * </p>
60   *
61   * <p>
62   * Unless an exception occurred the Object to the update() method of the
63   * Observer will be a varbind, so any AsnObject type can be returned.
64   * In the case of an exception, that exception will be passed.
65   * </p>
66   *
67   * <p>
68   * For SNMPv3: The receiver of a request PDU acts as the authoritative engine.
69   * </p>
70   *
71   * @see varbind
72   * @see InterfaceGetNextPdu
73   * @see GetNextPdu_vec
74   *
75   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
76   * @version $Revision: 3.14 $ $Date: 2006/01/17 17:49:53 $
77   */
78  public class OneGetNextPdu extends GetNextPdu 
79  {
80      private static final String     version_id =
81          "@(#)$Id: OneGetNextPdu.java,v 3.14 2006/01/17 17:49:53 birgit Exp $ Copyright Westhawk Ltd";
82  
83      varbind var;
84  
85      /**
86       * Constructor.
87       *
88       * @param con The context of the request
89       */
90      public OneGetNextPdu(SnmpContextBasisFace con)
91      {
92          super(con);
93      }
94  
95      /**
96       * Constructor that will send the request immediately. No Observer
97       * is set.
98       *
99       * @param con the SnmpContextBasisFace
100      * @param oid the oid 
101      */
102     public OneGetNextPdu(SnmpContextBasisFace con, String oid) 
103     throws PduException, java.io.IOException
104     {
105         this(con, oid, null);
106     }
107 
108     /**
109      * Constructor that will send the request immediately. 
110      *
111      * @param con the SnmpContextBasisFace
112      * @param oid the oid 
113      * @param o the Observer that will be notified when the answer is received
114      */
115     public OneGetNextPdu(SnmpContextBasisFace con, String oid, Observer o) 
116     throws PduException, java.io.IOException
117     {
118         super(con);
119         if (o != null) 
120         {
121             addObserver(o);
122         }
123         addOid(oid);
124         send();
125     }
126 
127     /**
128      * The value of the request is set. This will be called by
129      * Pdu.fillin().
130      *
131      * @param n the index of the value
132      * @param a_var the value
133      * @see Pdu#new_value 
134      */
135     protected void new_value(int n, varbind a_var) 
136     {
137         if (n == 0) 
138         {
139             var = a_var;
140         }
141     }
142 
143     /**
144      * This method notifies all observers. 
145      * This will be called by Pdu.fillin().
146      * 
147      * <p>
148      * Unless an exception occurred the Object to the update() method of the
149      * Observer will be a varbind, so any AsnObject type can be returned.
150      * In the case of an exception, that exception will be passed.
151      * </p>
152      */
153     protected void tell_them()  
154     {
155         notifyObservers(var);
156     }
157 
158 }