<commit_before>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2014, 2015
<NAME>

This file is part of Abaclade.

Abaclade 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 of the
License, or (at your option) any later version.

Abaclade 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 Abaclade. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#ifndef _ABACLADE_EVENT_LOOP_HXX
#define _ABACLADE_EVENT_LOOP_HXX

#ifndef _ABACLADE_HXX
   #error "Please #include <abaclade.hxx> before this file"
#endif
#ifdef ABC_CXX_PRAGMA_ONCE
   #pragma once
#endif

#include <abaclade/process.hxx>
#include <abaclade/thread.hxx>


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::timer

namespace abc {

//! Generates events based on a time interval expressed in milliseconds.
class ABACLADE_SYM timer {
private:
   friend class event_loop;

public:
   //! Constructor.
   timer();

   //! Destructor.
   ~timer();

   void start();

   void stop();

private:
   //! Underlying OS-dependent ID/handle.
#if ABC_HOST_API_BSD
   typedef int m_id;
#elif ABC_HOST_API_LINUX
   typedef int m_fd;
#elif ABC_HOST_API_WIN32
   typedef HANDLE m_h;
#else
   #error "TODO: HOST_API"
#endif
};

} //namespace abc

////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::event_loop

namespace abc {

//! Generic event loop for a single thread.
class ABACLADE_SYM event_loop : public noncopyable {
public:
   typedef std::function<
      void (event_loop * pel, std::shared_ptr<io::binary::file_base> pfile, std::exception_ptr px)
   > file_event_handler_t;
   typedef std::function<
      void (event_loop * pel, std::shared_ptr<thread> pthr, std::exception_ptr px)
   > thread_event_handler_t;
   typedef std::function<
      void (event_loop * pel, std::shared_ptr<process> pproc)
   > process_event_handler_t;
   typedef std::function<
      void (event_loop * pel, timer tmr)
   > timer_event_handler_t;

public:
   /*! Constructor.

   @param lpSrc
      Source event loop.
   */
   event_loop();
   event_loop(event_loop && elSrc) :
      m_pImpl(elSrc.m_pImpl) {
      elSrc.m_pImpl = nullptr;
   }

   //! Destructor.
   ~event_loop();

   /*! Assignment operator.

   @param lpSrc
      Source event loop.
   @return
      *this.
   */
   event_loop & operator=(event_loop && elSrc) {
      this->~event_loop();
      m_pImpl = elSrc.m_pImpl;
      elSrc.m_pImpl = nullptr;
      return *this;
   }

   void add_file_source(
      std::shared_ptr<io::binary::file_base> pfile, file_event_handler_t fnHandler<commit_msg>Fix code documentation<commit_after>﻿/* -*- coding: utf-8; mode: c++; tab-width: 3; indent-tabs-mode: nil -*-

Copyright 2014, 2015
<NAME>

This file is part of Abaclade.

Abaclade 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 of the
License, or (at your option) any later version.

Abaclade 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 Abaclade. If not, see
<http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------------------------------*/

#ifndef _ABACLADE_EVENT_LOOP_HXX
#define _ABACLADE_EVENT_LOOP_HXX

#ifndef _ABACLADE_HXX
   #error "Please #include <abaclade.hxx> before this file"
#endif
#ifdef ABC_CXX_PRAGMA_ONCE
   #pragma once
#endif

#include <abaclade/process.hxx>
#include <abaclade/thread.hxx>


////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::timer

namespace abc {

//! Generates events based on a time interval expressed in milliseconds.
class ABACLADE_SYM timer {
private:
   friend class event_loop;

public:
   //! Constructor.
   timer();

   //! Destructor.
   ~timer();

   void start();

   void stop();

private:
   //! Underlying OS-dependent ID/handle.
#if ABC_HOST_API_BSD
   typedef int m_id;
#elif ABC_HOST_API_LINUX
   typedef int m_fd;
#elif ABC_HOST_API_WIN32
   typedef HANDLE m_h;
#else
   #error "TODO: HOST_API"
#endif
};

} //namespace abc

////////////////////////////////////////////////////////////////////////////////////////////////////
// abc::event_loop

namespace abc {

//! Generic event loop for a single thread.
class ABACLADE_SYM event_loop : public noncopyable {
public:
   typedef std::function<
      void (event_loop * pel, std::shared_ptr<io::binary::file_base> pfile, std::exception_ptr px)
   > file_event_handler_t;
   typedef std::function<
      void (event_loop * pel, std::shared_ptr<thread> pthr, std::exception_ptr px)
   > thread_event_handler_t;
   typedef std::function<
      void (event_loop * pel, std::shared_ptr<process> pproc)
   > process_event_handler_t;
   typedef std::function<
      void (event_loop * pel, timer tmr)
   > timer_event_handler_t;

public:
   /*! Constructor.

   @param elSrc
      Source event loop.
   */
   event_loop();
   event_loop(event_loop && elSrc) :
      m_pImpl(elSrc.m_pImpl) {
      elSrc.m_pImpl = nullptr;
   }

   //! Destructor.
   ~event_loop();

   /*! Assignment operator.

   @param elSrc
      Source event loop.
   @return
      *this.
   */
   event_loop & operator=(event_loop && elSrc) {
      this->~event_loop();
      m_pImpl = elSrc.m_pImpl;
      elSrc.m_pImpl = nullptr;
      return *this;
   }

   void add_file_source(
      std::shared_ptr<io::binary::file_base> pfile, file_event_handler_t fnHandler
{'fraction_non_alphanumeric': 0.18568913078277574, 'fraction_numerical': 0.004161997758924283, 'mean_word_length': 2.4086197490452808, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1760783', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1884, 'n_words': 571}