00001 00003 00016 #ifndef _USERTABLE_H_ 00017 #define _USERTABLE_H_ 00018 00019 #include <map> 00020 #include <deque> 00021 00022 #include "inotify-cxx.h" 00023 #include "incrontab.h" 00024 00025 00026 class UserTable; 00027 00029 typedef void (*proc_done_cb)(InotifyWatch*); 00030 00032 typedef struct 00033 { 00034 pid_t pid; 00035 proc_done_cb onDone; 00036 InotifyWatch* pWatch; 00037 } ProcData_t; 00038 00040 typedef std::map<InotifyWatch*, UserTable*> IWUT_MAP; 00041 00043 typedef std::map<InotifyWatch*, InCronTabEntry*> IWCE_MAP; 00044 00046 typedef std::deque<ProcData_t> PROC_LIST; 00047 00049 00052 class EventDispatcher 00053 { 00054 public: 00056 00059 EventDispatcher(Inotify* pIn); 00060 00062 ~EventDispatcher() {} 00063 00065 00068 void DispatchEvent(InotifyEvent& rEvt); 00069 00071 00075 void Register(InotifyWatch* pWatch, UserTable* pTab); 00076 00078 00081 void Unregister(InotifyWatch* pWatch); 00082 00084 00087 void UnregisterAll(UserTable* pTab); 00088 00089 private: 00090 Inotify* m_pIn; 00091 IWUT_MAP m_maps; 00092 00094 00098 UserTable* FindTable(InotifyWatch* pW); 00099 }; 00100 00101 00103 00108 class UserTable 00109 { 00110 public: 00112 00117 UserTable(Inotify* pIn, EventDispatcher* pEd, const std::string& rUser); 00118 00120 virtual ~UserTable(); 00121 00123 00128 void Load(); 00129 00131 00135 void Dispose(); 00136 00138 00141 void OnEvent(InotifyEvent& rEvt); 00142 00144 00148 static void FinishDone(); 00149 private: 00150 Inotify* m_pIn; 00151 EventDispatcher* m_pEd; 00152 std::string m_user; 00153 InCronTab m_tab; 00154 IWCE_MAP m_map; 00155 00156 static PROC_LIST s_procList; 00157 00159 00163 InCronTabEntry* FindEntry(InotifyWatch* pWatch); 00164 00166 00172 bool PrepareArgs(const std::string& rCmd, int& argc, char**& argv); 00173 00175 00179 void CleanupArgs(int argc, char** argv); 00180 00181 }; 00182 00183 #endif //_USERTABLE_H_