]> sigrok.org Git - libsigrokflow.git/blame - include/libsigrokflow/libsigrokflow.hpp
tests/init: Multiple Srf::init() calls should throw.
[libsigrokflow.git] / include / libsigrokflow / libsigrokflow.hpp
CommitLineData
572e76fe
UH
1/*
2 * This file is part of the libsigrokflow project.
3 *
f1eaad84 4 * Copyright (C) 2018 Martin Ling <martin-sigrok@earth.li>
572e76fe
UH
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
15c57e97
UH
24/* Temporary workaround, will be dropped later. */
25#define HAVE_LIBSIGROKCXX 1
26#define HAVE_LIBSIGROKDECODE 1
27
f7363af1 28#include <gstreamermm.h>
37469b3d 29#include <gstreamermm/private/element_p.h>
e2cfc0ef 30#include <gstreamermm/private/basesink_p.h>
1060e9b5 31#ifdef HAVE_LIBSIGROKCXX
f7363af1 32#include <libsigrokcxx/libsigrokcxx.hpp>
1060e9b5 33#endif
45e6e688 34#ifdef HAVE_LIBSIGROKDECODE
b1322000 35#include <libsigrokdecode/libsigrokdecode.h>
45e6e688 36#endif
f7363af1 37
b903bb0a
UH
38namespace Srf
39{
40
f7363af1
ML
41using namespace std;
42
b903bb0a
UH
43void init();
44
f7363af1
ML
45class Block
46{
47 /* Config API etc goes here */
48};
49
e2cfc0ef
ML
50class Sink :
51 public Gst::BaseSink
f7363af1 52{
6d71d36a 53protected:
e2cfc0ef 54 explicit Sink(GstBaseSink *gobj);
f7363af1
ML
55};
56
57class Device :
e2cfc0ef 58 public Gst::Element
f7363af1
ML
59{
60 /* Operations specific to hardware devices go here */
6d71d36a
ML
61protected:
62 explicit Device(GstElement *gobj);
f7363af1 63};
b903bb0a 64
f7363af1
ML
65class CaptureDevice :
66 public Device
67{
68 /* Operations specific to capture (source) devices go here */
6d71d36a
ML
69protected:
70 explicit CaptureDevice(GstElement *gobj);
f7363af1
ML
71};
72
1060e9b5 73#ifdef HAVE_LIBSIGROKCXX
f7363af1
ML
74class LegacyCaptureDevice :
75 public CaptureDevice
76{
77public:
64b0db03
ML
78 /* Create from libsigrok device object */
79 static Glib::RefPtr<LegacyCaptureDevice> create(
80 shared_ptr<sigrok::HardwareDevice> libsigrok_device);
f7363af1
ML
81
82 /* Retrieve libsigrok device object */
d03b3a98
ML
83 shared_ptr<sigrok::HardwareDevice> libsigrok_device();
84
85 /* Override state change */
86 Gst::StateChangeReturn change_state_vfunc(Gst::StateChange transition);
6d71d36a
ML
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);
f7363af1 96private:
64b0db03 97 shared_ptr<sigrok::HardwareDevice> _libsigrok_device;
d03b3a98
ML
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();
f7363af1
ML
106};
107
92d521e7
ML
108class LegacyInput :
109 public Gst::Element
110{
111public:
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);
135private:
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
e2cfc0ef
ML
147class LegacyOutput :
148 public Sink
149{
150public:
151 /* Create from libsigrok output object */
152 static Glib::RefPtr<LegacyOutput> create(
726122c2
ML
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>());
e2cfc0ef 156
726122c2
ML
157 /* Override start */
158 bool start_vfunc();
e2cfc0ef
ML
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);
174private:
726122c2
ML
175 shared_ptr<sigrok::OutputFormat> _libsigrok_output_format;
176 shared_ptr<sigrok::Device> _libsigrok_device;
e2cfc0ef 177 shared_ptr<sigrok::Output> _libsigrok_output;
726122c2 178 map<string, Glib::VariantBase> _options;
e2cfc0ef 179};
1060e9b5 180#endif
e2cfc0ef 181
45e6e688 182#ifdef HAVE_LIBSIGROKDECODE
b1322000
UH
183class LegacyDecoder :
184 public Sink
185{
186public:
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);
210private:
211 struct srd_session *_session;
212 uint64_t _abs_ss;
213 uint64_t _unitsize;
214};
45e6e688 215#endif
f7363af1
ML
216
217}
572e76fe 218#endif