]> sigrok.org Git - libsigrokflow.git/blob - include/libsigrokflow/libsigrokflow.hpp
tests/init: Multiple Srf::init() calls should throw.
[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 /* Temporary workaround, will be dropped later. */
25 #define HAVE_LIBSIGROKCXX 1
26 #define HAVE_LIBSIGROKDECODE 1
27
28 #include <gstreamermm.h>
29 #include <gstreamermm/private/element_p.h>
30 #include <gstreamermm/private/basesink_p.h>
31 #ifdef HAVE_LIBSIGROKCXX
32 #include <libsigrokcxx/libsigrokcxx.hpp>
33 #endif
34 #ifdef HAVE_LIBSIGROKDECODE
35 #include <libsigrokdecode/libsigrokdecode.h>
36 #endif
37
38 namespace Srf
39 {
40
41 using namespace std;
42
43 void init();
44
45 class Block
46 {
47         /* Config API etc goes here */
48 };
49
50 class Sink :
51         public Gst::BaseSink
52 {
53 protected:
54         explicit Sink(GstBaseSink *gobj);
55 };
56
57 class Device :
58         public Gst::Element
59 {
60         /* Operations specific to hardware devices go here */
61 protected:
62         explicit Device(GstElement *gobj);
63 };
64
65 class CaptureDevice :
66         public Device
67 {
68         /* Operations specific to capture (source) devices go here */
69 protected:
70         explicit CaptureDevice(GstElement *gobj);
71 };
72
73 #ifdef HAVE_LIBSIGROKCXX
74 class LegacyCaptureDevice :
75         public CaptureDevice
76 {
77 public:
78         /* Create from libsigrok device object */
79         static Glib::RefPtr<LegacyCaptureDevice> create(
80                 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
81
82         /* Retrieve libsigrok device object */
83         shared_ptr<sigrok::HardwareDevice> libsigrok_device();
84
85         /* Override state change */
86         Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
87
88         /* Gst class init */
89         static void class_init(Gst::ElementClass<LegacyCaptureDevice> *klass);
90
91         /* Register class with plugin */
92         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
93
94         /* Construcor used by element factory */
95         explicit LegacyCaptureDevice(GstElement *gobj);
96 private:
97         shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
98         Glib::RefPtr<Gst::Pad> _src_pad;
99         Glib::Threads::RecMutex _mutex;
100         Glib::RefPtr<Gst::Task> _task;
101         shared_ptr<sigrok::Session> _session;
102
103         void _datafeed_callback(shared_ptr<sigrok::Device> device,
104                         shared_ptr<sigrok::Packet> packet);
105         void _run();
106 };
107
108 class LegacyInput :
109         public Gst::Element
110 {
111 public:
112         /* Create from libsigrok input */
113         static Glib::RefPtr<LegacyInput> create(
114                 shared_ptr<sigrok::InputFormat> format,
115                 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
116
117         /* Override start */
118         bool start_vfunc();
119
120         /* Chain function */
121         Gst::FlowReturn chain(const Glib::RefPtr<Gst::Pad> &pad,
122                         const Glib::RefPtr<Gst::Buffer> &buf);
123
124         /* Override stop */
125         bool stop_vfunc();
126
127         /* Gst class init */
128         static void class_init(Gst::ElementClass<LegacyInput> *klass);
129
130         /* Register class with plugin */
131         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
132
133         /* Construcor used by element factory */
134         explicit LegacyInput(GstElement *gobj);
135 private:
136         shared_ptr<sigrok::InputFormat> _libsigrok_input_format;
137         shared_ptr<sigrok::Input> _libsigrok_input;
138         shared_ptr<sigrok::Session> _session;
139         map<string, Glib::VariantBase> _options;
140         Glib::RefPtr<Gst::Pad> _sink_pad;
141         Glib::RefPtr<Gst::Pad> _src_pad;
142
143         void _datafeed_callback(shared_ptr<sigrok::Device> device,
144                         shared_ptr<sigrok::Packet> packet);
145 };
146
147 class LegacyOutput :
148         public Sink
149 {
150 public:
151         /* Create from libsigrok output object */
152         static Glib::RefPtr<LegacyOutput> create(
153                 shared_ptr<sigrok::OutputFormat> libsigrok_output_format,
154                 shared_ptr<sigrok::Device> libsigrok_device,
155                 map<string, Glib::VariantBase> options = map<string, Glib::VariantBase>());
156
157         /* Override start */
158         bool start_vfunc();
159
160         /* Override render */
161         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
162
163         /* Override stop */
164         bool stop_vfunc();
165
166         /* Gst class init */
167         static void class_init(Gst::ElementClass<LegacyOutput> *klass);
168
169         /* Register class with plugin */
170         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
171
172         /* Constructor used by element factory */
173         explicit LegacyOutput(GstBaseSink *gobj);
174 private:
175         shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
176         shared_ptr<sigrok::Device> _libsigrok_device;
177         shared_ptr<sigrok::Output> _libsigrok_output;
178         map<string, Glib::VariantBase> _options;
179 };
180 #endif
181
182 #ifdef HAVE_LIBSIGROKDECODE
183 class LegacyDecoder :
184         public Sink
185 {
186 public:
187         static Glib::RefPtr<LegacyDecoder> create(
188                 struct srd_session *libsigrokdecode_session, uint64_t unitsize);
189
190         /* Retrieve libsigrokdecode session */
191         struct srd_session *libsigrokdecode_session();
192
193         /* Override start */
194         bool start_vfunc();
195
196         /* Override render */
197         Gst::FlowReturn render_vfunc(const Glib::RefPtr<Gst::Buffer> &buffer);
198
199         /* Override stop */
200         bool stop_vfunc();
201
202         /* Gst class init */
203         static void class_init(Gst::ElementClass<LegacyDecoder> *klass);
204
205         /* Register class with plugin */
206         static bool register_element(Glib::RefPtr<Gst::Plugin> plugin);
207
208         /* Constructor used by element factory */
209         explicit LegacyDecoder(GstBaseSink *gobj);
210 private:
211         struct srd_session *_session;
212         uint64_t _abs_ss;
213         uint64_t _unitsize;
214 };
215 #endif
216
217 }
218 #endif