Skip to content

Commit 9fe40e9

Browse files
rkavitha-hclKAVITHA RAMALINGAM
authored and
KAVITHA RAMALINGAM
committed
Integrated Rebootbackend changes
1 parent 2ae8806 commit 9fe40e9

File tree

2 files changed

+208
-0
lines changed

2 files changed

+208
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
/*
3+
* This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT!
4+
*/
5+
6+
#ifndef __dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H
7+
#define __dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H
8+
9+
#include <dbus-c++/dbus.h>
10+
#include <cassert>
11+
12+
namespace org {
13+
namespace SONiC {
14+
namespace HostService {
15+
16+
class gnoi_reboot_proxy
17+
: public ::DBus::InterfaceProxy
18+
{
19+
public:
20+
21+
gnoi_reboot_proxy()
22+
: ::DBus::InterfaceProxy("org.SONiC.HostService.gnoi_reboot")
23+
{
24+
}
25+
26+
public:
27+
28+
/* properties exported by this interface */
29+
public:
30+
31+
/* methods exported by this interface,
32+
* this functions will invoke the corresponding methods on the remote objects
33+
*/
34+
void issue_reboot(const std::vector< std::string >& options, int32_t& argout0, std::string& argout1)
35+
{
36+
::DBus::CallMessage call;
37+
::DBus::MessageIter wi = call.writer();
38+
39+
wi << options;
40+
call.member("issue_reboot");
41+
::DBus::Message ret = invoke_method (call);
42+
::DBus::MessageIter ri = ret.reader();
43+
44+
ri >> argout0;
45+
ri >> argout1;
46+
}
47+
48+
void get_reboot_status(int32_t& argout0, std::string& argout1)
49+
{
50+
::DBus::CallMessage call;
51+
call.member("get_reboot_status");
52+
::DBus::Message ret = invoke_method (call);
53+
::DBus::MessageIter ri = ret.reader();
54+
55+
ri >> argout0;
56+
ri >> argout1;
57+
}
58+
59+
60+
public:
61+
62+
/* signal handlers for this interface
63+
*/
64+
65+
private:
66+
67+
/* unmarshalers (to unpack the DBus message before calling the actual signal handler)
68+
*/
69+
};
70+
71+
} } }
72+
#endif //__dbusxx__rebootbackend_gnoi_reboot_dbus_h__PROXY_MARSHAL_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#pragma once
2+
3+
#include <mutex>
4+
#include <thread>
5+
#include <unordered_set>
6+
#include <vector>
7+
8+
#include "dbconnector.h"
9+
#include "notificationproducer.h"
10+
#include "reboot_common.h"
11+
#include "reboot_interfaces.h"
12+
#include "redis_utils.h"
13+
#include "select.h"
14+
#include "selectableevent.h"
15+
#include "selectabletimer.h"
16+
#include "subscriberstatetable.h"
17+
#include "system/system.pb.h"
18+
19+
namespace rebootbackend {
20+
21+
// Holds a thread safe representation of the InitThread internal state.
22+
// Thread-safe: the expectation is one thread will write and multiple threads
23+
// will read.
24+
class InitThreadStatus {
25+
public:
26+
enum ThreadStatus {
27+
NOT_STARTED = 0,
28+
PENDING = 1,
29+
WAITING_FOR_REGISTRATION = 2,
30+
WAITING_FOR_RECONCILIATION = 3,
31+
WAITING_FOR_STATE_VERIFICATION = 4,
32+
WAITING_FOR_UNFREEZE = 5,
33+
FINALIZE = 6,
34+
DONE = 7,
35+
ERROR = 8,
36+
};
37+
38+
enum ErrorCondition {
39+
NO_ERROR = 0,
40+
UNKNOWN = 1,
41+
INTERNAL_ERROR = 2,
42+
REGISTRATION_FAILED = 3,
43+
RECONCILIATION_FAILED = 4,
44+
STATE_VERIFICATION_FAILED = 5,
45+
UNFREEZE_FAILED = 6,
46+
DETECTED_CRITICAL_STATE = 7,
47+
};
48+
49+
struct DetailedStatus {
50+
gnoi::system::RebootStatusResponse thread_state;
51+
InitThreadStatus::ThreadStatus detailed_thread_status =
52+
InitThreadStatus::ThreadStatus::NOT_STARTED;
53+
InitThreadStatus::ErrorCondition detailed_thread_error_condition =
54+
InitThreadStatus::ErrorCondition::NO_ERROR;
55+
};
56+
57+
InitThreadStatus() {
58+
m_status.detailed_thread_status = ThreadStatus::NOT_STARTED;
59+
m_status.detailed_thread_error_condition = ErrorCondition::NO_ERROR;
60+
61+
m_status.thread_state.set_active(false);
62+
m_status.thread_state.set_method(gnoi::system::RebootMethod::COLD);
63+
m_status.thread_state.mutable_status()->set_status(
64+
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_SUCCESS);
65+
m_status.thread_state.mutable_status()->set_message("");
66+
}
67+
68+
void set_start_status() {
69+
const std::lock_guard<std::mutex> lock(m_mutex);
70+
m_status.detailed_thread_status = ThreadStatus::PENDING;
71+
m_status.detailed_thread_error_condition = ErrorCondition::NO_ERROR;
72+
73+
m_status.thread_state.set_active(true);
74+
m_status.thread_state.set_method(gnoi::system::RebootMethod::NSF);
75+
m_status.thread_state.mutable_status()->set_status(
76+
gnoi::system::RebootStatus_Status::RebootStatus_Status_STATUS_UNKNOWN);
77+
m_status.thread_state.mutable_status()->set_message("");
78+
}
79+
80+
bool get_active(void) {
81+
const std::lock_guard<std::mutex> lock(m_mutex);
82+
return m_status.thread_state.active();
83+
}
84+
85+
void set_detailed_thread_status(ThreadStatus new_status) {
86+
const std::lock_guard<std::mutex> lock(m_mutex);
87+
if (m_status.thread_state.active()) {
88+
m_status.detailed_thread_status = new_status;
89+
}
90+
}
91+
92+
void set_success() {
93+
const std::lock_guard<std::mutex> lock(m_mutex);
94+
if (m_status.thread_state.active()) {
95+
m_status.detailed_thread_status = ThreadStatus::DONE;
96+
m_status.thread_state.mutable_status()->set_status(
97+
gnoi::system::RebootStatus_Status::
98+
RebootStatus_Status_STATUS_SUCCESS);
99+
}
100+
}
101+
102+
void set_error(ErrorCondition error_condition,
103+
const std::string &error_message) {
104+
const std::lock_guard<std::mutex> lock(m_mutex);
105+
if (m_status.thread_state.active()) {
106+
m_status.detailed_thread_status = ThreadStatus::ERROR;
107+
m_status.detailed_thread_error_condition = error_condition;
108+
m_status.thread_state.mutable_status()->set_status(
109+
gnoi::system::RebootStatus_Status::
110+
RebootStatus_Status_STATUS_FAILURE);
111+
m_status.thread_state.mutable_status()->set_message(error_message);
112+
}
113+
}
114+
115+
void set_inactive() {
116+
const std::lock_guard<std::mutex> lock(m_mutex);
117+
m_status.thread_state.set_active(false);
118+
}
119+
120+
DetailedStatus get_detailed_thread_status() {
121+
const std::lock_guard<std::mutex> lock(m_mutex);
122+
return m_status;
123+
}
124+
125+
gnoi::system::RebootStatusResponse get_response() {
126+
const std::lock_guard<std::mutex> lock(m_mutex);
127+
return m_status.thread_state;
128+
}
129+
130+
private:
131+
std::mutex m_mutex;
132+
DetailedStatus m_status;
133+
};
134+
135+
136+
} // namespace rebootbackend

0 commit comments

Comments
 (0)