Browse Source

[3156] Minor review changes.

Added empty implemenation of StateMode::onModelFailure and
renamed event and state boundary constants.
Thomas Markwalder 11 years ago
parent
commit
a617211d81

+ 2 - 2
src/bin/d2/nc_trans.cc

@@ -25,7 +25,7 @@ const int NameChangeTransaction::SELECTING_REV_SERVER_ST;
 const int NameChangeTransaction::PROCESS_TRANS_OK_ST;
 const int NameChangeTransaction::PROCESS_TRANS_FAILED_ST;
 
-const int NameChangeTransaction::NCT_STATE_MAX;
+const int NameChangeTransaction::NCT_DERIVED_STATE_MIN;
 
 // Common transaction events
 const int NameChangeTransaction::SELECT_SERVER_EVT;
@@ -36,7 +36,7 @@ const int NameChangeTransaction::IO_COMPLETED_EVT;
 const int NameChangeTransaction::UPDATE_OK_EVT;
 const int NameChangeTransaction::UPDATE_FAILED_EVT;
 
-const int NameChangeTransaction::NCT_EVENT_MAX;
+const int NameChangeTransaction::NCT_DERIVED_EVENT_MIN;
 
 NameChangeTransaction::
 NameChangeTransaction(isc::asiolink::IOService& io_service,

+ 23 - 14
src/bin/d2/nc_trans.h

@@ -87,7 +87,7 @@ public:
     //@{ States common to all transactions.
 
     /// @brief State from which a transaction is started.
-    static const int READY_ST = SM_STATE_MAX + 1;
+    static const int READY_ST = SM_DERIVED_STATE_MIN + 1;
 
     /// @brief State in which forward DNS server selection is done.
     ///
@@ -95,7 +95,7 @@ public:
     /// to use is conducted.  Upon conclusion of this state the next server
     /// is either selected or it should transition out with NO_MORE_SERVERS_EVT
     /// event.
-    static const int SELECTING_FWD_SERVER_ST = SM_STATE_MAX + 2;
+    static const int SELECTING_FWD_SERVER_ST = SM_DERIVED_STATE_MIN + 2;
 
     /// @brief State in which reverse DNS server  selection is done.
     ///
@@ -103,43 +103,52 @@ public:
     /// to use is conducted.  Upon conclusion of this state the next server
     /// is either selected or it should transition out with NO_MORE_SERVERS_EVT
     /// event.
-    static const int SELECTING_REV_SERVER_ST = SM_STATE_MAX + 3;
+    static const int SELECTING_REV_SERVER_ST = SM_DERIVED_STATE_MIN + 3;
 
-    static const int PROCESS_TRANS_OK_ST = SM_STATE_MAX + 4;
+    /// @brief State which processes successful transaction conclusion.
+    static const int PROCESS_TRANS_OK_ST = SM_DERIVED_STATE_MIN + 4;
 
-    static const int PROCESS_TRANS_FAILED_ST = SM_STATE_MAX + 5;
+    /// @brief State which processes an unsuccessful transaction conclusion.
+    static const int PROCESS_TRANS_FAILED_ST = SM_DERIVED_STATE_MIN + 5;
 
     /// @brief Value at which custom states in a derived class should begin.
-    static const int NCT_STATE_MAX = SM_STATE_MAX + 100;
+    static const int NCT_DERIVED_STATE_MIN = SM_DERIVED_STATE_MIN + 101;
     //@}
 
     //@{ Events common to all transactions.
     /// @brief Issued when a server needs to be selected.
-    static const int SELECT_SERVER_EVT = SM_STATE_MAX + 1;
+    static const int SELECT_SERVER_EVT = SM_DERIVED_EVENT_MIN + 1;
+
     /// @brief Issued when a server  has been selected.
-    static const int SERVER_SELECTED_EVT = SM_EVENT_MAX + 2;
+    static const int SERVER_SELECTED_EVT = SM_DERIVED_EVENT_MIN + 2;
+
     /// @brief Issued when an update fails due to an IO error.
-    static const int SERVER_IO_ERROR_EVT = SM_EVENT_MAX + 3;
+    static const int SERVER_IO_ERROR_EVT = SM_DERIVED_EVENT_MIN + 3;
+
     /// @brief Issued when there are no more servers from which to select.
     /// This occurs when none of the servers in the list can be reached to
     /// perform the update.
-    static const int NO_MORE_SERVERS_EVT =SM_EVENT_MAX +  4;
+
+    static const int NO_MORE_SERVERS_EVT =SM_DERIVED_EVENT_MIN +  4;
     /// @brief Issued when a DNS update packet exchange has completed.
     /// This occurs whenever the DNSClient callback is invoked whether the
     /// exchange was successful or not.
-    static const int IO_COMPLETED_EVT = SM_EVENT_MAX + 5;
+
+    static const int IO_COMPLETED_EVT = SM_DERIVED_EVENT_MIN + 5;
     /// @brief Issued when the attempted update successfully completed.
     /// This occurs when an DNS update packet was successfully processed
     /// by the server.
-    static const int UPDATE_OK_EVT = SM_EVENT_MAX + 6;
+
+    static const int UPDATE_OK_EVT = SM_DERIVED_EVENT_MIN + 6;
+
     /// @brief Issued when the attempted update fails to complete.
     /// This occurs when an DNS update packet fails to process. The nature of
     /// the failure is given by the DNSClient return status and the response
     /// packet (if one was received).
-    static const int UPDATE_FAILED_EVT = SM_EVENT_MAX + 7;
+    static const int UPDATE_FAILED_EVT = SM_DERIVED_EVENT_MIN + 7;
 
     /// @brief Value at which custom events in a derived class should begin.
-    static const int NCT_EVENT_MAX = SM_EVENT_MAX + 100;
+    static const int NCT_DERIVED_EVENT_MIN = SM_DERIVED_EVENT_MIN + 101;
     //@}
 
     /// @brief Constructor

+ 7 - 2
src/bin/d2/state_model.cc

@@ -71,7 +71,7 @@ StateSet::getState(int value) {
 const int StateModel::NEW_ST;
 const int StateModel::END_ST;
 
-const int StateModel::SM_STATE_MAX;
+const int StateModel::SM_DERIVED_STATE_MIN;
 
 // Common state model events
 const int StateModel::NOP_EVT;
@@ -79,7 +79,7 @@ const int StateModel::START_EVT;
 const int StateModel::END_EVT;
 const int StateModel::FAIL_EVT;
 
-const int StateModel::SM_EVENT_MAX;
+const int StateModel::SM_DERIVED_EVENT_MIN;
 
 StateModel::StateModel() : events_(), states_(), dictionaries_initted_(false),
                           curr_state_(NEW_ST), prev_state_(NEW_ST),
@@ -233,6 +233,11 @@ StateModel::verifyStates() {
     getState(END_ST);
 }
 
+void 
+StateModel::onModelFailure(const std::string&) {
+    // Empty implementation to make deriving classes simpler.
+}
+
 void
 StateModel::transition(unsigned int state, unsigned int event) {
     setState(state);

+ 5 - 4
src/bin/d2/state_model.h

@@ -246,7 +246,7 @@ public:
     static const int END_ST = 1;
 
     /// @brief Value at which custom states in a derived class should begin.
-    static const int SM_STATE_MAX = 10;
+    static const int SM_DERIVED_STATE_MIN = 11;
     //@}
 
     //@{ Events common to all state models.
@@ -265,7 +265,7 @@ public:
     static const int FAIL_EVT = 3;
 
     /// @brief Value at which custom events in a derived class should begin.
-    static const int SM_EVENT_MAX = 10;
+    static const int SM_DERIVED_EVENT_MIN = 11;
     //@}
 
     /// @brief Constructor
@@ -466,10 +466,11 @@ protected:
     /// model execution, such as a state handler throwing an exception.
     /// It provides derivations an opportunity to act accordingly by setting
     /// the appropriate status or taking other remedial action.   This allows
-    /// the model execution loop to remain exception safe.
+    /// the model execution loop to remain exception safe.  This default
+    /// implementation does nothing.
     ///
     /// @param explanation text detailing the error and state machine context
-    virtual void onModelFailure(const std::string& explanation) = 0;
+    virtual void onModelFailure(const std::string& explanation);
 
     /// @brief Sets up the model to transition into given state with a given
     /// event.

+ 2 - 2
src/bin/d2/tests/nc_trans_unittests.cc

@@ -35,10 +35,10 @@ class NameChangeStub : public NameChangeTransaction {
 public:
 
     // NameChangeStub states
-    static const int DOING_UPDATE_ST = NCT_STATE_MAX + 1;
+    static const int DOING_UPDATE_ST = NCT_DERIVED_STATE_MIN + 1;
 
     // NameChangeStub events
-    static const int SEND_UPDATE_EVT = NCT_EVENT_MAX + 2;
+    static const int SEND_UPDATE_EVT = NCT_DERIVED_EVENT_MIN + 2;
 
     /// @brief Constructor
     ///

+ 9 - 9
src/bin/d2/tests/state_model_unittests.cc

@@ -35,32 +35,32 @@ public:
 
     ///@brief StateModelTest states
     ///@brief Fake state used for handler mapping tests.
-    static const int DUMMY_ST = SM_STATE_MAX + 1;
+    static const int DUMMY_ST = SM_DERIVED_STATE_MIN + 1;
 
     ///@brief Starting state for the test state model.
-    static const int READY_ST = SM_STATE_MAX + 2;
+    static const int READY_ST = SM_DERIVED_STATE_MIN + 2;
 
     ///@brief State which simulates doing asynchronous work.
-    static const int DO_WORK_ST = SM_STATE_MAX + 3;
+    static const int DO_WORK_ST = SM_DERIVED_STATE_MIN + 3;
 
     ///@brief State which finishes off processing.
-    static const int DONE_ST = SM_STATE_MAX + 4;
+    static const int DONE_ST = SM_DERIVED_STATE_MIN + 4;
 
     // StateModelTest events
     ///@brief Event used to trigger initiation of asynchronous work.
-    static const int WORK_START_EVT = SM_EVENT_MAX + 1;
+    static const int WORK_START_EVT = SM_DERIVED_EVENT_MIN + 1;
 
     ///@brief Event issued when the asynchronous work "completes".
-    static const int WORK_DONE_EVT = SM_EVENT_MAX + 2;
+    static const int WORK_DONE_EVT = SM_DERIVED_EVENT_MIN + 2;
 
     ///@brief Event issued when all the work is done.
-    static const int ALL_DONE_EVT = SM_EVENT_MAX + 3;
+    static const int ALL_DONE_EVT = SM_DERIVED_EVENT_MIN + 3;
 
     ///@brief Event used to trigger an attempt to transition to bad state
-    static const int FORCE_UNDEFINED_ST_EVT = SM_EVENT_MAX + 4;
+    static const int FORCE_UNDEFINED_ST_EVT = SM_DERIVED_EVENT_MIN + 4;
 
     ///@brief Event used to trigger an attempt to transition to bad state
-    static const int SIMULATE_ERROR_EVT = SM_EVENT_MAX + 5;
+    static const int SIMULATE_ERROR_EVT = SM_DERIVED_EVENT_MIN + 5;
 
     /// @brief Constructor
     ///