]> sigrok.org Git - libsigrokflow.git/blob - include/libsigrokflow/libsigrokflow.hpp
Add missing copyright lines.
[libsigrokflow.git] / include / libsigrokflow / libsigrokflow.hpp
1 /*
2  * This file is part of the libsigrokflow project.
3  *
4  * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li>
5  * Copyright (C) 2018 Uwe Hermann <uwe@hermann-uwe.de>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
22 #define LIBSIGROKFLOW_LIBSIGROKFLOW_HPP
23
24 #include <gstreamermm.h>
25 #include <gstreamermm/private/element_p.h>
26 #include <gstreamermm/private/basesink_p.h>
27 #include <libsigrokcxx/libsigrokcxx.hpp>
28 #include <libsigrokdecode/libsigrokdecode.h>
29
30 namespace Srf
31 {
32
33 using namespace std;
34
35 void init();
36
37 class Block
38 {
39         /* Config API etc goes here */
40 };
41
42 class Sink :
43         public Gst::BaseSink
44 {
45 protected:
46         explicit Sink(GstBaseSink *gobj);
47 };
48
49 class Device :
50         public Gst::Element
51 {
52         /* Operations specific to hardware devices go here */
53 protected:
54         explicit Device(GstElement *gobj);
55 };
56
57 class CaptureDevice :
58         public Device
59 {
60         /* Operations specific to capture (source) devices go here */
61 protected:
62         explicit CaptureDevice(GstElement *gobj);
63 };
64
65 class LegacyCaptureDevice :
66         public CaptureDevice
67 {
68 public:
69         /* Create from libsigrok device object */
70         static Glib::RefPtr<LegacyCaptureDevice> create(
71                 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
72
73         /* Retrieve libsigrok device object */
74         shared_ptr<sigrok::HardwareDevice> libsigrok_device();
75
76         /* Override state change */
77         Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
78
79         /* Gst class init */
80         static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
81
82         /* Register class with plugin */
83         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
84
85         /* Construcor used by element factory */
86         explicit LegacyCaptureDevice(GstElement *gobj);
87 private:
88         shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
89         Glib::RefPtr<Gst::Pad> _src_pad;
90         Glib::Threads::RecMutex _mutex;
91         Glib::RefPtr<Gst::Task> _task;
92         shared_ptr<sigrok::Session> _session;
93
94         void _datafeed_callback(shared_ptr<sigrok::Device> device,
95                         shared_ptr<sigrok::Packet> packet);
96         void _run();
97 };
98
99 class LegacyOutput :
100         public Sink
101 {
102 public:
103         /* Create from libsigrok output object */
104         static Glib::RefPtr<LegacyOutput> create(
105                 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
106                 shared_ptr<sigrok::Device> libsigrok_device,
107                 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
108
109         /* Override start */
110         bool start_vfunc();
111
112         /* Override render */
113         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
114
115         /* Override stop */
116         bool stop_vfunc();
117
118         /* Gst class init */
119         static void class_init(Gst::ElementClass<LegacyOutput> *klass);
120
121         /* Register class with plugin */
122         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
123
124         /* Constructor used by element factory */
125         explicit LegacyOutput(GstBaseSink *gobj);
126 private:
127         shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
128         shared_ptr<sigrok::Device> _libsigrok_device;
129         shared_ptr<sigrok::Output> _libsigrok_output;
130         map<string, Glib::VariantBase> _options;
131 };
132
133 class LegacyDecoder :
134         public Sink
135 {
136 public:
137         static Glib::RefPtr<LegacyDecoder> create(
138                 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
139
140         /* Retrieve libsigrokdecode session */
141         struct srd_session *libsigrokdecode_session();
142
143         /* Override start */
144         bool start_vfunc();
145
146         /* Override render */
147         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
148
149         /* Override stop */
150         bool stop_vfunc();
151
152         /* Gst class init */
153         static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
154
155         /* Register class with plugin */
156         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
157
158         /* Constructor used by element factory */
159         explicit LegacyDecoder(GstBaseSink *gobj);
160 private:
161         struct srd_session *_session;
162         uint64_t _abs_ss;
163         uint64_t _unitsize;
164 };
165
166 }
167 #endif