Subversion Repositories public

Rev

Rev 45 | Rev 51 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45 Rev 47
Line 15... Line 15...
15
15
16
#ifndef _USERTABLE_H_
16
#ifndef _USERTABLE_H_
17
#define _USERTABLE_H_
17
#define _USERTABLE_H_
18
18
19
#include <map>
19
#include <map>
-
 
20
#include <deque>
20
21
21
#include "inotify-cxx.h"
22
#include "inotify-cxx.h"
22
#include "incrontab.h"
23
#include "incrontab.h"
23
24
24
25
25
class UserTable;
26
class UserTable;
26
27
-
 
28
/// Callback for calling after a process finishes.
-
 
29
typedef void (*proc_done_cb)(InotifyWatch*);
27
30
-
 
31
/// Child process data
-
 
32
typedef struct
-
 
33
{
-
 
34
  pid_t pid;            ///< PID
-
 
35
  proc_done_cb onDone;  ///< function called after process finishes
-
 
36
  InotifyWatch* pWatch; ///< related watch
-
 
37
} ProcData_t;
-
 
38
-
 
39
/// Watch-to-usertable mapping
28
typedef std::map<InotifyWatch*, UserTable*> IWUT_MAP;
40
typedef std::map<InotifyWatch*, UserTable*> IWUT_MAP;
-
 
41
-
 
42
/// Watch-to-tableentry mapping
29
typedef std::map<InotifyWatch*, InCronTabEntry*> IWCE_MAP;
43
typedef std::map<InotifyWatch*, InCronTabEntry*> IWCE_MAP;
30
44
-
 
45
/// Child process list
-
 
46
typedef std::deque<ProcData_t> PROC_LIST;
-
 
47
-
 
48
/// Event dispatcher class.
-
 
49
/**
-
 
50
 * This class distributes inotify events to appropriate user tables.
-
 
51
 */
31
class EventDispatcher
52
class EventDispatcher
32
{
53
{
33
public:
54
public:
-
 
55
  /// Constructor.
-
 
56
  /**
-
 
57
   * \param[in] pIn inotify object
-
 
58
   */
34
  EventDispatcher(Inotify* pIn);
59
  EventDispatcher(Inotify* pIn);
35
 
60
 
-
 
61
  /// Destructor.
36
  ~EventDispatcher() {}
62
  ~EventDispatcher() {}
37
63
-
 
64
  /// Dispatches an event.
-
 
65
  /**
-
 
66
   * \param[in] rEvt inotify event
-
 
67
   */
38
  void DispatchEvent(InotifyEvent& rEvt);
68
  void DispatchEvent(InotifyEvent& rEvt);
39
 
69
 
-
 
70
  /// Registers a watch for an user table.
-
 
71
  /**
-
 
72
   * \param[in] pWatch inotify watch
-
 
73
   * \param[in] pTab user table
-
 
74
   */
40
  void Register(InotifyWatch* pWatch, UserTable* pTab);
75
  void Register(InotifyWatch* pWatch, UserTable* pTab);
41
 
76
 
-
 
77
  /// Unregisters a watch.
-
 
78
  /**
-
 
79
   * \param[in] pWatch inotify watch
-
 
80
   */
42
  void Unregister(InotifyWatch* pWatch);
81
  void Unregister(InotifyWatch* pWatch);
43
 
82
 
-
 
83
  /// Unregisters all watches for an user table.
-
 
84
  /**
-
 
85
   * \param[in] pTab user table
-
 
86
   */
44
  void UnregisterAll(UserTable* pTab);
87
  void UnregisterAll(UserTable* pTab);
45
 
88
 
46
private:
89
private:
47
  Inotify* m_pIn;
90
  Inotify* m_pIn;   ///< inotify object
48
  IWUT_MAP m_maps;
91
  IWUT_MAP m_maps;  ///< watch-to-usertable mapping
49
 
92
 
-
 
93
  /// Finds an user table for a watch.
-
 
94
  /**
-
 
95
   * \param[in] pW inotify watch
-
 
96
   * \return pointer to the appropriate watch; NULL if no such watch exists
-
 
97
   */
50
  UserTable* FindTable(InotifyWatch* pW);
98
  UserTable* FindTable(InotifyWatch* pW);
51
};
99
};
52
100
53
101
-
 
