]> sigrok.org Git - libsigrokflow.git/commitdiff
Various whitespace/consistency/cosmetic fixes.
authorUwe Hermann <redacted>
Wed, 9 Jan 2019 00:42:46 +0000 (01:42 +0100)
committerUwe Hermann <redacted>
Wed, 9 Jan 2019 00:55:28 +0000 (01:55 +0100)
include/libsigrokflow/libsigrokflow.hpp
src/main.cpp

index 944c99c6fe94849324f91948d6d1db7d193f6559..8154951c86966e1ffc3d203a9088ae6370984d43 100644 (file)
@@ -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<LegacyCaptureDevice> create(
-                shared_ptr<sigrok::HardwareDevice> libsigrok_device);
+       /* Create from libsigrok device object. */
+       static Glib::RefPtr<LegacyCaptureDevice> create(
+               shared_ptr<sigrok::HardwareDevice> libsigrok_device);
 
-        /* Retrieve libsigrok device object */
-        shared_ptr<sigrok::HardwareDevice> libsigrok_device();
+       /* Retrieve libsigrok device object. */
+       shared_ptr<sigrok::HardwareDevice> 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<LegacyCaptureDevice> *klass);
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
 
-        /* Register class with plugin */
-        static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+       /* Constructor used by element factory. */
+       explicit LegacyCaptureDevice(GstElement *gobj);
 
-        /* Construcor used by element factory */
-        explicit LegacyCaptureDevice(GstElement *gobj);
 private:
-        shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
-        Glib::RefPtr<Gst::Pad> _src_pad;
-        Glib::Threads::RecMutex _mutex;
-        Glib::RefPtr<Gst::Task> _task;
-        shared_ptr<sigrok::Session> _session;
-
-        void _datafeed_callback(shared_ptr<sigrok::Device> device,
-                        shared_ptr<sigrok::Packet> packet);
-        void _run();
+       shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
+       Glib::RefPtr<Gst::Pad> _src_pad;
+       Glib::Threads::RecMutex _mutex;
+       Glib::RefPtr<Gst::Task> _task;
+       shared_ptr<sigrok::Session> _session;
+
+       void _datafeed_callback(shared_ptr<sigrok::Device> device,
+                       shared_ptr<sigrok::Packet> packet);
+       void _run();
 };
 
 class LegacyInput :
-        public Gst::Element
+       public Gst::Element
 {
 public:
-        /* Create from libsigrok input */
-        static Glib::RefPtr<LegacyInput> create(
-                shared_ptr<sigrok::InputFormat> format,
-                map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
+       /* Create from libsigrok input. */
+       static Glib::RefPtr<LegacyInput> create(
+               shared_ptr<sigrok::InputFormat> format,
+               map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
+
+       /* Override start. */
+       bool start_vfunc();
 
-        /* Override start */
-        bool start_vfunc();
+       /* Chain function. */
+       Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
+                       const Glib::RefPtr<Gst::Buffer> &buf);
 
-        /* Chain function */
-        Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
-                        const Glib::RefPtr<Gst::Buffer> &buf);
+       /* Override stop. */
+       bool stop_vfunc();
 
-        /* Override stop */
-        bool stop_vfunc();
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyInput> *klass);
 
-        /* Gst class init */
-        static void class_init(Gst::ElementClass<LegacyInput> *klass);
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
 
-        /* Register class with plugin */
-        static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+       /* Constructor used by element factory. */
+       explicit LegacyInput(GstElement *gobj);
 
-        /* Construcor used by element factory */
-        explicit LegacyInput(GstElement *gobj);
 private:
-        shared_ptr<sigrok::InputFormat> _libsigrok_input_format;
-        shared_ptr<sigrok::Input> _libsigrok_input;
-        shared_ptr<sigrok::Session> _session;
-        map<string, Glib::VariantBase> _options;
-        Glib::RefPtr<Gst::Pad> _sink_pad;
-        Glib::RefPtr<Gst::Pad> _src_pad;
-
-        void _datafeed_callback(shared_ptr<sigrok::Device> device,
-                        shared_ptr<sigrok::Packet> packet);
+       shared_ptr<sigrok::InputFormat> _libsigrok_input_format;
+       shared_ptr<sigrok::Input> _libsigrok_input;
+       shared_ptr<sigrok::Session> _session;
+       map<string, Glib::VariantBase> _options;
+       Glib::RefPtr<Gst::Pad> _sink_pad;
+       Glib::RefPtr<Gst::Pad> _src_pad;
+
+       void _datafeed_callback(shared_ptr<sigrok::Device> device,
+                       shared_ptr<sigrok::Packet> packet);
 };
 
 class LegacyOutput :
