View Javadoc
1   // NAME
2   //      $RCSfile: OneGetPdu.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 3.13 $
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 OneGetPdu class will ask for one (1) object (OID), based on
58   * the Get 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   *
73   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
74   * @version $Revision: 3.13 $ $Date: 2006/01/17 17:49:53 $
75   */
76  public class OneGetPdu extends GetPdu {
77      private static final String version_id = "@(#)$Id: OneGetPdu.java,v 3.13 2006/01/17 17:49:53 birgit Exp $ Copyright Westhawk Ltd";
78  
79      varbind var;
80  
81      /**
82       * Constructor.
83       *
84       * @param con The context of the request
85       */
86      public OneGetPdu(SnmpContextBasisFace con) {
87          super(con);
88      }
89  
90      /**
91       * Constructor that will send the request immediately. No Observer
92       * is set.
93       *
94       * @param con the SnmpContextBasisFace
95       * @param oid the oid
96       */
97      public OneGetPdu(SnmpContextBasisFace con, String oid)
98              throws PduException, java.io.IOException {
99          this(con, oid, null);
100     }
101 
102     /**
103      * Constructor that will send the request immediately.
104      *
105      * @param con the SnmpContextBasisFace
106      * @param oid the oid
107      * @param o   the Observer that will be notified when the answer is received
108      */
109     public OneGetPdu(SnmpContextBasisFace con, String oid, Observer o)
110             throws PduException, java.io.IOException {
111         super(con);
112         if (o != null) {
113             addObserver(o);
114         }
115         addOid(oid);
116         send();
117     }
118 
119     /**
120      * The value of the request is set. This will be called by
121      * Pdu.fillin().
122      *
123      * @param n     the index of the value
124      * @param a_var the value
125      * @see Pdu#new_value
126      */
127     protected void new_value(int n, varbind a_var) {
128         if (n == 0) {
129             var = a_var;
130         }
131     }
132 
133     /**
134      * This method notifies all observers.
135      * This will be called by Pdu.fillin().
136      * 
137      * <p>
138      * Unless an exception occurred the Object to the update() method of the
139      * Observer will be a varbind, so any AsnObject type can be returned.
140      * In the case of an exception, that exception will be passed.
141      * </p>
142      */
143     protected void tell_them() {
144         notifyObservers(var);
145     }
146 
147 }