]> sigrok.org Git - libsigrok.git/blobdiff - bindings/cxx/classes.cpp
drivers: Fix behaviour when trying to set an invalid capture ratio.
[libsigrok.git] / bindings / cxx / classes.cpp
index f40a6dc571d27aebf124427cf62cf6763096aea4..d7ba79177033bbee9ea164c20d787066fb7330a2 100644 (file)
@@ -325,12 +325,16 @@ shared_ptr<Packet> Context::create_analog_packet(
        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;
@@ -872,55 +876,6 @@ void DatafeedCallbackData::run(const struct sr_dev_inst *sdi,
        _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)
@@ -967,9 +922,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;
 }
@@ -1073,66 +1025,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<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;
@@ -1320,7 +1212,7 @@ shared_ptr<PacketPayload> Analog::get_shared_pointer(Packet *_parent)
                ParentOwned::get_shared_pointer(_parent));
 }
 
-float *Analog::data_pointer()
+void *Analog::data_pointer()
 {
        return _structure->data;
 }
@@ -1333,7 +1225,7 @@ unsigned int Analog::num_samples()
 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;
@@ -1341,17 +1233,17 @@ vector<shared_ptr<Channel>> Analog::channels()
 
 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) :