-        public Sink
+       public Sink
 {
 public:
-        /* Create from libsigrok output object */
-        static Glib::RefPtr<LegacyOutput> create(
-                shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
-                shared_ptr<sigrok::Device> libsigrok_device,
-                map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
+       /* Create from libsigrok output object. */
+       static Glib::RefPtr<LegacyOutput> create(
+               shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
+               shared_ptr<sigrok::Device> libsigrok_device,
+               map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
 
-        /* Override start */
-        bool start_vfunc();
+       /* Override start. */
+       bool start_vfunc().;
 
-        /* Override render */
-        Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
+       /* Override render. */
+       Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
 
-        /* Override stop */
-        bool stop_vfunc();
+       /* Override stop. */
+       bool stop_vfunc();
 
-        /* Gst class init */
-        static void class_init(Gst::ElementClass<LegacyOutput> *klass);
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyOutput> *klass);
 
-        /* Register class with plugin */
-        static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
+
+       /* Constructor used by element factory. */
+       explicit LegacyOutput(GstBaseSink *gobj);
 
-        /* Constructor used by element factory */
-        explicit LegacyOutput(GstBaseSink *gobj);
 private:
-        shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
-        shared_ptr<sigrok::Device> _libsigrok_device;
-        shared_ptr<sigrok::Output> _libsigrok_output;
-        map<string, Glib::VariantBase> _options;
+       shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
+       shared_ptr<sigrok::Device> _libsigrok_device;
+       shared_ptr<sigrok::Output> _libsigrok_output;
+       map<string, Glib::VariantBase> _options;
 };
 #endif
 
 #ifdef HAVE_LIBSIGROKDECODE
 class LegacyDecoder :
-        public Sink
+       public Sink
 {
 public:
-        static Glib::RefPtr<LegacyDecoder> create(
-                struct srd_session *libsigrokdecode_session, uint64_t unitsize);
+       static Glib::RefPtr<LegacyDecoder> 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<Gst::Buffer> &buffer);
 
-        /* Override render */
-        Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
+       /* Override stop. */
+       bool stop_vfunc();
 
-        /* Override stop */
-        bool stop_vfunc();
+       /* Gst class init. */
+       static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
 
-        /* Gst class init */
-        static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
+       /* Register class with plugin. */
+       static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
 
-        /* Register class with plugin */
-        static bool register_element(Glib::RefPtr<Gst::Plugin> 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
 
index b01ee39deaaddfdd5a9c1ce9ac8fcb01adbef737..1b985779e431f31c0519115df73eb2ffa4206291 100644 (file)
@@ -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<Gst::Plugin> plugin)
        Gst::ElementFactory::register_element(plugin, "sigrok_legacy_capture_device",
                        0, Gst::register_mm_type<LegacyCaptureDevice>(
                                "sigrok_legacy_capture_device"));
+
        return true;
 }
 
@@ -126,6 +127,7 @@ Glib::RefPtr<LegacyCaptureDevice>LegacyCaptureDevice::create(
                throw runtime_error("Failed to create element - plugin not registered?");
        auto device = Glib::RefPtr<LegacyCaptureDevice>::cast_static(element);
        device->_libsigrok_device = libsigrok_device;
+
        return device;
 }
 
@@ -136,18 +138,17 @@ shared_ptr<sigrok::HardwareDevice> 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<sigrok::Device> device,
        shared_ptr<sigrok::Packet> packet)
 {
-       (void) device;
+       (void)device;
+
        switch (packet->type()->id()) {
-               case SR_DF_LOGIC:
-               {
-                       auto logic = static_pointer_cast<sigrok::Logic>(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<sigrok::Logic>(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<Gst::Plugin> plugin)
        Gst::ElementFactory::register_element(plugin, "sigrok_legacy_input",
                        0, Gst::register_mm_type<LegacyInput>(
                                "sigrok_legacy_input"));
+
        return true;
 }
 
@@ -236,6 +238,7 @@ Glib::RefPtr<LegacyInput> LegacyInput::create(
        auto input = Glib::RefPtr<LegacyInput>::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<sigrok::Device> device,
        shared_ptr<sigrok::Packet> packet)
 {
-       (void) device;
+       (void)device;
+
        switch (packet->type()->id()) {
-               case SR_DF_LOGIC:
-               {
-                       auto logic = static_pointer_cast<sigrok::Logic>(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<sigrok::Logic>(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<Gst::Pad> &,
-                        const Glib::RefPtr<Gst::Buffer> &buf)
+       const Glib::RefPtr<Gst::Buffer> &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<Gst::Plugin> plugin)
        Gst::ElementFactory::register_element(plugin, "sigrok_legacy_output",
                        0, Gst::register_mm_type<LegacyOutput>(
                                "sigrok_legacy_output"));
+
        return true;
 }
 
@@ -334,6 +341,7 @@ Glib::RefPtr<LegacyOutput>LegacyOutput::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<Gst::Buffer> &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<Gst::Plugin> plugin)
        Gst::ElementFactory::register_element(plugin, "sigrok_legacy_decoder",
                        0, Gst::register_mm_type<LegacyDecoder>(
                                "sigrok_legacy_decoder"));
+
        return true;
 }
 
@@ -404,6 +416,7 @@ Glib::RefPtr<LegacyDecoder>LegacyDecoder::create(
        auto decoder = Glib::RefPtr<LegacyDecoder>::cast_static(element);
        decoder->_session = libsigrokdecode_session;
        decoder->_unitsize = unitsize;
+
        return decoder;
 }
 
@@ -421,6 +434,7 @@ Gst::FlowReturn LegacyDecoder::render_vfunc(const Glib::RefPtr<Gst::Buffer> &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