LOG_INFO(netconf_logger, NETCONF_STARTED).arg(VERSION);
try {
- // Initialize netconf agent in a thread.
- std::thread th([this]() {
- try {
- // Initialize sysrepo.
- agent_.initSysrepo();
-
- // Get the configuration manager.
- NetconfCfgMgrPtr cfg_mgr(getNetconfCfgMgr());
-
- // Call init.
- agent_.init(cfg_mgr);
- } catch (...) {
- // Should not happen but in case...
- std::exception_ptr eptr = std::current_exception();
- getIoService()->post([eptr] () {
- if (eptr) {
- std::rethrow_exception(eptr);
- }
- });
- }
- });
-
- // Detach the thread.
- th.detach();
+ // Initialize netconf agent.
+ // Initialize sysrepo.
+ agent_.initSysrepo();
+
+ // Get the configuration manager.
+ NetconfCfgMgrPtr cfg_mgr(getNetconfCfgMgr());
+
+ // Call init.
+ agent_.init(cfg_mgr);
// Let's process incoming data or expiring timers in a loop until
// shutdown condition is detected.
public:
/// @brief Constructor.
NetconfAgentLogTest()
- : io_service_(new IOService()),
+ : finished_(false),
+ io_service_(new IOService()),
thread_(),
agent_(new NakedNetconfAgent) {
}
/// @brief Destructor.
virtual ~NetconfAgentLogTest() {
+ if (agent_) {
+ clearYang(agent_);
+ agent_->clear();
+ }
+ agent_.reset();
// io_service must be stopped to make the thread to return.
io_service_->stop();
- io_service_.reset();
if (thread_) {
thread_->join();
thread_.reset();
}
- if (agent_) {
- clearYang(agent_);
- agent_->clear();
- }
- agent_.reset();
+ io_service_.reset();
}
-
- /// @brief To know when the callback was called.
- bool finished_;
-
/// @brief Default change callback (print changes and return OK).
sr_error_t callback(sysrepo::S_Session sess,
const char* module_name,
}
}
+ /// @brief To know when the callback was called.
+ std::atomic<bool> finished_;
+
/// @brief IOService object.
IOServicePtr io_service_;