5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Automated Testing Framework (atf)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Copyright (c) 2010 The NetBSD Foundation, Inc.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// All rights reserved.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// Redistribution and use in source and binary forms, with or without
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// modification, are permitted provided that the following conditions
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// are met:
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// 1. Redistributions of source code must retain the above copyright
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// notice, this list of conditions and the following disclaimer.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// 2. Redistributions in binary form must reproduce the above copyright
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// notice, this list of conditions and the following disclaimer in the
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// documentation and/or other materials provided with the distribution.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews//
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#if !defined(TOOLS_TIMERS_HPP)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#define TOOLS_TIMERS_HPP
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsextern "C" {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include <sys/types.h>
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews}
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#include <memory>
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsnamespace tools {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsnamespace timers {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsclass signal_programmer;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// ------------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// The "timer" class.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// ------------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsclass timer {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews // Non-copyable.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews timer(const timer&);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews timer& operator=(const timer&);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews struct impl;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews std::auto_ptr< impl > m_pimpl;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewspublic:
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews timer(const unsigned int);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews virtual ~timer(void);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews bool fired(void) const;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews void set_fired(void);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews virtual void timeout_callback(void) = 0;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews};
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// ------------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// The "child_timer" class.
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews// ------------------------------------------------------------------------
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewsclass child_timer : public timer {
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews const pid_t m_pid;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews volatile bool& m_terminate;
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrewspublic:
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews child_timer(const unsigned int, const pid_t, volatile bool&);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews virtual ~child_timer(void);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews void timeout_callback(void);
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews};
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews} // namespace timers
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews} // namespace tools
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews#endif // !defined(TOOLS_TIMERS_HPP)
5c526acb82c882e41b655c31f5fa4425c87b671cMark Andrews