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:
33 #ifdef __ANDROID__
34  , jvm_(0), rtabmap_(0)
35 #else
36  , swiftClassPtr_(0)
37 #endif
38  {
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;
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 
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 = [&](){
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_ */
UEventsHandler
Definition: UEventsHandler.h:128
rtabmap::ProgressionStatus::swiftCallback
void(* swiftCallback)(void *, int, int)
Definition: ProgressionStatus.h:148
int
int
rtabmap::ProgressionStatus::setMax
void setMax(int max)
Definition: ProgressionStatus.h:65
rtabmap::ProgressEvent::count_
int count_
Definition: ProgressionStatus.h:26
rtabmap::ProgressionStatus::getMax
int getMax() const
Definition: ProgressionStatus.h:69
UEventsHandler::registerToEventsManager
void registerToEventsManager()
Definition: UEventsHandler.cpp:29
rtabmap::ProgressionStatus::~ProgressionStatus
virtual ~ProgressionStatus()
Definition: ProgressionStatus.h:90
count
Index count
rtabmap::ProgressState::setCanceled
void setCanceled(bool canceled)
Definition: ProgressState.h:47
rtabmap::ProgressionStatus
Definition: ProgressionStatus.h:29
rtabmap::ProgressState::callback
virtual bool callback(const std::string &msg) const
Definition: ProgressState.h:39
ProgressState.h
rtabmap::ProgressionStatus::increment
void increment(int count=1) const
Definition: ProgressionStatus.h:71
UEvent
Definition: UEvent.h:57
rtabmap::ProgressionStatus::count_
int count_
Definition: ProgressionStatus.h:141
rtabmap::ProgressionStatus::max_
int max_
Definition: ProgressionStatus.h:142
UEvent::getClassName
virtual std::string getClassName() const =0
glm::max
GLM_FUNC_DECL genType max(genType const &x, genType const &y)
rtabmap::ProgressEvent::getClassName
virtual std::string getClassName() const
Definition: ProgressionStatus.h:24
rtabmap::ProgressState::isCanceled
bool isCanceled() const
Definition: ProgressState.h:51
rtabmap::ProgressState
Definition: ProgressState.h:35
rtabmap::ProgressEvent::ProgressEvent
ProgressEvent(int count=1)
Definition: ProgressionStatus.h:23
rtabmap::ProgressionStatus::handleEvent
virtual bool handleEvent(UEvent *event)
Definition: ProgressionStatus.h:93
rtabmap::ProgressionStatus::swiftClassPtr_
void * swiftClassPtr_
Definition: ProgressionStatus.h:147
rtabmap::ProgressionStatus::ProgressionStatus
ProgressionStatus()
Definition: ProgressionStatus.h:32
ULogger.h
ULogger class and convenient macros.
env
else
else
rtabmap::ProgressionStatus::setSwiftCallback
void setSwiftCallback(void *classPtr, void(*callback)(void *, int, int))
Definition: ProgressionStatus.h:49
UEventsManager::post
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)
Definition: UEventsManager.cpp:54
NULL
#define NULL
rtabmap::ProgressionStatus::callback
virtual bool callback(const std::string &msg) const
Definition: ProgressionStatus.h:81
rtabmap::ProgressEvent
Definition: ProgressionStatus.h:20
rtabmap::ProgressionStatus::finish
void finish()
Definition: ProgressionStatus.h:76
rtabmap
Definition: CameraARCore.cpp:35
UEventsManager.h
UERROR
#define UERROR(...)
rs
Definition: CameraRealSense.h:36
rtabmap::ProgressionStatus::reset
void reset(int max)
Definition: ProgressionStatus.h:56
msg
msg


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jul 25 2024 02:50:14