const Unit *unit, vector<const QuantityFlag *> 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 = (sr_mq)mq->id();
+ meaning->unit = (sr_unit)unit->id();
+ meaning->mqflags = (sr_mqflag)QuantityFlag::mask_from_flags(mqflags);
analog->data = data_pointer;
auto packet = g_new(struct sr_datafeed_packet, 1);
packet->type = SR_DF_ANALOG;
_callback(device, packet);
}
-SourceCallbackData::SourceCallbackData(shared_ptr<EventSource> source) :
- _source(source)
-{
-}
-
-bool SourceCallbackData::run(int revents)
-{
- return _source->_callback((Glib::IOCondition) revents);
-}
-
-shared_ptr<EventSource> 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<EventSource>(result, EventSource::Deleter());
-}
-
-shared_ptr<EventSource> 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<EventSource>(result, EventSource::Deleter());
-}
-
-shared_ptr<EventSource> EventSource::create(Glib::RefPtr<Glib::IOChannel> 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<EventSource>(result, EventSource::Deleter());
-}
-
-EventSource::EventSource(int timeout, SourceCallbackFunction callback) :
- _timeout(timeout),
- _callback(callback)
-{
-}
-
-EventSource::~EventSource()
-{
-}
-
SessionDevice::SessionDevice(struct sr_dev_inst *structure) :
ParentOwned(structure),
Device(structure)
for (auto callback : _datafeed_callbacks)
delete callback;
- for (auto entry : _source_callbacks)
- delete entry.second;
-
for (auto entry : _owned_devices)
delete entry.second;
}
check(sr_session_stop(_structure));
}
+bool Session::is_running() const
+{
+ const int ret = sr_session_is_running(_structure);
+ if (ret < 0)
+ throw Error{ret};
+ return (ret != 0);
+}
+
+static void session_stopped_callback(void *data)
+{
+ auto *const callback = static_cast<SessionStoppedCallback*>(data);
+ (*callback)();
+}
+
+void Session::set_stopped_callback(SessionStoppedCallback callback)
+{
+ _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)
{
_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<EventSource> 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<EventSource> 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<Trigger> Session::trigger()
{
return _trigger;
ParentOwned::get_shared_pointer(_parent));
}
-float *Analog::data_pointer()
+void *Analog::data_pointer()
{
return _structure->data;
}
vector<shared_ptr<Channel>> Analog::channels()
{
vector<shared_ptr<Channel>> result;
- for (auto l = _structure->channels; l; l = l->next)
+ for (auto l = _structure->meaning->channels; l; l = l->next)
result.push_back(_parent->_device->get_channel(
(struct sr_channel *)l->data));
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<const QuantityFlag *> 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) :