559148f12a98cbab87d9820088698303f9e1bf0b
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

1) /* Blinker
2)    Copyright 2011 Stefan Schuermans <stefan@blinkenarea.org>
3)    Copyleft GNU public license - http://www.gnu.org/copyleft/gpl.html
4)    a blinkenarea.org project */
5) 
6) #include <string>
7) #include <sys/stat.h>
8) #include <sys/types.h>
9) #include <unistd.h>
10) 
11) #include "File.h"
12) #include "Time.h"
13) 
14) namespace Blinker {
15) 
16) /**
17)  * @brief constructor from path
18)  * @param[in] path path to file
19)  */
20) File::File(const std::string &path):
21)   m_path(path),
Stefan Schuermans fixed getting current time

Stefan Schuermans authored 13 years ago

22)   m_lastCheck(Time::now())
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

23) {
24) }
25) 
26) /**
27)  * @brief get path to file
28)  * @return path to file
29)  */
30) const std::string & File::getPath()
31) {
32)   return m_path;
33) }
34) 
35) /**
36)  * @brief check if file has been modified
37)  * @return if file has been modified since last check
38)  */
39) bool File::checkModified()
40) {
41)   /* get current time before getting modification time
42)      for not missing any modification */
Stefan Schuermans fixed getting current time

Stefan Schuermans authored 13 years ago

43)   Time now = Time::now();
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

44) 
Stefan Schuermans treating file status change...

Stefan Schuermans authored 13 years ago

45)   // get modification/change times
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

46)   struct stat s;
47)   if (stat(m_path.c_str(), &s))
48)     return false; // cannot stat -> silently ignore
49)   Time modified(s.st_mtime);
Stefan Schuermans treating file status change...

Stefan Schuermans authored 13 years ago

50)   Time changed(s.st_mtime);
Stefan Schuermans first version, plays videos...

Stefan Schuermans authored 13 years ago

51) 
Stefan Schuermans treating file status change...

Stefan Schuermans authored 13 years ago

52)   // has file been modified/changed since last check
53)   bool mod = modified > m_lastCheck || changed > m_lastCheck;