<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 01/15/2013 10:41 AM, Joe Armstrong
wrote:<br>
</div>
<blockquote
cite="mid:CAANBt-pbTuQfZZS_bsksjb51tr3pB2KvnYr9_-GGjJBTLaqC0A@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div>Golly - I read the code - you modified error_handler.erl
!!!! <br>
<br>
So what happens is ...<br>
<br>
I call android:fooBar(Args) - fooBar is not defined in
android.erl<br>
so it's caught in error_handler and then
android:rpc(fooBar, [...]) is called<br>
and this ends up as a Json call to a socket -<br>
<br>
</div>
</div>
</blockquote>
Yes, that is what happens. <br>
<blockquote
cite="mid:CAANBt-pbTuQfZZS_bsksjb51tr3pB2KvnYr9_-GGjJBTLaqC0A@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div> (aside) I'm not sure I'm totally happy with modifying
the error_handler for this,<br>
what's wrong with calling android:rpc(Func, Args) in your
code and not<br>
changing the error handler?<br>
(/aside) <br>
<br>
</div>
</div>
</blockquote>
I think calling android:Func(Args) is prettier. The fact that it is
an rpc call is hidden in this way. Python4android provides a similar
api. Python has a supported way of handling missing functions,
Erlang has not (as far as I know). Have a look at the android api in
python4android:
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a
href="http://code.google.com/p/android-scripting/source/browse/python/ase/android.py">http://code.google.com/p/android-scripting/source/browse/python/ase/android.py</a>
<br>
If I interpret "error_handler" as "missing_function_handler", my
conscience can survive this hack.<br>
<br>
Note that I also implemented dynamic code compilation (as Python
does) by modifying error_handler.<br>
<blockquote
cite="mid:CAANBt-pbTuQfZZS_bsksjb51tr3pB2KvnYr9_-GGjJBTLaqC0A@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div><br>
It appears that SL4A is interfaced via a socket carrying
JSON encode terms - is that correct?<br>
<br>
</div>
</div>
</blockquote>
Yes, that is correct.<br>
<br>
<blockquote
cite="mid:CAANBt-pbTuQfZZS_bsksjb51tr3pB2KvnYr9_-GGjJBTLaqC0A@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div> I Googled a bit to see if I could find where the
protocol is defined - but found nothing.<br>
</div>
</div>
</blockquote>
I believe Python's android module was my main source of information,
together with
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a
href="http://code.google.com/p/android-scripting/wiki/InterpreterDeveloperGuide">http://code.google.com/p/android-scripting/wiki/InterpreterDeveloperGuide</a>
<blockquote
cite="mid:CAANBt-pbTuQfZZS_bsksjb51tr3pB2KvnYr9_-GGjJBTLaqC0A@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div>
Where, for example, is the handshake that you perform in
android:init *specified*<br>
<br>
</div>
</div>
</blockquote>
It is specified at the bottom of this page, under RPC
Authentication:
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<a
href="http://code.google.com/p/android-scripting/wiki/InterpreterDeveloperGuide">http://code.google.com/p/android-scripting/wiki/InterpreterDeveloperGuide</a>
<blockquote
cite="mid:CAANBt-pbTuQfZZS_bsksjb51tr3pB2KvnYr9_-GGjJBTLaqC0A@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div> If I want to call an andoid function I need to create a
JSON argument list from erlang -<br>
what are the calling conventions? <br>
<br>
</div>
</div>
</blockquote>
I included json2.erl from yaws, by A2Z Development USA, Inc. So,
from that source:<br>
<br>
%%% This module translates JSON types into the following Erlang
types:<br>
%%%<br>
%%% JSON Erlang<br>
%%% ---- ------<br>
%%% number number<br>
%%% string string<br>
%%% array {array, ElementList}<br>
%%% object tagged proplist with string keys
(i.e. {struct, PropList} )<br>
%%% true, false, null atoms 'true', 'false', and 'null'<br>
%%%<br>
%%% Character Sets: the external representation, and the internal<br>
%%% representation of strings, are lists of UTF-8 code units.<br>
%%%<br>
%%% Numbers: Thanks to Erlang's bignums, JSON-encoded integers of
any<br>
%%% size can be parsed. Conversely, extremely large integers may<br>
%%% be JSON-encoded. This may cause problems for interoperability<br>
%%% with JSON parsers which can't handle arbitrary-sized integers.<br>
%%% Erlang's floats are of fixed precision and limited range, so<br>
%%% syntactically valid JSON floating-point numbers could silently<br>
%%% lose precision or noisily cause an overflow. However, most<br>
%%% other JSON libraries are likely to behave in the same way.<br>
%%%<br>
%%% Strings: If we represented JSON string data as Erlang binaries,<br>
%%% we would have to choose a particular unicode format. Instead,<br>
%%% we use lists of UTF-16 code units, which applications may then<br>
%%% change to binaries in their application-preferred manner.<br>
%%%<br>
%%% Arrays: Because of the string decision above, and Erlang's<br>
%%% lack of a distinguished string datatype, JSON arrays map<br>
%%% to {array, ArrayElementList}, where ArrayElementList -> list.<br>
%%%<br>
%%% Objects: Though not explicitly stated in the JSON "spec",<br>
%%% JSON's JavaScript heritage mandates that member names must<br>
%%% be unique within an object. The object/tuple ambiguity is<br>
%%% not a problem, since the atom 'struct' is not an<br>
%%% allowable value. Object keys may be atoms or strings on<br>
%%% encoding but are always decoded as strings.<br>
%%%<br>
<br>
<blockquote
cite="mid:CAANBt-pbTuQfZZS_bsksjb51tr3pB2KvnYr9_-GGjJBTLaqC0A@mail.gmail.com"
type="cite">
<div class="gmail_quote">
<div> This is all very interesting stuff - I'd really like
some documentation though, how the<br>
heck did you figure out how the interface works? - did you
have to sniff the socket? - is there an architectural
description somewhere?<br>
<br>
</div>
</div>
</blockquote>
I read the source for the android module for python4android.<br>
<br>
Regards,<br>
*Erik.<br>
</body>
</html>