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 MetricsHub, 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      private static final String version_id = "@(#)$Id: OneGetNextPdu.java,v 3.14 2006/01/17 17:49:53 birgit Exp $ Copyright Westhawk Ltd";
80  
81      varbind var;
82  
83      /**
84       * Constructor.
85       *
86       * @param con The context of the request
87       */
88      public OneGetNextPdu(SnmpContextBasisFace con) {
89          super(con);
90      }
91  
92      /**
93       * Constructor that will send the request immediately. No Observer
94       * is set.
95       *
96       * @param con the SnmpContextBasisFace
97       * @param oid the oid
98       */
99      public OneGetNextPdu(SnmpContextBasisFace con, String oid)
100             throws PduException, java.io.IOException {
101         this(con, oid, null);
102     }
103 
104     /**
105      * Constructor that will send the request immediately.
106      *
107      * @param con the SnmpContextBasisFace
108      * @param oid the oid
109      * @param o   the Observer that will be notified when the answer is received
110      */
111     public OneGetNextPdu(SnmpContextBasisFace con, String oid, Observer o)
112             throws PduException, java.io.IOException {
113         super(con);
114         if (o != null) {
115             addObserver(o);
116         }
117         addOid(oid);
118         send();
119     }
120 
121     /**
122      * The value of the request is set. This will be called by
123      * Pdu.fillin().
124      *
125      * @param n     the index of the value
126      * @param a_var the value
127      * @see Pdu#new_value
128      */
129     protected void new_value(int n, varbind a_var) {
130         if (n == 0) {
131             var = a_var;
132         }
133     }
134 
135     /**
136      * This method notifies all observers.
137      * This will be called by Pdu.fillin().
138      * 
139      * <p>
140      * Unless an exception occurred the Object to the update() method of the
141      * Observer will be a varbind, so any AsnObject type can be returned.
142      * In the case of an exception, that exception will be passed.
143      * </p>
144      */
145     protected void tell_them() {
146         notifyObservers(var);
147     }
148 
149 }