[gst-debugger/refactor-v1.0] refactor: hooks refactoring
- From: Marcin Kolny <mkolny src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gst-debugger/refactor-v1.0] refactor: hooks refactoring
- Date: Sun, 4 Oct 2015 12:33:55 +0000 (UTC)
commit 500fe0b1a1a4ea17e207e52249fbf05b6ca0b251
Author: Marcin Kolny <marcin kolny gmail com>
Date: Sun Oct 4 13:28:26 2015 +0200
refactor: hooks refactoring
src/common/gstdebugger.proto | 87 ++++++++++++-----------
src/debugserver/gstdebugserver.c | 51 ++++++++------
src/debugserver/gstdebugservermessage.c | 4 +-
src/debugserver/gstdebugservermessage.h | 2 +-
src/gst-debugger/controller/command_factory.cpp | 68 ++++++++++-------
src/gst-debugger/controller/command_factory.h | 3 +-
src/gst-debugger/modules/buffer_module.cpp | 6 +-
src/gst-debugger/modules/event_module.cpp | 6 +-
src/gst-debugger/modules/log_module.cpp | 6 +-
src/gst-debugger/modules/message_module.cpp | 6 +-
src/gst-debugger/modules/query_module.cpp | 6 +-
11 files changed, 135 insertions(+), 110 deletions(-)
---
diff --git a/src/common/gstdebugger.proto b/src/common/gstdebugger.proto
index e0dfd8c..390ff81 100644
--- a/src/common/gstdebugger.proto
+++ b/src/common/gstdebugger.proto
@@ -33,11 +33,6 @@ message PropertyRequest {
required string object = 2;
}
-message MessageRequest {
- required Action action = 1;
- required int32 type = 2;
-}
-
message MessageInfo {
required int32 type = 1;
required uint64 timestamp = 2;
@@ -46,35 +41,6 @@ message MessageInfo {
required bytes structure_data = 5;
}
-message LogRequest {
- required Action action = 1;
- required int32 level = 2;
- optional string category = 3;
-}
-
-message QueryHookRequest {
- required int32 type = 1;
-}
-
-message BufferHookRequest {
- required bool send_data = 1;
-}
-
-message EventHookRequest {
- required int32 type = 1;
-}
-
-message PadHookRequest {
- required Action action = 1;
- optional string pad = 2;
-
- oneof pad_hook_type {
- QueryHookRequest query = 3;
- BufferHookRequest buffer = 4;
- EventHookRequest event = 5;
- }
-}
-
message EventInfo {
required int32 type = 1;
required uint64 timestamp = 2;
@@ -111,17 +77,56 @@ message TypeDescriptionRequest {
required Type type = 2;
}
+message QueryHookRequest {
+ required int32 type = 1;
+}
+
+message BufferHookRequest {
+ required bool send_data = 1;
+}
+
+message EventHookRequest {
+ required int32 type = 1;
+}
+
+message PadHookRequest {
+ optional string pad = 1;
+
+ oneof pad_hook_type {
+ QueryHookRequest query = 2;
+ BufferHookRequest buffer = 3;
+ EventHookRequest event = 4;
+ }
+}
+
+message LogRequest {
+ required int32 level = 1;
+ optional string category = 2;
+}
+
+message MessageRequest {
+ required int32 type = 1;
+}
+
+message HookRequest {
+ required Action action = 1;
+
+ oneof hook_type {
+ MessageRequest message = 2;
+ LogRequest log = 3;
+ PadHookRequest pad_hook = 4;
+ }
+}
+
message Command {
oneof command_type {
TypeDescriptionRequest type_description = 1;
bool debug_categories_list = 2;
- MessageRequest message = 3;
- LogRequest log = 4;
- PadHookRequest pad_hook = 5;
- string log_threshold = 6;
- bool entire_topology = 7;
- PropertyRequest property = 8;
- PropertyValue property_set = 9;
+ HookRequest hook_request = 3;
+ string log_threshold = 4;
+ bool entire_topology = 5;
+ PropertyRequest property = 6;
+ PropertyValue property_set = 7;
}
}
diff --git a/src/debugserver/gstdebugserver.c b/src/debugserver/gstdebugserver.c
index 9da43f4..be5b0fb 100644
--- a/src/debugserver/gstdebugserver.c
+++ b/src/debugserver/gstdebugserver.c
@@ -346,13 +346,14 @@ gst_debugserver_tracer_get_property (GObject * object, guint prop_id,
static void gst_debugserver_process_pad_hook (GstDebugserverTracer * self, GstDebugger__Command * command,
TcpClient * client)
{
- GstDebugger__PadHookRequest *request = command->pad_hook;
+ GstDebugger__PadHookRequest *request = command->hook_request->pad_hook;
GstPad *pad = gst_utils_get_pad_from_path (GST_ELEMENT_CAST (self->pipeline), request->pad);
+ gboolean add_hook = command->hook_request->action == GST_DEBUGGER__ACTION__ADD;
switch (request->pad_hook_type_case)
{
case GST_DEBUGGER__PAD_HOOK_REQUEST__PAD_HOOK_TYPE_EVENT:
- if (gst_debugserver_qe_set_hook (self->event, request->action == GST_DEBUGGER__ACTION__ADD,
request->event->type, pad, request->pad, client)) {
+ if (gst_debugserver_qe_set_hook (self->event, add_hook, request->event->type, pad, request->pad,
client)) {
GstDebugger__GStreamerData data = GST_DEBUGGER__GSTREAMER_DATA__INIT;
data.confirmation = command;
data.info_type_case = GST_DEBUGGER__GSTREAMER_DATA__INFO_TYPE_CONFIRMATION;
@@ -360,7 +361,7 @@ static void gst_debugserver_process_pad_hook (GstDebugserverTracer * self, GstDe
}
break;
case GST_DEBUGGER__PAD_HOOK_REQUEST__PAD_HOOK_TYPE_QUERY:
- if (gst_debugserver_qe_set_hook (self->query, request->action == GST_DEBUGGER__ACTION__ADD,
request->query->type, pad, request->pad, client)) {
+ if (gst_debugserver_qe_set_hook (self->query, add_hook, request->query->type, pad, request->pad,
client)) {
GstDebugger__GStreamerData data = GST_DEBUGGER__GSTREAMER_DATA__INIT;
data.confirmation = command;
data.info_type_case = GST_DEBUGGER__GSTREAMER_DATA__INFO_TYPE_CONFIRMATION;
@@ -368,7 +369,7 @@ static void gst_debugserver_process_pad_hook (GstDebugserverTracer * self, GstDe
}
break;
case GST_DEBUGGER__PAD_HOOK_REQUEST__PAD_HOOK_TYPE_BUFFER:
- if (gst_debugserver_buffer_set_hook (self->buffer, request->action == GST_DEBUGGER__ACTION__ADD,
request->buffer->send_data, pad,
+ if (gst_debugserver_buffer_set_hook (self->buffer, add_hook, request->buffer->send_data, pad,
request->pad, client)) {
GstDebugger__GStreamerData data = GST_DEBUGGER__GSTREAMER_DATA__INIT;
data.confirmation = command;
@@ -424,26 +425,32 @@ static void gst_debugserver_command_handler (GstDebugger__Command * command,
case GST_DEBUGGER__COMMAND__COMMAND_TYPE_LOG_THRESHOLD:
gst_debugserver_log_set_threshold (command->log_threshold);
break;
- case GST_DEBUGGER__COMMAND__COMMAND_TYPE_MESSAGE:
- if (gst_debugserver_message_set_hook (self->message, client, command->message)) {
- GstDebugger__GStreamerData data = GST_DEBUGGER__GSTREAMER_DATA__INIT;
- data.confirmation = command;
- data.info_type_case = GST_DEBUGGER__GSTREAMER_DATA__INFO_TYPE_CONFIRMATION;
- gst_debugserver_tcp_send_packet (self->tcp_server, client, &data);
- }
- break;
- case GST_DEBUGGER__COMMAND__COMMAND_TYPE_LOG:
- if (gst_debugserver_log_set_hook (self->log, command->log->action == GST_DEBUGGER__ACTION__ADD,
- command->log->level, command->log->category, client)) {
- GstDebugger__GStreamerData data = GST_DEBUGGER__GSTREAMER_DATA__INIT;
- data.confirmation = command;
- data.info_type_case = GST_DEBUGGER__GSTREAMER_DATA__INFO_TYPE_CONFIRMATION;
- gst_debugserver_tcp_send_packet (self->tcp_server, client, &data);
+ case GST_DEBUGGER__COMMAND__COMMAND_TYPE_HOOK_REQUEST:
+ {
+ switch (command->hook_request->hook_type_case) {
+ case GST_DEBUGGER__HOOK_REQUEST__HOOK_TYPE_MESSAGE:
+ if (gst_debugserver_message_set_hook (self->message, client, command->hook_request->action ==
GST_DEBUGGER__ACTION__ADD, command->hook_request->message)) {
+ GstDebugger__GStreamerData data = GST_DEBUGGER__GSTREAMER_DATA__INIT;
+ data.confirmation = command;
+ data.info_type_case = GST_DEBUGGER__GSTREAMER_DATA__INFO_TYPE_CONFIRMATION;
+ gst_debugserver_tcp_send_packet (self->tcp_server, client, &data);
+ }
+ break;
+ case GST_DEBUGGER__HOOK_REQUEST__HOOK_TYPE_LOG:
+ if (gst_debugserver_log_set_hook (self->log, command->hook_request->action ==
GST_DEBUGGER__ACTION__ADD,
+ command->hook_request->log->level, command->hook_request->log->category, client)) {
+ GstDebugger__GStreamerData data = GST_DEBUGGER__GSTREAMER_DATA__INIT;
+ data.confirmation = command;
+ data.info_type_case = GST_DEBUGGER__GSTREAMER_DATA__INFO_TYPE_CONFIRMATION;
+ gst_debugserver_tcp_send_packet (self->tcp_server, client, &data);
+ }
+ break;
+ case GST_DEBUGGER__HOOK_REQUEST__HOOK_TYPE_PAD_HOOK:
+ gst_debugserver_process_pad_hook (self, command, client);
+ break;
}
break;
- case GST_DEBUGGER__COMMAND__COMMAND_TYPE_PAD_HOOK:
- gst_debugserver_process_pad_hook (self, command, client);
- break;
+ }
case GST_DEBUGGER__COMMAND__COMMAND_TYPE_ENTIRE_TOPOLOGY:
gst_debugserver_topology_send_entire_topology (GST_BIN_CAST (self->pipeline), self->tcp_server, client);
break;
diff --git a/src/debugserver/gstdebugservermessage.c b/src/debugserver/gstdebugservermessage.c
index cac9f8b..40e0543 100644
--- a/src/debugserver/gstdebugservermessage.c
+++ b/src/debugserver/gstdebugservermessage.c
@@ -64,9 +64,9 @@ void gst_debugserver_message_clean (GstDebugserverMessage * msg)
}
gboolean gst_debugserver_message_set_hook (GstDebugserverMessage * msg,
- TcpClient * client, GstDebugger__MessageRequest * request)
+ TcpClient * client, gboolean enable, GstDebugger__MessageRequest * request)
{
- if (request->action == GST_DEBUGGER__ACTION__ADD) {
+ if (enable) {
return gst_debugserver_hooks_add_hook (&msg->hooks, GINT_TO_POINTER (request->type), client);
} else {
return gst_debugserver_hooks_remove_hook (&msg->hooks, GINT_TO_POINTER (request->type), client);
diff --git a/src/debugserver/gstdebugservermessage.h b/src/debugserver/gstdebugservermessage.h
index 0f50542..c6a6d04 100644
--- a/src/debugserver/gstdebugservermessage.h
+++ b/src/debugserver/gstdebugservermessage.h
@@ -40,7 +40,7 @@ void gst_debugserver_message_free (GstDebugserverMessage * msg);
void gst_debugserver_message_clean (GstDebugserverMessage * msg);
gboolean gst_debugserver_message_set_hook (GstDebugserverMessage * msg,
- TcpClient * client, GstDebugger__MessageRequest * request);
+ TcpClient * client, gboolean enable, GstDebugger__MessageRequest * request);
void gst_debugserver_message_remove_client (GstDebugserverMessage * msg,
TcpClient * client);
diff --git a/src/gst-debugger/controller/command_factory.cpp b/src/gst-debugger/controller/command_factory.cpp
index e99dda5..f2c5be5 100644
--- a/src/gst-debugger/controller/command_factory.cpp
+++ b/src/gst-debugger/controller/command_factory.cpp
@@ -20,7 +20,6 @@ void CommandFactory::send_property_request_command(const std::string &element_pa
client->send_command(cmd);
}
-
void CommandFactory::send_request_entire_topology_command()
{
GstDebugger::Command cmd;
@@ -29,57 +28,67 @@ void CommandFactory::send_request_entire_topology_command()
client->send_command(cmd);
}
-GstDebugger::PadHookRequest* CommandFactory::create_pad_hook_request(bool enable, const std::string
&pad_path)
+GstDebugger::HookRequest* CommandFactory::create_pad_hook_request(bool enable, const std::string &pad_path)
+{
+ auto *pad_request = new GstDebugger::PadHookRequest();
+ pad_request->set_pad(pad_path);
+ auto hook_request = create_hook_request(enable);
+ hook_request->set_allocated_pad_hook(pad_request);
+ return hook_request;
+}
+
+GstDebugger::HookRequest* CommandFactory::create_hook_request(bool enable)
{
- auto *request = new GstDebugger::PadHookRequest();
- request->set_pad(pad_path);
+ auto *request = new GstDebugger::HookRequest();
request->set_action(enable ? GstDebugger::ADD : GstDebugger::REMOVE);
return request;
}
void CommandFactory::send_query_request_command(bool enable, const std::string &pad_path, int type)
{
- auto request = create_pad_hook_request(enable, pad_path);
- auto *ev_request = new GstDebugger::QueryHookRequest();
- ev_request->set_type(type);
- request->set_allocated_query(ev_request);
+ auto *request = create_pad_hook_request(enable, pad_path);
+ request->mutable_pad_hook()->mutable_query()->set_type(type);
+
GstDebugger::Command cmd;
- cmd.set_allocated_pad_hook(request);
+ cmd.set_allocated_hook_request(request);
client->send_command(cmd);
}
void CommandFactory::send_event_request_command(bool enable, const std::string &pad_path, int type)
{
- auto request = create_pad_hook_request(enable, pad_path);
- GstDebugger::EventHookRequest *ev_request = new GstDebugger::EventHookRequest();
- ev_request->set_type(type);
- request->set_allocated_event(ev_request);
+ auto *request = create_pad_hook_request(enable, pad_path);
+ request->mutable_pad_hook()->mutable_event()->set_type(type);
+
GstDebugger::Command cmd;
- cmd.set_allocated_pad_hook(request);
+ cmd.set_allocated_hook_request(request);
client->send_command(cmd);
}
void CommandFactory::send_buffer_request_command(bool enable, const std::string &pad_path, bool send_data)
{
- auto request = create_pad_hook_request(enable, pad_path);
- auto *buf_request = new GstDebugger::BufferHookRequest();
- buf_request->set_send_data(send_data);
- request->set_allocated_buffer(buf_request);
+ auto *request = create_pad_hook_request(enable, pad_path);
+ request->mutable_pad_hook()->mutable_buffer()->set_send_data(send_data);
+
GstDebugger::Command cmd;
- cmd.set_allocated_pad_hook(request);
+ cmd.set_allocated_hook_request(request);
+
+ client->send_command(cmd);
client->send_command(cmd);
}
void CommandFactory::send_message_request_command(int message_type, bool enable)
{
- GstDebugger::MessageRequest *request = new GstDebugger::MessageRequest();
- request->set_type(message_type);
- request->set_action(enable ? GstDebugger::ADD : GstDebugger::REMOVE);
+ auto msg_request = new GstDebugger::MessageRequest();
+ msg_request->set_type(message_type);
+
+ auto hook_request = create_hook_request(enable);
+ hook_request->set_allocated_message(msg_request);
+
GstDebugger::Command cmd;
- cmd.set_allocated_message(request);
+ cmd.set_allocated_hook_request(hook_request);
client->send_command(cmd);
}
@@ -94,12 +103,15 @@ void CommandFactory::send_set_threshold_command(const std::string &threshold_lis
void CommandFactory::send_set_log_hook_command(bool enable, const std::string &category, int log_level)
{
+ auto log_request = new GstDebugger::LogRequest();
+ log_request->set_level(log_level);
+ log_request->set_category(category);
+
+ auto hook_request = create_hook_request(enable);
+ hook_request->set_allocated_log(log_request);
+
GstDebugger::Command cmd;
- GstDebugger::LogRequest *request = new GstDebugger::LogRequest();
- request->set_level(log_level);
- request->set_action(enable ? GstDebugger::ADD : GstDebugger::REMOVE);
- request->set_category(category);
- cmd.set_allocated_log(request);
+ cmd.set_allocated_hook_request(hook_request);
client->send_command(cmd);
}
diff --git a/src/gst-debugger/controller/command_factory.h b/src/gst-debugger/controller/command_factory.h
index 941d1f7..66397c7 100644
--- a/src/gst-debugger/controller/command_factory.h
+++ b/src/gst-debugger/controller/command_factory.h
@@ -16,7 +16,8 @@
class CommandFactory : public virtual BaseController
{
- static GstDebugger::PadHookRequest* create_pad_hook_request(bool enable, const std::string &pad_path);
+ static GstDebugger::HookRequest* create_pad_hook_request(bool enable, const std::string &pad_path);
+ static GstDebugger::HookRequest* create_hook_request(bool enable);
public:
void send_property_request_command(const std::string &element_path, const std::string &property_name);
diff --git a/src/gst-debugger/modules/buffer_module.cpp b/src/gst-debugger/modules/buffer_module.cpp
index 94e8f6d..d302678 100644
--- a/src/gst-debugger/modules/buffer_module.cpp
+++ b/src/gst-debugger/modules/buffer_module.cpp
@@ -98,11 +98,11 @@ void BufferControlModule::remove_hook(const Gtk::TreeModel::Row& row)
void BufferControlModule::confirmation_received(GstDebugger::Command* cmd)
{
- if (!cmd->has_pad_hook() || !cmd->pad_hook().has_buffer())
+ if (!cmd->has_hook_request() || !cmd->hook_request().has_pad_hook() ||
!cmd->hook_request().pad_hook().has_buffer())
return;
- auto confirmation = cmd->pad_hook();
- if (confirmation.action() == GstDebugger::ADD)
+ auto confirmation = cmd->hook_request().pad_hook();
+ if (cmd->hook_request().action() == GstDebugger::ADD)
{
Gtk::TreeModel::Row row = *(hooks_model->append());
row[hooks_model_columns.str1] = confirmation.pad();
diff --git a/src/gst-debugger/modules/event_module.cpp b/src/gst-debugger/modules/event_module.cpp
index 1703e6d..28cd766 100644
--- a/src/gst-debugger/modules/event_module.cpp
+++ b/src/gst-debugger/modules/event_module.cpp
@@ -61,11 +61,11 @@ void EventControlModule::remove_hook(const Gtk::TreeModel::Row& row)
void EventControlModule::confirmation_received(GstDebugger::Command* cmd)
{
- if (!cmd->has_pad_hook() || !cmd->pad_hook().has_event())
+ if (!cmd->has_hook_request() || !cmd->hook_request().has_pad_hook() ||
!cmd->hook_request().pad_hook().has_event())
return;
- auto confirmation = cmd->pad_hook();
- if (confirmation.action() == GstDebugger::ADD)
+ auto confirmation = cmd->hook_request().pad_hook();
+ if (cmd->hook_request().action() == GstDebugger::ADD)
{
Gtk::TreeModel::Row row = *(hooks_model->append());
row[hooks_model_columns.str1] =
Gst::Enums::get_name(static_cast<Gst::EventType>(confirmation.event().type()));
diff --git a/src/gst-debugger/modules/log_module.cpp b/src/gst-debugger/modules/log_module.cpp
index be8ce1f..66366d7 100644
--- a/src/gst-debugger/modules/log_module.cpp
+++ b/src/gst-debugger/modules/log_module.cpp
@@ -97,11 +97,11 @@ void LogControlModule::remove_hook(const Gtk::TreeModel::Row& row)
void LogControlModule::confirmation_received(GstDebugger::Command* cmd)
{
- if (!cmd->has_log())
+ if (!cmd->has_hook_request() || !cmd->hook_request().has_log())
return;
- auto confirmation = cmd->log();
- if (confirmation.action() == GstDebugger::ADD)
+ auto confirmation = cmd->hook_request().log();
+ if (cmd->hook_request().action() == GstDebugger::ADD)
{
Gtk::TreeModel::Row row = *(hooks_model->append());
row[hooks_model_columns.str1] = gst_debug_level_get_name
(static_cast<GstDebugLevel>(confirmation.level()));
diff --git a/src/gst-debugger/modules/message_module.cpp b/src/gst-debugger/modules/message_module.cpp
index b1fd300..e118d7e 100644
--- a/src/gst-debugger/modules/message_module.cpp
+++ b/src/gst-debugger/modules/message_module.cpp
@@ -96,11 +96,11 @@ void MessageControlModule::set_controller(const std::shared_ptr<Controller> &con
void MessageControlModule::confirmation_received(GstDebugger::Command* cmd)
{
- if (!cmd->has_message())
+ if (!cmd->has_hook_request() || !cmd->hook_request().has_message())
return;
- auto confirmation = cmd->message();
- if (confirmation.action() == GstDebugger::ADD)
+ auto confirmation = cmd->hook_request().message();
+ if (cmd->hook_request().action() == GstDebugger::ADD)
{
Gtk::TreeModel::Row row = *(hooks_model->append());
row[hooks_model_columns.str1] =
Gst::Enums::get_name(static_cast<Gst::MessageType>(confirmation.type()));
diff --git a/src/gst-debugger/modules/query_module.cpp b/src/gst-debugger/modules/query_module.cpp
index a5ae619..ea4287d 100644
--- a/src/gst-debugger/modules/query_module.cpp
+++ b/src/gst-debugger/modules/query_module.cpp
@@ -55,11 +55,11 @@ void QueryControlModule::remove_hook(const Gtk::TreeModel::Row& row)
void QueryControlModule::confirmation_received(GstDebugger::Command* cmd)
{
- if (!cmd->has_pad_hook() || !cmd->pad_hook().has_query())
+ if (!cmd->has_hook_request() || !cmd->hook_request().has_pad_hook() ||
!cmd->hook_request().pad_hook().has_query())
return;
- auto confirmation = cmd->pad_hook();
- if (confirmation.action() == GstDebugger::ADD)
+ auto confirmation = cmd->hook_request().pad_hook();
+ if (cmd->hook_request().action() == GstDebugger::ADD)
{
Gtk::TreeModel::Row row = *(hooks_model->append());
row[hooks_model_columns.str1] =
Gst::Enums::get_name(static_cast<Gst::QueryType>(confirmation.query().type()));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]