ProgressionStatus.h
Go to the documentation of this file.
1 /*
2  * ProgressionStatus.h
3  *
4  * Created on: Feb 28, 2017
5  * Author: mathieu
6  */
7 
8 #ifndef APP_ANDROID_JNI_PROGRESSIONSTATUS_H_
9 #define APP_ANDROID_JNI_PROGRESSIONSTATUS_H_
10 
14 #include <jni.h>
15 
16 namespace rtabmap {
17 
18 class ProgressEvent : public UEvent
19 {
20 public:
21  ProgressEvent(int count = 1) : count_(count){}
22  virtual std::string getClassName() const {return "ProgressEvent";}
23 
24  int count_;
25 };
26 
28 {
29 public:
30  ProgressionStatus() : count_(0), max_(100), jvm_(0), rtabmap_(0)
31  {
32  registerToEventsManager();
33  }
34 
35  void setJavaObjects(JavaVM * jvm, jobject rtabmap)
36  {
37  jvm_ = jvm;
38  rtabmap_ = rtabmap;
39  }
40 
41  void reset(int max)
42  {
43  count_=-1;
44  max_ = max;
45  setCanceled(false);
46 
47  increment();
48  }
49 
50  void setMax(int max)
51  {
52  max_ = max;
53  }
54  int getMax() const {return max_;}
55 
56  void increment(int count = 1) const
57  {
59  }
60 
61  void finish()
62  {
63 
64  }
65 
66  virtual bool callback(const std::string & msg) const
67  {
68  if(!isCanceled())
69  {
70  increment();
71  }
72 
73  return ProgressState::callback(msg);
74  }
75  virtual ~ProgressionStatus(){}
76 
77 protected:
78  virtual bool handleEvent(UEvent * event)
79  {
80  if(event->getClassName().compare("ProgressEvent") == 0)
81  {
82  count_ += ((ProgressEvent*)event)->count_;
83  // Call JAVA callback
84  bool success = false;
85  if(jvm_ && rtabmap_)
86  {
87  JNIEnv *env = 0;
88  jint rs = jvm_->AttachCurrentThread(&env, NULL);
89  if(rs == JNI_OK && env)
90  {
91  jclass clazz = env->GetObjectClass(rtabmap_);
92  if(clazz)
93  {
94  jmethodID methodID = env->GetMethodID(clazz, "updateProgressionCallback", "(II)V" );
95  if(methodID)
96  {
97  env->CallVoidMethod(rtabmap_, methodID,
98  count_,
99  max_);
100  success = true;
101  }
102  }
103  }
104  jvm_->DetachCurrentThread();
105  }
106  if(!success)
107  {
108  UERROR("Failed to call rtabmap::updateProgressionCallback");
109  }
110  }
111  return false;
112  }
113 
114 private:
115  int count_;
116  int max_;
117  JavaVM *jvm_;
118  jobject rtabmap_;
119 };
120 
121 }
122 
123 
124 #endif /* APP_ANDROID_JNI_PROGRESSIONSTATUS_H_ */
#define NULL
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)
Definition: UEvent.h:57
static JavaVM * jvm
Definition: RTABMapApp.cpp:66
virtual bool callback(const std::string &msg) const
virtual std::string getClassName() const
virtual bool callback(const std::string &msg) const
Definition: ProgressState.h:39
virtual std::string getClassName() const =0
Definition: CameraRGBD.h:73
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
void setJavaObjects(JavaVM *jvm, jobject rtabmap)
#define UERROR(...)
ULogger class and convenient macros.
virtual bool handleEvent(UEvent *event)
void increment(int count=1) const


rtabmap
Author(s): Mathieu Labbe
autogenerated on Wed Jun 5 2019 22:41:32