ewmscp  ..
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
inotify_event_copy Class Reference

smart copy class for inotify_event. More...

Collaboration diagram for inotify_event_copy:
[legend]

Public Member Functions

 inotify_event_copy (const inotify_event_wrapper *aEvent)
 
 ~inotify_event_copy ()
 
clock_type::time_point timeStamp () const
 
const inotify_event_wrappergetEvent () const
 

Static Public Member Functions

static void doCopyLeftovers ()
 
static inotify_event_copygetStaleSingles ()
 get the next old inotify_event. More...
 
static void forget (inotify_event_copy *what)
 deletes a copy. More...
 
static inotify_event_copygetPartner (const inotify_event_wrapper *event, clock_type::time_point then)
 get partner of a half rename event. More...
 

Protected Member Functions

void doCopyIfNeeded ()
 make a real copy of this inotify_event. More...
 

Static Protected Member Functions

static std::map< uint32_t, inotify_event_copy > & getRenameEvents ()
 return a map which contains the inotify_event_copys More...
 
static bool cmp (const inotify_event_copy *lhs, const inotify_event_copy *rhs)
 function to order inotify_event_copys by time More...
 
static std::multiset< inotify_event_copy *, decltype(cmp) * > & getSingleEvents ()
 return a multiset containing single inotify_event_copys ordered by time More...
 

Protected Attributes

std::remove_reference< decltype(getSingleEvents())>::type::iterator singleEventIterator
 iterator into the multiset containing the single events More...
 
const inotify_event_wrapperevent
 pointer to the event, either the original or a copy More...
 
clock_type::time_point then
 the time the event was recorded More...
 
bool isCopy
 true if it's a copy. We can't use singleEventIterator as this might be getSingleEvents().end() after erasing it. More...
 

Detailed Description

smart copy class for inotify_event.

This is needed only for matching the two halves of rename event pairs! This class holds a pointer to an inotify_event_wrapper. Normally this is in the current buffer returned by the last read() from the inotify object. If a rename-event pair is not completely inside one buffer a real copy has to be made and processing of the pair can then happen in the next buffer.

Definition at line 177 of file inotify_watch.cpp.

Constructor & Destructor Documentation

◆ inotify_event_copy()

inotify_event_copy::inotify_event_copy ( const inotify_event_wrapper aEvent)
inline

Definition at line 211 of file inotify_watch.cpp.

211  :
212  singleEventIterator(getSingleEvents().end()), event(aEvent), isCopy(false) {
213  }

◆ ~inotify_event_copy()

inotify_event_copy::~inotify_event_copy ( )
inline

Definition at line 214 of file inotify_watch.cpp.

214  {
215  if (isCopy) {
216  free(reinterpret_cast<void*>(const_cast<inotify_event_wrapper*>(event)));
217  }
218  }

References event, and isCopy.

Member Function Documentation

◆ cmp()

static bool inotify_event_copy::cmp ( const inotify_event_copy lhs,
const inotify_event_copy rhs 
)
inlinestaticprotected

function to order inotify_event_copys by time

Definition at line 185 of file inotify_watch.cpp.

185  {
186  return lhs->then < rhs->then;
187  }

References then.

Referenced by getSingleEvents().

Here is the caller graph for this function:

◆ doCopyIfNeeded()

void inotify_event_copy::doCopyIfNeeded ( )
inlineprotected

make a real copy of this inotify_event.

Definition at line 199 of file inotify_watch.cpp.

199  {
200  if (!isCopy) {
201  auto theEvent = getEvent();
202  void* newEvent = malloc(theEvent->size());
203  memcpy(newEvent, theEvent, theEvent->size());
204  event = reinterpret_cast<inotify_event_wrapper*>(newEvent);
205  isCopy = true;
206  singleEventIterator = getSingleEvents().emplace(this);
207  }
208  }

References getEvent(), getSingleEvents(), isCopy, and singleEventIterator.

Here is the call graph for this function:

◆ doCopyLeftovers()

static void inotify_event_copy::doCopyLeftovers ( )
inlinestatic

Definition at line 226 of file inotify_watch.cpp.

226  {
227  for (auto& it : getRenameEvents()) {
228  it.second.doCopyIfNeeded();
229  }
230  }

References getRenameEvents().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ forget()

static void inotify_event_copy::forget ( inotify_event_copy what)
inlinestatic

deletes a copy.

It will remove it from both the singles set as well as from the map, and call (indirectlly, through the erase in the map) the destructor. Is static with a parameter instead of a normal member, because that would destroy it's own this in the erase from the map.

Definition at line 254 of file inotify_watch.cpp.

254  {
255  if (what->singleEventIterator != getSingleEvents().end()) {
256  getSingleEvents().erase(what->singleEventIterator);
257  }
258 
259  getRenameEvents().erase(what->getEvent()->cookie());
260  }

References inotify_event_wrapper::cookie(), getEvent(), getRenameEvents(), getSingleEvents(), and singleEventIterator.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getEvent()

const inotify_event_wrapper* inotify_event_copy::getEvent ( ) const
inline

Definition at line 222 of file inotify_watch.cpp.

222  {
223  return event;
224  }

References event.

Referenced by doCopyIfNeeded(), and forget().

Here is the caller graph for this function:

◆ getPartner()

