Subversion Repositories public

Compare Revisions

Ignore whitespace Rev 28 → Rev 29

/inotify-cxx/trunk/inotify-cxx.cpp
26,6 → 26,9
 
#include "inotify-cxx.h"
 
/// procfs inotify base path
#define PROCFS_INOTIFY_BASE "/proc/sys/fs/inotify/"
 
/// dump separator (between particular entries)
#define DUMP_SEP \
({ \
93,6 → 96,11
else if (rName == "IN_ONLYDIR")
return IN_ONLYDIR;
#endif // IN_ONLYDIR
 
#ifdef IN_MOVE_SELF
else if (rName == "IN_MOVE_SELF")
return IN_MOVE_SELF;
#endif // IN_MOVE_SELF
return (uint32_t) 0;
}
196,6 → 204,13
rStr.append("IN_ONLYDIR");
}
#endif // IN_ONLYDIR
 
#ifdef IN_MOVE_SELF
if (IsType(uValue, IN_MOVE_SELF)) {
DUMP_SEP;
rStr.append("IN_MOVE_SELF");
}
#endif // IN_MOVE_SELF
}
 
void InotifyEvent::DumpTypes(std::string& rStr) const
506,5 → 521,57
}
IN_WRITE_END
}
}
 
uint32_t Inotify::GetCapability(InotifyCapability_t cap) throw (InotifyException)
{
FILE* f = fopen(GetCapabilityPath(cap).c_str(), "r");
if (f == NULL)
throw InotifyException(IN_EXC_MSG("cannot get capability"), errno, NULL);
unsigned int val = 0;
if (fscanf(f, "%u", &val) != 1) {
fclose(f);
throw InotifyException(IN_EXC_MSG("cannot get capability"), EIO, NULL);
}
fclose(f);
return (uint32_t) val;
}
 
void Inotify::SetCapability(InotifyCapability_t cap, uint32_t val) throw (InotifyException)
{
FILE* f = fopen(GetCapabilityPath(cap).c_str(), "w");
if (f == NULL)
throw InotifyException(IN_EXC_MSG("cannot set capability"), errno, NULL);
if (fprintf(f, "%u", (unsigned int) val) <= 0) {
fclose(f);
throw InotifyException(IN_EXC_MSG("cannot set capability"), EIO, NULL);
}
fclose(f);
}
 
std::string Inotify::GetCapabilityPath(InotifyCapability_t cap) throw (InotifyException)
{
std::string path(PROCFS_INOTIFY_BASE);
switch (cap) {
case IN_MAX_EVENTS:
path.append("max_queued_events");
break;
case IN_MAX_INSTANCES:
path.append("max_user_instances");
break;
case IN_MAX_WATCHES:
path.append("max_user_watches");
break;
default:
throw InotifyException(IN_EXC_MSG("unknown capability type"), EINVAL, NULL);
}
return path;
}
 
/inotify-cxx/trunk/TODO
1,3 → 1,3
Currently pending tasks:
 
*** nothing to do ***
* recursive watches (for watching whole directory subtrees)
/inotify-cxx/trunk/CHANGELOG
1,3 → 1,9
0.6.0 2006-12-28
* added methods for getting/setting inotify capabilities and limits
* added IN_SELF_MOVED flag (if defined)
* added Inotify::IsRecursive() for identifying recursive watches
(will be implemented in future versions)
 
0.5.3 2006-12-06
* fixed incorrect error handling in WaitForEvents()
 
/inotify-cxx/trunk/inotify-cxx.h
51,6 → 51,14
*/
#define IN_EXC_MSG(msg) (std::string(__PRETTY_FUNCTION__) + ": " + msg)
 
/// inotify capability/limit identifiers
typedef enum
{
IN_MAX_EVENTS = 0, ///< max. events in the kernel queue
IN_MAX_INSTANCES = 1, ///< max. inotify file descriptors per process
IN_MAX_WATCHES = 2 ///< max. watches per file descriptor
} InotifyCapability_t;
 
