Daniel Elstner [Mon, 26 Oct 2015 06:04:10 +0000 (07:04 +0100)]
C++: Avoid const ref args to appease Java bindings
The Java bindings currently have some weird problem with function
arguments passed by const reference. Not all types are affected,
but the collection types that involve custom typemaps are.
For now, revert back to pass-by-value for the problematic types.
Daniel Elstner [Mon, 26 Oct 2015 04:18:06 +0000 (05:18 +0100)]
C++: Use C++98 syntax for default arguments to appease SWIG
Looks like SWIG silently ignores default arguments specified via
aggregate initialization. This is rather unfortunate, especially
if the argument types are complex.
Daniel Elstner [Thu, 15 Oct 2015 17:21:28 +0000 (19:21 +0200)]
C++: Replace custom deleters with std::default_delete
Replace custom Deleter classes with std::default_delete<>, declared
as friend so it can invoke the private destructor. Inexplicably,
std::shared_ptr<> does not use default_delete<> by default, so it
is still necessary to explicitly specify the deleter when creating
shared_ptr instances.
With this, unique_ptr and shared_ptr instances now use the same
default delete mechanism.
Daniel Elstner [Thu, 15 Oct 2015 16:32:44 +0000 (18:32 +0200)]
C++: Use smart pointers instead of manual delete
Make use of std::unique_ptr<> to manage the lifetime of members
or container elements, so that manual invocations of delete can
be avoided. This also provides for exception safety.
Since std::unique_ptr<> is only movable but not copyable, adapt
the code to avoid copies and assignments of these pointers.
Daniel Elstner [Sun, 11 Oct 2015 15:57:30 +0000 (17:57 +0200)]
C++: Move C struct pointers out of ownership classes
Reduce needless over-generalization. There is no design need
for the ParentOwned and UserOwned classes to contain the C base
struct pointer. Instead, just make the _structure pointer a
private member of each class that needs one.
Daniel Elstner [Sun, 11 Oct 2015 12:31:18 +0000 (14:31 +0200)]
SWIG: Hack around SWIG segfault on private destructors
Apparently this problem has been fixed in SWIG 3.0.6. However,
until we can require that version, define "private" as "protected"
when running the SWIG parser.
Daniel Elstner [Sun, 11 Oct 2015 11:57:42 +0000 (13:57 +0200)]
C++: Make value get accessors const
Declare accessor methods that return value members const. For now,
skip all cases where constness would have to be applied transitively
to shared objects.
Daniel Elstner [Sun, 11 Oct 2015 10:35:01 +0000 (12:35 +0200)]
C++: Make some methods static to match the C API
Context::package_version() and Context::lib_version() do not access
context state and should be static. However, leave the logging
related methods alone for now, as making them static would entail
making the callback data a global static, since the C API lacks
destroy notification callbacks.
Daniel Elstner [Wed, 14 Oct 2015 18:56:51 +0000 (20:56 +0200)]
C++: Declare all callbacks invoked from C noexcept
If one of these functions does throw an exception, std::terminate()
will be called. Without this, the behavior is undefined since the C
stack is not prepared to deal with exceptions.
Daniel Elstner [Sun, 11 Oct 2015 10:12:28 +0000 (12:12 +0200)]
SWIG: Define "noexcept" empty to work around SWIG bug
The SWIG 2.0.12 on my system bails out with a syntax error on the
"noexcept" keyword in C++11 code. Define "noexcept" to nothing (for
the SWIG parser only) to work around this problem.
Daniel Elstner [Sun, 11 Oct 2015 01:12:02 +0000 (03:12 +0200)]
C++: Use move() and avoid passing containers by value
Make use of std::move() to transfer arguments passed in by value.
Take complex container arguments by const reference, as passing
those by value is rather unorthodox even for C++11 style code.
Martin Ling [Tue, 20 Oct 2015 23:29:50 +0000 (00:29 +0100)]
java: Don't use SWIG attribute mechanism.
Using the attribute mechanism results in badly named wrappers like
getLog_level(), as well as incompletely applied typemaps for templated
container types. If we just avoid this mechanism entirely, we get the
same foo() and set_foo() accessors as we have in the C++ API.
Tilman Sauerbeck [Thu, 15 Oct 2015 20:38:12 +0000 (22:38 +0200)]
drivers: Fix behaviour when trying to set an invalid capture ratio.
Trying to configure an invalid capture ratio would reset the
previously configured value. Instead, we should just reject the
new value and keep the original one.
Daniel Elstner [Fri, 9 Oct 2015 00:35:47 +0000 (02:35 +0200)]
session: Make sr_session_run() optional
Introduce a new API function sr_session_stopped_callback_set()
which can be used to receive notification when a session stops
running. This allows applications to integrate libsigrok event
processing with their own main loop, instead of blocking in
sr_session_run().
Daniel Elstner [Sat, 3 Oct 2015 12:08:32 +0000 (14:08 +0200)]
build: Do not define FIRMWARE_DIR on Windows
The hard-coded location is bound to be wrong anyway. Instead, rely
on the new resource lookup code to find the firmware files in a
location relative to the library or executable.
Daniel Elstner [Fri, 2 Oct 2015 18:09:46 +0000 (20:09 +0200)]
session-file: Use 32-bit int for channel count
SR_CONF_NUM_LOGIC_CHANNELS is defined as SR_T_INT32. Create the
GVariant with the correct type to avoid a type mismatch error in
sr_variant_type_check().
Daniel Elstner [Sat, 26 Sep 2015 11:38:30 +0000 (13:38 +0200)]
resource: New internal API for accessing resource files
The resource API provides a generic means for accessing resources
that are bundled with sigrok, such as device firmware files. Since
the manner of resource bundling is platform-dependent, users of
libsigrok may override the functions used to open, close and read
a resource. The default implementation accesses resources as files
located in one of the XDG data directories or a directory defined
at compile time.
Daniel Elstner [Sun, 20 Sep 2015 18:32:03 +0000 (20:32 +0200)]
srzip: Avoid low-level FD-based I/O
Use in-memory buffers instead of temporary files. This avoids
the need for low-level I/O on the FD returned by g_mkstemp().
Refactor the code accordingly. Also plug a number of leaks and
tighten the error checking.
Daniel Elstner [Sun, 20 Sep 2015 12:10:42 +0000 (14:10 +0200)]
session-file: Remove old session save API
Completely remove the old session save code that has been
superseded by the srzip output module. Also refactor a bit,
plug a number of leaks and tighten the error checking.
Daniel Elstner [Sat, 19 Sep 2015 18:43:25 +0000 (20:43 +0200)]
input: Use fseeko/ftello to get the size of a file
Introduce the sr_file_get_size() utility function to retrieve the
size of an open FILE stream. This is based on fseeko() followed by
ftello(), which are POSIX functions but quite portable in practice.
Since these calls operate on FILE streams instead of filenames, the
issue of filename encoding no longer arises.
Daniel Elstner [Fri, 18 Sep 2015 22:24:50 +0000 (00:24 +0200)]
input: Clean up input file scanning
Do not use Unix low-level I/O for reading a regular input file.
Read in the file header once and re-use the buffer for all input
modules participating in the scan. Also re-use a prefilled metadata
table instead of creating it anew for each input module tried.
Uwe Hermann [Fri, 25 Sep 2015 06:52:58 +0000 (08:52 +0200)]
Fix a few "value never read" scan-build warnings.
This fixes parts of bug #423.
The list of fixed warnings:
src/output/srzip.c:285:3: warning: Value stored to 'ret' is never read
ret = zip_append(o, logic->data, logic->unitsize, logic->length);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/scpi/scpi.c:610:2: warning: Value stored to 'ret' is never read
ret = SR_OK;
^ ~~~~~
src/scpi/scpi.c:667:2: warning: Value stored to 'ret' is never read
ret = SR_OK;
^ ~~~~~
src/dmm/vc870.c:410:2: warning: Value stored to 'info_local' is never read
info_local = (struct vc870_info *)info;
^ ~~~~~~~~~~~~~~~~~~~~~~~~~
src/hardware/conrad-digi-35-cpu/api.c:130:2: warning: Value stored to 'ret' is never read
ret = SR_OK;
^ ~~~~~
src/hardware/fx2lafw/api.c:658:2: warning: Value stored to 'timeout' is never read
timeout = fx2lafw_get_timeout(devc);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~
src/hardware/gmc-mh-1x-2x/protocol.c:941:3: warning: Value stored to 'retc' is never read
retc = SR_ERR_ARG;
^ ~~~~~~~~~~
src/hardware/gmc-mh-1x-2x/api.c:168:2: warning: Value stored to 'model' is never read
model = METRAHIT_NONE;
^ ~~~~~~~~~~~~~
src/hardware/ikalogic-scanalogic2/api.c:325:2: warning: Value stored to 'ret' is never read
ret = SR_OK;
^ ~~~~~
src/hardware/openbench-logic-sniffer/api.c:185:3: warning: Value stored to 'devc' is never read
devc = sdi->priv;
^ ~~~~~~~~~
src/hardware/rigol-ds/api.c:813:3: warning: Value stored to 'devc' is never read
devc = sdi->priv;
^ ~~~~~~~~~
src/hardware/scpi-pps/api.c:405:2: warning: Value stored to 'ret' is never read
ret = SR_OK;
^ ~~~~~
src/hardware/yokogawa-dlm/api.c:239:2: warning: Value stored to 'ret' is never read
ret = SR_ERR_NA;
^ ~~~~~~~~~
Daniel Elstner [Tue, 22 Sep 2015 04:54:33 +0000 (06:54 +0200)]
demo: Increase timer interval to 100 ms
Timer intervals shorter than about 100 ms are unnecessarily taxing
on system resources. Also, on systems like Windows the smallest
resolvable time unit without using high precision timers is about
15 ms. Regular timer intervals should be well above that value to
avoid being dominated by noise and round-off.
scpi/usbtmc: Implement Rigol DS1000 workaround on any firmware version.
Firmware versions starting with 00.02.04 apparently cause the in and out
bulk endpoints to end up in a HALT state. This is likely related to the
larger transfer size quirk implemented in the Linux kernel for the Rigol
DS1000: this USBTMC implementation does not have that workaround.
Instead, if the firmware version is >= 00.02.04, both endpoints have the HALT
condition cleared on device close.