X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Fclasses.cpp;h=f165128754ec0357b2ce1788caf58238bd0cd142;hb=a73d49263611b0d65a3ca1ad85bbee592cf1a234;hp=850225fdd467840630442442ab2159e3f852022d;hpb=c879dca3d71f321c2a972594a2186f01f398dce8;p=libsigrok.git
diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp
index 850225fd..f1651287 100644
--- a/bindings/cxx/classes.cpp
+++ b/bindings/cxx/classes.cpp
@@ -17,7 +17,13 @@
* along with this program. If not, see .
*/
-#include "libsigrokcxx/libsigrokcxx.hpp"
+/* Needed for isascii(), as used in the GNU libstdc++ headers */
+#ifndef _XOPEN_SOURCE
+#define _XOPEN_SOURCE 600
+#endif
+
+#include
+#include
#include
#include
@@ -33,39 +39,81 @@ static void check(int result)
}
/** Helper function to obtain valid strings from possibly null input. */
-static const char *valid_string(const char *input)
+static inline const char *valid_string(const char *input)
{
- if (input != NULL)
- return input;
- else
- return "";
+ return (input) ? input : "";
}
/** Helper function to convert between map and GHashTable */
-static GHashTable *map_to_hash_variant(map input)
+static GHashTable *map_to_hash_variant(const map &input)
{
- auto output = g_hash_table_new_full(
- g_str_hash, g_str_equal, g_free, (GDestroyNotify) g_variant_unref);
+ auto output = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ reinterpret_cast(&g_variant_unref));
for (auto entry : input)
g_hash_table_insert(output,
g_strdup(entry.first.c_str()),
entry.second.gobj_copy());
- return output;
+ return output;
}
Error::Error(int result) : result(result)
{
}
-const char *Error::what() const throw()
+const char *Error::what() const noexcept
{
return sr_strerror(result);
}
-Error::~Error() throw()
+Error::~Error() noexcept
+{
+}
+
+ResourceReader::~ResourceReader()
{
}
+SR_PRIV int ResourceReader::open_callback(struct sr_resource *res,
+ const char *name, void *cb_data) noexcept
+{
+ try {
+ auto *const reader = static_cast(cb_data);
+ reader->open(res, name);
+ } catch (const Error &err) {
+ return err.result;
+ } catch (...) {
+ return SR_ERR;
+ }
+ return SR_OK;
+}
+
+SR_PRIV int ResourceReader::close_callback(struct sr_resource *res,
+ void *cb_data) noexcept
+{
+ try {
+ auto *const reader = static_cast(cb_data);
+ reader->close(res);
+ } catch (const Error &err) {
+ return err.result;
+ } catch (...) {
+ return SR_ERR;
+ }
+ return SR_OK;
+}
+
+SR_PRIV ssize_t ResourceReader::read_callback(const struct sr_resource *res,
+ void *buf, size_t count, void *cb_data) noexcept
+{
+ try {
+ auto *const reader = static_cast(cb_data);
+ return reader->read(res, buf, count);
+ } catch (const Error &err) {
+ return err.result;
+ } catch (...) {
+ return SR_ERR;
+ }
+}
+
shared_ptr Context::create()
{
return shared_ptr(new Context(), Context::Deleter());
@@ -73,11 +121,11 @@ shared_ptr Context::create()
Context::Context() :
UserOwned(_structure),
- _session(NULL)
+ _session(nullptr)
{
check(sr_init(&_structure));
- struct sr_dev_driver **driver_list = sr_driver_list();
+ struct sr_dev_driver **driver_list = sr_driver_list(_structure);
if (driver_list)
for (int i = 0; driver_list[i]; i++)
_drivers[driver_list[i]->name] =
@@ -161,32 +209,17 @@ void Context::set_log_level(const LogLevel *level)
check(sr_log_loglevel_set(level->id()));
}
-string Context::log_domain()
-{
- return valid_string(sr_log_logdomain_get());
-}
-
-void Context::set_log_domain(string value)
-{
- check(sr_log_logdomain_set(value.c_str()));
-}
-
-static int call_log_callback(void *cb_data, int loglevel, const char *format, va_list args)
+static int call_log_callback(void *cb_data, int loglevel,
+ const char *format, va_list args) noexcept
{
- va_list args_copy;
- va_copy(args_copy, args);
- int length = vsnprintf(NULL, 0, format, args_copy);
- va_end(args_copy);
- char *buf = (char *) g_malloc(length + 1);
- vsprintf(buf, format, args);
- string message(buf, length);
- g_free(buf);
+ const unique_ptr
+ message {g_strdup_vprintf(format, args), &g_free};
- LogCallbackFunction callback = *((LogCallbackFunction *) cb_data);
+ auto *const callback = static_cast(cb_data);
try
{
- callback(LogLevel::get(loglevel), message);
+ (*callback)(LogLevel::get(loglevel), message.get());
}
catch (Error e)
{
@@ -198,15 +231,28 @@ static int call_log_callback(void *cb_data, int loglevel, const char *format, va
void Context::set_log_callback(LogCallbackFunction callback)
{
- _log_callback = callback;
+ _log_callback = move(callback);
check(sr_log_callback_set(call_log_callback, &_log_callback));
-}
+}
void Context::set_log_callback_default()
{
check(sr_log_callback_set_default());
_log_callback = nullptr;
-}
+}
+
+void Context::set_resource_reader(ResourceReader *reader)
+{
+ if (reader) {
+ check(sr_resource_set_hooks(_structure,
+ &ResourceReader::open_callback,
+ &ResourceReader::close_callback,
+ &ResourceReader::read_callback, reader));
+ } else {
+ check(sr_resource_set_hooks(_structure,
+ nullptr, nullptr, nullptr, nullptr));
+ }
+}
shared_ptr Context::create_session()
{
@@ -234,7 +280,7 @@ shared_ptr Context::create_header_packet(Glib::TimeVal start_time)
}
shared_ptr Context::create_meta_packet(
- map config)
+ const map &config)
{
auto meta = g_new0(struct sr_datafeed_meta, 1);
for (auto input : config)
@@ -267,17 +313,21 @@ shared_ptr Context::create_logic_packet(
}
shared_ptr Context::create_analog_packet(
- vector > channels,
+ const vector > &channels,
float *data_pointer, unsigned int num_samples, const Quantity *mq,
- const Unit *unit, vector mqflags)
+ const Unit *unit, const vector &mqflags)
{
auto analog = g_new0(struct sr_datafeed_analog, 1);
+ auto meaning = g_new0(struct sr_analog_meaning, 1);
+
+ analog->meaning = meaning;
+
for (auto channel : channels)
- analog->channels = g_slist_append(analog->channels, channel->_structure);
+ meaning->channels = g_slist_append(meaning->channels, channel->_structure);
analog->num_samples = num_samples;
- analog->mq = mq->id();
- analog->unit = unit->id();
- analog->mqflags = QuantityFlag::mask_from_flags(mqflags);
+ meaning->mq = static_cast(mq->id());
+ meaning->unit = static_cast(unit->id());
+ meaning->mqflags = static_cast(QuantityFlag::mask_from_flags(mqflags));
analog->data = data_pointer;
auto packet = g_new(struct sr_datafeed_packet, 1);
packet->type = SR_DF_ANALOG;
@@ -288,13 +338,13 @@ shared_ptr Context::create_analog_packet(
shared_ptr Context::load_session(string filename)
{
return shared_ptr(
- new Session(shared_from_this(), filename), Session::Deleter());
+ new Session(shared_from_this(), move(filename)), Session::Deleter());
}
shared_ptr Context::create_trigger(string name)
{
return shared_ptr(
- new Trigger(shared_from_this(), name), Trigger::Deleter());
+ new Trigger(shared_from_this(), move(name)), Trigger::Deleter());
}
shared_ptr Context::open_file(string filename)
@@ -320,21 +370,22 @@ shared_ptr Context::open_stream(string header)
map Context::serials(shared_ptr driver)
{
- GSList *serial_list = sr_serial_list(driver ? driver->_structure : NULL);
+ GSList *serial_list = sr_serial_list(driver ? driver->_structure : nullptr);
map serials;
for (GSList *serial = serial_list; serial; serial = serial->next) {
- struct sr_serial_port *port = (sr_serial_port *) serial->data;
+ auto *const port = static_cast(serial->data);
serials[string(port->name)] = string(port->description);
}
- g_slist_free_full(serial_list, (GDestroyNotify)sr_serial_free);
+ g_slist_free_full(serial_list,
+ reinterpret_cast(&sr_serial_free));
return serials;
}
Driver::Driver(struct sr_dev_driver *structure) :
ParentOwned(structure),
- Configurable(structure, NULL, NULL),
+ Configurable(structure, nullptr, nullptr),
_initialized(false)
{
}
@@ -354,7 +405,7 @@ string Driver::long_name()
}
vector> Driver::scan(
- map options)
+ const map &options)
{
/* Initialise the driver if not yet done. */
if (!_initialized)
@@ -364,7 +415,7 @@ vector> Driver::scan(
}
/* Translate scan options to GSList of struct sr_config pointers. */
- GSList *option_list = NULL;
+ GSList *option_list = nullptr;
for (auto entry : options)
{
auto key = entry.first;
@@ -386,7 +437,7 @@ vector> Driver::scan(
vector> result;
for (GSList *device = device_list; device; device = device->next)
{
- auto sdi = (struct sr_dev_inst *) device->data;
+ auto *const sdi = static_cast(device->data);
result.push_back(shared_ptr(
new HardwareDevice(shared_from_this(), sdi),
HardwareDevice::Deleter()));
@@ -421,11 +472,11 @@ Glib::VariantBase Configurable::config_get(const ConfigKey *key)
return Glib::VariantBase(data);
}
-void Configurable::config_set(const ConfigKey *key, Glib::VariantBase value)
+void Configurable::config_set(const ConfigKey *key, const Glib::VariantBase &value)
{
check(sr_config_set(
config_sdi, config_channel_group,
- key->id(), value.gobj()));
+ key->id(), const_cast(value.gobj())));
}
Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key)
@@ -448,8 +499,8 @@ map> Configurable::config_keys(const ConfigKe
config_driver, config_sdi, config_channel_group,
key->id(), &gvar_opts));
- opts = (const uint32_t *) g_variant_get_fixed_array(
- gvar_opts, &num_opts, sizeof(uint32_t));
+ opts = static_cast(g_variant_get_fixed_array(
+ gvar_opts, &num_opts, sizeof(uint32_t)));
for (gsize i = 0; i < num_opts; i++)
{
@@ -480,12 +531,12 @@ bool Configurable::config_check(const ConfigKey *key,
index_key->id(), &gvar_opts) != SR_OK)
return false;
- opts = (const uint32_t *) g_variant_get_fixed_array(
- gvar_opts, &num_opts, sizeof(uint32_t));
+ opts = static_cast(g_variant_get_fixed_array(
+ gvar_opts, &num_opts, sizeof(uint32_t)));
for (gsize i = 0; i < num_opts; i++)
{
- if ((opts[i] & SR_CONF_MASK) == (uint32_t) key->id())
+ if ((opts[i] & SR_CONF_MASK) == unsigned(key->id()))
{
g_variant_unref(gvar_opts);
return true;
@@ -498,18 +549,18 @@ bool Configurable::config_check(const ConfigKey *key,
}
Device::Device(struct sr_dev_inst *structure) :
- Configurable(sr_dev_inst_driver_get(structure), structure, NULL),
+ Configurable(sr_dev_inst_driver_get(structure), structure, nullptr),
_structure(structure)
{
for (GSList *entry = sr_dev_inst_channels_get(structure); entry; entry = entry->next)
{
- auto channel = (struct sr_channel *) entry->data;
+ auto *const channel = static_cast(entry->data);
_channels[channel] = new Channel(channel);
}
for (GSList *entry = sr_dev_inst_channel_groups_get(structure); entry; entry = entry->next)
{
- auto group = (struct sr_channel_group *) entry->data;
+ auto *const group = static_cast(entry->data);
_channel_groups[group->name] = new ChannelGroup(this, group);
}
}
@@ -550,10 +601,10 @@ string Device::connection_id()
vector> Device::channels()
{
vector> result;
- for (auto channel = sr_dev_inst_channels_get(_structure); channel; channel = channel->next)
- result.push_back(
- _channels[(struct sr_channel *) channel->data]->get_shared_pointer(
- get_shared_from_this()));
+ for (auto channel = sr_dev_inst_channels_get(_structure); channel; channel = channel->next) {
+ auto *const ch = static_cast(channel->data);
+ result.push_back(_channels[ch]->get_shared_pointer(get_shared_from_this()));
+ }
return result;
}
@@ -589,7 +640,7 @@ HardwareDevice::HardwareDevice(shared_ptr driver,
struct sr_dev_inst *structure) :
UserOwned(structure),
Device(structure),
- _driver(driver)
+ _driver(move(driver))
{
}
@@ -628,11 +679,10 @@ shared_ptr UserDevice::add_channel(unsigned int index,
{
check(sr_dev_inst_channel_add(Device::_structure,
index, type->id(), name.c_str()));
- struct sr_channel *structure = (struct sr_channel *)
- g_slist_last(sr_dev_inst_channels_get(Device::_structure))->data;
- Channel *channel = new Channel(structure);
- _channels[structure] = channel;
- return get_channel(structure);
+ GSList *const last = g_slist_last(sr_dev_inst_channels_get(Device::_structure));
+ auto *const ch = static_cast(last->data);
+ _channels[ch] = new Channel(ch);
+ return get_channel(ch);
}
Channel::Channel(struct sr_channel *structure) :
@@ -680,8 +730,10 @@ ChannelGroup::ChannelGroup(Device *device,
ParentOwned(structure),
Configurable(sr_dev_inst_driver_get(device->_structure), device->_structure, structure)
{
- for (GSList *entry = structure->channels; entry; entry = entry->next)
- _channels.push_back(device->_channels[(struct sr_channel *)entry->data]);
+ for (GSList *entry = structure->channels; entry; entry = entry->next) {
+ auto *const ch = static_cast(entry->data);
+ _channels.push_back(device->_channels[ch]);
+ }
}
ChannelGroup::~ChannelGroup()
@@ -703,11 +755,11 @@ vector> ChannelGroup::channels()
Trigger::Trigger(shared_ptr context, string name) :
UserOwned(sr_trigger_new(name.c_str())),
- _context(context)
+ _context(move(context))
{
for (auto stage = _structure->stages; stage; stage = stage->next)
_stages.push_back(
- new TriggerStage((struct sr_trigger_stage *) stage->data));
+ new TriggerStage(static_cast(stage->data)));
}
Trigger::~Trigger()
@@ -767,21 +819,22 @@ void TriggerStage::add_match(shared_ptr channel,
{
check(sr_trigger_match_add(_structure,
channel->_structure, type->id(), value));
+ GSList *const last = g_slist_last(_structure->matches);
_matches.push_back(new TriggerMatch(
- (struct sr_trigger_match *) g_slist_last(
- _structure->matches)->data, channel));
+ static_cast(last->data),
+ move(channel)));
}
void TriggerStage::add_match(shared_ptr channel,
const TriggerMatchType *type)
{
- add_match(channel, type, NAN);
+ add_match(move(channel), type, NAN);
}
TriggerMatch::TriggerMatch(struct sr_trigger_match *structure,
shared_ptr channel) :
ParentOwned(structure),
- _channel(channel)
+ _channel(move(channel))
{
}
@@ -806,7 +859,7 @@ float TriggerMatch::value()
DatafeedCallbackData::DatafeedCallbackData(Session *session,
DatafeedCallbackFunction callback) :
- _callback(callback),
+ _callback(move(callback)),
_session(session)
{
}
@@ -816,56 +869,7 @@ void DatafeedCallbackData::run(const struct sr_dev_inst *sdi,
{
auto device = _session->get_device(sdi);
auto packet = shared_ptr(new Packet(device, pkt), Packet::Deleter());
- _callback(device, packet);
-}
-
-SourceCallbackData::SourceCallbackData(shared_ptr source) :
- _source(source)
-{
-}
-
-bool SourceCallbackData::run(int revents)
-{
- return _source->_callback((Glib::IOCondition) revents);
-}
-
-shared_ptr EventSource::create(int fd, Glib::IOCondition events,
- int timeout, SourceCallbackFunction callback)
-{
- auto result = new EventSource(timeout, callback);
- result->_type = EventSource::SOURCE_FD;
- result->_fd = fd;
- result->_events = events;
- return shared_ptr(result, EventSource::Deleter());
-}
-
-shared_ptr EventSource::create(Glib::PollFD pollfd, int timeout,
- SourceCallbackFunction callback)
-{
- auto result = new EventSource(timeout, callback);
- result->_type = EventSource::SOURCE_POLLFD;
- result->_pollfd = pollfd;
- return shared_ptr(result, EventSource::Deleter());
-}
-
-shared_ptr EventSource::create(Glib::RefPtr channel,
- Glib::IOCondition events, int timeout, SourceCallbackFunction callback)
-{
- auto result = new EventSource(timeout, callback);
- result->_type = EventSource::SOURCE_IOCHANNEL;
- result->_channel = channel;
- result->_events = events;
- return shared_ptr(result, EventSource::Deleter());
-}
-
-EventSource::EventSource(int timeout, SourceCallbackFunction callback) :
- _timeout(timeout),
- _callback(callback)
-{
-}
-
-EventSource::~EventSource()
-{
+ _callback(move(device), move(packet));
}
SessionDevice::SessionDevice(struct sr_dev_inst *structure) :
@@ -885,25 +889,22 @@ shared_ptr SessionDevice::get_shared_from_this()
Session::Session(shared_ptr context) :
UserOwned(_structure),
- _context(context),
- _saving(false)
+ _context(move(context))
{
- check(sr_session_new(context->_structure, &_structure));
+ check(sr_session_new(_context->_structure, &_structure));
_context->_session = this;
}
Session::Session(shared_ptr context, string filename) :
UserOwned(_structure),
- _context(context),
- _filename(filename),
- _saving(false)
+ _context(move(context)),
+ _filename(move(filename))
{
- check(sr_session_load(context->_structure, filename.c_str(), &_structure));
+ check(sr_session_load(_context->_structure, _filename.c_str(), &_structure));
GSList *dev_list;
check(sr_session_dev_list(_structure, &dev_list));
- for (GSList *dev = dev_list; dev; dev = dev->next)
- {
- auto sdi = (struct sr_dev_inst *) dev->data;
+ for (GSList *dev = dev_list; dev; dev = dev->next) {
+ auto *const sdi = static_cast(dev->data);
_owned_devices[sdi] = new SessionDevice(sdi);
}
_context->_session = this;
@@ -916,9 +917,6 @@ Session::~Session()
for (auto callback : _datafeed_callbacks)
delete callback;
- for (auto entry : _source_callbacks)
- delete entry.second;
-
for (auto entry : _owned_devices)
delete entry.second;
}
@@ -936,8 +934,9 @@ shared_ptr Session::get_device(const struct sr_dev_inst *sdi)
void Session::add_device(shared_ptr device)
{
- check(sr_session_dev_add(_structure, device->_structure));
- _other_devices[device->_structure] = device;
+ const auto dev_struct = device->_structure;
+ check(sr_session_dev_add(_structure, dev_struct));
+ _other_devices[dev_struct] = move(device);
}
vector> Session::devices()
@@ -945,9 +944,8 @@ vector> Session::devices()
GSList *dev_list;
check(sr_session_dev_list(_structure, &dev_list));
vector> result;
- for (GSList *dev = dev_list; dev; dev = dev->next)
- {
- auto sdi = (struct sr_dev_inst *) dev->data;
+ for (GSList *dev = dev_list; dev; dev = dev->next) {
+ auto *const sdi = static_cast(dev->data);
result.push_back(get_device(sdi));
}
return result;
@@ -974,109 +972,47 @@ void Session::stop()
check(sr_session_stop(_structure));
}
-void Session::begin_save(string filename)
+bool Session::is_running() const
{
- _saving = true;
- _save_initialized = false;
- _save_filename = filename;
- _save_samplerate = 0;
+ const int ret = sr_session_is_running(_structure);
+ if (ret < 0)
+ throw Error{ret};
+ return (ret != 0);
}
-void Session::append(shared_ptr packet)
+static void session_stopped_callback(void *data) noexcept
{
- if (!_saving)
- throw Error(SR_ERR);
-
- switch (packet->_structure->type)
- {
- case SR_DF_META:
- {
- auto meta = (const struct sr_datafeed_meta *)
- packet->_structure->payload;
-
- for (auto l = meta->config; l; l = l->next)
- {
- auto config = (struct sr_config *) l->data;
- if (config->key == SR_CONF_SAMPLERATE)
- _save_samplerate = g_variant_get_uint64(config->data);
- }
-
- break;
- }
- case SR_DF_LOGIC:
- {
- if (_save_samplerate == 0)
- {
- GVariant *samplerate;
-
- check(sr_config_get(sr_dev_inst_driver_get(packet->_device->_structure),
- packet->_device->_structure, NULL, SR_CONF_SAMPLERATE,
- &samplerate));
-
- _save_samplerate = g_variant_get_uint64(samplerate);
-
- g_variant_unref(samplerate);
- }
-
- if (!_save_initialized)
- {
- vector> save_channels;
-
- for (auto channel : packet->_device->channels())
- if (channel->_structure->enabled &&
- channel->_structure->type == SR_CHANNEL_LOGIC)
- save_channels.push_back(channel);
-
- auto channels = g_new(char *, save_channels.size());
-
- int i = 0;
- for (auto channel : save_channels)
- channels[i++] = channel->_structure->name;
- channels[i] = NULL;
-
- int ret = sr_session_save_init(_structure, _save_filename.c_str(),
- _save_samplerate, channels);
-
- g_free(channels);
-
- if (ret != SR_OK)
- throw Error(ret);
-
- _save_initialized = true;
- }
-
- auto logic = (const struct sr_datafeed_logic *)
- packet->_structure->payload;
-
- check(sr_session_append(_structure, _save_filename.c_str(),
- (uint8_t *) logic->data, logic->unitsize,
- logic->length / logic->unitsize));
- }
- }
+ auto *const callback = static_cast(data);
+ (*callback)();
}
-void Session::append(void *data, size_t length, unsigned int unit_size)
+void Session::set_stopped_callback(SessionStoppedCallback callback)
{
- check(sr_session_append(_structure, _save_filename.c_str(),
- (uint8_t *) data, unit_size, length));
+ _stopped_callback = move(callback);
+ if (_stopped_callback)
+ check(sr_session_stopped_callback_set(_structure,
+ &session_stopped_callback, &_stopped_callback));
+ else
+ check(sr_session_stopped_callback_set(_structure,
+ nullptr, nullptr));
}
static void datafeed_callback(const struct sr_dev_inst *sdi,
- const struct sr_datafeed_packet *pkt, void *cb_data)
+ const struct sr_datafeed_packet *pkt, void *cb_data) noexcept
{
auto callback = static_cast(cb_data);
callback->run(sdi, pkt);
}
-
+
void Session::add_datafeed_callback(DatafeedCallbackFunction callback)
{
- auto cb_data = new DatafeedCallbackData(this, callback);
+ auto cb_data = new DatafeedCallbackData(this, move(callback));
check(sr_session_datafeed_callback_add(_structure,
datafeed_callback, cb_data));
_datafeed_callbacks.push_back(cb_data);
}
-void Session::remove_datafeed_callbacks(void)
+void Session::remove_datafeed_callbacks()
{
check(sr_session_datafeed_callback_remove_all(_structure));
for (auto callback : _datafeed_callbacks)
@@ -1084,66 +1020,6 @@ void Session::remove_datafeed_callbacks(void)
_datafeed_callbacks.clear();
}
-static int source_callback(int fd, int revents, void *cb_data)
-{
- (void) fd;
- auto callback = (SourceCallbackData *) cb_data;
- return callback->run(revents);
-}
-
-void Session::add_source(shared_ptr source)
-{
- if (_source_callbacks.count(source) == 1)
- throw Error(SR_ERR_ARG);
-
- auto cb_data = new SourceCallbackData(source);
-
- switch (source->_type)
- {
- case EventSource::SOURCE_FD:
- check(sr_session_source_add(_structure, source->_fd, source->_events,
- source->_timeout, source_callback, cb_data));
- break;
- case EventSource::SOURCE_POLLFD:
- check(sr_session_source_add_pollfd(_structure,
- source->_pollfd.gobj(), source->_timeout, source_callback,
- cb_data));
- break;
- case EventSource::SOURCE_IOCHANNEL:
- check(sr_session_source_add_channel(_structure,
- source->_channel->gobj(), source->_events, source->_timeout,
- source_callback, cb_data));
- break;
- }
-
- _source_callbacks[source] = cb_data;
-}
-
-void Session::remove_source(shared_ptr source)
-{
- if (_source_callbacks.count(source) == 0)
- throw Error(SR_ERR_ARG);
-
- switch (source->_type)
- {
- case EventSource::SOURCE_FD:
- check(sr_session_source_remove(_structure, source->_fd));
- break;
- case EventSource::SOURCE_POLLFD:
- check(sr_session_source_remove_pollfd(_structure,
- source->_pollfd.gobj()));
- break;
- case EventSource::SOURCE_IOCHANNEL:
- check(sr_session_source_remove_channel(_structure,
- source->_channel->gobj()));
- break;
- }
-
- delete _source_callbacks[source];
-
- _source_callbacks.erase(source);
-}
-
shared_ptr Session::trigger()
{
return _trigger;
@@ -1153,10 +1029,10 @@ void Session::set_trigger(shared_ptr trigger)
{
if (!trigger)
// Set NULL trigger, i.e. remove any trigger from the session.
- check(sr_session_trigger_set(_structure, NULL));
+ check(sr_session_trigger_set(_structure, nullptr));
else
check(sr_session_trigger_set(_structure, trigger->_structure));
- _trigger = trigger;
+ _trigger = move(trigger);
}
string Session::filename()
@@ -1172,7 +1048,7 @@ shared_ptr Session::context()
Packet::Packet(shared_ptr device,
const struct sr_datafeed_packet *structure) :
UserOwned(structure),
- _device(device)
+ _device(move(device))
{
switch (structure->type)
{
@@ -1276,9 +1152,8 @@ shared_ptr Meta::get_shared_pointer(Packet *_parent)
map Meta::config()
{
map result;
- for (auto l = _structure->config; l; l = l->next)
- {
- auto config = (struct sr_config *) l->data;
+ for (auto l = _structure->config; l; l = l->next) {
+ auto *const config = static_cast(l->data);
result[ConfigKey::get(config->key)] = Glib::VariantBase(config->data);
}
return result;
@@ -1331,7 +1206,7 @@ shared_ptr Analog::get_shared_pointer(Packet *_parent)
ParentOwned::get_shared_pointer(_parent));
}
-float *Analog::data_pointer()
+void *Analog::data_pointer()
{
return _structure->data;
}
@@ -1344,25 +1219,26 @@ unsigned int Analog::num_samples()
vector> Analog::channels()
{
vector> result;
- for (auto l = _structure->channels; l; l = l->next)
- result.push_back(_parent->_device->get_channel(
- (struct sr_channel *)l->data));
+ for (auto l = _structure->meaning->channels; l; l = l->next) {
+ auto *const ch = static_cast(l->data);
+ result.push_back(_parent->_device->get_channel(ch));
+ }
return result;
}
const Quantity *Analog::mq()
{
- return Quantity::get(_structure->mq);
+ return Quantity::get(_structure->meaning->mq);
}
const Unit *Analog::unit()
{
- return Unit::get(_structure->unit);
+ return Unit::get(_structure->meaning->unit);
}
vector Analog::mq_flags()
{
- return QuantityFlag::flags_from_mask(_structure->mqflags);
+ return QuantityFlag::flags_from_mask(_structure->meaning->mqflags);
}
InputFormat::InputFormat(const struct sr_input_module *structure) :
@@ -1409,7 +1285,7 @@ map> InputFormat::options()
}
shared_ptr InputFormat::create_input(
- map options)
+ const map &options)
{
auto input = sr_input_new(_structure, map_to_hash_variant(options));
if (!input)
@@ -1420,7 +1296,7 @@ shared_ptr InputFormat::create_input(
Input::Input(shared_ptr context, const struct sr_input *structure) :
UserOwned(structure),
- _context(context),
+ _context(move(context)),
_device(nullptr)
{
}
@@ -1438,9 +1314,9 @@ shared_ptr Input::device()
return _device->get_shared_pointer(shared_from_this());
}
-void Input::send(string data)
+void Input::send(void *data, size_t length)
{
- auto gstr = g_string_new(data.c_str());
+ auto gstr = g_string_new_len(static_cast(data), length);
auto ret = sr_input_send(_structure, gstr);
g_string_free(gstr, false);
check(ret);
@@ -1462,7 +1338,7 @@ InputDevice::InputDevice(shared_ptr input,
struct sr_dev_inst *structure) :
ParentOwned(structure),
Device(structure),
- _input(input)
+ _input(move(input))
{
}
@@ -1478,7 +1354,7 @@ shared_ptr InputDevice::get_shared_from_this()
Option::Option(const struct sr_option *structure,
shared_ptr structure_array) :
UserOwned(structure),
- _structure_array(structure_array)
+ _structure_array(move(structure_array))
{
}
@@ -1509,8 +1385,10 @@ Glib::VariantBase Option::default_value()
vector Option::values()
{
vector result;
- for (auto l = _structure->values; l; l = l->next)
- result.push_back(Glib::VariantBase((GVariant *) l->data, true));
+ for (auto l = _structure->values; l; l = l->next) {
+ auto *const var = static_cast(l->data);
+ result.push_back(Glib::VariantBase(var, true));
+ }
return result;
}
@@ -1558,19 +1436,42 @@ map> OutputFormat::options()
}
shared_ptr