X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=bindings%2Fcxx%2Fclasses.cpp;h=7f5b3b2407e164d3f985bf7ef26578d5964ea162;hb=d5d7b09eb76de71a42b780b97aee5f5019d2d799;hp=960ac39bc0524a5f0ae7f59604f1fa24eeefcee6;hpb=15bebf575da5fe1f587a052c3dc254eea1bf7659;p=libsigrok.git diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 960ac39b..7f5b3b24 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -120,7 +120,7 @@ shared_ptr Context::create() } Context::Context() : - UserOwned(_structure), + _structure(nullptr), _session(nullptr) { check(sr_init(&_structure)); @@ -159,7 +159,7 @@ map> Context::drivers() { auto name = entry.first; auto driver = entry.second; - result[name] = driver->get_shared_pointer(this); + result[name] = driver->share_owned_by(shared_from_this()); } return result; } @@ -171,7 +171,7 @@ map> Context::input_formats() { auto name = entry.first; auto input_format = entry.second; - result[name] = input_format->get_shared_pointer(this); + result[name] = input_format->share_owned_by(shared_from_this()); } return result; } @@ -183,7 +183,7 @@ map> Context::output_formats() { auto name = entry.first; auto output_format = entry.second; - result[name] = output_format->get_shared_pointer(this); + result[name] = output_format->share_owned_by(shared_from_this()); } return result; } @@ -384,8 +384,8 @@ map Context::serials(shared_ptr driver) const } Driver::Driver(struct sr_dev_driver *structure) : - ParentOwned(structure), Configurable(structure, nullptr, nullptr), + _structure(structure), _initialized(false) { } @@ -603,14 +603,14 @@ vector> Device::channels() vector> result; 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())); + result.push_back(_channels[ch]->share_owned_by(get_shared_from_this())); } return result; } shared_ptr Device::get_channel(struct sr_channel *ptr) { - return _channels[ptr]->get_shared_pointer(get_shared_from_this()); + return _channels[ptr]->share_owned_by(get_shared_from_this()); } map> @@ -621,7 +621,7 @@ Device::channel_groups() { auto name = entry.first; auto channel_group = entry.second; - result[name] = channel_group->get_shared_pointer(get_shared_from_this()); + result[name] = channel_group->share_owned_by(get_shared_from_this()); } return result; } @@ -638,7 +638,6 @@ void Device::close() HardwareDevice::HardwareDevice(shared_ptr driver, struct sr_dev_inst *structure) : - UserOwned(structure), Device(structure), _driver(move(driver)) { @@ -659,9 +658,8 @@ shared_ptr HardwareDevice::driver() } UserDevice::UserDevice(string vendor, string model, string version) : - UserOwned(sr_dev_inst_user_new( - vendor.c_str(), model.c_str(), version.c_str())), - Device(UserOwned::_structure) + Device(sr_dev_inst_user_new( + vendor.c_str(), model.c_str(), version.c_str())) { } @@ -686,7 +684,7 @@ shared_ptr UserDevice::add_channel(unsigned int index, } Channel::Channel(struct sr_channel *structure) : - ParentOwned(structure), + _structure(structure), _type(ChannelType::get(_structure->type)) { } @@ -727,10 +725,9 @@ unsigned int Channel::index() const ChannelGroup::ChannelGroup(Device *device, struct sr_channel_group *structure) : - ParentOwned(structure), Configurable(sr_dev_inst_driver_get(device->_structure), device->_structure, structure) { - for (GSList *entry = structure->channels; entry; entry = entry->next) { + for (GSList *entry = config_channel_group->channels; entry; entry = entry->next) { auto *const ch = static_cast(entry->data); _channels.push_back(device->_channels[ch]); } @@ -742,19 +739,19 @@ ChannelGroup::~ChannelGroup() string ChannelGroup::name() const { - return valid_string(_structure->name); + return valid_string(config_channel_group->name); } vector> ChannelGroup::channels() { vector> result; for (auto channel : _channels) - result.push_back(channel->get_shared_pointer(_parent)); + result.push_back(channel->share_owned_by(_parent)); return result; } Trigger::Trigger(shared_ptr context, string name) : - UserOwned(sr_trigger_new(name.c_str())), + _structure(sr_trigger_new(name.c_str())), _context(move(context)) { for (auto stage = _structure->stages; stage; stage = stage->next) @@ -779,7 +776,7 @@ vector> Trigger::stages() { vector> result; for (auto stage : _stages) - result.push_back(stage->get_shared_pointer(this)); + result.push_back(stage->share_owned_by(shared_from_this())); return result; } @@ -787,11 +784,11 @@ shared_ptr Trigger::add_stage() { auto stage = new TriggerStage(sr_trigger_stage_add(_structure)); _stages.push_back(stage); - return stage->get_shared_pointer(this); + return stage->share_owned_by(shared_from_this()); } -TriggerStage::TriggerStage(struct sr_trigger_stage *structure) : - ParentOwned(structure) +TriggerStage::TriggerStage(struct sr_trigger_stage *structure) : + _structure(structure) { } @@ -810,7 +807,7 @@ vector> TriggerStage::matches() { vector> result; for (auto match : _matches) - result.push_back(match->get_shared_pointer(this)); + result.push_back(match->share_owned_by(shared_from_this())); return result; } @@ -833,7 +830,7 @@ void TriggerStage::add_match(shared_ptr channel, TriggerMatch::TriggerMatch(struct sr_trigger_match *structure, shared_ptr channel) : - ParentOwned(structure), + _structure(structure), _channel(move(channel)) { } @@ -873,7 +870,6 @@ void DatafeedCallbackData::run(const struct sr_dev_inst *sdi, } SessionDevice::SessionDevice(struct sr_dev_inst *structure) : - ParentOwned(structure), Device(structure) { } @@ -888,7 +884,7 @@ shared_ptr SessionDevice::get_shared_from_this() } Session::Session(shared_ptr context) : - UserOwned(_structure), + _structure(nullptr), _context(move(context)) { check(sr_session_new(_context->_structure, &_structure)); @@ -896,7 +892,7 @@ Session::Session(shared_ptr context) : } Session::Session(shared_ptr context, string filename) : - UserOwned(_structure), + _structure(nullptr), _context(move(context)), _filename(move(filename)) { @@ -925,7 +921,7 @@ shared_ptr Session::get_device(const struct sr_dev_inst *sdi) { if (_owned_devices.count(sdi)) return static_pointer_cast( - _owned_devices[sdi]->get_shared_pointer(this)); + _owned_devices[sdi]->share_owned_by(shared_from_this())); else if (_other_devices.count(sdi)) return _other_devices[sdi]; else @@ -1047,7 +1043,7 @@ shared_ptr Session::context() Packet::Packet(shared_ptr device, const struct sr_datafeed_packet *structure) : - UserOwned(structure), + _structure(structure), _device(move(device)) { switch (structure->type) @@ -1092,7 +1088,7 @@ const PacketType *Packet::type() const shared_ptr Packet::payload() { if (_payload) - return _payload->get_shared_pointer(this); + return _payload->share_owned_by(shared_from_this()); else throw Error(SR_ERR_NA); } @@ -1106,8 +1102,8 @@ PacketPayload::~PacketPayload() } Header::Header(const struct sr_datafeed_header *structure) : - ParentOwned(structure), - PacketPayload() + PacketPayload(), + _structure(structure) { } @@ -1115,10 +1111,10 @@ Header::~Header() { } -shared_ptr Header::get_shared_pointer(Packet *_parent) +shared_ptr Header::share_owned_by(shared_ptr _parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(_parent)); + ParentOwned::share_owned_by(_parent)); } int Header::feed_version() const @@ -1134,8 +1130,8 @@ Glib::TimeVal Header::start_time() const } Meta::Meta(const struct sr_datafeed_meta *structure) : - ParentOwned(structure), - PacketPayload() + PacketPayload(), + _structure(structure) { } @@ -1143,10 +1139,10 @@ Meta::~Meta() { } -shared_ptr Meta::get_shared_pointer(Packet *_parent) +shared_ptr Meta::share_owned_by(shared_ptr _parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(_parent)); + ParentOwned::share_owned_by(_parent)); } map Meta::config() const @@ -1160,8 +1156,8 @@ map Meta::config() const } Logic::Logic(const struct sr_datafeed_logic *structure) : - ParentOwned(structure), - PacketPayload() + PacketPayload(), + _structure(structure) { } @@ -1169,10 +1165,10 @@ Logic::~Logic() { } -shared_ptr Logic::get_shared_pointer(Packet *_parent) +shared_ptr Logic::share_owned_by(shared_ptr _parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(_parent)); + ParentOwned::share_owned_by(_parent)); } void *Logic::data_pointer() @@ -1191,8 +1187,8 @@ unsigned int Logic::unit_size() const } Analog::Analog(const struct sr_datafeed_analog *structure) : - ParentOwned(structure), - PacketPayload() + PacketPayload(), + _structure(structure) { } @@ -1200,10 +1196,10 @@ Analog::~Analog() { } -shared_ptr Analog::get_shared_pointer(Packet *_parent) +shared_ptr Analog::share_owned_by(shared_ptr _parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(_parent)); + ParentOwned::share_owned_by(_parent)); } void *Analog::data_pointer() @@ -1242,7 +1238,7 @@ vector Analog::mq_flags() const } InputFormat::InputFormat(const struct sr_input_module *structure) : - ParentOwned(structure) + _structure(structure) { } @@ -1290,12 +1286,11 @@ shared_ptr InputFormat::create_input( auto input = sr_input_new(_structure, map_to_hash_variant(options)); if (!input) throw Error(SR_ERR_ARG); - return shared_ptr( - new Input(_parent->shared_from_this(), input), Input::Deleter()); + return shared_ptr(new Input(_parent, input), Input::Deleter()); } Input::Input(shared_ptr context, const struct sr_input *structure) : - UserOwned(structure), + _structure(structure), _context(move(context)), _device(nullptr) { @@ -1311,7 +1306,7 @@ shared_ptr Input::device() _device = new InputDevice(shared_from_this(), sdi); } - return _device->get_shared_pointer(shared_from_this()); + return _device->share_owned_by(shared_from_this()); } void Input::send(void *data, size_t length) @@ -1336,7 +1331,6 @@ Input::~Input() InputDevice::InputDevice(shared_ptr input, struct sr_dev_inst *structure) : - ParentOwned(structure), Device(structure), _input(move(input)) { @@ -1353,7 +1347,7 @@ shared_ptr InputDevice::get_shared_from_this() Option::Option(const struct sr_option *structure, shared_ptr structure_array) : - UserOwned(structure), + _structure(structure), _structure_array(move(structure_array)) { } @@ -1393,7 +1387,7 @@ vector Option::values() const } OutputFormat::OutputFormat(const struct sr_output_module *structure) : - ParentOwned(structure) + _structure(structure) { } @@ -1458,7 +1452,7 @@ bool OutputFormat::test_flag(const OutputFlag *flag) const Output::Output(shared_ptr format, shared_ptr device, const map &options) : - UserOwned(sr_output_new(format->_structure, + _structure(sr_output_new(format->_structure, map_to_hash_variant(options), device->_structure, nullptr)), _format(move(format)), _device(move(device)), @@ -1468,7 +1462,7 @@ Output::Output(shared_ptr format, Output::Output(string filename, shared_ptr format, shared_ptr device, const map &options) : - UserOwned(sr_output_new(format->_structure, + _structure(sr_output_new(format->_structure, map_to_hash_variant(options), device->_structure, filename.c_str())), _format(move(format)), _device(move(device)),