Skip to content

Commit

Permalink
Refactor inotify_monitor to use std::unique_ptr for implementation ma…
Browse files Browse the repository at this point in the history
…nagement and override destructor and run method
  • Loading branch information
emcrisostomo committed Dec 28, 2024
1 parent 4845f62 commit 488d272
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
4 changes: 1 addition & 3 deletions libfswatch/src/libfswatch/c++/inotify_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace fsw
FSW_EVENT_CALLBACK *callback,
void *context) :
monitor(paths_to_monitor, callback, context),
impl(new inotify_monitor_impl())
impl(std::make_unique<inotify_monitor_impl>())
{
impl->inotify_monitor_handle = inotify_init();

Expand Down Expand Up @@ -104,8 +104,6 @@ namespace fsw
{
close(impl->inotify_monitor_handle);
}

delete impl;
}

bool inotify_monitor::add_watch(const std::string& path)
Expand Down
7 changes: 4 additions & 3 deletions libfswatch/src/libfswatch/c++/inotify_monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# include <string>
# include <vector>
# include <filesystem>
# include <functional>

namespace fsw
{
Expand Down Expand Up @@ -59,7 +60,7 @@ namespace fsw
/**
* @brief Destroys an instance of this class.
*/
virtual ~inotify_monitor();
~inotify_monitor() override;

protected:
/**
Expand All @@ -69,7 +70,7 @@ namespace fsw
*
* @see stop()
*/
void run();
void run() override;

private:
inotify_monitor(const inotify_monitor& orig) = delete;
Expand All @@ -85,7 +86,7 @@ namespace fsw
void process_pending_events();
void remove_watch(int fd);

inotify_monitor_impl *impl;
std::unique_ptr<fsw::inotify_monitor_impl> impl;
};
}

Expand Down

0 comments on commit 488d272

Please sign in to comment.