]> Creatis software - creaImageIO.git/blobdiff - src/creaImageIOListener.h
move directory
[creaImageIO.git] / src / creaImageIOListener.h
diff --git a/src/creaImageIOListener.h b/src/creaImageIOListener.h
new file mode 100644 (file)
index 0000000..fe65ed8
--- /dev/null
@@ -0,0 +1,67 @@
+#ifndef __creaImageIOListener_h_INCLUDED__
+#define __creaImageIOListener_h_INCLUDED__
+
+#include <creaImageIOSystem.h>
+#include <stdio.h>
+#include <time.h>
+#include <wx/thread.h>
+// Signal/slot mechanism
+#include <boost/signal.hpp>
+#include <boost/bind.hpp>
+#include <boost/thread/mutex.hpp>
+
+namespace creaImageIO
+{
+
+  class Listener : public wxThread
+  {
+  public:
+    /// Ctors 
+    Listener();
+    /// Dtor
+    virtual ~Listener();
+       ///Thread method that is executed once create is called
+       void* Entry();
+       ///Thread method called upon exiting
+    void  OnExit();
+       ///Sets the new state of adding files
+       void SetAddFilesState(bool addFiles){boost::mutex::scoped_lock lock(mMutex);mAddFiles=addFiles;}
+       ///Sets the new state of removing files
+       void SetRemoveFilesState(bool removeFiles){boost::mutex::scoped_lock lock(mMutex);mRemoveFiles=removeFiles;}
+       ///Sets the new monitored drive
+       void SetMonitoredDrive(const std::string& dr){boost::mutex::scoped_lock lock(mMutex);mDrive=dr;}
+       ///Puts the name of the monitored drive in the given string
+       void GetMonitoredDrive(std::string& drive){drive=mDrive;}
+
+       ///Related with signals
+       //=============================================
+    typedef boost::signal<void (bool)>  MountingSignalType;
+    typedef MountingSignalType::slot_function_type MountingCallbackType;
+    //=============================================
+
+    //==================================================================
+    void ConnectObserver(MountingCallbackType callback);
+    //==================================================================
+
+       ///Sends a boost::signal to alert that the drive has changed its state (mounted/unmounted)
+       void SendSignal(bool ivalid);
+  
+
+  private:
+    /// The mutex
+    boost::mutex mMutex;
+    /// Boolean that declares if the files that are read on CD mount should be added
+    bool mAddFiles;
+       /// Boolean that declares if, on CD unmount, the files that were in the drive should be removed
+    bool mRemoveFiles;
+       ///Boolean that declares if a unit has been mounted
+       bool mMounted;
+       ///The monitored drive
+       std::string mDrive;
+       ///The validation signal
+       MountingSignalType mMountingSignal;
+  };
+
+}
+
+#endif