Debian Codegraph @

FaCT++.JNI/JNIMonitor.h

raw symbols SCIP
1 /* This file is part of the FaCT++ DL reasoner
2 Copyright (C) 2006-2015 Dmitry Tsarkov and The University of Manchester
3 Copyright (C) 2015-2017 Dmitry Tsarkov
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #ifndef JNIMONITOR_H
21 #define JNIMONITOR_H
22
23 #include "tProgressMonitor.h"
24 #include "JNISupport.h"
25
26 class JNIProgressMonitor: public TProgressMonitor
27 {
28 protected:
29 JNIEnv* env;
30 jobject javaMonitor;
31 jmethodID sCS, nC, sF, iC;
32 public:
33 /// c'tor: remember object and fill in methods to call
34 JNIProgressMonitor ( JNIEnv* Env, jobject obj )
35 : TProgressMonitor()
36 , env(Env)
37 {
38 javaMonitor = env->NewGlobalRef(obj);
39 jclass cls = env->GetObjectClass(obj);
40 if ( cls == nullptr )
41 Throw ( env, "Can't get class of ProgressMonitor object" );
42 sCS = env->GetMethodID ( cls, "setClassificationStarted", "(I)V" );
43 if ( sCS == nullptr )
44 Throw ( env, "Can't get method setClassificationStarted" );
45 nC = env->GetMethodID ( cls, "nextClass", "()V" );
46 if ( nC == nullptr )
47 Throw ( env, "Can't get method nextClass" );
48 sF = env->GetMethodID ( cls, "setFinished", "()V" );
49 if ( sF == nullptr )
50 Throw ( env, "Can't get method setFinished" );
51 iC = env->GetMethodID ( cls, "isCancelled", "()Z" );
52 if ( iC == nullptr )
53 Throw ( env, "Can't get method isCancelled" );
54 }
55 /// d'tor: allow JRE to delete object
56 ~JNIProgressMonitor() override { env->DeleteGlobalRef(javaMonitor); }
57
58 /// informs about beginning of classification with number of concepts to be classified
59 void setClassificationStarted ( unsigned int nConcepts ) override
60 { env->CallVoidMethod ( javaMonitor, sCS, nConcepts ); }
61 /// informs about beginning of classification of a given CONCEPT
62 void nextClass ( void ) override { env->CallVoidMethod ( javaMonitor, nC ); }
63 /// informs that the reasoning is done
64 void setFinished ( void ) override { env->CallVoidMethod ( javaMonitor, sF ); }
65 /// @return true iff reasoner have to be stopped
66 bool isCancelled ( void ) override { return env->CallBooleanMethod ( javaMonitor, iC ); }
67 }; // JNIProgressMonitor
68
69 #endif