Skip to content

Commit 14693a6

Browse files
committed
Obtaining session IDs
Change-Id: I1217dd636f2805c334df0c1f375d0701c8794960
1 parent 07655b2 commit 14693a6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

include/sysrepo-cpp/Session.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class Session {
148148
Connection getConnection();
149149
const libyang::Context getContext() const;
150150

151+
uint32_t getId() const;
152+
151153
private:
152154
friend Connection;
153155
friend Session wrapUnmanagedSession(sr_session_ctx_s* session);

src/Session.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,16 @@ const libyang::Context Session::getContext() const
685685
return libyang::createUnmanagedContext(const_cast<ly_ctx*>(ctx), [sess = m_sess] (ly_ctx*) { sr_session_release_context(sess.get()); });
686686
}
687687

688+
/**
689+
* @brief Get the internal, sysrepo-level session ID
690+
*
691+
* Wraps `sr_session_get_id`.
692+
*/
693+
uint32_t Session::getId() const
694+
{
695+
return sr_session_get_id(m_sess.get());
696+
}
697+
688698
sr_session_ctx_s* getRawSession(Session sess)
689699
{
690700
return sess.m_sess.get();

tests/session.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,10 @@ TEST_CASE("session")
213213
REQUIRE(*data->printStr(libyang::DataFormat::JSON, libyang::PrintFlags::WithSiblings) == "{\n\n}\n");
214214
REQUIRE_THROWS_AS(sess.setItem("/test_module:leafInt32", "123"), sysrepo::ErrorWithCode);
215215
}
216+
217+
DOCTEST_SUBCASE("session IDs")
218+
{
219+
REQUIRE(sess.getId() == sess.getId());
220+
REQUIRE(sess.getId() != conn->sessionStart().getId());
221+
}
216222
}

0 commit comments

Comments
 (0)