Permalink
Browse files

Add master_proxy::unregister_subtree().

  • Loading branch information...
1 parent 6f08cde commit e33b46984016c818621f4609e8058553c3bf0b01 @tanjeff committed Feb 26, 2012
Showing with 96 additions and 6 deletions.
  1. +48 −0 src/master_proxy.cpp
  2. +48 −6 src/master_proxy.hpp
View
48 src/master_proxy.cpp
@@ -354,6 +354,54 @@ void master_proxy::register_subtree(oid subtree,
+void master_proxy::unregister_subtree(oid subtree,
+ byte_t priority)
+{
+ // Remove the registration from registrations list
+ std::list< boost::shared_ptr<RegisterPDU> >::iterator r;
+ r = this->registrations.begin();
+ while (r != this->registrations.end())
+ {
+ if( (*r)->get_priority() == priority
+ && (*r)->get_subtree() == subtree
+ && (*r)->get_range_subid() == 0
+ && (*r)->get_upper_bound() == 0 )
+ {
+ // registration found: remove it, forward to next one
+ r = registrations.erase(r);
+ }
+ else
+ {
+ // Ignore registration, inspect next one
+ r++;
+ }
+ }
+
+ // Build UnregisterPDU
+ boost::shared_ptr<UnregisterPDU> pdu(new UnregisterPDU);
+ pdu->set_subtree(subtree);
+ pdu->set_priority(priority);
+
+ // Sent PDU
+ try
+ {
+ this->undo_registration(pdu);
+ }
+ catch( internal_error )
+ {
+ // Huh, it seems that we sent a malformed PDU to the master. We convert
+ // this to parse_error.
+ throw(parse_error());
+ }
+ catch(...)
+ {
+ // All other exceptions are forwarded unmodified:
+ throw;
+ }
+}
+
+
+
void master_proxy::undo_registration(boost::shared_ptr<UnregisterPDU> pdu)
{
// Are we connected?
View
54 src/master_proxy.hpp
@@ -294,10 +294,8 @@ namespace agentxcpp
* request. The reason for that is
* unknown.
*
- * \exception unknown_registration If the exact same subtree was
- * alread registered, either by
- * another subagent or by this
- * subagent.
+ * \exception unknown_registration The MIB region is not currently
+ * registered with this parameters.
*
* \exception parse_error If an unexpected response was received
* from the master. This is probably a
@@ -418,8 +416,8 @@ namespace agentxcpp
*
* \internal
*
- * This method calls adds the registered subtree to
- * registered_subtrees on success.
+ * This method adds the registered subtree to registered_subtrees
+ * on success.
*
* \endinternal
*
@@ -470,6 +468,50 @@ namespace agentxcpp
byte_t timeout=0);
/**
+ * \brief Unregister a subtree with the master agent
+ *
+ * This function unregisters a subtree (or MIB region) which has
+ * previously been registered.
+ *
+ * \internal
+ *
+ * This method removes the registered subtree from
+ * registered_subtrees.
+ *
+ * \endinternal
+ *
+ * \param subtree The (root of the) subtree to unregister.
+ *
+ * \param priority The priority with which the registration was
+ * done. the subtree. Because register_subtree()
+ * uses 127 as default, this value is also the
+ * default for this function.
+ *
+ * \exception disconnected If the master_proxy is currently in
+ * state 'disconnected'.
+ *
+ * \exception timeout_error If the master agent does not
+ * respond within the timeout interval.
+ *
+ * \exception master_is_unable The master agent was unable to
+ * perform the desired unregister
+ * request. The reason for that is
+ * unknown.
+ *
+ * \exception unknown_registration The MIB region is not currently
+ * registered with this parameters.
+ *
+ * \exception parse_error A malformed network message was found
+ * during communcation with the master. This
+ * may be a programming error in the master
+ * or in the agentXcpp library. It is
+ * possible that the master actually
+ * unregistered the MIB region.
+ */
+ void unregister_subtree(oid subtree,
+ byte_t priority=127);
+
+ /**
* \brief Get the io_service object used by this master_proxy.
*/
boost::asio::io_service* get_io_service() const

0 comments on commit e33b469

Please sign in to comment.