Martin Vajnar [Mon, 5 Aug 2013 21:37:29 +0000 (23:37 +0200)]
ROBOT_DEMO: fix sync. problems in publisher for "motion_speed"
Don't use synchronized(), because it may block the setSpeed() and prevent
receiving new data from accelerometer. The isSent variable is now used
to determine whether we need new data.
Add robot's IP address to the list of fellow managers.
Martin Vajnar [Mon, 5 Aug 2013 19:26:29 +0000 (21:26 +0200)]
ROBOT_DEMO: fix sync. problems in HokuyoView
Set new data only if the previous batch has been drawn and clone the newly
arrived data array. This prevents concurrent access problems when
the previous batch is being drawn on the UI thread and new data arrives
through ORTE's receive thread.
Martin Vajnar [Fri, 26 Jul 2013 08:44:46 +0000 (10:44 +0200)]
JORTE: improve ByteOrder handling
Store the ByteOrder of MessageData's ByteBuffer in receive callback
structure in C (in case someone reuses already created MessageData instance
with new subscriber).
Martin Vajnar [Thu, 25 Jul 2013 12:45:43 +0000 (14:45 +0200)]
JORTE: switch from deserialize function to endianness callback
Yesterday's attempt at setting the byte order of ByteBuffer through
a deserialize function has one significant drawback and that is if more
than one data type is defined under one VM instance (thus accessible by
other threads) and subscribers are then registered for these data types
the deserialize function will stop working correctly, because there are
no parameter structures being passed to it, except for the CDR_Codec,
thus it had to use a global reference to a byte buffer which is
unfortunately overwritten the moment a new data type is registered.
If the deserialize function for the previously registered data type
is invoked it then tampers with ByteBuffer settings of a newly registered
data type.
Martin Vajnar [Tue, 23 Jul 2013 09:09:39 +0000 (11:09 +0200)]
JORTE: fix memory leak and add DomainEvents to DomainMgr
Memory leaks in jORTEDomainAppCreate() and jORTEDomainMgrCreate()
(domain events callback structure) are fixed. Domain events callbacks
are placed in a separate file. Their prototypes are placed in "jorte/
/jorte_protos_api.h". This way they could be used by DomainApp
and DomainMgr.
Native functions in both DomainApp.java and DomainMgr.java are now non-
static. This allows native domain destructor to free the memory allocated
to domain events callback structure.
It is now also possible to pass null for DomainEvents or DomainProp to
DomainApp and DomainMgr constructors.
The header file onLoad.h is removed and the findClass() prototype is placed
into "jorte/jorte_protos_api.h".
Martin Vajnar [Sun, 21 Jul 2013 08:25:50 +0000 (10:25 +0200)]
JORTE: remove unused code
Since the domain is started (receiving and sending threads) either by
calling ORTEDomainAppCreate() or ORTEDomainMgrCreate(), there is no need
to have DomainStart() on the Java side.
Martin Vajnar [Fri, 19 Jul 2013 09:37:04 +0000 (11:37 +0200)]
ROBOT_DEMO: completely rewritten
This adds complete rewrite of the demo application. Buttons are now removed
from views and are instead placed to a menu. At the start a domain manager
and an application domain are created under which every subscriber
and publisher is launched. Support for hokuyo_scan is added.
Martin Vajnar [Fri, 19 Jul 2013 09:20:39 +0000 (11:20 +0200)]
JORTE: fix subscription destruction
Destroy subscription first, then destroy references to objects
in subscription callback. This prevents SEGFAULTs from the receiving
thread, that tries to save received instance to a non-existent object.
DeleteLocalReference was replaced with DeleteGlobalReference, since we are
destroying a global reference. This prevents dvmAbort() being called
on Android. This also fixes a memory leak (the ctx->msg reference was not
deleted).
Martin Vajnar [Tue, 16 Jul 2013 09:48:07 +0000 (11:48 +0200)]
JORTE: don't use finalizers in Java classes
This replaces finalizers with explicit destroy() functions, because the
order in which objects with no reference in the VM are garbage-collected
is not guaranteed. This caused trouble with finalization of DomainApp
and Publisher (or Subscriber). If the DomainApp was destroyed before
the Publisher (or Subscriber) the Publisher's finalizer would have been
stuck (eventually leading to TimeoutException to be thrown).
Martin Vajnar [Sun, 14 Jul 2013 18:08:07 +0000 (20:08 +0200)]
JORTE: switch to direct ByteBuffer
This commit significantly changes the way new issues are sent and received
both on the Java side and on the C side.
In the past there was one Java instance of HeapByteBuffer in the
MessageData class. ByteBuffer is used to perform serialization and
deserialization of received and sent issues in Java. It is compatible with
the CORBA standard that is used in the main ORTE library.
The HeapByteBuffer has one significant drawback. It allocates memory
on the heap managed by Java VM's garbage collector and when accessing
the backing array from C it has to copy the entire array to new space
in memory outside the VM. Added to that the backing array wasn't accessed
as an array object from the C code, but rather every byte from the Java
buffer was copied to a C byte array or vice versa (publisher x subscriber
part). This adds a lot of overhead (calling JNI functions to obtain new
values).
Instead the DirectByteBuffer is now used which allocates memory directly
(outside of Java VM) through malloc() and stores the pointer in such a way,
that it is easily accesible from C code using GetDirectBufferAddress,
that returns (void *). The Java part behaves much the same as normal
(Heap) ByteBuffer. The allocated byte array could be used like any other
C array and the VM ensures that the memory region allocated by direct
ByteBuffer is contiguous. This is very useful, because normal Java arrays
are not guaranteed to be contiguous which makes them difficult to handle,
because JNI functions must be called that make copies of them in a
contiguous space and that adds another overhead.
As a bonus the C code for both publisher and subscriber Java wrappers
is much shorter and simpler than it used to be.
Martin Vajnar [Sun, 14 Jul 2013 12:57:21 +0000 (14:57 +0200)]
JORTE: fix endianness the proper way
Use the GNU C compiler macro __BYTE_ORDER__ to set data_endian on the C
side and ByteOrder.nativeOrder() function to set ByteBuffer's order
in the MessageData class on the Java side.
Martin Vajnar [Sat, 13 Jul 2013 16:50:14 +0000 (18:50 +0200)]
ROBOT_DEMO: decrease CPU usage
Now there are 2 major threads on the Java side. The first one is main which
takes care of drawing GUI and receives callbacks from accelerometer.
The second one computes and sends values to the robot's motors.
Martin Vajnar [Sun, 7 Jul 2013 17:24:59 +0000 (19:24 +0200)]
ANDROID: add support for Android
Add preliminary Android library.
Note: Current Android NDK doesn't allow libraries to have assets folder,
but we place the ortemanager in there. At current point it is necessary
for applications using this library to either manually copy the compiled
ortemanager over to their own assets folder or to create a symlink.
Martin Vajnar [Sun, 7 Jul 2013 16:50:01 +0000 (18:50 +0200)]
JORTE: prepare for Android (fix class loader problems + add logging)
This fixes class loading problems on Android.
As per the Android Documentation (http://developer.android.com/training/articles/perf-jni.html#faq_FindClass):
Android's Dalvik VM uses the loader associated with the method
at the top of the interpreted stack, or if there isn't one
(because the thread was just attached), it uses the "system" class
loader, for FindClass calls.
To overcome this the JNI_OnLoad function is used. Any FindClass calls made
from there will happen in the context of the class loader used to load
the shared library. So from there one class that will always be present
in the JORTE Java package is chosen (org.ocera.orte.JOrte) and it's
class loader is stored as a global reference inside the VM (thus shared
by all processes attached to the VM) and as a static variable (accesible
only by functions from the onLoad.c file) on the C side.Also the findClass
and findLoadedClass method IDs are cached. To simplify the class loading
process inside C functions the findClass functions is written.
Android also doesn't implement the printf function. However it does have
a logging capability, so a variadic macro replacing occurences of printf
with __android_log_print is used.
Pavel Pisa [Fri, 20 Sep 2013 10:11:55 +0000 (12:11 +0200)]
ANDROID: added variant of orte_config.h which provides configuration for android build.
The file orte_config_android.h provides Android contents of
orte_config.h used by Martin Vajnar <martin.vajnar@gmail.com>
during ORTE Android support development which was introduced
by his patches
ORTE: Android hack - define HAVE_CONFIG_H
ANDROID: allow compilation from command line add new orte_config.h
This allows compilation of native code with ndk-build and
of Java part with ant.
Pavel Pisa [Sat, 14 Sep 2013 17:16:12 +0000 (19:16 +0200)]
Use portable and type-safe way to obtain network interface addresses where available
Use of SIOCGIFCONF is quite error prone. It fills fixed sized
elements array on Linux filled only by IPv4 (AF_INET).
On the other hand on BSD it returns all addresses including
hardware ones and IPv6. It requires variable size for
entries where address does not fit into struct sockaddr.
But switching rules seems to differ even between BSD flavors.
On the other hand getifaddrs() and struct ifaddrs
are defined with potability and extendability in mind.
Michal Sojka [Sat, 14 Sep 2013 14:16:20 +0000 (16:16 +0200)]
Fix a problem in configure on Windows
On Windows, we link ORTE against a version of pthread library shipped
in our tree. Therefore we add some switches to linker command line.
The problem is that this command line is also used for all configure
tests. Since our library is not yet compiled at compile time, it
caused many configure checks to fail even if they should succeed.
With this change, I'm able to cross-compile ORTE for Windows on Debian
Wheezy with mingw32 package. The used configure command was: