Procedure Java_Event_pOnThread(env: PJNIEnv; this: jobject;
Obj: TObject; Mode:Integer); cdecl;
var
fEnv : PJNIEnv;
ID:pthread_t;
I,Index:integer;
begin
if not (Assigned(Obj)) then Exit;
case TThreadMode(Mode) of
Thread_Begin:
begin
dbg('Java_Event_pOnThread begin');
Exit;
end;
Thread_End:
begin
dbg('Java_Event_pOnThread end');
Exit;
end;
Thread_Execute:
begin
dbg('Java_Event_pOnThread execute1');
if Obj is TThread then TThread(Obj).GenEvent_OnThread(TThreadMode(Mode));
dbg('Java_Event_pOnThread execute2');
end;
Thread_Synchronize:
begin
dbg('Java_Event_pOnThread synchronize1');
if Obj is TThread then TThread(Obj).GenEvent_OnThread(TThreadMode(Mode));
dbg('Java_Event_pOnThread synchronize2');
end;
end;
end;
Function jGetMethodID(var Env : PJNIEnv; var jControls:jobject; FuncName, FuncSig : PChar) : jMethodID;
var
jClass : jobject;
begin
Result := nil;
Env:=nil;
gApp.jVM^.AttachCurrentThread(gApp.jVM,@Env,nil);
if (Env = nil) then
begin
dbgf(PChar(FuncName+' ('+IntToStr(gettid)+') Env = nil'));
Exit;
end;
dbg(Pchar(FuncName+' ('+IntToStr(gettid)+')'));
jClass := Env^.FindClass(Env,_cAppC);
if (jClass = nil) then
begin
dbge(PChar(FuncName+' ('+IntToStr(gettid)+') jClass = nil'));
Exit;
end;
Result := Env^.GetMethodID(Env, jClass, FuncName, FuncSig);
Env^.DeleteLocalRef(Env,jClass);
jControls:=gApp.jControls;
end;
//------------------------------------------------------------------------------
// Thread
//------------------------------------------------------------------------------
Function jThread_Create(ClassObj : TObject) : jObject;
Const
_cFuncName = 'jThread_Create';
_cFuncSig = '(ILjava/lang/String;)Ljava/lang/Object;';
Var
Env : PJNIEnv;
jControls: jobject;
_jMethod : jMethodID {$IFDef FPC} = nil {$EndIf};
_jParams : Array[0..0] of jValue;
begin
_jMethod := jGetMethodID(Env,jControls,_cFuncName,_cFuncSig);
_jParams[0].l := ClassObj;
Result := Env^.CallObjectMethodA(Env,jControls,_jMethod,@_jParams);
Result := Env^.NewGlobalRef(Env,Result);
dbg(_cFuncName+' 2');
end;
Procedure jThread_Free(var Thread : jObject);
Const
_cFuncName = 'jThread_Free';
_cFuncSig = '(Ljava/lang/Object;)V';
Var
Env : PJNIEnv;
jControls: jobject;
_jMethod : jMethodID {$IFDef FPC} = nil {$EndIf};
_jParams : Array[0..0] of jValue;
begin
if Thread = nil then Exit;
_jMethod := jGetMethodID(Env,jControls,_cFuncName,_cFuncSig);
_jParams[0].l := Thread;
Env^.CallVoidMethodA(Env,jControls,_jMethod,@_jParams);
Env^.DeleteGlobalRef(Env,Thread);
Thread := nil;
dbg(_cFuncName+' 2');
end;
Procedure jThread_Run(Thread : jObject);
Const
_cFuncName = 'jThread_Run';
_cFuncSig = '(Ljava/lang/Object;)V';
Var
Env : PJNIEnv;
jControls: jobject;
_jMethod : jMethodID {$IFDef FPC} = nil {$EndIf};
_jParams : Array[0..0] of jValue;
begin
if Thread = nil then Exit;
_jMethod := jGetMethodID(Env,jControls,_cFuncName,_cFuncSig);
_jParams[0].l := Thread;
Env^.CallVoidMethodA(Env,jControls,_jMethod,@_jParams);
dbg(_cFuncName+' 2');
end;
Procedure jThread_Synchronize(Thread : jObject);
Const
_cFuncName = 'jThread_Synchronize';
_cFuncSig = '(Ljava/lang/Object;)V';
Var
Env : PJNIEnv;
jControls: jobject;
_jMethod : jMethodID {$IFDef FPC} = nil {$EndIf};
_jParams : Array[0..0] of jValue;
begin
if Thread = nil then Exit;
_jMethod := jGetMethodID(Env,jControls,_cFuncName,_cFuncSig,s);
_jParams[0].l := Thread;
Env^.CallVoidMethodA(Env,jControls,_jMethod,@_jParams);
dbg(_cFuncName+' 2');
end;
Procedure jThread_Resume(Thread : jObject);
Const
_cFuncName = 'jThread_Resume';
_cFuncSig = '(Ljava/lang/Object;)V';
Var
Env : PJNIEnv;
jControls: jobject;
_jMethod : jMethodID {$IFDef FPC} = nil {$EndIf};
_jParams : Array[0..0] of jValue;
begin
if Thread = nil then Exit;
_jMethod := jGetMethodID(Env,jControls,_cFuncName,_cFuncSig);
_jParams[0].l := Thread;
Env^.CallVoidMethodA(Env,jControls,_jMethod,@_jParams);
dbg(_cFuncName+' 2');
end;
Procedure jThread_Suspend(Thread : jObject);
Const
_cFuncName = 'jThread_Suspend';
_cFuncSig = '(Ljava/lang/Object;)V';
Var
Env : PJNIEnv;
jControls: jobject;
_jMethod : jMethodID {$IFDef FPC} = nil {$EndIf};
_jParams : Array[0..0] of jValue;
begin
if Thread = nil then Exit;
_jMethod := jGetMethodID(Env,jControls,_cFuncName,_cFuncSig);
_jParams[0].l := Thread;
Env^.CallVoidMethodA(Env,jControls,_jMethod,@_jParams);
dbg(_cFuncName+' 2');
end;
Procedure jThread_Sleep(Thread : jObject; Milliseconds:integer);
Const
_cFuncName = 'jThread_Sleep';
_cFuncSig = '(Ljava/lang/Object;I)V';
Var
Env : PJNIEnv;
jControls: jobject;
_jMethod : jMethodID {$IFDef FPC} = nil {$EndIf};
_jParams : Array[0..1] of jValue;
PJ : Pjvalue;
begin
if Thread = nil then Exit;
_jMethod := jGetMethodID(Env,jControls,_cFuncName,_cFuncSig);
_jParams[0].l := Thread;
_jParams[1].i := Milliseconds;
Env^.CallVoidMethodA(Env,jControls,_jMethod,@_jParams);
dbg(PChar(_cFuncName+' 2 ('+IntToStr(Milliseconds)+')'));
end;