|
@@ -33,51 +33,13 @@
|
|
|
namespace isc {
|
|
|
namespace auth {
|
|
|
|
|
|
-namespace internal {
|
|
|
+namespace datasrc_clientmgr_internal {
|
|
|
enum CommandID {
|
|
|
NOOP, ///< Do nothing. Only useful for tests
|
|
|
SHUTDOWN ///< Shutdown the builder.
|
|
|
};
|
|
|
typedef std::pair<CommandID, data::ConstElementPtr> Command;
|
|
|
-
|
|
|
-template <typename MutexType, typename CondVarType>
|
|
|
-class DataSrcClientsBuilderBase {
|
|
|
-public:
|
|
|
- DataSrcClientsBuilderBase(std::list<Command>* command_queue,
|
|
|
- CondVarType* cond, MutexType* queue_mutex) :
|
|
|
- command_queue_(command_queue), cond_(cond), queue_mutex_(queue_mutex)
|
|
|
- {}
|
|
|
-
|
|
|
- /// Not sure if we need this. It depends on test details.
|
|
|
- /// \brief Destructor.
|
|
|
- ///
|
|
|
- /// This does nothing, but explicitly defined to silence 'unused variable'
|
|
|
- /// warnings from some versions of clang++.
|
|
|
- ///~DataSrcClientsBuilderBase() {}
|
|
|
-
|
|
|
- void run();
|
|
|
-
|
|
|
- /// separated from run() and made public for the purpose of tests.
|
|
|
- ///
|
|
|
- /// \return true if it the builder should keep running; false otherwise.
|
|
|
- bool handleCommand(const Command& command);
|
|
|
-
|
|
|
-private:
|
|
|
- // NOOP command handler. We use this so tests can override it.
|
|
|
- void doNoop() {}
|
|
|
-
|
|
|
- // end-in, front-out queue
|
|
|
- std::list<Command>* command_queue_;
|
|
|
- CondVarType* cond_;
|
|
|
- MutexType* queue_mutex_;
|
|
|
- //boost::shared_ptr<DataSrcClientListMap>* map;
|
|
|
- //MutexType* data_mutex_;
|
|
|
-};
|
|
|
-
|
|
|
-// Shortcut typedef for normal use
|
|
|
-typedef DataSrcClientsBuilderBase<util::thread::Mutex, util::thread::CondVar>
|
|
|
-DataSrcClientsBuilder;
|
|
|
-}
|
|
|
+} // namespace datasrc_clientmgr_internal
|
|
|
|
|
|
template <typename ThreadType, typename BuilderType, typename MutexType,
|
|
|
typename CondVarType>
|
|
@@ -98,7 +60,8 @@ public:
|
|
|
// is Thread::UncaughtException when the builder thread died due to
|
|
|
// an exception. We specifically log it and just ignore others.
|
|
|
try {
|
|
|
- sendCommand(internal::SHUTDOWN, data::ConstElementPtr());
|
|
|
+ sendCommand(datasrc_clientmgr_internal::SHUTDOWN,
|
|
|
+ data::ConstElementPtr());
|
|
|
builder_thread_.wait();
|
|
|
} catch (const util::thread::Thread::UncaughtException& ex) {
|
|
|
LOG_ERROR(auth_logger, AUTH_DATASRC_CLIENTS_SHUTDOWN_ERROR).
|
|
@@ -107,22 +70,62 @@ public:
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
- void sendCommand(internal::CommandID command, data::ConstElementPtr arg) {
|
|
|
+ void sendCommand(datasrc_clientmgr_internal::CommandID command,
|
|
|
+ data::ConstElementPtr arg) {
|
|
|
{
|
|
|
typename MutexType::Locker locker(queue_mutex_);
|
|
|
- command_queue_.push_back(internal::Command(command, arg));
|
|
|
+ command_queue_.push_back(
|
|
|
+ datasrc_clientmgr_internal::Command(command, arg));
|
|
|
}
|
|
|
cond_.signal();
|
|
|
}
|
|
|
|
|
|
- std::list<internal::Command> command_queue_;
|
|
|
+ std::list<datasrc_clientmgr_internal::Command> command_queue_;
|
|
|
CondVarType cond_;
|
|
|
MutexType queue_mutex_;
|
|
|
BuilderType builder_;
|
|
|
ThreadType builder_thread_;
|
|
|
};
|
|
|
|
|
|
-namespace internal {
|
|
|
+namespace datasrc_clientmgr_internal {
|
|
|
+template <typename MutexType, typename CondVarType>
|
|
|
+class DataSrcClientsBuilderBase {
|
|
|
+public:
|
|
|
+ DataSrcClientsBuilderBase(std::list<Command>* command_queue,
|
|
|
+ CondVarType* cond, MutexType* queue_mutex) :
|
|
|
+ command_queue_(command_queue), cond_(cond), queue_mutex_(queue_mutex)
|
|
|
+ {}
|
|
|
+
|
|
|
+ /// Not sure if we need this. It depends on test details.
|
|
|
+ /// \brief Destructor.
|
|
|
+ ///
|
|
|
+ /// This does nothing, but explicitly defined to silence 'unused variable'
|
|
|
+ /// warnings from some versions of clang++.
|
|
|
+ ///~DataSrcClientsBuilderBase() {}
|
|
|
+
|
|
|
+ void run();
|
|
|
+
|
|
|
+ /// separated from run() and made public for the purpose of tests.
|
|
|
+ ///
|
|
|
+ /// \return true if it the builder should keep running; false otherwise.
|
|
|
+ bool handleCommand(const Command& command);
|
|
|
+
|
|
|
+private:
|
|
|
+ // NOOP command handler. We use this so tests can override it.
|
|
|
+ void doNoop() {}
|
|
|
+
|
|
|
+ // end-in, front-out queue
|
|
|
+ std::list<Command>* command_queue_;
|
|
|
+ CondVarType* cond_;
|
|
|
+ MutexType* queue_mutex_;
|
|
|
+ //boost::shared_ptr<DataSrcClientListMap>* map;
|
|
|
+ //MutexType* data_mutex_;
|
|
|
+};
|
|
|
+
|
|
|
+// Shortcut typedef for normal use
|
|
|
+typedef DataSrcClientsBuilderBase<util::thread::Mutex, util::thread::CondVar>
|
|
|
+DataSrcClientsBuilder;
|
|
|
+
|
|
|
template <typename MutexType, typename CondVarType>
|
|
|
void
|
|
|
DataSrcClientsBuilderBase<MutexType, CondVarType>::run() {
|
|
@@ -177,16 +180,16 @@ DataSrcClientsBuilderBase<MutexType, CondVarType>::handleCommand(
|
|
|
}
|
|
|
return (true);
|
|
|
}
|
|
|
-} // namespace internal
|
|
|
+} // namespace datasrc_clientmgr_internal
|
|
|
|
|
|
/// \brief Shortcut type for normal data source clients manager.
|
|
|
///
|
|
|
/// In fact, for non test applications this is the only type of this kind
|
|
|
/// to be considered.
|
|
|
-typedef DataSrcClientsMgrBase<util::thread::Thread,
|
|
|
- internal::DataSrcClientsBuilder,
|
|
|
- util::thread::Mutex, util::thread::CondVar>
|
|
|
-DataSrcClientsMgr;
|
|
|
+typedef DataSrcClientsMgrBase<
|
|
|
+ util::thread::Thread,
|
|
|
+ datasrc_clientmgr_internal::DataSrcClientsBuilder,
|
|
|
+ util::thread::Mutex, util::thread::CondVar> DataSrcClientsMgr;
|
|
|
} // namespace auth
|
|
|
} // namespace isc
|
|
|
|