102
/// User table class.
-
 
103
/**
-
 
104
 * This class processes inotify events for an user. It creates
-
 
105
 * child processes which do appropriate actions as defined
-
 
106
 * in the user table file.
-
 
107
 */
54
class UserTable
108
class UserTable
55
{
109
{
56
public:
110
public:
-
 
111
  /// Constructor.
-
 
112
  /**
-
 
113
   * \param[in] pIn inotify object
-
 
114
   * \param[in] pEd event dispatcher
-
 
115
   * \param[in] rUser user name
-
 
116
   */
57
        UserTable(Inotify* pIn, EventDispatcher* pEd, const std::string& rUser);
117
        UserTable(Inotify* pIn, EventDispatcher* pEd, const std::string& rUser);
-
 
118
 
-
 
119
  /// Destructor.
58
        virtual ~UserTable();
120
        virtual ~UserTable();
59
 
121
 
-
 
122
  /// Loads the table.
-
 
123
  /**
-
 
124
   * All loaded entries have their inotify watches and are
-
 
125
   * registered for event dispatching.
-
 
126
   * If loading fails the table remains empty.
-
 
127
   */
60
  void Load();
128
  void Load();
61
 
129
 
-
 
130
  /// Removes all entries from the table.
-
 
131
  /**
-
 
132
   * All entries are unregistered from the event dispatcher and
-
 
133
   * their watches are destroyed.
-
 
134
   */
62
  void Dispose();
135
  void Dispose();
63
 
136
 
-
 
137
  /// Processes an inotify event.
-
 
138
  /**
-
 
139
   * \param[in] rEvt inotify event
-
 
140
   */
64
  void OnEvent(InotifyEvent& rEvt);
141
  void OnEvent(InotifyEvent& rEvt);
65
private:
-
 
66
  Inotify* m_pIn;
-
 
67
  EventDispatcher* m_pEd;
-
 
68
  std::string m_user;
-
 
69
  InCronTab m_tab;
-
 
70
  IWCE_MAP m_map;
-
 
71
 
142
 
-
 
143
  /// Cleans-up all zombie child processes and enables disabled watches.
-
 
144
  /**
-
 
145
   * \attention This method must be called AFTER processing all events
-
 
146
   *            which has been caused by the processes.
-
 
147
   */
-
 
148
  static void FinishDone();
-
 
149
private:
-
 
150
  Inotify* m_pIn;         ///< inotify object
-
 
151
  EventDispatcher* m_pEd; ///< event dispatcher
-
 
152
  std::string m_user;     ///< user name
-
 
153
  InCronTab m_tab;        ///< incron table
-
 
154
  IWCE_MAP m_map;         ///< watch-to-entry mapping
-
 
155
-
 
156
  static PROC_LIST s_procList;  ///< child process list
-
 
157
 
-
 
158
  /// Finds an entry for a watch.
-
 
159
  /**
-
 
160
   * \param[in] pWatch inotify watch
-
 
161
   * \return pointer to the appropriate entry; NULL if no such entry exists
-
 
162
   */
72
  InCronTabEntry* FindEntry(InotifyWatch* pWatch);
163
  InCronTabEntry* FindEntry(InotifyWatch* pWatch);
73
 
164
 
-
 
165
  /// Prepares arguments for creating a child process.
-
 
166
  /**
-
 
167
   * \param[in] rCmd command string
-
 
168
   * \param[out] argc argument count
-
 
169
   * \param[out] argv argument array
-
 
170
   * \return true = success, false = failure
-
 
171
   */
74
  bool PrepareArgs(const std::string& rCmd, int& argc, char**& argv);
172
  bool PrepareArgs(const std::string& rCmd, int& argc, char**& argv);
-
 
173
 
75
};
174
};
76
175
77
#endif //_USERTABLE_H_
176
#endif //_USERTABLE_H_