static inotify_event_copy* inotify_event_copy::getPartner ( const inotify_event_wrapper event,
clock_type::time_point  then 
)
inlinestatic

get partner of a half rename event.

If the other half of the rename event is already known a pointer to it is returned. If not a copy of this event is emplaced into the half rename event map and a nullptr is returned.

Definition at line 267 of file inotify_watch.cpp.

268  {
269  auto result = getRenameEvents().emplace(event->cookie(), event);
270 
271  if (result.second) {
272  result.first->second.then = then;
273  return nullptr;
274  } else {
275  return &(result.first->second);
276  }
277  }

References inotify_event_wrapper::cookie(), event, getRenameEvents(), and then.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRenameEvents()

static std::map<uint32_t, inotify_event_copy>& inotify_event_copy::getRenameEvents ( )
inlinestaticprotected

return a map which contains the inotify_event_copys

Definition at line 180 of file inotify_watch.cpp.

180  {
181  static std::remove_reference<decltype(getRenameEvents())>::type renameEvents;
182  return renameEvents;
183  }

Referenced by doCopyLeftovers(), forget(), and getPartner().

Here is the caller graph for this function:

◆ getSingleEvents()

static std::multiset<inotify_event_copy*, decltype(cmp)*>& inotify_event_copy::getSingleEvents ( )
inlinestaticprotected

return a multiset containing single inotify_event_copys ordered by time

Definition at line 189 of file inotify_watch.cpp.

189  {
190  static std::remove_reference<decltype(getSingleEvents())>::type singleEvents(&cmp);
191  return singleEvents;
192  }

References cmp().

Referenced by doCopyIfNeeded(), forget(), and getStaleSingles().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getStaleSingles()

static inotify_event_copy* inotify_event_copy::getStaleSingles ( )
inlinestatic

get the next old inotify_event.

return a pointer to the next old (>5s) half of a rename event the parameter then is set to the time of the event. If no old event is found a nullptr is returned;

Definition at line 237 of file inotify_watch.cpp.

237  {
238  auto it = getSingleEvents().begin();
239 
240  if (it != getSingleEvents().end() &&
241  (*it)->then < clock_type::now() - std::chrono::seconds(5)) {
242  auto retval = *it;
243  return retval;
244  }
245 
246  return nullptr;
247  }

References getSingleEvents().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ timeStamp()

clock_type::time_point inotify_event_copy::timeStamp ( ) const
inline

< returns time of the event

Definition at line 219 of file inotify_watch.cpp.

219  {
220  return then;
221  }

References then.

Member Data Documentation

◆ event

const inotify_event_wrapper* inotify_event_copy::event
protected

pointer to the event, either the original or a copy

Definition at line 194 of file inotify_watch.cpp.

Referenced by getEvent(), getPartner(), and ~inotify_event_copy().

◆ isCopy

bool inotify_event_copy::isCopy
protected

true if it's a copy. We can't use singleEventIterator as this might be getSingleEvents().end() after erasing it.

Definition at line 196 of file inotify_watch.cpp.

Referenced by doCopyIfNeeded(), and ~inotify_event_copy().

◆ singleEventIterator

std::remove_reference<decltype(getSingleEvents())>::type::iterator inotify_event_copy::singleEventIterator
protected

iterator into the multiset containing the single events

Definition at line 193 of file inotify_watch.cpp.

Referenced by doCopyIfNeeded(), and forget().

◆ then

clock_type::time_point inotify_event_copy::then
protected

the time the event was recorded

Definition at line 195 of file inotify_watch.cpp.

Referenced by cmp(), getPartner(), and timeStamp().


The documentation for this class was generated from the following file:
inotify_event_copy::getSingleEvents
static std::multiset< inotify_event_copy *, decltype(cmp) * > & getSingleEvents()
return a multiset containing single inotify_event_copys ordered by time
Definition: inotify_watch.cpp:189
inotify_event_copy::then
clock_type::time_point then
the time the event was recorded
Definition: inotify_watch.cpp:195
inotify_event_copy::singleEventIterator
std::remove_reference< decltype(getSingleEvents())>::type::iterator singleEventIterator
iterator into the multiset containing the single events
Definition: inotify_watch.cpp:193
inotify_event_wrapper
wrapper for inotify_event with nicer interface.
Definition: inotify_watch.cpp:132
inotify_event_copy::getRenameEvents
static std::map< uint32_t, inotify_event_copy > & getRenameEvents()
return a map which contains the inotify_event_copys
Definition: inotify_watch.cpp:180
inotify_event_wrapper::cookie
uint32_t cookie() const
Definition: inotify_watch.cpp:143
inotify_event_copy::event
const inotify_event_wrapper * event
pointer to the event, either the original or a copy
Definition: inotify_watch.cpp:194
inotify_event_copy::getEvent
const inotify_event_wrapper * getEvent() const
Definition: inotify_watch.cpp:222
inotify_event_copy::cmp
static bool cmp(const inotify_event_copy *lhs, const inotify_event_copy *rhs)
function to order inotify_event_copys by time
Definition: inotify_watch.cpp:185
inotify_event_copy::isCopy
bool isCopy
true if it's a copy. We can't use singleEventIterator as this might be getSingleEvents()....
Definition: inotify_watch.cpp:196