-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7c6203
commit b393ce2
Showing
14 changed files
with
1,195 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?ignore | ||
XML representation of dbus interface created by: sonic-host-services/host_modules/gnoi_reboot.py | ||
|
||
XML generated on switch by executing: | ||
dbus-send --system --type=method_call --print-reply --dest=org.SONiC.HostService.gnoi_reboot /org/SONiC/HostService/gnoi_reboot org.freedesktop.DBus.Introspectable.Introspect | ||
|
||
C++ header file generated by: | ||
sudo apt-get install libdbus-c++-dev | ||
dbusxx-xml2cpp ./gnoi_reboot.xml --proxy=gnoi_reboot_dbus.h | ||
?> | ||
|
||
<node name="/org/SONiC/HostService/gnoi_reboot"> | ||
<interface name="org.freedesktop.DBus.Introspectable"> | ||
<method name="Introspect"> | ||
<arg direction="out" type="s" /> | ||
</method> | ||
</interface> | ||
<interface name="org.SONiC.HostService.gnoi_reboot"> | ||
<method name="issue_reboot"> | ||
<arg direction="in" type="as" name="options" /> | ||
<arg direction="out" type="i" /> | ||
<arg direction="out" type="s" /> | ||
</method> | ||
<method name="get_reboot_status"> | ||
<arg direction="out" type="i" /> | ||
<arg direction="out" type="s" /> | ||
</method> | ||
</interface> | ||
</node> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "interfaces.h" | ||
|
||
#include <dbus-c++/dbus.h> // DBus | ||
|
||
//#include "component_state_helper.h" | ||
#include "reboot_interfaces.h" | ||
|
||
constexpr char kRebootBusName[] = "org.SONiC.HostService.gnoi_reboot"; | ||
constexpr char kRebootPath[] = "/org/SONiC/HostService/gnoi_reboot"; | ||
|
||
constexpr char kContainerShutdownBusName[] = "org.SONiC.HostService.gnoi_container_shutdown"; | ||
constexpr char kContainerShutdownPath[] = "/org/SONiC/HostService/gnoi_container_shutdown"; | ||
|
||
// DBus::BusDispatcher dispatcher; | ||
DBus::Connection& HostServiceDbus::getConnection(void) { | ||
static DBus::Connection* connPtr = nullptr; | ||
if (connPtr == nullptr) { | ||
static DBus::BusDispatcher dispatcher; | ||
DBus::default_dispatcher = &dispatcher; | ||
|
||
static DBus::Connection conn = DBus::Connection::SystemBus(); | ||
connPtr = &conn; | ||
} | ||
return *connPtr; | ||
} | ||
|
||
DbusInterface::DbusResponse HostServiceDbus::Reboot( | ||
const std::string& json_reboot_request) { | ||
int32_t status; | ||
std::string ret_string; | ||
std::vector<std::string> options; | ||
options.push_back(json_reboot_request); | ||
|
||
GnoiDbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath); | ||
try { | ||
reboot_client.issue_reboot(options, status, ret_string); | ||
} catch (DBus::Error& ex) { | ||
return DbusResponse{ | ||
DbusStatus::DBUS_FAIL, | ||
"HostServiceDbus::Reboot: failed to call reboot host service"}; | ||
} | ||
|
||
// gnoi_reboot.py returns 0 for success, 1 for failure | ||
if (status == 0) { | ||
// Successful reboot response is an empty string. | ||
return DbusResponse{DbusStatus::DBUS_SUCCESS, ""}; | ||
} | ||
return DbusResponse{DbusStatus::DBUS_FAIL, ret_string}; | ||
} | ||
|
||
DbusInterface::DbusResponse HostServiceDbus::RebootStatus( | ||
const std::string& json_status_request) { | ||
int32_t status; | ||
std::string ret_string; | ||
|
||
GnoiDbusReboot reboot_client(getConnection(), kRebootBusName, kRebootPath); | ||
try { | ||
reboot_client.get_reboot_status(status, ret_string); | ||
} catch (DBus::Error& ex) { | ||
return DbusResponse{ | ||
DbusStatus::DBUS_FAIL, | ||
"HostServiceDbus::RebootStatus: failed to call reboot status " | ||
"host service"}; | ||
} | ||
|
||
// gnoi_reboot.py returns 0 for success, 1 for failure | ||
if (status == 0) { | ||
return DbusResponse{DbusStatus::DBUS_SUCCESS, ret_string}; | ||
} | ||
return DbusResponse{DbusStatus::DBUS_FAIL, ret_string}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include <dbus-c++/dbus.h> | ||
|
||
#include <string> | ||
|
||
#include "gnoi_reboot_dbus.h" // auto generated gnoi_reboot_proxy | ||
#include "reboot_interfaces.h" | ||
|
||
class GnoiDbusReboot : public org::SONiC::HostService::gnoi_reboot_proxy, | ||
public DBus::IntrospectableProxy, | ||
public DBus::ObjectProxy { | ||
public: | ||
GnoiDbusReboot(DBus::Connection& connection, const char* dbus_bus_name_p, | ||
const char* dbus_obj_name_p) | ||
: DBus::ObjectProxy(connection, dbus_obj_name_p, dbus_bus_name_p) {} | ||
}; | ||
|
||
class HostServiceDbus : public DbusInterface { | ||
public: | ||
DbusInterface::DbusResponse Reboot( | ||
const std::string& json_reboot_request) override; | ||
DbusInterface::DbusResponse RebootStatus( | ||
const std::string& json_status_request) override; | ||
|
||
private: | ||
static DBus::Connection& getConnection(void); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "reboot_common.h" | ||
|
||
#include <time.h> | ||
|
||
namespace rebootbackend { | ||
|
||
timespec milliseconds_to_timespec(uint64_t time_ms) { | ||
timespec l_timespec; | ||
l_timespec.tv_sec = time_ms / ONE_THOUSAND; | ||
l_timespec.tv_nsec = (time_ms % ONE_THOUSAND) * ONE_THOUSAND * ONE_THOUSAND; | ||
return l_timespec; | ||
} | ||
|
||
} // namespace rebootbackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include <time.h> | ||
|
||
#include "status_code_util.h" | ||
|
||
namespace rebootbackend { | ||
|
||
#define ONE_THOUSAND (1000) | ||
|
||
extern bool sigterm_requested; | ||
|
||
extern timespec milliseconds_to_timespec(uint64_t time_ms); | ||
|
||
struct NotificationResponse { | ||
swss::StatusCode status; | ||
std::string json_string; | ||
}; | ||
|
||
} // namespace rebootbackend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
class DbusInterface { | ||
public: | ||
enum class DbusStatus { | ||
DBUS_SUCCESS, | ||
DBUS_FAIL, | ||
}; | ||
|
||
struct DbusResponse { | ||
DbusStatus status; | ||
std::string json_string; | ||
}; | ||
|
||
virtual ~DbusInterface() = default; | ||
virtual DbusResponse Reboot(const std::string& json_reboot_request) = 0; | ||
virtual DbusResponse RebootStatus(const std::string& json_status_request) = 0; | ||
}; | ||
|
Oops, something went wrong.