blob: 71bb7e42cf701b8acb1d5a6fbb068c5201ab9d2d [file] [log] [blame]
Tom Joseph3e61aa02016-08-08 08:42:39 -05001#pragma once
2
3#include <map>
4#include <memory>
5#include <mutex>
6
7#include "session.hpp"
8
9namespace session
10{
11
12enum class RetrieveOption
13{
14 BMC_SESSION_ID,
15 RC_SESSION_ID,
16};
17
18constexpr size_t SESSION_ZERO = 0;
19constexpr size_t MAX_SESSIONLESS_COUNT = 1;
20constexpr size_t MAX_SESSION_COUNT = 5;
21
22/*
23 * @class Manager
24 *
25 * Manager class acts a manager for the IPMI sessions and provides interfaces
26 * to start a session, stop a session and get reference to the session objects.
27 *
28 */
29
30class Manager
31{
32 public:
33
34 // BMC Session ID is the key for the map
35 using SessionMap = std::map<SessionID, std::shared_ptr<Session>>;
36
37 Manager();
38 ~Manager() = default;
39 Manager(const Manager&) = delete;
40 Manager& operator=(const Manager&) = delete;
41 Manager(Manager&&) = default;
42 Manager& operator=(Manager&&) = default;
43
44 /*
45 * @brief Start an IPMI session
46 *
47 * @param[in] remoteConsoleSessID - Remote Console Session ID mentioned
48 * in the Open SessionRequest Command
49 * @param[in] priv - Privilege level requested
50 * @param[in] authAlgo - Authentication Algorithm
51 *
52 * @return session handle on success and nullptr on failure
53 *
54 */
55 std::weak_ptr<Session> startSession(SessionID remoteConsoleSessID,
56 Privilege priv, cipher::rakp_auth::Algorithms authAlgo);
57
58 /*
59 * @brief Stop IPMI Session
60 *
61 * @param[in] bmcSessionID - BMC Session ID
62 *
63 */
64 void stopSession(SessionID bmcSessionID);
65
66 /*
67 * @brief Get Session Handle
68 *
69 * @param[in] sessionID - Session ID
70 * @param[in] option - Select between BMC Session ID and Remote Console
71 * Session ID, Default option is BMC Session ID
72 *
73 * @return session handle on success and nullptr on failure
74 *
75 */
76 std::weak_ptr<Session> getSession(
77 SessionID sessionID,
78 RetrieveOption option = RetrieveOption::BMC_SESSION_ID);
79
80 private:
81
82 /*
83 * @brief Session Manager keeps the session objects as a sorted
84 * associative container with Session ID as the unique key
85 */
86 SessionMap sessionsMap;
87
88 /*
89 * @brief Clean Session Stale Entries
90 *
91 * Removes the inactive sessions entries from the Session Map
92 */
93 void cleanStaleEntries();
94};
95
96} // namespace session