Skip to content

Commit

Permalink
Reindent.
Browse files Browse the repository at this point in the history
  • Loading branch information
emcrisostomo committed Jul 27, 2014
1 parent a3223da commit 78180d0
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 112 deletions.
8 changes: 4 additions & 4 deletions event.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_EVENT_H
#define FSW_EVENT_H
# define FSW_EVENT_H

#include <string>
#include <ctime>
#include <vector>
# include <string>
# include <ctime>
# include <vector>

enum class event_flag
{
Expand Down
58 changes: 29 additions & 29 deletions fsevent_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

#ifdef HAVE_CORESERVICES_CORESERVICES_H

#include "fsw_exception.h"
#include "fsw_log.h"
#include <iostream>
#include "event.h"
# include "fsw_exception.h"
# include "fsw_log.h"
# include <iostream>
# include "event.h"

using namespace std;

Expand All @@ -37,27 +37,27 @@ static const vector<FSEventFlagType> event_flag_type = create_flag_type_vector()
vector<FSEventFlagType> create_flag_type_vector()
{
vector<FSEventFlagType> flags;
flags.push_back({ kFSEventStreamEventFlagNone, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagMustScanSubDirs, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagUserDropped, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagKernelDropped, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagEventIdsWrapped, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagHistoryDone, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagRootChanged, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagMount, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagUnmount, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagItemCreated, event_flag::Created});
flags.push_back({ kFSEventStreamEventFlagItemRemoved, event_flag::Removed});
flags.push_back({ kFSEventStreamEventFlagItemInodeMetaMod, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagItemRenamed, event_flag::Renamed});
flags.push_back({ kFSEventStreamEventFlagItemModified, event_flag::Updated});
flags.push_back({ kFSEventStreamEventFlagItemFinderInfoMod, event_flag::PlatformSpecific});
flags.push_back({ kFSEventStreamEventFlagItemChangeOwner, event_flag::OwnerModified});
flags.push_back({ kFSEventStreamEventFlagItemXattrMod, event_flag::AttributeModified});
flags.push_back({ kFSEventStreamEventFlagItemIsFile, event_flag::IsFile});
flags.push_back({ kFSEventStreamEventFlagItemIsDir, event_flag::IsDir});
flags.push_back({ kFSEventStreamEventFlagItemIsSymlink, event_flag::IsSymLink});
flags.push_back({kFSEventStreamEventFlagNone, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagMustScanSubDirs, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagUserDropped, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagKernelDropped, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagEventIdsWrapped, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagHistoryDone, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagRootChanged, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagMount, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagUnmount, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagItemCreated, event_flag::Created});
flags.push_back({kFSEventStreamEventFlagItemRemoved, event_flag::Removed});
flags.push_back({kFSEventStreamEventFlagItemInodeMetaMod, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagItemRenamed, event_flag::Renamed});
flags.push_back({kFSEventStreamEventFlagItemModified, event_flag::Updated});
flags.push_back({kFSEventStreamEventFlagItemFinderInfoMod, event_flag::PlatformSpecific});
flags.push_back({kFSEventStreamEventFlagItemChangeOwner, event_flag::OwnerModified});
flags.push_back({kFSEventStreamEventFlagItemXattrMod, event_flag::AttributeModified});
flags.push_back({kFSEventStreamEventFlagItemIsFile, event_flag::IsFile});
flags.push_back({kFSEventStreamEventFlagItemIsDir, event_flag::IsDir});
flags.push_back({kFSEventStreamEventFlagItemIsSymlink, event_flag::IsSymLink});

return flags;
}

Expand Down Expand Up @@ -98,9 +98,9 @@ void fsevent_monitor::run()

for (string path : paths)
{
dirs.push_back(CFStringCreateWithCString(NULL,
path.c_str(),
kCFStringEncodingUTF8));
dirs.push_back(CFStringCreateWithCString(NULL,
path.c_str(),
kCFStringEncodingUTF8));
}

if (dirs.size() == 0) return;
Expand Down Expand Up @@ -182,7 +182,7 @@ void fsevent_monitor::fsevent_callback(ConstFSEventStreamRef streamRef,
for (size_t i = 0; i < numEvents; ++i)
{
const char * path = ((char **) eventPaths)[i];

if (!fse_monitor->accept_path(path)) continue;

events.push_back({path, curr_time, decode_flags(eventFlags[i])});
Expand Down
12 changes: 6 additions & 6 deletions fsevent_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_FSEVENT_MONITOR_H
#define FSW_FSEVENT_MONITOR_H
# define FSW_FSEVENT_MONITOR_H

#include "config.h"
# include "config.h"

#ifdef HAVE_CORESERVICES_CORESERVICES_H
# ifdef HAVE_CORESERVICES_CORESERVICES_H

#include "monitor.h"
#include <CoreServices/CoreServices.h>
# include "monitor.h"
# include <CoreServices/CoreServices.h>

class fsevent_monitor : public monitor
{
Expand All @@ -48,5 +48,5 @@ class fsevent_monitor : public monitor
bool numeric_event = false;
};

#endif /* HAVE_CORESERVICES_CORESERVICES_H */
# endif /* HAVE_CORESERVICES_CORESERVICES_H */
#endif /* FSW_FSEVENT_MONITOR_H */
9 changes: 4 additions & 5 deletions fsw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ static void usage(ostream& stream)
# endif
stream << " -f Print the event time stamp with the specified format.\n";
stream << " -h Show this message.\n";
# ifdef HAVE_REGCOMP
# ifdef HAVE_REGCOMP
stream << " -i Use case insensitive regular expressions.\n";
stream << " -i Include paths matching REGEX.\n";
# endif
Expand Down Expand Up @@ -376,7 +376,6 @@ static void process_events(const vector<event> &events)
write_events(events);
}


static void start_monitor(int argc, char ** argv, int optind)
{
// parsing paths
Expand Down Expand Up @@ -490,7 +489,7 @@ static void parse_opts(int argc, char ** argv)
case '1':
_1flag = true;
break;

#ifdef HAVE_REGCOMP
case 'e':
filters.push_back({optarg, filter_type::filter_exclude});
Expand All @@ -514,7 +513,7 @@ static void parse_opts(int argc, char ** argv)
case 'i':
filters.push_back({optarg, filter_type::filter_include});
break;

case 'I':
Iflag = true;
break;
Expand Down Expand Up @@ -598,7 +597,7 @@ int main(int argc, char ** argv)
cerr << "-k and -p are mutually exclusive." << endl;
::exit(FSW_EXIT_OPT);
}

// configure and start the monitor
try
{
Expand Down
22 changes: 11 additions & 11 deletions fsw.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_H
#define FSW_H
# define FSW_H

#include <exception>
#include <string>
# include <exception>
# include <string>

#define FSW_EXIT_OK 0
#define FSW_EXIT_UNK_OPT 1
#define FSW_EXIT_USAGE 2
#define FSW_EXIT_LATENCY 4
#define FSW_EXIT_STREAM 8
#define FSW_EXIT_ERROR 16
#define FSW_EXIT_ENFILE 32
#define FSW_EXIT_OPT 64
# define FSW_EXIT_OK 0
# define FSW_EXIT_UNK_OPT 1
# define FSW_EXIT_USAGE 2
# define FSW_EXIT_LATENCY 4
# define FSW_EXIT_STREAM 8
# define FSW_EXIT_ERROR 16
# define FSW_EXIT_ENFILE 32
# define FSW_EXIT_OPT 64

bool is_verbose();

Expand Down
6 changes: 3 additions & 3 deletions fsw_exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_EXCEPTION_H
#define FSW_EXCEPTION_H
# define FSW_EXCEPTION_H

#include <exception>
#include <string>
# include <exception>
# include <string>

class fsw_exception : public std::exception
{
Expand Down
2 changes: 1 addition & 1 deletion fsw_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_LOG_H
#define FSW_LOG_H
# define FSW_LOG_H

void fsw_log(const char * msg);
void fsw_perror(const char * msg);
Expand Down
30 changes: 23 additions & 7 deletions fsw_map.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
/*
* Copyright (C) 2014, Enrico M. Crisostomo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_MAP_H
#define FSW_MAP_H
# define FSW_MAP_H

#include "config.h"
# include "config.h"

#if defined(HAVE_UNORDERED_MAP)
#include <unordered_map>
# if defined(HAVE_UNORDERED_MAP)
# include <unordered_map>

template <typename K, typename V>
using fsw_hash_map = std::unordered_map<K, V>;

#else
#include <map>
# else
# include <map>

template <typename K, typename V>
using fsw_hash_map = std::map<K, V>;

#endif
# endif

#endif /* FSW_MAP_H */
30 changes: 23 additions & 7 deletions fsw_set.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
/*
* Copyright (C) 2014, Enrico M. Crisostomo
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_SET_H
#define FSW_SET_H
# define FSW_SET_H

#include "config.h"
# include "config.h"

#if defined(HAVE_UNORDERED_SET)
#include <unordered_set>
# if defined(HAVE_UNORDERED_SET)
# include <unordered_set>

template <typename K>
using fsw_hash_set = std::unordered_set<K>;

#else
#include <set>
# else
# include <set>

template <typename K>
using fsw_hash_set = std::set<K>;

#endif
# endif

#endif /* FSW_SET_H */
2 changes: 1 addition & 1 deletion inotify_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void inotify_monitor::scan(const string &path)

std::ostringstream s;
s << "Watching " << path << ".\n";

fsw_log(s.str().c_str());
}

Expand Down
24 changes: 12 additions & 12 deletions inotify_monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FSW_INOTIFY_MONITOR_H
#define FSW_INOTIFY_MONITOR_H
# define FSW_INOTIFY_MONITOR_H

#include "config.h"
# include "config.h"

#ifdef HAVE_SYS_INOTIFY_H
# ifdef HAVE_SYS_INOTIFY_H

#include "monitor.h"
#include <sys/inotify.h>
#include <ctime>
#include <string>
#include <vector>
#include "fsw_map.h"
# include "monitor.h"
# include <sys/inotify.h>
# include <ctime>
# include <string>
# include <vector>
# include "fsw_map.h"

class inotify_monitor : public monitor
{
Expand All @@ -39,19 +39,19 @@ class inotify_monitor : public monitor
private:
inotify_monitor(const inotify_monitor& orig);
inotify_monitor& operator=(const inotify_monitor & that);

void collect_initial_data();
void notify_events();
void preprocess_dir_event(struct inotify_event * event);
void preprocess_event(struct inotify_event * event);
void preprocess_node_event(struct inotify_event * event);
void scan(const std::string &path);

int inotify = -1;
std::vector<event> events;
fsw_hash_map<int, std::string> file_names_by_descriptor;
time_t curr_time;
};

#endif /* HAVE_SYS_INOTIFY_H */
# endif /* HAVE_SYS_INOTIFY_H */
#endif /* FSW_INOTIFY_MONITOR_H */
Loading

0 comments on commit 78180d0

Please sign in to comment.