Subversion Repositories public

Compare Revisions

Regard whitespace Rev 10 → Rev 11

/inotify-cxx/trunk/inotify-cxx.cpp
28,89 → 28,145
#define DUMP_SEP \
({ \
if (!rStr.empty()) { \
rStr.append(" "); \
rStr.append(","); \
} \
})
 
uint32_t InotifyEvent::GetMaskByName(const std::string& rName)
{
if (rName == "IN_ACCESS")
return IN_ACCESS;
else if (rName == "IN_MODIFY")
return IN_MODIFY;
else if (rName == "IN_ATTRIB")
return IN_ATTRIB;
else if (rName == "IN_CLOSE_WRITE")
return IN_CLOSE_WRITE;
else if (rName == "IN_CLOSE_NOWRITE")
return IN_CLOSE_NOWRITE;
else if (rName == "IN_MOVED_FROM")
return IN_MOVED_FROM;
else if (rName == "IN_MOVED_TO")
return IN_MOVED_TO;
else if (rName == "IN_CREATE")
return IN_CREATE;
else if (rName == "IN_DELETE")
return IN_DELETE;
else if (rName == "IN_DELETE_SELF")
return IN_DELETE_SELF;
else if (rName == "IN_UNMOUNT")
return IN_UNMOUNT;
else if (rName == "IN_Q_OVERFLOW")
return IN_Q_OVERFLOW;
else if (rName == "IN_IGNORED")
return IN_IGNORED;
else if (rName == "IN_CLOSE")
return IN_CLOSE;
else if (rName == "IN_MOVE")
return IN_MOVE;
else if (rName == "IN_ISDIR")
return IN_ISDIR;
else if (rName == "IN_ONESHOT")
return IN_ONESHOT;
else if (rName == "IN_ALL_EVENTS")
return IN_ALL_EVENTS;
 
void InotifyEvent::DumpTypes(std::string& rStr) const
return (uint32_t) 0;
}
 
