ProgressionStatus.h
Go to the documentation of this file.
00001 /*
00002  * ProgressionStatus.h
00003  *
00004  *  Created on: Feb 28, 2017
00005  *      Author: mathieu
00006  */
00007 
00008 #ifndef APP_ANDROID_JNI_PROGRESSIONSTATUS_H_
00009 #define APP_ANDROID_JNI_PROGRESSIONSTATUS_H_
00010 
00011 #include <rtabmap/core/ProgressState.h>
00012 #include <rtabmap/utilite/ULogger.h>
00013 #include <rtabmap/utilite/UEventsManager.h>
00014 #include <jni.h>
00015 
00016 namespace rtabmap {
00017 
00018 class ProgressEvent : public UEvent
00019 {
00020 public:
00021         ProgressEvent(int count = 1) : count_(count){}
00022         virtual std::string getClassName() const {return "ProgressEvent";}
00023 
00024         int count_;
00025 };
00026 
00027 class ProgressionStatus: public ProgressState, public UEventsHandler
00028 {
00029 public:
00030         ProgressionStatus() : count_(0), max_(100), jvm_(0), rtabmap_(0)
00031         {
00032                 registerToEventsManager();
00033         }
00034 
00035         void setJavaObjects(JavaVM * jvm, jobject rtabmap)
00036         {
00037                 jvm_ = jvm;
00038                 rtabmap_ = rtabmap;
00039         }
00040 
00041         void reset(int max)
00042         {
00043                 count_=-1;
00044                 max_ = max;
00045                 setCanceled(false);
00046 
00047                 increment();
00048         }
00049 
00050         void setMax(int max)
00051         {
00052                 max_ = max;
00053         }
00054         int getMax() const {return max_;}
00055 
00056         void increment(int count = 1) const
00057         {
00058                 UEventsManager::post(new ProgressEvent(count));
00059         }
00060 
00061         void finish()
00062         {
00063 
00064         }
00065 
00066         virtual bool callback(const std::string & msg) const
00067         {
00068                 if(!isCanceled())
00069                 {
00070                         increment();
00071                 }
00072 
00073                 return ProgressState::callback(msg);
00074         }
00075         virtual ~ProgressionStatus(){}
00076 
00077 protected:
00078         virtual bool handleEvent(UEvent * event)
00079         {
00080                 if(event->getClassName().compare("ProgressEvent") == 0)
00081                 {
00082                         count_ += ((ProgressEvent*)event)->count_;
00083                         // Call JAVA callback
00084                         bool success = false;
00085                         if(jvm_ && rtabmap_)
00086                         {
00087                                 JNIEnv *env = 0;
00088                                 jint rs = jvm_->AttachCurrentThread(&env, NULL);
00089                                 if(rs == JNI_OK && env)
00090                                 {
00091                                         jclass clazz = env->GetObjectClass(rtabmap_);
00092                                         if(clazz)
00093                                         {
00094                                                 jmethodID methodID = env->GetMethodID(clazz, "updateProgressionCallback", "(II)V" );
00095                                                 if(methodID)
00096                                                 {
00097                                                         env->CallVoidMethod(rtabmap_, methodID,
00098                                                                         count_,
00099                                                                         max_);
00100                                                         success = true;
00101                                                 }
00102                                         }
00103                                 }
00104                                 jvm_->DetachCurrentThread();
00105                         }
00106                         if(!success)
00107                         {
00108                                 UERROR("Failed to call rtabmap::updateProgressionCallback");
00109                         }
00110                 }
00111                 return false;
00112         }
00113 
00114 private:
00115         int count_;
00116         int max_;
00117         JavaVM *jvm_;
00118         jobject rtabmap_;
00119 };
00120 
00121 }
00122 
00123 
00124 #endif /* APP_ANDROID_JNI_PROGRESSIONSTATUS_H_ */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:21