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 #ifdef __ANDROID__
15 #include <jni.h>
16 #endif
17 
18 namespace rtabmap {
19 
20 class ProgressEvent : public UEvent
21 {
22 public:
23  ProgressEvent(int count = 1) : count_(count){}
24  virtual std::string getClassName() const {return "ProgressEvent";}
25 
26  int count_;
27 };
28 
30 {
31 public:
32  ProgressionStatus() : count_(0), max_(100)
33 #ifdef __ANDROID__
34  , jvm_(0), rtabmap_(0)
35 #else
36  , swiftClassPtr_(0)
37 #endif
38  {
39  registerToEventsManager();
40  }
41 
42 #ifdef __ANDROID__
43  void setJavaObjects(JavaVM * jvm, jobject rtabmap)
44  {
45  jvm_ = jvm;
46  rtabmap_ = rtabmap;
47  }
48 #else
49  void setSwiftCallback(void * classPtr, void(*callback)(void *, int, int))
50  {
51  swiftClassPtr_ = classPtr;
52  swiftCallback = callback;
53  }
54 #endif
55 
56  void reset(int max)
57  {
58  count_=-1;
59  max_ = max;
60  setCanceled(false);
61 
62  increment();
63  }
64 
65  void setMax(int max)
66  {
67  max_ = max;
68  }
69  int getMax() const {return max_;}
70 
71  void increment(int count = 1) const
72  {
74  }
75 
76  void finish()
77  {
78 
79  }
80 
81  virtual bool callback(const std::string & msg) const
82  {
83  if(!isCanceled())
84  {
85  increment();
86  }
87 
88  return ProgressState::callback(msg);
89  }
90  virtual ~ProgressionStatus(){}
91 
92 protected:
93  virtual bool handleEvent(UEvent * event)
94  {
95  if(event->getClassName().compare("ProgressEvent") == 0)
96  {
97  count_ += ((ProgressEvent*)event)->count_;
98  // Call JAVA callback
99  bool success = false;
100 #ifdef __ANDROID__
101  if(jvm_ && rtabmap_)
102  {
103  JNIEnv *env = 0;
104  jint rs = jvm_->AttachCurrentThread(&env, NULL);
105  if(rs == JNI_OK && env)
106  {
107  jclass clazz = env->GetObjectClass(rtabmap_);
108  if(clazz)
109  {
110  jmethodID methodID = env->GetMethodID(clazz, "updateProgressionCallback", "(II)V" );
111  if(methodID)
112  {
113  env->CallVoidMethod(rtabmap_, methodID,
114  count_,
115  max_);
116  success = true;
117  }
118  }
119  }
120  jvm_->DetachCurrentThread();
121  }
122 #else // APPLE
123  if(swiftClassPtr_)
124  {
125  std::function<void()> actualCallback = [&](){
126  swiftCallback(swiftClassPtr_, count_, max_);
127  };
128  actualCallback();
129  success = true;
130  }
131 #endif
132  if(!success)
133  {
134  UERROR("Failed to call rtabmap::updateProgressionCallback");
135  }
136  }
137  return false;
138  }
139 
140 private:
141  int count_;
142  int max_;
143 #ifdef __ANDROID__
144  JavaVM *jvm_;
145  jobject rtabmap_;
146 #else
148  void(*swiftCallback)(void *, int, int);
149 #endif
150 };
151 
152 }
153 
154 
155 #endif /* APP_ANDROID_JNI_PROGRESSIONSTATUS_H_ */
#define NULL
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)
Definition: UEvent.h:57
virtual bool callback(const std::string &msg) const
Definition: ProgressState.h:39
virtual std::string getClassName() const =0
void setSwiftCallback(void *classPtr, void(*callback)(void *, int, int))
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
#define UERROR(...)
ULogger class and convenient macros.
virtual bool callback(const std::string &msg) const
virtual bool handleEvent(UEvent *event)
void increment(int count=1) const
virtual std::string getClassName() const


rtabmap
Author(s): Mathieu Labbe
autogenerated on Mon Jan 23 2023 03:37:29