void InotifyEvent::DumpTypes(uint32_t uValue, std::string& rStr)
{
rStr = "";
if (IsType(IN_ACCESS)) {
if (IsType(uValue, IN_ALL_EVENTS)) {
rStr.append("IN_ALL_EVENTS");
}
else {
if (IsType(uValue, IN_ACCESS)) {
DUMP_SEP;
rStr.append("IN_ACCESS");
}
if (IsType(IN_MODIFY)) {
if (IsType(uValue, IN_MODIFY)) {
DUMP_SEP;
rStr.append("IN_MODIFY");
}
if (IsType(IN_ATTRIB)) {
if (IsType(uValue, IN_ATTRIB)) {
DUMP_SEP;
rStr.append("IN_ATTRIB");
}
if (IsType(IN_CLOSE_WRITE)) {
if (IsType(uValue, IN_CREATE)) {
DUMP_SEP;
rStr.append("IN_CLOSE_WRITE");
rStr.append("IN_CREATE");
}
if (IsType(IN_CLOSE_NOWRITE)) {
if (IsType(uValue, IN_DELETE)) {
DUMP_SEP;
rStr.append("IN_CLOSE_NOWRITE");
rStr.append("IN_DELETE");
}
if (IsType(IN_OPEN)) {
if (IsType(uValue, IN_DELETE_SELF)) {
DUMP_SEP;
rStr.append("IN_DELETE_SELF");
}
if (IsType(uValue, IN_OPEN)) {
DUMP_SEP;
rStr.append("IN_OPEN");
}
if (IsType(IN_MOVED_FROM)) {
if (IsType(uValue, IN_CLOSE)) {
DUMP_SEP;
rStr.append("IN_MOVED_FROM");
rStr.append("IN_CLOSE");
}
if (IsType(IN_MOVED_TO)) {
else {
if (IsType(uValue, IN_CLOSE_WRITE)) {
DUMP_SEP;
rStr.append("IN_MOVED_TO");
rStr.append("IN_CLOSE_WRITE");
}
if (IsType(IN_CREATE)) {
if (IsType(uValue, IN_CLOSE_NOWRITE)) {
DUMP_SEP;
rStr.append("IN_CREATE");
rStr.append("IN_CLOSE_NOWRITE");
}
if (IsType(IN_DELETE)) {
}
if (IsType(uValue, IN_MOVE)) {
DUMP_SEP;
rStr.append("IN_DELETE");
rStr.append("IN_MOVE");
}
if (IsType(IN_DELETE_SELF)) {
else {
if (IsType(uValue, IN_MOVED_FROM)) {
DUMP_SEP;
rStr.append("IN_DELETE_SELF");
rStr.append("IN_MOVED_FROM");
}
if (IsType(IN_UNMOUNT)) {
if (IsType(uValue, IN_MOVED_TO)) {
DUMP_SEP;
rStr.append("IN_MOVED_TO");
}
}
}
if (IsType(uValue, IN_UNMOUNT)) {
DUMP_SEP;
rStr.append("IN_UNMOUNT");
}
if (IsType(IN_Q_OVERFLOW)) {
if (IsType(uValue, IN_Q_OVERFLOW)) {
DUMP_SEP;
rStr.append("IN_Q_OVERFLOW");
}
if (IsType(IN_IGNORED)) {
if (IsType(uValue, IN_IGNORED)) {
DUMP_SEP;
rStr.append("IN_IGNORED");
}
if (IsType(IN_CLOSE)) {
if (IsType(uValue, IN_ISDIR)) {
DUMP_SEP;
rStr.append("IN_CLOSE");
}
if (IsType(IN_MOVE)) {
DUMP_SEP;
rStr.append("IN_MOVE");
}
if (IsType(IN_ISDIR)) {
DUMP_SEP;
rStr.append("IN_ISDIR");
}
if (IsType(IN_ONESHOT)) {
if (IsType(uValue, IN_ONESHOT)) {
DUMP_SEP;
rStr.append("IN_ONESHOT");
}
}
 
void InotifyEvent::DumpTypes(std::string& rStr) const
{
DumpTypes((uint32_t) m_evt.mask, rStr);
}
 
 
Inotify::Inotify()
{
m_fd = inotify_init();
138,6 → 194,7
pWatch->m_wd = inotify_add_watch(m_fd, pWatch->GetPath().c_str(), pWatch->GetMask());
if (pWatch->m_wd != -1) {
m_watches.insert(IN_WATCH_MAP::value_type(pWatch->m_wd, pWatch));
pWatch->m_pInotify = this;
return true;
}
152,6 → 209,7
if (inotify_rm_watch(m_fd, pWatch->GetMask()) != -1) {
m_watches.erase(pWatch->m_wd);
pWatch->m_wd = -1;
pWatch->m_pInotify = NULL;
}
}
 
159,7 → 217,10
{
IN_WATCH_MAP::iterator it = m_watches.begin();
while (it != m_watches.end()) {
inotify_rm_watch(m_fd, (*it).second->GetMask());
InotifyWatch* pW = (*it).second;
inotify_rm_watch(m_fd, pW->GetMask());
pW->m_wd = -1;
pW->m_pInotify = NULL;
it++;
}
180,7 → 241,8
ssize_t i = 0;
while (i < len) {
InotifyEvent evt((struct inotify_event *) &m_buf[i]);
InotifyWatch* pW = FindWatch(((struct inotify_event *) &m_buf[i])->wd);
InotifyEvent evt((struct inotify_event *) &m_buf[i], pW);
m_events.push_back(evt);
i += INOTIFY_EVENT_SIZE + (int) evt.GetLength();
}
/inotify-cxx/trunk/CHANGELOG
1,2 → 1,15
0.2.0 2006-09-15
* InotifyEvent now contains a pointer to the source InotifyWatch
* fixed: InotifyEvent::IsType() - it now handles the mask correctly
* added a static method (InotifyEvent::GetMaskByName()) for finding a mask
for a name
* added a static version of InotifyEvent::DumpTypes() method
* added a static version of InotifyEvent::IsType() method
* dumped types (InotifyEvent::DumpTypes()) now separated by commas
instead of spaces
* InotifyEvent::DumpTypes() methods now use as general types as possible
* InotifyWatch now contains a pointer to the related Inotify
 
 
0.1.0 2006-09-04
first alpha version
/inotify-cxx/trunk/inotify-cxx.h
40,6 → 40,12
/// Event buffer length
#define INOTIFY_BUFLEN (1024 * (INOTIFY_EVENT_SIZE + 16))
 
 
// forward declaration
class InotifyWatch;
class Inotify;
 
 
/// inotify event class
/**
* It holds all information about inotify event and provides
56,25 → 62,29
{
memset(&m_evt, 0, sizeof(m_evt));
m_evt.wd = (int32_t) -1;
m_pWatch = NULL;
}
/// Constructor.
/**
* Creates an event based on inotify event data.
* For NULL pointer it works the same way as InotifyEvent().
* For NULL pointers it works the same way as InotifyEvent().
*
* \param[in] pEvt event data
* \param[in] pWatch inotify watch
*/
InotifyEvent(const struct inotify_event* pEvt)
InotifyEvent(const struct inotify_event* pEvt, InotifyWatch* pWatch)
{
if (pEvt != NULL) {
memcpy(&m_evt, pEvt, sizeof(m_evt));
if (pEvt->name != NULL)
m_name = pEvt->name;
m_pWatch = pWatch;
}
else {
memset(&m_evt, 0, sizeof(m_evt));
m_evt.wd = (int32_t) -1;
m_pWatch = NULL;
}
}
103,6 → 113,17
return (uint32_t) m_evt.mask;
}
/// Checks a value for the event type.
/**
* \param[in] uValue checked value
* \param[in] uType type which is checked for
* \return true = the value contains the given type, false = otherwise
*/
inline static bool IsType(uint32_t uValue, uint32_t uType)
{
return ((uValue & uType) != 0) && ((~uValue & uType) == 0);
}
/// Checks for the event type.
/**
* \param[in] uType type which is checked for
110,7 → 131,7
*/
inline bool IsType(uint32_t uType) const
{
return (((uint32_t) m_evt.mask) & uType) != 0;
return IsType((uint32_t) m_evt.mask, uType);
}
/// Returns the event cookie.
149,6 → 170,15
rName = GetName();
}
/// Returns the source watch.
/**
* \return source watch
*/
inline InotifyWatch* GetWatch()
{
return m_pWatch;
}
/// Returns the event raw data.
/**
* For NULL pointer it does nothing.
170,6 → 200,20
memcpy(&rEvt, &m_evt, sizeof(m_evt));
}
/// Finds the appropriate mask for a name.
/**
* \param[in] rName mask name
* \return mask for name; 0 on failure
*/
static uint32_t GetMaskByName(const std::string& rName);
/// Fills the string with all types contained in an event mask value.
/**
* \param[in] uValue event mask value
* \param[out] rStr dumped event types
*/
static void DumpTypes(uint32_t uValue, std::string& rStr);
/// Fills the string with all types contained in the event mask.
/**
* \param[out] rStr dumped event types
179,12 → 223,11
private:
struct inotify_event m_evt; ///< event structure
std::string m_name; ///< event name
InotifyWatch* m_pWatch; ///< source watch
};
 
 
class Inotify; // forward declaration
 
 
/// inotify watch class
class InotifyWatch
{
234,6 → 277,15
return (uint32_t) m_uMask;
}
/// Returns the appropriate inotify class instance.
/**
* \return inotify instance
*/
inline Inotify* GetInotify()
{
return m_pInotify;
}
private:
friend class Inotify;
 
240,6 → 292,7
std::string m_path; ///< watched file path
uint32_t m_uMask; ///< event mask
int32_t m_wd; ///< watch descriptor
Inotify* m_pInotify; ///< inotify object
};