From: Martin Ling Date: Thu, 11 Sep 2014 20:25:52 +0000 (+0100) Subject: bindings: Remove 'get_' prefix from all accessors. X-Git-Tag: libsigrok-0.4.0~1007 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=3b161085731fc6e86f7decedee34f55096282581 bindings: Remove 'get_' prefix from all accessors. --- diff --git a/bindings/cxx/ConfigKey_methods.cpp b/bindings/cxx/ConfigKey_methods.cpp index ceeea025..f9ce9984 100644 --- a/bindings/cxx/ConfigKey_methods.cpp +++ b/bindings/cxx/ConfigKey_methods.cpp @@ -1,22 +1,22 @@ -const DataType *ConfigKey::get_data_type() const +const DataType *ConfigKey::data_type() const { - const struct sr_config_info *info = sr_config_info_get(id); + const struct sr_config_info *info = sr_config_info_get(_id); if (!info) throw Error(SR_ERR_NA); return DataType::get(info->datatype); } -string ConfigKey::get_identifier() const +string ConfigKey::identifier() const { - const struct sr_config_info *info = sr_config_info_get(id); + const struct sr_config_info *info = sr_config_info_get(_id); if (!info) throw Error(SR_ERR_NA); return valid_string(info->id); } -string ConfigKey::get_description() const +string ConfigKey::description() const { - const struct sr_config_info *info = sr_config_info_get(id); + const struct sr_config_info *info = sr_config_info_get(_id); if (!info) throw Error(SR_ERR_NA); return valid_string(info->name); @@ -75,7 +75,7 @@ Glib::VariantBase ConfigKey::parse_string(string value) const GVariant *variant; uint64_t p, q; - switch (get_data_type()->get_id()) + switch (data_type()->id()) { case SR_T_UINT64: check(sr_parse_sizestring(value.c_str(), &p)); diff --git a/bindings/cxx/ConfigKey_methods.hpp b/bindings/cxx/ConfigKey_methods.hpp index 00a508d6..35315318 100644 --- a/bindings/cxx/ConfigKey_methods.hpp +++ b/bindings/cxx/ConfigKey_methods.hpp @@ -1,9 +1,9 @@ /** Data type used for this configuration key. */ - const DataType *get_data_type() const; + const DataType *data_type() const; /** String identifier for this configuration key, suitable for CLI use. */ - string get_identifier() const; + string identifier() const; /** Description of this configuration key. */ - string get_description() const; + string description() const; /** Get configuration key by string identifier. */ static const ConfigKey *get(string identifier); /** Parse a string argument into the appropriate type for this key. */ diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 8ecffd72..ec9b6d8f 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -71,42 +71,42 @@ shared_ptr Context::create() } Context::Context() : - UserOwned(structure), - session(NULL) + UserOwned(_structure), + _session(NULL) { - check(sr_init(&structure)); + check(sr_init(&_structure)); struct sr_dev_driver **driver_list = sr_driver_list(); if (driver_list) for (int i = 0; driver_list[i]; i++) - drivers[driver_list[i]->name] = + _drivers[driver_list[i]->name] = new Driver(driver_list[i]); const struct sr_input_module **input_list = sr_input_list(); if (input_list) for (int i = 0; input_list[i]; i++) - input_formats[sr_input_id_get(input_list[i])] = + _input_formats[sr_input_id_get(input_list[i])] = new InputFormat(input_list[i]); const struct sr_output_module **output_list = sr_output_list(); if (output_list) for (int i = 0; output_list[i]; i++) - output_formats[sr_output_id_get(output_list[i])] = + _output_formats[sr_output_id_get(output_list[i])] = new OutputFormat(output_list[i]); } -string Context::get_package_version() +string Context::package_version() { return sr_package_version_string_get(); } -string Context::get_lib_version() +string Context::lib_version() { return sr_lib_version_string_get(); } -map> Context::get_drivers() +map> Context::drivers() { map> result; - for (auto entry: drivers) + for (auto entry: _drivers) { auto name = entry.first; auto driver = entry.second; @@ -115,10 +115,10 @@ map> Context::get_drivers() return result; } -map> Context::get_input_formats() +map> Context::input_formats() { map> result; - for (auto entry: input_formats) + for (auto entry: _input_formats) { auto name = entry.first; auto input_format = entry.second; @@ -127,10 +127,10 @@ map> Context::get_input_formats() return result; } -map> Context::get_output_formats() +map> Context::output_formats() { map> result; - for (auto entry: output_formats) + for (auto entry: _output_formats) { auto name = entry.first; auto output_format = entry.second; @@ -141,26 +141,26 @@ map> Context::get_output_formats() Context::~Context() { - for (auto entry : drivers) + for (auto entry : _drivers) delete entry.second; - for (auto entry : input_formats) + for (auto entry : _input_formats) delete entry.second; - for (auto entry : output_formats) + for (auto entry : _output_formats) delete entry.second; - check(sr_exit(structure)); + check(sr_exit(_structure)); } -const LogLevel *Context::get_log_level() +const LogLevel *Context::log_level() { return LogLevel::get(sr_log_loglevel_get()); } void Context::set_log_level(const LogLevel *level) { - check(sr_log_loglevel_set(level->get_id())); + check(sr_log_loglevel_set(level->id())); } -string Context::get_log_domain() +string Context::log_domain() { return valid_string(sr_log_logdomain_get()); } @@ -197,14 +197,14 @@ static int call_log_callback(void *cb_data, int loglevel, const char *format, va void Context::set_log_callback(LogCallbackFunction callback) { - log_callback = callback; - check(sr_log_callback_set(call_log_callback, &log_callback)); + _log_callback = 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; + _log_callback = nullptr; } shared_ptr Context::create_session() @@ -249,40 +249,40 @@ shared_ptr Context::open_stream(string header) Driver::Driver(struct sr_dev_driver *structure) : ParentOwned(structure), Configurable(structure, NULL, NULL), - initialized(false) + _initialized(false) { } Driver::~Driver() { - for (auto device : devices) + for (auto device : _devices) delete device; } -string Driver::get_name() +string Driver::name() { - return valid_string(structure->name); + return valid_string(_structure->name); } -string Driver::get_long_name() +string Driver::long_name() { - return valid_string(structure->longname); + return valid_string(_structure->longname); } vector> Driver::scan( map options) { /* Initialise the driver if not yet done. */ - if (!initialized) + if (!_initialized) { - check(sr_driver_init(parent->structure, structure)); - initialized = true; + check(sr_driver_init(_parent->_structure, _structure)); + _initialized = true; } /* Clear all existing instances. */ - for (auto device : devices) + for (auto device : _devices) delete device; - devices.clear(); + _devices.clear(); /* Translate scan options to GSList of struct sr_config pointers. */ GSList *option_list = NULL; @@ -291,13 +291,13 @@ vector> Driver::scan( auto key = entry.first; auto value = entry.second; auto config = g_new(struct sr_config, 1); - config->key = key->get_id(); + config->key = key->id(); config->data = value.gobj(); option_list = g_slist_append(option_list, config); } /* Run scan. */ - GSList *device_list = sr_driver_scan(structure, option_list); + GSList *device_list = sr_driver_scan(_structure, option_list); /* Free option list. */ g_slist_free_full(option_list, g_free); @@ -306,7 +306,7 @@ vector> Driver::scan( for (GSList *device = device_list; device; device = device->next) { auto sdi = (struct sr_dev_inst *) device->data; - devices.push_back(new HardwareDevice(this, sdi)); + _devices.push_back(new HardwareDevice(this, sdi)); } /* Free GSList returned from scan. */ @@ -314,8 +314,8 @@ vector> Driver::scan( /* Create list of shared pointers to device instances for return. */ vector> result; - for (auto device : devices) - result.push_back(device->get_shared_pointer(parent)); + for (auto device : _devices) + result.push_back(device->get_shared_pointer(_parent)); return result; } @@ -338,7 +338,7 @@ Glib::VariantBase Configurable::config_get(const ConfigKey *key) GVariant *data; check(sr_config_get( config_driver, config_sdi, config_channel_group, - key->get_id(), &data)); + key->id(), &data)); return Glib::VariantBase(data); } @@ -346,7 +346,7 @@ void Configurable::config_set(const ConfigKey *key, Glib::VariantBase value) { check(sr_config_set( config_sdi, config_channel_group, - key->get_id(), value.gobj())); + key->id(), value.gobj())); } Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key) @@ -354,7 +354,7 @@ Glib::VariantContainerBase Configurable::config_list(const ConfigKey *key) GVariant *data; check(sr_config_list( config_driver, config_sdi, config_channel_group, - key->get_id(), &data)); + key->id(), &data)); return Glib::VariantContainerBase(data); } @@ -367,7 +367,7 @@ vector Configurable::config_keys(const ConfigKey *key) check(sr_config_list( config_driver, config_sdi, config_channel_group, - key->get_id(), &gvar_opts)); + key->id(), &gvar_opts)); opts = (const int32_t *) g_variant_get_fixed_array( gvar_opts, &num_opts, sizeof(int32_t)); @@ -388,7 +388,7 @@ bool Configurable::config_check(const ConfigKey *key, const int32_t *opts; if (sr_config_list(config_driver, config_sdi, config_channel_group, - index_key->get_id(), &gvar_opts) != SR_OK) + index_key->id(), &gvar_opts) != SR_OK) return false; opts = (const int32_t *) g_variant_get_fixed_array( @@ -396,7 +396,7 @@ bool Configurable::config_check(const ConfigKey *key, for (gsize i = 0; i < num_opts; i++) { - if (opts[i] == key->get_id()) + if (opts[i] == key->id()) { g_variant_unref(gvar_opts); return true; @@ -410,35 +410,35 @@ bool Configurable::config_check(const ConfigKey *key, Device::Device(struct sr_dev_inst *structure) : Configurable(structure->driver, structure, NULL), - structure(structure) + _structure(structure) { for (GSList *entry = structure->channels; entry; entry = entry->next) { auto channel = (struct sr_channel *) entry->data; - channels[channel] = new Channel(channel); + _channels[channel] = new Channel(channel); } for (GSList *entry = structure->channel_groups; entry; entry = entry->next) { auto group = (struct sr_channel_group *) entry->data; - channel_groups[group->name] = new ChannelGroup(this, group); + _channel_groups[group->name] = new ChannelGroup(this, group); } } Device::~Device() { - for (auto entry : channels) + for (auto entry : _channels) delete entry.second; - for (auto entry : channel_groups) + for (auto entry : _channel_groups) delete entry.second; } -string Device::get_description() +string Device::description() { ostringstream s; vector parts = - {get_vendor(), get_model(), get_version()}; + {vendor(), model(), version()}; for (string part : parts) if (part.length() > 0) @@ -447,41 +447,41 @@ string Device::get_description() return s.str(); } -string Device::get_vendor() +string Device::vendor() { - return valid_string(structure->vendor); + return valid_string(_structure->vendor); } -string Device::get_model() +string Device::model() { - return valid_string(structure->model); + return valid_string(_structure->model); } -string Device::get_version() +string Device::version() { - return valid_string(structure->version); + return valid_string(_structure->version); } -vector> Device::get_channels() +vector> Device::channels() { vector> result; - for (auto channel = structure->channels; channel; channel = channel->next) + for (auto channel = _structure->channels; channel; channel = channel->next) result.push_back( - channels[(struct sr_channel *) channel->data]->get_shared_pointer( + _channels[(struct sr_channel *) channel->data]->get_shared_pointer( 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]->get_shared_pointer(get_shared_from_this()); } map> -Device::get_channel_groups() +Device::channel_groups() { map> result; - for (auto entry: channel_groups) + for (auto entry: _channel_groups) { auto name = entry.first; auto channel_group = entry.second; @@ -492,18 +492,18 @@ Device::get_channel_groups() void Device::open() { - check(sr_dev_open(structure)); + check(sr_dev_open(_structure)); } void Device::close() { - check(sr_dev_close(structure)); + check(sr_dev_close(_structure)); } HardwareDevice::HardwareDevice(Driver *driver, struct sr_dev_inst *structure) : ParentOwned(structure), Device(structure), - driver(driver) + _driver(driver) { } @@ -516,14 +516,14 @@ shared_ptr HardwareDevice::get_shared_from_this() return static_pointer_cast(shared_from_this()); } -shared_ptr HardwareDevice::get_driver() +shared_ptr HardwareDevice::driver() { - return driver->get_shared_pointer(parent); + return _driver->get_shared_pointer(_parent); } Channel::Channel(struct sr_channel *structure) : ParentOwned(structure), - type(ChannelType::get(structure->type)) + _type(ChannelType::get(_structure->type)) { } @@ -531,95 +531,97 @@ Channel::~Channel() { } -string Channel::get_name() +string Channel::name() { - return valid_string(structure->name); + return valid_string(_structure->name); } void Channel::set_name(string name) { - check(sr_dev_channel_name_set(parent->structure, structure->index, name.c_str())); + check(sr_dev_channel_name_set(_parent->_structure, + _structure->index, name.c_str())); } -const ChannelType *Channel::get_type() +const ChannelType *Channel::type() { - return ChannelType::get(structure->type); + return ChannelType::get(_structure->type); } -bool Channel::get_enabled() +bool Channel::enabled() { - return structure->enabled; + return _structure->enabled; } void Channel::set_enabled(bool value) { - check(sr_dev_channel_enable(parent->structure, structure->index, value)); + check(sr_dev_channel_enable(_parent->_structure, _structure->index, value)); } -unsigned int Channel::get_index() +unsigned int Channel::index() { - return structure->index; + return _structure->index; } ChannelGroup::ChannelGroup(Device *device, struct sr_channel_group *structure) : ParentOwned(structure), - Configurable(device->structure->driver, device->structure, structure) + Configurable(device->_structure->driver, device->_structure, structure) { for (GSList *entry = structure->channels; entry; entry = entry->next) - channels.push_back(device->channels[(struct sr_channel *)entry->data]); + _channels.push_back(device->_channels[(struct sr_channel *)entry->data]); } ChannelGroup::~ChannelGroup() { } -string ChannelGroup::get_name() +string ChannelGroup::name() { - return valid_string(structure->name); + return valid_string(_structure->name); } -vector> ChannelGroup::get_channels() +vector> ChannelGroup::channels() { vector> result; - for (auto channel : channels) - result.push_back(channel->get_shared_pointer(parent)); + for (auto channel : _channels) + result.push_back(channel->get_shared_pointer(_parent)); return result; } Trigger::Trigger(shared_ptr context, string name) : UserOwned(sr_trigger_new(name.c_str())), - context(context) + _context(context) { - for (auto stage = structure->stages; stage; stage = stage->next) - stages.push_back(new TriggerStage((struct sr_trigger_stage *) stage->data)); + for (auto stage = _structure->stages; stage; stage = stage->next) + _stages.push_back( + new TriggerStage((struct sr_trigger_stage *) stage->data)); } Trigger::~Trigger() { - for (auto stage: stages) + for (auto stage: _stages) delete stage; - sr_trigger_free(structure); + sr_trigger_free(_structure); } -string Trigger::get_name() +string Trigger::name() { - return structure->name; + return _structure->name; } -vector> Trigger::get_stages() +vector> Trigger::stages() { vector> result; - for (auto stage : stages) + for (auto stage : _stages) result.push_back(stage->get_shared_pointer(this)); return result; } shared_ptr Trigger::add_stage() { - auto stage = new TriggerStage(sr_trigger_stage_add(structure)); - stages.push_back(stage); + auto stage = new TriggerStage(sr_trigger_stage_add(_structure)); + _stages.push_back(stage); return stage->get_shared_pointer(this); } @@ -630,37 +632,43 @@ TriggerStage::TriggerStage(struct sr_trigger_stage *structure) : TriggerStage::~TriggerStage() { - for (auto match : matches) + for (auto match : _matches) delete match; } -int TriggerStage::get_number() +int TriggerStage::number() { - return structure->stage; + return _structure->stage; } -vector> TriggerStage::get_matches() +vector> TriggerStage::matches() { vector> result; - for (auto match : matches) + for (auto match : _matches) result.push_back(match->get_shared_pointer(this)); return result; } -void TriggerStage::add_match(shared_ptr channel, const TriggerMatchType *type, float value) +void TriggerStage::add_match(shared_ptr channel, + const TriggerMatchType *type, float value) { - check(sr_trigger_match_add(structure, channel->structure, type->get_id(), value)); - matches.push_back(new TriggerMatch( - (struct sr_trigger_match *) g_slist_last(structure->matches)->data, channel)); + check(sr_trigger_match_add(_structure, + channel->_structure, type->id(), value)); + _matches.push_back(new TriggerMatch( + (struct sr_trigger_match *) g_slist_last( + _structure->matches)->data, channel)); } -void TriggerStage::add_match(shared_ptr channel, const TriggerMatchType *type) +void TriggerStage::add_match(shared_ptr channel, + const TriggerMatchType *type) { add_match(channel, type, NAN); } -TriggerMatch::TriggerMatch(struct sr_trigger_match *structure, shared_ptr channel) : - ParentOwned(structure), channel(channel) +TriggerMatch::TriggerMatch(struct sr_trigger_match *structure, + shared_ptr channel) : + ParentOwned(structure), + _channel(channel) { } @@ -668,52 +676,53 @@ TriggerMatch::~TriggerMatch() { } -shared_ptr TriggerMatch::get_channel() +shared_ptr TriggerMatch::channel() { - return channel; + return _channel; } -const TriggerMatchType *TriggerMatch::get_type() +const TriggerMatchType *TriggerMatch::type() { - return TriggerMatchType::get(structure->match); + return TriggerMatchType::get(_structure->match); } -float TriggerMatch::get_value() +float TriggerMatch::value() { - return structure->value; + return _structure->value; } DatafeedCallbackData::DatafeedCallbackData(Session *session, DatafeedCallbackFunction callback) : - callback(callback), session(session) + _callback(callback), + _session(session) { } void DatafeedCallbackData::run(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *pkt) { - auto device = session->devices[sdi]; + auto device = _session->_devices[sdi]; auto packet = shared_ptr(new Packet(device, pkt), Packet::Deleter()); - callback(device, packet); + _callback(device, packet); } SourceCallbackData::SourceCallbackData(shared_ptr source) : - source(source) + _source(source) { } bool SourceCallbackData::run(int revents) { - return source->callback((Glib::IOCondition) 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; + result->_type = EventSource::SOURCE_FD; + result->_fd = fd; + result->_events = events; return shared_ptr(result, EventSource::Deleter()); } @@ -721,8 +730,8 @@ 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; + result->_type = EventSource::SOURCE_POLLFD; + result->_pollfd = pollfd; return shared_ptr(result, EventSource::Deleter()); } @@ -730,14 +739,15 @@ shared_ptr EventSource::create(Glib::RefPtr channe Glib::IOCondition events, int timeout, SourceCallbackFunction callback) { auto result = new EventSource(timeout, callback); - result->type = EventSource::SOURCE_IOCHANNEL; - result->channel = channel; - result->events = events; + 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) + _timeout(timeout), + _callback(callback) { } @@ -761,156 +771,158 @@ shared_ptr SessionDevice::get_shared_from_this() } Session::Session(shared_ptr context) : - UserOwned(structure), - context(context), saving(false) + UserOwned(_structure), + _context(context), + _saving(false) { - check(sr_session_new(&structure)); - context->session = this; + check(sr_session_new(&_structure)); + _context->_session = this; } Session::Session(shared_ptr context, string filename) : - UserOwned(structure), - context(context), saving(false) + UserOwned(_structure), + _context(context), + _saving(false) { - check(sr_session_load(filename.c_str(), &structure)); + check(sr_session_load(filename.c_str(), &_structure)); GSList *dev_list; - check(sr_session_dev_list(structure, &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; auto device = new SessionDevice(sdi); - devices[sdi] = shared_ptr(device, + _devices[sdi] = shared_ptr(device, SessionDevice::Deleter()); } - context->session = this; + _context->_session = this; } Session::~Session() { - check(sr_session_destroy(structure)); + check(sr_session_destroy(_structure)); - for (auto callback : datafeed_callbacks) + for (auto callback : _datafeed_callbacks) delete callback; - for (auto entry : source_callbacks) + for (auto entry : _source_callbacks) delete entry.second; } void Session::add_device(shared_ptr device) { - check(sr_session_dev_add(structure, device->structure)); - devices[device->structure] = device; + check(sr_session_dev_add(_structure, device->_structure)); + _devices[device->_structure] = device; } -vector> Session::get_devices() +vector> Session::devices() { GSList *dev_list; - check(sr_session_dev_list(structure, &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; - result.push_back(devices[sdi]); + result.push_back(_devices[sdi]); } return result; } void Session::remove_devices() { - devices.clear(); - check(sr_session_dev_remove_all(structure)); + _devices.clear(); + check(sr_session_dev_remove_all(_structure)); } void Session::start() { - check(sr_session_start(structure)); + check(sr_session_start(_structure)); } void Session::run() { - check(sr_session_run(structure)); + check(sr_session_run(_structure)); } void Session::stop() { - check(sr_session_stop(structure)); + check(sr_session_stop(_structure)); } void Session::begin_save(string filename) { - saving = true; - save_initialized = false; - save_filename = filename; - save_samplerate = 0; + _saving = true; + _save_initialized = false; + _save_filename = filename; + _save_samplerate = 0; } void Session::append(shared_ptr packet) { - if (!saving) + if (!_saving) throw Error(SR_ERR); - switch (packet->structure->type) + switch (packet->_structure->type) { case SR_DF_META: { auto meta = (const struct sr_datafeed_meta *) - packet->structure->payload; + 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); + _save_samplerate = g_variant_get_uint64(config->data); } break; } case SR_DF_LOGIC: { - if (save_samplerate == 0) + if (_save_samplerate == 0) { GVariant *samplerate; - check(sr_config_get(packet->device->structure->driver, - packet->device->structure, NULL, SR_CONF_SAMPLERATE, + check(sr_config_get(packet->_device->_structure->driver, + packet->_device->_structure, NULL, SR_CONF_SAMPLERATE, &samplerate)); - save_samplerate = g_variant_get_uint64(samplerate); + _save_samplerate = g_variant_get_uint64(samplerate); g_variant_unref(samplerate); } - if (!save_initialized) + if (!_save_initialized) { vector> save_channels; - for (auto channel : packet->device->get_channels()) - if (channel->structure->enabled && - channel->structure->type == SR_CHANNEL_LOGIC) + 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++] = channel->_structure->name; channels[i] = NULL; - int ret = sr_session_save_init(structure, save_filename.c_str(), - save_samplerate, channels); + 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; + _save_initialized = true; } auto logic = (const struct sr_datafeed_logic *) - packet->structure->payload; + packet->_structure->payload; - check(sr_session_append(structure, save_filename.c_str(), + check(sr_session_append(_structure, _save_filename.c_str(), (uint8_t *) logic->data, logic->unitsize, logic->length / logic->unitsize)); } @@ -919,7 +931,7 @@ void Session::append(shared_ptr packet) void Session::append(void *data, size_t length, unsigned int unit_size) { - check(sr_session_append(structure, save_filename.c_str(), + check(sr_session_append(_structure, _save_filename.c_str(), (uint8_t *) data, unit_size, length)); } @@ -933,16 +945,17 @@ static void datafeed_callback(const struct sr_dev_inst *sdi, void Session::add_datafeed_callback(DatafeedCallbackFunction callback) { auto cb_data = new DatafeedCallbackData(this, callback); - check(sr_session_datafeed_callback_add(structure, datafeed_callback, cb_data)); - datafeed_callbacks.push_back(cb_data); + check(sr_session_datafeed_callback_add(_structure, + datafeed_callback, cb_data)); + _datafeed_callbacks.push_back(cb_data); } void Session::remove_datafeed_callbacks(void) { - check(sr_session_datafeed_callback_remove_all(structure)); - for (auto callback : datafeed_callbacks) + check(sr_session_datafeed_callback_remove_all(_structure)); + for (auto callback : _datafeed_callbacks) delete callback; - datafeed_callbacks.clear(); + _datafeed_callbacks.clear(); } static int source_callback(int fd, int revents, void *cb_data) @@ -954,116 +967,116 @@ static int source_callback(int fd, int revents, void *cb_data) void Session::add_source(shared_ptr source) { - if (source_callbacks.count(source) == 1) + if (_source_callbacks.count(source) == 1) throw Error(SR_ERR_ARG); auto cb_data = new SourceCallbackData(source); - switch (source->type) + switch (source->_type) { case EventSource::SOURCE_FD: - check(sr_session_source_add(structure, source->fd, source->events, - source->timeout, source_callback, cb_data)); + 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, + 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, + check(sr_session_source_add_channel(_structure, + source->_channel->gobj(), source->_events, source->_timeout, source_callback, cb_data)); break; } - source_callbacks[source] = cb_data; + _source_callbacks[source] = cb_data; } void Session::remove_source(shared_ptr source) { - if (source_callbacks.count(source) == 0) + if (_source_callbacks.count(source) == 0) throw Error(SR_ERR_ARG); - switch (source->type) + switch (source->_type) { case EventSource::SOURCE_FD: - check(sr_session_source_remove(structure, 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())); + 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())); + check(sr_session_source_remove_channel(_structure, + source->_channel->gobj())); break; } - delete source_callbacks[source]; + delete _source_callbacks[source]; - source_callbacks.erase(source); + _source_callbacks.erase(source); } -shared_ptr Session::get_trigger() +shared_ptr Session::trigger() { - return trigger; + return _trigger; } void Session::set_trigger(shared_ptr trigger) { - check(sr_session_trigger_set(structure, trigger->structure)); - this->trigger = trigger; + check(sr_session_trigger_set(_structure, trigger->_structure)); + _trigger = trigger; } Packet::Packet(shared_ptr device, const struct sr_datafeed_packet *structure) : UserOwned(structure), - device(device) + _device(device) { switch (structure->type) { case SR_DF_HEADER: - payload = new Header( + _payload = new Header( static_cast( structure->payload)); break; case SR_DF_META: - payload = new Meta( + _payload = new Meta( static_cast( structure->payload)); break; case SR_DF_LOGIC: - payload = new Logic( + _payload = new Logic( static_cast( structure->payload)); break; case SR_DF_ANALOG: - payload = new Analog( + _payload = new Analog( static_cast( structure->payload)); break; default: - payload = nullptr; + _payload = nullptr; break; } } Packet::~Packet() { - if (payload) - delete payload; + if (_payload) + delete _payload; } -const PacketType *Packet::get_type() +const PacketType *Packet::type() { - return PacketType::get(structure->type); + return PacketType::get(_structure->type); } -shared_ptr Packet::get_payload() +shared_ptr Packet::payload() { - if (payload) - return payload->get_shared_pointer(this); + if (_payload) + return _payload->get_shared_pointer(this); else throw Error(SR_ERR_NA); } @@ -1086,22 +1099,22 @@ Header::~Header() { } -shared_ptr Header::get_shared_pointer(Packet *parent) +shared_ptr Header::get_shared_pointer(Packet *_parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(parent)); + ParentOwned::get_shared_pointer(_parent)); } -int Header::get_feed_version() +int Header::feed_version() { - return structure->feed_version; + return _structure->feed_version; } -Glib::TimeVal Header::get_start_time() +Glib::TimeVal Header::start_time() { return Glib::TimeVal( - structure->starttime.tv_sec, - structure->starttime.tv_usec); + _structure->starttime.tv_sec, + _structure->starttime.tv_usec); } Meta::Meta(const struct sr_datafeed_meta *structure) : @@ -1114,16 +1127,16 @@ Meta::~Meta() { } -shared_ptr Meta::get_shared_pointer(Packet *parent) +shared_ptr Meta::get_shared_pointer(Packet *_parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(parent)); + ParentOwned::get_shared_pointer(_parent)); } -map Meta::get_config() +map Meta::config() { map result; - for (auto l = structure->config; l; l = l->next) + for (auto l = _structure->config; l; l = l->next) { auto config = (struct sr_config *) l->data; result[ConfigKey::get(config->key)] = Glib::VariantBase(config->data); @@ -1141,25 +1154,25 @@ Logic::~Logic() { } -shared_ptr Logic::get_shared_pointer(Packet *parent) +shared_ptr Logic::get_shared_pointer(Packet *_parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(parent)); + ParentOwned::get_shared_pointer(_parent)); } -void *Logic::get_data_pointer() +void *Logic::data_pointer() { - return structure->data; + return _structure->data; } -size_t Logic::get_data_length() +size_t Logic::data_length() { - return structure->length; + return _structure->length; } -unsigned int Logic::get_unit_size() +unsigned int Logic::unit_size() { - return structure->unitsize; + return _structure->unitsize; } Analog::Analog(const struct sr_datafeed_analog *structure) : @@ -1172,44 +1185,44 @@ Analog::~Analog() { } -shared_ptr Analog::get_shared_pointer(Packet *parent) +shared_ptr Analog::get_shared_pointer(Packet *_parent) { return static_pointer_cast( - ParentOwned::get_shared_pointer(parent)); + ParentOwned::get_shared_pointer(_parent)); } -float *Analog::get_data_pointer() +float *Analog::data_pointer() { - return structure->data; + return _structure->data; } -unsigned int Analog::get_num_samples() +unsigned int Analog::num_samples() { - return structure->num_samples; + return _structure->num_samples; } -vector> Analog::get_channels() +vector> Analog::channels() { vector> result; - for (auto l = structure->channels; l; l = l->next) - result.push_back(parent->device->get_channel( + for (auto l = _structure->channels; l; l = l->next) + result.push_back(_parent->_device->get_channel( (struct sr_channel *)l->data)); return result; } -const Quantity *Analog::get_mq() +const Quantity *Analog::mq() { - return Quantity::get(structure->mq); + return Quantity::get(_structure->mq); } -const Unit *Analog::get_unit() +const Unit *Analog::unit() { - return Unit::get(structure->unit); + return Unit::get(_structure->unit); } -vector Analog::get_mq_flags() +vector Analog::mq_flags() { - return QuantityFlag::flags_from_mask(structure->mqflags); + return QuantityFlag::flags_from_mask(_structure->mqflags); } InputFormat::InputFormat(const struct sr_input_module *structure) : @@ -1221,19 +1234,19 @@ InputFormat::~InputFormat() { } -string InputFormat::get_name() +string InputFormat::name() { - return valid_string(sr_input_id_get(structure)); + return valid_string(sr_input_id_get(_structure)); } -string InputFormat::get_description() +string InputFormat::description() { - return valid_string(sr_input_description_get(structure)); + return valid_string(sr_input_description_get(_structure)); } -map> InputFormat::get_options() +map> InputFormat::options() { - const struct sr_option **options = sr_input_options_get(structure); + const struct sr_option **options = sr_input_options_get(_structure); auto option_array = shared_ptr( options, sr_input_options_free); map> result; @@ -1246,53 +1259,53 @@ map> InputFormat::get_options() shared_ptr InputFormat::create_input( map options) { - auto input = sr_input_new(structure, map_to_hash_variant(options)); + 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()); + new Input(_parent->shared_from_this(), input), Input::Deleter()); } Input::Input(shared_ptr context, const struct sr_input *structure) : UserOwned(structure), - context(context), - device(nullptr) + _context(context), + _device(nullptr) { } -shared_ptr Input::get_device() +shared_ptr Input::device() { - if (!device) + if (!_device) { - auto sdi = sr_input_dev_inst_get(structure); + auto sdi = sr_input_dev_inst_get(_structure); if (!sdi) throw Error(SR_ERR_NA); - device = new InputDevice(shared_from_this(), sdi); + _device = new InputDevice(shared_from_this(), sdi); } - return device->get_shared_pointer(shared_from_this()); + return _device->get_shared_pointer(shared_from_this()); } void Input::send(string data) { auto gstr = g_string_new(data.c_str()); - auto ret = sr_input_send(structure, gstr); + auto ret = sr_input_send(_structure, gstr); g_string_free(gstr, false); check(ret); } Input::~Input() { - if (device) - delete device; - check(sr_input_free(structure)); + if (_device) + delete _device; + check(sr_input_free(_structure)); } InputDevice::InputDevice(shared_ptr input, struct sr_dev_inst *structure) : ParentOwned(structure), Device(structure), - input(input) + _input(input) { } @@ -1308,7 +1321,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(structure_array) { } @@ -1316,30 +1329,30 @@ Option::~Option() { } -string Option::get_id() +string Option::id() { - return valid_string(structure->id); + return valid_string(_structure->id); } -string Option::get_name() +string Option::name() { - return valid_string(structure->name); + return valid_string(_structure->name); } -string Option::get_description() +string Option::description() { - return valid_string(structure->desc); + return valid_string(_structure->desc); } -Glib::VariantBase Option::get_default_value() +Glib::VariantBase Option::default_value() { - return Glib::VariantBase(structure->def, true); + return Glib::VariantBase(_structure->def, true); } -vector Option::get_values() +vector Option::values() { vector result; - for (auto l = structure->values; l; l = l->next) + for (auto l = _structure->values; l; l = l->next) result.push_back(Glib::VariantBase((GVariant *) l->data, true)); return result; } @@ -1353,19 +1366,19 @@ OutputFormat::~OutputFormat() { } -string OutputFormat::get_name() +string OutputFormat::name() { - return valid_string(sr_output_id_get(structure)); + return valid_string(sr_output_id_get(_structure)); } -string OutputFormat::get_description() +string OutputFormat::description() { - return valid_string(sr_output_description_get(structure)); + return valid_string(sr_output_description_get(_structure)); } -map> OutputFormat::get_options() +map> OutputFormat::options() { - const struct sr_option **options = sr_output_options_get(structure); + const struct sr_option **options = sr_output_options_get(_structure); auto option_array = shared_ptr( options, sr_output_options_free); map> result; @@ -1385,21 +1398,23 @@ shared_ptr OutputFormat::create_output( Output::Output(shared_ptr format, shared_ptr device, map options) : - UserOwned(sr_output_new(format->structure, - map_to_hash_variant(options), device->structure)), - format(format), device(device), options(options) + UserOwned(sr_output_new(format->_structure, + map_to_hash_variant(options), device->_structure)), + _format(format), + _device(device), + _options(options) { } Output::~Output() { - check(sr_output_free(structure)); + check(sr_output_free(_structure)); } string Output::receive(shared_ptr packet) { GString *out; - check(sr_output_send(structure, packet->structure, &out)); + check(sr_output_send(_structure, packet->_structure, &out)); if (out) { auto result = string(out->str, out->str + out->len); diff --git a/bindings/cxx/enums.py b/bindings/cxx/enums.py index 380faf91..e942058c 100644 --- a/bindings/cxx/enums.py +++ b/bindings/cxx/enums.py @@ -82,7 +82,7 @@ public: # Template for beginning of private members. header_private_template = """ private: - static const std::map values; + static const std::map _values; {classname}(enum {enumname} id, const char name[]); """ @@ -95,7 +95,7 @@ code_template = """ const {classname} *{classname}::get(int id) {{ - return {classname}::values.at(static_cast<{enumname}>(id)); + return {classname}::_values.at(static_cast<{enumname}>(id)); }} """ @@ -153,7 +153,7 @@ for enum, (classname, classbrief) in classes.items(): classname, classname, trimmed_name, classname, trimmed_name) # Define map of enum values to constants - print >> code, 'const std::map %s::values = {' % ( + print >> code, 'const std::map %s::_values = {' % ( enum_name, classname, classname) for name, trimmed_name in zip(member_names, trimmed_names): print >> code, '\t{%s, %s::%s},' % (name, classname, trimmed_name) diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index 2a819b09..15509c9c 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -142,10 +142,10 @@ protected: This strategy ensures that the destructors for both the child and the parent are called at the correct time, i.e. only when all references to both the parent and all its children are gone. */ - shared_ptr parent; + shared_ptr _parent; /* Weak pointer for shared_from_this() implementation. */ - weak_ptr weak_this; + weak_ptr _weak_this; public: /* Note, this implementation will create a new smart_ptr if none exists. */ @@ -153,10 +153,10 @@ public: { shared_ptr shared; - if (!(shared = weak_this.lock())) + if (!(shared = _weak_this.lock())) { shared = shared_ptr((Class *) this, reset_parent); - weak_this = shared; + _weak_this = shared; } return shared; @@ -166,7 +166,7 @@ public: { if (!parent) throw Error(SR_ERR_BUG); - this->parent = parent; + this->_parent = parent; return shared_from_this(); } @@ -179,15 +179,15 @@ public: protected: static void reset_parent(Class *object) { - if (!object->parent) + if (!object->_parent) throw Error(SR_ERR_BUG); - object->parent.reset(); + object->_parent.reset(); } - Struct *structure; + Struct *_structure; ParentOwned(Struct *structure) : - structure(structure) + _structure(structure) { } }; @@ -205,10 +205,10 @@ public: return shared; } protected: - Struct *structure; + Struct *_structure; UserOwned(Struct *structure) : - structure(structure) + _structure(structure) { } @@ -230,22 +230,22 @@ public: /** Create new context */ static shared_ptr create(); /** libsigrok package version. */ - string get_package_version(); + string package_version(); /** libsigrok library version. */ - string get_lib_version(); + string lib_version(); /** Available hardware drivers, indexed by name. */ - map > get_drivers(); + map > drivers(); /** Available input formats, indexed by name. */ - map > get_input_formats(); + map > input_formats(); /** Available output formats, indexed by name. */ - map > get_output_formats(); + map > output_formats(); /** Current log level. */ - const LogLevel *get_log_level(); + const LogLevel *log_level(); /** Set the log level. * @param level LogLevel to use. */ void set_log_level(const LogLevel *level); /** Current log domain. */ - string get_log_domain(); + string log_domain(); /** Set the log domain. * @param value Log domain prefix string. */ void set_log_domain(string value); @@ -269,11 +269,11 @@ public: * @param header Initial data from stream. */ shared_ptr open_stream(string header); protected: - map drivers; - map input_formats; - map output_formats; - Session *session; - LogCallbackFunction log_callback; + map _drivers; + map _input_formats; + map _output_formats; + Session *_session; + LogCallbackFunction _log_callback; Context(); ~Context(); friend class Deleter; @@ -317,16 +317,16 @@ class SR_API Driver : { public: /** Name of this driver. */ - string get_name(); + string name(); /** Long name for this driver. */ - string get_long_name(); + string long_name(); /** Scan for devices and return a list of devices found. * @param options Mapping of (ConfigKey, value) pairs. */ vector > scan( map options = {}); protected: - bool initialized; - vector devices; + bool _initialized; + vector _devices; Driver(struct sr_dev_driver *structure); ~Driver(); friend class Context; @@ -339,17 +339,17 @@ class SR_API Device : public Configurable { public: /** Description identifying this device. */ - string get_description(); + string description(); /** Vendor name for this device. */ - string get_vendor(); + string vendor(); /** Model name for this device. */ - string get_model(); + string model(); /** Version string for this device. */ - string get_version(); + string version(); /** List of the channels available on this device. */ - vector > get_channels(); + vector > channels(); /** Channel groups available on this device, indexed by name. */ - map > get_channel_groups(); + map > channel_groups(); /** Open device. */ void open(); /** Close device. */ @@ -359,9 +359,9 @@ protected: ~Device(); virtual shared_ptr get_shared_from_this() = 0; shared_ptr get_channel(struct sr_channel *ptr); - struct sr_dev_inst *structure; - map channels; - map channel_groups; + struct sr_dev_inst *_structure; + map _channels; + map _channel_groups; /** Deleter needed to allow shared_ptr use with protected destructor. */ class Deleter { @@ -383,12 +383,12 @@ class SR_API HardwareDevice : { public: /** Driver providing this device. */ - shared_ptr get_driver(); + shared_ptr driver(); protected: HardwareDevice(Driver *driver, struct sr_dev_inst *structure); ~HardwareDevice(); shared_ptr get_shared_from_this(); - Driver *driver; + Driver *_driver; friend class Driver; friend class ChannelGroup; }; @@ -399,23 +399,23 @@ class SR_API Channel : { public: /** Current name of this channel. */ - string get_name(); + string name(); /** Set the name of this channel. * * @param name Name string to set. */ void set_name(string name); /** Type of this channel. */ - const ChannelType *get_type(); + const ChannelType *type(); /** Enabled status of this channel. */ - bool get_enabled(); + bool enabled(); /** Set the enabled status of this channel. * @param value Boolean value to set. */ void set_enabled(bool value); /** Get the index number of this channel. */ - unsigned int get_index(); + unsigned int index(); protected: Channel(struct sr_channel *structure); ~Channel(); - const ChannelType * const type; + const ChannelType * const _type; friend class Device; friend class ChannelGroup; friend class Session; @@ -429,13 +429,13 @@ class SR_API ChannelGroup : { public: /** Name of this channel group. */ - string get_name(); + string name(); /** List of the channels in this group. */ - vector > get_channels(); + vector > channels(); protected: ChannelGroup(Device *device, struct sr_channel_group *structure); ~ChannelGroup(); - vector channels; + vector _channels; friend class Device; }; @@ -444,16 +444,16 @@ class SR_API Trigger : public UserOwned { public: /** Name of this trigger configuration. */ - string get_name(); + string name(); /** List of the stages in this trigger. */ - vector > get_stages(); + vector > stages(); /** Add a new stage to this trigger. */ shared_ptr add_stage(); protected: Trigger(shared_ptr context, string name); ~Trigger(); - shared_ptr context; - vector stages; + shared_ptr _context; + vector _stages; friend class Deleter; friend class Context; friend class Session; @@ -465,9 +465,9 @@ class SR_API TriggerStage : { public: /** Index number of this stage. */ - int get_number(); + int number(); /** List of match conditions on this stage. */ - vector > get_matches(); + vector > matches(); /** Add a new match condition to this stage. * @param channel Channel to match on. * @param type TriggerMatchType to apply. */ @@ -478,7 +478,7 @@ public: * @param value Threshold value. */ void add_match(shared_ptr channel, const TriggerMatchType *type, float value); protected: - vector matches; + vector _matches; TriggerStage(struct sr_trigger_stage *structure); ~TriggerStage(); friend class Trigger; @@ -490,15 +490,15 @@ class SR_API TriggerMatch : { public: /** Channel this condition matches on. */ - shared_ptr get_channel(); + shared_ptr channel(); /** Type of match. */ - const TriggerMatchType *get_type(); + const TriggerMatchType *type(); /** Threshold value. */ - float get_value(); + float value(); protected: TriggerMatch(struct sr_trigger_match *structure, shared_ptr channel); ~TriggerMatch(); - shared_ptr channel; + shared_ptr _channel; friend class TriggerStage; }; @@ -513,10 +513,10 @@ public: void run(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *pkt); protected: - DatafeedCallbackFunction callback; + DatafeedCallbackFunction _callback; DatafeedCallbackData(Session *session, DatafeedCallbackFunction callback); - Session *session; + Session *_session; friend class Session; }; @@ -531,7 +531,7 @@ public: bool run(int revents); protected: SourceCallbackData(shared_ptr source); - shared_ptr source; + shared_ptr _source; friend class Session; }; @@ -567,13 +567,13 @@ protected: SOURCE_FD, SOURCE_POLLFD, SOURCE_IOCHANNEL - } type; - int fd; - Glib::PollFD pollfd; - Glib::RefPtr channel; - Glib::IOCondition events; - int timeout; - SourceCallbackFunction callback; + } _type; + int _fd; + Glib::PollFD _pollfd; + Glib::RefPtr _channel; + Glib::IOCondition _events; + int _timeout; + SourceCallbackFunction _callback; /** Deleter needed to allow shared_ptr use with protected destructor. */ class Deleter { @@ -612,7 +612,7 @@ public: * @param device Device to add. */ void add_device(shared_ptr device); /** List devices attached to this session. */ - vector > get_devices(); + vector > devices(); /** Remove all devices from this session. */ void remove_devices(); /** Add a datafeed callback to this session. @@ -641,7 +641,7 @@ public: /** Append raw logic data to the session file being saved. */ void append(void *data, size_t length, unsigned int unit_size); /** Get current trigger setting. */ - shared_ptr get_trigger(); + shared_ptr trigger(); /** Set trigger setting. * @param trigger Trigger object to use. */ void set_trigger(shared_ptr trigger); @@ -649,15 +649,15 @@ protected: Session(shared_ptr context); Session(shared_ptr context, string filename); ~Session(); - const shared_ptr context; - map > devices; - vector datafeed_callbacks; - map, SourceCallbackData *> source_callbacks; - bool saving; - bool save_initialized; - string save_filename; - uint64_t save_samplerate; - shared_ptr trigger; + const shared_ptr _context; + map > _devices; + vector _datafeed_callbacks; + map, SourceCallbackData *> _source_callbacks; + bool _saving; + bool _save_initialized; + string _save_filename; + uint64_t _save_samplerate; + shared_ptr _trigger; friend class Deleter; friend class Context; friend class DatafeedCallbackData; @@ -668,15 +668,15 @@ class SR_API Packet : public UserOwned { public: /** Type of this packet. */ - const PacketType *get_type(); + const PacketType *type(); /** Payload of this packet. */ - shared_ptr get_payload(); + shared_ptr payload(); protected: Packet(shared_ptr device, const struct sr_datafeed_packet *structure); ~Packet(); - shared_ptr device; - PacketPayload *payload; + shared_ptr _device; + PacketPayload *_payload; friend class Deleter; friend class Session; friend class Output; @@ -712,9 +712,9 @@ class SR_API Header : { public: /* Feed version number. */ - int get_feed_version(); + int feed_version(); /* Start time of this session. */ - Glib::TimeVal get_start_time(); + Glib::TimeVal start_time(); protected: Header(const struct sr_datafeed_header *structure); ~Header(); @@ -729,12 +729,12 @@ class SR_API Meta : { public: /* Mapping of (ConfigKey, value) pairs. */ - map get_config(); + map config(); protected: Meta(const struct sr_datafeed_meta *structure); ~Meta(); shared_ptr get_shared_pointer(Packet *parent); - map config; + map _config; friend class Packet; }; @@ -745,11 +745,11 @@ class SR_API Logic : { public: /* Pointer to data. */ - void *get_data_pointer(); + void *data_pointer(); /* Data length in bytes. */ - size_t get_data_length(); + size_t data_length(); /* Size of each sample in bytes. */ - unsigned int get_unit_size(); + unsigned int unit_size(); protected: Logic(const struct sr_datafeed_logic *structure); ~Logic(); @@ -764,17 +764,17 @@ class SR_API Analog : { public: /** Pointer to data. */ - float *get_data_pointer(); + float *data_pointer(); /** Number of samples in this packet. */ - unsigned int get_num_samples(); + unsigned int num_samples(); /** Channels for which this packet contains data. */ - vector > get_channels(); + vector > channels(); /** Measured quantity of the samples in this packet. */ - const Quantity *get_mq(); + const Quantity *mq(); /** Unit of the samples in this packet. */ - const Unit *get_unit(); + const Unit *unit(); /** Measurement flags associated with the samples in this packet. */ - vector get_mq_flags(); + vector mq_flags(); protected: Analog(const struct sr_datafeed_analog *structure); ~Analog(); @@ -788,11 +788,11 @@ class SR_API InputFormat : { public: /** Name of this input format. */ - string get_name(); + string name(); /** Description of this input format. */ - string get_description(); + string description(); /** Options supported by this input format. */ - map > get_options(); + map > options(); /** Create an input using this input format. * @param options Mapping of (option name, value) pairs. */ shared_ptr create_input(map options = {}); @@ -808,15 +808,15 @@ class SR_API Input : public UserOwned { public: /** Virtual device associated with this input. */ - shared_ptr get_device(); + shared_ptr device(); /** Send next stream data. * @param data Next stream data. */ void send(string data); protected: Input(shared_ptr context, const struct sr_input *structure); ~Input(); - shared_ptr context; - InputDevice *device; + shared_ptr _context; + InputDevice *_device; friend class Deleter; friend class Context; friend class InputFormat; @@ -831,7 +831,7 @@ protected: InputDevice(shared_ptr input, struct sr_dev_inst *sdi); ~InputDevice(); shared_ptr get_shared_from_this(); - shared_ptr input; + shared_ptr _input; friend class Input; }; @@ -840,20 +840,20 @@ class SR_API Option : public UserOwned { public: /** Short name of this option suitable for command line usage. */ - string get_id(); + string id(); /** Short name of this option suitable for GUI usage. */ - string get_name(); + string name(); /** Description of this option in a sentence. */ - string get_description(); + string description(); /** Default value for this option. */ - Glib::VariantBase get_default_value(); + Glib::VariantBase default_value(); /** Possible values for this option, if a limited set. */ - vector get_values(); + vector values(); protected: Option(const struct sr_option *structure, shared_ptr structure_array); ~Option(); - shared_ptr structure_array; + shared_ptr _structure_array; friend class Deleter; friend class InputFormat; friend class OutputFormat; @@ -865,11 +865,11 @@ class SR_API OutputFormat : { public: /** Name of this output format. */ - string get_name(); + string name(); /** Description of this output format. */ - string get_description(); + string description(); /** Options supported by this output format. */ - map > get_options(); + map > options(); /** Create an output using this format. * @param device Device to output for. * @param options Mapping of (option name, value) pairs. */ @@ -894,9 +894,9 @@ protected: Output(shared_ptr format, shared_ptr device, map options); ~Output(); - const shared_ptr format; - const shared_ptr device; - const map options; + const shared_ptr _format; + const shared_ptr _device; + const map _options; friend class Deleter; friend class OutputFormat; }; @@ -906,14 +906,14 @@ template class SR_API EnumValue { public: /** The enum constant associated with this value. */ - T get_id() const { return id; } + T id() const { return _id; } /** The name associated with this value. */ - string get_name() const { return name; } + string name() const { return _name; } protected: - EnumValue(T id, const char name[]) : id(id), name(name) {} + EnumValue(T id, const char name[]) : _id(id), _name(name) {} ~EnumValue() {} - const T id; - const string name; + const T _id; + const string _name; }; #include "enums.hpp" diff --git a/bindings/java/org/sigrok/core/classes/classes.i b/bindings/java/org/sigrok/core/classes/classes.i index c7173e4a..4fe326d1 100644 --- a/bindings/java/org/sigrok/core/classes/classes.i +++ b/bindings/java/org/sigrok/core/classes/classes.i @@ -376,8 +376,5 @@ typedef jobject jsourcecallback; } } -/* Currently broken due to some std::map typemap issues. */ -%ignore sigrok::Meta::get_config; - %include "doc.i" %include "bindings/swig/classes.i" diff --git a/bindings/python/sigrok/core/classes.i b/bindings/python/sigrok/core/classes.i index b7552890..a01d18af 100644 --- a/bindings/python/sigrok/core/classes.i +++ b/bindings/python/sigrok/core/classes.i @@ -287,7 +287,7 @@ std::map dict_to_map_string(PyObject *dict) /* Convert from a Python type to Glib::Variant, according to config key data type. */ Glib::VariantBase python_to_variant_by_key(PyObject *input, const sigrok::ConfigKey *key) { - enum sr_datatype type = key->get_data_type()->get_id(); + enum sr_datatype type = key->data_type()->id(); if (type == SR_T_UINT64 && PyInt_Check(input)) return Glib::Variant::create(PyInt_AsLong(input)); @@ -309,7 +309,7 @@ Glib::VariantBase python_to_variant_by_key(PyObject *input, const sigrok::Config Glib::VariantBase python_to_variant_by_option(PyObject *input, std::shared_ptr option) { - GVariantType *type = option->get_default_value().get_type().gobj(); + GVariantType *type = option->default_value().get_type().gobj(); if (type == G_VARIANT_TYPE_UINT64 && PyInt_Check(input)) return Glib::Variant::create(PyInt_AsLong(input)); @@ -400,7 +400,7 @@ std::map dict_to_map_options(PyObject *dict, std::shared_ptr _create_input_kwargs(PyObject *dict) { return $self->create_input( - dict_to_map_options(dict, $self->get_options())); + dict_to_map_options(dict, $self->options())); } } @@ -419,7 +419,7 @@ std::map dict_to_map_options(PyObject *dict, std::shared_ptr device, PyObject *dict) { return $self->create_output(device, - dict_to_map_options(dict, $self->get_options())); + dict_to_map_options(dict, $self->options())); } } diff --git a/bindings/swig/classes.i b/bindings/swig/classes.i index fe89952c..983fcdc2 100644 --- a/bindings/swig/classes.i +++ b/bindings/swig/classes.i @@ -139,12 +139,6 @@ template< class T > class enable_shared_from_this; %ignore sigrok::DatafeedCallbackData; %ignore sigrok::SourceCallbackData; -%include "libsigrok/libsigrok.hpp" - -namespace sigrok { -%include "libsigrok/enums.hpp" -} - #define SWIG_ATTRIBUTE_TEMPLATE %include "attribute.i" @@ -167,108 +161,114 @@ typedef std::map } %attributeval(sigrok::Context, - map_string_Driver, drivers, get_drivers); + map_string_Driver, drivers, drivers); %attributeval(sigrok::Context, - map_string_InputFormat, input_formats, get_input_formats); + map_string_InputFormat, input_formats, input_formats); %attributeval(sigrok::Context, - map_string_OutputFormat, output_formats, get_output_formats); + map_string_OutputFormat, output_formats, output_formats); %attributestring(sigrok::Context, - std::string, package_version, get_package_version); + std::string, package_version, package_version); %attributestring(sigrok::Context, - std::string, lib_version, get_lib_version); + std::string, lib_version, lib_version); %attribute(sigrok::Context, - const sigrok::LogLevel *, log_level, get_log_level, set_log_level); + const sigrok::LogLevel *, log_level, log_level, set_log_level); %attributestring(sigrok::Context, - std::string, log_domain, get_log_domain, set_log_domain); + std::string, log_domain, log_domain, set_log_domain); -%attributestring(sigrok::Driver, std::string, name, get_name); -%attributestring(sigrok::Driver, std::string, long_name, get_long_name); +%attributestring(sigrok::Driver, std::string, name, name); +%attributestring(sigrok::Driver, std::string, long_name, long_name); %attributestring(sigrok::InputFormat, - std::string, name, get_name); + std::string, name, name); %attributestring(sigrok::InputFormat, - std::string, description, get_description); + std::string, description, description); %attributestring(sigrok::Input, - std::shared_ptr, device, get_device); + std::shared_ptr, device, device); %attributestring(sigrok::Option, - std::string, id, get_id); + std::string, id, id); %attributestring(sigrok::Option, - std::string, name, get_name); + std::string, name, name); %attributestring(sigrok::Option, - std::string, description, get_description); + std::string, description, description); /* Currently broken on Python due to some issue with variant typemaps. */ /* %attributeval(sigrok::Option, - Glib::VariantBase, default_value, get_default_value); */ + Glib::VariantBase, default_value, default_value); */ %attributeval(sigrok::Option, - std::vector, values, get_values); + std::vector, values, values); %attributestring(sigrok::OutputFormat, - std::string, name, get_name); + std::string, name, name); %attributestring(sigrok::OutputFormat, - std::string, description, get_description); + std::string, description, description); %attributeval(sigrok::OutputFormat, - map_string_Option, options, get_options); + map_string_Option, options, options); -%attributestring(sigrok::Device, std::string, description, get_description); -%attributestring(sigrok::Device, std::string, vendor, get_vendor); -%attributestring(sigrok::Device, std::string, model, get_model); -%attributestring(sigrok::Device, std::string, version, get_version); +%attributestring(sigrok::Device, std::string, description, description); +%attributestring(sigrok::Device, std::string, vendor, vendor); +%attributestring(sigrok::Device, std::string, model, model); +%attributestring(sigrok::Device, std::string, version, version); %attributeval(sigrok::Device, std::vector >, - channels, get_channels); + channels, channels); %attributeval(sigrok::Device, map_string_ChannelGroup, - channel_groups, get_channel_groups); + channel_groups, channel_groups); /* Using %attributestring for shared_ptr attribute. See http://sourceforge.net/p/swig/mailman/message/31832070/ */ %attributestring(sigrok::HardwareDevice, - std::shared_ptr, driver, get_driver); + std::shared_ptr, driver, driver); -%attributestring(sigrok::Channel, std::string, name, get_name, set_name); -%attribute(sigrok::Channel, bool, enabled, get_enabled, set_enabled); -%attribute(sigrok::Channel, const sigrok::ChannelType *, type, get_type); -%attribute(sigrok::Channel, unsigned int, index, get_index); +%attributestring(sigrok::Channel, std::string, name, name, set_name); +%attribute(sigrok::Channel, bool, enabled, enabled, set_enabled); +%attribute(sigrok::Channel, const sigrok::ChannelType *, type, type); +%attribute(sigrok::Channel, unsigned int, index, index); -%attributestring(sigrok::ChannelGroup, std::string, name, get_name); +%attributestring(sigrok::ChannelGroup, std::string, name, name); %attributeval(sigrok::ChannelGroup, std::vector >, - channels, get_channels); + channels, channels); -%attributestring(sigrok::Trigger, std::string, name, get_name); +%attributestring(sigrok::Trigger, std::string, name, name); %attributeval(sigrok::Trigger, std::vector >, - stages, get_stages); + stages, stages); -%attribute(sigrok::TriggerStage, int, number, get_number); +%attribute(sigrok::TriggerStage, int, number, number); %attributeval(sigrok::TriggerStage, std::vector >, - matches, get_matches); + matches, matches); %attributestring(sigrok::TriggerMatch, - std::shared_ptr, channel, get_channel); -%attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, get_type); -%attribute(sigrok::TriggerMatch, float, value, get_value); + std::shared_ptr, channel, channel); +%attribute(sigrok::TriggerMatch, const sigrok::TriggerMatchType *, type, type); +%attribute(sigrok::TriggerMatch, float, value, value); %attributeval(sigrok::Session, std::vector >, - devices, get_devices); + devices, devices); %attributestring(sigrok::Session, - std::shared_ptr, trigger, get_trigger, set_trigger); + std::shared_ptr, trigger, trigger, set_trigger); %attributestring(sigrok::Packet, - std::shared_ptr, payload, get_payload); + std::shared_ptr, payload, payload); -%attributeval(sigrok::Meta, map_ConfigKey_Variant, config, get_config); +%attributeval(sigrok::Meta, map_ConfigKey_Variant, config, config); -%attribute(sigrok::Analog, int, num_samples, get_num_samples); -%attribute(sigrok::Analog, const sigrok::Quantity *, mq, get_mq); -%attribute(sigrok::Analog, const sigrok::Unit *, unit, get_unit); -%attributeval(sigrok::Analog, std::vector, mq_flags, get_mq_flags); +%attribute(sigrok::Analog, int, num_samples, num_samples); +%attribute(sigrok::Analog, const sigrok::Quantity *, mq, mq); +%attribute(sigrok::Analog, const sigrok::Unit *, unit, unit); +%attributeval(sigrok::Analog, std::vector, mq_flags, mq_flags); + +%include "libsigrok/libsigrok.hpp" + +namespace sigrok { +%include "libsigrok/enums.hpp" +}