/// inotify-cxx thread safety
/**
* If this symbol is defined you can use this interface safely
469,6 → 477,21
return m_fEnabled;
}
/// Checks whether the watch is recursive.
/**
* A recursive watch monitors a directory itself and all
* its subdirectories. This watch is a logical object
* which may have many underlying kernel watches.
*
* \return currently always false (recursive watches not yet supported)
* \attention Recursive watches are currently NOT supported.
* They are planned for future versions.
*/
inline bool IsRecursive() const
{
return false;
}
private:
friend class Inotify;
 
719,6 → 742,103
* \sa GetDescriptor()
*/
void SetNonBlock(bool fNonBlock) throw (InotifyException);
/// Acquires a particular inotify capability/limit.
/**
* \param[in] cap capability/limit identifier
* \return capability/limit value
* \throw InotifyException thrown if the given value cannot be acquired
*/
static uint32_t GetCapability(InotifyCapability_t cap) throw (InotifyException);
/// Modifies a particular inotify capability/limit.
/**
* \param[in] cap capability/limit identifier
* \param[in] val new capability/limit value
* \throw InotifyException thrown if the given value cannot be set
* \attention Using this function requires root privileges.
* Beware of setting extensive values - it may seriously
* affect system performance and/or stability.
*/
static void SetCapability(InotifyCapability_t cap, uint32_t val) throw (InotifyException);
/// Returns the maximum number of events in the kernel queue.
/**
* \return maximum number of events in the kernel queue
* \throw InotifyException thrown if the given value cannot be acquired
*/
inline static uint32_t GetMaxEvents() throw (InotifyException)
{
return GetCapability(IN_MAX_EVENTS);
}
/// Sets the maximum number of events in the kernel queue.
/**
* \param[in] val new value
* \throw InotifyException thrown if the given value cannot be set
* \attention Using this function requires root privileges.
* Beware of setting extensive values - the greater value
* is set here the more physical memory may be used for the inotify
* infrastructure.
*/
inline static void SetMaxEvents(uint32_t val) throw (InotifyException)
{
SetCapability(IN_MAX_EVENTS, val);
}
/// Returns the maximum number of inotify instances per process.
/**
* It means the maximum number of open inotify file descriptors
* per running process.
*
* \return maximum number of inotify instances
* \throw InotifyException thrown if the given value cannot be acquired
*/
inline static uint32_t GetMaxInstances() throw (InotifyException)
{
return GetCapability(IN_MAX_INSTANCES);
}
/// Sets the maximum number of inotify instances per process.
/**
* \param[in] val new value
* \throw InotifyException thrown if the given value cannot be set
* \attention Using this function requires root privileges.
* Beware of setting extensive values - the greater value
* is set here the more physical memory may be used for the inotify
* infrastructure.
*/
inline static void SetMaxInstances(uint32_t val) throw (InotifyException)
{
SetCapability(IN_MAX_INSTANCES, val);
}
/// Returns the maximum number of inotify watches per instance.
/**
* It means the maximum number of inotify watches per inotify
* file descriptor.
*
* \return maximum number of inotify watches
* \throw InotifyException thrown if the given value cannot be acquired
*/
inline static uint32_t GetMaxWatches() throw (InotifyException)
{
return GetCapability(IN_MAX_WATCHES);
}
/// Sets the maximum number of inotify watches per instance.
/**
* \param[in] val new value
* \throw InotifyException thrown if the given value cannot be set
* \attention Using this function requires root privileges.
* Beware of setting extensive values - the greater value
* is set here the more physical memory may be used for the inotify
* infrastructure.
*/
inline static void SetMaxWatches(uint32_t val) throw (InotifyException)
{
SetCapability(IN_MAX_WATCHES, val);
}
 
private:
int m_fd; ///< file descriptor
730,6 → 850,8
IN_LOCK_DECL
friend class InotifyWatch;
static std::string GetCapabilityPath(InotifyCapability_t cap) throw (InotifyException);
};