<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello all</p>
<p align="justify">I'm starting the development of Java Native
Interface (JNI) for PROJ on a separated GitHub repository [1],
with completion date targeted for December. We have chosen to use
the C++ API instead than the C API, even if the C API may be more
stable, for the following reasons:</p>
<div align="justify">
<ul>
<li>Straightforward mapping to ISO 19111 objects. The C API in
comparison uses a conceptual model which is particular to
PROJ.</li>
<li>It seems possible to wrap the C++ objects into classical <tt>PJ</tt>
structures using the <tt>PJ.iso_obj</tt> field, but it seems
to impose a significant overhead (e.g. the process of wrapping
an ISO 19111 object into a <tt>PJ</tt> involves formatting
the object in a PROJ string and parsing it in <tt>PJ</tt>).</li>
<li>Many (not all) C++ objects are immutable, which make easier
to be thread-safe.</li>
</ul>
</div>
<p align="justify">I have a first series of questions in order to
help me to make some design choices. Can anyone gives some tips on
the following?</p>
<p><br>
</p>
<h2>PJ_CONTEXT</h2>
<p align="justify">I understand that a given <tt>PJ_CONTEXT</tt>
can be used by only one thread at a time. But after a thread has
(at least temporarily) finished to use a <tt>PJ_CONTEXT</tt>, can
that <tt>PJ_CONTEXT</tt> be given to another thread (making sure
that no other thread uses it in same time), or is it preferable to
restrict the use of a <tt>PJ_CONTEXT</tt> to the thread that
created it?</p>
<p align="justify">Are <tt>PJ_CONTEXT</tt> expected to be short
lived (extreme case: a create/destroy cycle in a each JNI call),
long lived (e.g. the whole lifetime of a Java Virtual Machine), or
something between the two (e.g. I could setup a pool of <tt>PJ_CONTEXT</tt>
which automatically destroys instances that were unused for more
than 2 minutes)? I guess the answer depends on the cost of <tt>PJ_CONTEXT</tt>
create/destroy cycles compared to the cost of holding them a long
time.<br>
</p>
<p align="justify">Above questions are because I wish to avoid
exposing <tt>PJ_CONTEXT</tt> in Java API, and instead have them
managed automatically.</p>
<p align="justify"><br>
</p>
<h2 align="justify">Disposal at shutdown time</h2>
<p align="justify">What is the consequence if an application using
PROJ exits without destroying all PROJ objects? Is there a risk
that PROJ leaves some files (e.g. related to the use of SQLite) in
a locked or corrupted state? I ask because by default, Java does
not wait for all objects to be garbage collected when an
application terminates. If we need to ensure that all PROJ objects
are properly destroyed at exit time, then I need to register a
shutdown hook for them (not a difficult task - I'm just checking
if it is necessary).</p>
<p align="justify"><br>
</p>
<h2 align="justify">Encoding of std::string</h2>
<p align="justify">The C++ API has many methods expecting or
returning a <tt>std::string</tt> object. In my reading of C++
specification, <tt>std::string</tt> seems to be encoding
agnostic. Does PROJ makes any assumption on the encoding of <tt>std::string</tt>
instances? Is it okay to unconditionally use UTF-8 regardless the
platform encoding when using <tt>std::string</tt> with PROJ API?
Or should I unconditionally convert UTF-8 to platform encoding
before to build a <tt>std::string</tt>?<br>
</p>
<p align="justify"> Thanks,</p>
<p align="justify"> Martin<br>
</p>
<pre>[1] <a class="moz-txt-link-freetext" href="https://github.com/Kortforsyningen/PROJ-JNI">https://github.com/Kortforsyningen/PROJ-JNI</a>
</pre>
</body>
</html>