Skip to content

Commit

Permalink
Handle shutdown event
Browse files Browse the repository at this point in the history
  • Loading branch information
topilski committed Feb 7, 2021
1 parent da4cee6 commit 7b04a9b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/client/events/network_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <fastotv/commands_info/runtime_channel_info.h>
#include <fastotv/commands_info/server_info.h>
#include <fastotv/commands_info/vods_info.h>
#include <fastotv/commands_info/shutdown_info.h>

#define CLIENT_DISCONNECT_EVENT static_cast<EventsType>(USER_EVENTS + 1)
#define CLIENT_CONNECT_EVENT static_cast<EventsType>(USER_EVENTS + 2)
Expand All @@ -40,6 +41,7 @@
#define CLIENT_CHAT_MESSAGE_SENT_EVENT static_cast<EventsType>(USER_EVENTS + 9)
#define CLIENT_CHAT_MESSAGE_RECEIVE_EVENT static_cast<EventsType>(USER_EVENTS + 10)
#define CLIENT_NOTIFICATION_TEXT_EVENT static_cast<EventsType>(USER_EVENTS + 11)
#define CLIENT_NOTIFICATION_SHUTDOWN_EVENT static_cast<EventsType>(USER_EVENTS + 12)

namespace fastotv {
namespace client {
Expand Down Expand Up @@ -71,6 +73,8 @@ typedef fastoplayer::gui::events::EventBase<CLIENT_RECEIVE_RUNTIME_CHANNELS_EVEN
ReceiveRuntimeChannelEvent;
typedef fastoplayer::gui::events::EventBase<CLIENT_NOTIFICATION_TEXT_EVENT, commands_info::NotificationTextInfo>
NotificationTextEvent;
typedef fastoplayer::gui::events::EventBase<CLIENT_NOTIFICATION_SHUTDOWN_EVENT, commands_info::ShutDownInfo>
NotificationShutdownEvent;

} // namespace events
} // namespace client
Expand Down
25 changes: 25 additions & 0 deletions src/client/inner/inner_tcp_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,29 @@ common::ErrnoError InnerTcpHandler::HandleRequestServerTextNotification(Client*
return common::make_errno_error_inval();
}

common::ErrnoError InnerTcpHandler::HandleRequestServerShutdownNotification(Client* client, const protocol::request_t* req) {
if (req->params) {
const char* params_ptr = req->params->c_str();
json_object* jnotify_text = json_tokener_parse(params_ptr);
if (!jnotify_text) {
return common::make_errno_error_inval();
}

commands_info::ShutDownInfo shutdown_info;
common::Error err_des = shutdown_info.DeSerialize(jnotify_text);
json_object_put(jnotify_text);
if (err_des) {
const std::string err_str = err_des->GetDescription();
return common::make_errno_error(err_str, EAGAIN);
}

fApp->PostEvent(new events::NotificationShutdownEvent(this, shutdown_info));
return client->NotificationTextOK(req->id);
}

return common::make_errno_error_inval();
}

common::ErrnoError InnerTcpHandler::HandleInnerDataReceived(Client* client, const std::string& input_command) {
protocol::request_t* req = nullptr;
protocol::response_t* resp = nullptr;
Expand Down Expand Up @@ -318,6 +341,8 @@ common::ErrnoError InnerTcpHandler::HandleRequestCommand(Client* client, const p
return HandleRequestServerClientInfo(sclient, req);
} else if (req->method == SERVER_TEXT_NOTIFICATION) {
return HandleRequestServerTextNotification(sclient, req);
} else if (req->method == SERVER_SHUTDOWN_NOTIFICATION) {
return HandleRequestServerShutdownNotification(sclient, req);
}

WARNING_LOG() << "Received unknown command: " << req->method;
Expand Down
1 change: 1 addition & 0 deletions src/client/inner/inner_tcp_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class InnerTcpHandler : public common::libev::IoLoopObserver {
common::ErrnoError HandleRequestServerPing(Client* client, const protocol::request_t* req);
common::ErrnoError HandleRequestServerClientInfo(Client* client, const protocol::request_t* req);
common::ErrnoError HandleRequestServerTextNotification(Client* client, const protocol::request_t* req);
common::ErrnoError HandleRequestServerShutdownNotification(Client* client, const protocol::request_t* req);

common::ErrnoError HandleResponceClientActivateDevice(Client* client, const protocol::response_t* resp);
common::ErrnoError HandleResponceClientLogin(Client* client, const protocol::response_t* resp);
Expand Down
9 changes: 9 additions & 0 deletions src/client/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Player::Player(const std::string& app_directory_absolute_path,
fApp->Subscribe(this, events::ReceiveChannelsEvent::EventType);
fApp->Subscribe(this, events::ReceiveRuntimeChannelEvent::EventType);
fApp->Subscribe(this, events::NotificationTextEvent::EventType);
fApp->Subscribe(this, events::NotificationShutdownEvent::EventType);

// descr window
description_label_ = new fastoplayer::gui::IconLabel(failed_color);
Expand Down Expand Up @@ -236,6 +237,9 @@ void Player::HandleEvent(event_t* event) {
} else if (event->GetEventType() == events::NotificationTextEvent::EventType) {
events::NotificationTextEvent* notify_text_event = static_cast<events::NotificationTextEvent*>(event);
HandleNotificationTextEvent(notify_text_event);
} else if (event->GetEventType() == events::NotificationShutdownEvent::EventType) {
events::NotificationShutdownEvent* notify_shut_event = static_cast<events::NotificationShutdownEvent*>(event);
HandleNotificationShutdownEvent(notify_shut_event);
}

base_class::HandleEvent(event);
Expand Down Expand Up @@ -564,6 +568,11 @@ void Player::HandleNotificationTextEvent(events::NotificationTextEvent* event) {
StartShowAdminMessage(inf.GetText(), inf.GetType(), inf.GetShowTime());
}

void Player::HandleNotificationShutdownEvent(events::NotificationShutdownEvent* event) {
const commands_info::ShutDownInfo inf = event->GetInfo();
Quit();
}

void Player::HandleKeyPressEvent(fastoplayer::gui::events::KeyPressEvent* event) {
if (programs_window_->IsActived()) {
return;
Expand Down
1 change: 1 addition & 0 deletions src/client/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Player : public fastoplayer::ISimplePlayer {
virtual void HandleReceiveChannelsEvent(events::ReceiveChannelsEvent* event);
virtual void HandleReceiveRuntimeChannelEvent(events::ReceiveRuntimeChannelEvent* event);
virtual void HandleNotificationTextEvent(events::NotificationTextEvent* event);
virtual void HandleNotificationShutdownEvent(events::NotificationShutdownEvent *event);

void HandleKeyPressEvent(fastoplayer::gui::events::KeyPressEvent* event) override;
void HandleLircPressEvent(fastoplayer::gui::events::LircPressEvent* event) override;
Expand Down

0 comments on commit 7b04a9b

Please sign in to comment.