From: Uwe Hermann Date: Wed, 9 Jan 2019 00:42:46 +0000 (+0100) Subject: Various whitespace/consistency/cosmetic fixes. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=31b3babdb6de8e5aa887049faf519d1fb4f9924a;p=libsigrokflow.git Various whitespace/consistency/cosmetic fixes. --- diff --git a/include/libsigrokflow/libsigrokflow.hpp b/include/libsigrokflow/libsigrokflow.hpp index 944c99c..8154951 100644 --- a/include/libsigrokflow/libsigrokflow.hpp +++ b/include/libsigrokflow/libsigrokflow.hpp @@ -46,173 +46,177 @@ void deinit(); class Block { - /* Config API etc goes here */ + /* Config API etc. goes here. */ }; class Sink : - public Gst::BaseSink + public Gst::BaseSink { protected: - explicit Sink(GstBaseSink *gobj); + explicit Sink(GstBaseSink *gobj); }; class Device : - public Gst::Element + public Gst::Element { - /* Operations specific to hardware devices go here */ + /* Operations specific to hardware devices go here. */ protected: - explicit Device(GstElement *gobj); + explicit Device(GstElement *gobj); }; class CaptureDevice : - public Device + public Device { - /* Operations specific to capture (source) devices go here */ + /* Operations specific to capture (source) devices go here. */ protected: - explicit CaptureDevice(GstElement *gobj); + explicit CaptureDevice(GstElement *gobj); }; #ifdef HAVE_LIBSIGROKCXX class LegacyCaptureDevice : - public CaptureDevice + public CaptureDevice { public: - /* Create from libsigrok device object */ - static Glib::RefPtr create( - shared_ptr libsigrok_device); + /* Create from libsigrok device object. */ + static Glib::RefPtr create( + shared_ptr libsigrok_device); - /* Retrieve libsigrok device object */ - shared_ptr libsigrok_device(); + /* Retrieve libsigrok device object. */ + shared_ptr libsigrok_device(); - /* Override state change */ - Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition); + /* Override state change. */ + Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition); - /* Gst class init */ - static void class_init(Gst::ElementClass *klass); + /* Gst class init. */ + static void class_init(Gst::ElementClass *klass); - /* Register class with plugin */ - static bool register_element(Glib::RefPtr plugin); + /* Register class with plugin. */ + static bool register_element(Glib::RefPtr plugin); + + /* Constructor used by element factory. */ + explicit LegacyCaptureDevice(GstElement *gobj); - /* Construcor used by element factory */ - explicit LegacyCaptureDevice(GstElement *gobj); private: - shared_ptr _libsigrok_device; - Glib::RefPtr _src_pad; - Glib::Threads::RecMutex _mutex; - Glib::RefPtr _task; - shared_ptr _session; - - void _datafeed_callback(shared_ptr device, - shared_ptr packet); - void _run(); + shared_ptr _libsigrok_device; + Glib::RefPtr _src_pad; + Glib::Threads::RecMutex _mutex; + Glib::RefPtr _task; + shared_ptr _session; + + void _datafeed_callback(shared_ptr device, + shared_ptr packet); + void _run(); }; class LegacyInput : - public Gst::Element + public Gst::Element { public: - /* Create from libsigrok input */ - static Glib::RefPtr create( - shared_ptr format, - map options = map()); + /* Create from libsigrok input. */ + static Glib::RefPtr create( + shared_ptr format, + map options = map()); + + /* Override start. */ + bool start_vfunc(); - /* Override start */ - bool start_vfunc(); + /* Chain function. */ + Gst::FlowReturn chain(const Glib::RefPtr &pad, + const Glib::RefPtr &buf); - /* Chain function */ - Gst::FlowReturn chain(const Glib::RefPtr &pad, - const Glib::RefPtr &buf); + /* Override stop. */ + bool stop_vfunc(); - /* Override stop */ - bool stop_vfunc(); + /* Gst class init. */ + static void class_init(Gst::ElementClass *klass); - /* Gst class init */ - static void class_init(Gst::ElementClass *klass); + /* Register class with plugin. */ + static bool register_element(Glib::RefPtr plugin); - /* Register class with plugin */ - static bool register_element(Glib::RefPtr plugin); + /* Constructor used by element factory. */ + explicit LegacyInput(GstElement *gobj); - /* Construcor used by element factory */ - explicit LegacyInput(GstElement *gobj); private: - shared_ptr _libsigrok_input_format; - shared_ptr _libsigrok_input; - shared_ptr _session; - map _options; - Glib::RefPtr _sink_pad; - Glib::RefPtr _src_pad; - - void _datafeed_callback(shared_ptr device, - shared_ptr packet); + shared_ptr _libsigrok_input_format; + shared_ptr _libsigrok_input; + shared_ptr _session; + map _options; + Glib::RefPtr _sink_pad; + Glib::RefPtr _src_pad; + + void _datafeed_callback(shared_ptr device, + shared_ptr packet); }; class LegacyOutput : - public Sink + public Sink { public: - /* Create from libsigrok output object */ - static Glib::RefPtr create( - shared_ptr libsigrok_output_format, - shared_ptr libsigrok_device, - map options = map()); + /* Create from libsigrok output object. */ + static Glib::RefPtr create( + shared_ptr libsigrok_output_format, + shared_ptr libsigrok_device, + map options = map()); - /* Override start */ - bool start_vfunc(); + /* Override start. */ + bool start_vfunc().; - /* Override render */ - Gst::FlowReturn render_vfunc(const Glib::RefPtr &buffer); + /* Override render. */ + Gst::FlowReturn render_vfunc(const Glib::RefPtr &buffer); - /* Override stop */ - bool stop_vfunc(); + /* Override stop. */ + bool stop_vfunc(); - /* Gst class init */ - static void class_init(Gst::ElementClass *klass); + /* Gst class init. */ + static void class_init(Gst::ElementClass *klass); - /* Register class with plugin */ - static bool register_element(Glib::RefPtr plugin); + /* Register class with plugin. */ + static bool register_element(Glib::RefPtr plugin); + + /* Constructor used by element factory. */ + explicit LegacyOutput(GstBaseSink *gobj); - /* Constructor used by element factory */ - explicit LegacyOutput(GstBaseSink *gobj); private: - shared_ptr _libsigrok_output_format; - shared_ptr _libsigrok_device; - shared_ptr _libsigrok_output; - map _options; + shared_ptr _libsigrok_output_format; + shared_ptr _libsigrok_device; + shared_ptr _libsigrok_output; + map _options; }; #endif #ifdef HAVE_LIBSIGROKDECODE class LegacyDecoder : - public Sink + public Sink { public: - static Glib::RefPtr create( - struct srd_session *libsigrokdecode_session, uint64_t unitsize); + static Glib::RefPtr create( + struct srd_session *libsigrokdecode_session, uint64_t unitsize); + + /* Retrieve libsigrokdecode session. */ + struct srd_session *libsigrokdecode_session(); - /* Retrieve libsigrokdecode session */ - struct srd_session *libsigrokdecode_session(); + /* Override start. */ + bool start_vfunc(); - /* Override start */ - bool start_vfunc(); + /* Override render. */ + Gst::FlowReturn render_vfunc(const Glib::RefPtr &buffer); - /* Override render */ - Gst::FlowReturn render_vfunc(const Glib::RefPtr &buffer); + /* Override stop. */ + bool stop_vfunc(); - /* Override stop */ - bool stop_vfunc(); + /* Gst class init. */ + static void class_init(Gst::ElementClass *klass); - /* Gst class init */ - static void class_init(Gst::ElementClass *klass); + /* Register class with plugin. */ + static bool register_element(Glib::RefPtr plugin); - /* Register class with plugin */ - static bool register_element(Glib::RefPtr plugin); + /* Constructor used by element factory. */ + explicit LegacyDecoder(GstBaseSink *gobj); - /* Constructor used by element factory */ - explicit LegacyDecoder(GstBaseSink *gobj); private: - struct srd_session *_session; - uint64_t _abs_ss; - uint64_t _unitsize; + struct srd_session *_session; + uint64_t _abs_ss; + uint64_t _unitsize; }; #endif diff --git a/src/main.cpp b/src/main.cpp index b01ee39..1b98577 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,7 +70,7 @@ void deinit() { if (!srf_initialized_) throw runtime_error("libsigrokflow is not initialized"); - + srf_initialized_ = false; } @@ -108,6 +108,7 @@ bool LegacyCaptureDevice::register_element(Glib::RefPtr plugin) Gst::ElementFactory::register_element(plugin, "sigrok_legacy_capture_device", 0, Gst::register_mm_type( "sigrok_legacy_capture_device")); + return true; } @@ -126,6 +127,7 @@ Glib::RefPtrLegacyCaptureDevice::create( throw runtime_error("Failed to create element - plugin not registered?"); auto device = Glib::RefPtr::cast_static(element); device->_libsigrok_device = libsigrok_device; + return device; } @@ -136,18 +138,17 @@ shared_ptr LegacyCaptureDevice::libsigrok_device() Gst::StateChangeReturn LegacyCaptureDevice::change_state_vfunc(Gst::StateChange transition) { - switch (transition) - { - case Gst::STATE_CHANGE_READY_TO_PAUSED: - return Gst::StateChangeReturn::STATE_CHANGE_NO_PREROLL; - case Gst::STATE_CHANGE_PAUSED_TO_PLAYING: - _task = Gst::Task::create(std::bind(&LegacyCaptureDevice::_run, this)); - _task->set_lock(_mutex); - _src_pad->set_active(true); - _task->start(); - return Gst::STATE_CHANGE_SUCCESS; - default: - return Gst::STATE_CHANGE_SUCCESS; + switch (transition) { + case Gst::STATE_CHANGE_READY_TO_PAUSED: + return Gst::StateChangeReturn::STATE_CHANGE_NO_PREROLL; + case Gst::STATE_CHANGE_PAUSED_TO_PLAYING: + _task = Gst::Task::create(std::bind(&LegacyCaptureDevice::_run, this)); + _task->set_lock(_mutex); + _src_pad->set_active(true); + _task->start(); + return Gst::STATE_CHANGE_SUCCESS; + default: + return Gst::STATE_CHANGE_SUCCESS; } } @@ -155,28 +156,28 @@ void LegacyCaptureDevice::_datafeed_callback( shared_ptr device, shared_ptr packet) { - (void) device; + (void)device; + switch (packet->type()->id()) { - case SR_DF_LOGIC: - { - auto logic = static_pointer_cast(packet->payload()); - auto mem = Gst::Memory::create( - Gst::MEMORY_FLAG_READONLY, - logic->data_pointer(), - logic->data_length(), - 0, - logic->data_length()); - auto buf = Gst::Buffer::create(); - buf->append_memory(move(mem)); - _src_pad->push(move(buf)); - break; - } - case SR_DF_END: - _session->stop(); - _src_pad->push_event(Gst::EventEos::create()); - break; - default: - break; + case SR_DF_LOGIC: { + auto logic = static_pointer_cast(packet->payload()); + auto mem = Gst::Memory::create( + Gst::MEMORY_FLAG_READONLY, + logic->data_pointer(), + logic->data_length(), + 0, + logic->data_length()); + auto buf = Gst::Buffer::create(); + buf->append_memory(move(mem)); + _src_pad->push(move(buf)); + break; + } + case SR_DF_END: + _session->stop(); + _src_pad->push_event(Gst::EventEos::create()); + break; + default: + break; } } @@ -214,6 +215,7 @@ bool LegacyInput::register_element(Glib::RefPtr plugin) Gst::ElementFactory::register_element(plugin, "sigrok_legacy_input", 0, Gst::register_mm_type( "sigrok_legacy_input")); + return true; } @@ -236,6 +238,7 @@ Glib::RefPtr LegacyInput::create( auto input = Glib::RefPtr::cast_static(element); input->_libsigrok_input_format = libsigrok_input_format; input->_options = options; + return input; } @@ -247,6 +250,7 @@ bool LegacyInput::start_vfunc() _session->add_device(_libsigrok_input->device()); _session->add_datafeed_callback(bind(&LegacyInput::_datafeed_callback, this, _1, _2)); _session->start(); + return true; } @@ -254,44 +258,46 @@ void LegacyInput::_datafeed_callback( shared_ptr device, shared_ptr packet) { - (void) device; + (void)device; + switch (packet->type()->id()) { - case SR_DF_LOGIC: - { - auto logic = static_pointer_cast(packet->payload()); - auto mem = Gst::Memory::create( - Gst::MEMORY_FLAG_READONLY, - logic->data_pointer(), - logic->data_length(), - 0, - logic->data_length()); - auto buf = Gst::Buffer::create(); - buf->append_memory(move(mem)); - _src_pad->push(move(buf)); - break; - } - case SR_DF_END: - _session->stop(); - _src_pad->push_event(Gst::EventEos::create()); - break; - default: - break; + case SR_DF_LOGIC: { + auto logic = static_pointer_cast(packet->payload()); + auto mem = Gst::Memory::create( + Gst::MEMORY_FLAG_READONLY, + logic->data_pointer(), + logic->data_length(), + 0, + logic->data_length()); + auto buf = Gst::Buffer::create(); + buf->append_memory(move(mem)); + _src_pad->push(move(buf)); + break; + } + case SR_DF_END: + _session->stop(); + _src_pad->push_event(Gst::EventEos::create()); + break; + default: + break; } } Gst::FlowReturn LegacyInput::chain(const Glib::RefPtr &, - const Glib::RefPtr &buf) + const Glib::RefPtr &buf) { Gst::MapInfo info; buf->map(info, Gst::MAP_READ); _libsigrok_input->send(info.get_data(), info.get_size()); buf->unmap(info); + return Gst::FLOW_OK; } bool LegacyInput::stop_vfunc() { _libsigrok_input->end(); + return true; } @@ -313,6 +319,7 @@ bool LegacyOutput::register_element(Glib::RefPtr plugin) Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output", 0, Gst::register_mm_type( "sigrok_legacy_output")); + return true; } @@ -334,6 +341,7 @@ Glib::RefPtrLegacyOutput::create( output->_libsigrok_output_format = libsigrok_output_format; output->_libsigrok_device = libsigrok_device; output->_options = options; + return output; } @@ -341,6 +349,7 @@ bool LegacyOutput::start_vfunc() { _libsigrok_output = _libsigrok_output_format->create_output( _libsigrok_device, _options); + return true; } @@ -354,6 +363,7 @@ Gst::FlowReturn LegacyOutput::render_vfunc(const Glib::RefPtr &buff auto result = _libsigrok_output->receive(packet); cout << result; buffer->unmap(info); + return Gst::FLOW_OK; } @@ -363,6 +373,7 @@ bool LegacyOutput::stop_vfunc() auto end_packet = context->create_end_packet(); auto result = _libsigrok_output->receive(end_packet); cout << result; + return true; } #endif @@ -386,6 +397,7 @@ bool LegacyDecoder::register_element(Glib::RefPtr plugin) Gst::ElementFactory::register_element(plugin, "sigrok_legacy_decoder", 0, Gst::register_mm_type( "sigrok_legacy_decoder")); + return true; } @@ -404,6 +416,7 @@ Glib::RefPtrLegacyDecoder::create( auto decoder = Glib::RefPtr::cast_static(element); decoder->_session = libsigrokdecode_session; decoder->_unitsize = unitsize; + return decoder; } @@ -421,6 +434,7 @@ Gst::FlowReturn LegacyDecoder::render_vfunc(const Glib::RefPtr &buf info.get_data(), info.get_size(), _unitsize); _abs_ss += num_samples; buffer->unmap(info); + return Gst::FLOW_OK; } @@ -428,12 +442,14 @@ bool LegacyDecoder::start_vfunc() { _abs_ss = 0; srd_session_start(_session); + return true; } bool LegacyDecoder::stop_vfunc() { srd_session_terminate_reset(_session); + return true; } #endif