]> Creatis software - creaImageIO.git/blob - src/creaImageIOListener.h
fe65ed80075ae65797548e158390c959a16f366c
[creaImageIO.git] / src / creaImageIOListener.h
1 #ifndef __creaImageIOListener_h_INCLUDED__
2 #define __creaImageIOListener_h_INCLUDED__
3
4 #include <creaImageIOSystem.h>
5 #include <stdio.h>
6 #include <time.h>
7 #include <wx/thread.h>
8 // Signal/slot mechanism
9 #include <boost/signal.hpp>
10 #include <boost/bind.hpp>
11 #include <boost/thread/mutex.hpp>
12
13 namespace creaImageIO
14 {
15
16   class Listener : public wxThread
17   {
18   public:
19     /// Ctors 
20     Listener();
21     /// Dtor
22     virtual ~Listener();
23         ///Thread method that is executed once create is called
24         void* Entry();
25         ///Thread method called upon exiting
26     void  OnExit();
27         ///Sets the new state of adding files
28         void SetAddFilesState(bool addFiles){boost::mutex::scoped_lock lock(mMutex);mAddFiles=addFiles;}
29         ///Sets the new state of removing files
30         void SetRemoveFilesState(bool removeFiles){boost::mutex::scoped_lock lock(mMutex);mRemoveFiles=removeFiles;}
31         ///Sets the new monitored drive
32         void SetMonitoredDrive(const std::string& dr){boost::mutex::scoped_lock lock(mMutex);mDrive=dr;}
33         ///Puts the name of the monitored drive in the given string
34         void GetMonitoredDrive(std::string& drive){drive=mDrive;}
35
36         ///Related with signals
37         //=============================================
38     typedef boost::signal<void (bool)>  MountingSignalType;
39     typedef MountingSignalType::slot_function_type MountingCallbackType;
40     //=============================================
41
42     //==================================================================
43     void ConnectObserver(MountingCallbackType callback);
44     //==================================================================
45
46         ///Sends a boost::signal to alert that the drive has changed its state (mounted/unmounted)
47         void SendSignal(bool ivalid);
48   
49
50   private:
51     /// The mutex
52     boost::mutex mMutex;
53     /// Boolean that declares if the files that are read on CD mount should be added
54     bool mAddFiles;
55         /// Boolean that declares if, on CD unmount, the files that were in the drive should be removed
56     bool mRemoveFiles;
57         ///Boolean that declares if a unit has been mounted
58         bool mMounted;
59         ///The monitored drive
60         std::string mDrive;
61         ///The validation signal
62         MountingSignalType mMountingSignal;
63   };
64
65 }
66
67 #endif