Hello
I finish first stage to move my webapp as native Android application.
Its consists one java file with declaration webWiew, and all rest, written
in FPC, is build as library. Of course start is thought jni, but after
that http server (based on Synapse) is started, and build in browser can
play with them.
If someone is interesting: attached patch consist changes to enable
pthreads and dynamic linking working on Android
Darek
Index: unix/initc.pp
===================================================================
--- unix/initc.pp (wersja 15763)
+++ unix/initc.pp (kopia robocza)
@@ -17,7 +17,9 @@
interface
uses
ctypes;
+{$ifndef android}
{$linklib c}
+{$endif}
function fpgetCerrno:cint;
procedure fpsetCerrno(err:cint);
@@ -52,8 +54,12 @@
{$ifdef Linux}
+{$ifdef android}
+function geterrnolocation: pcint; cdecl;external clib name '__errno';
+{$else}
function geterrnolocation: pcint; cdecl;external clib name '__errno_location';
{$endif}
+{$endif}
{$ifdef FreeBSD} // tested on x86
function geterrnolocation: pcint; cdecl;external clib name '__error';
Index: unix/cthreads.pp
===================================================================
--- unix/cthreads.pp (wersja 15763)
+++ unix/cthreads.pp (kopia robocza)
@@ -21,9 +21,11 @@
b) still enabling dynamically checking whether or not certain functions
are available (could also be implemented via weak linking)
}
+{$ifndef android}
{$linklib pthread}
{$define dynpthreads} // Useless on BSD, since they are in libc
{$endif}
+{$endif}
{ sem_init is best, since it does not consume any file descriptors. }
@@ -51,7 +53,9 @@
interface
{$S-}
+{$ifndef android}
{$ifndef dynpthreads} // If you have problems compiling this on FreeBSD 5.x
+
{$linklib c} // try adding -Xf
{$ifndef Darwin}
{$ifndef haiku}
@@ -59,6 +63,7 @@
{$endif haiku}
{$endif darwin}
{$endif}
+{$endif}
{$define basicevents_with_pthread_cond}
@@ -332,6 +337,7 @@
writeln('Starting new thread');
{$endif DEBUG_MT}
pthread_attr_init(@thread_attr);
+{$ifndef android}
{$ifndef HAIKU}
{$ifdef solaris}
pthread_attr_setinheritsched(@thread_attr, PTHREAD_INHERIT_SCHED);
@@ -339,6 +345,7 @@
pthread_attr_setinheritsched(@thread_attr, PTHREAD_EXPLICIT_SCHED);
{$endif not solaris}
{$endif}
+{$endif}
// will fail under linux -- apparently unimplemented
pthread_attr_setscope(@thread_attr, PTHREAD_SCOPE_PROCESS);
@@ -409,7 +416,9 @@
function CKillThread (threadHandle : TThreadID) : dword;
begin
pthread_detach(pthread_t(threadHandle));
+ {$ifndef android}
CKillThread := pthread_cancel(pthread_t(threadHandle));
+ {$endif}
end;
function CCloseThread (threadHandle : TThreadID) : dword;
@@ -437,8 +446,8 @@
{$Warning ThreadGetPriority needs to be implemented}
result:=0;
end;
+
-
function CGetCurrentThreadId : TThreadID;
begin
CGetCurrentThreadId := TThreadID (pthread_self());
@@ -507,7 +516,7 @@
{*****************************************************************************
Semaphore routines
*****************************************************************************}
-
+
procedure cSemaphoreWait(const FSem: Pointer);
var
res: cint;
Index: unix/dl.pp
===================================================================
--- unix/dl.pp (wersja 15763)
+++ unix/dl.pp (kopia robocza)
@@ -29,8 +29,10 @@
{$if defined(linux) and defined(cpuarm)}
{ arm-linux seems to require this }
+{$ifndef android}
{$linklib c}
{$endif}
+{$endif}
RTLD_LAZY = $001;
RTLD_NOW = $002;
Index: linux/pthread.inc
===================================================================
--- linux/pthread.inc (wersja 15763)
+++ linux/pthread.inc (kopia robocza)
@@ -119,6 +119,7 @@
function pthread_join(__th:pthread_t; __thread_return:ppointer):longint;cdecl;external;
function pthread_detach(__th:pthread_t):longint;cdecl;external;
function pthread_attr_init(__attr:ppthread_attr_t):longint;cdecl;external;
+{$ifndef android}
function pthread_attr_destroy(__attr:ppthread_attr_t):longint;cdecl;external;
function pthread_attr_setdetachstate(__attr:ppthread_attr_t; __detachstate:longint):longint;cdecl;external;
function pthread_attr_getdetachstate(__attr:ppthread_attr_t; __detachstate:plongint):longint;cdecl;external;
@@ -126,6 +127,7 @@
function pthread_attr_getschedparam(__attr:ppthread_attr_t; __param:psched_param):longint;cdecl;external;
function pthread_attr_setschedpolicy(__attr:ppthread_attr_t; __policy:longint):longint;cdecl;external;
function pthread_attr_getschedpolicy(__attr:ppthread_attr_t; __policy:plongint):longint;cdecl;external;
+{$endif}
function pthread_attr_setinheritsched(__attr:ppthread_attr_t; __inherit:longint):longint;cdecl;external;
function pthread_attr_getinheritsched(__attr:ppthread_attr_t; __inherit:plongint):longint;cdecl;external;
function pthread_attr_setstacksize(p: ppthread_attr_t;s:size_t):cint;cdecl;external;
@@ -155,6 +157,7 @@
function pthread_key_delete(__key:pthread_key_t):longint;cdecl;external;
function pthread_setspecific(__key:pthread_key_t; __pointer:pointer):longint;cdecl;external;
function pthread_getspecific(__key:pthread_key_t):pointer;cdecl;external;
+{$ifndef android}
{ function pthread_once(__once_control:ppthread_once_t; __init_routine:tprocedure ):longint;cdecl;external;}
function pthread_setcancelstate(__state:longint; __oldstate:plongint):longint;cdecl;external;
function pthread_setcanceltype(__type:longint; __oldtype:plongint):longint;cdecl;external;
@@ -167,6 +170,7 @@
{ function sigwait(__set:plibc_sigset; __sig:plongint):longint;cdecl;external;}
function pthread_atfork(__prepare:tprocedure ; __parent:tprocedure ; __child:tprocedure ):longint;cdecl;external;
procedure pthread_kill_other_threads_np;cdecl;external;
+{$endif}
function pthread_sigmask(how: cint; nset: plibc_sigset; oset: plibc_sigset): cint; cdecl; external;
function sem_init (__sem:Psem_t; __pshared:longint; __value:dword):longint;cdecl;external;
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel